Najeebsk

IPTV-CHECK-M3U-01.py

Mar 13th, 2024
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 8.12 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') 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') 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' names and URLs
  59.     global channels_info
  60.     channels_info = {}
  61.     # Extract channel names and URLs
  62.     channel_name = None
  63.     for line in m3u_data:
  64.         if line.startswith('#EXTINF:'):
  65.             channel_name = line.split(',')[-1]
  66.         elif line.startswith('http') and channel_name:
  67.             channels_info[channel_name] = line.strip()
  68.             # Insert channel name into the listbox
  69.             result_text.insert(tk.END, channel_name)
  70.             channel_name = None
  71.  
  72. def play_selected_channel(event):
  73.     try:
  74.         # Get the selected channel name
  75.         selected_channel = result_text.get(tk.ACTIVE)
  76.        
  77.         # Check if the selected channel is a local file path
  78.         if os.path.exists(selected_channel):
  79.             subprocess.Popen([r"C:\Program Files\VideoLAN\VLC\vlc.exe", selected_channel])
  80.         else:
  81.             # Open the corresponding URL in VLC
  82.             subprocess.Popen([r"C:\Program Files\VideoLAN\VLC\vlc.exe", channels_info[selected_channel]])
  83.     except (tk.TclError, KeyError):
  84.         pass  # Ignore if no channel is selected or channel info is missing
  85.  
  86. def check_links():
  87.     global working_links
  88.     working_links = {}
  89.     for channel_name, url in channels_info.items():
  90.         try:
  91.             response = requests.get(url)
  92.             if response.status_code == 200:
  93.                 working_links[channel_name] = url
  94.         except requests.RequestException:
  95.             pass
  96.  
  97.     # Display working links in the result_text widget
  98.     result_text.delete(0, tk.END)
  99.     for channel_name, url in working_links.items():
  100.         result_text.insert(tk.END, f"{channel_name}: {url}\n")
  101.  
  102. def save_working_links():
  103.     with open("working_channels.m3u", "w", encoding="utf-8") as f:
  104.         for channel_name, url in working_links.items():
  105.             f.write(f"#EXTINF:-1,{channel_name}\n{url}\n")
  106.  
  107. # Create the main application window
  108. app = tk.Tk()
  109. app.title("Najeeb IPTV Channel Search M3u All Category")
  110. app.geometry("800x600")
  111. app.configure(bg="#336699")
  112.  
  113. # Add labels, entry fields, buttons, etc.
  114. url_frame = tk.Frame(app, bg="#336699")
  115. url_frame.pack(pady=10)
  116.  
  117. url_label = tk.Label(url_frame, text="Enter URL 0R local OR Select Category:", bg="#336699", fg="white")
  118. url_label.pack(side=tk.LEFT, padx=5)
  119.  
  120. url_entry = tk.Entry(url_frame, width=80)  # Adjust width here
  121. url_entry.pack(side=tk.LEFT, padx=5)
  122.  
  123. search_button = tk.Button(url_frame, text="Search", command=search_channels, bg="#FFA500", fg="white")
  124. search_button.pack(side=tk.LEFT, padx=5)
  125.  
  126. 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")
  127. result_label.pack()
  128.  
  129. # Add scrollbar to the listbox
  130. scrollbar = tk.Scrollbar(app, orient=tk.VERTICAL)
  131. scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
  132.  
  133. result_text = tk.Listbox(app, height=30, width=130, yscrollcommand=scrollbar.set)
  134. result_text.pack()
  135.  
  136. # Configure scrollbar
  137. scrollbar.config(command=result_text.yview)
  138.  
  139. # Bind double click event to play_selected_channel function
  140. result_text.bind("<Double-1>", play_selected_channel)
  141.  
  142. # Add button to check links
  143. check_button = tk.Button(app, text="Check Links", command=check_links, bg="#008000", fg="white")
  144. check_button.pack(side=tk.RIGHT, padx=5)
  145.  
  146. # Add button to save working links
  147. save_button = tk.Button(app, text="Save Working Links", command=save_working_links, bg="#FF0000", fg="white")
  148. save_button.pack(side=tk.LEFT, padx=5)
  149.  
  150. # Dropdown menu for channel categories
  151. category_urls = {
  152.     "ALL-CATEGORY": "",
  153.     "Animation": "https://iptv-org.github.io/iptv/categories/animation.m3u",
  154.     "Auto": "https://iptv-org.github.io/iptv/categories/auto.m3u",
  155.     "Business": "https://iptv-org.github.io/iptv/categories/business.m3u",
  156.     "Classic": "https://iptv-org.github.io/iptv/categories/classic.m3u",
  157.     "Comedy": "https://iptv-org.github.io/iptv/categories/comedy.m3u",
  158.     "Cooking": "https://iptv-org.github.io/iptv/categories/cooking.m3u",
  159.     "Culture": "https://iptv-org.github.io/iptv/categories/culture.m3u",
  160.     "Documentary": "https://iptv-org.github.io/iptv/categories/documentary.m3u",
  161.     "Education": "https://iptv-org.github.io/iptv/categories/education.m3u",
  162.     "Entertainment": "https://iptv-org.github.io/iptv/categories/entertainment.m3u",
  163.     "Family": "https://iptv-org.github.io/iptv/categories/family.m3u",
  164.     "General": "https://iptv-org.github.io/iptv/categories/general.m3u",
  165.     "Kids": "https://iptv-org.github.io/iptv/categories/kids.m3u",
  166.     "Legislative": "https://iptv-org.github.io/iptv/categories/legislative.m3u",
  167.     "Lifestyle": "https://iptv-org.github.io/iptv/categories/lifestyle.m3u",
  168.     "Movies": "https://iptv-org.github.io/iptv/categories/movies.m3u",
  169.     "Music": "https://iptv-org.github.io/iptv/categories/music.m3u",
  170.     "News": "https://iptv-org.github.io/iptv/categories/news.m3u",
  171.     "Outdoor": "https://iptv-org.github.io/iptv/categories/outdoor.m3u",
  172.     "Relax": "https://iptv-org.github.io/iptv/categories/relax.m3u",
  173.     "Religious": "https://iptv-org.github.io/iptv/categories/religious.m3u",
  174.     "Science": "https://iptv-org.github.io/iptv/categories/science.m3u",
  175.     "Series": "https://iptv-org.github.io/iptv/categories/series.m3u",
  176.     "Shop": "https://iptv-org.github.io/iptv/categories/shop.m3u",
  177.     "Sports": "https://iptv-org.github.io/iptv/categories/sports.m3u",
  178.     "Travel": "https://iptv-org.github.io/iptv/categories/travel.m3u",
  179.     "Weather": "https://iptv-org.github.io/iptv/categories/weather.m3u",
  180.     "XXX": "https://iptv-org.github.io/iptv/categories/xxx.m3u",
  181.     "Undefined": "https://iptv-org.github.io/iptv/categories/undefined.m3u",
  182.     # Add more categories here
  183. }
  184.  
  185. category_var = tk.StringVar(app)
  186. category_var.set("NAJEEB-IPTV")  # default value
  187. category_dropdown = ttk.OptionMenu(app, category_var, *category_urls.keys())
  188. category_dropdown.pack(pady=10)
  189.  
  190. # Global variable to store channels' info
  191. channels_info = {}
  192. working_links = {}
  193.  
  194. # Run the application loop
  195. app.mainloop()
  196.  
Add Comment
Please, Sign In to add comment