Advertisement
Najeebsk

IPTV.pyw

Jul 19th, 2024 (edited)
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 11.16 KB | None | 0 0
  1. import os
  2. import tkinter as tk
  3. from tkinter import ttk, filedialog, messagebox
  4. import vlc
  5. import subprocess
  6. import threading
  7.  
  8. # Constants
  9. CHANNELS_FOLDER = 'CHANNELS'
  10. VLC_PATH = r"C:\Program Files\VideoLAN\VLC\vlc.exe"
  11. WGET_PATH = r"C:\CMDER\APP\wget.exe"  # Update this with the correct path to wget.exe
  12. FFMPEG_PATH = r"C:\CMDER\APP\ffmpeg.exe"  # Update this with the correct path to ffmpeg.exe
  13.  
  14. # Initialize VLC
  15. instance = vlc.Instance('--verbose 2')
  16. player = instance.media_player_new()
  17.  
  18. class NajeebChannelPlayer(tk.Tk):
  19.     def __init__(self):
  20.         super().__init__()
  21.  
  22.         self.title("Najeeb IPTV Channel Player")
  23.         self.geometry("1000x600")
  24.         self.configure(bg='#2E2E2E')
  25.  
  26.         self.channels_info = {}
  27.         self.process = None
  28.         self.is_fullscreen = False
  29.         self.is_dragging_slider = False  # Initialize as an instance variable
  30.         self.is_muted = False
  31.  
  32.         self.create_widgets()
  33.         self.load_channels_from_folder()
  34.         self.update_video_slider()
  35.  
  36.     def create_widgets(self):
  37.         self.control_frame = ttk.Frame(self, style="TFrame")
  38.         self.control_frame.pack(side=tk.TOP, fill=tk.X, padx=10, pady=5)
  39.  
  40.         self.search_entry = ttk.Entry(self.control_frame, width=50)
  41.         self.search_entry.pack(side=tk.LEFT, padx=5, pady=5)
  42.         search_button = ttk.Button(self.control_frame, text="Search", command=self.search_channels)
  43.         search_button.pack(side=tk.LEFT, padx=5, pady=5)
  44.  
  45.         filter_button = ttk.Button(self.control_frame, text="Filter", command=self.filter_channels)
  46.         filter_button.pack(side=tk.LEFT, padx=5, pady=5)
  47.  
  48.         copy_button = ttk.Button(self.control_frame, text="Copy URL", command=self.copy_selected_url)
  49.         copy_button.pack(side=tk.LEFT, padx=5, pady=5)
  50.  
  51.         preview_button = ttk.Button(self.control_frame, text="Preview", command=self.preview_selected_channel)
  52.         preview_button.pack(side=tk.LEFT, padx=5, pady=5)
  53.  
  54.         stop_button = ttk.Button(self.control_frame, text="Stop Preview", command=self.stop_preview)
  55.         stop_button.pack(side=tk.LEFT, padx=5, pady=5)
  56.  
  57.  
  58.         # Volume and Mute Controls
  59.         volume_frame = ttk.Frame(self.control_frame, style="TFrame")
  60.         volume_frame.pack(side=tk.LEFT, padx=5, pady=5)
  61.  
  62.         volume_label = ttk.Label(volume_frame, text="Volume")
  63.         volume_label.pack(side=tk.LEFT)
  64.  
  65.         volume_slider = ttk.Scale(volume_frame, from_=0, to=100, orient=tk.HORIZONTAL, command=self.set_volume)
  66.         volume_slider.set(50)  # Default volume
  67.         volume_slider.pack(side=tk.LEFT, padx=5)
  68.  
  69.         self.mute_button = ttk.Button(volume_frame, text="Mute", command=self.mute_unmute)
  70.         self.mute_button.pack(side=tk.LEFT, padx=5)
  71.  
  72.         # Additional Buttons
  73.         self.additional_buttons_frame = ttk.Frame(self, style="TFrame")
  74.         self.additional_buttons_frame.pack(side=tk.TOP, fill=tk.X, padx=10, pady=5)
  75.  
  76.         capture_video_button = ttk.Button(self.additional_buttons_frame, text="Capture Video", command=self.capture_video)
  77.         capture_video_button.pack(side=tk.LEFT, padx=5, pady=5)
  78.  
  79.         record_audio_button = ttk.Button(self.additional_buttons_frame, text="Record Audio", command=self.record_audio)
  80.         record_audio_button.pack(side=tk.LEFT, padx=5, pady=5)
  81.  
  82.         stop_record_button = ttk.Button(self.additional_buttons_frame, text="Stop Recording", command=self.stop_recording)
  83.         stop_record_button.pack(side=tk.LEFT, padx=5, pady=5)
  84.  
  85.         screenshot_button = ttk.Button(self.additional_buttons_frame, text="Capture Screenshots", command=self.capture_screenshots)
  86.         screenshot_button.pack(side=tk.LEFT, padx=5, pady=5)
  87.  
  88.         fullscreen_button = ttk.Button(self.additional_buttons_frame, text="Full Screen", command=self.toggle_fullscreen)
  89.         fullscreen_button.pack(side=tk.LEFT, padx=5, pady=5)
  90.  
  91.         download_button = ttk.Button(self.additional_buttons_frame, text="Download with wget", command=self.download_video)
  92.         download_button.pack(side=tk.LEFT, padx=5, pady=5)
  93.  
  94.         download_ffmpeg_button = ttk.Button(self.additional_buttons_frame, text="Download with ffmpeg", command=self.download_with_ffmpeg)
  95.         download_ffmpeg_button.pack(side=tk.LEFT, padx=5, pady=5)
  96.  
  97.         # Video control slider
  98.         self.video_slider = ttk.Scale(self, from_=0, to=1000, orient=tk.HORIZONTAL)
  99.         self.video_slider.pack(side=tk.BOTTOM, fill=tk.X, padx=5, pady=5)
  100.         self.video_slider.bind("<ButtonPress-1>", self.slider_pressed)
  101.         self.video_slider.bind("<ButtonRelease-1>", self.slider_released)
  102.  
  103.         self.result_frame = ttk.Frame(self, style="TFrame")
  104.         self.result_frame.pack(side=tk.LEFT, fill=tk.BOTH, expand=False, padx=1, pady=5)
  105.  
  106.         self.result_text = tk.Listbox(self.result_frame, width=30, height=25, selectmode=tk.SINGLE, bg='#FFFFFF', fg='#000000')
  107.         self.result_text.pack(side=tk.LEFT, fill=tk.BOTH, expand=False)
  108.  
  109.         # Add scrollbars
  110.         vsb = ttk.Scrollbar(self.result_frame, orient="vertical", command=self.result_text.yview)
  111.         vsb.pack(side=tk.RIGHT, fill="y")
  112.         self.result_text.configure(yscrollcommand=vsb.set)
  113.  
  114.         self.result_text.bind('<Double-1>', self.play_selected_channel)
  115.  
  116.         self.video_frame = tk.Frame(self, bg='#000000')
  117.         self.video_frame.pack(side=tk.RIGHT, fill=tk.BOTH, expand=True, padx=10, pady=5)
  118.  
  119.         self.video_panel = tk.Frame(self.video_frame, bg='#000000')
  120.         self.video_panel.pack(fill=tk.BOTH, expand=True)
  121.  
  122.         # Ensure control frames are always visible
  123.         self.control_frame.pack(side=tk.TOP, fill=tk.X, padx=10, pady=5)
  124.         self.additional_buttons_frame.pack(side=tk.TOP, fill=tk.X, padx=10, pady=5)
  125.  
  126.     def load_channels_from_folder(self):
  127.         try:
  128.             files = [f for f in os.listdir(CHANNELS_FOLDER) if f.endswith('.txt')]
  129.             all_channels = []
  130.             for file in files:
  131.                 file_path = os.path.join(CHANNELS_FOLDER, file)
  132.                 with open(file_path, 'r', encoding='utf-8') as f:
  133.                     all_channels.extend(f.readlines())
  134.             self.process_text_data(all_channels)
  135.         except FileNotFoundError:
  136.             messagebox.showerror("Error", f"The folder '{CHANNELS_FOLDER}' does not exist.")
  137.         except PermissionError:
  138.             messagebox.showerror("Error", f"Permission denied while accessing '{CHANNELS_FOLDER}'.")
  139.         except Exception as e:
  140.             self.result_text.insert(tk.END, f"Error loading channels from folder: {str(e)}\n")
  141.  
  142.     def process_text_data(self, text_data):
  143.         self.result_text.delete(0, tk.END)
  144.         self.channels_info = {}
  145.         for line in text_data:
  146.             line = line.strip()
  147.             if line:
  148.                 if "http" in line:
  149.                     # Find the URL by splitting on space
  150.                     parts = line.split(' ', 1)
  151.                     if len(parts) == 2:
  152.                         channel_name = parts[0].strip()
  153.                         url = parts[1].strip()
  154.                         self.channels_info[channel_name] = url
  155.                         self.result_text.insert(tk.END, channel_name)
  156.  
  157.     def search_channels(self):
  158.         search_term = self.search_entry.get().lower()
  159.         self.result_text.delete(0, tk.END)
  160.         for channel_name, url in self.channels_info.items():
  161.             if search_term in channel_name.lower():
  162.                 self.result_text.insert(tk.END, channel_name)
  163.  
  164.     def filter_channels(self):
  165.         search_term = self.search_entry.get().lower()
  166.         self.result_text.delete(0, tk.END)
  167.         for channel_name, url in self.channels_info.items():
  168.             if search_term in channel_name.lower() or search_term in url.lower():
  169.                 self.result_text.insert(tk.END, channel_name)
  170.  
  171.     def play_selected_channel(self, event):
  172.         try:
  173.             selected_channel = self.result_text.get(tk.ACTIVE)
  174.             if selected_channel in self.channels_info:
  175.                 url = self.channels_info[selected_channel]
  176.                 subprocess.Popen([VLC_PATH, url])
  177.         except (tk.TclError, KeyError):
  178.             pass
  179.  
  180.     def preview_selected_channel(self):
  181.         try:
  182.             selected_channel = self.result_text.get(tk.ACTIVE)
  183.             if selected_channel in self.channels_info:
  184.                 url = self.channels_info[selected_channel]
  185.                 self.play_vlc_stream(url)
  186.         except (tk.TclError, KeyError):
  187.             pass
  188.  
  189.     def play_vlc_stream(self, stream_url):
  190.         media = instance.media_new(stream_url)
  191.         player.set_media(media)
  192.         player.set_hwnd(self.video_panel.winfo_id())
  193.         player.play()
  194.  
  195.     def slider_pressed(self, event):
  196.         self.is_dragging_slider = True
  197.  
  198.     def slider_released(self, event):
  199.         self.is_dragging_slider = False
  200.         value = self.video_slider.get()
  201.         self.set_position(value)
  202.  
  203.     def set_position(self, value):
  204.         player.set_time(int((value / 1000) * player.get_length()))
  205.  
  206.     def update_video_slider(self):
  207.         if player and not self.is_dragging_slider:
  208.             length = player.get_length()
  209.             time = player.get_time()
  210.             if length > 0:
  211.                 value = int((time / length) * 1000)
  212.                 self.video_slider.set(value)
  213.         self.after(1000, self.update_video_slider)
  214.  
  215.     def set_volume(self, value):
  216.         player.audio_set_volume(int(float(value)))  # Convert float to int
  217.  
  218.     def mute_unmute(self):
  219.         if self.is_muted:
  220.             player.audio_set_mute(False)
  221.             self.mute_button.config(text="Mute")
  222.         else:
  223.             player.audio_set_mute(True)
  224.             self.mute_button.config(text="Unmute")
  225.         self.is_muted = not self.is_muted
  226.  
  227.     def capture_video(self):
  228.         self.process = subprocess.Popen(['ffmpeg', '-f', 'gdigrab', '-framerate', '30', '-i', 'desktop', 'output.mp4'])
  229.  
  230.     def record_audio(self):
  231.         self.process = subprocess.Popen(['ffmpeg', '-f', 'dshow', '-i', 'audio=Stereo Mix (Realtek(R) Audio)', 'output_audio.mp3'])
  232.  
  233.     def stop_recording(self):
  234.         if self.process:
  235.             self.process.terminate()
  236.             self.process = None
  237.  
  238.     def capture_screenshots(self):
  239.         subprocess.Popen(['ffmpeg', '-f', 'gdigrab', '-framerate', '1', '-i', 'desktop', '-frames:v', '1', 'screenshot.png'])
  240.  
  241.     def copy_selected_url(self):
  242.         selected_channel = self.result_text.get(tk.ACTIVE)
  243.         if selected_channel in self.channels_info:
  244.             url = self.channels_info[selected_channel]
  245.             self.clipboard_clear()
  246.             self.clipboard_append(url)
  247.  
  248.     def toggle_fullscreen(self):
  249.         self.is_fullscreen = not self.is_fullscreen
  250.         self.attributes("-fullscreen", self.is_fullscreen)
  251.  
  252.     def stop_preview(self):
  253.         player.stop()
  254.  
  255.     def download_video(self):
  256.         url = self.search_entry.get()
  257.         if url:
  258.             subprocess.Popen([WGET_PATH, url])
  259.  
  260.     def download_with_ffmpeg(self):
  261.         url = self.search_entry.get()
  262.         if url:
  263.             subprocess.Popen([FFMPEG_PATH, '-i', url, 'output_video.mp4'])
  264.  
  265. if __name__ == "__main__":
  266.     app = NajeebChannelPlayer()
  267.     app.mainloop()
  268.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement