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 subprocess
import shutil
import urllib.request
import requests
import os
import os.path
import sys
import time
import logging
import certifi
from PIL import Image
from mutagen.oggvorbis import OggVorbis
from distutils.dir_util import copy_tree
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):
try:
shutil.rmtree(dirpath)
@ -30,7 +40,7 @@ def update():
def download_and_extract(url_source, out_archive):
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)
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"
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)
logging.info("Download complete.")
@ -77,9 +87,9 @@ def download_git(clean=False):
def get_ffmpeg_version():
url_ffmpeg_version = "https://www.gyan.dev/ffmpeg/builds/release-version"
fp = urllib.request.urlopen(url_ffmpeg_version)
ffmpeg_version = fp.read().decode("utf8")
fp.close()
fp = requests.get(url_ffmpeg_version, verify=certifi.where())
ffmpeg_version = fp.text
del fp
return ffmpeg_version