#!/usr/bin/env python3 import argparse import os import re import subprocess import sys import requests parser = argparse.ArgumentParser() parser.add_argument("-r", "--remote", type=str, required=True) parser.add_argument("-f", "--force", action=argparse.BooleanOptionalAction) args = parser.parse_args() remote = args.remote force = args.force def drive_list(path): proc = subprocess.run( ["rclone", "lsf", f"{remote}:{path}"], check=True, capture_output=True, ) return proc.stdout.decode().split("\n") def download(path, file): if os.path.isfile(os.path.join(path, file)): return subprocess.run( ["rclone", "copy", "-P", "-v", f"{remote}:{path}/{file}", f"{path}/"], check=True, stdout=sys.stdout, ) req_titles = requests.get( "https://raw.githubusercontent.com/blawar/titledb/master/FR.fr.json" ) json_titles = req_titles.json() titles = [] for json_title in json_titles: titles.append(json_titles[json_title]["id"]) print("Titles OK") bases = drive_list("nsz/base") print("Base OK") dlcs = drive_list("nsz/dlc") print("DLC OK") updates = drive_list("nsz/updates") print("Updates OK") for base in bases: re_id = re.search(r"\[([0-9A-F]*)\]", base) if not re_id: continue id = re_id.group(1) if not force and id not in titles: continue id = id[0:-4] download("nsz/base", base) for dlc in dlcs: if id in dlc: download("nsz/dlc", dlc) for update in updates: if id in update: download("nsz/updates", update)