Formatting

This commit is contained in:
nathom 2021-03-29 15:46:26 -07:00
parent d05bd9632d
commit ecae32e9b8
6 changed files with 25 additions and 22 deletions

View file

@ -172,11 +172,11 @@ def discover(ctx, **kwargs):
@cli.command()
@click.option("-o", "--open", is_flag=True, help="Open the config file")
@click.option("-q", "--qobuz", is_flag=True, help="Set Qobuz credentials")
@click.option("--reset", is_flag=True, help='RESET the config file')
@click.option("--reset", is_flag=True, help="RESET the config file")
@click.pass_context
def config(ctx, **kwargs):
"""Manage the streamrip configuration."""
if kwargs['reset']:
if kwargs["reset"]:
config.reset()
if kwargs["open"]:

View file

@ -12,16 +12,16 @@ from typing import Generator, Sequence, Tuple, Union
import click
import requests
from requests.packages import urllib3
from dogpile.cache import make_region
from requests.packages import urllib3
from .constants import (
AGENT,
AVAILABLE_QUALITY_IDS,
CACHE_DIR,
DEEZER_MAX_Q,
QOBUZ_FEATURED_KEYS,
TIDAL_MAX_Q,
AVAILABLE_QUALITY_IDS,
)
from .exceptions import (
AuthenticationError,
@ -30,8 +30,8 @@ from .exceptions import (
InvalidAppSecretError,
InvalidQuality,
)
from .utils import get_quality
from .spoofbuz import Spoofer
from .utils import get_quality
urllib3.disable_warnings()
requests.adapters.DEFAULT_RETRIES = 5
@ -324,7 +324,9 @@ class QobuzClient(ClientInterface):
unix_ts = time.time()
if int(quality) not in AVAILABLE_QUALITY_IDS: # Needed?
raise InvalidQuality(f"Invalid quality id {quality}. Choose from {AVAILABLE_QUALITY_IDS}")
raise InvalidQuality(
f"Invalid quality id {quality}. Choose from {AVAILABLE_QUALITY_IDS}"
)
if sec is not None:
secret = sec
@ -472,7 +474,7 @@ class TidalClient(ClientInterface):
self._login_new_user()
self.logged_in = True
click.secho("Logged into Tidal", fg='green')
click.secho("Logged into Tidal", fg="green")
def get(self, item_id, media_type):
return self._api_get(item_id, media_type)

View file

@ -129,9 +129,9 @@ class Config:
@property
def tidal_creds(self):
creds = dict(self.file['tidal'])
creds = dict(self.file["tidal"])
logger.debug(creds)
del creds['quality'] # should not be included in creds
del creds["quality"] # should not be included in creds
return creds
@property

View file

@ -124,12 +124,14 @@ class MusicDL(list):
arguments = {
"database": self.db,
"parent_folder": self.config.session["downloads"]["folder"],
"keep_cover": self.config.session['keep_cover'],
"large_cover": self.config.session['metadata']['large_cover'],
# TODO: fully implement this
# "embed_cover": self.config.session["metadata"]["embed_cover"],
}
logger.debug("Arguments from config: %s", arguments)
for item in self:
arguments['quality'] = self.config.session[item.client.source]['quality']
arguments["quality"] = self.config.session[item.client.source]["quality"]
if isinstance(item, Artist):
filters_ = tuple(
k for k, v in self.config.session["filters"].items() if v
@ -188,8 +190,8 @@ class MusicDL(list):
self.config.file["qobuz"]["secrets"],
) = client.get_tokens()
self.config.save()
elif client.source == 'tidal':
self.config.file['tidal'].update(client.get_tokens())
elif client.source == "tidal":
self.config.file["tidal"].update(client.get_tokens())
self.config.save()
def parse_urls(self, url: str) -> Tuple[str, str]:

View file

@ -10,7 +10,6 @@ from tempfile import gettempdir
from typing import Any, Callable, Optional, Tuple, Union
import click
import requests
from mutagen.flac import FLAC, Picture
from mutagen.id3 import APIC, ID3, ID3NoHeaderError
from pathvalidate import sanitize_filename, sanitize_filepath
@ -598,8 +597,8 @@ class Tracklist(list, ABC):
return cover_obj
@staticmethod
@abstractmethod
@staticmethod
def _parse_get_resp(item, client):
pass
@ -664,7 +663,7 @@ class Album(Tracklist):
for k, v in self._parse_get_resp(self.meta, self.client).items():
setattr(self, k, v) # prefer to __dict__.update for properties
if not self.get("streamable", False): # Typing's sake
if not self.get("streamable", False):
raise NonStreamable(f"This album is not streamable ({self.id} ID)")
self._load_tracks()
@ -714,7 +713,7 @@ class Album(Tracklist):
},
"streamable": resp.get("allowStreaming"),
"quality": TIDAL_Q_MAP[resp.get("audioQuality")],
"bit_depth": 24 if resp.get("audioQuality") == 'HI_RES' else 16,
"bit_depth": 24 if resp.get("audioQuality") == "HI_RES" else 16,
"sampling_rate": 44100, # always 44.1 kHz
"tracktotal": resp.get("numberOfTracks"),
}
@ -1106,11 +1105,11 @@ class Artist(Tracklist):
generate album objects and append them to self.
"""
if self.client.source == "qobuz":
self.name = self.meta['name']
self.name = self.meta["name"]
albums = self.meta["albums"]["items"]
elif self.client.source == "tidal":
self.name = self.meta['items'][0]['artist']['name']
self.name = self.meta["items"][0]["artist"]["name"]
albums = self.meta["items"]
elif self.client.source == "deezer":

View file

@ -12,7 +12,7 @@ from pathvalidate import sanitize_filename
from tqdm import tqdm
from .constants import LOG_DIR, TIDAL_COVER_URL
from .exceptions import NonStreamable, InvalidSourceError
from .exceptions import InvalidSourceError, NonStreamable
logger = logging.getLogger(__name__)
@ -46,21 +46,21 @@ def get_quality(quality_id: int, source: str) -> Union[str, int]:
:type source: str
:rtype: Union[str, int]
"""
if source == 'qobuz':
if source == "qobuz":
q_map = {
1: 5,
2: 6,
3: 7,
4: 27,
}
elif source == 'tidal':
elif source == "tidal":
q_map = {
0: "LOW", # AAC
1: "HIGH", # AAC
2: "LOSSLESS", # CD Quality
3: "HI_RES", # MQA
}
elif source == 'deezer':
elif source == "deezer":
q_map = {
0: 128,
1: 320,