Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import tkinter as tk
- from tkinter import ttk, scrolledtext
- import vlc
- class MediaSearchApp:
- def __init__(self, root):
- self.root = root
- self.root.title("Najeeb Media File Search and Play")
- self.root.configure(bg='#f0f8ff') # Set background color
- # Create frame for the top row
- top_frame = tk.Frame(root, bg='#f0f8ff')
- top_frame.pack(pady=10)
- # Create drive selection label and combobox
- self.drive_label = tk.Label(top_frame, text="Select Drive:", bg='#f0f8ff', fg='#00008b')
- self.drive_label.pack(side=tk.LEFT, padx=5)
- self.drive_list = ttk.Combobox(top_frame, values=['C:\\', 'D:\\', 'E:\\', 'F:\\', 'G\\', 'H\\', 'I\\', 'J\\', 'K\\'])
- self.drive_list.pack(side=tk.LEFT, padx=5)
- # Create file extension input field
- self.ext_label = tk.Label(top_frame, text="File Extensions (comma-separated):", bg='#f0f8ff', fg='#00008b')
- self.ext_label.pack(side=tk.LEFT, padx=5)
- self.ext_entry = tk.Entry(top_frame)
- self.ext_entry.pack(side=tk.LEFT, padx=5)
- self.ext_entry.insert(0, ".mp4, .mkv, .avi, .flv, .mp3") # Default extensions
- # Create search button
- self.search_button = tk.Button(top_frame, text="Search Media Files", command=self.search_files, bg='#008b8b', fg='#ffffff')
- self.search_button.pack(side=tk.LEFT, padx=5)
- # Create scrolled text to display search results
- self.result_text = scrolledtext.ScrolledText(root, width=100, height=20, bg='#e6e6fa', fg='#00008b')
- self.result_text.pack(pady=10)
- # Create frame for the bottom row of buttons
- bottom_frame = tk.Frame(root, bg='#f0f8ff')
- bottom_frame.pack(pady=10)
- # Create play button
- self.play_button = tk.Button(bottom_frame, text="Play Selected File", command=self.play_file, bg='#32cd32', fg='#ffffff')
- self.play_button.pack(side=tk.LEFT, padx=5)
- # Create stop button
- self.stop_button = tk.Button(bottom_frame, text="Stop VLC Player", command=self.stop_player, bg='#b22222', fg='#ffffff')
- self.stop_button.pack(side=tk.LEFT, padx=5)
- # Create save list button
- self.save_button = tk.Button(bottom_frame, text="Save List", command=self.save_list, bg='#ff8c00', fg='#ffffff')
- self.save_button.pack(side=tk.LEFT, padx=5)
- # Create volume control slider
- self.volume_up = tk.Scale(bottom_frame, from_=0, to=200, orient=tk.HORIZONTAL, label="Volume", bg='#f0f8ff', fg='#00008b', command=self.set_volume)
- self.volume_up.pack(side=tk.LEFT, padx=5)
- self.volume_up.set(50) # Set initial volume to 50%
- # Create video position control slider
- self.video_position = tk.Scale(bottom_frame, from_=0, to=100, orient=tk.HORIZONTAL, label="Position", bg='#f0f8ff', fg='#00008b', command=self.set_position)
- self.video_position.pack(side=tk.LEFT, padx=5)
- # Create video width control slider
- self.video_width = tk.Scale(bottom_frame, from_=100, to=1600, orient=tk.HORIZONTAL, label="Width", bg='#f0f8ff', fg='#00008b', command=self.set_video_width)
- self.video_width.pack(side=tk.LEFT, padx=5)
- self.video_width.set(800) # Set initial width to 800 pixels
- # Create video height control slider
- self.video_height = tk.Scale(bottom_frame, from_=100, to=1200, orient=tk.HORIZONTAL, label="Height", bg='#f0f8ff', fg='#00008b', command=self.set_video_height)
- self.video_height.pack(side=tk.LEFT, padx=5)
- self.video_height.set(600) # Set initial height to 600 pixels
- # Create a Toplevel window for video playback
- self.video_window = tk.Toplevel(root)
- self.video_window.title("VLC Player")
- self.video_window.geometry("800x600")
- # Embed VLC player in the Toplevel window
- self.player = vlc.MediaPlayer()
- self.player.set_hwnd(self.video_window.winfo_id())
- def search_files(self):
- self.result_text.delete(1.0, tk.END) # Clear previous results
- drive = self.drive_list.get()
- if not drive:
- self.result_text.insert(tk.END, "Please select a drive.\n")
- return
- extensions = self.ext_entry.get().split(',')
- extensions = [ext.strip() for ext in extensions]
- found_files = []
- for root, dirs, files in os.walk(drive):
- for file in files:
- if any(file.endswith(ext) for ext in extensions):
- found_files.append(os.path.join(root, file))
- if not found_files:
- self.result_text.insert(tk.END, "No media files found.\n")
- else:
- for file in found_files:
- self.result_text.insert(tk.END, file + '\n')
- def save_list(self):
- found_files = self.result_text.get(1.0, tk.END).strip().split('\n')
- if found_files and found_files[0] != "No media files found.":
- with open("List.txt", "w") as file:
- for line in found_files:
- file.write(line + "\n")
- self.result_text.insert(tk.END, "\nResults saved to List.txt\n")
- else:
- self.result_text.insert(tk.END, "\nNo results to save.\n")
- def play_file(self):
- try:
- selected_file = self.result_text.get(tk.SEL_FIRST, tk.SEL_LAST).strip()
- if selected_file:
- if self.player.is_playing():
- self.player.stop() # Stop any currently playing media
- self.player.set_media(vlc.Media(selected_file))
- self.player.play()
- self.set_volume(self.volume_up.get())
- else:
- self.result_text.insert(tk.END, "\nNo file selected. Please highlight a file to play.\n")
- except tk.TclError:
- self.result_text.insert(tk.END, "\nNo file selected. Please highlight a file to play.\n")
- def stop_player(self):
- if self.player:
- self.player.stop()
- def set_volume(self, volume):
- if self.player:
- self.player.audio_set_volume(int(volume))
- def set_position(self, position):
- if self.player:
- self.player.set_position(float(position) / 100.0)
- def set_video_width(self, width):
- self.video_window.geometry(f"{width}x{self.video_height.get()}")
- def set_video_height(self, height):
- self.video_window.geometry(f"{self.video_width.get()}x{height}")
- if __name__ == "__main__":
- root = tk.Tk()
- app = MediaSearchApp(root)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement