Najeebsk

IPTV-MAC. Py

Mar 12th, 2024
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.98 KB | None | 0 0
  1. import tkinter as tk
  2. import requests
  3. import subprocess
  4.  
  5. def search_channels():
  6.     url = url_entry.get()
  7.     mac_address = mac_entry.get()
  8.  
  9.     # Construct the request URL with the provided MAC address
  10.     request_url = f"{url}?mac={mac_address}"
  11.  
  12.     try:
  13.         # Send a GET request to the constructed URL
  14.         response = requests.get(request_url)
  15.        
  16.         # Check if the request was successful (status code 200)
  17.         if response.status_code == 200:
  18.             # Parse M3U data
  19.             m3u_data = response.text.split('\n')
  20.            
  21.             # Clear any previous results
  22.             result_text.delete(0, tk.END)
  23.            
  24.             # Store channels' names and URLs
  25.             global channels_info
  26.             channels_info = {}
  27.            
  28.             # Extract channel names and URLs
  29.             channel_name = None
  30.             for line in m3u_data:
  31.                 if line.startswith('#EXTINF:'):
  32.                     channel_name = line.split(',')[-1]
  33.                 elif line.startswith('http') and channel_name:
  34.                     channels_info[channel_name] = line.strip()
  35.                     # Insert channel name into the listbox
  36.                     result_text.insert(tk.END, channel_name)
  37.                     channel_name = None
  38.         else:
  39.             result_text.insert(tk.END, f"Error: Failed to fetch channel data. Status Code: {response.status_code}")
  40.     except requests.RequestException as e:
  41.         result_text.insert(tk.END, f"Error: {str(e)}")
  42.  
  43. def play_selected_channel(event):
  44.     try:
  45.         # Get the selected channel name
  46.         selected_channel = result_text.get(tk.ACTIVE)
  47.        
  48.         # Open the corresponding URL in VLC
  49.         subprocess.Popen([r"C:\Program Files\VideoLAN\VLC\vlc.exe", channels_info[selected_channel]])
  50.     except (tk.TclError, KeyError):
  51.         pass  # Ignore if no channel is selected or channel info is missing
  52.  
  53. def check_links():
  54.     global working_links
  55.     working_links = {}
  56.     for channel_name, url in channels_info.items():
  57.         try:
  58.             response = requests.get(url)
  59.             if response.status_code == 200:
  60.                 working_links[channel_name] = url
  61.         except requests.RequestException:
  62.             pass
  63.  
  64.     # Display working links in the result_text widget
  65.     result_text.delete(0, tk.END)
  66.     for channel_name, url in working_links.items():
  67.         result_text.insert(tk.END, f"{channel_name}: {url}\n")
  68.  
  69. def save_working_links():
  70.     with open("working_channels.m3u", "w", encoding="utf-8") as f:
  71.         for channel_name, url in working_links.items():
  72.             f.write(f"#EXTINF:-1,{channel_name}\n{url}\n")
  73.  
  74. # Create the main application window
  75. app = tk.Tk()
  76. app.title("IPTV Channel Search")
  77.  
  78. # Add labels, entry fields, buttons, etc.
  79. url_label = tk.Label(app, text="Enter URL:")
  80. url_label.pack()
  81.  
  82. url_entry = tk.Entry(app)
  83. url_entry.pack()
  84.  
  85. mac_label = tk.Label(app, text="Enter MAC Address:")
  86. mac_label.pack()
  87.  
  88. mac_entry = tk.Entry(app)
  89. mac_entry.pack()
  90.  
  91. search_button = tk.Button(app, text="Search", command=search_channels)
  92. search_button.pack()
  93.  
  94. result_label = tk.Label(app, text="Channels:")
  95. result_label.pack()
  96.  
  97. # Add scrollbar to the listbox
  98. scrollbar = tk.Scrollbar(app, orient=tk.VERTICAL)
  99. scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
  100.  
  101. result_text = tk.Listbox(app, height=10, width=50, yscrollcommand=scrollbar.set)
  102. result_text.pack()
  103.  
  104. # Configure scrollbar
  105. scrollbar.config(command=result_text.yview)
  106.  
  107. # Bind double click event to play_selected_channel function
  108. result_text.bind("<Double-1>", play_selected_channel)
  109.  
  110. # Add button to check links
  111. check_button = tk.Button(app, text="Check Links", command=check_links)
  112. check_button.pack()
  113.  
  114. # Add button to save working links
  115. save_button = tk.Button(app, text="Save Working Links", command=save_working_links)
  116. save_button.pack()
  117.  
  118. # Global variable to store channels' info
  119. channels_info = {}
  120. working_links = {}
  121.  
  122. # Run the application loop
  123. app.mainloop()
  124.  
Add Comment
Please, Sign In to add comment