def test_enrichment_pipeline_missing_creds(test_tracks): track_tags = test_tracks[0] with pytest.raises(enrichments.MissingCredentials) as excinfo: enrichments.pipeline(track_tags, ["discogs"]) assert "You need to provide a discogs token" in str(excinfo.value) with pytest.raises(enrichments.MissingCredentials) as excinfo: enrichments.pipeline(track_tags, ["spotify"]) assert "You need to provide sp_client_id and sp_client_secret" in str( excinfo.value)
def test_enrichment_pipeline_unexisting_track(test_tracks_not_existing, all_creds, available_enrichments): results = enrichments.pipeline(test_tracks_not_existing[0], **all_creds) assert all([e in results for e in available_enrichments]) for k, v in results.items(): assert v["best_match"] == None assert v["other_results"] == []
def harmonize_file(local_file_path, audio_output_dir, json_output_dir, image_output_dir, parsed_config): enrichment_creds = {} for e in parsed_config["enrichments"].values(): enrichment_creds.update(e) basename = os.path.basename(local_file_path) basename, _ = os.path.splitext(basename) output_file_path = os.path.join(audio_output_dir, basename) + ".mp3" output_result_path = os.path.join(json_output_dir, basename) + ".json" manipulation_metadata, exported_filepath, cover_art_path = manipulations.pipeline( local_file_path, output_file_path, image_output_dir, active_normalize=parsed_config["normalization_headroom"] > 0, normalization_headroom=parsed_config["normalization_headroom"], ) if "tags" in manipulation_metadata: enrichments_metadata = enrichments.pipeline( manipulation_metadata["tags"], list(parsed_config.get("enrichments", {}).keys()), **enrichment_creds, ) else: enrichments_metadata = {} is_valid, validations_metadata = validations.validate( parsed_config.get("validations", {}), tags=manipulation_metadata.get("tags"), output_bitrate=manipulation_metadata["export"].get("output_bitrate"), input_bitrate=manipulation_metadata.get("original_bitrate"), input_mime_type=manipulation_metadata.get("mime_type"), enrichments=enrichments_metadata, ) results = { "output_file_path": output_file_path, "validation_errors": validations_metadata, "enrichments_metadata": enrichments_metadata, "manipulation_metadata": manipulation_metadata, } with open(output_result_path, "w") as f: json.dump(results, f) return results
def test_enrichment_pipeline_insufficient_tags(test_tracks, spotify_creds, discogs_token): track_tags = test_tracks[0].copy() track_tags.pop("artist") with pytest.raises(enrichments.InsufficientTags) as excinfo: enrichments.pipeline(track_tags, ["discogs"]) assert "missing a tag" in str(excinfo.value) with pytest.raises(enrichments.InsufficientTags) as excinfo: enrichments.pipeline(track_tags, ["spotify"]) assert "missing a tag" in str(excinfo.value) with pytest.raises(enrichments.InsufficientTags) as excinfo: enrichments.pipeline(track_tags) assert "missing a tag" in str(excinfo.value) track_tags = test_tracks[0].copy() track_tags.pop("album") with pytest.raises(enrichments.InsufficientTags) as excinfo: enrichments.pipeline(track_tags, ["discogs"]) assert "missing a tag" in str(excinfo.value) results = enrichments.pipeline(track_tags, enrichments=["spotify"], **spotify_creds) assert "spotify" in results track_tags = test_tracks[0].copy() track_tags.pop("title") with pytest.raises(enrichments.InsufficientTags) as excinfo: enrichments.pipeline(track_tags, ["spotify"]) assert "missing a tag" in str(excinfo.value) results = enrichments.pipeline(track_tags, enrichments=["discogs"], discogs_token=discogs_token) assert "discogs" in results
def test_enrichment_pipeline_unavailable(test_tracks): track_tags = test_tracks[0] with pytest.raises(enrichments.UnavailableEnrichment) as excinfo: enrichments.pipeline(track_tags, ["youtube"]) assert "does not exist" in str(excinfo.value)
def test_enrichment_pipeline(test_tracks, all_creds, available_enrichments): for t in test_tracks: results = enrichments.pipeline(t, **all_creds) assert all([e in results for e in available_enrichments])