Add option to download videos and booklets in config; #53

This commit is contained in:
nathom 2021-04-17 13:13:32 -07:00
parent b0f6e7b197
commit c4f2740d93
4 changed files with 15 additions and 6 deletions

View file

@ -594,6 +594,8 @@ class Video:
p = subprocess.Popen(command) p = subprocess.Popen(command)
p.wait() # remove this? p.wait() # remove this?
return False # so that it is not tagged
@classmethod @classmethod
def from_album_meta(cls, track: dict, client: Client): def from_album_meta(cls, track: dict, client: Client):
return cls( return cls(

View file

@ -48,6 +48,7 @@ class Config:
defaults = { defaults = {
"qobuz": { "qobuz": {
"quality": 3, "quality": 3,
"download_booklets": True,
"email": None, "email": None,
"password": None, "password": None,
"app_id": "", "app_id": "",
@ -55,6 +56,7 @@ class Config:
}, },
"tidal": { "tidal": {
"quality": 3, "quality": 3,
"download_videos": True,
"user_id": None, "user_id": None,
"country_code": None, "country_code": None,
"access_token": None, "access_token": None,
@ -115,10 +117,11 @@ class Config:
self.load() self.load()
def update(self): def update(self):
"""Resets the config file except for credentials."""
self.reset() self.reset()
temp = copy.deepcopy(self.defaults) temp = copy.deepcopy(self.defaults)
temp["qobuz"] = self.file["qobuz"] temp["qobuz"].update(self.file["qobuz"])
temp["tidal"] = self.file["tidal"] temp['tidal'].update(self.file['tidal'])
self.dump(temp) self.dump(temp)
def save(self): def save(self):
@ -209,11 +212,13 @@ class ConfigDocumentation:
"""Documentation is stored in this docstring. """Documentation is stored in this docstring.
qobuz: qobuz:
quality: 1: 320kbps MP3, 2: 16/44.1, 3: 24/<=96, 4: 24/>=96 quality: 1: 320kbps MP3, 2: 16/44.1, 3: 24/<=96, 4: 24/>=96
download_booklets: This will download booklet pdfs that are included with some albums
password: This is an md5 hash of the plaintext password password: This is an md5 hash of the plaintext password
app_id: Do not change app_id: Do not change
secrets: Do not change secrets: Do not change
tidal: tidal:
quality: 0, 1, 2, or 3 quality: 0, 1, 2, or 3
download_videos: This will download videos included in Video Albums.
user_id: Do not change any of the fields below user_id: Do not change any of the fields below
token_expiry: Tokens last 1 week after refresh. This is the Unix timestamp of the expiration time. token_expiry: Tokens last 1 week after refresh. This is the Unix timestamp of the expiration time.
deezer: Deezer doesn't require login deezer: Deezer doesn't require login

View file

@ -132,6 +132,8 @@ class MusicDL(list):
"new_tracknumbers": self.config.session["metadata"][ "new_tracknumbers": self.config.session["metadata"][
"new_playlist_tracknumbers" "new_playlist_tracknumbers"
], ],
"download_videos": self.config.session['tidal']['download_videos'],
'download_booklets': self.config.session['qobuz']['download_booklets'],
} }
def download(self): def download(self):

View file

@ -7,7 +7,7 @@ import logging
import os import os
import re import re
from tempfile import gettempdir from tempfile import gettempdir
from typing import Generator, Iterable from typing import Generator, Iterable, Union
import click import click
from pathvalidate import sanitize_filename from pathvalidate import sanitize_filename
@ -139,20 +139,20 @@ class Album(Tracklist):
self.cover_obj = None self.cover_obj = None
# Download the booklet if applicable # Download the booklet if applicable
if self.get("booklets"): if self.get("booklets") and kwargs.get('download_booklets', True):
click.secho("\nDownloading booklets", fg='blue') click.secho("\nDownloading booklets", fg='blue')
for item in self.booklets: for item in self.booklets:
Booklet(item).download(parent_folder=self.folder) Booklet(item).download(parent_folder=self.folder)
def _download_item( def _download_item(
self, self,
track: Track, track: Union[Track, Video],
quality: int = 3, quality: int = 3,
database: MusicDB = None, database: MusicDB = None,
**kwargs, **kwargs,
) -> bool: ) -> bool:
logger.debug("Downloading track to %s", self.folder) logger.debug("Downloading track to %s", self.folder)
if self.disctotal > 1: if self.disctotal > 1 and isinstance(track, Track):
disc_folder = os.path.join(self.folder, f"Disc {track.meta.discnumber}") disc_folder = os.path.join(self.folder, f"Disc {track.meta.discnumber}")
kwargs["parent_folder"] = disc_folder kwargs["parent_folder"] = disc_folder
else: else: