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