From b509f0785141bbba3adcd35db823b173e0659889 Mon Sep 17 00:00:00 2001 From: bux Date: Wed, 30 Mar 2022 01:13:41 +0200 Subject: [PATCH] select best match based on record type when multiple are returned --- out-deezer-cover.jq | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/out-deezer-cover.jq b/out-deezer-cover.jq index 9f1877a..8fcd0b0 100755 --- a/out-deezer-cover.jq +++ b/out-deezer-cover.jq @@ -1,2 +1,40 @@ #!/usr/bin/env -S jq -fMr -select(.total == 1) | [._scene_release_name, .data[0].cover_xl ] | @tsv + +def format_as_deezer_record_type($format): + $format | ascii_upcase | + if . == "SINGLE-WEB" then + "single" + elif . == "CDS" then + "single" + elif . == "CDM" then + "single" + elif . == "CDEP" then + "ep" + elif . == "EP-WEB" then + "ep" + elif . == "EP" then + "ep" + elif . == "WEB" then + "album" + elif . == "2CD" then + "album" + elif . == "CD" then + "album" + else + null + end; + +if .total == 1 then + [._scene_release_name, .data[0].cover_xl ] +elif .total > 1 then + ._scene_release_name as $rls | + format_as_deezer_record_type(._format) as $record_type | + if $record_type != null then + # alternate to empty if there is no matching record type + .data | map(select(.record_type == $record_type))[0]//empty | [$rls, .cover_xl] + else + empty + end +else + empty +end | @tsv