Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import subprocess
- import tkinter as tk
- from tkinter import filedialog, Text, Scrollbar, messagebox
- import re
- import threading
- import time
- # Path to VLC executable
- VLC_PATH = r"C:\Program Files\VideoLAN\VLC\vlc.exe"
- class FileSearcherApp:
- def __init__(self, root):
- self.root = root
- self.root.title("Najeeb Inside Folder Text File Searcher")
- # Adjust the window size to fit the screen
- screen_width = self.root.winfo_screenwidth()
- screen_height = self.root.winfo_screenheight()
- self.root.geometry(f"{screen_width}x{screen_height}")
- # Frame for buttons
- self.frame = tk.Frame(self.root)
- self.frame.pack(pady=10)
- # Entry to input search keyword
- self.search_label = tk.Label(self.frame, text="Search Keyword:")
- self.search_label.pack(side=tk.LEFT)
- self.search_entry = tk.Entry(self.frame)
- self.search_entry.pack(side=tk.LEFT, padx=5)
- # Button to select folder
- self.folder_btn = tk.Button(self.frame, text="Select Folder", command=self.select_folder)
- self.folder_btn.pack(side=tk.LEFT, padx=5)
- # Button to start search
- self.search_btn = tk.Button(self.frame, text="Search", command=self.search_files)
- self.search_btn.pack(side=tk.LEFT, padx=5)
- # Button to save results
- self.save_btn = tk.Button(self.frame, text="Save", command=self.save_results)
- self.save_btn.pack(side=tk.LEFT, padx=5)
- # Play button
- self.play_button = tk.Button(self.frame, text="Play", command=self.play_channel)
- self.play_button.pack(side=tk.LEFT, padx=5)
- # Toggle button
- self.toggle_button = tk.Button(self.frame, text="Toggle Display", command=self.toggle_display)
- self.toggle_button.pack(side=tk.LEFT, padx=5)
- # Capture Video button
- self.capture_video_btn = tk.Button(self.frame, text="Capture Video", command=self.capture_video)
- self.capture_video_btn.pack(side=tk.LEFT, padx=5)
- # Record Audio button
- self.record_audio_btn = tk.Button(self.frame, text="Record Audio", command=self.record_audio)
- self.record_audio_btn.pack(side=tk.LEFT, padx=5)
- # Capture Screenshots button
- self.capture_screenshots_btn = tk.Button(self.frame, text="Screen Shot", command=self.capture_screenshots)
- self.capture_screenshots_btn.pack(side=tk.LEFT, padx=5)
- # Stop Screenshot button
- self.stop_screenshots_btn = tk.Button(self.frame, text="Stop", command=self.stop_screenshots_capture)
- self.stop_screenshots_btn.pack(side=tk.LEFT, padx=5)
- # Run button
- self.run_button = tk.Button(self.frame, text="Run", command=self.run_in_notepad)
- self.run_button.pack(side=tk.LEFT, padx=5)
- # CMD button
- self.cmd_button = tk.Button(self.frame, text="Run CMD", command=self.run_cmd)
- self.cmd_button.pack(side=tk.LEFT, padx=5)
- # Text field for displaying results with a larger font size
- self.result_text = Text(self.root, wrap='none', undo=True, width=80, height=20, font=("Times New Roman", 16))
- self.result_text.pack(padx=10, pady=10, fill=tk.BOTH, expand=True)
- # Scrollbars for the text field
- self.v_scroll = Scrollbar(self.result_text, orient=tk.VERTICAL, command=self.result_text.yview)
- self.v_scroll.pack(side=tk.RIGHT, fill=tk.Y)
- self.result_text['yscrollcommand'] = self.v_scroll.set
- self.h_scroll = Scrollbar(self.result_text, orient=tk.HORIZONTAL, command=self.result_text.xview)
- self.h_scroll.pack(side=tk.BOTTOM, fill=tk.X)
- self.result_text['xscrollcommand'] = self.h_scroll.set
- self.folder_path = ""
- self.show_full_info = False
- self.stop_event = threading.Event() # Event to stop screenshot capturing
- def select_folder(self):
- self.folder_path = filedialog.askdirectory()
- def search_files(self):
- keyword = self.search_entry.get()
- if not self.folder_path:
- self.result_text.insert(tk.END, "Please select a folder first.\n")
- return
- if not keyword:
- self.result_text.insert(tk.END, "Please enter a keyword to search for.\n")
- return
- self.result_text.delete(1.0, tk.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, keyword)
- def search_in_file(self, file_path, keyword):
- try:
- with open(file_path, 'r', encoding='utf-8', errors='ignore') as f:
- lines = f.readlines()
- for i, line in enumerate(lines):
- if keyword.lower() in line.lower():
- if self.show_full_info:
- self.result_text.insert(tk.END, f"{file_path} - Line {i+1}: {line}")
- else:
- self.result_text.insert(tk.END, f"{line.strip()}\n")
- except Exception as e:
- self.result_text.insert(tk.END, f"Error reading {file_path}: {str(e)}\n")
- def save_results(self):
- results = self.result_text.get(1.0, tk.END)
- if not results.strip():
- messagebox.showwarning("No Results", "There are no results to save.")
- return
- save_path = filedialog.asksaveasfilename(defaultextension=".txt",
- filetypes=[("Text files", "*.txt"), ("All files", "*.*")])
- if save_path:
- try:
- with open(save_path, 'w', encoding='utf-8') as file:
- file.write(results)
- messagebox.showinfo("Success", "Results saved successfully.")
- except Exception as e:
- messagebox.showerror("Error", f"Failed to save results: {str(e)}")
- def play_channel(self):
- try:
- selected_text = self.result_text.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)
- subprocess.Popen([VLC_PATH, url])
- else:
- messagebox.showwarning("Invalid Selection", "No valid URL found in the selected text.")
- except tk.TclError:
- messagebox.showwarning("No Selection", "Please select a line containing a valid URL to play.")
- 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_text.delete(1.0, tk.END) # Clear the text field
- if self.folder_path and self.search_entry.get():
- self.search_files()
- def capture_video(self):
- try:
- selected_text = self.result_text.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', '03:55:00', '-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):
- try:
- selected_text = self.result_text.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 capture_screenshots(self):
- def take_screenshots(url, filename_base, interval, num_screenshots):
- for i in range(num_screenshots):
- if self.stop_event.is_set():
- break
- filename = f"{filename_base}_{i + 1}.png"
- command = ['ffmpeg', '-y', '-i', url, '-vframes', '1', filename]
- subprocess.run(command)
- time.sleep(interval)
- messagebox.showinfo("Capturing Screenshots", f"Captured {i + 1} screenshots every {interval} seconds to {filename_base}")
- try:
- selected_text = self.result_text.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_base = filedialog.asksaveasfilename(defaultextension=".png", filetypes=[("PNG files", "*.png")])
- if filename_base:
- self.stop_event.clear() # Clear the stop event flag
- interval = 2 # Interval in seconds
- num_screenshots = 100 # Number of screenshots
- threading.Thread(target=take_screenshots, args=(url, filename_base, interval, num_screenshots)).start()
- else:
- messagebox.showerror("Error", "Selected text is not a valid URL.")
- except tk.TclError:
- messagebox.showerror("Error", "No text selected.")
- def stop_screenshots_capture(self):
- self.stop_event.set() # Set the stop event flag
- messagebox.showinfo("Screenshot Capture", "Stopping screenshot capture.")
- def run_in_notepad(self):
- try:
- selected_text = self.result_text.get(tk.SEL_FIRST, tk.SEL_LAST).strip()
- expanded_path = os.path.expandvars(selected_text)
- if os.path.isfile(expanded_path):
- subprocess.run(['notepad.exe', expanded_path]) # Open with Notepad
- else:
- messagebox.showerror("Invalid Selection", "The selected text is not a valid file path.")
- except tk.TclError:
- messagebox.showwarning("No Selection", "Please select a valid file path.")
- def run_cmd(self):
- try:
- selected_text = self.result_text.get(tk.SEL_FIRST, tk.SEL_LAST).strip()
- subprocess.run(selected_text, shell=True)
- except tk.TclError:
- messagebox.showwarning("No Selection", "Please select a command to run.")
- except Exception as e:
- messagebox.showerror("Error", f"Failed to execute the command: {str(e)}")
- if __name__ == "__main__":
- root = tk.Tk()
- app = FileSearcherApp(root)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement