Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- from tkinter import messagebox, filedialog
- import youtube_dl
- def scrape_channel():
- output_text.delete('1.0', tk.END) # Clear previous results
- channel_url = channel_entry.get()
- ydl_opts = {
- 'quiet': True,
- 'extract_flat': True,
- }
- with youtube_dl.YoutubeDL(ydl_opts) as ydl:
- result = ydl.extract_info(channel_url, download=False)
- videos = result.get('entries')
- if videos:
- for video in videos:
- title = video.get('title')
- url = video.get('url')
- full_link = f"https://www.youtube.com/watch?v={url}"
- output_text.insert(tk.END, f"{title}\n{full_link}\n\n")
- def save_results():
- file_path = filedialog.asksaveasfilename(defaultextension=".txt", filetypes=[("Text files", "*.txt")])
- if file_path:
- try:
- with open(file_path, 'w') as file:
- file.write(output_text.get("1.0", tk.END))
- messagebox.showinfo("Success", "Results saved successfully!")
- except Exception as e:
- messagebox.showerror("Error", f"An error occurred: {str(e)}")
- root = tk.Tk()
- root.title("Najeeb YouTube Channel Scraper")
- root.config(bg='green')
- label = tk.Label(root, text="Enter YouTube Channel URL:")
- label.grid(row=0, column=0, pady=10)
- channel_entry = tk.Entry(root, width=50)
- channel_entry.grid(row=0, column=1)
- scrape_button = tk.Button(root, text="Scrape Channel", command=scrape_channel)
- scrape_button.grid(row=0, column=2, pady=5)
- output_text = tk.Text(root, height=20, width=100)
- output_text.grid(row=1, column=0, columnspan=3, padx=10, pady=10)
- scrollbar = tk.Scrollbar(root, orient=tk.VERTICAL, command=output_text.yview)
- scrollbar.grid(row=1, column=3, sticky="ns")
- output_text.config(yscrollcommand=scrollbar.set)
- save_button = tk.Button(root, text="Save", command=save_results)
- save_button.grid(row=2, column=1, pady=5)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement