Advertisement
Najeebsk

VIDEO-SEARCH-PLAY-2.2.pyw

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