Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import subprocess
- import threading
- import re
- import tkinter as tk
- from tkinter import filedialog, messagebox, Scrollbar, Text, END
- from googleapiclient.discovery import build
- # Path to VLC executable
- VLC_PATH = r"C:\Program Files\VideoLAN\VLC\vlc.exe"
- # YouTube API key
- YOUTUBE_API_KEY = 'AIzaSyCzS7PGThVFxD83UFbfU5DOSZBMTxNpEeA'
- class AdvancedFileSearchApp(tk.Tk):
- def __init__(self):
- super().__init__()
- self.title("Najeeb Advanced File Search with YouTube and Media Controls")
- self.geometry("900x700")
- self.configure(bg="#282C34")
- self.folder_path = None
- self.lines = []
- self.stop_event = threading.Event()
- self.create_widgets()
- def create_widgets(self):
- # Top Frame for main controls
- self.top_frame = tk.Frame(self, bg="#282C34")
- self.top_frame.pack(fill=tk.X, pady=10)
- # Drive Selector
- self.drive_var = tk.StringVar()
- self.drive_dropdown = tk.OptionMenu(self.top_frame, self.drive_var, *self.get_drives())
- self.drive_dropdown.config(width=6, bg="#3E4451", fg="#ABB2BF", highlightbackground="#4B5263", highlightcolor="#4B5263")
- self.drive_var.set(self.get_drives()[0] if self.get_drives() else "")
- self.drive_dropdown.pack(side=tk.LEFT, padx=5)
- # Select Folder Button
- self.select_folder_btn = tk.Button(self.top_frame, text="Select Folder", command=self.select_folder, bg='lightgreen', fg='black')
- self.select_folder_btn.pack(side=tk.LEFT, padx=5)
- # First Search Entry
- self.search_var = tk.StringVar()
- self.search_entry = tk.Entry(self.top_frame, textvariable=self.search_var, width=24, bg="#3E4451", fg="#ABB2BF")
- self.search_entry.pack(side=tk.LEFT, padx=5)
- # Second Search Entry
- self.search_var2 = tk.StringVar()
- self.search_entry2 = tk.Entry(self.top_frame, textvariable=self.search_var2, width=24)
- self.search_entry2.pack(side=tk.LEFT, padx=5)
- # Search Text Button
- self.search_text_btn = tk.Button(self.top_frame, text="Search Text All", command=self.search_files, bg='lightcoral', fg='black')
- self.search_text_btn.pack(side=tk.LEFT, padx=5)
- # Search Word Button
- self.search_word_btn = tk.Button(self.top_frame, text="Search Word", command=self.search_files, bg='lightcoral', fg='black')
- self.search_word_btn.pack(side=tk.LEFT, padx=5)
- # Search Drive Button
- self.search_drive_btn = tk.Button(self.top_frame, text="Search Drive", command=self.search_drive, bg='lightgreen', fg='black')
- self.search_drive_btn.pack(side=tk.LEFT, padx=5)
- # YouTube Search Button
- self.youtube_search_btn = tk.Button(self.top_frame, text="Search YouTube", command=self.search_youtube, bg='lightyellow', fg='black')
- self.youtube_search_btn.pack(side=tk.LEFT, padx=5)
- # Second Line Frame for additional controls
- self.second_line_frame = tk.Frame(self, bg="#282C34")
- self.second_line_frame.pack(fill=tk.X, pady=10)
- # Capture Video Button
- self.capture_video_btn = tk.Button(self.second_line_frame, text="Capture Video", command=self.capture_video, bg='lightblue', fg='black')
- self.capture_video_btn.pack(side=tk.LEFT, padx=5)
- # Record Audio Button
- self.record_audio_btn = tk.Button(self.second_line_frame, text="Record Audio", command=self.record_audio, bg='lightgreen', fg='black')
- self.record_audio_btn.pack(side=tk.LEFT, padx=5)
- # Download Button
- self.download_btn = tk.Button(self.second_line_frame, text="Download Video", command=self.download_video, bg='lightgoldenrod', fg='black')
- self.download_btn.pack(side=tk.LEFT, padx=5)
- # Run button
- self.run_button = tk.Button(self.second_line_frame, text="Open Notepad", command=self.run_in_notepad, bg='#90EE90', fg='black')
- self.run_button.pack(side=tk.LEFT, padx=5)
- # CMD button
- self.cmd_button = tk.Button(self.second_line_frame, text="Run CMD", command=self.run_cmd, bg='#90EE90', fg='black')
- self.cmd_button.pack(side=tk.LEFT, padx=5)
- # Play PotPlayer Button
- self.play_btn = tk.Button(self.second_line_frame, text="Play Selected PotPlayer", command=self.play_selected, bg='lightpink', fg='black')
- self.play_btn.pack(side=tk.LEFT, padx=5)
- # Play VLC Player Button
- self.play_vlc_btn = tk.Button(self.second_line_frame, text="Play Selected VLC", command=self.play_selected_vlc, bg='lightpink', fg='black')
- self.play_vlc_btn.pack(side=tk.LEFT, padx=5)
- # Save List Button
- self.save_list_btn = tk.Button(self.second_line_frame, text="Save List", command=self.save_list, bg='lightblue', fg='black')
- self.save_list_btn.pack(side=tk.LEFT, padx=5)
- # Toggle button
- self.toggle_button = tk.Button(self.second_line_frame, text="Toggle Display", command=self.toggle_display, bg='#ffcc00', fg='black')
- self.toggle_button.pack(side=tk.LEFT, padx=5)
- # Text widget with Scrollbars
- self.text_frame = tk.Frame(self, bg="#282C34")
- self.text_frame.pack(fill=tk.BOTH, expand=True)
- self.result_area = Text(self.text_frame, wrap=tk.NONE, bg='#1E2127', fg='#ABB2BF')
- self.result_area.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
- self.scrollbar_y = Scrollbar(self.text_frame, orient=tk.VERTICAL)
- self.scrollbar_y.pack(side=tk.RIGHT, fill=tk.Y)
- self.scrollbar_x = Scrollbar(self, orient=tk.HORIZONTAL)
- self.scrollbar_x.pack(fill=tk.X)
- self.result_area.config(yscrollcommand=self.scrollbar_y.set, xscrollcommand=self.scrollbar_x.set)
- self.scrollbar_y.config(command=self.result_area.yview)
- self.scrollbar_x.config(command=self.result_area.xview)
- self.folder_path = ""
- self.show_full_info = False
- def get_drives(self):
- """Return a list of all available drives on the system."""
- drives = []
- for drive in range(ord('A'), ord('Z')+1):
- drive_letter = f"{chr(drive)}:\\"
- if os.path.exists(drive_letter):
- drives.append(drive_letter)
- return drives
- def select_folder(self):
- self.folder_path = filedialog.askdirectory()
- if self.folder_path:
- messagebox.showinfo("Selected Folder", f"Selected folder: {self.folder_path}")
- def search_files(self):
- keyword1 = self.search_entry.get().strip()
- keyword2 = self.search_entry2.get().strip()
- if not self.folder_path:
- self.result_area.insert(END, "Please select a folder first.\n")
- return
- if not keyword1 and not keyword2:
- self.result_area.insert(END, "Please enter at least one keyword to search for.\n")
- return
- self.result_area.delete(1.0, END) # Clear the text field
- for root, dirs, files in os.walk(self.folder_path):
- for file in files:
- if file.endswith(('.txt', '.ls', '.ini', '.m3u', '.m3u8', '.py', '.pyw', '.ahk', '.bat', '.cmd', '.vbs', '.htm', '.html', '.au3', '.reg')):
- file_path = os.path.join(root, file)
- self.search_in_file(file_path, keyword1, keyword2)
- def search_in_file(self, file_path, keyword1, keyword2):
- try:
- with open(file_path, 'r', encoding='utf-8', errors='ignore') as f:
- lines = f.readlines()
- for i, line in enumerate(lines):
- if (keyword1.lower() in line.lower()) or (keyword2.lower() in line.lower()):
- if self.show_full_info:
- self.result_area.insert(tk.END, f"{file_path} - Line {i+1}: {line}")
- else:
- self.result_area.insert(tk.END, f"{line.strip()}\n")
- except Exception as e:
- self.result_area.insert(tk.END, f"Error reading {file_path}: {str(e)}\n")
- def save_list(self):
- save_path = filedialog.asksaveasfilename(defaultextension=".txt", filetypes=[("Text files", "*.txt")])
- if save_path:
- try:
- with open(save_path, 'w', encoding='utf-8') as f:
- f.write(self.result_area.get(1.0, END))
- messagebox.showinfo("Save Success", f"Results saved to {save_path}")
- except Exception as e:
- messagebox.showerror("Save Error", f"Could not save results: {str(e)}")
- def run_in_notepad(self):
- selected_text = self.result_area.get(tk.SEL_FIRST, tk.SEL_LAST)
- with open("temp_file.txt", "w", encoding='utf-8') as f:
- f.write(selected_text)
- os.startfile("temp_file.txt")
- def run_cmd(self):
- selected_text = self.result_area.get(tk.SEL_FIRST, tk.SEL_LAST)
- os.system(f'cmd /c "{selected_text}"')
- def toggle_display(self):
- self.show_full_info = not self.show_full_info
- state = "Full Info" if self.show_full_info else "Search Word Only"
- self.toggle_button.config(text=f"Toggle Display ({state})")
- self.result_area.delete(1.0, tk.END) # Clear the text field
- if self.folder_path and self.search_entry.get():
- self.search_files()
- def search_youtube(self):
- query = self.search_var.get()
- if not query:
- self.result_area.insert(END, "Please enter a query for YouTube search.\n")
- return
- youtube = build('youtube', 'v3', developerKey=YOUTUBE_API_KEY)
- request = youtube.search().list(q=query, part='snippet', type='video', maxResults=5)
- response = request.execute()
- self.result_area.delete(1.0, END)
- for item in response['items']:
- video_title = item['snippet']['title']
- video_url = f"https://www.youtube.com/watch?v={item['id']['videoId']}"
- self.result_area.insert(END, f"{video_title}\n{video_url}\n\n")
- def capture_video(self):
- # Implement video capture functionality
- try:
- selected_text = self.result_area.get(tk.SEL_FIRST, tk.SEL_LAST).strip()
- url_match = re.search(r'(https?://\S+)', selected_text)
- if url_match:
- url = url_match.group(0)
- filename = filedialog.asksaveasfilename(defaultextension=".mp4", filetypes=[("MP4 files", "*.mp4")])
- if filename:
- command = ['ffmpeg', '-y', '-i', url, '-t', '01:35:55', '-c', 'copy', filename]
- threading.Thread(target=lambda: subprocess.run(command)).start()
- messagebox.showinfo("Capturing", f"Capturing 03:55 minutes of video to {filename}")
- else:
- messagebox.showerror("Error", "Selected text is not a valid URL.")
- except tk.TclError:
- messagebox.showerror("Error", "No text selected.")
- def record_audio(self):
- # Implement audio recording functionality
- try:
- selected_text = self.result_area.get(tk.SEL_FIRST, tk.SEL_LAST).strip()
- url_match = re.search(r'(https?://\S+)', selected_text)
- if url_match:
- url = url_match.group(0)
- filename = filedialog.asksaveasfilename(defaultextension=".mp3", filetypes=[("MP3 files", "*.mp3")])
- if filename:
- command = ['ffmpeg', '-y', '-i', url, '-f', 'mp3', '-c:a', 'libmp3lame', filename]
- threading.Thread(target=lambda: subprocess.run(command)).start()
- messagebox.showinfo("Recording", f"Recording audio to {filename}")
- else:
- messagebox.showerror("Error", "Selected text is not a valid URL.")
- except tk.TclError:
- messagebox.showerror("Error", "No text selected.")
- def download_video(self):
- # Implement video download functionality
- #selected_quality = self.quality_var.get()
- selected_text = self.result_area.get(tk.SEL_FIRST, tk.SEL_LAST).strip()
- if not selected_text.startswith("http"):
- messagebox.showerror("Invalid Selection", "Please select a valid YouTube URL.")
- return
- download_command = f'youtube-dl -f "bestvideo[height<=360]+bestaudio/best" {selected_text} -o "%(title)s.%(ext)s"'
- subprocess.run(download_command, shell=True)
- messagebox.showinfo("Download Complete", "Video downloaded successfully.")
- def play_selected(self):
- selected_text = self.result_area.get(tk.SEL_FIRST, tk.SEL_LAST).strip()
- if selected_text:
- subprocess.Popen([r"C:\Program Files\DAUM\PotPlayer\PotPlayerMini.exe", selected_text])
- else:
- messagebox.showwarning("No Selection", "Please select a URL or file path to play.")
- def play_selected_vlc(self):
- selected_text = self.result_area.get(tk.SEL_FIRST, tk.SEL_LAST).strip()
- if selected_text:
- subprocess.Popen([VLC_PATH, selected_text])
- else:
- messagebox.showwarning("No Selection", "Please select a URL or file path to play.")
- def search(self, event=None):
- drive = self.drive_var.get()
- search_term = self.search_var.get().lower()
- self.result_area.delete(1.0, END)
- if not drive or not search_term:
- messagebox.showwarning("Warning", "Please select a drive and enter a search term.")
- return
- # Search for files
- for root, dirs, files in os.walk(drive):
- for file in files:
- if search_term in file.lower():
- self.result_area.insert(END, os.path.join(root, file) + "\n")
- def search_drive(self):
- self.search() # Reuse the search function for drive-specific searches
- if __name__ == "__main__":
- app = AdvancedFileSearchApp()
- app.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement