Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import subprocess
- import threading
- import time
- import re
- import tkinter as tk
- from tkinter import filedialog, messagebox, Scrollbar, Text, END
- from googleapiclient.discovery import build
- YOUTUBE_API_KEY = 'AIzaSyCzS7PGThVFxD83UFbfU5DOSZBMTxNpEeA'
- class IPTVChannelPlayer(tk.Tk):
- def __init__(self):
- super().__init__()
- self.title("Najeeb Youtube IPTV Channel PotPlayer")
- self.geometry("800x600")
- # Initialize self.lines to an empty list and threading event for screenshots
- self.lines = []
- self.stop_event = threading.Event()
- self.create_widgets()
- def create_widgets(self):
- # Top Frame for Buttons
- self.top_frame = tk.Frame(self, bg='lightblue')
- self.top_frame.pack(fill=tk.X, pady=10)
- # File Selection Button
- self.select_file_btn = tk.Button(self.top_frame, text="Select File", command=self.load_file, bg='lightgreen', fg='black')
- self.select_file_btn.pack(side=tk.LEFT, padx=5)
- # Search Bar
- self.search_var = tk.StringVar()
- self.search_entry = tk.Entry(self.top_frame, textvariable=self.search_var, width=40)
- self.search_entry.pack(side=tk.LEFT, padx=5)
- # Search Button
- self.search_btn = tk.Button(self.top_frame, text="Search", command=self.search, bg='lightcoral', fg='black')
- self.search_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)
- # Play Button
- self.play_btn = tk.Button(self.top_frame, text="Play Selected", command=self.play_selected, bg='lightpink', fg='black')
- self.play_btn.pack(side=tk.LEFT, padx=5)
- # Capture Video Button
- self.capture_video_btn = tk.Button(self.top_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.top_frame, text="Record Audio", command=self.record_audio, bg='lightgreen', fg='black')
- self.record_audio_btn.pack(side=tk.LEFT, padx=5)
- # Capture Screenshots Button
- self.capture_screenshots_btn = tk.Button(self.top_frame, text="Capture Screenshots", command=self.capture_screenshots, bg='lightcoral', fg='black')
- self.capture_screenshots_btn.pack(side=tk.LEFT, padx=5)
- # Stop Screenshots Capture Button
- self.stop_screenshots_btn = tk.Button(self.top_frame, text="Stop Capturing", command=self.stop_screenshots_capture, bg='lightgrey', fg='black')
- self.stop_screenshots_btn.pack(side=tk.LEFT, padx=5)
- # Text widget with Scrollbars
- self.text_frame = tk.Frame(self)
- self.text_frame.pack(fill=tk.BOTH, expand=True)
- self.result_area = Text(self.text_frame, wrap=tk.NONE, bg='white', fg='black')
- 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)
- def load_file(self):
- self.file_path = filedialog.askopenfilename(filetypes=[("M3U, M3U8, TXT Files", "*.m3u *.m3u8 *.txt")])
- if not self.file_path:
- return
- self.result_area.delete(1.0, END)
- try:
- with open(self.file_path, "r", encoding="utf-8", errors="replace") as file:
- self.lines = file.readlines() # Load lines from the file
- for line in self.lines:
- self.result_area.insert(END, line)
- except UnicodeDecodeError:
- messagebox.showerror("Error", "Failed to load the file due to encoding issues.")
- def search(self, event=None):
- search_term = self.search_var.get().lower()
- self.result_area.delete(1.0, END)
- # Ensure self.lines is populated before searching
- if search_term and self.lines:
- for line in self.lines:
- if search_term in line.lower():
- self.result_area.insert(END, line.strip() + "\n")
- def search_youtube(self):
- search_term = self.search_var.get().strip()
- if not search_term:
- messagebox.showwarning("Warning", "Please enter a search term.")
- return
- # Clear the result area
- self.result_area.delete(1.0, END)
- youtube = build('youtube', 'v3', developerKey=YOUTUBE_API_KEY)
- request = youtube.search().list(
- q=search_term,
- part='snippet',
- type='video',
- maxResults=5
- )
- response = request.execute()
- self.video_urls = []
- for item in response['items']:
- video_title = item['snippet']['title']
- video_id = item['id']['videoId']
- video_url = f"https://www.youtube.com/watch?v={video_id}"
- self.result_area.insert(END, f"{video_title}\n{video_url}\n\n")
- self.video_urls.append(video_url)
- def play_selected(self):
- try:
- selected_text = self.result_area.get(tk.SEL_FIRST, tk.SEL_LAST).strip()
- if selected_text:
- potplayer_path = r"C:\Program Files\DAUM\PotPlayer\PotPlayerMini.exe"
- if os.path.exists(potplayer_path):
- subprocess.Popen([potplayer_path, selected_text], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
- else:
- messagebox.showerror("Error", "PotPlayer not found at the specified path.")
- else:
- messagebox.showwarning("Warning", "No text selected to play.")
- except tk.TclError:
- messagebox.showwarning("Warning", "No text selected to play.")
- def capture_video(self):
- 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', '00:03: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):
- 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 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_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_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.")
- if __name__ == "__main__":
- app = IPTVChannelPlayer()
- app.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement