Compare commits

...

8 Commits

Author SHA1 Message Date
bux
b509f07851 select best match based on record type when multiple are returned 2022-03-30 01:13:41 +02:00
bux
8b16a2b03d test that API response contains total 2022-03-30 01:11:54 +02:00
bux
cecbc9d41b remove record type test code 2022-03-28 01:25:24 +02:00
bux
6e54242c1d example cover art download 2022-03-28 01:21:52 +02:00
bux
b168ea1c7e filter cover URL from deezer search result 2022-03-28 01:00:17 +02:00
bux
631f6e3fba add deezer search 2022-03-27 16:26:24 +02:00
bux
d9e026a4ff accept SP as lang/country 2022-03-27 16:00:26 +02:00
bux
57a3b775d7 readme formating 2022-03-27 03:03:43 +02:00
4 changed files with 157 additions and 2 deletions

View File

@ -20,6 +20,7 @@ scene rls name > parse > artist / title / year as .tsv > search discogs > .json
- `parse-rls.fish` parse scene release name
- `search-discogs-api.fish` search discogs release using Discogs REST API
- `search-discogs-elastic.fish` search discogs release using ElasticSearch
- `search-deezer-api.fish` search for album with Deezer REST API
- `out-fallback.jq` fallback search helper
- `out-ids.jq` filter ids from json output
- `out-simple.jq` filter genre from json output
@ -60,8 +61,16 @@ $ ./in-ws-predb.ovh.sh | ./parse-rls.fish | search-discogs-api.fish > out.api.js
parse rls name, search local ElasticSearch, write json, filter empty results and convert json to tsv, fallback search with Discogs API, write json
```sh
$ echo 'Band_Of_Horses-Things_Are_Great-CD-2022-FATHEAD' | ./parse-rls.fish | ./search-discogs-elastic.fish | tee out.es.json | ./out-fallback.jq | ./search-discogs-api.fish > out.api.json
$ echo 'Band_Of_Horses-Things_Are_Great-CD-2022-FATHEAD' | ./parse-rls.fish | ./search-discogs-elastic.fish | \
tee out.es.json | ./out-fallback.jq | ./search-discogs-api.fish > out.api.json
$ jq ._search_result_count out.es.json out.api.json
0
1
```
With fish shell:
parse rls names from local folder, search Deezer, filter cover URL, download cover image into local folder
```sh
ls -1 /path/ | ./parse-rls.fish | ./search-deezer-api.fish | ./out-deezer-cover.jq | while read -l RLS COVER ; if not test -f "/path/$RLS/cover.jpg"; curl -s -o "/path/$RLS/cover.jpg" "$COVER"; end; end
```

40
out-deezer-cover.jq Executable file
View File

@ -0,0 +1,40 @@
#!/usr/bin/env -S jq -fMr
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

View File

@ -59,7 +59,7 @@ set ISO3166 'AW|AF|AO|AI|AX|AL|AD|AE|AR|AM|AS|AQ|TF|AG|AU|AT|AZ|BI|BE|BJ|BQ|BF|B
set ISO639 'AA|AB|AE|AF|AK|AM|AN|AR|AS|AV|AY|AZ|BA|BE|BG|BH|BI|BM|BN|BO|BR|BS|CA|CE|CH|CO|CR|CS|CU|CV|CY|DA|DE|DV|DZ|EE|EL|EN|EO|ES|ET|EU|FA|FF|FI|FJ|FO|FR|FY|GA|GD|GL|GN|GU|GV|HA|HE|HI|HO|HR|HT|HU|HY|HZ|IA|ID|IE|IG|II|IK|IO|IS|IT|IU|JA|JV|KA|KG|KI|KJ|KK|KL|KM|KN|KO|KR|KS|KU|KV|KW|KY|LA|LB|LG|LI|LN|LO|LT|LU|LV|MG|MH|MI|MK|ML|MN|MR|MS|MT|MY|NA|NB|ND|NE|NG|NL|NN|NO|NR|NV|NY|OC|OJ|OM|OR|OS|PA|PI|PL|PS|PT|QU|RM|RN|RO|RU|RW|SA|SC|SD|SE|SG|SI|SK|SL|SM|SN|SO|SQ|SR|SS|ST|SU|SV|SW|TA|TE|TG|TH|TI|TK|TL|TN|TO|TR|TS|TT|TW|TY|UG|UK|UR|UZ|VE|VI|VO|WA|WO|XH|YI|YO|ZA|ZH|ZU'
set LANG "(?<L>$ISO3166|$ISO639)"
set LANG "(?<L>$ISO3166|$ISO639|SP)"
set TEAM '[a-zA-Z0-9_]+'
set YEAR '\(?(?<Y>(19|20)[0-9]{2})\)?'

