Najeebsk

IPTV-PLAYER.py

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