Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- import requests
- import subprocess
- def search_channels():
- url = url_entry.get()
- mac_address = mac_entry.get()
- # Construct the request URL with the provided MAC address
- request_url = f"{url}?mac={mac_address}"
- try:
- # Send a GET request to the constructed URL
- response = requests.get(request_url)
- # Check if the request was successful (status code 200)
- if response.status_code == 200:
- # Parse M3U data
- m3u_data = response.text.split('\n')
- # Clear any previous results
- result_text.delete(0, tk.END)
- # Store channels' names and URLs
- global channels_info
- channels_info = {}
- # Convert m3u_data to an iterator
- m3u_iter = iter(m3u_data)
- # Extract channel names and URLs
- for line in m3u_iter:
- if line.startswith('#EXTINF:'):
- channel_name = line.split(',')[-1]
- url_line = next(m3u_iter, '')
- if url_line.startswith('http'):
- channels_info[channel_name] = url_line.strip()
- # Insert channel name into the listbox
- result_text.insert(tk.END, channel_name)
- else:
- result_text.insert(tk.END, f"Error: Failed to fetch channel data. Status Code: {response.status_code}")
- except requests.RequestException as e:
- result_text.insert(tk.END, f"Error: {str(e)}")
- def play_selected_channel(event):
- try:
- # Get the selected channel name
- selected_channel = result_text.get(tk.ACTIVE)
- # Open the corresponding URL in VLC
- subprocess.Popen([r"C:\Program Files\VideoLAN\VLC\vlc.exe", channels_info[selected_channel]])
- except (tk.TclError, KeyError):
- pass # Ignore if no channel is selected or channel info is missing
- # Create the main application window
- app = tk.Tk()
- app.title("IPTV Channel Search")
- # Add labels, entry fields, buttons, etc.
- url_label = tk.Label(app, text="Enter URL:")
- url_label.pack()
- url_entry = tk.Entry(app)
- url_entry.pack()
- mac_label = tk.Label(app, text="Enter MAC Address:")
- mac_label.pack()
- mac_entry = tk.Entry(app)
- mac_entry.pack()
- search_button = tk.Button(app, text="Search", command=search_channels)
- search_button.pack()
- result_label = tk.Label(app, text="Channels:")
- result_label.pack()
- # Add scrollbar to the listbox
- scrollbar = tk.Scrollbar(app, orient=tk.VERTICAL)
- scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
- result_text = tk.Listbox(app, height=10, width=50, yscrollcommand=scrollbar.set)
- result_text.pack()
- # Configure scrollbar
- scrollbar.config(command=result_text.yview)
- # Bind double click event to play_selected_channel function
- result_text.bind("<Double-1>", play_selected_channel)
- # Global variable to store channels' info
- channels_info = {}
- # Run the application loop
- app.mainloop()
Add Comment
Please, Sign In to add comment