Advertisement
Najeebsk

IPTV-YT-POTPLAYER.pyw

Aug 9th, 2024 (edited)
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 9.72 KB | None | 0 0
  1. import os
  2. import subprocess
  3. import threading
  4. import time
  5. import re
  6. import tkinter as tk
  7. from tkinter import filedialog, messagebox, Scrollbar, Text, END
  8. from googleapiclient.discovery import build
  9.  
  10. YOUTUBE_API_KEY = 'AIzaSyCzS7PGThVFxD83UFbfU5DOSZBMTxNpEeA'
  11.  
  12. class IPTVChannelPlayer(tk.Tk):
  13.     def __init__(self):
  14.         super().__init__()
  15.         self.title("Najeeb Youtube IPTV Channel PotPlayer")
  16.         self.geometry("800x600")
  17.        
  18.         # Initialize self.lines to an empty list and threading event for screenshots
  19.         self.lines = []
  20.         self.stop_event = threading.Event()
  21.  
  22.         self.create_widgets()
  23.  
  24.     def create_widgets(self):
  25.         # Top Frame for Buttons
  26.         self.top_frame = tk.Frame(self, bg='lightblue')
  27.         self.top_frame.pack(fill=tk.X, pady=10)
  28.  
  29.         # File Selection Button
  30.         self.select_file_btn = tk.Button(self.top_frame, text="Select File", command=self.load_file, bg='lightgreen', fg='black')
  31.         self.select_file_btn.pack(side=tk.LEFT, padx=5)
  32.  
  33.         # Search Bar
  34.         self.search_var = tk.StringVar()
  35.         self.search_entry = tk.Entry(self.top_frame, textvariable=self.search_var, width=40)
  36.         self.search_entry.pack(side=tk.LEFT, padx=5)
  37.  
  38.         # Search Button
  39.         self.search_btn = tk.Button(self.top_frame, text="Search", command=self.search, bg='lightcoral', fg='black')
  40.         self.search_btn.pack(side=tk.LEFT, padx=5)
  41.  
  42.         # YouTube Search Button
  43.         self.youtube_search_btn = tk.Button(self.top_frame, text="Search YouTube", command=self.search_youtube, bg='lightyellow', fg='black')
  44.         self.youtube_search_btn.pack(side=tk.LEFT, padx=5)
  45.  
  46.         # Play Button
  47.         self.play_btn = tk.Button(self.top_frame, text="Play Selected", command=self.play_selected, bg='lightpink', fg='black')
  48.         self.play_btn.pack(side=tk.LEFT, padx=5)
  49.  
  50.         # Capture Video Button
  51.         self.capture_video_btn = tk.Button(self.top_frame, text="Capture Video", command=self.capture_video, bg='lightblue', fg='black')
  52.         self.capture_video_btn.pack(side=tk.LEFT, padx=5)
  53.  
  54.         # Record Audio Button
  55.         self.record_audio_btn = tk.Button(self.top_frame, text="Record Audio", command=self.record_audio, bg='lightgreen', fg='black')
  56.         self.record_audio_btn.pack(side=tk.LEFT, padx=5)
  57.  
  58.         # Capture Screenshots Button
  59.         self.capture_screenshots_btn = tk.Button(self.top_frame, text="Capture Screenshots", command=self.capture_screenshots, bg='lightcoral', fg='black')
  60.         self.capture_screenshots_btn.pack(side=tk.LEFT, padx=5)
  61.  
  62.         # Stop Screenshots Capture Button
  63.         self.stop_screenshots_btn = tk.Button(self.top_frame, text="Stop Capturing", command=self.stop_screenshots_capture, bg='lightgrey', fg='black')
  64.         self.stop_screenshots_btn.pack(side=tk.LEFT, padx=5)
  65.  
  66.         # Text widget with Scrollbars
  67.         self.text_frame = tk.Frame(self)
  68.         self.text_frame.pack(fill=tk.BOTH, expand=True)
  69.  
  70.         self.result_area = Text(self.text_frame, wrap=tk.NONE, bg='white', fg='black')
  71.         self.result_area.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
  72.  
  73.         self.scrollbar_y = Scrollbar(self.text_frame, orient=tk.VERTICAL)
  74.         self.scrollbar_y.pack(side=tk.RIGHT, fill=tk.Y)
  75.  
  76.         self.scrollbar_x = Scrollbar(self, orient=tk.HORIZONTAL)
  77.         self.scrollbar_x.pack(fill=tk.X)
  78.  
  79.         self.result_area.config(yscrollcommand=self.scrollbar_y.set, xscrollcommand=self.scrollbar_x.set)
  80.         self.scrollbar_y.config(command=self.result_area.yview)
  81.         self.scrollbar_x.config(command=self.result_area.xview)
  82.  
  83.     def load_file(self):
  84.         self.file_path = filedialog.askopenfilename(filetypes=[("M3U, M3U8, TXT Files", "*.m3u *.m3u8 *.txt")])
  85.         if not self.file_path:
  86.             return
  87.  
  88.         self.result_area.delete(1.0, END)
  89.         try:
  90.             with open(self.file_path, "r", encoding="utf-8", errors="replace") as file:
  91.                 self.lines = file.readlines()  # Load lines from the file
  92.                 for line in self.lines:
  93.                     self.result_area.insert(END, line)
  94.         except UnicodeDecodeError:
  95.             messagebox.showerror("Error", "Failed to load the file due to encoding issues.")
  96.  
  97.     def search(self, event=None):
  98.         search_term = self.search_var.get().lower()
  99.         self.result_area.delete(1.0, END)
  100.  
  101.         # Ensure self.lines is populated before searching
  102.         if search_term and self.lines:
  103.             for line in self.lines:
  104.                 if search_term in line.lower():
  105.                     self.result_area.insert(END, line.strip() + "\n")
  106.  
  107.     def search_youtube(self):
  108.         search_term = self.search_var.get().strip()
  109.         if not search_term:
  110.             messagebox.showwarning("Warning", "Please enter a search term.")
  111.             return
  112.  
  113.         # Clear the result area
  114.         self.result_area.delete(1.0, END)
  115.  
  116.         youtube = build('youtube', 'v3', developerKey=YOUTUBE_API_KEY)
  117.  
  118.         request = youtube.search().list(
  119.             q=search_term,
  120.             part='snippet',
  121.             type='video',
  122.             maxResults=5
  123.         )
  124.         response = request.execute()
  125.  
  126.         self.video_urls = []
  127.  
  128.         for item in response['items']:
  129.             video_title = item['snippet']['title']
  130.             video_id = item['id']['videoId']
  131.             video_url = f"https://www.youtube.com/watch?v={video_id}"
  132.             self.result_area.insert(END, f"{video_title}\n{video_url}\n\n")
  133.             self.video_urls.append(video_url)
  134.  
  135.     def play_selected(self):
  136.         try:
  137.             selected_text = self.result_area.get(tk.SEL_FIRST, tk.SEL_LAST).strip()
  138.             if selected_text:
  139.                 potplayer_path = r"C:\Program Files\DAUM\PotPlayer\PotPlayerMini.exe"
  140.                 if os.path.exists(potplayer_path):
  141.                     subprocess.Popen([potplayer_path, selected_text], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
  142.                 else:
  143.                     messagebox.showerror("Error", "PotPlayer not found at the specified path.")
  144.             else:
  145.                 messagebox.showwarning("Warning", "No text selected to play.")
  146.         except tk.TclError:
  147.             messagebox.showwarning("Warning", "No text selected to play.")
  148.  
  149.     def capture_video(self):
  150.         try:
  151.             selected_text = self.result_area.get(tk.SEL_FIRST, tk.SEL_LAST).strip()
  152.             url_match = re.search(r'(https?://\S+)', selected_text)
  153.             if url_match:
  154.                 url = url_match.group(0)
  155.                 filename = filedialog.asksaveasfilename(defaultextension=".mp4", filetypes=[("MP4 files", "*.mp4")])
  156.                 if filename:
  157.                     command = ['ffmpeg', '-y', '-i', url, '-t', '00:03:55', '-c', 'copy', filename]
  158.                     threading.Thread(target=lambda: subprocess.run(command)).start()
  159.                     messagebox.showinfo("Capturing", f"Capturing 03:55 minutes of video to {filename}")
  160.             else:
  161.                 messagebox.showerror("Error", "Selected text is not a valid URL.")
  162.         except tk.TclError:
  163.             messagebox.showerror("Error", "No text selected.")
  164.  
  165.     def record_audio(self):
  166.         try:
  167.             selected_text = self.result_area.get(tk.SEL_FIRST, tk.SEL_LAST).strip()
  168.             url_match = re.search(r'(https?://\S+)', selected_text)
  169.             if url_match:
  170.                 url = url_match.group(0)
  171.                 filename = filedialog.asksaveasfilename(defaultextension=".mp3", filetypes=[("MP3 files", "*.mp3")])
  172.                 if filename:
  173.                     command = ['ffmpeg', '-y', '-i', url, '-f', 'mp3', '-c:a', 'libmp3lame', filename]
  174.                     threading.Thread(target=lambda: subprocess.run(command)).start()
  175.                     messagebox.showinfo("Recording", f"Recording audio to {filename}")
  176.             else:
  177.                 messagebox.showerror("Error", "Selected text is not a valid URL.")
  178.         except tk.TclError:
  179.             messagebox.showerror("Error", "No text selected.")
  180.  
  181.     def capture_screenshots(self):
  182.         def take_screenshots(url, filename_base, interval, num_screenshots):
  183.             for i in range(num_screenshots):
  184.                 if self.stop_event.is_set():
  185.                     break
  186.                 filename = f"{filename_base}_{i + 1}.png"
  187.                 command = ['ffmpeg', '-y', '-i', url, '-vframes', '1', filename]
  188.                 subprocess.run(command)
  189.                 time.sleep(interval)
  190.             messagebox.showinfo("Capturing Screenshots", f"Captured {i + 1} screenshots every {interval} seconds to {filename_base}")
  191.  
  192.         try:
  193.             selected_text = self.result_area.get(tk.SEL_FIRST, tk.SEL_LAST).strip()
  194.             url_match = re.search(r'(https?://\S+)', selected_text)
  195.             if url_match:
  196.                 url = url_match.group(0)
  197.                 filename_base = filedialog.asksaveasfilename(defaultextension=".png", filetypes=[("PNG files", "*.png")])
  198.                 if filename_base:
  199.                     self.stop_event.clear()  # Clear the stop event flag
  200.                     interval = 2  # Interval in seconds
  201.                     num_screenshots = 100  # Number of screenshots
  202.                     threading.Thread(target=take_screenshots, args=(url, filename_base, interval, num_screenshots)).start()
  203.             else:
  204.                 messagebox.showerror("Error", "Selected text is not a valid URL.")
  205.         except tk.TclError:
  206.             messagebox.showerror("Error", "No text selected.")
  207.  
  208.     def stop_screenshots_capture(self):
  209.         self.stop_event.set()  # Set the stop event flag
  210.         messagebox.showinfo("Screenshot Capture", "Stopping screenshot capture.")
  211.  
  212. if __name__ == "__main__":
  213.     app = IPTVChannelPlayer()
  214.     app.mainloop()
  215.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement