Advertisement
Najeebsk

YT-PLAYLIST.pyw

Sep 9th, 2024
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.59 KB | None | 0 0
  1. import os
  2. import tkinter as tk
  3. from tkinter import filedialog, messagebox
  4. import yt_dlp
  5.  
  6. # Function to fetch video titles and URLs from the playlist or channel
  7. def fetch_playlist_info():
  8.     url = url_entry.get()
  9.     save_folder = folder_entry.get()
  10.    
  11.     if not url:
  12.         messagebox.showwarning("Input Error", "Please enter a YouTube playlist or channel URL")
  13.         return
  14.    
  15.     if not save_folder:
  16.         messagebox.showwarning("Input Error", "Please select a destination folder")
  17.         return
  18.  
  19.     save_path = os.path.join(save_folder, "playlist_videos.txt")
  20.    
  21.     ydl_opts = {
  22.         'extract_flat': True,  # Extract metadata without downloading
  23.         'dump_single_json': True,
  24.         'playlistend': 100,  # Modify if you want to limit the number of videos (default 100)
  25.     }
  26.  
  27.     try:
  28.         with yt_dlp.YoutubeDL(ydl_opts) as ydl:
  29.             playlist_info = ydl.extract_info(url, download=False)
  30.            
  31.             with open(save_path, "w", encoding="utf-8") as f:
  32.                 f.write(f"Playlist/Channel: {playlist_info.get('title', 'No Title')}\n\n")
  33.                
  34.                 for entry in playlist_info.get('entries', []):
  35.                     title = entry.get('title', 'No Title')
  36.                     video_url = entry.get('url', '')
  37.                     f.write(f"{title}\n{video_url}\n\n")
  38.        
  39.         messagebox.showinfo("Success", f"Titles and URLs saved to {save_path}!")
  40.     except Exception as e:
  41.         messagebox.showerror("Error", f"An error occurred: {str(e)}")
  42.  
  43. # Function to choose folder
  44. def choose_folder():
  45.     folder = filedialog.askdirectory()
  46.     if folder:
  47.         folder_entry.delete(0, tk.END)
  48.         folder_entry.insert(0, folder)
  49.  
  50. # Set up the Tkinter window
  51. root = tk.Tk()
  52. root.title("Najeeb YouTube Playlist/Channel Info Fetcher")
  53.  
  54. # URL label and entry
  55. url_label = tk.Label(root, text="YouTube Playlist/Channel URL:")
  56. url_label.grid(row=0, column=0, padx=10, pady=10)
  57.  
  58. url_entry = tk.Entry(root, width=50)
  59. url_entry.grid(row=0, column=1, padx=10, pady=10)
  60.  
  61. # Folder label, entry, and browse button
  62. folder_label = tk.Label(root, text="Save Folder:")
  63. folder_label.grid(row=1, column=0, padx=10, pady=10)
  64.  
  65. folder_entry = tk.Entry(root, width=50)
  66. folder_entry.grid(row=1, column=1, padx=10, pady=10)
  67.  
  68. browse_button = tk.Button(root, text="Browse", command=choose_folder)
  69. browse_button.grid(row=1, column=2, padx=10, pady=10)
  70.  
  71. # Fetch button
  72. fetch_button = tk.Button(root, text="Fetch Playlist Info", command=fetch_playlist_info)
  73. fetch_button.grid(row=2, column=1, padx=10, pady=10)
  74.  
  75. root.mainloop()
  76.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement