Najeebsk

IPTV-MAC-CHECK. Py

Mar 12th, 2024
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.03 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.             # Convert m3u_data to an iterator
  29.             m3u_iter = iter(m3u_data)
  30.            
  31.             # Extract channel names and URLs
  32.             for line in m3u_iter:
  33.                 if line.startswith('#EXTINF:'):
  34.                     channel_name = line.split(',')[-1]
  35.                     url_line = next(m3u_iter, '')
  36.                     if url_line.startswith('http'):
  37.                         channels_info[channel_name] = url_line.strip()
  38.                         # Insert channel name into the listbox
  39.                         result_text.insert(tk.END, channel_name)
  40.         else:
  41.             result_text.insert(tk.END, f"Error: Failed to fetch channel data. Status Code: {response.status_code}")
  42.     except requests.RequestException as e:
  43.         result_text.insert(tk.END, f"Error: {str(e)}")
  44.  
  45. def play_selected_channel(event):
  46.     try:
  47.         # Get the selected channel name
  48.         selected_channel = result_text.get(tk.ACTIVE)
  49.        
  50.         # Open the corresponding URL in VLC
  51.         subprocess.Popen([r"C:\Program Files\VideoLAN\VLC\vlc.exe", channels_info[selected_channel]])
  52.     except (tk.TclError, KeyError):
  53.         pass  # Ignore if no channel is selected or channel info is missing
  54.  
  55. # Create the main application window
  56. app = tk.Tk()
  57. app.title("IPTV Channel Search")
  58.  
  59. # Add labels, entry fields, buttons, etc.
  60. url_label = tk.Label(app, text="Enter URL:")
  61. url_label.pack()
  62.  
  63. url_entry = tk.Entry(app)
  64. url_entry.pack()
  65.  
  66. mac_label = tk.Label(app, text="Enter MAC Address:")
  67. mac_label.pack()
  68.  
  69. mac_entry = tk.Entry(app)
  70. mac_entry.pack()
  71.  
  72. search_button = tk.Button(app, text="Search", command=search_channels)
  73. search_button.pack()
  74.  
  75. result_label = tk.Label(app, text="Channels:")
  76. result_label.pack()
  77.  
  78. # Add scrollbar to the listbox
  79. scrollbar = tk.Scrollbar(app, orient=tk.VERTICAL)
  80. scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
  81.  
  82. result_text = tk.Listbox(app, height=10, width=50, yscrollcommand=scrollbar.set)
  83. result_text.pack()
  84.  
  85. # Configure scrollbar
  86. scrollbar.config(command=result_text.yview)
  87.  
  88. # Bind double click event to play_selected_channel function
  89. result_text.bind("<Double-1>", play_selected_channel)
  90.  
  91. # Global variable to store channels' info
  92. channels_info = {}
  93.  
  94. # Run the application loop
  95. app.mainloop()
  96.  
Add Comment
Please, Sign In to add comment