dl/commands/tinfoil.py
Michel Roux f64c87732a
All checks were successful
dl / lint (push) Successful in 1m15s
dl / docker (push) Successful in 53s
Use nsz base
2023-09-11 09:02:57 +02:00

82 lines
1.7 KiB
Python
Executable File

#!/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)
args = parser.parse_args()
remote = args.remote
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")
proc_bases = subprocess.run(
["rclone", "lsf", f"{remote}:nsz/base"],
check=True,
capture_output=True,
)
bases = proc_bases.stdout.decode().split("\n")
print("Base OK")
proc_dlcs = subprocess.run(
["rclone", "lsf", f"{remote}:nsz/dlc"],
check=True,
capture_output=True,
)
dlcs = proc_dlcs.stdout.decode().split("\n")
print("DLC OK")
proc_updates = subprocess.run(
["rclone", "lsf", f"{remote}:nsz/updates"],
check=True,
capture_output=True,
)
updates = proc_updates.stdout.decode().split("\n")
print("Updates OK")
def download(path, file):
if os.path.isfile(os.path.join(path, file)):
return
subprocess.run(
["rclone", "copy", "-P", "-v", f"{remote}:{path}/{base}", f"{path}/"],
check=True,
stdout=sys.stdout,
)
for base in bases:
re_id = re.search(r"\[([0-9A-F]*)\]", base)
if not re_id:
continue
id = re_id.group(1)
if 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)