Advertisement
Najeebsk

VIDEO-SEARCH-PLAY-2.0.pyw

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