Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- from tkinter import ttk, filedialog
- import vlc
- import rarfile
- import tempfile
- import shutil
- class VideoPlayer:
- def __init__(self, root):
- self.root = root
- self.instance = vlc.Instance('--no-xlib')
- self.player = self.instance.media_player_new()
- self.main_frame = tk.Frame(root, bg="#4a4a4a")
- self.main_frame.pack(fill="both", expand=True)
- # Add password entry
- tk.Label(root, text="Password:", bg="#4a4a4a", fg="white").place(x=10, y=10)
- self.password_entry = tk.Entry(root, show='*', bg="#4a4a4a", fg="white")
- self.password_entry.place(x=80, y=10)
- # Add file browse button
- tk.Label(root, text="Select RAR File:", bg="#4a4a4a", fg="white").place(x=220, y=10)
- self.rar_entry = tk.Entry(root, bg="#4a4a4a", fg="white")
- self.rar_entry.place(x=320, y=10)
- self.browse_rar_button = tk.Button(root, text="Browse", command=self.browse_file, bg="#FFA500", fg="white")
- self.browse_rar_button.place(x=460, y=8)
- # Dropdown list for videos
- tk.Label(root, text="Select Video from RAR:", bg="#4a4a4a", fg="white").place(x=530, y=10)
- self.video_dropdown = ttk.Combobox(root, state="readonly")
- self.video_dropdown.place(x=670, y=10, width=280)
- self.video_dropdown.bind("<<ComboboxSelected>>", lambda e: self.show_video())
- self.button_frame = tk.Frame(self.main_frame, bg="#4a4a4a")
- self.button_frame.pack(side="bottom", fill="x")
- self.play_button = tk.Button(self.button_frame, text="Play", command=self.play_video, bg="#008000", fg="white")
- self.play_button.pack(side="left", padx=5, pady=5)
- self.stop_button = tk.Button(self.button_frame, text="Stop", command=self.stop_video, bg="#FF0000", fg="white")
- self.stop_button.pack(side="left", padx=5, pady=5)
- self.prev_button = tk.Button(self.button_frame, text="Prev", command=self.prev_video, bg="#5a5a5a", fg="white")
- self.prev_button.pack(side="left", padx=5, pady=5)
- self.next_button = tk.Button(self.button_frame, text="Next", command=self.next_video, bg="#5a5a5a", fg="white")
- self.next_button.pack(side="left", padx=5, pady=5)
- self.volume_scale = tk.Scale(self.button_frame, from_=0, to=100, orient="horizontal", command=self.set_volume, label="Volume", bg="#4a4a4a", fg="white")
- self.volume_scale.set(50) # Set the initial volume to 50%
- self.volume_scale.pack(side="left", fill="x", padx=5, pady=5)
- self.player_position = tk.Scale(self.button_frame, from_=0, to=100, orient="horizontal", command=self.set_position, length=640, bg="#4a4a4a", fg="white")
- self.player_position.pack(side="left", fill="x", padx=5, pady=5)
- self.current_video_label = tk.Label(root, text="No video selected", bg="#4a4a4a", fg="white")
- self.current_video_label.pack(pady=5)
- self.player_frame = tk.Frame(self.main_frame, bg="#4a4a4a")
- self.player_frame.pack(side="right", fill="both", expand=True)
- self.video_list = []
- def browse_file(self):
- file_path = filedialog.askopenfilename(filetypes=[("RAR files", "*.rar")])
- if file_path:
- self.rar_entry.delete(0, tk.END)
- self.rar_entry.insert(0, file_path)
- self.load_videos_from_rar(file_path)
- def load_videos_from_rar(self, rar_path):
- password = self.password_entry.get()
- try:
- with rarfile.RarFile(rar_path) as rf:
- if password:
- rf.setpassword(password)
- self.video_list = [f.filename for f in rf.infolist() if f.filename.endswith(('.mp4', '.mkv', '.avi'))]
- self.video_list.sort()
- self.video_dropdown['values'] = self.video_list
- self.current_rar_path = rar_path
- self.current_password = password
- self.current_video_label.config(text="Videos loaded. Select a video.")
- except rarfile.BadRarFile:
- self.current_video_label.config(text="Failed to open RAR file.")
- except rarfile.RarWrongPassword:
- self.current_video_label.config(text="Incorrect password.")
- def play_video(self):
- if self.player.get_state() == vlc.State.Ended:
- self.player.stop()
- self.player.play()
- self.current_video_label.config(text="Video playing")
- def show_video(self):
- video_name = self.video_dropdown.get()
- if video_name:
- with rarfile.RarFile(self.current_rar_path) as rf:
- if self.current_password:
- rf.setpassword(self.current_password)
- with tempfile.NamedTemporaryFile(delete=False) as temp_video:
- with rf.open(video_name) as source_file:
- shutil.copyfileobj(source_file, temp_video)
- temp_video_path = temp_video.name
- media = self.instance.media_new(temp_video_path)
- self.player.set_media(media)
- if self.player_frame.winfo_children():
- self.player_frame.winfo_children()[0].destroy()
- self.player_frame.update()
- self.player.set_hwnd(self.player_frame.winfo_id())
- self.play_video()
- self.current_video_label.config(text="Current video: " + video_name)
- def stop_video(self):
- self.player.stop()
- self.current_video_label.config(text="Video stopped")
- def prev_video(self):
- current_index = self.video_list.index(self.video_dropdown.get())
- prev_index = current_index - 1 if current_index > 0 else len(self.video_list) - 1
- self.video_dropdown.current(prev_index)
- self.show_video()
- def next_video(self):
- current_index = self.video_list.index(self.video_dropdown.get())
- next_index = (current_index + 1) % len(self.video_list)
- self.video_dropdown.current(next_index)
- self.show_video()
- def set_position(self, value):
- self.player.set_position(float(value) / 100)
- def set_volume(self, value):
- self.player.audio_set_volume(int(value))
- root = tk.Tk()
- root.geometry("960x660")
- root.title("Najeeb VLC Player")
- root.configure(bg="#4a4a4a")
- video_player = VideoPlayer(root)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement