SHARE
    TWEET
    Najeebsk

    IPTV-EXTRAC-URLS.pyw

    Jun 21st, 2024
    1,006
    0
    Never
    Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
    Python 3.63 KB | None | 0 0
    1. import tkinter as tk
    2. from tkinter import filedialog, messagebox, scrolledtext, ttk
    3. import re
    4. import subprocess
    5. def browse_file():
    6. file_path = filedialog.askopenfilename(
    7. filetypes=[("Text files", "*.txt"), ("All files", "*.*")]
    8. )
    9. if file_path:
    10. entry_file_path.delete(0, tk.END)
    11. entry_file_path.insert(0, file_path)
    12. extract_urls(file_path)
    13. def extract_urls(file_path):
    14. try:
    15. with open(file_path, 'r', encoding='utf-8', errors='ignore') as file:
    16. content = file.read()
    17. urls = re.findall(r'(https?://\S+)', content)
    18. display_urls(urls)
    19. except Exception as e:
    20. messagebox.showerror("Error", f"Failed to read file: {e}")
    21. def display_urls(urls):
    22. text_urls.config(state=tk.NORMAL)
    23. text_urls.delete(1.0, tk.END)
    24. for url in urls:
    25. text_urls.insert(tk.END, url + "\n")
    26. text_urls.config(state=tk.NORMAL)
    27. def remove_duplicates():
    28. content = text_urls.get(1.0, tk.END).strip()
    29. urls = content.split('\n')
    30. unique_urls = list(dict.fromkeys(urls))
    31. text_urls.delete(1.0, tk.END)
    32. for url in unique_urls:
    33. text_urls.insert(tk.END, url + "\n")
    34. def save_urls():
    35. urls = text_urls.get(1.0, tk.END).strip().split('\n')
    36. if urls:
    37. try:
    38. with open("urls.txt", 'w', encoding='utf-8') as file:
    39. for index, url in enumerate(urls):
    40. if url:
    41. channel_name = f"Channel{index + 1}"
    42. file.write(f"{channel_name} {url}\n")
    43. messagebox.showinfo("Success", "URLs saved successfully to urls.txt.")
    44. except Exception as e:
    45. messagebox.showerror("Error", f"Failed to save file: {e}")
    46. else:
    47. messagebox.showwarning("No URLs", "No URLs to save.")
    48. def open_vlc(event):
    49. try:
    50. index = text_urls.index(tk.CURRENT)
    51. line_start = f"{index.split('.')[0]}.0"
    52. line_end = f"{index.split('.')[0]}.end"
    53. url = text_urls.get(line_start, line_end).strip()
    54. if url:
    55. vlc_path = r"C:\Program Files\VideoLAN\VLC\vlc.exe"
    56. subprocess.Popen([vlc_path, url])
    57. except Exception as e:
    58. messagebox.showerror("Error", f"Failed to open VLC: {e}")
    59. # Create the main window
    60. root = tk.Tk()
    61. root.title("Najeeb URL Extractor and Play VLC")
    62. root.configure(bg="#4a4a4a")
    63. root.geometry("740x640")
    64. # Apply style
    65. style = ttk.Style()
    66. style.theme_use('clam')
    67. style.configure("TFrame", background="#f0f0f0")
    68. style.configure("TLabel", background="#f0f0f0", foreground="#333")
    69. style.configure("TButton", background="#0052cc", foreground="white")
    70. style.map("TButton", background=[('active', '#003d99')])
    71. # Create and place the widgets
    72. frame = ttk.Frame(root, padding=10)
    73. frame.pack(pady=10)
    74. label_file_path = ttk.Label(frame, text="File Path:")
    75. label_file_path.grid(row=0, column=0, padx=5, pady=5)
    76. entry_file_path = ttk.Entry(frame, width=50)
    77. entry_file_path.grid(row=0, column=1, padx=5, pady=5)
    78. button_browse = ttk.Button(frame, text="Browse", command=browse_file)
    79. button_browse.grid(row=0, column=2, padx=5, pady=5)
    80. button_save = ttk.Button(frame, text="Save URLs to File", command=save_urls)
    81. button_save.grid(row=0, column=3, pady=10)
    82. button_remove_duplicates = ttk.Button(frame, text="Remove Duplicates", command=remove_duplicates)
    83. button_remove_duplicates.grid(row=0, column=4, pady=10, padx=5)
    84. text_urls = scrolledtext.ScrolledText(root, width=100, height=33, state=tk.NORMAL, bg="#e6f2ff")
    85. text_urls.pack(padx=10, pady=10)
    86. text_urls.bind("<Double-1>", open_vlc)
    87. # Start the GUI event loop
    88. root.mainloop()
    Advertisement
    Add Comment
    Please, Sign In to add comment
    Public Pastes
    We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
    Not a member of Pastebin yet?
    Sign Up, it unlocks many cool features!

    AltStyle によって変換されたページ (->オリジナル) /