Advertisement
Najeebsk

CHECK-IPTV-TEXT.pyw

May 16th, 2024 (edited)
736
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.13 KB | None | 0 0
  1. import tkinter as tk
  2. from tkinter import messagebox, filedialog
  3. import requests
  4. import subprocess
  5.  
  6. def browse_file():
  7.     filename = filedialog.askopenfilename(filetypes=[("Text files", "*.txt")])
  8.     if filename:
  9.         try:
  10.             with open(filename, "r", encoding="utf-8") as file:
  11.                 content = file.read()
  12.         except UnicodeDecodeError:
  13.             try:
  14.                 with open(filename, "r", encoding="iso-8859-1") as file:
  15.                     content = file.read()
  16.             except UnicodeDecodeError:
  17.                 messagebox.showerror("Error", "Failed to decode file. The file might be corrupted or use an unsupported encoding.")
  18.                 return
  19.         playlist_entry.delete("1.0", "end")
  20.         playlist_entry.insert("1.0", content)
  21.  
  22. def check_links():
  23.     playlist_text = playlist_entry.get("1.0", "end-1c")
  24.     links = playlist_text.split('\n')
  25.    
  26.     valid_links = []
  27.     for link in links:
  28.         if link.strip() == "":
  29.             continue
  30.         try:
  31.             response = requests.head(link, timeout=5)  # added timeout to avoid hanging
  32.             if response.status_code == 200:
  33.                 valid_links.append(link)
  34.         except requests.RequestException:
  35.             pass
  36.    
  37.     if valid_links:
  38.         messagebox.showinfo("Valid Links", "Valid links found!")
  39.         result_text.set(f"{len(valid_links)} valid links found.")
  40.     else:
  41.         messagebox.showinfo("No Valid Links", "No valid links found!")
  42.         result_text.set("No valid links found.")
  43.    
  44.     return valid_links
  45.  
  46. def save_valid_links():
  47.     valid_links = check_links()
  48.     if valid_links:
  49.         with open("Valid_Playlist.txt", "w", encoding="utf-8") as file:
  50.             file.write("\n".join(valid_links))
  51.         messagebox.showinfo("Saved", "Valid links saved to Valid_Playlist.txt")
  52.  
  53. def play_selected_link():
  54.     try:
  55.         selected_text = playlist_entry.get(tk.SEL_FIRST, tk.SEL_LAST).strip()
  56.         if selected_text.startswith("http"):
  57.             subprocess.Popen([r"C:\Program Files\VideoLAN\VLC\vlc.exe", selected_text])
  58.         else:
  59.             messagebox.showerror("Error", "Selected text is not a valid URL.")
  60.     except tk.TclError:
  61.         messagebox.showerror("Error", "No text selected.")
  62.  
  63. def search_links():
  64.     search_term = search_entry.get().strip()
  65.     playlist_text = playlist_entry.get("1.0", "end-1c")
  66.    
  67.     if search_term:
  68.         playlist_entry.tag_remove("highlight", "1.0", "end")
  69.        
  70.         start_idx = "1.0"
  71.         while True:
  72.             start_idx = playlist_entry.search(search_term, start_idx, stopindex="end")
  73.             if not start_idx:
  74.                 break
  75.             end_idx = f"{start_idx}+{len(search_term)}c"
  76.             playlist_entry.tag_add("highlight", start_idx, end_idx)
  77.             start_idx = end_idx
  78.             # Move the view to the start of the found search term
  79.             playlist_entry.see(start_idx)
  80.            
  81.         playlist_entry.tag_config("highlight", background="yellow", foreground="black")
  82.  
  83. # GUI
  84. root = tk.Tk()
  85. root.title("Najeeb IPTV Channel Link Checker")
  86. root.configure(bg="#4a4a4a")  # Set background color of the main window
  87.  
  88. playlist_label = tk.Label(root, text="Paste Playlist:", bg="#4a4a4a", fg="white")
  89. playlist_label.pack()
  90.  
  91. # Frame for text widget and scrollbar
  92. text_frame = tk.Frame(root, bg="#4a4a4a")
  93. text_frame.pack()
  94.  
  95. playlist_entry = tk.Text(text_frame, height=36, width=120, bg="#2b2b2b", fg="white", insertbackground="white")
  96. playlist_entry.pack(side=tk.LEFT)
  97.  
  98. scrollbar = tk.Scrollbar(text_frame)
  99. scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
  100.  
  101. playlist_entry.config(yscrollcommand=scrollbar.set)
  102. scrollbar.config(command=playlist_entry.yview)
  103.  
  104. # Frame for buttons and search entry in one row
  105. button_frame = tk.Frame(root, bg="#4a4a4a")
  106. button_frame.pack()
  107.  
  108. button_bg_color = "#5a5a5a"
  109. button_fg_color = "white"
  110.  
  111. browse_button = tk.Button(button_frame, text="Browse Playlist", command=browse_file, bg=button_bg_color, fg=button_fg_color)
  112. browse_button.pack(side=tk.LEFT, padx=5)
  113.  
  114. check_button = tk.Button(button_frame, text="Check Links", command=check_links, bg=button_bg_color, fg=button_fg_color)
  115. check_button.pack(side=tk.LEFT, padx=5)
  116.  
  117. save_button = tk.Button(button_frame, text="Save Valid Links", command=save_valid_links, bg=button_bg_color, fg=button_fg_color)
  118. save_button.pack(side=tk.LEFT, padx=5)
  119.  
  120. play_button = tk.Button(button_frame, text="Play Selected Link", command=play_selected_link, bg=button_bg_color, fg=button_fg_color)
  121. play_button.pack(side=tk.LEFT, padx=5)
  122.  
  123. search_label = tk.Label(button_frame, text="Search:", bg="#4a4a4a", fg="white")
  124. search_label.pack(side=tk.LEFT, padx=5)
  125.  
  126. search_entry = tk.Entry(button_frame, bg="#2b2b2b", fg="white", insertbackground="white")
  127. search_entry.pack(side=tk.LEFT, padx=5)
  128.  
  129. search_button = tk.Button(button_frame, text="Search", command=search_links, bg=button_bg_color, fg=button_fg_color)
  130. search_button.pack(side=tk.LEFT, padx=5)
  131.  
  132. # Label for displaying results
  133. result_text = tk.StringVar()
  134. result_label = tk.Label(root, textvariable=result_text, bg="#4a4a4a", fg="white")
  135. result_label.pack()
  136.  
  137. root.mainloop()
  138.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement