Add musicbrainz and discography
This commit is contained in:
parent
52e1bfbfed
commit
745cfd5e52
1 changed files with 44 additions and 1 deletions
|
@ -10,6 +10,7 @@ import requests
|
|||
import tqdm
|
||||
from mutagen.flac import FLAC, Picture
|
||||
from PIL import Image
|
||||
import musicbrainzngs as mb
|
||||
|
||||
|
||||
@dataclass
|
||||
|
@ -205,6 +206,14 @@ def main() -> None:
|
|||
default="album",
|
||||
help="Type of search to perform",
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"--additional-releases",
|
||||
"-a",
|
||||
action="append",
|
||||
default=[],
|
||||
help="Include additional releases in discography search (may be applied multiple times)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"query", type=str, help="Search query for the album to download"
|
||||
)
|
||||
|
@ -213,7 +222,41 @@ def main() -> None:
|
|||
|
||||
query = args.query
|
||||
qb = Qobuz(api_base=base_url, quality=quality)
|
||||
print(qb.search_and_download(query))
|
||||
match args.type:
|
||||
case "album":
|
||||
qb.search_and_download(query)
|
||||
case "discography":
|
||||
mb.set_useragent(
|
||||
"Qobuz-dl-remote",
|
||||
version="0.1.0",
|
||||
contact="christoph.stahl@tu-dortmund.de",
|
||||
)
|
||||
result = mb.search_artists(query=query, limit=1)
|
||||
artist_id = result["artist-list"][0]["id"]
|
||||
artist_name = result["artist-list"][0]["name"]
|
||||
artist_with_releases = mb.get_artist_by_id(
|
||||
artist_id, includes=["release-groups"]
|
||||
)
|
||||
all_releases = artist_with_releases["artist"]["release-group-list"]
|
||||
album_releases = filter(
|
||||
lambda entry: entry["primary-type"]
|
||||
in ["Album", *args.additional_releases],
|
||||
all_releases,
|
||||
)
|
||||
|
||||
album_names = [
|
||||
f"{entry['title']} ({entry['first-release-date'][:4]})"
|
||||
for entry in album_releases
|
||||
]
|
||||
|
||||
for album in album_names:
|
||||
print(f"Found album: {artist_name} - {album}")
|
||||
qb.search_and_download(f"{artist_name} {album}")
|
||||
|
||||
print(album_names)
|
||||
case _:
|
||||
print("Invalid type specified, use 'album' or 'discography'.")
|
||||
return
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
Loading…
Add table
Reference in a new issue