SHARE
    TWEET
    Najeebsk

    Extrac-Urls3.0.pyw

    Jun 25th, 2024
    681
    0
    Never
    Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
    Python 4.20 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. search_text = entry_search.get().lower()
    23. text_urls.config(state=tk.NORMAL)
    24. text_urls.delete(1.0, tk.END)
    25. filtered_urls = [url for url in urls if search_text in url.lower()]
    26. for url in filtered_urls:
    27. text_urls.insert(tk.END, url + "\n")
    28. text_urls.config(state=tk.NORMAL)
    29. def remove_duplicates():
    30. content = text_urls.get(1.0, tk.END).strip()
    31. urls = content.split('\n')
    32. unique_urls = list(dict.fromkeys(urls))
    33. text_urls.delete(1.0, tk.END)
    34. for url in unique_urls:
    35. text_urls.insert(tk.END, url + "\n")
    36. def save_urls():
    37. urls = text_urls.get(1.0, tk.END).strip().split('\n')
    38. if urls:
    39. try:
    40. with open("urls.txt", 'w', encoding='utf-8') as file:
    41. for index, url in enumerate(urls):
    42. if url:
    43. channel_name = f"Channel{index + 1}"
    44. file.write(f"{channel_name} {url}\n")
    45. messagebox.showinfo("Success", "URLs saved successfully to urls.txt.")
    46. except Exception as e:
    47. messagebox.showerror("Error", f"Failed to save file: {e}")
    48. else:
    49. messagebox.showwarning("No URLs", "No URLs to save.")
    50. def open_vlc(event):
    51. try:
    52. index = text_urls.index(tk.CURRENT)
    53. line_start = f"{index.split('.')[0]}.0"
    54. line_end = f"{index.split('.')[0]}.end"
    55. url = text_urls.get(line_start, line_end).strip()
    56. if url:
    57. vlc_path = r"C:\Program Files\VideoLAN\VLC\vlc.exe"
    58. subprocess.Popen([vlc_path, url])
    59. except Exception as e:
    60. messagebox.showerror("Error", f"Failed to open VLC: {e}")
    61. def search_urls(event):
    62. file_path = entry_file_path.get()
    63. if file_path:
    64. extract_urls(file_path)
    65. else:
    66. messagebox.showwarning("No File", "Please select a file first.")
    67. # Create the main window
    68. root = tk.Tk()
    69. root.title("Najeeb URL Extractor and Play VLC")
    70. root.configure(bg="#4a4a4a")
    71. root.geometry("740x680")
    72. # Apply style
    73. style = ttk.Style()
    74. style.theme_use('clam')
    75. style.configure("TFrame", background="#f0f0f0")
    76. style.configure("TLabel", background="#f0f0f0", foreground="#333")
    77. style.configure("TButton", background="#0052cc", foreground="white")
    78. style.map("TButton", background=[('active', '#003d99')])
    79. # Create and place the widgets
    80. frame = ttk.Frame(root, padding=10)
    81. frame.pack(pady=10)
    82. label_file_path = ttk.Label(frame, text="File Path:")
    83. label_file_path.grid(row=0, column=0, padx=5, pady=5)
    84. entry_file_path = ttk.Entry(frame, width=50)
    85. entry_file_path.grid(row=0, column=1, padx=5, pady=5)
    86. button_browse = ttk.Button(frame, text="Browse", command=browse_file)
    87. button_browse.grid(row=0, column=2, padx=5, pady=5)
    88. label_search = ttk.Label(frame, text="Search URL:")
    89. label_search.grid(row=1, column=0, padx=5, pady=5)
    90. entry_search = ttk.Entry(frame, width=50)
    91. entry_search.grid(row=1, column=1, padx=5, pady=5)
    92. entry_search.bind("<KeyRelease>", search_urls)
    93. button_save = ttk.Button(frame, text="Save URLs to File", command=save_urls)
    94. button_save.grid(row=0, column=3, pady=10)
    95. button_remove_duplicates = ttk.Button(frame, text="Remove Duplicates", command=remove_duplicates)
    96. button_remove_duplicates.grid(row=0, column=4, pady=10, padx=5)
    97. text_urls = scrolledtext.ScrolledText(root, width=100, height=33, state=tk.NORMAL, bg="#e6f2ff")
    98. text_urls.pack(padx=10, pady=10)
    99. text_urls.bind("<Double-1>", open_vlc)
    100. # Start the GUI event loop
    101. 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 によって変換されたページ (->オリジナル) /