Advertisement
Najeebsk

IPTV-URLS-PLAYER.pyw

Jun 22nd, 2024 (edited)
491
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.89 KB | None | 0 0
  1. import tkinter as tk
  2. from tkinter import ttk, messagebox
  3. import vlc
  4. import subprocess
  5.  
  6. # Path to VLC executable
  7. VLC_PATH = r"C:\Program Files\VideoLAN\VLC\vlc.exe"
  8.  
  9. # Path to the URLs file
  10. file_path = "urls.txt"
  11.  
  12. class ChannelPlayer:
  13.     def __init__(self, root):
  14.         self.root = root
  15.         self.root.title("Najeeb Live Videos and IPTV Channels Player")
  16.        
  17.         self.channels = {}
  18.         self.current_instance = None
  19.         self.player = None
  20.         self.media = None
  21.         self.is_dragging_slider = False
  22.         self.is_fullscreen = False
  23.  
  24.         self.create_widgets()
  25.         self.load_channels(file_path)
  26.    
  27.     def load_channels(self, file_path):
  28.         self.channels.clear()
  29.         try:
  30.             with open(file_path, 'r') as file:
  31.                 for line in file:
  32.                     parts = line.strip().split(maxsplit=1)
  33.                     if len(parts) == 2:
  34.                         self.channels[parts[0]] = parts[1]
  35.             self.update_channel_dropdown()
  36.         except FileNotFoundError:
  37.             messagebox.showerror("Error", f"File not found: {file_path}")
  38.    
  39.     def update_channel_dropdown(self):
  40.         self.channel_dropdown['values'] = list(self.channels.keys())
  41.    
  42.     def create_widgets(self):
  43.         style = ttk.Style()
  44.         style.configure('TButton', font=('Helvetica', 10))
  45.         style.configure('TCombobox', font=('Helvetica', 10))
  46.        
  47.         # Search field for channel title
  48.         self.search_label = ttk.Label(self.root, text="Search Channel Title:")
  49.         self.search_label.grid(row=0, column=0, padx=5, pady=5, sticky="w")
  50.  
  51.         self.search_var = tk.StringVar()
  52.         self.search_entry = ttk.Entry(self.root, textvariable=self.search_var)
  53.         self.search_entry.grid(row=0, column=1, columnspan=2, padx=5, pady=5, sticky="ew")
  54.         self.search_entry.bind("<KeyRelease>", self.filter_channels)
  55.  
  56.         # Channel selection
  57.         self.channel_var = tk.StringVar()
  58.         self.channel_dropdown = ttk.Combobox(self.root, textvariable=self.channel_var)
  59.         self.channel_dropdown.grid(row=1, column=0, columnspan=2, padx=5, pady=5, sticky="ew")
  60.        
  61.         # Preview button
  62.         self.preview_button = ttk.Button(self.root, text="Preview", command=self.preview_channel)
  63.         self.preview_button.grid(row=1, column=2, padx=5, pady=5, sticky="ew")
  64.  
  65.         # Stop preview button
  66.         self.stop_preview_button = ttk.Button(self.root, text="Stop Preview", command=self.stop_preview)
  67.         self.stop_preview_button.grid(row=1, column=3, padx=5, pady=5, sticky="ew")
  68.  
  69.         # Play button
  70.         self.play_button = ttk.Button(self.root, text="Play", command=self.play_channel)
  71.         self.play_button.grid(row=1, column=4, padx=5, pady=5, sticky="ew")
  72.  
  73.         # Volume control
  74.         self.volume_slider = ttk.Scale(self.root, from_=0, to=100, orient=tk.HORIZONTAL, command=self.set_volume)
  75.         self.volume_slider.set(50)  # Set initial volume to 50%
  76.         self.volume_slider.grid(row=1, column=5, padx=5, pady=5, sticky="ew")
  77.  
  78.         # Full screen button
  79.         self.fullscreen_button = ttk.Button(self.root, text="Full Screen", command=self.toggle_fullscreen)
  80.         self.fullscreen_button.grid(row=1, column=6, padx=5, pady=5, sticky="ew")
  81.  
  82.         # VLC video frame
  83.         self.video_frame = tk.Frame(self.root, bg="black", height=300)
  84.         self.video_frame.grid(row=2, column=0, columnspan=7, padx=5, pady=5, sticky="nsew")
  85.  
  86.         # Video control slider
  87.         self.video_slider = ttk.Scale(self.root, from_=0, to=1000, orient=tk.HORIZONTAL)
  88.         self.video_slider.grid(row=3, column=0, columnspan=7, padx=5, pady=5, sticky="ew")
  89.         self.video_slider.bind("<ButtonPress-1>", self.slider_pressed)
  90.         self.video_slider.bind("<ButtonRelease-1>", self.slider_released)
  91.  
  92.         self.root.grid_rowconfigure(2, weight=1)
  93.         self.root.grid_rowconfigure(3, weight=0)
  94.         self.root.grid_columnconfigure(0, weight=1)
  95.         self.root.grid_columnconfigure(1, weight=1)
  96.         self.root.grid_columnconfigure(2, weight=1)
  97.         self.root.grid_columnconfigure(3, weight=1)
  98.         self.root.grid_columnconfigure(4, weight=1)
  99.         self.root.grid_columnconfigure(5, weight=1)
  100.         self.root.grid_columnconfigure(6, weight=1)
  101.         self.root.protocol("WM_DELETE_WINDOW", self.on_closing)
  102.  
  103.     def filter_channels(self, event):
  104.         search_term = self.search_var.get().lower()
  105.         filtered_channels = [channel for channel in self.channels.keys() if search_term in channel.lower()]
  106.         self.channel_dropdown['values'] = filtered_channels
  107.  
  108.     def preview_channel(self):
  109.         self.stop_preview()
  110.         channel = self.channel_var.get()
  111.         if channel and channel in self.channels:
  112.             url = self.channels[channel]
  113.             self.current_instance = vlc.Instance()
  114.             self.player = self.current_instance.media_player_new()
  115.             self.player.set_hwnd(self.video_frame.winfo_id())
  116.             self.media = self.current_instance.media_new(url)
  117.             self.player.set_media(self.media)
  118.             self.player.play()
  119.             self.update_video_slider()
  120.  
  121.     def stop_preview(self):
  122.         if self.player:
  123.             self.player.stop()
  124.             self.player.release()
  125.             self.player = None
  126.         if self.current_instance:
  127.             self.current_instance.release()
  128.             self.current_instance = None
  129.  
  130.     def play_channel(self):
  131.         self.stop_preview()
  132.         channel = self.channel_var.get()
  133.         if channel and channel in self.channels:
  134.             url = self.channels[channel]
  135.             subprocess.Popen([VLC_PATH, url])
  136.  
  137.     def set_volume(self, value):
  138.         if self.player:
  139.             self.player.audio_set_volume(int(float(value)))
  140.  
  141.     def slider_pressed(self, event):
  142.         self.is_dragging_slider = True
  143.  
  144.     def slider_released(self, event):
  145.         self.is_dragging_slider = False
  146.         self.set_position(self.video_slider.get())
  147.  
  148.     def set_position(self, value):
  149.         if self.player:
  150.             self.player.set_position(float(value) / 1000.0)
  151.  
  152.     def update_video_slider(self):
  153.         if self.player and not self.is_dragging_slider:
  154.             length = self.player.get_length()
  155.             if length > 0:
  156.                 current_time = self.player.get_time()
  157.                 position = int(current_time / length * 1000)
  158.                 self.video_slider.set(position)
  159.         self.root.after(1000, self.update_video_slider)
  160.  
  161.     def toggle_fullscreen(self):
  162.         self.is_fullscreen = not self.is_fullscreen
  163.         self.root.attributes("-fullscreen", self.is_fullscreen)
  164.         if not self.is_fullscreen:
  165.             self.root.geometry("800x600")
  166.  
  167.     def on_closing(self):
  168.         self.stop_preview()
  169.         self.root.destroy()
  170.  
  171. if __name__ == "__main__":
  172.     root = tk.Tk()
  173.     app = ChannelPlayer(root)
  174.     root.mainloop()
  175.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement