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 and Other File Search and Play are Open")
- 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=3)
- 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=3)
- # Create file extension selection label and combobox for media files
- self.ext_label = tk.Label(top_frame, text="Select Media Extension:", bg='#f0f8ff', fg='#00008b')
- self.ext_label.pack(side=tk.LEFT, padx=3)
- self.ext_list = ttk.Combobox(top_frame, values=['.mp4', '.mkv', '.avi', '.flv', '.mp3'])
- self.ext_list.pack(side=tk.LEFT, padx=3)
- # Create file extension selection label and combobox for other files
- self.other_ext_label = tk.Label(top_frame, text="Select Other Extension:", bg='#f0f8ff', fg='#00008b')
- self.other_ext_label.pack(side=tk.LEFT, padx=3)
- self.other_ext_list = ttk.Combobox(top_frame, values=['.txt', '.pdf', '.docx', '.xlsx', '.jpg', '.png'])
- self.other_ext_list.pack(side=tk.LEFT, padx=3)
- # Create search button for media files
- self.search_button = tk.Button(top_frame, text="Search Media", command=self.search_files, bg='#008b8b', fg='#ffffff')
- self.search_button.pack(side=tk.LEFT, padx=3)
- # Create search button for other files
- self.search_other_button = tk.Button(top_frame, text="Search Other", command=self.search_other_files, bg='#6a5acd', fg='#ffffff')
- self.search_other_button.pack(side=tk.LEFT, padx=3)
- # Create scrolled text to display search results
- self.result_text = scrolledtext.ScrolledText(root, width=120, 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 open in default program button
- self.open_button = tk.Button(bottom_frame, text="Open in Default Program", command=self.open_file, bg='#4682b4', fg='#ffffff')
- self.open_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
- extension = self.ext_list.get()
- if not extension:
- self.result_text.insert(tk.END, "Please select a file extension.\n")
- return
- found_files = []
- for root, dirs, files in os.walk(drive):
- for file in files:
- if file.endswith(extension):
- 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 search_other_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
- extension = self.other_ext_list.get()
- if not extension:
- self.result_text.insert(tk.END, "Please select a file extension.\n")
- return
- found_files = []
- for root, dirs, files in os.walk(drive):
- for file in files:
- if file.endswith(extension):
- found_files.append(os.path.join(root, file))
- if not found_files:
- self.result_text.insert(tk.END, "No 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." and found_files[0] != "No 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 open_file(self):
- try:
- selected_file = self.result_text.get(tk.SEL_FIRST, tk.SEL_LAST).strip()
- if selected_file:
- os.startfile(selected_file)
- else:
- self.result_text.insert(tk.END, "\nNo file selected. Please highlight a file to open.\n")
- except tk.TclError:
- self.result_text.insert(tk.END, "\nNo file selected. Please highlight a file to open.\n")
- 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