Skip to content

Commit 8558601

Browse files
Merge pull request #1625 from anandanmukh/youtube-video-downloader
youtube-video-downloader functionality addition & bug fix
2 parents 51463de + 584e1e5 commit 8558601

File tree

3 files changed

+50
-22
lines changed

3 files changed

+50
-22
lines changed

YouTube-Video-Downloader/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# YouTube Video Downloader
22

3-
The objective of this project is to download any type of video in a fast and easy way from youtube in your device.
3+
The objective of this project is to download any type of video or an entire playlist in a fast and easy way from YouTube in your device.
44

5-
In this, user has to copy the youtube video URL that they want to download and simply paste that URL in the ‘paste link here’ section and click on the download button, it will start downloading the video. When video downloading finishes, it shows a message ‘downloaded’ popup on the window below the download button.
5+
In this, user has to copy the youtube video/playlist URL that they want to download and simply paste that URL in the ‘paste link here’ section and click on the download button, it will start downloading the video. When video downloading finishes, it shows a message ‘DOWNLOADED!’ popup on the window below the download button.
66

77
</br>
88

@@ -83,4 +83,4 @@ After running this script, you will be able to see this:
8383

8484
</br>
8585

86-
![YTVD](https://user-images.githubusercontent.com/73488906/111301619-6eeaa100-8678-11eb-9ef2-5ce1b02571cf.png)
86+
![YTVD](screenshot.png)
245 KB
Loading

YouTube-Video-Downloader/youtube_vid_dl.py

Lines changed: 47 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,60 @@
11
from tkinter import *
22
from pytube import YouTube
3+
from pytube import Playlist
34

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)
815

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)
1123

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)
1433

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()
1754

18-
# function to download video
1955

2056

21-
def Downloader():
2257

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)
2758

2859

29-
Button(root, text='DOWNLOAD', font='arial 15 bold', bg='white',
30-
padx=2, command=Downloader).place(x=280, y=150)
3160

32-
root.mainloop()

0 commit comments

Comments
 (0)