106
search-deezer-api.fish Executable file
View File

@ -0,0 +1,106 @@
#!/usr/bin/env fish
#set fish_trace on
function usage
begin
echo "Read TSV release data from sdtin > query Deezer API > output JSON"
exit 1
end
end
argparse -n (status current-filename) 'h/help' -- $argv
if test $status -ne 0
usage
end
if set -q _flag_help
usage
end
set API_OUT (mktemp -t rls.deezer.API.XXXXXXXX.json)
set DAPI "https://api.deezer.com/search/album"
set UA "search-deezer.fish/v0.0.3"
while read -l -d (printf '\t') ORG A T C B F E Y
if test -z "$A"; or test -z "$T"
echo "WARN: Skipping empty artist / title input"
continue
end
set _in_A "$A"; set _in_T "$T"; set _in_C "$C";
set _in_B "$B"; set _in_F "$F"; set _in_E "$E"; set _in_Y "$Y"
sleep .2
set API_CODE (curl -s -G "$DAPI" --user-agent "$UA" -w '%{http_code}' -o "$API_OUT" --data-urlencode "q=$A $T $E" --data-urlencode "strict=on")
if test $status -ne 0
echo "curl API request failed" >&2
rm "$API_OUT"
continue
end
if test $API_CODE -ne 200
begin
echo "Deezer API status code $CODE"
echo $ORG
end >&2
rm "$API_OUT"
continue
end
set API_COUNT (jq -r .total "$API_OUT")
if test $status -ne 0
begin
echo "Failed parsing API result"
echo $ORG
end >&2
rm "$API_OUT"
continue
end
if test "$API_COUNT" = "null"
begin
echo "ERR: API result has no total count"
echo $ORG
end >&2
rm "$API_OUT"
continue
end
if test $API_COUNT -eq 0
echo '{}' | jq -SMc --arg rls "$ORG" --arg api_count "$API_COUNT" \
--arg a "$_in_A" --arg t "$_in_T" --arg c "$_in_C" \
--arg b "$_in_B" --arg f "$_in_F" --arg e "$_in_E" --arg y "$_in_Y" \
'{
"_scene_release_name": $rls,
"_source": "api.deezer.com",
"_search_result_count": $api_count | tonumber,
"_artist": $a,
"_title": $t,
"_catno": $c,
"_barcode": $b,
"_format": $f,
"_edition": $e,
"_year": $y
}'
rm "$API_OUT"
continue
else if test $API_COUNT -ge 1
jq -SMc --arg rls "$ORG" --arg api_count "$API_COUNT" \
--arg a "$_in_A" --arg t "$_in_T" --arg c "$_in_C" \
--arg b "$_in_B" --arg f "$_in_F" --arg e "$_in_E" --arg y "$_in_Y" \
'. + {
"_scene_release_name": $rls,
"_source": "api.deezer.com",
"_search_result_count": $api_count | tonumber,
"_artist": $a,
"_title": $t,
"_catno": $c,
"_barcode": $b,
"_format": $f,
"_edition": $e,
"_year": $y
}' "$API_OUT"
end
rm "$API_OUT"
end