Skip to content

Commit

Permalink
Fix dzr-dec loop and add dzr deps check
Browse files Browse the repository at this point in the history
  • Loading branch information
yne committed Apr 12, 2021
1 parent 9781884 commit 948da16
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 29 deletions.
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: yne
31 changes: 16 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
<img width=100% height=200 src=".github/.logo.svg">
<p align=center>Your favorite flows, straight from shell</p>
![dzr logo](.github/.logo.svg)

> ⚠️ For legal reasons, this project does not provide the [decyption key](https://github.com/yne/dzr/wiki)
# DZR: Stream from SHell

# Preview

[![](https://asciinema.org/a/NpET2MMpGN41QW2a0JOjFru0l.svg)](https://asciinema.org/a/NpET2MMpGN41QW2a0JOjFru0l)
> ⚠️ For [legal reasons](https://github.com/github/dmca/blob/master/2021/02/2021-02-10-deezer.md), dzr does not come with any [track decryption key](https://github.com/yne/dzr/wiki) and so, does not work "out of the box"
# Requirement
# Preview
[![asciicast](https://asciinema.org/a/406758.svg)](https://asciinema.org/a/406758)

- `apt install wget jq openssl`
- Set the [decryption key](https://github.com/yne/dzr/wiki) `export DZR_CBC=g*******0zvf9na1` in your `.bashrc`/`.zshrc`/`.profile`
# Install/Update
- Find (or just google) the [DZR_CBC key](https://github.com/yne/dzr/wiki) then `export` it in your `~/.profile`
- Install deps: `curl` `jq` `openssl` `dialog` `mpv` (package names may vary depending on your OS)
- Install dzr: `rm -f dzr* && wget raw.githubusercontent.com/yne/dzr/master/dzr{,-dec,-url} && chmod +x ./dzr*`

# Usage Example (using curl + mpv)
> The Deezer API rapidly change so in case of breakage: update your dzr or open an issue
```sh
# Note: DZR_CBC must be set for dzr-dec to work
./dzr-url 5404528 664107 | while read url id; do curl -s "$url" | ./dzr-dec $id | mpv - ; done
```
# Compatibility

> You shall wrap the above line in a frontend `dzr` script (change mpv/curl if needed) so you would just have to type `dzr 5404528 664107` (see Preview)
This project shall work on any OS:
- Linux
- *BSD (even OpenBSD)
- Android via [F-Droid Termux](https://termux.com/) (Note: `pkg install openssl-tool` instead of `openssl`)
- Open an Issue/PR if you need more OS
12 changes: 7 additions & 5 deletions dzr
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#!/bin/sh
which jq curl dialog openssl mpv>/dev/null || { echo "please install: jq curl dialog openssl mpv" 1>&2 && exit 1 ;}
[ $(printf "$DZR_CBC" | wc -m) -eq 16 ] || { echo -n "Missing/Bad DZR_CBC env variable:\necho 'export DZR_CBC=g*******0zvf9na1' > \$HOME/.profile\nand restart your shell\n" 1>&2 && exit 1 ;}
API="api.deezer.com"
DLG_LIST="dialog --keep-tite --output-fd 1 --menu $1: 0 0 0"
DLG_TEXT="dialog --keep-tite --output-fd 1 --inputbox $1: 0 0"
FMT_LIST='(if .data then .data else .tracks.data end)[]|("/"+.type+"/"+(.id|tostring), (.title+.name+" "+.artist.name|gsub("\\x22";"")))'
dzr() { $DLG_LIST /search/track?q= 'by name' /search/artist?q= 'by name' /search/album?q= 'by name' /search/playlist?q= 'by name' /search/user?q= 'by name' /genre 'list' /radio 'list' /user/0 'by id' /track/0 'by id' /artist/0 'by id' /album/0 'by id';}
dzr() { $DLG_LIST /search/track?q= 'by name' /search/artist?q= 'by name' /search/album?q= 'by name' /search/playlist?q= 'by name' /search/user?q= 'by name' /user/0 'by id' /track/0 'by id' /artist/0 'by id' /album/0 'by id';} # /genre 'list' /radio 'list'
dzr_default() { curl -s "$API$1" | jq "$FMT_LIST" | xargs $DLG_LIST @ "play all /track/" ;} # TODO: .next
dzr_genre_0() { curl -s "$API$1/0/artists" | jq "$FMT_LIST" | xargs $DLG_LIST ;}
dzr_radio() { curl -s "$API$1" | jq "$FMT_LIST" | xargs $DLG_LIST top '' genres '' lists '' ;}
dzr_radio_0() { $DLG_LIST tracks '' fans '' ;}
#dzr_genre_0() { curl -s "$API$1/0/artists" | jq "$FMT_LIST" | xargs $DLG_LIST ;}
#dzr_radio() { curl -s "$API$1" | jq "$FMT_LIST" | xargs $DLG_LIST top '' genres '' lists '' ;}
#dzr_radio_0() { $DLG_LIST tracks '' fans '' ;}
dzr_album_0() { $DLG_LIST tracks '' fans '' ;}
dzr_user_0() { $DLG_LIST charts '' albums '' playlists '' flow '' tracks '' artists '' ;}
dzr_artist_0() { $DLG_LIST top?limit=50 '' albums '' fans '' related '' radio '' playlists '' ;}
Expand All @@ -21,7 +23,7 @@ for url in "$@"; do # convert argument (/search/artist?q=x) to shell function na
/track/*) echo $url | dzr_play; break ;;
esac
echo "$url use $FUNC" >&2
while path=$($FUNC $url); do # browse loop
while path=$($FUNC $url); do # browse REPL
case "$path" in
@) curl -s "$API$url" | jq '"/track/"+([.data[]|select(.type=="track")|.id]|@csv)' | dzr_play ; break ;;
/*) $0 "$path";;
Expand Down
4 changes: 0 additions & 4 deletions dzr-dec
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#!/bin/sh
#TODO: avoid decode error (iflag=fullblock iflag=nocache iflag=sync conv=fsync) ?

SNG_ID="$1"
[ -z "$DZR_CBC" ] && echo "Missing 'DZR_CBC' env variable" 1>&2 && exit 1
[ -z "$SNG_ID" ] && echo "USAGE: DZR_CBC=XXXX dzr-dec 1234 < enc.mp3 > dec.mp3" 1>&2 && exit 1
Expand All @@ -15,11 +13,9 @@ track_key=$(for k in 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31; do # no seq in
done)

stripe_size=2048

# And now for my next loop, I'd like to return to the classics
set -e; # if an iteration fail we stop the loop (you better pipe me with curl)
while true; do
LC_ALL=POSIX dd bs=$stripe_size count=1 status=none | openssl bf-cbc -nopad -bufsize $stripe_size -K $track_key -iv 0001020304050607 -d 2>/dev/null 1>&4
{ LC_ALL=POSIX dd bs=$stripe_size count=2 2>&3 >&4; } 3>&1 | grep -qe '^0[+]0 ' && break
done 4>&1

10 changes: 5 additions & 5 deletions dzr-url
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ SNG_IDS=$(printf "%s" "$*" | sed 's/ /,/g')

gw () {
method="$1"; session="$2" ;apiToken="$3" ; shift 3 # curl args ...
wget -qO- "https://www.deezer.com/ajax/gw-light.php?method=$method&input=3&api_version=1.0&api_token=$apiToken" --header="Cookie: sid=$session" "$@"
curl -s "https://www.deezer.com/ajax/gw-light.php?method=$method&input=3&api_version=1.0&api_token=$apiToken" --header "Cookie: sid=$session" "$@"
}

[ -z "$SNG_IDS" ] && echo "USAGE: dzr-url 5404528,664107" && exit 1
DZR_URL="www.deezer.com/ajax/gw-light.php?method=deezer.ping&api_version=1.0&api_token"
DZR_SID=$(wget -qO- "$DZR_URL" | jq -r .results.SESSION)
DZR_SID=$(curl -s "$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_IDS\n" 1>&2
#printf "SID=$DZR_SID\nAPI=$API_TOK\nLIC=$USR_LIC\nTOK=$USR_TOK\nIDS=$SNG_IDS\n" 1>&2

SNG_NFO=$(gw song.getListData "$DZR_SID" "$API_TOK" --post-data="{\"sng_ids\":[$SNG_IDS]}")
SNG_NFO=$(gw song.getListData "$DZR_SID" "$API_TOK" --data "{\"sng_ids\":[$SNG_IDS]}")
SNG_TOK=$(printf "%s" "$SNG_NFO" | jq [.results.data[].TRACK_TOKEN])
URL_NFO=$(wget -qO- 'https://media.deezer.com/v1/get_url' --post-data="{\"license_token\":\"$USR_LIC\",\"media\":[{\"type\":\"FULL\",\"formats\":[{\"cipher\":\"BF_CBC_STRIPE\",\"format\":\"MP3_128\"}]}],\"track_tokens\":$SNG_TOK}")
URL_NFO=$(curl -s 'https://media.deezer.com/v1/get_url' --data "{\"license_token\":\"$USR_LIC\",\"media\":[{\"type\":\"FULL\",\"formats\":[{\"cipher\":\"BF_CBC_STRIPE\",\"format\":\"MP3_128\"}]}],\"track_tokens\":$SNG_TOK}")
URL_SRC=$(printf "%s" "$URL_NFO" | jq -r .data[].media[].sources[0].url)

i=0
Expand Down

0 comments on commit 948da16

Please sign in to comment.