Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import tkinter as tk
- from tkinter import filedialog, messagebox
- import yt_dlp
- # Function to fetch video titles and URLs from the playlist or channel
- def fetch_playlist_info():
- url = url_entry.get()
- save_folder = folder_entry.get()
- if not url:
- messagebox.showwarning("Input Error", "Please enter a YouTube playlist or channel URL")
- return
- if not save_folder:
- messagebox.showwarning("Input Error", "Please select a destination folder")
- return
- save_path = os.path.join(save_folder, "playlist_videos.txt")
- ydl_opts = {
- 'extract_flat': True, # Extract metadata without downloading
- 'dump_single_json': True,
- 'playlistend': 100, # Modify if you want to limit the number of videos (default 100)
- }
- try:
- with yt_dlp.YoutubeDL(ydl_opts) as ydl:
- playlist_info = ydl.extract_info(url, download=False)
- with open(save_path, "w", encoding="utf-8") as f:
- f.write(f"Playlist/Channel: {playlist_info.get('title', 'No Title')}\n\n")
- for entry in playlist_info.get('entries', []):
- title = entry.get('title', 'No Title')
- video_url = entry.get('url', '')
- f.write(f"{title}\n{video_url}\n\n")
- messagebox.showinfo("Success", f"Titles and URLs saved to {save_path}!")
- except Exception as e:
- messagebox.showerror("Error", f"An error occurred: {str(e)}")
- # Function to choose folder
- def choose_folder():
- folder = filedialog.askdirectory()
- if folder:
- folder_entry.delete(0, tk.END)
- folder_entry.insert(0, folder)
- # Set up the Tkinter window
- root = tk.Tk()
- root.title("Najeeb YouTube Playlist/Channel Info Fetcher")
- # URL label and entry
- url_label = tk.Label(root, text="YouTube Playlist/Channel URL:")
- url_label.grid(row=0, column=0, padx=10, pady=10)
- url_entry = tk.Entry(root, width=50)
- url_entry.grid(row=0, column=1, padx=10, pady=10)
- # Folder label, entry, and browse button
- folder_label = tk.Label(root, text="Save Folder:")
- folder_label.grid(row=1, column=0, padx=10, pady=10)
- folder_entry = tk.Entry(root, width=50)
- folder_entry.grid(row=1, column=1, padx=10, pady=10)
- browse_button = tk.Button(root, text="Browse", command=choose_folder)
- browse_button.grid(row=1, column=2, padx=10, pady=10)
- # Fetch button
- fetch_button = tk.Button(root, text="Fetch Playlist Info", command=fetch_playlist_info)
- fetch_button.grid(row=2, column=1, padx=10, pady=10)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement