Najeebsk

IPTV-CHECK-M3U-MAC.py

Mar 12th, 2024 (edited)
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.46 KB | None | 0 0
  1. import tkinter as tk
  2. import requests
  3. import subprocess
  4.  
  5. def search_channels():
  6.     url = url_entry.get()
  7.     mac_address = mac_entry.get()
  8.  
  9.     # Construct the request URL with the provided MAC address
  10.     request_url = f"{url}?mac={mac_address}"
  11.  
  12.     try:
  13.         # Send a GET request to the constructed URL
  14.         response = requests.get(request_url)
  15.        
  16.         # Check if the request was successful (status code 200)
  17.         if response.status_code == 200:
  18.             # Parse M3U data
  19.             m3u_data = response.text.split('\n')
  20.            
  21.             # Clear any previous results
  22.             result_text.delete(0, tk.END)
  23.            
  24.             # Store channels' names and URLs
  25.             global channels_info
  26.             channels_info = {}
  27.            
  28.             # Extract channel names and URLs
  29.             channel_name = None
  30.             for line in m3u_data:
  31.                 if line.startswith('#EXTINF:'):
  32.                     channel_name = line.split(',')[-1]
  33.                 elif line.startswith('http') and channel_name:
  34.                     channels_info[channel_name] = line.strip()
  35.                     # Insert channel name into the listbox
  36.                     result_text.insert(tk.END, channel_name)
  37.                     channel_name = None
  38.         else:
  39.             result_text.insert(tk.END, f"Error: Failed to fetch channel data. Status Code: {response.status_code}")
  40.     except requests.RequestException as e:
  41.         result_text.insert(tk.END, f"Error: {str(e)}")
  42.  
  43. def play_selected_channel(event):
  44.     try:
  45.         # Get the selected channel name
  46.         selected_channel = result_text.get(tk.ACTIVE)
  47.        
  48.         # Open the corresponding URL in VLC
  49.         subprocess.Popen([r"C:\Program Files\VideoLAN\VLC\vlc.exe", channels_info[selected_channel]])
  50.     except (tk.TclError, KeyError):
  51.         pass  # Ignore if no channel is selected or channel info is missing
  52.  
  53. def check_links():
  54.     global working_links
  55.     working_links = {}
  56.     for channel_name, url in channels_info.items():
  57.         try:
  58.             response = requests.get(url)
  59.             if response.status_code == 200:
  60.                 working_links[channel_name] = url
  61.         except requests.RequestException:
  62.             pass
  63.  
  64.     # Display working links in the result_text widget
  65.     result_text.delete(0, tk.END)
  66.     for channel_name, url in working_links.items():
  67.         result_text.insert(tk.END, f"{channel_name}: {url}\n")
  68.  
  69. def save_working_links():
  70.     with open("working_channels.m3u", "w", encoding="utf-8") as f:
  71.         for channel_name, url in working_links.items():
  72.             f.write(f"#EXTINF:-1,{channel_name}\n{url}\n")
  73.  
  74. # Create the main application window
  75. app = tk.Tk()
  76. app.title("Najeeb IPTV Channel Search M3u and Mac")
  77. app.geometry("800x600")
  78. app.configure(bg="#336699")
  79.  
  80. # Add labels, entry fields, buttons, etc.
  81. url_frame = tk.Frame(app, bg="#336699")
  82. url_frame.pack(pady=10)
  83.  
  84. url_label = tk.Label(url_frame, text="Enter URL:", bg="#336699", fg="white")
  85. url_label.pack(side=tk.LEFT, padx=5)
  86.  
  87. url_entry = tk.Entry(url_frame, width=50)  # Adjust width here
  88. url_entry.pack(side=tk.LEFT, padx=5)
  89.  
  90. mac_label = tk.Label(url_frame, text="Enter MAC Address:", bg="#336699", fg="white")
  91. mac_label.pack(side=tk.LEFT, padx=5)
  92.  
  93. mac_entry = tk.Entry(url_frame)
  94. mac_entry.pack(side=tk.LEFT, padx=5)
  95.  
  96. search_button = tk.Button(url_frame, text="Search", command=search_channels, bg="#FFA500", fg="white")
  97. search_button.pack(side=tk.LEFT, padx=5)
  98.  
  99. result_label = tk.Label(app, text="Channels:", bg="#336699", fg="white")
  100. result_label.pack()
  101.  
  102. # Add scrollbar to the listbox
  103. scrollbar = tk.Scrollbar(app, orient=tk.VERTICAL)
  104. scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
  105.  
  106. result_text = tk.Listbox(app, height=30, width=130, yscrollcommand=scrollbar.set)
  107. result_text.pack()
  108.  
  109. # Configure scrollbar
  110. scrollbar.config(command=result_text.yview)
  111.  
  112. # Bind double click event to play_selected_channel function
  113. result_text.bind("<Double-1>", play_selected_channel)
  114.  
  115. # Add button to check links
  116. check_button = tk.Button(app, text="Check Links", command=check_links, bg="#008000", fg="white")
  117. check_button.pack(side=tk.RIGHT, padx=5)
  118.  
  119. # Add button to save working links
  120. save_button = tk.Button(app, text="Save Working Links", command=save_working_links, bg="#FF0000", fg="white")
  121. save_button.pack(side=tk.LEFT, padx=5)
  122.  
  123. # Global variable to store channels' info
  124. channels_info = {}
  125. working_links = {}
  126.  
  127. # Run the application loop
  128. app.mainloop()
  129.  
Add Comment
Please, Sign In to add comment