Najeebsk

IPTV-PLAYER2.py

Mar 22nd, 2024 (edited)
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.90 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.seek_slider = tk.Scale(self.control_frame, from_=0, to=100, orient="horizontal", command=self.seek_video, bg="#336699")
  33.         self.seek_slider.pack(side="left", padx=5)
  34.  
  35.         self.lst_frame = tk.Frame(self.frame, bg="#336699")
  36.         self.lst_frame.pack(side="bottom", fill="both", expand=True)
  37.  
  38.         self.lst = tk.Listbox(self.lst_frame, width=20, height=20, bg="#FFFFFF")  # Adjust width as needed
  39.         self.lst.pack(side="left", fill="both", expand=True)
  40.  
  41.         self.scrollbar = tk.Scrollbar(self.lst_frame, orient="vertical", command=self.lst.yview)
  42.         self.scrollbar.pack(side="right", fill="y")
  43.  
  44.         self.lst.config(yscrollcommand=self.scrollbar.set)
  45.  
  46.         self.lst.bind("<<ListboxSelect>>", self.play_selected_channel)
  47.         self.read_playlist()
  48.         self.current_channel_index = 0
  49.  
  50.     def read_playlist(self):
  51.         try:
  52.             with open("playlist.m3u8", "r") as file:
  53.                 lines = file.readlines()
  54.                 for line in lines:
  55.                     if line.startswith("#EXTINF:"):
  56.                         channel_name = line.split('group-title="')[1].split('"')[0]
  57.                         self.lst.insert(tk.END, channel_name)
  58.         except FileNotFoundError:
  59.             self.status_label.config(text="Playlist not found", fg="red")
  60.  
  61.     def play_selected_channel(self, event):
  62.         selection = self.lst.curselection()
  63.         if selection:
  64.             channel_index = selection[0]
  65.             self.play_channel(channel_index)
  66.  
  67.     def play_video(self):
  68.         self.player.play()
  69.         self.status_label.config(text="Playing", fg="white")
  70.  
  71.     def stop_video(self):
  72.         self.player.stop()
  73.         self.status_label.config(text="Stopped", fg="red")
  74.  
  75.     def toggle_mute(self):
  76.         if self.player.audio_get_mute():
  77.             self.player.audio_set_mute(False)
  78.             self.mute_button.config(text="Mute", bg="#6699CC")
  79.         else:
  80.             self.player.audio_set_mute(True)
  81.             self.mute_button.config(text="Unmute", bg="#FF0000")
  82.  
  83.     def play_channel(self, channel_index):
  84.         try:
  85.             with open("playlist.m3u8", "r") as file:
  86.                 lines = file.readlines()
  87.                 for i, line in enumerate(lines):
  88.                     if line.startswith("#EXTINF:"):
  89.                         if i // 2 == channel_index:
  90.                             stream_url = lines[i + 1].strip()
  91.                             media = self.instance.media_new(stream_url)
  92.                             self.player.set_media(media)
  93.  
  94.                             if self.player_frame.winfo_children():
  95.                                 self.player_frame.winfo_children()[0].destroy()
  96.  
  97.                             self.player_frame.update()
  98.                             self.player.set_hwnd(self.player_frame.winfo_id())
  99.                             self.player.play()
  100.  
  101.                             self.status_label.config(text="Playing", fg="white")
  102.                             self.current_channel_index = channel_index
  103.                             return
  104.  
  105.             self.status_label.config(text="Channel not found", fg="red")
  106.  
  107.         except Exception as e:
  108.             self.status_label.config(text="Failed to play", fg="red")
  109.  
  110.     def seek_video(self, value):
  111.         if self.player.get_length() > 0:
  112.             seek_position = int(value) * self.player.get_length() // 100
  113.             self.player.set_time(seek_position)
  114.  
  115.  
  116. root = tk.Tk()
  117. root.title("NAJEEB IPTV PLAYER")
  118. root.config(bg='#336699')
  119. root.geometry("800x600+300+50")
  120. video_player = VideoPlayer(root)
  121. root.mainloop()
  122.  
Add Comment
Please, Sign In to add comment