|
1 | 1 | from tkinter import *
|
2 | 2 | from pytube import YouTube
|
| 3 | +from pytube import Playlist |
3 | 4 |
|
4 |
| -root = Tk() |
5 |
| -root.geometry('700x300') |
6 |
| -root.resizable(0, 0) |
7 |
| -root.title("YouTube Video Downloader") |
| 5 | +# select wether to download video or playlist |
| 6 | +def mode_selector(): |
| 7 | + url = link.get() |
| 8 | + if "watch?v=" in url: |
| 9 | + video_downloader(url) |
| 10 | + elif "playlist?list=" in url: |
| 11 | + playlist_downloader(url) |
| 12 | + else: |
| 13 | + print("Invalid YouTube URL!") |
| 14 | + Label(root, text='DOWNLOADED!', font='arial 15').place(x=280, y=230) |
8 | 15 |
|
9 |
| -Label(root, text='Copy the link of the video you want to download from YouTube', |
10 |
| - font='arial 15 bold').pack() |
| 16 | +# function to download single video |
| 17 | +def video_downloader(url): |
| 18 | + try: |
| 19 | + yt = YouTube(url, use_oauth=True, allow_oauth_cache=True) |
| 20 | + yt.streams.first().download() |
| 21 | + except Exception as e: |
| 22 | + Label(root, text=f'Video Error Downloading!.... Try Again #{e}', font='arial 15').place(x=100, y=210) |
11 | 23 |
|
12 |
| -# enter link |
13 |
| -link = StringVar() |
| 24 | +#function to download playlist |
| 25 | +def playlist_downloader(url): |
| 26 | + try: |
| 27 | + py = Playlist(url) |
| 28 | + for video in py.videos: |
| 29 | + video_downloader(video.watch_url) |
| 30 | + except Exception as e: |
| 31 | + Label(root, text=f'Playlist Error Downloading!.... Try Again #{e}', font='arial 15').place(x=100, y=210) |
| 32 | + print(e) |
14 | 33 |
|
15 |
| -Label(root, text='Paste Link Here:', font='arial 15 bold').place(x=270, y=60) |
16 |
| -Entry(root, width=80, textvariable=link).place(x=32, y=90) |
| 34 | +if __name__ == "__main__": |
| 35 | + root = Tk() |
| 36 | + root.geometry('800x600') |
| 37 | + root.resizable(0, 0) |
| 38 | + root.title("YouTube Video Downloader") |
| 39 | + |
| 40 | + Label(root, text='Copy the link of the VIDEO/PLAYLIST you want to download from YouTube', |
| 41 | + font='arial 15 bold').pack() |
| 42 | + |
| 43 | + # enter link |
| 44 | + link = StringVar() |
| 45 | + |
| 46 | + |
| 47 | + Label(root, text='Paste Link Here:', font='arial 15 bold').place(x=270, y=60) |
| 48 | + Entry(root, width=80, textvariable=link).place(x=32, y=90) |
| 49 | + Button(root, text='DOWNLOAD', font='arial 15 bold', bg='white', |
| 50 | + padx=2, command=mode_selector).place(x=280, y=150) |
| 51 | + |
| 52 | + |
| 53 | + root.mainloop() |
17 | 54 |
|
18 |
| -# function to download video |
19 | 55 |
|
20 | 56 |
|
21 |
| -def Downloader(): |
22 | 57 |
|
23 |
| - url = YouTube(str(link.get())) |
24 |
| - video = url.streams.first() |
25 |
| - video.download() |
26 |
| - Label(root, text='DOWNLOADED', font='arial 15').place(x=270, y=210) |
27 | 58 |
|
28 | 59 |
|
29 |
| -Button(root, text='DOWNLOAD', font='arial 15 bold', bg='white', |
30 |
| - padx=2, command=Downloader).place(x=280, y=150) |
31 | 60 |
|
32 |
| -root.mainloop() |
|
0 commit comments