SHARE
    TWEET
    Najeebsk

    IPTV-CHANNEL-URL-M3U.pyw

    Nov 29th, 2024
    1,943
    0
    Never
    Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
    Python 6.05 KB | None | 0 0
    1. import os
    2. import subprocess
    3. import tkinter as tk
    4. from tkinter import messagebox, scrolledtext, filedialog # Include filedialog here
    5. import requests
    6. # Paths for media players
    7. POTPLAYER_PATH = r"C:\Program Files\DAUM\PotPlayer\PotPlayerMini.exe"
    8. VLC_PATH = r"C:\Program Files\VideoLAN\VLC\vlc.exe"
    9. def fetch_playlist():
    10. """Fetch M3U playlist from the provided URL and display it."""
    11. url = url_entry.get().strip()
    12. if not url:
    13. messagebox.showwarning("Input Required", "Please enter a playlist URL.")
    14. return
    15. # Clear the results field
    16. results_field.delete(1.0, tk.END)
    17. try:
    18. # Fetch content from the URL
    19. response = requests.get(url, timeout=10)
    20. response.raise_for_status() # Raise an error for HTTP errors
    21. # Check if the response is a valid M3U playlist
    22. if not response.text.strip().startswith("#EXTM3U"):
    23. raise ValueError("The fetched file is not a valid M3U playlist.")
    24. # Display content in the results field
    25. results_field.insert(tk.END, response.text)
    26. messagebox.showinfo("Success", "Playlist fetched successfully.")
    27. except requests.exceptions.RequestException as e:
    28. messagebox.showerror("Network Error", f"Failed to fetch the playlist:\n{e}")
    29. except ValueError as ve:
    30. messagebox.showerror("Invalid Playlist", str(ve))
    31. def open_m3u_file():
    32. """Open an M3U file and display its contents in the results field."""
    33. file_path = filedialog.askopenfilename(
    34. filetypes=[("M3U Files", "*.m3u"), ("All Files", "*.*")]
    35. )
    36. if file_path:
    37. try:
    38. with open(file_path, "r", encoding="utf-8") as file:
    39. links = file.readlines()
    40. results_field.delete(1.0, tk.END)
    41. results_field.insert(tk.END, "".join(links))
    42. except Exception as e:
    43. messagebox.showerror("Error", f"Failed to open file: {e}")
    44. def save_m3u_file():
    45. """Save the M3U playlist content to a local file."""
    46. content = results_field.get(1.0, tk.END).strip()
    47. if not content:
    48. messagebox.showwarning("No Content", "No playlist content to save.")
    49. return
    50. try:
    51. with open("Channels.m3u", "w", encoding="utf-8") as file:
    52. file.write(content)
    53. messagebox.showinfo("Success", "File saved as Channels.m3u")
    54. except Exception as e:
    55. messagebox.showerror("Error", f"Failed to save file:\n{e}")
    56. def play_selected_link():
    57. """Play the selected link using the chosen media player."""
    58. try:
    59. # Retrieve the selected text
    60. selected_text = results_field.get(tk.SEL_FIRST, tk.SEL_LAST).strip()
    61. except tk.TclError:
    62. messagebox.showwarning("No Selection", "Please select a link to play.")
    63. return
    64. if not selected_text.startswith("http"):
    65. messagebox.showwarning("Invalid Selection", "Please select a valid URL.")
    66. return
    67. # Determine the player to use
    68. player_path = VLC_PATH if player_var.get() == "vlc" else POTPLAYER_PATH
    69. if not os.path.exists(player_path):
    70. messagebox.showerror(
    71. "Player Not Found", f"The selected player is not installed:\n{player_path}"
    72. )
    73. return
    74. try:
    75. # Use subprocess to launch the player with the selected URL
    76. subprocess.Popen([player_path, selected_text], shell=False)
    77. except Exception as e:
    78. messagebox.showerror("Error", f"Failed to play link: {e}")
    79. # Create the main Tkinter window
    80. root = tk.Tk()
    81. root.title("Najeeb Advanced IPTV URL Player")
    82. root.geometry("800x600")
    83. root.configure(bg="#2a2a2a")
    84. # Create styles
    85. header_font = ("Arial", 18, "bold")
    86. button_font = ("Arial", 12)
    87. text_font = ("Courier", 12)
    88. bg_color = "#1f1f1f"
    89. fg_color = "#ffffff"
    90. button_color = "#5a9bd3"
    91. highlight_color = "#ff9f43"
    92. # Header
    93. header_label = tk.Label(
    94. root, text="Najeeb Advanced IPTV URL Player", font=header_font, bg=bg_color, fg=highlight_color
    95. )
    96. header_label.pack(pady=10)
    97. # URL entry frame
    98. url_frame = tk.Frame(root, bg=bg_color)
    99. url_frame.pack(pady=10, fill=tk.X, padx=10)
    100. url_label = tk.Label(
    101. url_frame, text="Playlist URL:", font=button_font, bg=bg_color, fg=fg_color
    102. )
    103. url_label.pack(side=tk.LEFT, padx=5)
    104. url_entry = tk.Entry(url_frame, font=text_font, bg="#333333", fg=fg_color, insertbackground=fg_color, width=40)
    105. url_entry.pack(side=tk.LEFT, padx=5, fill=tk.X, expand=True)
    106. fetch_button = tk.Button(
    107. url_frame, text="Fetch Playlist", font=button_font, bg=button_color, fg=fg_color, command=fetch_playlist
    108. )
    109. fetch_button.pack(side=tk.LEFT, padx=5)
    110. # Buttons frame
    111. buttons_frame = tk.Frame(root, bg=bg_color)
    112. buttons_frame.pack(pady=10)
    113. open_button = tk.Button(
    114. buttons_frame, text="Open M3U File", font=button_font, bg=button_color, fg=fg_color, command=open_m3u_file
    115. )
    116. open_button.grid(row=0, column=0, padx=5)
    117. save_button = tk.Button(
    118. buttons_frame, text="Save File", font=button_font, bg=button_color, fg=fg_color, command=save_m3u_file
    119. )
    120. save_button.grid(row=0, column=1, padx=5)
    121. play_button = tk.Button(
    122. buttons_frame, text="Play Selected Link", font=button_font, bg=button_color, fg=fg_color, command=play_selected_link
    123. )
    124. play_button.grid(row=0, column=2, padx=5)
    125. # Player selection
    126. player_var = tk.StringVar(value="vlc")
    127. player_frame = tk.Frame(root, bg=bg_color)
    128. player_frame.pack(pady=5)
    129. vlc_radio = tk.Radiobutton(
    130. player_frame, text="VLC Player", variable=player_var, value="vlc", bg=bg_color, fg=fg_color, selectcolor=bg_color
    131. )
    132. vlc_radio.grid(row=0, column=0, padx=10)
    133. potplayer_radio = tk.Radiobutton(
    134. player_frame, text="PotPlayer", variable=player_var, value="potplayer", bg=bg_color, fg=fg_color, selectcolor=bg_color
    135. )
    136. potplayer_radio.grid(row=0, column=1, padx=10)
    137. # Results field
    138. results_field = scrolledtext.ScrolledText(
    139. root, font=text_font, bg="#333333", fg=fg_color, insertbackground=fg_color, wrap=tk.WORD
    140. )
    141. results_field.pack(fill=tk.BOTH, expand=True, padx=10, pady=10)
    142. # Run the main event loop
    143. 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 によって変換されたページ (->オリジナル) /