mirror of
https://github.com/nathom/streamrip.git
synced 2025-05-13 14:44:49 -04:00
Make streamrip into a module
Signed-off-by: nathom <nathanthomas707@gmail.com>
This commit is contained in:
parent
6d2951a0e9
commit
bc917167d2
11 changed files with 48 additions and 40 deletions
|
@ -15,7 +15,7 @@ classifiers = [
|
|||
]
|
||||
|
||||
[tool.poetry.scripts]
|
||||
rip = "streamrip.cli:main"
|
||||
rip = "rip.cli:main"
|
||||
|
||||
[tool.poetry.dependencies]
|
||||
python = "^3.8"
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
click
|
||||
pathvalidate
|
||||
requests
|
||||
mutagen>=1.45.1
|
||||
tqdm
|
||||
tomlkit
|
3
rip/__main__.py
Normal file
3
rip/__main__.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from .cli import main
|
||||
|
||||
main()
|
|
@ -9,10 +9,10 @@ from hashlib import md5
|
|||
import click
|
||||
import requests
|
||||
|
||||
from . import __version__
|
||||
from .clients import TidalClient
|
||||
from streamrip import __version__
|
||||
from streamrip.clients import TidalClient
|
||||
from .config import Config
|
||||
from .constants import CACHE_DIR, CONFIG_DIR, CONFIG_PATH, QOBUZ_FEATURED_KEYS
|
||||
from streamrip.constants import CACHE_DIR, CONFIG_DIR, CONFIG_PATH, QOBUZ_FEATURED_KEYS
|
||||
from .core import MusicDL
|
||||
|
||||
logging.basicConfig(level="WARNING")
|
|
@ -10,8 +10,8 @@ from typing import Any, Dict
|
|||
import click
|
||||
import tomlkit
|
||||
|
||||
from .constants import CONFIG_DIR, CONFIG_PATH, DOWNLOADS_DIR
|
||||
from .exceptions import InvalidSourceError
|
||||
from streamrip.constants import CONFIG_DIR, CONFIG_PATH, DOWNLOADS_DIR
|
||||
from streamrip.exceptions import InvalidSourceError
|
||||
|
||||
logger = logging.getLogger("streamrip")
|
||||
|
|
@ -14,8 +14,8 @@ import click
|
|||
import requests
|
||||
from tqdm import tqdm
|
||||
|
||||
from .bases import Track, Video, YoutubeVideo
|
||||
from .clients import (
|
||||
from streamrip.bases import Track, Video, YoutubeVideo
|
||||
from streamrip.clients import (
|
||||
Client,
|
||||
DeezerClient,
|
||||
QobuzClient,
|
||||
|
@ -23,7 +23,7 @@ from .clients import (
|
|||
TidalClient,
|
||||
)
|
||||
from .config import Config
|
||||
from .constants import (
|
||||
from streamrip.constants import (
|
||||
CONFIG_PATH,
|
||||
DB_PATH,
|
||||
DEEZER_DYNAMIC_LINK_REGEX,
|
||||
|
@ -35,15 +35,15 @@ from .constants import (
|
|||
YOUTUBE_URL_REGEX,
|
||||
)
|
||||
from .db import MusicDB
|
||||
from .exceptions import (
|
||||
from streamrip.exceptions import (
|
||||
AuthenticationError,
|
||||
MissingCredentials,
|
||||
NonStreamable,
|
||||
NoResultsFound,
|
||||
ParsingError,
|
||||
)
|
||||
from .tracklists import Album, Artist, Label, Playlist, Tracklist
|
||||
from .utils import extract_deezer_dynamic_link, extract_interpreter_url
|
||||
from streamrip.tracklists import Album, Artist, Label, Playlist, Tracklist
|
||||
from streamrip.utils import extract_deezer_dynamic_link, extract_interpreter_url
|
||||
|
||||
logger = logging.getLogger("streamrip")
|
||||
|
||||
|
@ -98,7 +98,7 @@ class MusicDL(list):
|
|||
"soundcloud": SoundCloudClient(),
|
||||
}
|
||||
|
||||
self.db: Union[MusicDB, list]
|
||||
self.db: MusicDB
|
||||
db_settings = self.config.session["database"]
|
||||
if db_settings["enabled"]:
|
||||
path = db_settings["path"]
|
||||
|
@ -109,7 +109,7 @@ class MusicDL(list):
|
|||
self.config.file["database"]["path"] = DB_PATH
|
||||
self.config.save()
|
||||
else:
|
||||
self.db = []
|
||||
self.db = MusicDB(None, empty=True)
|
||||
|
||||
def handle_urls(self, urls):
|
||||
"""Download a url.
|
||||
|
@ -191,7 +191,6 @@ class MusicDL(list):
|
|||
session[key] for key in ("artwork", "conversion", "filepaths")
|
||||
)
|
||||
return {
|
||||
"database": self.db,
|
||||
"parent_folder": session["downloads"]["folder"],
|
||||
"folder_format": filepaths["folder_format"],
|
||||
"track_format": filepaths["track_format"],
|
||||
|
@ -254,15 +253,14 @@ class MusicDL(list):
|
|||
click.secho(f"{item!s} is not available, skipping.", fg="red")
|
||||
continue
|
||||
|
||||
item.download(**arguments)
|
||||
if item.download(**arguments) and hasattr(item, "id"):
|
||||
self.db.add(item.id)
|
||||
|
||||
if isinstance(item, Track):
|
||||
item.tag()
|
||||
if arguments["conversion"]["enabled"]:
|
||||
item.convert(**arguments["conversion"])
|
||||
|
||||
if self.db != [] and hasattr(item, "id"):
|
||||
self.db.add(item.id)
|
||||
|
||||
def get_client(self, source: str) -> Client:
|
||||
"""Get a client given the source and log in.
|
||||
|
|
@ -11,12 +11,15 @@ logger = logging.getLogger("streamrip")
|
|||
class MusicDB:
|
||||
"""Simple interface for the downloaded track database."""
|
||||
|
||||
def __init__(self, db_path: Union[str, os.PathLike]):
|
||||
def __init__(self, db_path: Union[str, os.PathLike], empty=False):
|
||||
"""Create a MusicDB object.
|
||||
|
||||
:param db_path: filepath of the database
|
||||
:type db_path: Union[str, os.PathLike]
|
||||
"""
|
||||
if empty:
|
||||
self.path = None
|
||||
|
||||
self.path = db_path
|
||||
if not os.path.exists(self.path):
|
||||
self.create()
|
||||
|
@ -39,6 +42,9 @@ class MusicDB:
|
|||
:type item_id: str
|
||||
:rtype: bool
|
||||
"""
|
||||
if self.path is None:
|
||||
return False
|
||||
|
||||
logger.debug("Checking database for ID %s", item_id)
|
||||
with sqlite3.connect(self.path) as conn:
|
||||
return (
|
||||
|
@ -55,6 +61,10 @@ class MusicDB:
|
|||
:type item_id: str
|
||||
"""
|
||||
logger.debug("Adding ID %s", item_id)
|
||||
|
||||
if self.path is None:
|
||||
return
|
||||
|
||||
with sqlite3.connect(self.path) as conn:
|
||||
try:
|
||||
conn.execute(
|
|
@ -1,3 +1,5 @@
|
|||
"""streamrip: the all in one music downloader."""
|
||||
|
||||
__version__ = "0.6.7"
|
||||
|
||||
from . import clients, converter, bases, tracklists, constants
|
||||
|
|
|
@ -163,15 +163,15 @@ class Track:
|
|||
|
||||
os.makedirs(self.folder, exist_ok=True)
|
||||
|
||||
if self.id in kwargs.get("database", []):
|
||||
self.downloaded = True
|
||||
self.tagged = True
|
||||
self.path = self.final_path
|
||||
decho(
|
||||
f"{self['title']} already logged in database, skipping.",
|
||||
fg="magenta",
|
||||
)
|
||||
return False # because the track was not downloaded
|
||||
# if self.id in kwargs.get("database", []):
|
||||
# self.downloaded = True
|
||||
# self.tagged = True
|
||||
# self.path = self.final_path
|
||||
# decho(
|
||||
# f"{self['title']} already logged in database, skipping.",
|
||||
# fg="magenta",
|
||||
# )
|
||||
# return False # because the track was not downloaded
|
||||
|
||||
if os.path.isfile(self.final_path): # track already exists
|
||||
self.downloaded = True
|
||||
|
@ -263,10 +263,10 @@ class Track:
|
|||
if not kwargs.get("stay_temp", False):
|
||||
self.move(self.final_path)
|
||||
|
||||
database = kwargs.get("database")
|
||||
if database:
|
||||
database.add(self.id)
|
||||
logger.debug(f"{self.id} added to database")
|
||||
# database = kwargs.get("database")
|
||||
# if database:
|
||||
# database.add(self.id)
|
||||
# logger.debug(f"{self.id} added to database")
|
||||
|
||||
logger.debug("Downloaded: %s -> %s", self.path, self.final_path)
|
||||
|
||||
|
|
|
@ -14,7 +14,8 @@ from pathvalidate import sanitize_filename
|
|||
from .bases import Booklet, Track, Tracklist, Video
|
||||
from .clients import Client
|
||||
from .constants import ALBUM_KEYS, FLAC_MAX_BLOCKSIZE, FOLDER_FORMAT
|
||||
from .db import MusicDB
|
||||
|
||||
# from .db import MusicDB
|
||||
from .exceptions import InvalidSourceError, NonStreamable
|
||||
from .metadata import TrackMetadata
|
||||
from .utils import (
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue