Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- from tkinter import filedialog, messagebox
- import subprocess
- import os
- import threading
- class IPTVApp:
- def __init__(self, root):
- self.root = root
- self.root.title("Najeeb IPTV and Video Recoder")
- self.root.geometry("500x400")
- self.root.configure(bg='#f0f0f0')
- # Title Label
- self.title_label = tk.Label(root, text="Najeeb IPTV Video Recoder", font=("Helvetica", 18), bg='#f0f0f0', fg='#333')
- self.title_label.pack(pady=10)
- # URL Entry
- self.url_entry = tk.Entry(root, width=50, font=("Helvetica", 12))
- self.url_entry.pack(pady=10)
- # Start Time
- self.start_time_label = tk.Label(root, text="Start Time (HH:MM:SS):", font=("Helvetica", 12), bg='#f0f0f0', fg='#333')
- self.start_time_label.pack(pady=5)
- self.start_time_entry = tk.Entry(root, width=20, font=("Helvetica", 12))
- self.start_time_entry.pack(pady=5)
- self.start_time_entry.insert(0, "00:00:00")
- # End Time
- self.end_time_label = tk.Label(root, text="End Time (HH:MM:SS):", font=("Helvetica", 12), bg='#f0f0f0', fg='#333')
- self.end_time_label.pack(pady=5)
- self.end_time_entry = tk.Entry(root, width=20, font=("Helvetica", 12))
- self.end_time_entry.pack(pady=5)
- self.end_time_entry.insert(0, "00:00:00")
- # Recode Button
- self.recode_button = tk.Button(root, text="Recode Video", command=self.start_recode, bg='#4CAF50', fg='white', font=("Helvetica", 12))
- self.recode_button.pack(pady=20)
- # Play Button
- self.play_button = tk.Button(root, text="Play URL", command=self.play_url, bg='#2196F3', fg='white', font=("Helvetica", 12))
- self.play_button.pack(pady=10)
- # Progress Label
- self.progress_label = tk.Label(root, text="", font=("Helvetica", 12), bg='#f0f0f0', fg='#333')
- self.progress_label.pack(pady=10)
- def play_url(self):
- url = self.url_entry.get()
- vlc_path = r"C:\Program Files\VideoLAN\VLC\vlc.exe"
- if not os.path.isfile(vlc_path):
- messagebox.showerror("Error", "VLC executable not found.")
- return
- try:
- subprocess.Popen([vlc_path, url])
- except Exception as e:
- messagebox.showerror("Error", f"Failed to play URL: {e}")
- def start_recode(self):
- threading.Thread(target=self.recode_video).start()
- def recode_video(self):
- url = self.url_entry.get()
- start_time = self.start_time_entry.get()
- end_time = self.end_time_entry.get()
- output_file = filedialog.asksaveasfilename(defaultextension=".mp4",
- filetypes=[("MP4 files", "*.mp4"),
- ("MKV files", "*.mkv"),
- ("AVI files", "*.avi"),
- ("FLV files", "*.flv")])
- if not output_file:
- messagebox.showwarning("Warning", "No output file selected.")
- return
- try:
- # Convert start and end times to seconds
- start_time_seconds = self.time_to_seconds(start_time)
- end_time_seconds = self.time_to_seconds(end_time)
- duration_seconds = end_time_seconds - start_time_seconds
- if duration_seconds <= 0:
- raise ValueError("End time must be after start time")
- # FFmpeg command for recoding video
- command = [
- 'ffmpeg', '-y', '-ss', str(start_time_seconds), '-i', url,
- '-t', str(duration_seconds), '-c:v', 'libx264', '-preset', 'fast',
- '-c:a', 'aac', output_file
- ]
- process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
- while True:
- line = process.stderr.readline()
- if not line:
- break
- self.update_progress(line)
- process.wait()
- if process.returncode != 0:
- raise subprocess.CalledProcessError(process.returncode, command)
- self.progress_label.config(text="Video recoded successfully.")
- messagebox.showinfo("Success", "Video recoded successfully.")
- except subprocess.CalledProcessError as e:
- stderr = e.stderr.decode() if e.stderr else 'Unknown error'
- self.progress_label.config(text=f"FFmpeg error: {stderr}")
- messagebox.showerror("Error", f"FFmpeg error: {stderr}")
- except ValueError as e:
- self.progress_label.config(text=str(e))
- messagebox.showerror("Error", str(e))
- except Exception as e:
- self.progress_label.config(text=f"An unexpected error occurred: {e}")
- messagebox.showerror("Error", f"An unexpected error occurred: {e}")
- def update_progress(self, line):
- if "time=" in line:
- time_str = line.split("time=")[1].split(" ")[0]
- self.progress_label.config(text=f"Progress: {time_str}")
- def time_to_seconds(self, time_str):
- """Convert time string (HH:MM:SS) to seconds."""
- h, m, s = map(int, time_str.split(':'))
- return h * 3600 + m * 60 + s
- if __name__ == "__main__":
- root = tk.Tk()
- app = IPTVApp(root)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement