Advertisement
Najeebsk

VIDEO-RAR-PLAYER.pyw

May 25th, 2024 (edited)
815
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. from tkinter import ttk, filedialog
  3. import vlc
  4. import rarfile
  5. import tempfile
  6. import shutil
  7.  
  8. class VideoPlayer:
  9.     def __init__(self, root):
  10.         self.root = root
  11.         self.instance = vlc.Instance('--no-xlib')  
  12.         self.player = self.instance.media_player_new()
  13.  
  14.         self.main_frame = tk.Frame(root, bg="#4a4a4a")
  15.         self.main_frame.pack(fill="both", expand=True)
  16.  
  17.         # Add title label with custom font and color
  18.         #self.title_label = tk.Label(self.main_frame, text="NAJEEB VIDEO PLAYER", font=("Arial", 24, "bold"), fg="blue")
  19.         #self.title_label.pack(pady=5)
  20.        
  21.         # Add password entry
  22.         tk.Label(root, text="Password:", bg="#4a4a4a", fg="white").place(x=10, y=10)
  23.         self.password_entry = tk.Entry(root, show='*', bg="#4a4a4a", fg="white")
  24.         self.password_entry.place(x=80, y=10)
  25.  
  26.         # Add file browse button
  27.         tk.Label(root, text="Select RAR File:", bg="#4a4a4a", fg="white").place(x=220, y=10)
  28.         self.rar_entry = tk.Entry(root, bg="#4a4a4a", fg="white")
  29.         self.rar_entry.place(x=320, y=10)
  30.         self.browse_rar_button = tk.Button(root, text="Browse", command=self.browse_file, bg="#FFA500", fg="white")
  31.         self.browse_rar_button.place(x=460, y=8)
  32.  
  33.         # Dropdown list for videos
  34.         tk.Label(root, text="Select Video from RAR:", bg="#4a4a4a", fg="white").place(x=530, y=10)
  35.         self.video_dropdown = ttk.Combobox(root, state="readonly")
  36.         self.video_dropdown.place(x=670, y=10, width=280)
  37.         self.video_dropdown.bind("<<ComboboxSelected>>", lambda e: self.show_video())
  38.  
  39.         self.button_frame = tk.Frame(self.main_frame, bg="#4a4a4a")
  40.         self.button_frame.pack(side="bottom", fill="x")
  41.  
  42.         self.play_button = tk.Button(self.button_frame, text="Play", command=self.play_video, bg="#008000", fg="white")
  43.         self.play_button.pack(side="left", padx=5, pady=5)
  44.  
  45.         self.stop_button = tk.Button(self.button_frame, text="Stop", command=self.stop_video, bg="#FF0000", fg="white")
  46.         self.stop_button.pack(side="left", padx=5, pady=5)
  47.  
  48.         self.prev_button = tk.Button(self.button_frame, text="Prev", command=self.prev_video, bg="#5a5a5a", fg="white")
  49.         self.prev_button.pack(side="left", padx=5, pady=5)
  50.  
  51.         self.next_button = tk.Button(self.button_frame, text="Next", command=self.next_video, bg="#5a5a5a", fg="white")
  52.         self.next_button.pack(side="left", padx=5, pady=5)
  53.  
  54.         self.player_position = tk.Scale(self.button_frame, from_=0, to=100, orient="horizontal", command=self.set_position, length=760, bg="#4a4a4a", fg="white")
  55.         self.player_position.pack(side="left", fill="x", padx=5, pady=5)
  56.  
  57.         self.current_video_label = tk.Label(root, text="No video selected", bg="#4a4a4a", fg="white")
  58.         self.current_video_label.pack(pady=5)
  59.  
  60.         self.player_frame = tk.Frame(self.main_frame, bg="#4a4a4a")
  61.         self.player_frame.pack(side="right", fill="both", expand=True)
  62.  
  63.         self.video_list = []
  64.  
  65.     def browse_file(self):
  66.         file_path = filedialog.askopenfilename(filetypes=[("RAR files", "*.rar")])
  67.         if file_path:
  68.             self.rar_entry.delete(0, tk.END)
  69.             self.rar_entry.insert(0, file_path)
  70.             self.load_videos_from_rar(file_path)
  71.  
  72.     def load_videos_from_rar(self, rar_path):
  73.         password = self.password_entry.get()
  74.         try:
  75.             with rarfile.RarFile(rar_path) as rf:
  76.                 if password:
  77.                     rf.setpassword(password)
  78.                 self.video_list = [f.filename for f in rf.infolist() if f.filename.endswith(('.mp4', '.mkv', '.avi'))]
  79.                 self.video_list.sort()
  80.                 self.video_dropdown['values'] = self.video_list
  81.                 self.current_rar_path = rar_path
  82.                 self.current_password = password
  83.                 self.current_video_label.config(text="Videos loaded. Select a video.")
  84.         except rarfile.BadRarFile:
  85.             self.current_video_label.config(text="Failed to open RAR file.")
  86.         except rarfile.RarWrongPassword:
  87.             self.current_video_label.config(text="Incorrect password.")
  88.  
  89.     def play_video(self):
  90.         if self.player.get_state() == vlc.State.Ended:
  91.             self.player.stop()
  92.         self.player.play()
  93.         self.current_video_label.config(text="Video playing")
  94.  
  95.     def show_video(self):
  96.         video_name = self.video_dropdown.get()
  97.         if video_name:
  98.             with rarfile.RarFile(self.current_rar_path) as rf:
  99.                 if self.current_password:
  100.                     rf.setpassword(self.current_password)
  101.                 with tempfile.NamedTemporaryFile(delete=False) as temp_video:
  102.                     with rf.open(video_name) as source_file:
  103.                         shutil.copyfileobj(source_file, temp_video)
  104.                     temp_video_path = temp_video.name
  105.  
  106.             media = self.instance.media_new(temp_video_path)
  107.             self.player.set_media(media)
  108.                
  109.             if self.player_frame.winfo_children():
  110.                 self.player_frame.winfo_children()[0].destroy()
  111.  
  112.             self.player_frame.update()
  113.             self.player.set_hwnd(self.player_frame.winfo_id())
  114.             self.play_video()
  115.             self.current_video_label.config(text="Current video: " + video_name)
  116.  
  117.     def stop_video(self):
  118.         self.player.stop()
  119.         self.current_video_label.config(text="Video stopped")
  120.  
  121.     def prev_video(self):
  122.         current_index = self.video_list.index(self.video_dropdown.get())
  123.         prev_index = current_index - 1 if current_index > 0 else len(self.video_list) - 1
  124.         self.video_dropdown.current(prev_index)
  125.         self.show_video()
  126.  
  127.     def next_video(self):
  128.         current_index = self.video_list.index(self.video_dropdown.get())
  129.         next_index = (current_index + 1) % len(self.video_list)
  130.         self.video_dropdown.current(next_index)
  131.         self.show_video()
  132.  
  133.     def set_position(self, value):
  134.         self.player.set_position(float(value) / 100)
  135.  
  136. root = tk.Tk()
  137. root.geometry("960x660")
  138. root.title("Najeeb VLC Player")
  139. root.configure(bg="#4a4a4a")
  140. video_player = VideoPlayer(root)
  141. root.mainloop()
  142.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement