From 229fe6881883e5172088bddc811d4b9efef313a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BA=90=E6=96=87=E9=9B=A8?= <41315874+fumiama@users.noreply.github.com> Date: Sun, 21 Apr 2024 01:59:01 +0900 Subject: [PATCH] feat(rvcmd): add dns and dl link fallback --- .github/workflows/unitest.yml | 2 +- go-realtime-gui-dml.bat | 2 +- go-realtime-gui.bat | 2 +- go-web-dml.bat | 2 +- go-web.bat | 2 +- infer-web.py | 11 +++---- infer/lib/rvcmd.py | 56 ++++++++++++++++++++++++++--------- tools/ipynb/v1.ipynb | 4 +-- tools/ipynb/v2.ipynb | 4 +-- 9 files changed, 57 insertions(+), 28 deletions(-) diff --git a/.github/workflows/unitest.yml b/.github/workflows/unitest.yml index d38a76a..c5a7d80 100644 --- a/.github/workflows/unitest.yml +++ b/.github/workflows/unitest.yml @@ -19,7 +19,7 @@ jobs: run: | sudo apt update sudo apt -y install ffmpeg - wget https://github.com/RVC-Project/RVC-Models-Downloader/releases/download/v0.2.1/rvcmd_linux_amd64.deb + wget https://github.com/RVC-Project/RVC-Models-Downloader/releases/download/v0.2.2/rvcmd_linux_amd64.deb sudo apt -y install ./rvcmd_linux_amd64.deb python -m pip install --upgrade pip python -m pip install --upgrade setuptools diff --git a/go-realtime-gui-dml.bat b/go-realtime-gui-dml.bat index 2c87633..0f92142 100644 --- a/go-realtime-gui-dml.bat +++ b/go-realtime-gui-dml.bat @@ -1,2 +1,2 @@ -runtime\python.exe gui_v1.py --pycmd runtime\python.exe --dml +runtime\python.exe gui_v1.py --pycmd runtime\python.exe --nocheck --dml pause diff --git a/go-realtime-gui.bat b/go-realtime-gui.bat index 8c08290..d0ed2dc 100644 --- a/go-realtime-gui.bat +++ b/go-realtime-gui.bat @@ -1,2 +1,2 @@ -runtime\python.exe gui_v1.py +runtime\python.exe --nocheck gui_v1.py pause diff --git a/go-web-dml.bat b/go-web-dml.bat index fc5e708..2bb2901 100644 --- a/go-web-dml.bat +++ b/go-web-dml.bat @@ -1,2 +1,2 @@ -runtime\python.exe infer-web.py --pycmd runtime\python.exe --port 7897 --dml +runtime\python.exe infer-web.py --pycmd runtime\python.exe --nocheck --port 7897 --dml pause diff --git a/go-web.bat b/go-web.bat index db1dec5..3b91773 100644 --- a/go-web.bat +++ b/go-web.bat @@ -1,2 +1,2 @@ -runtime\python.exe infer-web.py --pycmd runtime\python.exe --port 7897 +runtime\python.exe infer-web.py --pycmd runtime\python.exe --nocheck --port 7897 pause diff --git a/infer-web.py b/infer-web.py index 7e28423..98ba598 100644 --- a/infer-web.py +++ b/infer-web.py @@ -13,7 +13,6 @@ from infer.lib.train.process_ckpt import ( merge, show_info, ) -from infer.lib.rvcmd import check_all_assets, download_all_assets from i18n.i18n import I18nAuto from configs.config import Config from sklearn.cluster import MiniBatchKMeans @@ -54,11 +53,13 @@ torch.manual_seed(114514) config = Config() vc = VC(config) -if not config.nocheck and not check_all_assets(): - download_all_assets(tmpdir=tmp) +if not config.nocheck: + from infer.lib.rvcmd import check_all_assets, download_all_assets if not check_all_assets(): - logging.error("counld not satisfy all assets needed.") - exit(1) + download_all_assets(tmpdir=tmp) + if not check_all_assets(): + logging.error("counld not satisfy all assets needed.") + exit(1) if config.dml == True: diff --git a/infer/lib/rvcmd.py b/infer/lib/rvcmd.py index db4c89f..b17e376 100644 --- a/infer/lib/rvcmd.py +++ b/infer/lib/rvcmd.py @@ -30,6 +30,7 @@ def check_model(dir_name: Path, model_name: str, hash: str) -> bool: logger.info(f"{target} sha256 hash mismatch.") logger.info(f"expected: {hash}") logger.info(f"real val: {digest}") + os.remove(str(target)) return False return True @@ -113,7 +114,7 @@ def download_and_extract_tar_gz(url: str, folder: str): import tarfile logger.info(f"downloading {url}") - response = requests.get(url, stream=True) + response = requests.get(url, stream=True, timeout=(5,10)) with BytesIO() as out_file: out_file.write(response.content) out_file.seek(0) @@ -127,7 +128,7 @@ def download_and_extract_zip(url: str, folder: str): import zipfile logger.info(f"downloading {url}") - response = requests.get(url) + response = requests.get(url, stream=True, timeout=(5,10)) with BytesIO() as out_file: out_file.write(response.content) out_file.seek(0) @@ -136,8 +137,14 @@ def download_and_extract_zip(url: str, folder: str): zip_ref.extractall(folder) logger.info(f"extracted into {folder}") +def download_dns_yaml(url: str, folder: str): + logger.info(f"downloading {url}") + response = requests.get(url, stream=True, timeout=(5,10)) + with open(f"{folder}/dns.yaml", "wb") as out_file: + out_file.write(response.content) + logger.info(f"downloaded into {folder}") -def download_all_assets(tmpdir: str, version="0.2.1"): +def download_all_assets(tmpdir: str, version="0.2.2"): import subprocess import platform @@ -161,14 +168,35 @@ def download_all_assets(tmpdir: str, version="0.2.1"): if not architecture: logger.error(f"architecture {architecture} is not supported") exit(1) - BASE_URL = "https://github.com/RVC-Project/RVC-Models-Downloader/releases/download/" - suffix = "zip" if is_win else "tar.gz" - RVCMD_URL = BASE_URL + f"v{version}/rvcmd_{system_type}_{architecture}.{suffix}" - cmdfile = tmpdir + "/rvcmd" - if is_win: - download_and_extract_zip(RVCMD_URL, tmpdir) - cmdfile += ".exe" - else: - download_and_extract_tar_gz(RVCMD_URL, tmpdir) - os.chmod(cmdfile, 0o755) - subprocess.run([cmdfile, "-notui", "-w", "0", "assets/all"]) + try: + BASE_URL = "https://github.com/RVC-Project/RVC-Models-Downloader/releases/download/" + suffix = "zip" if is_win else "tar.gz" + RVCMD_URL = BASE_URL + f"v{version}/rvcmd_{system_type}_{architecture}.{suffix}" + cmdfile = tmpdir + "/rvcmd" + if is_win: + download_and_extract_zip(RVCMD_URL, tmpdir) + cmdfile += ".exe" + else: + download_and_extract_tar_gz(RVCMD_URL, tmpdir) + os.chmod(cmdfile, 0o755) + subprocess.run([cmdfile, "-notui", "-w", "0", "assets/all"]) + except Exception: + BASE_URL = "https://raw.gitcode.com/u011570312/RVC-Models-Downloader/assets/" + suffix = { + "darwin_amd64": "421", + "darwin_arm64": "422", + "linux_386": "423", + "linux_amd64": "424", + "linux_arm64": "425", + "windows_386": "426", + "windows_amd64": "427", + }[f"{system_type}_{architecture}"] + RVCMD_URL = BASE_URL + suffix + download_dns_yaml("https://raw.gitcode.com/u011570312/RVC-Models-Downloader/raw/main/dns.yaml", tmpdir) + if is_win: + download_and_extract_zip(RVCMD_URL, tmpdir) + cmdfile += ".exe" + else: + download_and_extract_tar_gz(RVCMD_URL, tmpdir) + os.chmod(cmdfile, 0o755) + subprocess.run([cmdfile, "-notui", "-w", "0", "-dns", f"{tmpdir}/dns.yaml", "assets/all"]) diff --git a/tools/ipynb/v1.ipynb b/tools/ipynb/v1.ipynb index 78a867f..b9e64dd 100644 --- a/tools/ipynb/v1.ipynb +++ b/tools/ipynb/v1.ipynb @@ -94,7 +94,7 @@ "outputs": [], "source": [ "# @title 下载安装 RVC-Models-Downloader\n", - "!wget https://github.com/RVC-Project/RVC-Models-Downloader/releases/download/v0.2.1/rvcmd_linux_amd64.deb\n", + "!wget https://github.com/RVC-Project/RVC-Models-Downloader/releases/download/v0.2.2/rvcmd_linux_amd64.deb\n", "!apt install ./rvcmd_linux_amd64.deb" ] }, @@ -350,4 +350,4 @@ }, "nbformat": 4, "nbformat_minor": 0 -} \ No newline at end of file +} diff --git a/tools/ipynb/v2.ipynb b/tools/ipynb/v2.ipynb index 1275311..e1464a8 100644 --- a/tools/ipynb/v2.ipynb +++ b/tools/ipynb/v2.ipynb @@ -94,7 +94,7 @@ "outputs": [], "source": [ "# @title 下载安装 RVC-Models-Downloader\n", - "!wget https://github.com/RVC-Project/RVC-Models-Downloader/releases/download/v0.2.1/rvcmd_linux_amd64.deb\n", + "!wget https://github.com/RVC-Project/RVC-Models-Downloader/releases/download/v0.2.2/rvcmd_linux_amd64.deb\n", "!apt install ./rvcmd_linux_amd64.deb" ] }, @@ -349,4 +349,4 @@ }, "nbformat": 4, "nbformat_minor": 0 -} \ No newline at end of file +}