Compare commits

...

5 Commits

Author SHA1 Message Date
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
4 changed files with 103 additions and 1 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
@ -66,3 +67,10 @@ $ 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
```

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

@ -0,0 +1,2 @@
#!/usr/bin/env -S jq -fMr
select(.total == 1) | [._scene_release_name, .data[0].cover_xl ] | @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})\)?'

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

@ -0,0 +1,92 @@
#!/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
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 -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