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
- 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()
- except UnicodeDecodeError:
- try:
- with open(filename, "r", encoding="iso-8859-1") as file:
- content = file.read()
- except UnicodeDecodeError:
- messagebox.showerror("Error", "Failed to decode file. The file might be corrupted or use an unsupported encoding.")
- return
- playlist_entry.delete("1.0", "end")
- playlist_entry.insert("1.0", content)
- 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 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")
- # 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=36, 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)
- # 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