Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import tkinter as tk
- from tkinter import ttk, filedialog, messagebox
- import requests
- import subprocess
- import threading
- import time
- import vlc
- # Functions for the main functionalities
- def search_channels():
- search_term = url_entry.get().lower()
- if search_term.startswith("http"):
- search_by_url(search_term)
- else:
- search_by_path_or_category(search_term)
- def search_by_url(url):
- try:
- if os.path.exists(url):
- with open(url, 'r', encoding='utf-8') as file:
- m3u_data = file.readlines()
- process_m3u_data(m3u_data)
- else:
- response = requests.get(url)
- if response.status_code == 200:
- try:
- m3u_data = response.text.split('\n')
- except UnicodeDecodeError:
- m3u_data = response.content.decode('ISO-8859-1').split('\n')
- process_m3u_data(m3u_data)
- else:
- result_text.insert(tk.END, f"Error: Failed to fetch channel data. Status Code: {response.status_code}\n")
- except Exception as e:
- result_text.insert(tk.END, f"Error: {str(e)}\n")
- def search_by_path_or_category(path):
- try:
- if os.path.exists(path):
- try:
- with open(path, 'r', encoding='utf-8') as file:
- m3u_data = file.readlines()
- except UnicodeDecodeError:
- with open(path, 'r', encoding='ISO-8859-1') as file:
- m3u_data = file.readlines()
- process_m3u_data(m3u_data)
- else:
- selected_category = category_var.get()
- if selected_category in category_urls:
- category_url = category_urls[selected_category]
- if category_url:
- search_by_url(category_url)
- else:
- result_text.insert(tk.END, f"Error: Category URL is not provided for {selected_category}\n")
- else:
- result_text.insert(tk.END, f"Error: Category '{selected_category}' not found\n")
- except Exception as e:
- result_text.insert(tk.END, f"Error: {str(e)}\n")
- def process_m3u_data(m3u_data):
- result_text.delete(0, tk.END)
- global channels_info
- channels_info = {}
- channel_name = None
- for line in m3u_data:
- if line.startswith('#EXTINF:'):
- channel_name = line.split(',')[-1].strip()
- elif line.startswith('http') and channel_name:
- channels_info[channel_name] = line.strip()
- result_text.insert(tk.END, channel_name)
- channel_name = None
- def play_selected_channel(event):
- try:
- selected_channel = result_text.get(tk.ACTIVE)
- if os.path.exists(selected_channel):
- subprocess.Popen([r"C:\Program Files\VideoLAN\VLC\vlc.exe", selected_channel])
- else:
- subprocess.Popen([r"C:\Program Files\VideoLAN\VLC\vlc.exe", channels_info[selected_channel]])
- except (tk.TclError, KeyError):
- pass
- def check_links():
- global working_links
- working_links = {}
- for channel_name, url in channels_info.items():
- try:
- response = requests.get(url)
- if response.status_code == 200:
- working_links[channel_name] = url
- except requests.RequestException:
- pass
- result_text.delete(0, tk.END)
- for channel_name, url in working_links.items():
- result_text.insert(tk.END, f"{channel_name}: {url}\n")
- def save_working_links():
- with open("working_channels.m3u", "w", encoding="utf-8") as f:
- for channel_name, url in working_links.items():
- f.write(f"#EXTINF:-1,{channel_name}\n{url}\n")
- def filter_channels(event=None):
- keyword = search_entry.get().lower()
- result_text.delete(0, tk.END)
- for channel_name, url in channels_info.items():
- if keyword in channel_name.lower():
- result_text.insert(tk.END, channel_name)
- def browse_file():
- file_path = filedialog.askopenfilename(filetypes=[("M3U Files", "*.m3u"), ("All Files", "*.*")])
- if file_path:
- url_entry.delete(0, tk.END)
- url_entry.insert(0, file_path)
- def preview_selected_link():
- try:
- selected_channel = result_text.get(tk.ACTIVE).strip()
- if selected_channel in channels_info:
- url = channels_info[selected_channel]
- preview_frame.pack(fill="both", expand=True)
- media = instance.media_new(url)
- player.set_media(media)
- player.play()
- update_slider()
- else:
- messagebox.showerror("Error", "Selected text is not a valid URL.")
- except tk.TclError:
- messagebox.showerror("Error", "No text selected.")
- def stop_preview():
- player.stop()
- preview_frame.pack_forget()
- def capture_video():
- try:
- selected_channel = result_text.get(tk.ACTIVE).strip()
- if selected_channel in channels_info:
- url = channels_info[selected_channel]
- filename = filedialog.asksaveasfilename(defaultextension=".mp4", filetypes=[("MP4 files", "*.mp4")])
- if filename:
- command = ['ffmpeg', '-y', '-i', url, '-t', '03:55:00', '-c', 'copy', filename]
- threading.Thread(target=lambda: subprocess.run(command)).start()
- messagebox.showinfo("Capturing", f"Capturing 03:55 minutes of video to {filename}")
- else:
- messagebox.showerror("Error", "Selected text is not a valid URL.")
- except tk.TclError:
- messagebox.showerror("Error", "No text selected.")
- def record_audio():
- try:
- selected_channel = result_text.get(tk.ACTIVE).strip()
- if selected_channel in channels_info:
- url = channels_info[selected_channel]
- filename = filedialog.asksaveasfilename(defaultextension=".mp3", filetypes=[("MP3 files", "*.mp3")])
- if filename:
- command = ['ffmpeg', '-y', '-i', url, '-f', 'mp3', '-c:a', 'libmp3lame', filename]
- global process
- process = subprocess.Popen(command)
- messagebox.showinfo("Recording", f"Recording audio to {filename}")
- else:
- messagebox.showerror("Error", "Selected text is not a valid URL.")
- except tk.TclError:
- messagebox.showerror("Error", "No text selected.")
- def stop_recording():
- if process:
- process.terminate()
- messagebox.showinfo("Stopped", "Recording stopped")
- def capture_screenshots():
- if player.get_media():
- filename_base = filedialog.asksaveasfilename(defaultextension=".png", filetypes=[("PNG files", "*.png")])
- if filename_base:
- interval = 5
- num_screenshots = 5
- for i in range(num_screenshots):
- time.sleep(interval)
- filename = f"{filename_base}_{i+1}.png"
- player.video_take_snapshot(0, filename, 0, 0)
- messagebox.showinfo("Captured", f"Screenshot {i+1} saved to {filename}")
- def update_slider():
- if player.get_media():
- length = player.get_length() / 1000
- position = player.get_time() / 1000
- if length > 0:
- slider.set(position / length * 100)
- root.after(1000, update_slider)
- def set_position(event):
- if player.get_media():
- length = player.get_length() / 1000
- player.set_time(int(slider.get() / 100 * length * 1000))
- def on_configure(event):
- if event.widget == canvas:
- player.set_hwnd(canvas.winfo_id())
- def toggle_mute():
- is_muted = player.audio_get_mute()
- player.audio_set_mute(not is_muted)
- # GUI setup
- root = tk.Tk()
- root.title("Najeeb IPTV Channel Link Checker")
- root.configure(bg="#4a4a4a")
- url_frame = tk.Frame(root, bg="#4a4a4a")
- url_frame.pack(pady=10)
- url_label = tk.Label(url_frame, text="Enter URL or local path or select category:", bg="#4a4a4a", fg="white")
- url_label.pack(side=tk.LEFT, padx=5)
- url_entry = tk.Entry(url_frame, width=80)
- url_entry.pack(side=tk.LEFT, padx=5)
- search_button = tk.Button(url_frame, text="Search", command=search_channels, bg="#FFA500", fg="white")
- search_button.pack(side=tk.LEFT, padx=5)
- #result_label = tk.Label(root, text="Check and save working URLs in M3U file:", bg="#4a4a4a", fg="white")
- #result_label.pack()
- search_frame = tk.Frame(root, bg="#4a4a4a")
- search_frame.pack()
- search_label = tk.Label(search_frame, text="Search Channel Name:", bg="#4a4a4a", fg="white")
- search_label.pack(side=tk.LEFT, padx=5)
- search_entry = tk.Entry(search_frame, width=105)
- search_entry.pack(side=tk.LEFT, padx=5)
- search_entry.bind('<KeyRelease>', filter_channels)
- result_frame = tk.Frame(root)
- result_frame.pack(pady=10)
- scrollbar = tk.Scrollbar(result_frame)
- scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
- result_text = tk.Listbox(result_frame, width=150, height=12, bg="#333333", fg="white", selectbackground="#FFA500", selectforeground="black", yscrollcommand=scrollbar.set)
- result_text.pack(side=tk.LEFT, fill=tk.BOTH)
- result_text.bind('<Double-1>', play_selected_channel)
- scrollbar.config(command=result_text.yview)
- button_frame = tk.Frame(root, bg="#4a4a4a")
- button_frame.pack()
- browse_button = tk.Button(button_frame, text="Browse Playlist", command=browse_file, bg="#5a5a5a", fg="white")
- browse_button.pack(side=tk.LEFT, padx=5)
- preview_button = tk.Button(button_frame, text="Preview", command=preview_selected_link, bg="#5a5a5a", fg="white")
- preview_button.pack(side=tk.LEFT, padx=5)
- capture_video_button = tk.Button(button_frame, text="Capture Video", command=capture_video, bg="#5a5a5a", fg="white")
- capture_video_button.pack(side=tk.LEFT, padx=5)
- record_button = tk.Button(button_frame, text="Record Audio", command=record_audio, bg="#5a5a5a", fg="white")
- record_button.pack(side=tk.LEFT, padx=5)
- stop_recording_button = tk.Button(button_frame, text="Stop Recording", command=stop_recording, bg="#5a5a5a", fg="white")
- stop_recording_button.pack(side=tk.LEFT, padx=5)
- capture_screenshot_button = tk.Button(button_frame, text="Capture Screenshots", command=capture_screenshots, bg="#5a5a5a", fg="white")
- capture_screenshot_button.pack(side=tk.LEFT, padx=5)
- toggle_mute_button = tk.Button(button_frame, text="Toggle Audio Mute", command=toggle_mute, bg="#5a5a5a", fg="white")
- toggle_mute_button.pack(side=tk.LEFT, padx=5)
- category_urls = {
- "NAJEEB-IPTV": "",
- "ALL-INDEX": "https://iptv-org.github.io/iptv/index.m3u",
- "CATEGORY": "https://iptv-org.github.io/iptv/index.category.m3u",
- "LANGUAGE": "https://iptv-org.github.io/iptv/index.language.m3u",
- "REGION": "https://iptv-org.github.io/iptv/index.region.m3u",
- "Brazil": "https://iptv-org.github.io/iptv/countries/br.m3u",
- "France": "https://iptv-org.github.io/iptv/countries/fr.m3u",
- "India": "https://iptv-org.github.io/iptv/countries/in.m3u",
- "Italy": "https://iptv-org.github.io/iptv/countries/it.m3u",
- "Pakistan": "https://iptv-org.github.io/iptv/countries/pk.m3u",
- "Spain": "https://iptv-org.github.io/iptv/countries/es.m3u",
- "Thailand": "https://iptv-org.github.io/iptv/countries/th.m3u",
- "UK": "https://iptv-org.github.io/iptv/countries/uk.m3u",
- "USA": "https://iptv-org.github.io/iptv/countries/us.m3u",
- "Classic": "https://iptv-org.github.io/iptv/categories/classic.m3u",
- "Comedy": "https://iptv-org.github.io/iptv/categories/comedy.m3u",
- "Documentary": "https://iptv-org.github.io/iptv/categories/documentary.m3u",
- "Entertainment": "https://iptv-org.github.io/iptv/categories/entertainment.m3u",
- "Kids": "https://iptv-org.github.io/iptv/categories/kids.m3u",
- "Movies": "https://iptv-org.github.io/iptv/categories/movies.m3u",
- "Music": "https://iptv-org.github.io/iptv/categories/music.m3u",
- "News": "https://iptv-org.github.io/iptv/categories/news.m3u",
- "Science": "https://iptv-org.github.io/iptv/categories/science.m3u",
- "Sports": "https://iptv-org.github.io/iptv/categories/sports.m3u",
- "Travel": "https://iptv-org.github.io/iptv/categories/travel.m3u",
- "PLAYLIST-1": "C:/Users/Najeeb/Desktop/IPTV/PL1.m3u",
- "PLAYLIST-2": "C:/Users/Najeeb/Desktop/IPTV/PL2.m3u",
- "PLAYLIST-3": "C:/Users/Najeeb/Desktop/IPTV/PL3.m3u",
- "PLAYLIST-4": "C:/Users/Najeeb/Desktop/IPTV/PL4.m3u",
- "PLAYLIST-5": "C:/Users/Najeeb/Desktop/IPTV/PL5.m3u",
- "PLAYLIST-6": "C:/Users/Najeeb/Desktop/IPTV/PL6.m3u",
- "PLAYLIST-7": "C:/Users/Najeeb/Desktop/IPTV/PL7.m3u",
- "PLAYLIST-R": "C:/Users/Najeeb/Desktop/IPTV/PLR.m3u",
- "PLAYLIST-X": "C:/Users/Najeeb/Desktop/IPTV/PLX.m3u",
- }
- category_var = tk.StringVar(button_frame)
- category_var.set("NAJEEB-IPTV")
- category_dropdown = ttk.OptionMenu(button_frame, category_var, *category_urls.keys())
- category_dropdown.pack(side=tk.RIGHT, padx=5)
- # Add this section for the preview frame setup
- preview_frame = tk.Frame(root, bg="#4a4a4a", height=200)
- preview_frame.pack(fill="both", expand=True)
- preview_frame.pack_forget()
- # Move stop_button creation here and pack it at the top
- stop_button = tk.Button(preview_frame, text="Close Preview", command=stop_preview, bg="#5a5a5a", fg="white")
- stop_button.pack(side=tk.TOP, padx=5, pady=5)
- canvas = tk.Canvas(preview_frame, bg="#4a4a4a")
- canvas.pack(fill="both", expand=True)
- canvas.bind("<Configure>", on_configure)
- slider = tk.Scale(preview_frame, from_=0, to=100, orient=tk.HORIZONTAL, command=set_position, bg="#4a4a4a", fg="white")
- slider.pack(fill="x", padx=5)
- # VLC setup
- instance = vlc.Instance()
- player = instance.media_player_new()
- channels_info = {}
- working_links = {}
- root.mainloop()
Add Comment
Please, Sign In to add comment