Najeebsk

IPTV-EXTRAC-URLS.pyw

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