Najeebsk

IPTVPLAYER2.pyw

May 2nd, 2024
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.02 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", encoding="utf-8") as file:
  53.                 lines = file.readlines()
  54.                 for line in lines:
  55.                     if line.startswith("#EXTINF:"):
  56.                         parts = line.split('group-title="')
  57.                         if len(parts) > 1:
  58.                             channel_name = parts[1].split('"')[0]
  59.                             self.lst.insert(tk.END, channel_name)
  60.         except FileNotFoundError:
  61.             self.status_label.config(text="Playlist not found", fg="red")
  62.  
  63.     def play_selected_channel(self, event):
  64.         selection = self.lst.curselection()
  65.         if selection:
  66.             channel_index = selection[0]
  67.             self.play_channel(channel_index)
  68.  
  69.     def play_video(self):
  70.         self.player.play()
  71.         self.status_label.config(text="Playing", fg="white")
  72.  
  73.     def stop_video(self):
  74.         self.player.stop()
  75.         self.status_label.config(text="Stopped", fg="red")
  76.  
  77.     def toggle_mute(self):
  78.         if self.player.audio_get_mute():
  79.             self.player.audio_set_mute(False)
  80.             self.mute_button.config(text="Mute", bg="#6699CC")
  81.         else:
  82.             self.player.audio_set_mute(True)
  83.             self.mute_button.config(text="Unmute", bg="#FF0000")
  84.  
  85.     def play_channel(self, channel_index):
  86.         try:
  87.             with open("playlist.m3u8", "r", encoding="utf-8") as file:
  88.                 lines = file.readlines()
  89.                 for i, line in enumerate(lines):
  90.                     if line.startswith("#EXTINF:"):
  91.                         if i // 2 == channel_index:
  92.                             stream_url = lines[i + 1].strip()
  93.                             media = self.instance.media_new(stream_url)
  94.                             self.player.set_media(media)
  95.  
  96.                             if self.player_frame.winfo_children():
  97.                                 self.player_frame.winfo_children()[0].destroy()
  98.  
  99.                             self.player_frame.update()
  100.                             self.player.set_hwnd(self.player_frame.winfo_id())
  101.                             self.player.play()
  102.  
  103.                             self.status_label.config(text="Playing", fg="white")
  104.                             self.current_channel_index = channel_index
  105.                             return
  106.  
  107.             self.status_label.config(text="Channel not found", fg="red")
  108.  
  109.         except Exception as e:
  110.             self.status_label.config(text="Failed to play", fg="red")
  111.  
  112.     def seek_video(self, value):
  113.         if self.player.get_length() > 0:
  114.             seek_position = int(value) * self.player.get_length() // 100
  115.             self.player.set_time(seek_position)
  116.  
  117.  
  118. root = tk.Tk()
  119. root.title("NAJEEB IPTV PLAYER")
  120. root.config(bg='#336699')
  121. root.geometry("800x600+300+50")
  122. video_player = VideoPlayer(root)
  123. root.mainloop()
  124.  
Add Comment
Please, Sign In to add comment