Najeebsk

IPTV-M3U.pyw

Mar 30th, 2025
13
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.53 KB | None | 0 0
  1. VERSION = "4.7.1"
  2. import requests
  3. import tkinter as tk
  4. from tkinter import messagebox, filedialog
  5. import subprocess
  6. import os
  7. import re
  8. #================ADD-IMAGE-ICON=================
  9. import sys
  10.  
  11. def resource_path(relative_path):
  12.     """ Get the absolute path to the resource, works for PyInstaller. """
  13.     if getattr(sys, '_MEIPASS', False):
  14.         return os.path.join(sys._MEIPASS, relative_path)
  15.     return os.path.join(os.path.abspath("."), relative_path)
  16.  
  17. # Use this function to load files:
  18. splash_image = resource_path("splash-1.png")
  19. icon_path = resource_path("IPTV.ico")
  20. # ==================ADD-SPLASH==================
  21. import tkinter as tk
  22. from PIL import Image, ImageTk
  23. import time
  24.  
  25.  
  26. def show_splash(image_path):
  27.     # Create splash screen window
  28.     splash = tk.Tk()
  29.     splash.overrideredirect(True)  # Remove window border
  30.    
  31.     # Load the image
  32.     image = Image.open(image_path)
  33.     img = ImageTk.PhotoImage(image)
  34.  
  35.     # Get image dimensions
  36.     img_width, img_height = image.size
  37.  
  38.     # Calculate position to center the splash screen
  39.     screen_width = splash.winfo_screenwidth()
  40.     screen_height = splash.winfo_screenheight()
  41.     x = (screen_width - img_width) // 2
  42.     y = (screen_height - img_height) // 2
  43.     splash.geometry(f"{img_width}x{img_height}+{x}+{y}")
  44.  
  45.     # Set transparent background
  46.     splash.config(bg="white")
  47.     splash.attributes("-transparentcolor", "white")  # Make white color transparent
  48.  
  49.     # Display the image
  50.     label = tk.Label(splash, image=img, bg="white")
  51.     label.pack()
  52.  
  53.     # Display the splash screen for 5 seconds
  54.     splash.after(5000, splash.destroy)
  55.     splash.mainloop()
  56.  
  57.  
  58. # Call splash screen function
  59. show_splash(splash_image) # Replace with your image file path 1 To 6
  60. # ==================ADD-SPLASH==================
  61. def fetch_m3u():
  62.     url = entry_url.get()
  63.     if not url:
  64.         messagebox.showerror("Error", "Please enter a valid URL")
  65.         return
  66.    
  67.     try:
  68.         response = requests.get(url)
  69.         response.raise_for_status()
  70.         content = response.text
  71.        
  72.         parse_m3u(content)
  73.     except requests.exceptions.RequestException as e:
  74.         messagebox.showerror("Error", f"Failed to fetch M3U file: {e}")
  75.  
  76. def save_m3u():
  77.     file_path = filedialog.asksaveasfilename(defaultextension=".m3u", filetypes=[("M3U files", "*.m3u")])
  78.     if file_path:
  79.         with open(file_path, "w", encoding="utf-8") as file:
  80.             for title, url in stream_list:
  81.                 file.write(f"#EXTINF:-1,{title}\n{url}\n")
  82.         messagebox.showinfo("Success", f"M3U file saved: {file_path}")
  83.  
  84. def parse_m3u(content):
  85.     global stream_list, displayed_list
  86.     stream_list.clear()
  87.     displayed_list.clear()
  88.     listbox.delete(0, tk.END)
  89.    
  90.     lines = content.splitlines()
  91.     title = "Unknown"
  92.    
  93.     for line in lines:
  94.         if line.startswith("#EXTINF"):
  95.             match = re.search(r'#EXTINF:-1,([^\n]+)', line)
  96.             if match:
  97.                 title = match.group(1)
  98.         elif line.startswith("http"):
  99.             stream_list.append((title, line))
  100.             displayed_list.append((title, line))
  101.             listbox.insert(tk.END, f"{title} - {line}")
  102.             title = "Unknown"  # Reset title for next entry
  103.  
  104. def play_selected():
  105.     selected = listbox.curselection()
  106.     if not selected:
  107.         messagebox.showwarning("Warning", "Please select a stream to play")
  108.         return
  109.    
  110.     _, url = displayed_list[selected[0]]
  111.     vlc_path = r"C:\\Program Files\\VideoLAN\\VLC\\vlc.exe"
  112.     try:
  113.         subprocess.run([vlc_path, url], check=True)
  114.     except FileNotFoundError:
  115.         messagebox.showerror("Error", "VLC Player not found. Ensure VLC is installed and added to PATH.")
  116.  
  117. def clear_all():
  118.     entry_url.delete(0, tk.END)
  119.     listbox.delete(0, tk.END)
  120.     stream_list.clear()
  121.     displayed_list.clear()
  122.  
  123. def search_streams():
  124.     query = search_entry.get().lower()
  125.     listbox.delete(0, tk.END)
  126.     displayed_list.clear()
  127.     for title, url in stream_list:
  128.         if query in title.lower() or query in url.lower():
  129.             displayed_list.append((title, url))
  130.             listbox.insert(tk.END, f"{title} - {url}")
  131.  
  132. # UI Setup
  133. root = tk.Tk()
  134. root.title("Najeeb M3U Scraper & VLC Player")
  135. root.geometry("900x600")
  136. root.configure(bg="#2c3e50")
  137. root.iconbitmap(icon_path)
  138.  
  139. stream_list = []
  140. displayed_list = []
  141.  
  142. input_frame = tk.Frame(root, bg="#2c3e50")
  143. input_frame.pack(pady=5)
  144.  
  145. tk.Label(input_frame, text="Enter M3U URL:", bg="#2c3e50", fg="white", font=("Arial", 12, "bold")).pack(side=tk.LEFT, padx=5)
  146. entry_url = tk.Entry(input_frame, width=60, font=("Arial", 12))
  147. entry_url.pack(side=tk.LEFT, padx=5)
  148.  
  149. button_frame = tk.Frame(root, bg="#2c3e50")
  150. button_frame.pack(pady=5)
  151.  
  152. tk.Button(button_frame, text="Fetch M3U", command=fetch_m3u, bg="#3498db", fg="white", font=("Arial", 12, "bold"), width=12).pack(side=tk.LEFT, padx=5)
  153. tk.Button(button_frame, text="Save M3U", command=save_m3u, bg="#27ae60", fg="white", font=("Arial", 12, "bold"), width=12).pack(side=tk.LEFT, padx=5)
  154. tk.Button(button_frame, text="Play in VLC", command=play_selected, bg="#e74c3c", fg="white", font=("Arial", 12, "bold"), width=12).pack(side=tk.LEFT, padx=5)
  155. tk.Button(button_frame, text="Clear All", command=clear_all, bg="#f1c40f", fg="black", font=("Arial", 12, "bold"), width=12).pack(side=tk.LEFT, padx=5)
  156.  
  157. search_frame = tk.Frame(root, bg="#2c3e50")
  158. search_frame.pack(pady=5)
  159.  
  160. tk.Label(search_frame, text="Search:", bg="#2c3e50", fg="white", font=("Arial", 12, "bold")).pack(side=tk.LEFT, padx=5)
  161. search_entry = tk.Entry(search_frame, width=40, font=("Arial", 12))
  162. search_entry.pack(side=tk.LEFT, padx=5)
  163. tk.Button(search_frame, text="Search", command=search_streams, bg="#8e44ad", fg="white", font=("Arial", 12, "bold"), width=12).pack(side=tk.LEFT, padx=5)
  164.  
  165. frame = tk.Frame(root)
  166. frame.pack(pady=5, fill=tk.BOTH, expand=True)
  167.  
  168. scrollbar = tk.Scrollbar(frame, orient=tk.VERTICAL)
  169. listbox = tk.Listbox(frame, width=100, height=25, yscrollcommand=scrollbar.set, font=("Arial", 10))
  170. scrollbar.config(command=listbox.yview)
  171. scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
  172. listbox.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
  173.  
  174. root.mainloop()
  175. # pyinstaller --onefile --windowed --icon=IPTV.ico --add-data "splash-1.png;." --add-data "IPTV.ico;." IPTV-M3U.pyw
  176. # pyinstaller --onefile --windowed --icon=IPTV.ico --add-data "splash-1.png:." --add-data "IPTV.ico:." IPTV-M3U.pyw
  177. # pyinstaller --onefile --windowed --noconsole --icon=IPTV.ico --add-data "splash-1.png;." --add-data "IPTV.ico;." IPTV-M3U.pyw
Add Comment
Please, Sign In to add comment