-
Notifications
You must be signed in to change notification settings - Fork 13
/
dzr-srt
executable file
·27 lines (23 loc) · 1.5 KB
/
dzr-srt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/bin/sh
# USAGE Example:
# ./dzr-srt 355777961
SNG_ID=$(echo "$1" | tr -dc '0-9') # extract id from path,url,...
[ -z "$SNG_ID" ] && echo "USAGE: $0 5404528" && exit 1
FETCH=${FETCH:-curl -s} # FETCH="wget -q -O -" or FETCH="curl -s -k"
gw () {
method="$1"; session="$2" ;apiToken="$3" ; shift 3 # curl args ...
$FETCH "https://www.deezer.com/ajax/gw-light.php?method=$method&input=3&api_version=1.0&api_token=$apiToken" --header "Cookie: sid=$session" "$@"
}
DZR_URL="www.deezer.com/ajax/gw-light.php?method=deezer.ping&api_version=1.0&api_token"
DZR_SID=$($FETCH "$DZR_URL" | jq -r .results.SESSION)
USR_NFO=$(gw deezer.getUserData "$DZR_SID" "$API_TOK")
USR_TOK=$(printf "%s" "$USR_NFO" | jq -r .results.USER_TOKEN)
USR_LIC=$(printf "%s" "$USR_NFO" | jq -r .results.USER.OPTIONS.license_token)
API_TOK=$(printf "%s" "$USR_NFO" | jq -r .results.checkForm)
#printf "SID=$DZR_SID\nAPI=$API_TOK\nLIC=$USR_LIC\nTOK=$USR_TOK\nIDS=$SNG_ID\n" 1>&2
gw song.getLyrics "$DZR_SID" "$API_TOK" --data "{\"sng_id\":$SNG_ID}" | jq -r 'if (.results.LYRICS_SYNC_JSON) then .results.LYRICS_SYNC_JSON | map(select(.lrc_timestamp)) | to_entries | map([.key+1, "00:"+.value.lrc_timestamp[1:-1] + .value.milliseconds, (.value.duration|tonumber/1000|tostring), .value.line])[]|@tsv else "1\t00:00:00.0\t0.0\t" end' |
while IFS=' ' read -r id start length text ; do
from=$(date +%H:%M:%S,%N --date "$start" | cut -c1-12) ;
to=$(date +%H:%M:%S,%N --date "$start + $length second" | cut -c1-12) ;
printf "$id\n${from} --> ${to}\n$text\n\n" ;
done