Advertisement
Najeebsk

CHECK-IPTV-TEXT-PREVIWE.pyw

May 18th, 2024 (edited)
520
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 10.46 KB | None | 0 0
  1. import tkinter as tk
  2. from tkinter import messagebox, filedialog
  3. import requests
  4. import subprocess
  5. import vlc
  6. import threading
  7. import time
  8.  
  9. def browse_file():
  10.     filename = filedialog.askopenfilename(filetypes=[("Text files", "*.txt")])
  11.     if filename:
  12.         try:
  13.             with open(filename, "r", encoding="utf-8") as file:
  14.                 content = file.read()
  15.             playlist_entry.delete("1.0", "end")
  16.             playlist_entry.insert("1.0", content)
  17.         except UnicodeDecodeError:
  18.             try:
  19.                 with open(filename, "r", encoding="iso-8859-1") as file:
  20.                     content = file.read()
  21.                 playlist_entry.delete("1.0", "end")
  22.                 playlist_entry.insert("1.0", content)
  23.             except UnicodeDecodeError:
  24.                 messagebox.showerror("Error", "Failed to decode file. The file might be corrupted or use an unsupported encoding.")
  25.  
  26. def check_links():
  27.     playlist_text = playlist_entry.get("1.0", "end-1c")
  28.     links = playlist_text.split('\n')
  29.    
  30.     valid_links = []
  31.     for link in links:
  32.         if link.strip() == "":
  33.             continue
  34.         try:
  35.             response = requests.head(link, timeout=5)  # added timeout to avoid hanging
  36.             if response.status_code == 200:
  37.                 valid_links.append(link)
  38.         except requests.RequestException:
  39.             pass
  40.    
  41.     if valid_links:
  42.         messagebox.showinfo("Valid Links", "Valid links found!")
  43.         result_text.set(f"{len(valid_links)} valid links found.")
  44.     else:
  45.         messagebox.showinfo("No Valid Links", "No valid links found!")
  46.         result_text.set("No valid links found.")
  47.    
  48.     return valid_links
  49.  
  50. def save_valid_links():
  51.     valid_links = check_links()
  52.     if valid_links:
  53.         with open("Valid_Playlist.txt", "w", encoding="utf-8") as file:
  54.             file.write("\n".join(valid_links))
  55.         messagebox.showinfo("Saved", "Valid links saved to Valid_Playlist.txt")
  56.  
  57. def play_selected_link():
  58.     try:
  59.         selected_text = playlist_entry.get(tk.SEL_FIRST, tk.SEL_LAST).strip()
  60.         if selected_text.startswith("http"):
  61.             subprocess.Popen([r"C:\Program Files\VideoLAN\VLC\vlc.exe", selected_text])
  62.         else:
  63.             messagebox.showerror("Error", "Selected text is not a valid URL.")
  64.     except tk.TclError:
  65.         messagebox.showerror("Error", "No text selected.")
  66.  
  67. def preview_selected_link():
  68.     try:
  69.         selected_text = playlist_entry.get(tk.SEL_FIRST, tk.SEL_LAST).strip()
  70.         if selected_text.startswith("http"):
  71.             preview_frame.pack(fill="both", expand=True)  # Show the preview frame
  72.             media = instance.media_new(selected_text)
  73.             player.set_media(media)
  74.             player.play()
  75.             update_slider()
  76.         else:
  77.             messagebox.showerror("Error", "Selected text is not a valid URL.")
  78.     except tk.TclError:
  79.         messagebox.showerror("Error", "No text selected.")
  80.  
  81. def stop_preview():
  82.     player.stop()
  83.     preview_frame.pack_forget()  # Hide the preview frame
  84.  
  85. def capture_video():
  86.     try:
  87.         selected_text = playlist_entry.get(tk.SEL_FIRST, tk.SEL_LAST).strip()
  88.         if selected_text.startswith("http"):
  89.             filename = filedialog.asksaveasfilename(defaultextension=".mp4", filetypes=[("MP4 files", "*.mp4")])
  90.             if filename:
  91.                 # Run FFMPEG command to capture 5 minutes of video
  92.                 command = [
  93.                     'ffmpeg', '-y', '-i', selected_text, '-t', '00:05:00', '-c', 'copy', filename
  94.                 ]
  95.                 threading.Thread(target=lambda: subprocess.run(command)).start()
  96.                 messagebox.showinfo("Capturing", f"Capturing 5 minutes of video to {filename}")
  97.         else:
  98.             messagebox.showerror("Error", "Selected text is not a valid URL.")
  99.     except tk.TclError:
  100.         messagebox.showerror("Error", "No text selected.")
  101.  
  102. #def capture_screenshot():
  103.     #if player.get_media():
  104.         #filename = filedialog.asksaveasfilename(defaultextension=".png", filetypes=[("PNG files", "*.png")])
  105.         #if filename:
  106.             #player.video_take_snapshot(0, filename, 0, 0)
  107.             #messagebox.showinfo("Captured", f"Screenshot saved to {filename}")
  108.  
  109. def capture_screenshots():
  110.     if player.get_media():
  111.         filename_base = filedialog.asksaveasfilename(defaultextension=".png", filetypes=[("PNG files", "*.png")])
  112.         if filename_base:
  113.             interval = 5  # Interval between screenshots in seconds
  114.             num_screenshots = 5  # Number of screenshots to capture
  115.             for i in range(num_screenshots):
  116.                 time.sleep(interval)
  117.                 filename = f"{filename_base}_{i+1}.png"
  118.                 player.video_take_snapshot(0, filename, 0, 0)
  119.                 messagebox.showinfo("Captured", f"Screenshot {i+1} saved to {filename}")
  120.                
  121. def search_links():
  122.     search_term = search_entry.get().strip()
  123.     playlist_text = playlist_entry.get("1.0", "end-1c")
  124.    
  125.     if search_term:
  126.         playlist_entry.tag_remove("highlight", "1.0", "end")
  127.        
  128.         start_idx = "1.0"
  129.         while True:
  130.             start_idx = playlist_entry.search(search_term, start_idx, stopindex="end")
  131.             if not start_idx:
  132.                 break
  133.             end_idx = f"{start_idx}+{len(search_term)}c"
  134.             playlist_entry.tag_add("highlight", start_idx, end_idx)
  135.             start_idx = end_idx
  136.             # Move the view to the start of the found search term
  137.             playlist_entry.see(start_idx)
  138.            
  139.         playlist_entry.tag_config("highlight", background="yellow", foreground="black")
  140.  
  141. # Update the slider position based on the current video position
  142. def update_slider():
  143.     if player.get_media():
  144.         length = player.get_length() / 1000  # Get the length in seconds
  145.         position = player.get_time() / 1000  # Get the current position in seconds
  146.         if length > 0:
  147.             slider.set(position / length * 100)
  148.         root.after(1000, update_slider)
  149.  
  150. # Change the video position when the slider is moved
  151. def set_position(event):
  152.     if player.get_media():
  153.         length = player.get_length() / 1000  # Get the length in seconds
  154.         player.set_time(int(slider.get() / 100 * length * 1000))
  155.        
  156. #def toggle_mute():
  157.     #is_muted = player.audio_get_mute()
  158.     #player.audio_set_mute(not is_muted)
  159.  
  160. def set_volume(value):
  161.         player.audio_set_volume(int(value))        
  162.        
  163. # GUI
  164. root = tk.Tk()
  165. root.title("Najeeb IPTV Channel Link Checker")
  166. root.configure(bg="#4a4a4a")  # Set background color of the main window
  167.  
  168. playlist_label = tk.Label(root, text="Paste Playlist:", bg="#4a4a4a", fg="white")
  169. playlist_label.pack()
  170.  
  171. # Frame for text widget and scrollbar
  172. text_frame = tk.Frame(root, bg="#4a4a4a")
  173. text_frame.pack()
  174.  
  175. playlist_entry = tk.Text(text_frame, height=16, width=120, bg="#2b2b2b", fg="white", insertbackground="white")
  176. playlist_entry.pack(side=tk.LEFT)
  177.  
  178. scrollbar = tk.Scrollbar(text_frame)
  179. scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
  180.  
  181. playlist_entry.config(yscrollcommand=scrollbar.set)
  182. scrollbar.config(command=playlist_entry.yview)
  183.  
  184. # Frame for buttons and search entry in one row
  185. button_frame = tk.Frame(root, bg="#4a4a4a")
  186. button_frame.pack()
  187.  
  188. button_bg_color = "#5a5a5a"
  189. button_fg_color = "white"
  190.  
  191. browse_button = tk.Button(button_frame, text="Browse Playlist", command=browse_file, bg=button_bg_color, fg=button_fg_color)
  192. browse_button.pack(side=tk.LEFT, padx=5)
  193.  
  194. check_button = tk.Button(button_frame, text="Check Links", command=check_links, bg=button_bg_color, fg=button_fg_color)
  195. check_button.pack(side=tk.LEFT, padx=5)
  196.  
  197. save_button = tk.Button(button_frame, text="Save Valid Links", command=save_valid_links, bg=button_bg_color, fg=button_fg_color)
  198. save_button.pack(side=tk.LEFT, padx=5)
  199.  
  200. play_button = tk.Button(button_frame, text="Play Selected Link", command=play_selected_link, bg=button_bg_color, fg=button_fg_color)
  201. play_button.pack(side=tk.LEFT, padx=5)
  202.  
  203. search_label = tk.Label(button_frame, text="Search:", bg="#4a4a4a", fg="white")
  204. search_label.pack(side=tk.LEFT, padx=5)
  205.  
  206. search_entry = tk.Entry(button_frame, bg="#2b2b2b", fg="white", insertbackground="white")
  207. search_entry.pack(side=tk.LEFT, padx=5)
  208.  
  209. search_button = tk.Button(button_frame, text="Search", command=search_links, bg=button_bg_color, fg=button_fg_color)
  210. search_button.pack(side=tk.LEFT, padx=5)
  211.  
  212. preview_button = tk.Button(button_frame, text="Preview", command=preview_selected_link, bg=button_bg_color, fg=button_fg_color)
  213. preview_button.pack(side=tk.LEFT, padx=5)
  214.  
  215. #toggle_mute_button = tk.Button(button_frame, text="Toggle Audio Mute", command=toggle_mute, bg="#5a5a5a", fg="white")
  216. #toggle_mute_button.pack(side=tk.LEFT, padx=5)
  217.  
  218. volume_scale = tk.Scale(root, from_=0, to=100, orient="vertical", command=set_volume, label="", bg="#4a4a4a", fg="white")
  219. volume_scale.set(50)  # Set the initial volume to 50%
  220. volume_scale.pack(side="left", fill="x", padx=5, pady=5)
  221.  
  222. # Frame for previewing the video
  223. preview_frame = tk.Frame(root, bg="#4a4a4a", height=200)
  224. preview_frame.pack(fill="both", expand=True)
  225. preview_frame.pack_forget()  # Hide initially
  226.  
  227. canvas = tk.Canvas(preview_frame, bg="#4a4a4a")
  228. canvas.pack(fill="both", expand=True)
  229.  
  230. capture_button = tk.Button(preview_frame, text="Capture Video", command=capture_video, bg=button_bg_color, fg=button_fg_color)
  231. capture_button.pack(side=tk.LEFT, padx=5)
  232.  
  233. screenshot_button = tk.Button(preview_frame, text="Capture Screenshots", command=capture_screenshots, bg=button_bg_color, fg=button_fg_color)
  234. screenshot_button.pack(side=tk.LEFT, padx=5)
  235.  
  236. stop_button = tk.Button(preview_frame, text="Close Preview", command=stop_preview, bg=button_bg_color, fg=button_fg_color)
  237. stop_button.pack(side=tk.LEFT, padx=5)
  238.  
  239. # Slider for video position
  240. slider = tk.Scale(preview_frame, from_=0, to=100, orient=tk.HORIZONTAL, command=set_position, bg="#4a4a4a", fg="white")
  241. slider.pack(fill="x", padx=5)
  242.  
  243. # VLC player setup
  244. instance = vlc.Instance()
  245. player = instance.media_player_new()
  246.  
  247. def on_configure(event):
  248.     if event.widget == canvas:
  249.         #player.set_xwindow(canvas.winfo_id())  # for Linux
  250.         player.set_hwnd(canvas.winfo_id())  # for Windows
  251.         # player.set_nsobject(canvas.winfo_id())  # for macOS
  252.  
  253. canvas.bind("<Configure>", on_configure)
  254.  
  255. # Label for displaying results
  256. result_text = tk.StringVar()
  257. result_label = tk.Label(root, textvariable=result_text, bg="#4a4a4a", fg="white")
  258. result_label.pack()
  259.  
  260. root.mainloop()
  261.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement