Skip to content

Commit e206ff1

Browse files
authored
Youtube MP4 Download
Nice script to download mp4 from yt playlist
1 parent 9923778 commit e206ff1

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed
+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import re, os, time, urllib.request, urllib.error, pytube
2+
3+
video_file = "video_list.txt"
4+
path = "Video"
5+
url = "https://www.youtube.com/playlist?list=myplaylist"
6+
7+
if not os.path.exists(path):
8+
os.mkdir(path)
9+
10+
def get_playlist(url):
11+
amp = 0
12+
final_url = []
13+
if 'list=' in url:
14+
eq = url.rfind('=') + 1
15+
cPL = url[eq:]
16+
else:
17+
print('Incorrect Playlist.')
18+
exit(1)
19+
try:
20+
sTUBE = str(urllib.request.urlopen(url).read())
21+
except urllib.error.URLError as e:
22+
print(e.reason)
23+
tmp_mat = re.compile(r'watch\?v=\S+?list=' + cPL)
24+
mat = re.findall(tmp_mat, sTUBE)
25+
if mat:
26+
for PL in mat:
27+
yPL = str(PL)
28+
if '&' in yPL:
29+
yPL_amp = yPL.index('&')
30+
final_url.append('http://www.youtube.com/' + yPL[:yPL_amp])
31+
all_url = list(set(final_url))
32+
i = 0
33+
file = open(video_file, "w", encoding="utf-8")
34+
while i < len(all_url):
35+
file.write(all_url[i].strip() + '\n')
36+
time.sleep(0.04)
37+
i = i + 1
38+
file.close()
39+
else:
40+
print('No videos found.')
41+
exit(1)
42+
43+
if not 'http' in url:
44+
url = 'http://' + url
45+
get_playlist(url)
46+
47+
with open(video_file) as file:
48+
for line in file:
49+
pytube.YouTube(line).streams.filter(subtype="mp4").filter(progressive=True).first().download(path)

0 commit comments

Comments
 (0)