From 71ad1daf2b1e0c0ff7cbebfa30b5e92272847964 Mon Sep 17 00:00:00 2001 From: localhost_frssoft Date: Tue, 31 Jan 2023 15:23:56 +0300 Subject: [PATCH] Copy from cache --- src/utils.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/utils.py b/src/utils.py index aafd15a..f81c846 100644 --- a/src/utils.py +++ b/src/utils.py @@ -1,6 +1,7 @@ import src.fw_api import sys +import shutil from urllib.parse import unquote @@ -13,6 +14,10 @@ def get_remote_file_name(url): def download_track(url, name=None): + if not url.startswith('http'): + copy_from_cache(url) + return + url = url.split('?')[0] # Stripe all params from url r = src.fw_api.current_instance.s.get(url, stream=True) if not name: @@ -39,6 +44,12 @@ def download_track(url, name=None): return name +def copy_from_cache(url_file): + uuid = url_file.split(r'/')[-1] + original_name = get_remote_file_name(f'https://{src.fw_api.current_instance.instance}/api/v1/listen/{uuid}') + shutil.copyfile(url_file, original_name) + + def print_there(x, y, text): '''Print at position x, y caption in terminal (? Linux only)''' sys.stdout.write("\x1b7\x1b[%d;%df%s\x1b8" % (x, y, text))