Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- from tkinter import ttk
- import requests
- import subprocess
- def search_channels():
- search_term = url_entry.get().lower()
- if search_term.startswith("http"):
- search_by_url(search_term)
- else:
- search_by_category()
- def search_by_url(url):
- try:
- # Send a GET request to the provided URL
- response = requests.get(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 search_by_category():
- category = category_var.get()
- url = category_urls.get(category)
- 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 All Category")
- 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 or select category:", 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)
- # Dropdown menu for channel categories
- category_urls = {
- "ALL-CATEGORY": "",
- "Animation": "https://iptv-org.github.io/iptv/categories/animation.m3u",
- "Auto": "https://iptv-org.github.io/iptv/categories/auto.m3u",
- "Business": "https://iptv-org.github.io/iptv/categories/business.m3u",
- "Classic": "https://iptv-org.github.io/iptv/categories/classic.m3u",
- "Comedy": "https://iptv-org.github.io/iptv/categories/comedy.m3u",
- "Cooking": "https://iptv-org.github.io/iptv/categories/cooking.m3u",
- "Culture": "https://iptv-org.github.io/iptv/categories/culture.m3u",
- "Documentary": "https://iptv-org.github.io/iptv/categories/documentary.m3u",
- "Education": "https://iptv-org.github.io/iptv/categories/education.m3u",
- "Entertainment": "https://iptv-org.github.io/iptv/categories/entertainment.m3u",
- "Family": "https://iptv-org.github.io/iptv/categories/family.m3u",
- "General": "https://iptv-org.github.io/iptv/categories/general.m3u",
- "Kids": "https://iptv-org.github.io/iptv/categories/kids.m3u",
- "Legislative": "https://iptv-org.github.io/iptv/categories/legislative.m3u",
- "Lifestyle": "https://iptv-org.github.io/iptv/categories/lifestyle.m3u",
- "Movies": "https://iptv-org.github.io/iptv/categories/movies.m3u",
- "Music": "https://iptv-org.github.io/iptv/categories/music.m3u",
- "News": "https://iptv-org.github.io/iptv/categories/news.m3u",
- "Outdoor": "https://iptv-org.github.io/iptv/categories/outdoor.m3u",
- "Relax": "https://iptv-org.github.io/iptv/categories/relax.m3u",
- "Religious": "https://iptv-org.github.io/iptv/categories/religious.m3u",
- "Science": "https://iptv-org.github.io/iptv/categories/science.m3u",
- "Series": "https://iptv-org.github.io/iptv/categories/series.m3u",
- "Shop": "https://iptv-org.github.io/iptv/categories/shop.m3u",
- "Sports": "https://iptv-org.github.io/iptv/categories/sports.m3u",
- "Travel": "https://iptv-org.github.io/iptv/categories/travel.m3u",
- "Weather": "https://iptv-org.github.io/iptv/categories/weather.m3u",
- "XXX": "https://iptv-org.github.io/iptv/categories/xxx.m3u",
- "Undefined": "https://iptv-org.github.io/iptv/categories/undefined.m3u",
- # Add more categories here
- }
- category_var = tk.StringVar(app)
- category_var.set("CLASSIC") # default value
- category_dropdown = ttk.OptionMenu(app, category_var, *category_urls.keys())
- category_dropdown.pack(pady=10)
- # Global variable to store channels' info
- channels_info = {}
- working_links = {}
- # Run the application loop
- app.mainloop()
Add Comment
Please, Sign In to add comment