mirror of
https://github.com/nathom/streamrip.git
synced 2025-06-04 17:03:48 -04:00
Add dosctrings
This commit is contained in:
parent
8d0dc7fb7f
commit
e73bff8d6b
12 changed files with 295 additions and 106 deletions
|
@ -0,0 +1 @@
|
|||
"""Rip: an easy to use command line utility for downloading audio streams."""
|
|
@ -1,3 +1,4 @@
|
|||
"""Run the rip program."""
|
||||
from .cli import main
|
||||
|
||||
main()
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
"""Various constant values that are used by RipCore."""
|
||||
|
||||
import os
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
|
|
@ -240,6 +240,10 @@ class RipCore(list):
|
|||
}
|
||||
|
||||
def repair(self, max_items=None):
|
||||
"""Iterate through the failed_downloads database and retry them.
|
||||
|
||||
:param max_items: The maximum number of items to download.
|
||||
"""
|
||||
if max_items is None:
|
||||
max_items = float("inf")
|
||||
|
||||
|
@ -331,6 +335,11 @@ class RipCore(list):
|
|||
item.convert(**arguments["conversion"])
|
||||
|
||||
def scrape(self, featured_list: str):
|
||||
"""Download all of the items in a Qobuz featured list.
|
||||
|
||||
:param featured_list: The name of the list. See `rip discover --help`.
|
||||
:type featured_list: str
|
||||
"""
|
||||
self.extend(self.search("qobuz", featured_list, "featured", limit=500))
|
||||
|
||||
def get_client(self, source: str) -> Client:
|
||||
|
|
27
rip/db.py
27
rip/db.py
|
@ -15,6 +15,11 @@ class Database:
|
|||
name: str
|
||||
|
||||
def __init__(self, path, dummy=False):
|
||||
"""Create a Database instance.
|
||||
|
||||
:param path: Path to the database file.
|
||||
:param dummy: Make the database empty.
|
||||
"""
|
||||
assert self.structure != []
|
||||
assert self.name
|
||||
|
||||
|
@ -72,7 +77,15 @@ class Database:
|
|||
|
||||
return bool(conn.execute(command, tuple(items.values())).fetchone()[0])
|
||||
|
||||
def __contains__(self, keys: dict) -> bool:
|
||||
def __contains__(self, keys: Union[str, dict]) -> bool:
|
||||
"""Check whether a key-value pair exists in the database.
|
||||
|
||||
:param keys: Either a dict with the structure {key: value_to_search_for, ...},
|
||||
or if there is only one key in the table, value_to_search_for can be
|
||||
passed in by itself.
|
||||
:type keys: Union[str, dict]
|
||||
:rtype: bool
|
||||
"""
|
||||
if isinstance(keys, dict):
|
||||
return self.contains(**keys)
|
||||
|
||||
|
@ -119,6 +132,12 @@ class Database:
|
|||
logger.debug(e)
|
||||
|
||||
def remove(self, **items):
|
||||
"""Remove items from a table.
|
||||
|
||||
Warning: NOT TESTED!
|
||||
|
||||
:param items:
|
||||
"""
|
||||
# not in use currently
|
||||
if self.is_dummy:
|
||||
return
|
||||
|
@ -131,6 +150,7 @@ class Database:
|
|||
conn.execute(command, tuple(items.values()))
|
||||
|
||||
def __iter__(self):
|
||||
"""Iterate through the rows of the table."""
|
||||
if self.is_dummy:
|
||||
return ()
|
||||
|
||||
|
@ -138,6 +158,7 @@ class Database:
|
|||
return conn.execute(f"SELECT * FROM {self.name}")
|
||||
|
||||
def reset(self):
|
||||
"""Delete the database file."""
|
||||
try:
|
||||
os.remove(self.path)
|
||||
except FileNotFoundError:
|
||||
|
@ -145,6 +166,8 @@ class Database:
|
|||
|
||||
|
||||
class Downloads(Database):
|
||||
"""A table that stores the downloaded IDs."""
|
||||
|
||||
name = "downloads"
|
||||
structure = {
|
||||
"id": ["text", "unique"],
|
||||
|
@ -152,6 +175,8 @@ class Downloads(Database):
|
|||
|
||||
|
||||
class FailedDownloads(Database):
|
||||
"""A table that stores information about failed downloads."""
|
||||
|
||||
name = "failed_downloads"
|
||||
structure = {
|
||||
"source": ["text"],
|
||||
|
|
|
@ -1,2 +1,5 @@
|
|||
"""Exceptions used by RipCore."""
|
||||
|
||||
|
||||
class DeezloaderFallback(Exception):
|
||||
pass
|
||||
"""Raise if Deezer account isn't logged in and rip is falling back to Deezloader."""
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
"""Utility functions for RipCore."""
|
||||
|
||||
import re
|
||||
from typing import Tuple
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue