diff --git a/streamrip/cli.py b/streamrip/cli.py index c2018d41..90c8b193 100644 --- a/streamrip/cli.py +++ b/streamrip/cli.py @@ -269,12 +269,24 @@ def lastfm(ctx, source, url): @click.option("-q", "--qobuz", is_flag=True, help="Set Qobuz credentials") @click.option("-t", "--tidal", is_flag=True, help="Re-login into Tidal") @click.option("--reset", is_flag=True, help="RESET the config file") +@click.option( + "--update", + is_flag=True, + help="Reset the config file, keeping the credentials", +) +@click.option("-p", "--path", is_flag=True, help="Show the config file's path") @click.pass_context def config(ctx, **kwargs): """Manage the streamrip configuration file.""" if kwargs["reset"]: config.reset() + if kwargs["update"]: + config.update() + + if kwargs["path"]: + print(CONFIG_PATH) + if kwargs["open"]: click.secho(f"Opening {CONFIG_PATH}", fg="green") click.launch(CONFIG_PATH) diff --git a/streamrip/metadata.py b/streamrip/metadata.py index 3accc4cc..8f48dc59 100644 --- a/streamrip/metadata.py +++ b/streamrip/metadata.py @@ -275,6 +275,7 @@ def add_track_meta(self, track: dict): self.copyright = safe_get(track, "publisher_metadata", "p_line") self.tracknumber = 0 self.tracktotal = 0 + self.quality = 0 else: raise ValueError(self.__source) diff --git a/tests.py b/tests.py new file mode 100644 index 00000000..4e2ec185 --- /dev/null +++ b/tests.py @@ -0,0 +1,113 @@ +import subprocess +import click +import os +import shutil + +test_urls = { + "qobuz": "https://www.qobuz.com/us-en/album/blackest-blue-morcheeba/h4nngz0wgqesc", + "tidal": "https://tidal.com/browse/album/183284294", + "deezer": "https://www.deezer.com/us/album/225281222", + "soundcloud": "https://soundcloud.com/dj-khaled/sets/khaled-khaled", +} + + +def reset_config(): + global cfg_path + global new_cfg_path + + p = subprocess.Popen( + ["rip", "config", "-p"], stdout=subprocess.PIPE, stderr=subprocess.PIPE + ) + out, err = p.communicate() + cfg_path = out.decode("utf-8").strip() + # cfg_path = re.search( + # r"(/[\w\d\s]+(?:/[\w\d \.]+)*)", out.decode("utf-8") + # ).group(1) + new_cfg_path = f"{cfg_path}.tmp" + shutil.copy(cfg_path, new_cfg_path) + subprocess.Popen(["rip", "config", "--update"]) + + +def restore_config(): + global cfg_path + global new_cfg_path + + os.remove(cfg_path) + shutil.move(new_cfg_path, cfg_path) + + +def download_albums(): + rip_url = ["rip", "-nd", "-u"] + procs = [] + for url in test_urls.values(): + procs.append(subprocess.run([*rip_url, url])) + + for p in procs: + print(p) + + +def check_album_dl_success(folder, correct): + if set(os.listdir(folder)) != set(correct): + click.secho(f"Check for {folder} failed!", fg="red") + else: + click.secho(f"Check for {folder} succeeded!", fg="green") + + +reset_config() +download_albums() +check_album_dl_success( + "/Users/nathan/StreamripDownloads/Morcheeba - Blackest Blue (2021) [FLAC] [24B-44.1kHz]", + { + "04. Morcheeba - Say It's Over.flac", + "01. Morcheeba - Cut My Heart Out.flac", + "02. Morcheeba - Killed Our Love.flac", + "07. Morcheeba - Namaste.flac", + "03. Morcheeba - Sounds Of Blue.flac", + "10. Morcheeba - The Edge Of The World.flac", + "08. Morcheeba - The Moon.flac", + "09. Morcheeba - Falling Skies.flac", + "cover.jpg", + "05. Morcheeba - Sulphur Soul.flac", + "06. Morcheeba - Oh Oh Yeah.flac", + }, +) + +check_album_dl_success( + "/Users/nathan/StreamripDownloads/KHALED KHALED", + { + "05. DJ Khaled - I DID IT (feat. Post Malone, Megan Thee Stallion, Lil Baby & DaBaby).mp3", + "09. DJ Khaled - THIS IS MY YEAR (feat. A Boogie Wit Da Hoodie, Big Sean, Rick Ross & Puff Daddy).mp3", + "01. DJ Khaled - THANKFUL (feat. Lil Wayne & Jeremih).mp3", + "12. DJ Khaled - I CAN HAVE IT ALL (feat. Bryson Tiller, H.E.R. & Meek Mill).mp3", + "02. DJ Khaled - EVERY CHANCE I GET (feat. Lil Baby & Lil Durk).mp3", + "08. DJ Khaled - POPSTAR (feat. Drake).mp3", + "13. DJ Khaled - GREECE (feat. Drake).mp3", + "04. DJ Khaled - WE GOING CRAZY (feat. H.E.R. & Migos).mp3", + "10. DJ Khaled - SORRY NOT SORRY (Harmonies by The Hive) [feat. Nas, JAY-Z & James Fauntleroy].mp3", + "03. DJ Khaled - BIG PAPER (feat. Cardi B).mp3", + "14. DJ Khaled - WHERE YOU COME FROM (feat. Buju Banton, Capleton & Bounty Killer).mp3", + "07. DJ Khaled - BODY IN MOTION (feat. Bryson Tiller, Lil Baby & Roddy Ricch).mp3", + "06. DJ Khaled - LET IT GO (feat. Justin Bieber & 21 Savage).mp3", + "11. DJ Khaled - JUST BE (feat. Justin Timberlake).mp3", + }, +) + +check_album_dl_success( + "/Users/nathan/StreamripDownloads/Paul Weller - Fat Pop (2021) [FLAC] [24B-44.1kHz]", + { + "01. Paul Weller - Cosmic Fringes.flac", + "11. Paul Weller - In Better Times.flac", + "05. Paul Weller - Glad Times.flac", + "08. Paul Weller - That Pleasure.flac", + "04. Paul Weller - Shades Of Blue.flac", + "12. Paul Weller - Still Glides The Stream.flac", + "03. Paul Weller - Fat Pop.flac", + "cover.jpg", + "02. Paul Weller - True.flac", + "09. Paul Weller - Failed.flac", + "06. Paul Weller - Cobweb Connections.flac", + "10. Paul Weller - Moving Canvas.flac", + "07. Paul Weller - Testify.flac", + }, +) +restore_config()