Najeebsk

IPTV-PLAYER3.0.pyw

May 3rd, 2024
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.21 KB | None | 0 0
  1. import tkinter as tk
  2. import vlc
  3.  
  4. class VideoPlayer:
  5.     def __init__(self, root):
  6.         self.root = root
  7.         self.instance = vlc.Instance('--no-xlib')  # Add this line for Windows support
  8.         self.player = self.instance.media_player_new()
  9.         self.player.set_fullscreen(True)
  10.  
  11.         self.frame = tk.Frame(root, bg="#336699")
  12.         self.frame.pack(side="left", fill="both", expand=True)
  13.  
  14.         self.player_frame = tk.Frame(root, width=600, height=400, bg="#336699")
  15.         self.player_frame.pack(side="right", fill="both", expand=True)
  16.  
  17.         self.status_label = tk.Label(self.frame, text="", fg="green", bg="#336699")
  18.         self.status_label.pack()
  19.  
  20.         self.control_frame = tk.Frame(self.frame, bg="#336699")
  21.         self.control_frame.pack(side="bottom", fill="x")
  22.  
  23.         self.play_button = tk.Button(self.control_frame, text="Play", command=self.play_video, fg="white", bg="#6699CC")
  24.         self.play_button.pack(side="left", padx=5)
  25.  
  26.         self.stop_button = tk.Button(self.control_frame, text="Stop", command=self.stop_video, fg="white", bg="#6699CC")
  27.         self.stop_button.pack(side="left", padx=5)
  28.  
  29.         self.mute_button = tk.Button(self.control_frame, text="Mute", command=self.toggle_mute, fg="white", bg="#6699CC")
  30.         self.mute_button.pack(side="left", padx=5)
  31.  
  32.         self.fullscreen_button = tk.Button(self.control_frame, text="Fullscreen", command=self.toggle_fullscreen, fg="white", bg="#6699CC")
  33.         self.fullscreen_button.pack(side="left", padx=5)
  34.  
  35.         self.seek_slider = tk.Scale(self.control_frame, from_=0, to=100, orient="horizontal", command=self.seek_video, bg="#336699")
  36.         self.seek_slider.pack(side="left", padx=5)
  37.  
  38.         self.lst_frame = tk.Frame(self.frame, bg="#336699")
  39.         self.lst_frame.pack(side="bottom", fill="both", expand=True)
  40.  
  41.         self.search_entry = tk.Entry(self.lst_frame, bg="#FFFFFF")
  42.         self.search_entry.pack(side="top", fill="x")
  43.         self.search_entry.bind('<KeyRelease>', self.search_channels)
  44.  
  45.         self.lst = tk.Listbox(self.lst_frame, width=20, height=20, bg="#FFFFFF")  # Adjust width as needed
  46.         self.lst.pack(side="left", fill="both", expand=True)
  47.  
  48.         self.scrollbar = tk.Scrollbar(self.lst_frame, orient="vertical", command=self.lst.yview)
  49.         self.scrollbar.pack(side="right", fill="y")
  50.  
  51.         self.lst.config(yscrollcommand=self.scrollbar.set)
  52.  
  53.         self.lst.bind("<<ListboxSelect>>", self.play_selected_channel)
  54.         self.read_playlist()
  55.         self.current_channel_index = 0
  56.  
  57.         self.root.bind("<Escape>", self.exit_fullscreen)
  58.  
  59.     def read_playlist(self):
  60.         try:
  61.             with open("playlist.m3u8", "r", encoding="utf-8") as file:
  62.                 self.channels = {}
  63.                 channel_name = None
  64.                 for line in file:
  65.                     if line.startswith("#EXTINF:"):
  66.                         channel_name = line.split(',')[1].strip()
  67.                     elif channel_name:
  68.                         url = line.strip()
  69.                         self.channels[channel_name] = url
  70.                         self.lst.insert(tk.END, channel_name)
  71.                         channel_name = None
  72.         except FileNotFoundError:
  73.             self.status_label.config(text="Playlist not found", fg="red")
  74.  
  75.     def search_channels(self, event):
  76.         query = self.search_entry.get().lower()
  77.         self.lst.delete(0, tk.END)
  78.         for channel_name, url in self.channels.items():
  79.             if query in channel_name.lower():
  80.                 self.lst.insert(tk.END, channel_name)
  81.  
  82.     def play_selected_channel(self, event):
  83.         selection = self.lst.curselection()
  84.         if selection:
  85.             channel_name = self.lst.get(selection[0])
  86.             self.play_channel(channel_name)
  87.  
  88.     def play_video(self):
  89.         self.player.play()
  90.         self.status_label.config(text="Playing", fg="white")
  91.  
  92.     def stop_video(self):
  93.         self.player.stop()
  94.         self.status_label.config(text="Stopped", fg="red")
  95.  
  96.     def toggle_mute(self):
  97.         if self.player.audio_get_mute():
  98.             self.player.audio_set_mute(False)
  99.             self.mute_button.config(text="Mute", bg="#6699CC")
  100.         else:
  101.             self.player.audio_set_mute(True)
  102.             self.mute_button.config(text="Unmute", bg="#FF0000")
  103.  
  104.     def toggle_fullscreen(self):
  105.         if self.player.get_fullscreen():
  106.             self.player.set_fullscreen(False)
  107.             self.fullscreen_button.config(text="Fullscreen")
  108.             self.root.attributes("-fullscreen", False)
  109.             self.frame.pack(side="left", fill="both", expand=True)
  110.             self.player_frame.pack(side="right", fill="both", expand=True)
  111.         else:
  112.             self.player.set_fullscreen(True)
  113.             self.fullscreen_button.config(text="Exit Fullscreen")
  114.             self.root.attributes("-fullscreen", True)
  115.             self.frame.pack_forget()
  116.             self.player_frame.pack(fill="both", expand=True)
  117.  
  118.     def exit_fullscreen(self, event):
  119.         if self.player.get_fullscreen():
  120.             self.toggle_fullscreen()
  121.  
  122.     def play_channel(self, channel_name):
  123.         url = self.channels.get(channel_name)
  124.         if url:
  125.             try:
  126.                 media = self.instance.media_new(url)
  127.                 self.player.set_media(media)
  128.  
  129.                 if self.player_frame.winfo_children():
  130.                     self.player_frame.winfo_children()[0].destroy()
  131.  
  132.                 self.player_frame.update()
  133.                 self.player.set_hwnd(self.player_frame.winfo_id())
  134.                 self.player.play()
  135.  
  136.                 self.status_label.config(text=f"Playing {channel_name}", fg="white")
  137.             except Exception as e:
  138.                 self.status_label.config(text="Failed to play", fg="red")
  139.         else:
  140.             self.status_label.config(text="Channel not found", fg="red")
  141.  
  142.     def seek_video(self, value):
  143.         if self.player.get_length() > 0:
  144.             seek_position = int(value) * self.player.get_length() // 100
  145.             self.player.set_time(seek_position)
  146.  
  147.  
  148. root = tk.Tk()
  149. root.title("NAJEEB IPTV PLAYER")
  150. root.config(bg='#336699')
  151. root.geometry("800x600+300+50")
  152. video_player = VideoPlayer(root)
  153. root.mainloop()
  154.  
Add Comment
Please, Sign In to add comment