changed the urllib to requests

master
Jaka Perovšek 2021-11-14 14:52:53 +01:00
parent c7c6c3faa5
commit 8f6ad9b7ee
1 changed files with 16 additions and 6 deletions

View File

@ -2,18 +2,28 @@ import jinja2 as j2
import yaml import yaml
import subprocess import subprocess
import shutil import shutil
import urllib.request import requests
import os import os
import os.path import os.path
import sys import sys
import time import time
import logging import logging
import certifi
from PIL import Image from PIL import Image
from mutagen.oggvorbis import OggVorbis from mutagen.oggvorbis import OggVorbis
from distutils.dir_util import copy_tree from distutils.dir_util import copy_tree
from pathlib import Path from pathlib import Path
def download_via_requests(url_source, file_name):
response = requests.get(url_source, stream=True, verify=certifi.where())
with open(file_name, 'wb') as out_file:
shutil.copyfileobj(response.raw, out_file)
del response
def rmfulldir(dirpath): def rmfulldir(dirpath):
try: try:
shutil.rmtree(dirpath) shutil.rmtree(dirpath)
@ -30,7 +40,7 @@ def update():
def download_and_extract(url_source, out_archive): def download_and_extract(url_source, out_archive):
logging.info(f"Downloading {url_source}, this may take a while.") logging.info(f"Downloading {url_source}, this may take a while.")
urllib.request.urlretrieve(url_source, out_archive) download_via_requests(url_source, out_archive)
time.sleep(0.7) time.sleep(0.7)
logging.info("Download complete.") logging.info("Download complete.")
@ -61,7 +71,7 @@ def download_git(clean=False):
"v2.33.0.windows.2/PortableGit-2.33.0.2-64-bit.7z.exe" "v2.33.0.windows.2/PortableGit-2.33.0.2-64-bit.7z.exe"
out_git_archive = "./utils/PortableGit-2.33.0.2-64-bit.7z" out_git_archive = "./utils/PortableGit-2.33.0.2-64-bit.7z"
urllib.request.urlretrieve(url_git_source, out_git_archive) download_via_requests(url_git_source, out_git_archive)
time.sleep(0.7) time.sleep(0.7)
logging.info("Download complete.") logging.info("Download complete.")
@ -77,9 +87,9 @@ def download_git(clean=False):
def get_ffmpeg_version(): def get_ffmpeg_version():
url_ffmpeg_version = "https://www.gyan.dev/ffmpeg/builds/release-version" url_ffmpeg_version = "https://www.gyan.dev/ffmpeg/builds/release-version"
fp = urllib.request.urlopen(url_ffmpeg_version) fp = requests.get(url_ffmpeg_version, verify=certifi.where())
ffmpeg_version = fp.read().decode("utf8") ffmpeg_version = fp.text
fp.close() del fp
return ffmpeg_version return ffmpeg_version