Najeebsk

IPTV-PLAYER2.0.pyw

May 3rd, 2024
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.17 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.lst = tk.Listbox(self.lst_frame, width=20, height=20, bg="#FFFFFF")  # Adjust width as needed
  42.         self.lst.pack(side="left", fill="both", expand=True)
  43.  
  44.         self.scrollbar = tk.Scrollbar(self.lst_frame, orient="vertical", command=self.lst.yview)
  45.         self.scrollbar.pack(side="right", fill="y")
  46.  
  47.         self.lst.config(yscrollcommand=self.scrollbar.set)
  48.  
  49.         self.lst.bind("<<ListboxSelect>>", self.play_selected_channel)
  50.         self.read_playlist()
  51.         self.current_channel_index = 0
  52.  
  53.         self.root.bind("<Escape>", self.exit_fullscreen)
  54.  
  55.     def read_playlist(self):
  56.         try:
  57.             with open("playlist.m3u8", "r", encoding="utf-8") as file:
  58.                 lines = file.readlines()
  59.                 for line in lines:
  60.                     if line.startswith("#EXTINF:"):
  61.                         parts = line.split('group-title="')
  62.                         if len(parts) > 1:
  63.                             channel_name = parts[1].split('"')[0]
  64.                             self.lst.insert(tk.END, channel_name)
  65.         except FileNotFoundError:
  66.             self.status_label.config(text="Playlist not found", fg="red")
  67.  
  68.     def play_selected_channel(self, event):
  69.         selection = self.lst.curselection()
  70.         if selection:
  71.             channel_index = selection[0]
  72.             self.play_channel(channel_index)
  73.  
  74.     def play_video(self):
  75.         self.player.play()
  76.         self.status_label.config(text="Playing", fg="white")
  77.  
  78.     def stop_video(self):
  79.         self.player.stop()
  80.         self.status_label.config(text="Stopped", fg="red")
  81.  
  82.     def toggle_mute(self):
  83.         if self.player.audio_get_mute():
  84.             self.player.audio_set_mute(False)
  85.             self.mute_button.config(text="Mute", bg="#6699CC")
  86.         else:
  87.             self.player.audio_set_mute(True)
  88.             self.mute_button.config(text="Unmute", bg="#FF0000")
  89.  
  90.     def toggle_fullscreen(self):
  91.         if self.player.get_fullscreen():
  92.             self.player.set_fullscreen(False)
  93.             self.fullscreen_button.config(text="Fullscreen")
  94.             self.root.attributes("-fullscreen", False)
  95.             self.frame.pack(side="left", fill="both", expand=True)
  96.             self.player_frame.pack(side="right", fill="both", expand=True)
  97.             self.lst_frame.pack(side="bottom", fill="both", expand=True)
  98.         else:
  99.             self.player.set_fullscreen(True)
  100.             self.fullscreen_button.config(text="Exit Fullscreen")
  101.             self.root.attributes("-fullscreen", True)
  102.             self.frame.pack_forget()
  103.             self.player_frame.pack(fill="both", expand=True)
  104.             self.lst_frame.pack_forget()
  105.  
  106.     def exit_fullscreen(self, event):
  107.         if self.player.get_fullscreen():
  108.             self.toggle_fullscreen()
  109.  
  110.     def play_channel(self, channel_index):
  111.         try:
  112.             with open("playlist.m3u8", "r", encoding="utf-8") as file:
  113.                 lines = file.readlines()
  114.                 for i, line in enumerate(lines):
  115.                     if line.startswith("#EXTINF:"):
  116.                         if i // 2 == channel_index:
  117.                             stream_url = lines[i + 1].strip()
  118.                             media = self.instance.media_new(stream_url)
  119.                             self.player.set_media(media)
  120.  
  121.                             if self.player_frame.winfo_children():
  122.                                 self.player_frame.winfo_children()[0].destroy()
  123.  
  124.                             self.player_frame.update()
  125.                             self.player.set_hwnd(self.player_frame.winfo_id())
  126.                             self.player.play()
  127.  
  128.                             self.status_label.config(text="Playing", fg="white")
  129.                             self.current_channel_index = channel_index
  130.                             return
  131.  
  132.             self.status_label.config(text="Channel not found", fg="red")
  133.  
  134.         except Exception as e:
  135.             self.status_label.config(text="Failed to play", fg="red")
  136.  
  137.     def seek_video(self, value):
  138.         if self.player.get_length() > 0:
  139.             seek_position = int(value) * self.player.get_length() // 100
  140.             self.player.set_time(seek_position)
  141.  
  142.  
  143. root = tk.Tk()
  144. root.title("NAJEEB IPTV PLAYER")
  145. root.config(bg='#336699')
  146. root.geometry("800x600+300+50")
  147. video_player = VideoPlayer(root)
  148. root.mainloop()
  149.  
Add Comment
Please, Sign In to add comment