Last active
July 6, 2020 00:26
-
-
Save infval/257d71eb08c329f59124a536da708003 to your computer and use it in GitHub Desktop.
Update yuzu EA from mediafire folder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
__version__ = '1.0.1' | |
import os | |
import re | |
import sys | |
import json | |
import shutil | |
import zipfile | |
import requests | |
def download_file(url, filename): | |
r = requests.get(url, stream=True) | |
total_size = int(r.headers.get('content-length', 0)) | |
block_size = 4096 | |
current_size = 0 | |
char_size = total_size // 80 | |
with open(filename, 'wb') as f: | |
for data in r.iter_content(block_size): | |
current_size += len(data) | |
while current_size >= char_size: | |
current_size -= char_size | |
print('#', end='', flush=True) | |
f.write(data) | |
VERSION_FILENAME = 'Version.txt' | |
MF_FOLDER_KEY = 'rrat84il8xewc' | |
API_URL = ('http://www.mediafire.com/api/1.5/folder/get_content.php' | |
'?folder_key={}&content_type=files' | |
'&order_by=created&order_direction=desc' | |
'&response_format=json').format(MF_FOLDER_KEY) | |
try: | |
r = requests.get(API_URL).text | |
mfolder = json.loads(r) | |
mfile = mfolder['response']['folder_content']['files'][0] | |
filename = mfile['filename'] | |
link = mfile['links']['normal_download'] | |
version = int(re.search('Yuzu Early Access (\\d+)', filename).group(1)) | |
except Exception as e: | |
print('Parse Error: https://www.mediafire.com/folder/{}'.format(MF_FOLDER_KEY)) | |
print('{}: {}'.format(sys.exc_info()[0].__name__, e)) | |
input('Press any key...') | |
sys.exit() | |
try: | |
version_file = open(VERSION_FILENAME, 'r+') | |
except OSError: | |
with open(VERSION_FILENAME, 'w+') as f: | |
f.write('0') | |
version_file = open(VERSION_FILENAME, 'r+') | |
for line in version_file: | |
pass | |
current = int(line) | |
if version > current: | |
print('Downloading newest version ' + str(version) + ', please wait!') | |
try: | |
download_file(link, 'yuzu.zip') | |
except Exception as e: | |
print('Download Error. {}: {}'.format(sys.exc_info()[0].__name__, e)) | |
input('Press any key...') | |
sys.exit() | |
print() | |
print('Extracting files!') | |
try: | |
with zipfile.ZipFile('yuzu.zip', 'r') as zip_ref: | |
zip_ref.extractall('yuzu') | |
shutil.copytree('yuzu/Yuzu Early Access ' + str(version) + ' (Update)/Yuzu Early Access', | |
os.getcwd(), dirs_exist_ok=True) | |
shutil.rmtree('yuzu') | |
version_file.seek(0) | |
version_file.write(str(version)) | |
version_file.truncate() | |
version_file.close() | |
print('Done!') | |
except: | |
print('File has not been uploaded yet, please try again later!') | |
else: | |
os.remove('yuzu.zip') | |
else: | |
print('You are on the newest version (' + str(current) + ')!') | |
input('Press any key...') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment