Advertisement
Najeebsk

VIDEO-RAR-PLAYER2.0.pyw

May 26th, 2024
748
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.33 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 password entry
  18.         tk.Label(root, text="Password:", bg="#4a4a4a", fg="white").place(x=10, y=10)
  19.         self.password_entry = tk.Entry(root, show='*', bg="#4a4a4a", fg="white")
  20.         self.password_entry.place(x=80, y=10)
  21.  
  22.         # Add file browse button
  23.         tk.Label(root, text="Select RAR File:", bg="#4a4a4a", fg="white").place(x=220, y=10)
  24.         self.rar_entry = tk.Entry(root, bg="#4a4a4a", fg="white")
  25.         self.rar_entry.place(x=320, y=10)
  26.         self.browse_rar_button = tk.Button(root, text="Browse", command=self.browse_file, bg="#FFA500", fg="white")
  27.         self.browse_rar_button.place(x=460, y=8)
  28.  
  29.         # Dropdown list for videos
  30.         tk.Label(root, text="Select Video from RAR:", bg="#4a4a4a", fg="white").place(x=530, y=10)
  31.         self.video_dropdown = ttk.Combobox(root, state="readonly")
  32.         self.video_dropdown.place(x=670, y=10, width=280)
  33.         self.video_dropdown.bind("<<ComboboxSelected>>", lambda e: self.show_video())
  34.  
  35.         self.button_frame = tk.Frame(self.main_frame, bg="#4a4a4a")
  36.         self.button_frame.pack(side="bottom", fill="x")
  37.  
  38.         self.play_button = tk.Button(self.button_frame, text="Play", command=self.play_video, bg="#008000", fg="white")
  39.         self.play_button.pack(side="left", padx=5, pady=5)
  40.  
  41.         self.stop_button = tk.Button(self.button_frame, text="Stop", command=self.stop_video, bg="#FF0000", fg="white")
  42.         self.stop_button.pack(side="left", padx=5, pady=5)
  43.  
  44.         self.prev_button = tk.Button(self.button_frame, text="Prev", command=self.prev_video, bg="#5a5a5a", fg="white")
  45.         self.prev_button.pack(side="left", padx=5, pady=5)
  46.  
  47.         self.next_button = tk.Button(self.button_frame, text="Next", command=self.next_video, bg="#5a5a5a", fg="white")
  48.         self.next_button.pack(side="left", padx=5, pady=5)
  49.  
  50.         self.volume_scale = tk.Scale(self.button_frame, from_=0, to=100, orient="horizontal", command=self.set_volume, label="Volume", bg="#4a4a4a", fg="white")
  51.         self.volume_scale.set(50)  # Set the initial volume to 50%
  52.         self.volume_scale.pack(side="left", fill="x", 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=640, 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.     def set_volume(self, value):
  137.         self.player.audio_set_volume(int(value))
  138.  
  139. root = tk.Tk()
  140. root.geometry("960x660")
  141. root.title("Najeeb VLC Player")
  142. root.configure(bg="#4a4a4a")
  143. video_player = VideoPlayer(root)
  144. root.mainloop()
  145.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement