Advertisement
Najeebsk

YOUTUBE-ALL-LINKS.py

Feb 28th, 2024
827
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.96 KB | None | 1 0
  1. import tkinter as tk
  2. from tkinter import messagebox, filedialog
  3. import youtube_dl
  4.  
  5. def scrape_channel():
  6.     output_text.delete('1.0', tk.END)  # Clear previous results
  7.     channel_url = channel_entry.get()
  8.     ydl_opts = {
  9.         'quiet': True,
  10.         'extract_flat': True,
  11.     }
  12.     with youtube_dl.YoutubeDL(ydl_opts) as ydl:
  13.         result = ydl.extract_info(channel_url, download=False)
  14.         videos = result.get('entries')
  15.         if videos:
  16.             for video in videos:
  17.                 title = video.get('title')
  18.                 url = video.get('url')
  19.                 full_link = f"https://www.youtube.com/watch?v={url}"
  20.                 output_text.insert(tk.END, f"{title}\n{full_link}\n\n")
  21.  
  22. def save_results():
  23.     file_path = filedialog.asksaveasfilename(defaultextension=".txt", filetypes=[("Text files", "*.txt")])
  24.     if file_path:
  25.         try:
  26.             with open(file_path, 'w') as file:
  27.                 file.write(output_text.get("1.0", tk.END))
  28.             messagebox.showinfo("Success", "Results saved successfully!")
  29.         except Exception as e:
  30.             messagebox.showerror("Error", f"An error occurred: {str(e)}")
  31.  
  32. root = tk.Tk()
  33. root.title("Najeeb YouTube Channel Scraper")
  34. root.config(bg='green')
  35.  
  36. label = tk.Label(root, text="Enter YouTube Channel URL:")
  37. label.grid(row=0, column=0, pady=10)
  38.  
  39. channel_entry = tk.Entry(root, width=50)
  40. channel_entry.grid(row=0, column=1)
  41.  
  42. scrape_button = tk.Button(root, text="Scrape Channel", command=scrape_channel)
  43. scrape_button.grid(row=0, column=2, pady=5)
  44.  
  45. output_text = tk.Text(root, height=20, width=100)
  46. output_text.grid(row=1, column=0, columnspan=3, padx=10, pady=10)
  47.  
  48. scrollbar = tk.Scrollbar(root, orient=tk.VERTICAL, command=output_text.yview)
  49. scrollbar.grid(row=1, column=3, sticky="ns")
  50. output_text.config(yscrollcommand=scrollbar.set)
  51.  
  52. save_button = tk.Button(root, text="Save", command=save_results)
  53. save_button.grid(row=2, column=1, pady=5)
  54.  
  55. root.mainloop()
  56.  
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement