Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import webbrowser
- from tkinter import Tk, Label, Button, Text, Entry, Scrollbar, messagebox
- from pytube import Playlist
- def install_missing_modules():
- try:
- from pytube import Playlist
- except ModuleNotFoundError:
- os.system('pip install pytube')
- messagebox.showinfo("Modules Installed", "Required modules have been installed. Please restart the application.")
- exit()
- def save_playlist_info(playlists):
- with open('playlist_info.txt', 'w', encoding='utf-8') as f:
- for playlist_url in playlists:
- playlist = Playlist(playlist_url)
- f.write(f"Playlist: {playlist.title}\n")
- for video in playlist.videos:
- f.write(f"Title: {video.title}\n")
- f.write(f"URL: {video.watch_url}\n")
- f.write("\n")
- messagebox.showinfo("Success", "Playlist information successfully saved to playlist_info.txt")
- display_playlist_info()
- def display_playlist_info():
- text.delete(1.0, "end") # Clear previous content
- with open('playlist_info.txt', 'r', encoding='utf-8') as f:
- text.insert("end", f.read())
- def open_url(event):
- url_index = text.index("current")
- line_num = int(url_index.split('.')[0]) - 1
- url_line = text.get(f"{line_num + 1}.0", f"{line_num + 1}.end")
- if url_line.startswith("URL:"):
- url = url_line.strip().split(": ")[1]
- webbrowser.open(url)
- def get_playlist_info():
- playlists = entry.get().split(',')
- save_playlist_info(playlists)
- def on_closing():
- if messagebox.askokcancel("Quit", "Do you want to quit?"):
- root.destroy()
- # GUI setup
- root = Tk()
- root.title("Najeeb Youtube Channel Url Scraping")
- root.protocol("WM_DELETE_WINDOW", on_closing)
- root.configure(bg='pink')
- label = Label(root, text="Enter playlist URLs (comma separated):", bg='black', fg='white')
- label.pack()
- entry = Entry(root, width=100)
- entry.pack()
- button = Button(root, text="Save Playlist Info", command=get_playlist_info, bg='#4CAF50', fg='white')
- button.pack()
- scrollbar = Scrollbar(root, orient="vertical")
- scrollbar.pack(side="right", fill="y")
- text = Text(root, height=20, width=80, yscrollcommand=scrollbar.set)
- text.pack()
- scrollbar.config(command=text.yview)
- text.bind("<Double-1>", open_url)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement