mirror of
https://github.com/nathom/streamrip.git
synced 2025-05-20 18:25:30 -04:00
Misc changes
Formatting, remove extra functions, documentation
This commit is contained in:
parent
0966263556
commit
f93a018163
6 changed files with 26 additions and 32 deletions
|
@ -865,7 +865,7 @@ class Tracklist(list):
|
||||||
:param codec:
|
:param codec:
|
||||||
:param kwargs:
|
:param kwargs:
|
||||||
"""
|
"""
|
||||||
if (sr := kwargs.get("sampling_rate")) :
|
if sr := kwargs.get("sampling_rate"):
|
||||||
if sr < 44100:
|
if sr < 44100:
|
||||||
logger.warning(
|
logger.warning(
|
||||||
"Sampling rate %d is lower than 44.1kHz."
|
"Sampling rate %d is lower than 44.1kHz."
|
||||||
|
|
|
@ -36,7 +36,7 @@ if not os.path.isdir(CACHE_DIR):
|
||||||
@click.option("-t", "--text", metavar="PATH")
|
@click.option("-t", "--text", metavar="PATH")
|
||||||
@click.option("-nd", "--no-db", is_flag=True)
|
@click.option("-nd", "--no-db", is_flag=True)
|
||||||
@click.option("--debug", is_flag=True)
|
@click.option("--debug", is_flag=True)
|
||||||
@click.version_option(prog_name='streamrip')
|
@click.version_option(prog_name="streamrip")
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
def cli(ctx, **kwargs):
|
def cli(ctx, **kwargs):
|
||||||
"""Streamrip: The all-in-one Qobuz, Tidal, SoundCloud, and Deezer music downloader.
|
"""Streamrip: The all-in-one Qobuz, Tidal, SoundCloud, and Deezer music downloader.
|
||||||
|
|
|
@ -643,7 +643,7 @@ class TidalClient(Client):
|
||||||
click.launch(login_link)
|
click.launch(login_link)
|
||||||
|
|
||||||
start = time.time()
|
start = time.time()
|
||||||
elapsed = 0
|
elapsed = 0.0
|
||||||
while elapsed < 600: # 5 mins to login
|
while elapsed < 600: # 5 mins to login
|
||||||
elapsed = time.time() - start
|
elapsed = time.time() - start
|
||||||
status = self._check_auth_status()
|
status = self._check_auth_status()
|
||||||
|
|
|
@ -25,22 +25,14 @@ yaml = YAML()
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
# ---------- Utilities -------------
|
|
||||||
def _set_to_none(d: dict):
|
|
||||||
for k, v in d.items():
|
|
||||||
if isinstance(v, dict):
|
|
||||||
_set_to_none(v)
|
|
||||||
else:
|
|
||||||
d[k] = None
|
|
||||||
|
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
"""Config class that handles command line args and config files.
|
"""Config class that handles command line args and config files.
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
>>> config = Config('test_config.yaml')
|
|
||||||
>>> config.defaults['qobuz']['quality']
|
>>> config = Config('test_config.yaml')
|
||||||
3
|
>>> config.defaults['qobuz']['quality']
|
||||||
|
3
|
||||||
|
|
||||||
If test_config was already initialized with values, this will load them
|
If test_config was already initialized with values, this will load them
|
||||||
into `config`. Otherwise, a new config file is created with the default
|
into `config`. Otherwise, a new config file is created with the default
|
||||||
|
@ -204,7 +196,7 @@ class Config:
|
||||||
if source == "tidal":
|
if source == "tidal":
|
||||||
return self.tidal_creds
|
return self.tidal_creds
|
||||||
if source == "deezer" or source == "soundcloud":
|
if source == "deezer" or source == "soundcloud":
|
||||||
return dict()
|
return {}
|
||||||
|
|
||||||
raise InvalidSourceError(source)
|
raise InvalidSourceError(source)
|
||||||
|
|
||||||
|
@ -348,6 +340,7 @@ class ConfigDocumentation:
|
||||||
|
|
||||||
# ------------- ~~ Experimental ~~ ----------------- #
|
# ------------- ~~ Experimental ~~ ----------------- #
|
||||||
|
|
||||||
|
|
||||||
def load_yaml(path: str):
|
def load_yaml(path: str):
|
||||||
"""Load a streamrip config YAML file.
|
"""Load a streamrip config YAML file.
|
||||||
|
|
||||||
|
@ -374,33 +367,33 @@ def load_yaml(path: str):
|
||||||
level += 1
|
level += 1
|
||||||
|
|
||||||
chars.prev()
|
chars.prev()
|
||||||
if (c := next(chars)) == '#':
|
if (c := next(chars)) == "#":
|
||||||
# is a comment
|
# is a comment
|
||||||
continue
|
continue
|
||||||
|
|
||||||
elif c == '-':
|
elif c == "-":
|
||||||
# is an item in a list
|
# is an item in a list
|
||||||
next(chars)
|
next(chars)
|
||||||
val_l = list(chars)
|
val_l = list(chars)
|
||||||
level += 2 # it is a child of the previous key
|
level += 2 # it is a child of the previous key
|
||||||
item_type = 'list'
|
item_type = "list"
|
||||||
else:
|
else:
|
||||||
# undo char read
|
# undo char read
|
||||||
chars.prev()
|
chars.prev()
|
||||||
|
|
||||||
if not val_l:
|
if not val_l:
|
||||||
while (c := next(chars)) != ':':
|
while (c := next(chars)) != ":":
|
||||||
key_l.append(c)
|
key_l.append(c)
|
||||||
val_l = list(''.join(chars).strip())
|
val_l = list("".join(chars).strip())
|
||||||
|
|
||||||
if val_l:
|
if val_l:
|
||||||
val = ''.join(val_l)
|
val = "".join(val_l)
|
||||||
else:
|
else:
|
||||||
# start of a section
|
# start of a section
|
||||||
item_type = 'dict'
|
item_type = "dict"
|
||||||
val = type_dict[item_type]()
|
val = type_dict[item_type]()
|
||||||
|
|
||||||
key = ''.join(key_l)
|
key = "".join(key_l)
|
||||||
if level == 0:
|
if level == 0:
|
||||||
settings[key] = val
|
settings[key] = val
|
||||||
elif level == 2:
|
elif level == 2:
|
||||||
|
@ -424,7 +417,7 @@ class StringWalker:
|
||||||
:param s:
|
:param s:
|
||||||
:type s: str
|
:type s: str
|
||||||
"""
|
"""
|
||||||
self.__val = s.replace('\n', '')
|
self.__val = s.replace("\n", "")
|
||||||
self.__pos = 0
|
self.__pos = 0
|
||||||
|
|
||||||
def __next__(self) -> str:
|
def __next__(self) -> str:
|
||||||
|
|
|
@ -70,6 +70,7 @@ __MP4_KEYS = (
|
||||||
"disk",
|
"disk",
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
|
None,
|
||||||
)
|
)
|
||||||
|
|
||||||
__MP3_KEYS = (
|
__MP3_KEYS = (
|
||||||
|
@ -93,6 +94,7 @@ __MP3_KEYS = (
|
||||||
id3.TPOS,
|
id3.TPOS,
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
|
None,
|
||||||
)
|
)
|
||||||
|
|
||||||
__METADATA_TYPES = (
|
__METADATA_TYPES = (
|
||||||
|
@ -116,6 +118,7 @@ __METADATA_TYPES = (
|
||||||
"discnumber",
|
"discnumber",
|
||||||
"tracktotal",
|
"tracktotal",
|
||||||
"disctotal",
|
"disctotal",
|
||||||
|
"date",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -324,11 +324,9 @@ def get_container(quality: int, source: str) -> str:
|
||||||
:rtype: str
|
:rtype: str
|
||||||
"""
|
"""
|
||||||
if quality >= 2:
|
if quality >= 2:
|
||||||
container = "FLAC"
|
return "FLAC"
|
||||||
else:
|
|
||||||
if source == "tidal":
|
|
||||||
container = "AAC"
|
|
||||||
else:
|
|
||||||
container = "MP3"
|
|
||||||
|
|
||||||
return container
|
if source == "tidal":
|
||||||
|
return "AAC"
|
||||||
|
|
||||||
|
return "MP3"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue