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 = {}
- # Extract channel names and URLs
- channel_name = None
- for line in m3u_data:
- if line.startswith('#EXTINF:'):
- channel_name = line.split(',')[-1]
- elif line.startswith('http') and channel_name:
- channels_info[channel_name] = line.strip()
- # Insert channel name into the listbox
- result_text.insert(tk.END, channel_name)
- channel_name = None
- 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
- def check_links():
- global working_links
- working_links = {}
- for channel_name, url in channels_info.items():
- try:
- response = requests.get(url)
- if response.status_code == 200:
- working_links[channel_name] = url
- except requests.RequestException:
- pass
- # Display working links in the result_text widget
- result_text.delete(0, tk.END)
- for channel_name, url in working_links.items():
- result_text.insert(tk.END, f"{channel_name}: {url}\n")
- def save_working_links():
- with open("working_channels.m3u", "w", encoding="utf-8") as f:
- for channel_name, url in working_links.items():
- f.write(f"#EXTINF:-1,{channel_name}\n{url}\n")
- # Create the main application window
- app = tk.Tk()
- app.title("Najeeb IPTV Channel Search M3u and Mac")
- app.geometry("800x600")
- app.configure(bg="#336699")
- # Add labels, entry fields, buttons, etc.
- url_frame = tk.Frame(app, bg="#336699")
- url_frame.pack(pady=10)
- url_label = tk.Label(url_frame, text="Enter URL:", bg="#336699", fg="white")
- url_label.pack(side=tk.LEFT, padx=5)
- url_entry = tk.Entry(url_frame, width=50) # Adjust width here
- url_entry.pack(side=tk.LEFT, padx=5)
- mac_label = tk.Label(url_frame, text="Enter MAC Address:", bg="#336699", fg="white")
- mac_label.pack(side=tk.LEFT, padx=5)
- mac_entry = tk.Entry(url_frame)
- mac_entry.pack(side=tk.LEFT, padx=5)
- search_button = tk.Button(url_frame, text="Search", command=search_channels, bg="#FFA500", fg="white")
- search_button.pack(side=tk.LEFT, padx=5)
- result_label = tk.Label(app, text="Channels:", bg="#336699", fg="white")
- 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=30, width=130, 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)
- # Add button to check links
- check_button = tk.Button(app, text="Check Links", command=check_links, bg="#008000", fg="white")
- check_button.pack(side=tk.RIGHT, padx=5)
- # Add button to save working links
- save_button = tk.Button(app, text="Save Working Links", command=save_working_links, bg="#FF0000", fg="white")
- save_button.pack(side=tk.LEFT, padx=5)
- # Global variable to store channels' info
- channels_info = {}
- working_links = {}
- # Run the application loop
- app.mainloop()
Add Comment
Please, Sign In to add comment