перепиши и усовершенствуй этот код,чтобы он скачивал любое видео
import requests
import wget
headers = {
'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3;q=0.9',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.142.86 Safari/537.36'
}
video_url = input('input video url')
video2_url = video_url
def download_video(url='', headers=headers):
try:
response = requests.get(url=url,headers=headers, stream=True)
if response:
print("all okay")
with open('req_video.mp4', 'wb') as file:
for chunk in response.iter_content(chunk_size=1024 * 1024):
if chunk:
file.write(chunk)
return 'Video successfully downloaded!'
except Exception as _ex:
return 'Upps... Check the URL please!'
def main():
#print(download_img(url=img_url))
print(download_video(url=video_url))
if name == 'main':
main()
import requests
import wget
headers = {
'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3;q=0.9',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.142.86 Safari/537.36'
}
video_url = input('input video url')
video2_url = video_url
def download_video(url='', headers=headers):
try:
response = requests.get(url=url,headers=headers, stream=True)
if response:
print("all okay")
with open('req_video.mp4', 'wb') as file:
for chunk in response.iter_content(chunk_size=1024 * 1024):
if chunk:
file.write(chunk)
return 'Video successfully downloaded!'
except Exception as _ex:
return 'Upps... Check the URL please!'
def main():
#print(download_img(url=img_url))
print(download_video(url=video_url))
if name == 'main':
main()