Advertisement
Najeebsk

SEARCH-PLAY-OPEN.pyw

Jun 6th, 2024 (edited)
423
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 10.57 KB | None | 0 0
  1. import os
  2. import subprocess
  3. import tkinter as tk
  4. from tkinter import ttk, scrolledtext
  5. import vlc
  6.  
  7. class MediaSearchApp:
  8.     def __init__(self, root):
  9.         self.root = root
  10.         self.root.title("Najeeb Media File Search and Play and other Files Search And Open")
  11.         self.root.configure(bg='#f0f8ff')  # Set background color
  12.  
  13.         # Create frame for the top row
  14.         top_frame = tk.Frame(root, bg='#f0f8ff')
  15.         top_frame.pack(pady=10)
  16.  
  17.         # Create drive selection label and combobox
  18.         self.drive_label = tk.Label(top_frame, text="Select Drive:", bg='#f0f8ff', fg='#00008b')
  19.         self.drive_label.pack(side=tk.LEFT, padx=3)
  20.        
  21.         self.drive_list = ttk.Combobox(top_frame, values=['C:\\', 'D:\\', 'E:\\', 'F:\\', 'G\\', 'H\\', 'I\\', 'J\\', 'K\\', 'L\\', 'M\\', 'N\\', 'O\\', 'P\\', 'Q\\', 'R\\', 'S\\', 'T\\', 'U\\', 'V\\', 'W\\', 'X\\', 'Y\\', 'Z\\'])
  22.         self.drive_list.pack(side=tk.LEFT, padx=3)
  23.  
  24.         # Create file extension selection label and combobox for media files
  25.         self.ext_label = tk.Label(top_frame, text="Select Media Extension:", bg='#f0f8ff', fg='#00008b')
  26.         self.ext_label.pack(side=tk.LEFT, padx=3)
  27.        
  28.         self.ext_list = ttk.Combobox(top_frame, values=['.mp4', '.mkv', '.avi', '.flv', '.3gp', '.webm', '.m3u', '.m3u8', '.xml', '.mpg', '.vob', '.wmv', '.mp3', '.aac', '.flac', '.aif', '.aiff', '.m4a', '.wav'])
  29.         self.ext_list.pack(side=tk.LEFT, padx=3)
  30.  
  31.         # Create file extension selection label and combobox for other files
  32.         self.other_ext_label = tk.Label(top_frame, text="Select Other Extension:", bg='#f0f8ff', fg='#00008b')
  33.         self.other_ext_label.pack(side=tk.LEFT, padx=3)
  34.        
  35.         self.other_ext_list = ttk.Combobox(top_frame, values=['.txt', '.pdf', '.docx', '.doc', '.xlsx', '.jpg', '.jpge', '.bmp', '.gif', '.ico', '.png', '.bat', '.vbs', '.ahk', '.au3', '.sh', '.ini', '.ls', '.cmd', '.js', '.fm', '.exe', '.ink', '.cpl', '.rar', '.zip', '.7z', '.iso', '.daa', '.bin', '.cue', '.img'])
  36.         self.other_ext_list.pack(side=tk.LEFT, padx=3)
  37.  
  38.         # Create search button for media files
  39.         self.search_button = tk.Button(top_frame, text="Search Media", command=self.search_files, bg='#008b8b', fg='#ffffff')
  40.         self.search_button.pack(side=tk.LEFT, padx=3)
  41.  
  42.         # Create search button for other files
  43.         self.search_other_button = tk.Button(top_frame, text="Search Other", command=self.search_other_files, bg='#6a5acd', fg='#ffffff')
  44.         self.search_other_button.pack(side=tk.LEFT, padx=3)
  45.  
  46.         # Create scrolled text to display search results
  47.         self.result_text = scrolledtext.ScrolledText(root, width=120, height=20, bg='#e6e6fa', fg='#00008b')
  48.         self.result_text.pack(pady=5)
  49.  
  50.         # Create frame for the bottom row of buttons
  51.         bottom_frame = tk.Frame(root, bg='#f0f8ff')
  52.         bottom_frame.pack(pady=10)
  53.  
  54.         # Create play button
  55.         self.play_button = tk.Button(bottom_frame, text="Play", command=self.play_file, bg='#32cd32', fg='#ffffff')
  56.         self.play_button.pack(side=tk.LEFT, padx=3)
  57.  
  58.         # Create stop button
  59.         self.stop_button = tk.Button(bottom_frame, text="Stop", command=self.stop_player, bg='#b22222', fg='#ffffff')
  60.         self.stop_button.pack(side=tk.LEFT, padx=3)
  61.  
  62.         # Create save list button
  63.         self.save_button = tk.Button(bottom_frame, text="Save", command=self.save_list, bg='#ff8c00', fg='#ffffff')
  64.         self.save_button.pack(side=tk.LEFT, padx=3)
  65.  
  66.         # Create open in default program button
  67.         self.open_button = tk.Button(bottom_frame, text="Open in Default", command=self.open_file, bg='#4682b4', fg='#ffffff')
  68.         self.open_button.pack(side=tk.LEFT, padx=3)
  69.  
  70.         # Create open with dropdown menu
  71.         self.open_with_label = tk.Label(bottom_frame, text="Open With:", bg='#f0f8ff', fg='#00008b')
  72.         self.open_with_label.pack(side=tk.LEFT, padx=3)
  73.        
  74.         self.open_with_list = ttk.Combobox(bottom_frame, values=['notepad', 'mspaint', 'wordpad', 'explorer', 'chrome', 'FireFox', 'NOTE++/notepad++.exe'])
  75.         self.open_with_list.pack(side=tk.LEFT, padx=3)
  76.  
  77.         # Create open with selected program button
  78.         self.open_with_button = tk.Button(bottom_frame, text="Selected Program", command=self.open_with_selected_program, bg='#daa520', fg='#ffffff')
  79.         self.open_with_button.pack(side=tk.LEFT, padx=3)
  80.  
  81.         # Create volume control slider
  82.         self.volume_up = tk.Scale(bottom_frame, from_=0, to=200, orient=tk.HORIZONTAL, label="Volume", bg='#f0f8ff', fg='#00008b', command=self.set_volume)
  83.         self.volume_up.pack(side=tk.LEFT, padx=3)
  84.         self.volume_up.set(30)  # Set initial volume to 50%
  85.  
  86.         # Create video position control slider
  87.         self.video_position = tk.Scale(bottom_frame, from_=0, to=100, orient=tk.HORIZONTAL, label="Position", bg='#f0f8ff', fg='#00008b', command=self.set_position)
  88.         self.video_position.pack(side=tk.LEFT, padx=3)
  89.  
  90.         # Create video width control slider
  91.         self.video_width = tk.Scale(bottom_frame, from_=50, to=1600, orient=tk.HORIZONTAL, label="Width", bg='#f0f8ff', fg='#00008b', command=self.set_video_width)
  92.         self.video_width.pack(side=tk.LEFT, padx=3)
  93.         self.video_width.set(400)  # Set initial width to 800 pixels
  94.  
  95.         # Create video height control slider
  96.         self.video_height = tk.Scale(bottom_frame, from_=40, to=1200, orient=tk.HORIZONTAL, label="Height", bg='#f0f8ff', fg='#00008b', command=self.set_video_height)
  97.         self.video_height.pack(side=tk.LEFT, padx=3)
  98.         self.video_height.set(300)  # Set initial height to 600 pixels
  99.  
  100.         # Create a Toplevel window for video playback
  101.         self.video_window = tk.Toplevel(root)
  102.         self.video_window.title("VLC Player")
  103.         self.video_window.geometry("800x600")
  104.  
  105.         # Embed VLC player in the Toplevel window
  106.         self.player = vlc.MediaPlayer()
  107.         self.player.set_hwnd(self.video_window.winfo_id())
  108.  
  109.     def search_files(self):
  110.         self.result_text.delete(1.0, tk.END)  # Clear previous results
  111.         drive = self.drive_list.get()
  112.         if not drive:
  113.             self.result_text.insert(tk.END, "Please select a drive.\n")
  114.             return
  115.        
  116.         extension = self.ext_list.get()
  117.         if not extension:
  118.             self.result_text.insert(tk.END, "Please select a file extension.\n")
  119.             return
  120.  
  121.         found_files = []
  122.  
  123.         for root, dirs, files in os.walk(drive):
  124.             for file in files:
  125.                 if file.endswith(extension):
  126.                     found_files.append(os.path.join(root, file))
  127.  
  128.         if not found_files:
  129.             self.result_text.insert(tk.END, "No media files found.\n")
  130.         else:
  131.             for file in found_files:
  132.                 self.result_text.insert(tk.END, file + '\n')
  133.  
  134.     def search_other_files(self):
  135.         self.result_text.delete(1.0, tk.END)  # Clear previous results
  136.         drive = self.drive_list.get()
  137.         if not drive:
  138.             self.result_text.insert(tk.END, "Please select a drive.\n")
  139.             return
  140.        
  141.         extension = self.other_ext_list.get()
  142.         if not extension:
  143.             self.result_text.insert(tk.END, "Please select a file extension.\n")
  144.             return
  145.  
  146.         found_files = []
  147.  
  148.         for root, dirs, files in os.walk(drive):
  149.             for file in files:
  150.                 if file.endswith(extension):
  151.                     found_files.append(os.path.join(root, file))
  152.  
  153.         if not found_files:
  154.             self.result_text.insert(tk.END, "No files found.\n")
  155.         else:
  156.             for file in found_files:
  157.                 self.result_text.insert(tk.END, file + '\n')
  158.  
  159.     def save_list(self):
  160.         found_files = self.result_text.get(1.0, tk.END).strip().split('\n')
  161.         if found_files and found_files[0] != "No media files found." and found_files[0] != "No files found.":
  162.             with open("List.txt", "w") as file:
  163.                 for line in found_files:
  164.                     file.write(line + "\n")
  165.             self.result_text.insert(tk.END, "\nResults saved to List.txt\n")
  166.         else:
  167.             self.result_text.insert(tk.END, "\nNo results to save.\n")
  168.  
  169.     def play_file(self):
  170.         try:
  171.             selected_file = self.result_text.get(tk.SEL_FIRST, tk.SEL_LAST).strip()
  172.             if selected_file:
  173.                 if self.player.is_playing():
  174.                     self.player.stop()  # Stop any currently playing media
  175.                 self.player.set_media(vlc.Media(selected_file))
  176.                 self.player.play()
  177.                 self.set_volume(self.volume_up.get())
  178.             else:
  179.                 self.result_text.insert(tk.END, "\nNo file selected. Please highlight a file to play.\n")
  180.         except tk.TclError:
  181.             self.result_text.insert(tk.END, "\nNo file selected. Please highlight a file to play.\n")
  182.  
  183.     def stop_player(self):
  184.         if self.player:
  185.             self.player.stop()
  186.  
  187.     def open_file(self):
  188.         try:
  189.             selected_file = self.result_text.get(tk.SEL_FIRST, tk.SEL_LAST).strip()
  190.             if selected_file:
  191.                 os.startfile(selected_file)
  192.             else:
  193.                 self.result_text.insert(tk.END, "\nNo file selected. Please highlight a file to open.\n")
  194.         except tk.TclError:
  195.             self.result_text.insert(tk.END, "\nNo file selected. Please highlight a file to open.\n")
  196.  
  197.     def open_with_selected_program(self):
  198.         try:
  199.             selected_file = self.result_text.get(tk.SEL_FIRST, tk.SEL_LAST).strip()
  200.             program = self.open_with_list.get()
  201.             if selected_file and program:
  202.                 subprocess.run([program, selected_file])
  203.             else:
  204.                 self.result_text.insert(tk.END, "\nNo file or program selected. Please highlight a file and select a program to open.\n")
  205.         except tk.TclError:
  206.             self.result_text.insert(tk.END, "\nNo file or program selected. Please highlight a file and select a program to open.\n")
  207.  
  208.     def set_volume(self, volume):
  209.         if self.player:
  210.             self.player.audio_set_volume(int(volume))
  211.  
  212.     def set_position(self, position):
  213.         if self.player:
  214.             self.player.set_position(float(position) / 100.0)
  215.  
  216.     def set_video_width(self, width):
  217.         self.video_window.geometry(f"{width}x{self.video_height.get()}")
  218.  
  219.     def set_video_height(self, height):
  220.         self.video_window.geometry(f"{self.video_width.get()}x{height}")
  221.  
  222. if __name__ == "__main__":
  223.     root = tk.Tk()
  224.     app = MediaSearchApp(root)
  225.     root.mainloop()
  226.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement