Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- 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_path_or_category(search_term)
- def search_by_url(url):
- try:
- # Check if the URL is a local file path
- if os.path.exists(url):
- with open(url, 'r') as file:
- m3u_data = file.readlines()
- # Process M3U data
- process_m3u_data(m3u_data)
- else:
- # 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:
- m3u_data = response.text.split('\n')
- # Process M3U data
- process_m3u_data(m3u_data)
- else:
- result_text.insert(tk.END, f"Error: Failed to fetch channel data. Status Code: {response.status_code}")
- except Exception as e:
- result_text.insert(tk.END, f"Error: {str(e)}")
- def search_by_path_or_category(path):
- try:
- if os.path.exists(path):
- with open(path, 'r') as file:
- m3u_data = file.readlines()
- process_m3u_data(m3u_data)
- else:
- # Check if the selected category exists in the category_urls dictionary
- selected_category = category_var.get()
- if selected_category in category_urls:
- category_url = category_urls[selected_category]
- if category_url:
- search_by_url(category_url)
- else:
- result_text.insert(tk.END, f"Error: Category URL is not provided for {selected_category}")
- else:
- result_text.insert(tk.END, f"Error: Category '{selected_category}' not found")
- except Exception as e:
- result_text.insert(tk.END, f"Error: {str(e)}")
- def process_m3u_data(m3u_data):
- # 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
- def play_selected_channel(event):
- try:
- # Get the selected channel name
- selected_channel = result_text.get(tk.ACTIVE)
- # Check if the selected channel is a local file path
- if os.path.exists(selected_channel):
- subprocess.Popen([r"C:\Program Files\VideoLAN\VLC\vlc.exe", selected_channel])
- else:
- # 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 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 0R local OR Select Category:", bg="#336699", fg="white")
- url_label.pack(side=tk.LEFT, padx=5)
- url_entry = tk.Entry(url_frame, width=80) # Adjust width here
- url_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="Najeeb Iptv Channels Run Vlc Player Check Working Or Not Working And save Working URLS in M3U File:", 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 = {
- "NAJEEB-IPTV": "",
- "ALL-INDEX": "https://iptv-org.github.io/iptv/index.m3u",
- "CATEGORY": "https://iptv-org.github.io/iptv/index.category.m3u",
- "LANGUAGE": "https://iptv-org.github.io/iptv/index.language.m3u",
- "COUNTRY": "https://iptv-org.github.io/iptv/index.country.m3u",
- "REGION": "https://iptv-org.github.io/iptv/index.region.m3u",
- # Add more categories here
- }
- category_var = tk.StringVar(app)
- category_var.set("NAJEEB-IPTV") # 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