Fixes misc bugs related to configs, tags
- Replaced code that tagged the files was accidentally removed - Fix error where config and cache dirs don’t exist - Fix some issues with storing secrets, removed the empty str that is sometimes there - Rename config.__path to _path for access if needed
This commit is contained in:
+11
-1
@@ -8,11 +8,17 @@ import click
|
||||
from qobuz_dl_rewrite.config import Config
|
||||
from qobuz_dl_rewrite.core import QobuzDL
|
||||
from qobuz_dl_rewrite.utils import init_log
|
||||
from qobuz_dl_rewrite.constants import CONFIG_DIR, CACHE_DIR
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _get_config(ctx):
|
||||
if not os.path.isdir(CONFIG_DIR):
|
||||
os.makedirs(CONFIG_DIR)
|
||||
if not os.path.isdir(CACHE_DIR):
|
||||
os.makedirs(CONFIG_DIR)
|
||||
|
||||
config = Config(ctx.obj.get("config"))
|
||||
config.load()
|
||||
config.update_from_cli(**ctx.obj)
|
||||
@@ -93,6 +99,10 @@ def download(ctx, items):
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
def main():
|
||||
cli.add_command(download)
|
||||
cli(obj={})
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
@@ -124,7 +124,7 @@ class QobuzClient(ClientInterface):
|
||||
logger.debug("Already logged in")
|
||||
return
|
||||
|
||||
if not (kwargs.get("app_id") or kwargs.get("secrets")):
|
||||
if (kwargs.get("app_id") or kwargs.get("secrets")) in (None, ['']):
|
||||
logger.info("Fetching tokens from Qobuz")
|
||||
spoofer = Spoofer()
|
||||
kwargs["app_id"] = spoofer.get_app_id()
|
||||
@@ -312,7 +312,13 @@ class QobuzClient(ClientInterface):
|
||||
if int(quality) not in (5, 6, 7, 27): # Needed?
|
||||
raise InvalidQuality(f"Invalid quality id {quality}. Choose 5, 6, 7 or 27")
|
||||
|
||||
secret = sec or self.sec
|
||||
if sec is not None:
|
||||
secret = sec
|
||||
elif hasattr(self, 'sec'):
|
||||
secret = self.sec
|
||||
else:
|
||||
raise InvalidAppSecretError('Cannot find app secret')
|
||||
|
||||
r_sig = f"trackgetFileUrlformat_id{quality}intentstreamtrack_id{track_id}{unix_ts}{secret}"
|
||||
logger.debug("Raw request signature: %s", r_sig)
|
||||
r_sig_hashed = hashlib.md5(r_sig.encode("utf-8")).hexdigest()
|
||||
|
||||
@@ -65,7 +65,7 @@ class Config:
|
||||
}
|
||||
self.path_format = {"folder": folder_format, "track": track_format}
|
||||
|
||||
self.__path = config_path or CONFIG_PATH
|
||||
self._path = config_path or CONFIG_PATH
|
||||
self.__loaded = False
|
||||
|
||||
def save(self):
|
||||
@@ -76,25 +76,25 @@ class Config:
|
||||
if not k.startswith("_"):
|
||||
info[k] = v
|
||||
|
||||
with open(self.__path, "w") as cfg:
|
||||
logger.debug("Config saved: %s", self.__path)
|
||||
with open(self._path, "w") as cfg:
|
||||
logger.debug("Config saved: %s", self._path)
|
||||
yaml.dump(info, cfg)
|
||||
|
||||
def load(self):
|
||||
if not os.path.isfile(self.__path):
|
||||
logger.debug("File not found. Creating one: %s", self.__path)
|
||||
if not os.path.isfile(self._path):
|
||||
logger.debug("File not found. Creating one: %s", self._path)
|
||||
self.__loaded = True
|
||||
self.save()
|
||||
|
||||
click.secho(
|
||||
"A config file has been created. Please update it "
|
||||
f"with your credentials: {self.__path}",
|
||||
f"with your credentials: {self._path}",
|
||||
fg="yellow",
|
||||
)
|
||||
else:
|
||||
logger.debug("Config file found: %s", self.__path)
|
||||
logger.debug("Config file found: %s", self._path)
|
||||
|
||||
with open(self.__path) as cfg:
|
||||
with open(self._path) as cfg:
|
||||
self.__dict__.update(yaml.load(cfg))
|
||||
|
||||
logger.debug("Config loaded")
|
||||
@@ -127,7 +127,7 @@ class Config:
|
||||
"email": self.qobuz["email"],
|
||||
"pwd": self.qobuz["password"],
|
||||
"app_id": self.qobuz["app_id"],
|
||||
"secrets": self.qobuz["secrets"].split(","),
|
||||
"secrets": self.qobuz["secrets"],
|
||||
}
|
||||
|
||||
def creds(self, source: str):
|
||||
|
||||
@@ -72,7 +72,6 @@ class QobuzDL:
|
||||
|
||||
def handle_item(self, media_type, item_id):
|
||||
arguments = {
|
||||
# TODO: add option for album/playlist subfolders
|
||||
"parent_folder": self.config.downloads["folder"],
|
||||
"quality": self.config.downloads["quality"],
|
||||
"embed_cover": self.config.metadata["embed_cover"],
|
||||
|
||||
@@ -327,6 +327,10 @@ class Track:
|
||||
else:
|
||||
raise InvalidQuality(f'Invalid quality: "{self.quality}"')
|
||||
|
||||
# automatically generate key, value pairs based on container
|
||||
for k, v in self.meta.tags(self.container):
|
||||
audio[k] = v
|
||||
|
||||
if cover is None and embed_cover:
|
||||
assert hasattr(self, "cover")
|
||||
cover = self.cover
|
||||
|
||||
@@ -51,4 +51,6 @@ class Spoofer:
|
||||
secrets[secret_pair] = base64.standard_b64decode(
|
||||
"".join(secrets[secret_pair])[:-44]
|
||||
).decode("utf-8")
|
||||
return secrets.values()
|
||||
vals = list(secrets.values())
|
||||
vals.remove("")
|
||||
return vals
|
||||
|
||||
Reference in New Issue
Block a user