diff --git a/README.md b/README.md
index 4431d13..771ac06 100644
--- a/README.md
+++ b/README.md
@@ -31,6 +31,8 @@
| Ubuntu + [snap](https://snapcraft.io/dzr) | `snap install --edge dzr` | [Help Me](https://github.com/yne/dzr/issues/25)
| Android + [Termux](https://f-droid.org/packages/com.termux/) | `curl -sL github.com/yne/dzr/archive/master.tar.gz \| tar xzf -`
`sudo mv dzr-master/dzr* /usr/local/bin` | [![](https://img.shields.io/badge/-tar.gz-40c010?logo=hackthebox)](https://github.com/yne/dzr/archive/master.tar.gz)
| VSCode | `code --install-extension ./path/tos/dzr-x.y.z.vsix` | [![](https://img.shields.io/badge/VSIX-4c1?logo=visualstudiocode)](https://github.com/yne/dzr/releases)
+| Nix | `nix run github.com:yne/dzr` | latest |
+
## Usage
```sh
@@ -63,3 +65,11 @@ mkdir -p ./cgi-bin/ && install dzr* ./cgi-bin/
python3 -m http.server --cgi
open http://127.0.0.1:8000/cgi-bin/dzr?6113114
```
+
+## Running with Nix
+
+- Make sure you have Nix installed first, see the [Nix documentation](https://nixos.org/download/)
+- Make sure Flakes are enabled, see the [Nix Flakes documentation](https://nixos.wiki/wiki/Flakes)
+- Run it!
+ - Default branch: `nix run github.com/yne/dzr`
+ - Specific revision: `nix run github.com/yne/dzr/`
\ No newline at end of file
diff --git a/dzr b/dzr
index cee4494..5e96953 100755
--- a/dzr
+++ b/dzr
@@ -1,5 +1,11 @@
#!/bin/sh
+BINARY_NAME="$(basename "$0")"
+
+if ! command -v "$BINARY_NAME" &>/dev/null; then
+ BINARY_NAME=$0
+fi
+
# CGI call handling, for example moving ./dzr* bin to ~/cgi-bin and running :
# python3 -m http.server --cgi
# from your ~ (as non-root !) will reply to http://0.0.0.0:8000/cgi-bin/dzr?6113114,806027
@@ -9,29 +15,30 @@ if [ "$REQUEST_METHOD" = "HEAD" ] ; then
printf 'Access-Control-Allow-Origin: *\ndzr-api: 0\n\n'
elif [ "$REQUEST_METHOD" = "GET" ] ; then
printf "Cache-Control: max-age=31536000, immutable\nContent-Type: audio/mpeg\n\n"
- echo "$QUERY_STRING" | xargs basename | xargs $0-url | while read url id; do
- $FETCH "$url" | $0-dec $id
+ echo "$QUERY_STRING" | xargs basename | xargs "$BINARY_NAME-url" | while read url id; do
+ $FETCH "$url" | "$BINARY_NAME-dec" "$id"
done
fi
-[ ! -z "$REQUEST_METHOD" ] && exit
+[ -n "$REQUEST_METHOD" ] && exit
# extraction + warning by charleywright, see: https://github.com/yne/dzr/issues/11
-unscramble(){ printf "${8}${16}${7}${15}${6}${14}${5}${13}${4}${12}${3}${11}${2}${10}${1}${9}";}
+unscramble(){ printf "%s" "${8}${16}${7}${15}${6}${14}${5}${13}${4}${12}${3}${11}${2}${10}${1}${9}";}
if [ -z "$DZR_CBC" ]; then
- command -v $(echo "$FETCH" | cut -f 1 -d " ") >/dev/null || { echo "key extraction require $FETCH" 1>&2 ; exit 1 ;}
+ command -v "$(echo "$FETCH" | cut -f 1 -d " ")" >/dev/null || { echo "key extraction require $FETCH" 1>&2 ; exit 1 ;}
printf "Add the following to your shell profile e.g. ~/.profile or ~/.zshrc:\n" >&2
APP_WEB=$($FETCH -L deezer.com/en/channels/explore | sed -n 's/.*src="\([^"]*app-web[^"]*\).*/\1/p' | xargs $FETCH -L)
TMP_CBC=$(echo "$APP_WEB" | tr ,_ '\n' | sed -n 's/.*\(%5B0x..%2C.\{39\}%2C0x..%5D\).*/\1/p' | sed 's/%../\n/g' | xargs printf '\\%o ')
- export DZR_CBC=$(unscramble $TMP_CBC);
- printf " export DZR_CBC=$DZR_CBC" >&2
- [ "-$@" = "-!" ] && printf '%s' "$DZR_CBC" && exit
+ DZR_CBC=$(unscramble $TMP_CBC);
+ export DZR_CBC
+ printf " export DZR_CBC=%s" "$DZR_CBC" >&2
+ [ "-$*" = "-!" ] && printf '%s' "$DZR_CBC" && exit
sleep 2 # give time to read the warning
echo
fi
# dependencies check, see: https://github.com/yne/dzr/issues/12
-for c in jq curl dialog openssl $(echo "$PLAYER" | cut -f 1 -d " "); do
- command -v $c >/dev/null || { echo "$c is required" 1>&2 ; UNMET_DEPENDENCIES=1;}
+for c in jq curl dialog openssl "$(echo "$PLAYER" | cut -f 1 -d " ")"; do
+ command -v "$c" >/dev/null || { echo "$c is required" 1>&2 ; UNMET_DEPENDENCIES=1;}
done
[ -n "$UNMET_DEPENDENCIES" ] && exit 1;
@@ -51,8 +58,8 @@ dzr_user_0() { $DLG_LIST charts '' albums '' playlists '' flow '' tracks '' ar
dzr_artist_0() { $DLG_LIST top?limit=50 '' albums '' fans '' related '' radio '' playlists '' ;}
dzr_default() { $FETCH -H "Accept-Language: $LANG" "$API$1" | jq "$FMT_LIST" | xargs $DLG_LIST ▸ "play all /track/" ⇄ "shuf all /track/" ;} # TODO: .next
play() { # receive /track/1,2,3 from stdin
- xargs basename | xargs $0-url | ${1:-cat} | while read url id; do
- $FETCH "$url" | $0-dec $id | eval ${PLAYER:-'mpv -'} || break # stop if Ctrl+C : $? = 4
+ xargs basename | xargs $BINARY_NAME-url | ${1:-cat} | while read url id; do
+ $FETCH "$url" | $BINARY_NAME-dec $id | eval ${PLAYER:-'mpv -'} || break # stop if Ctrl+C : $? = 4
done
}
for url in "$@"; do
diff --git a/flake.lock b/flake.lock
new file mode 100644
index 0000000..af324b5
--- /dev/null
+++ b/flake.lock
@@ -0,0 +1,61 @@
+{
+ "nodes": {
+ "nixpkgs": {
+ "locked": {
+ "lastModified": 1711655175,
+ "narHash": "sha256-1xiaYhC3ul4y+i3eicYxeERk8ZkrNjLkrFSb/UW36Zw=",
+ "owner": "NixOS",
+ "repo": "nixpkgs",
+ "rev": "64c81edb4b97a51c5bbc54c191763ac71a6517ee",
+ "type": "github"
+ },
+ "original": {
+ "owner": "NixOS",
+ "ref": "nixpkgs-unstable",
+ "repo": "nixpkgs",
+ "type": "github"
+ }
+ },
+ "root": {
+ "inputs": {
+ "nixpkgs": "nixpkgs",
+ "utils": "utils"
+ }
+ },
+ "systems": {
+ "locked": {
+ "lastModified": 1681028828,
+ "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
+ "owner": "nix-systems",
+ "repo": "default",
+ "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
+ "type": "github"
+ },
+ "original": {
+ "owner": "nix-systems",
+ "repo": "default",
+ "type": "github"
+ }
+ },
+ "utils": {
+ "inputs": {
+ "systems": "systems"
+ },
+ "locked": {
+ "lastModified": 1710146030,
+ "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
+ "owner": "numtide",
+ "repo": "flake-utils",
+ "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
+ "type": "github"
+ },
+ "original": {
+ "owner": "numtide",
+ "repo": "flake-utils",
+ "type": "github"
+ }
+ }
+ },
+ "root": "root",
+ "version": 7
+}
diff --git a/flake.nix b/flake.nix
new file mode 100644
index 0000000..f1e9b5d
--- /dev/null
+++ b/flake.nix
@@ -0,0 +1,43 @@
+{
+ inputs = {
+ nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
+ utils.url = "github:numtide/flake-utils";
+ };
+
+ outputs = { self, nixpkgs, utils }:
+ utils.lib.eachDefaultSystem (system:
+ let
+ pkgs = import nixpkgs { inherit system; };
+ shellApplication = name:
+ pkgs.writeShellApplication {
+ name = "${name}";
+ text =
+ let
+ binPath = pkgs.lib.makeBinPath [ ];
+ in
+ ''
+ #!${pkgs.runtimeShell}
+ export PATH="${binPath}:$PATH"
+ '' + builtins.readFile (./. + "/${name}");
+ runtimeInputs = [
+ pkgs.curl
+ pkgs.jq
+ pkgs.openssl
+ pkgs.mpv
+ pkgs.dialog
+ pkgs.python311Packages.eyeD3
+ pkgs.pv
+ ];
+ checkPhase = "${pkgs.stdenv.shellDryRun} $target";
+ bashOptions = [ ];
+ };
+ in
+ {
+ packages.default = (shellApplication "dzr");
+ packages.dzr-dec = (shellApplication "dzr-dec");
+ packages.dzr-id3 = (shellApplication "dzr-id3");
+ packages.dzr-srt = (shellApplication "dzr-srt");
+ packages.dzr-url = (shellApplication "dzr-url");
+ }
+ );
+}