small fixes
This commit is contained in:
parent
2ac8a4e1bc
commit
f11b5f014c
|
@ -13,7 +13,6 @@ from Crypto.Util import Counter
|
||||||
from typing import Tuple
|
from typing import Tuple
|
||||||
from typing import BinaryIO
|
from typing import BinaryIO
|
||||||
|
|
||||||
# MASTER_KEY = b64decode("UIlTTEMmmLfGowo/UC60x2H45W6MdGgTRfo/umg4754=")
|
|
||||||
MASTER_KEY = (
|
MASTER_KEY = (
|
||||||
b"P\x89SLC&\x98\xb7\xc6\xa3\n?P.\xb4\xc7a\xf8\xe5n\x8cth\x13E\xfa?\xbah8\xef\x9e"
|
b"P\x89SLC&\x98\xb7\xc6\xa3\n?P.\xb4\xc7a\xf8\xe5n\x8cth\x13E\xfa?\xbah8\xef\x9e"
|
||||||
)
|
)
|
||||||
|
@ -96,16 +95,16 @@ def download_track(
|
||||||
dest += ext
|
dest += ext
|
||||||
break
|
break
|
||||||
if os.path.exists(dest) and skip_dl:
|
if os.path.exists(dest) and skip_dl:
|
||||||
print(f"Skipping track")
|
print("Skipping track")
|
||||||
return
|
return
|
||||||
|
|
||||||
assert track.name and album.name
|
assert track.name and album.name
|
||||||
with io.BytesIO() as b:
|
with io.BytesIO() as b:
|
||||||
print(f"Downloading track")
|
print("Downloading track")
|
||||||
key_id = manifest.get("keyId", None)
|
key_id = manifest.get("keyId", None)
|
||||||
mime = __download_file(url, b)
|
mime = __download_file(url, b)
|
||||||
if key_id:
|
if key_id:
|
||||||
print(f"Decrypting track")
|
print("Decrypting track")
|
||||||
__decrypt_file(b, *__decode_key_id(key_id))
|
__decrypt_file(b, *__decode_key_id(key_id))
|
||||||
metadata.write(
|
metadata.write(
|
||||||
b,
|
b,
|
||||||
|
@ -124,7 +123,7 @@ def download_track(
|
||||||
http_failures += 1
|
http_failures += 1
|
||||||
except KeyboardInterrupt as e:
|
except KeyboardInterrupt as e:
|
||||||
raise e
|
raise e
|
||||||
except Exception as e:
|
except:
|
||||||
log_error(
|
log_error(
|
||||||
errorfile or "error.log",
|
errorfile or "error.log",
|
||||||
"Failure while downloading {artist} - {track}",
|
"Failure while downloading {artist} - {track}",
|
||||||
|
|
|
@ -14,7 +14,9 @@ def get_conf(state_dir: str | None = None, conf_file: str | None = None) -> dict
|
||||||
home = os.getenv("HOME")
|
home = os.getenv("HOME")
|
||||||
assert home
|
assert home
|
||||||
|
|
||||||
conf_file = (os.getenv("XDG_CONFIG_HOME") or home + "/.config") + "/tidal-scraper/conf.toml"
|
conf_file = (
|
||||||
|
os.getenv("XDG_CONFIG_HOME") or home + "/.config"
|
||||||
|
) + "/tidal-scraper/conf.toml"
|
||||||
with open(conf_file, "rb") as f:
|
with open(conf_file, "rb") as f:
|
||||||
conf = tomllib.load(f)
|
conf = tomllib.load(f)
|
||||||
|
|
||||||
|
@ -46,5 +48,5 @@ def log_error(logfile: str, template: str, **kwargs):
|
||||||
|
|
||||||
|
|
||||||
def human_sleep() -> None:
|
def human_sleep() -> None:
|
||||||
t = random.randrange(10, 50) / 10
|
t = random.randrange(1000, 5000) / 1000
|
||||||
time.sleep(t)
|
time.sleep(t)
|
||||||
|
|
|
@ -1,10 +1,23 @@
|
||||||
import json
|
import json
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from tidalapi import session, user, playlist, media, album, artist
|
from tidalapi import session, user, playlist, media, album, artist
|
||||||
|
from helper import log_error
|
||||||
|
|
||||||
|
|
||||||
class State:
|
class State:
|
||||||
def __init__(self, user_id: int, quality: str, dl_state_path: str):
|
def __init__(
|
||||||
|
self,
|
||||||
|
user_id: int,
|
||||||
|
quality: str,
|
||||||
|
dl_state_path: str,
|
||||||
|
conf: dict | None = None,
|
||||||
|
errorfile: str | None = None,
|
||||||
|
):
|
||||||
|
if conf is None:
|
||||||
|
assert errorfile is not None
|
||||||
|
else:
|
||||||
|
errorfile = errorfile or conf["error_log"]
|
||||||
|
|
||||||
match quality:
|
match quality:
|
||||||
case "master":
|
case "master":
|
||||||
q = session.Quality.master
|
q = session.Quality.master
|
||||||
|
@ -22,7 +35,11 @@ class State:
|
||||||
self.favorites = user.Favorites(self.session, user_id)
|
self.favorites = user.Favorites(self.session, user_id)
|
||||||
try:
|
try:
|
||||||
self.load_dl_state(dl_state_path)
|
self.load_dl_state(dl_state_path)
|
||||||
except:
|
except (FileNotFoundError, IndexError, AssertionError):
|
||||||
|
log_error(
|
||||||
|
errorfile or "error.log",
|
||||||
|
f"Could not find state file at {dl_state_path}",
|
||||||
|
)
|
||||||
self._state = {
|
self._state = {
|
||||||
"albums": {},
|
"albums": {},
|
||||||
"artists": {},
|
"artists": {},
|
||||||
|
|
Loading…
Reference in New Issue