Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- from tkinter import messagebox, filedialog
- import requests
- import subprocess
- import vlc
- import threading
- import time
- def browse_file():
- filename = filedialog.askopenfilename(filetypes=[("Text files", "*.txt")])
- if filename:
- try:
- with open(filename, "r", encoding="utf-8") as file:
- content = file.read()
- playlist_entry.delete("1.0", "end")
- playlist_entry.insert("1.0", content)
- except UnicodeDecodeError:
- try:
- with open(filename, "r", encoding="iso-8859-1") as file:
- content = file.read()
- playlist_entry.delete("1.0", "end")
- playlist_entry.insert("1.0", content)
- except UnicodeDecodeError:
- messagebox.showerror("Error", "Failed to decode file. The file might be corrupted or use an unsupported encoding.")
- def check_links():
- playlist_text = playlist_entry.get("1.0", "end-1c")
- links = playlist_text.split('\n')
- valid_links = []
- for link in links:
- if link.strip() == "":
- continue
- try:
- response = requests.head(link, timeout=5) # added timeout to avoid hanging
- if response.status_code == 200:
- valid_links.append(link)
- except requests.RequestException:
- pass
- if valid_links:
- messagebox.showinfo("Valid Links", "Valid links found!")
- result_text.set(f"{len(valid_links)} valid links found.")
- else:
- messagebox.showinfo("No Valid Links", "No valid links found!")
- result_text.set("No valid links found.")
- return valid_links
- def save_valid_links():
- valid_links = check_links()
- if valid_links:
- with open("Valid_Playlist.txt", "w", encoding="utf-8") as file:
- file.write("\n".join(valid_links))
- messagebox.showinfo("Saved", "Valid links saved to Valid_Playlist.txt")
- def play_selected_link():
- try:
- selected_text = playlist_entry.get(tk.SEL_FIRST, tk.SEL_LAST).strip()
- if selected_text.startswith("http"):
- subprocess.Popen([r"C:\Program Files\VideoLAN\VLC\vlc.exe", selected_text])
- else:
- messagebox.showerror("Error", "Selected text is not a valid URL.")
- except tk.TclError:
- messagebox.showerror("Error", "No text selected.")
- def preview_selected_link():
- try:
- selected_text = playlist_entry.get(tk.SEL_FIRST, tk.SEL_LAST).strip()
- if selected_text.startswith("http"):
- preview_frame.pack(fill="both", expand=True) # Show the preview frame
- media = instance.media_new(selected_text)
- player.set_media(media)
- player.play()
- update_slider()
- else:
- messagebox.showerror("Error", "Selected text is not a valid URL.")
- except tk.TclError:
- messagebox.showerror("Error", "No text selected.")
- def stop_preview():
- player.stop()
- preview_frame.pack_forget() # Hide the preview frame
- def capture_video():
- try:
- selected_text = playlist_entry.get(tk.SEL_FIRST, tk.SEL_LAST).strip()
- if selected_text.startswith("http"):
- filename = filedialog.asksaveasfilename(defaultextension=".mp4", filetypes=[("MP4 files", "*.mp4")])
- if filename:
- # Run FFMPEG command to capture 5 minutes of video
- command = [
- 'ffmpeg', '-y', '-i', selected_text, '-t', '00:05:00', '-c', 'copy', filename
- ]
- threading.Thread(target=lambda: subprocess.run(command)).start()
- messagebox.showinfo("Capturing", f"Capturing 5 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 capture_screenshot():
- #if player.get_media():
- #filename = filedialog.asksaveasfilename(defaultextension=".png", filetypes=[("PNG files", "*.png")])
- #if filename:
- #player.video_take_snapshot(0, filename, 0, 0)
- #messagebox.showinfo("Captured", f"Screenshot saved to {filename}")
- def capture_screenshots():
- if player.get_media():
- filename_base = filedialog.asksaveasfilename(defaultextension=".png", filetypes=[("PNG files", "*.png")])
- if filename_base:
- interval = 5 # Interval between screenshots in seconds
- num_screenshots = 5 # Number of screenshots to capture
- for i in range(num_screenshots):
- time.sleep(interval)
- filename = f"{filename_base}_{i+1}.png"
- player.video_take_snapshot(0, filename, 0, 0)
- messagebox.showinfo("Captured", f"Screenshot {i+1} saved to {filename}")
- def search_links():
- search_term = search_entry.get().strip()
- playlist_text = playlist_entry.get("1.0", "end-1c")
- if search_term:
- playlist_entry.tag_remove("highlight", "1.0", "end")
- start_idx = "1.0"
- while True:
- start_idx = playlist_entry.search(search_term, start_idx, stopindex="end")
- if not start_idx:
- break
- end_idx = f"{start_idx}+{len(search_term)}c"
- playlist_entry.tag_add("highlight", start_idx, end_idx)
- start_idx = end_idx
- # Move the view to the start of the found search term
- playlist_entry.see(start_idx)
- playlist_entry.tag_config("highlight", background="yellow", foreground="black")
- # Update the slider position based on the current video position
- def update_slider():
- if player.get_media():
- length = player.get_length() / 1000 # Get the length in seconds
- position = player.get_time() / 1000 # Get the current position in seconds
- if length > 0:
- slider.set(position / length * 100)
- root.after(1000, update_slider)
- # Change the video position when the slider is moved
- def set_position(event):
- if player.get_media():
- length = player.get_length() / 1000 # Get the length in seconds
- player.set_time(int(slider.get() / 100 * length * 1000))
- #def toggle_mute():
- #is_muted = player.audio_get_mute()
- #player.audio_set_mute(not is_muted)
- def set_volume(value):
- player.audio_set_volume(int(value))
- # GUI
- root = tk.Tk()
- root.title("Najeeb IPTV Channel Link Checker")
- root.configure(bg="#4a4a4a") # Set background color of the main window
- playlist_label = tk.Label(root, text="Paste Playlist:", bg="#4a4a4a", fg="white")
- playlist_label.pack()
- # Frame for text widget and scrollbar
- text_frame = tk.Frame(root, bg="#4a4a4a")
- text_frame.pack()
- playlist_entry = tk.Text(text_frame, height=16, width=120, bg="#2b2b2b", fg="white", insertbackground="white")
- playlist_entry.pack(side=tk.LEFT)
- scrollbar = tk.Scrollbar(text_frame)
- scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
- playlist_entry.config(yscrollcommand=scrollbar.set)
- scrollbar.config(command=playlist_entry.yview)
- # Frame for buttons and search entry in one row
- button_frame = tk.Frame(root, bg="#4a4a4a")
- button_frame.pack()
- button_bg_color = "#5a5a5a"
- button_fg_color = "white"
- browse_button = tk.Button(button_frame, text="Browse Playlist", command=browse_file, bg=button_bg_color, fg=button_fg_color)
- browse_button.pack(side=tk.LEFT, padx=5)
- check_button = tk.Button(button_frame, text="Check Links", command=check_links, bg=button_bg_color, fg=button_fg_color)
- check_button.pack(side=tk.LEFT, padx=5)
- save_button = tk.Button(button_frame, text="Save Valid Links", command=save_valid_links, bg=button_bg_color, fg=button_fg_color)
- save_button.pack(side=tk.LEFT, padx=5)
- play_button = tk.Button(button_frame, text="Play Selected Link", command=play_selected_link, bg=button_bg_color, fg=button_fg_color)
- play_button.pack(side=tk.LEFT, padx=5)
- search_label = tk.Label(button_frame, text="Search:", bg="#4a4a4a", fg="white")
- search_label.pack(side=tk.LEFT, padx=5)
- search_entry = tk.Entry(button_frame, bg="#2b2b2b", fg="white", insertbackground="white")
- search_entry.pack(side=tk.LEFT, padx=5)
- search_button = tk.Button(button_frame, text="Search", command=search_links, bg=button_bg_color, fg=button_fg_color)
- search_button.pack(side=tk.LEFT, padx=5)
- preview_button = tk.Button(button_frame, text="Preview", command=preview_selected_link, bg=button_bg_color, fg=button_fg_color)
- preview_button.pack(side=tk.LEFT, padx=5)
- #toggle_mute_button = tk.Button(button_frame, text="Toggle Audio Mute", command=toggle_mute, bg="#5a5a5a", fg="white")
- #toggle_mute_button.pack(side=tk.LEFT, padx=5)
- volume_scale = tk.Scale(root, from_=0, to=100, orient="vertical", command=set_volume, label="", bg="#4a4a4a", fg="white")
- volume_scale.set(50) # Set the initial volume to 50%
- volume_scale.pack(side="left", fill="x", padx=5, pady=5)
- # Frame for previewing the video
- preview_frame = tk.Frame(root, bg="#4a4a4a", height=200)
- preview_frame.pack(fill="both", expand=True)
- preview_frame.pack_forget() # Hide initially
- canvas = tk.Canvas(preview_frame, bg="#4a4a4a")
- canvas.pack(fill="both", expand=True)
- capture_button = tk.Button(preview_frame, text="Capture Video", command=capture_video, bg=button_bg_color, fg=button_fg_color)
- capture_button.pack(side=tk.LEFT, padx=5)
- screenshot_button = tk.Button(preview_frame, text="Capture Screenshots", command=capture_screenshots, bg=button_bg_color, fg=button_fg_color)
- screenshot_button.pack(side=tk.LEFT, padx=5)
- stop_button = tk.Button(preview_frame, text="Close Preview", command=stop_preview, bg=button_bg_color, fg=button_fg_color)
- stop_button.pack(side=tk.LEFT, padx=5)
- # Slider for video position
- slider = tk.Scale(preview_frame, from_=0, to=100, orient=tk.HORIZONTAL, command=set_position, bg="#4a4a4a", fg="white")
- slider.pack(fill="x", padx=5)
- # VLC player setup
- instance = vlc.Instance()
- player = instance.media_player_new()
- def on_configure(event):
- if event.widget == canvas:
- #player.set_xwindow(canvas.winfo_id()) # for Linux
- player.set_hwnd(canvas.winfo_id()) # for Windows
- # player.set_nsobject(canvas.winfo_id()) # for macOS
- canvas.bind("<Configure>", on_configure)
- # Label for displaying results
- result_text = tk.StringVar()
- result_label = tk.Label(root, textvariable=result_text, bg="#4a4a4a", fg="white")
- result_label.pack()
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement