-
Notifications
You must be signed in to change notification settings - Fork 15
/
downloadVid.py
29 lines (23 loc) · 860 Bytes
/
downloadVid.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import os
from pytube import YouTube
import requests
from tqdm import tqdm
import math
# Input video url
video_url = input("[*]Enter video URL: ")
def download_video(video_url):
yt = YouTube(video_url)
stream = yt.streams.filter(file_extension='mp4').first()
response = requests.get(stream.url, stream=True)
total_size = int(response.headers.get("Content-Length", 0))
block_size = 1024
wrote = 0
filename = yt.title + ".mp4"
file_path = os.path.join("Video/", filename)
with open(file_path, "wb") as f:
for data in tqdm(response.iter_content(block_size), total=math.ceil(total_size//block_size), unit="KB", unit_scale=True):
wrote = wrote + len(data)
f.write(data)
if total_size != 0 and wrote != total_size:
print("ERROR, something went wrong")
download_video(video_url)