Advertisement
Najeebsk

DRIVE-MEDIA-SEARCH-PLAY.pyw

May 29th, 2024
490
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.02 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("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="", 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.         self.player = vlc.MediaPlayer()  # Initialize VLC player instance
  61.  
  62.     def search_files(self):
  63.         self.result_text.delete(1.0, tk.END)  # Clear previous results
  64.         drive = self.drive_list.get()
  65.         if not drive:
  66.             self.result_text.insert(tk.END, "Please select a drive.\n")
  67.             return
  68.        
  69.         extensions = self.ext_entry.get().split(',')
  70.         extensions = [ext.strip() for ext in extensions]
  71.         found_files = []
  72.  
  73.         for root, dirs, files in os.walk(drive):
  74.             for file in files:
  75.                 if any(file.endswith(ext) for ext in extensions):
  76.                     found_files.append(os.path.join(root, file))
  77.  
  78.         if not found_files:
  79.             self.result_text.insert(tk.END, "No media files found.\n")
  80.         else:
  81.             for file in found_files:
  82.                 self.result_text.insert(tk.END, file + '\n')
  83.  
  84.     def save_list(self):
  85.         found_files = self.result_text.get(1.0, tk.END).strip().split('\n')
  86.         if found_files and found_files[0] != "No media files found.":
  87.             with open("List.txt", "w") as file:
  88.                 for line in found_files:
  89.                     file.write(line + "\n")
  90.             self.result_text.insert(tk.END, "\nResults saved to List.txt\n")
  91.         else:
  92.             self.result_text.insert(tk.END, "\nNo results to save.\n")
  93.  
  94.     def play_file(self):
  95.         try:
  96.             selected_file = self.result_text.get(tk.SEL_FIRST, tk.SEL_LAST).strip()
  97.             if selected_file:
  98.                 if self.player.is_playing():
  99.                     self.player.stop()  # Stop any currently playing media
  100.                 self.player.set_media(vlc.Media(selected_file))
  101.                 self.player.play()
  102.                 self.set_volume(self.volume_up.get())
  103.             else:
  104.                 self.result_text.insert(tk.END, "\nNo file selected. Please highlight a file to play.\n")
  105.         except tk.TclError:
  106.             self.result_text.insert(tk.END, "\nNo file selected. Please highlight a file to play.\n")
  107.  
  108.     def stop_player(self):
  109.         if self.player:
  110.             self.player.stop()
  111.  
  112.     def set_volume(self, volume):
  113.         if self.player:
  114.             self.player.audio_set_volume(int(volume))
  115.  
  116. if __name__ == "__main__":
  117.     root = tk.Tk()
  118.     app = MediaSearchApp(root)
  119.     root.mainloop()
  120.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement