Najeebsk

IPTV-CHECK-ALL-M3U.py

Mar 13th, 2024
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.66 KB | None | 0 0
  1. import tkinter as tk
  2. from tkinter import ttk
  3. import requests
  4. import subprocess
  5.  
  6. def search_channels():
  7.     search_term = url_entry.get().lower()
  8.     if search_term.startswith("http"):
  9.         search_by_url(search_term)
  10.     else:
  11.         search_by_category()
  12.  
  13. def search_by_url(url):
  14.     try:
  15.         # Send a GET request to the provided URL
  16.         response = requests.get(url)
  17.        
  18.         # Check if the request was successful (status code 200)
  19.         if response.status_code == 200:
  20.             # Parse M3U data
  21.             m3u_data = response.text.split('\n')
  22.            
  23.             # Clear any previous results
  24.             result_text.delete(0, tk.END)
  25.            
  26.             # Store channels' names and URLs
  27.             global channels_info
  28.             channels_info = {}
  29.            
  30.             # Extract channel names and URLs
  31.             channel_name = None
  32.             for line in m3u_data:
  33.                 if line.startswith('#EXTINF:'):
  34.                     channel_name = line.split(',')[-1]
  35.                 elif line.startswith('http') and channel_name:
  36.                     channels_info[channel_name] = line.strip()
  37.                     # Insert channel name into the listbox
  38.                     result_text.insert(tk.END, channel_name)
  39.                     channel_name = None
  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 search_by_category():
  46.     category = category_var.get()
  47.     url = category_urls.get(category)
  48.     mac_address = mac_entry.get()
  49.  
  50.     # Construct the request URL with the provided MAC address
  51.     request_url = f"{url}?mac={mac_address}"
  52.  
  53.     try:
  54.         # Send a GET request to the constructed URL
  55.         response = requests.get(request_url)
  56.        
  57.         # Check if the request was successful (status code 200)
  58.         if response.status_code == 200:
  59.             # Parse M3U data
  60.             m3u_data = response.text.split('\n')
  61.            
  62.             # Clear any previous results
  63.             result_text.delete(0, tk.END)
  64.            
  65.             # Store channels' names and URLs
  66.             global channels_info
  67.             channels_info = {}
  68.            
  69.             # Extract channel names and URLs
  70.             channel_name = None
  71.             for line in m3u_data:
  72.                 if line.startswith('#EXTINF:'):
  73.                     channel_name = line.split(',')[-1]
  74.                 elif line.startswith('http') and channel_name:
  75.                     channels_info[channel_name] = line.strip()
  76.                     # Insert channel name into the listbox
  77.                     result_text.insert(tk.END, channel_name)
  78.                     channel_name = None
  79.         else:
  80.             result_text.insert(tk.END, f"Error: Failed to fetch channel data. Status Code: {response.status_code}")
  81.     except requests.RequestException as e:
  82.         result_text.insert(tk.END, f"Error: {str(e)}")
  83.  
  84. def play_selected_channel(event):
  85.     try:
  86.         # Get the selected channel name
  87.         selected_channel = result_text.get(tk.ACTIVE)
  88.        
  89.         # Open the corresponding URL in VLC
  90.         subprocess.Popen([r"C:\Program Files\VideoLAN\VLC\vlc.exe", channels_info[selected_channel]])
  91.     except (tk.TclError, KeyError):
  92.         pass  # Ignore if no channel is selected or channel info is missing
  93.  
  94. def check_links():
  95.     global working_links
  96.     working_links = {}
  97.     for channel_name, url in channels_info.items():
  98.         try:
  99.             response = requests.get(url)
  100.             if response.status_code == 200:
  101.                 working_links[channel_name] = url
  102.         except requests.RequestException:
  103.             pass
  104.  
  105.     # Display working links in the result_text widget
  106.     result_text.delete(0, tk.END)
  107.     for channel_name, url in working_links.items():
  108.         result_text.insert(tk.END, f"{channel_name}: {url}\n")
  109.  
  110. def save_working_links():
  111.     with open("working_channels.m3u", "w", encoding="utf-8") as f:
  112.         for channel_name, url in working_links.items():
  113.             f.write(f"#EXTINF:-1,{channel_name}\n{url}\n")
  114.  
  115. # Create the main application window
  116. app = tk.Tk()
  117. app.title("Najeeb IPTV Channel Search M3u and Mac All Category")
  118. app.geometry("800x600")
  119. app.configure(bg="#336699")
  120.  
  121. # Add labels, entry fields, buttons, etc.
  122. url_frame = tk.Frame(app, bg="#336699")
  123. url_frame.pack(pady=10)
  124.  
  125. url_label = tk.Label(url_frame, text="Enter URL or select category:", bg="#336699", fg="white")
  126. url_label.pack(side=tk.LEFT, padx=5)
  127.  
  128. url_entry = tk.Entry(url_frame, width=50)  # Adjust width here
  129. url_entry.pack(side=tk.LEFT, padx=5)
  130.  
  131. mac_label = tk.Label(url_frame, text="Enter MAC Address:", bg="#336699", fg="white")
  132. mac_label.pack(side=tk.LEFT, padx=5)
  133.  
  134. mac_entry = tk.Entry(url_frame)
  135. mac_entry.pack(side=tk.LEFT, padx=5)
  136.  
  137. search_button = tk.Button(url_frame, text="Search", command=search_channels, bg="#FFA500", fg="white")
  138. search_button.pack(side=tk.LEFT, padx=5)
  139.  
  140. result_label = tk.Label(app, text="Channels:", bg="#336699", fg="white")
  141. result_label.pack()
  142.  
  143. # Add scrollbar to the listbox
  144. scrollbar = tk.Scrollbar(app, orient=tk.VERTICAL)
  145. scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
  146.  
  147. result_text = tk.Listbox(app, height=30, width=130, yscrollcommand=scrollbar.set)
  148. result_text.pack()
  149.  
  150. # Configure scrollbar
  151. scrollbar.config(command=result_text.yview)
  152.  
  153. # Bind double click event to play_selected_channel function
  154. result_text.bind("<Double-1>", play_selected_channel)
  155.  
  156. # Add button to check links
  157. check_button = tk.Button(app, text="Check Links", command=check_links, bg="#008000", fg="white")
  158. check_button.pack(side=tk.RIGHT, padx=5)
  159.  
  160. # Add button to save working links
  161. save_button = tk.Button(app, text="Save Working Links", command=save_working_links, bg="#FF0000", fg="white")
  162. save_button.pack(side=tk.LEFT, padx=5)
  163.  
  164. # Dropdown menu for channel categories
  165. category_urls = {
  166.     "NAJEEB-IPTV": "",
  167.     "ALL-INDEX": "https://iptv-org.github.io/iptv/index.m3u",
  168.     "CATEGORY": "https://iptv-org.github.io/iptv/index.category.m3u",
  169.     "LANGUAGE": "https://iptv-org.github.io/iptv/index.language.m3u",
  170.     "COUNTRY": "https://iptv-org.github.io/iptv/index.country.m3u",
  171.     "REGION": "https://iptv-org.github.io/iptv/index.region.m3u",
  172.     # Add more categories here
  173. }
  174.  
  175. category_var = tk.StringVar(app)
  176. category_var.set("CLASSIC")  # default value
  177. category_dropdown = ttk.OptionMenu(app, category_var, *category_urls.keys())
  178. category_dropdown.pack(pady=10)
  179.  
  180. # Global variable to store channels' info
  181. channels_info = {}
  182. working_links = {}
  183.  
  184. # Run the application loop
  185. app.mainloop()
  186.  
Add Comment
Please, Sign In to add comment