Najeebsk

IPTV-CHECK-M3U1.py

Mar 12th, 2024 (edited)
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 8.42 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.     "ALL-CATEGORY": "",
  167.     "Animation": "https://iptv-org.github.io/iptv/categories/animation.m3u",
  168.     "Auto": "https://iptv-org.github.io/iptv/categories/auto.m3u",
  169.     "Business": "https://iptv-org.github.io/iptv/categories/business.m3u",
  170.     "Classic": "https://iptv-org.github.io/iptv/categories/classic.m3u",
  171.     "Comedy": "https://iptv-org.github.io/iptv/categories/comedy.m3u",
  172.     "Cooking": "https://iptv-org.github.io/iptv/categories/cooking.m3u",
  173.     "Culture": "https://iptv-org.github.io/iptv/categories/culture.m3u",
  174.     "Documentary": "https://iptv-org.github.io/iptv/categories/documentary.m3u",
  175.     "Education": "https://iptv-org.github.io/iptv/categories/education.m3u",
  176.     "Entertainment": "https://iptv-org.github.io/iptv/categories/entertainment.m3u",
  177.     "Family": "https://iptv-org.github.io/iptv/categories/family.m3u",
  178.     "General": "https://iptv-org.github.io/iptv/categories/general.m3u",
  179.     "Kids": "https://iptv-org.github.io/iptv/categories/kids.m3u",
  180.     "Legislative": "https://iptv-org.github.io/iptv/categories/legislative.m3u",
  181.     "Lifestyle": "https://iptv-org.github.io/iptv/categories/lifestyle.m3u",
  182.     "Movies": "https://iptv-org.github.io/iptv/categories/movies.m3u",
  183.     "Music": "https://iptv-org.github.io/iptv/categories/music.m3u",
  184.     "News": "https://iptv-org.github.io/iptv/categories/news.m3u",
  185.     "Outdoor": "https://iptv-org.github.io/iptv/categories/outdoor.m3u",
  186.     "Relax": "https://iptv-org.github.io/iptv/categories/relax.m3u",
  187.     "Religious": "https://iptv-org.github.io/iptv/categories/religious.m3u",
  188.     "Science": "https://iptv-org.github.io/iptv/categories/science.m3u",
  189.     "Series": "https://iptv-org.github.io/iptv/categories/series.m3u",
  190.     "Shop": "https://iptv-org.github.io/iptv/categories/shop.m3u",
  191.     "Sports": "https://iptv-org.github.io/iptv/categories/sports.m3u",
  192.     "Travel": "https://iptv-org.github.io/iptv/categories/travel.m3u",
  193.     "Weather": "https://iptv-org.github.io/iptv/categories/weather.m3u",
  194.     "XXX": "https://iptv-org.github.io/iptv/categories/xxx.m3u",
  195.     "Undefined": "https://iptv-org.github.io/iptv/categories/undefined.m3u",
  196.     # Add more categories here
  197. }
  198.  
  199. category_var = tk.StringVar(app)
  200. category_var.set("CLASSIC")  # default value
  201. category_dropdown = ttk.OptionMenu(app, category_var, *category_urls.keys())
  202. category_dropdown.pack(pady=10)
  203.  
  204. # Global variable to store channels' info
  205. channels_info = {}
  206. working_links = {}
  207.  
  208. # Run the application loop
  209. app.mainloop()
  210.  
Add Comment
Please, Sign In to add comment