Advertisement
Najeebsk

VIDEO-SEARCH-PLAY.pyw

Jun 6th, 2024
379
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.58 KB | None | 0 0
  1. import os
  2. import tkinter as tk
  3. from tkinter import ttk, scrolledtext
  4. import vlc
  5.  
  6. class MediaSearchApp:
  7.     def __init__(self, root):
  8.         self.root = root
  9.         self.root.title("Najeeb Media File Search and Play")
  10.         self.root.configure(bg='#f0f8ff')  # Set background color
  11.  
  12.         # Create frame for the top row
  13.         top_frame = tk.Frame(root, bg='#f0f8ff')
  14.         top_frame.pack(pady=10)
  15.  
  16.         # Create drive selection label and combobox
  17.         self.drive_label = tk.Label(top_frame, text="Select Drive:", bg='#f0f8ff', fg='#00008b')
  18.         self.drive_label.pack(side=tk.LEFT, padx=5)
  19.        
  20.         self.drive_list = ttk.Combobox(top_frame, values=['C:\\', 'D:\\', 'E:\\', 'F:\\', 'G\\', 'H\\', 'I\\', 'J\\', 'K\\'])
  21.         self.drive_list.pack(side=tk.LEFT, padx=5)
  22.  
  23.         # Create file extension input field
  24.         self.ext_label = tk.Label(top_frame, text="File Extensions (comma-separated):", bg='#f0f8ff', fg='#00008b')
  25.         self.ext_label.pack(side=tk.LEFT, padx=5)
  26.        
  27.         self.ext_entry = tk.Entry(top_frame)
  28.         self.ext_entry.pack(side=tk.LEFT, padx=5)
  29.         self.ext_entry.insert(0, ".mp4, .mkv, .avi, .flv, .mp3")  # Default extensions
  30.  
  31.         # Create search button
  32.         self.search_button = tk.Button(top_frame, text="Search Media Files", command=self.search_files, bg='#008b8b', fg='#ffffff')
  33.         self.search_button.pack(side=tk.LEFT, padx=5)
  34.  
  35.         # Create scrolled text to display search results
  36.         self.result_text = scrolledtext.ScrolledText(root, width=100, height=20, bg='#e6e6fa', fg='#00008b')
  37.         self.result_text.pack(pady=10)
  38.  
  39.         # Create frame for the bottom row of buttons
  40.         bottom_frame = tk.Frame(root, bg='#f0f8ff')
  41.         bottom_frame.pack(pady=10)
  42.  
  43.         # Create play button
  44.         self.play_button = tk.Button(bottom_frame, text="Play Selected File", command=self.play_file, bg='#32cd32', fg='#ffffff')
  45.         self.play_button.pack(side=tk.LEFT, padx=5)
  46.  
  47.         # Create stop button
  48.         self.stop_button = tk.Button(bottom_frame, text="Stop VLC Player", command=self.stop_player, bg='#b22222', fg='#ffffff')
  49.         self.stop_button.pack(side=tk.LEFT, padx=5)
  50.  
  51.         # Create save list button
  52.         self.save_button = tk.Button(bottom_frame, text="Save List", command=self.save_list, bg='#ff8c00', fg='#ffffff')
  53.         self.save_button.pack(side=tk.LEFT, padx=5)
  54.  
  55.         # Create volume control slider
  56.         self.volume_up = tk.Scale(bottom_frame, from_=0, to=200, orient=tk.HORIZONTAL, label="Volume", bg='#f0f8ff', fg='#00008b', command=self.set_volume)
  57.         self.volume_up.pack(side=tk.LEFT, padx=5)
  58.         self.volume_up.set(50)  # Set initial volume to 50%
  59.  
  60.         # Create video position control slider
  61.         self.video_position = tk.Scale(bottom_frame, from_=0, to=100, orient=tk.HORIZONTAL, label="Position", bg='#f0f8ff', fg='#00008b', command=self.set_position)
  62.         self.video_position.pack(side=tk.LEFT, padx=5)
  63.  
  64.         # Create video width control slider
  65.         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)
  66.         self.video_width.pack(side=tk.LEFT, padx=5)
  67.         self.video_width.set(800)  # Set initial width to 800 pixels
  68.  
  69.         # Create video height control slider
  70.         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)
  71.         self.video_height.pack(side=tk.LEFT, padx=5)
  72.         self.video_height.set(600)  # Set initial height to 600 pixels
  73.  
  74.         # Create a Toplevel window for video playback
  75.         self.video_window = tk.Toplevel(root)
  76.         self.video_window.title("VLC Player")
  77.         self.video_window.geometry("800x600")
  78.  
  79.         # Embed VLC player in the Toplevel window
  80.         self.player = vlc.MediaPlayer()
  81.         self.player.set_hwnd(self.video_window.winfo_id())
  82.  
  83.     def search_files(self):
  84.         self.result_text.delete(1.0, tk.END)  # Clear previous results
  85.         drive = self.drive_list.get()
  86.         if not drive:
  87.             self.result_text.insert(tk.END, "Please select a drive.\n")
  88.             return
  89.        
  90.         extensions = self.ext_entry.get().split(',')
  91.         extensions = [ext.strip() for ext in extensions]
  92.         found_files = []
  93.  
  94.         for root, dirs, files in os.walk(drive):
  95.             for file in files:
  96.                 if any(file.endswith(ext) for ext in extensions):
  97.                     found_files.append(os.path.join(root, file))
  98.  
  99.         if not found_files:
  100.             self.result_text.insert(tk.END, "No media files found.\n")
  101.         else:
  102.             for file in found_files:
  103.                 self.result_text.insert(tk.END, file + '\n')
  104.  
  105.     def save_list(self):
  106.         found_files = self.result_text.get(1.0, tk.END).strip().split('\n')
  107.         if found_files and found_files[0] != "No media files found.":
  108.             with open("List.txt", "w") as file:
  109.                 for line in found_files:
  110.                     file.write(line + "\n")
  111.             self.result_text.insert(tk.END, "\nResults saved to List.txt\n")
  112.         else:
  113.             self.result_text.insert(tk.END, "\nNo results to save.\n")
  114.  
  115.     def play_file(self):
  116.         try:
  117.             selected_file = self.result_text.get(tk.SEL_FIRST, tk.SEL_LAST).strip()
  118.             if selected_file:
  119.                 if self.player.is_playing():
  120.                     self.player.stop()  # Stop any currently playing media
  121.                 self.player.set_media(vlc.Media(selected_file))
  122.                 self.player.play()
  123.                 self.set_volume(self.volume_up.get())
  124.             else:
  125.                 self.result_text.insert(tk.END, "\nNo file selected. Please highlight a file to play.\n")
  126.         except tk.TclError:
  127.             self.result_text.insert(tk.END, "\nNo file selected. Please highlight a file to play.\n")
  128.  
  129.     def stop_player(self):
  130.         if self.player:
  131.             self.player.stop()
  132.  
  133.     def set_volume(self, volume):
  134.         if self.player:
  135.             self.player.audio_set_volume(int(volume))
  136.  
  137.     def set_position(self, position):
  138.         if self.player:
  139.             self.player.set_position(float(position) / 100.0)
  140.  
  141.     def set_video_width(self, width):
  142.         self.video_window.geometry(f"{width}x{self.video_height.get()}")
  143.  
  144.     def set_video_height(self, height):
  145.         self.video_window.geometry(f"{self.video_width.get()}x{height}")
  146.  
  147. if __name__ == "__main__":
  148.     root = tk.Tk()
  149.     app = MediaSearchApp(root)
  150.     root.mainloop()
  151.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement