From 62ffc8c4e2fa996dd6da8b007b9bda6f1144d8a1 Mon Sep 17 00:00:00 2001 From: Mandy Schoep Date: Fri, 29 Mar 2024 14:48:38 +0100 Subject: [PATCH 1/4] Nix flake --- dzr | 27 +++++++++++++----------- flake.lock | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 43 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 119 insertions(+), 12 deletions(-) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/dzr b/dzr index cee4494..58377ef 100755 --- a/dzr +++ b/dzr @@ -1,5 +1,7 @@ #!/bin/sh +BINARY_NAME="$(basename "$0")" + # 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 +11,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 +54,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"); + } + ); +} From 053a6080efbbaa6c24bb480cb1e372aba7cbae2c Mon Sep 17 00:00:00 2001 From: Mandy Schoep Date: Fri, 29 Mar 2024 14:55:15 +0100 Subject: [PATCH 2/4] Nix docs --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index 4431d13..5dadc3a 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 branch: `nix run github.com/yne/dzr/branch-name` \ No newline at end of file From 1be7e5288d6c8b9226c2596a615225630ee7b848 Mon Sep 17 00:00:00 2001 From: Mandy Schoep Date: Fri, 29 Mar 2024 14:56:12 +0100 Subject: [PATCH 3/4] Updated documentation --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5dadc3a..5524de3 100644 --- a/README.md +++ b/README.md @@ -72,4 +72,4 @@ open http://127.0.0.1:8000/cgi-bin/dzr?6113114 - 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 branch: `nix run github.com/yne/dzr/branch-name` \ No newline at end of file + - Specific revision: `nix run github.com/yne/dzr/` \ No newline at end of file From f641840f63ab5549837b697e945436a692a3995c Mon Sep 17 00:00:00 2001 From: Mandy Schoep <2277717+OhMyMndy@users.noreply.github.com> Date: Fri, 26 Apr 2024 13:18:10 +0000 Subject: [PATCH 4/4] Check for dzr in path to work with Nix and non Nix --- README.md | 2 +- dzr | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5524de3..771ac06 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ | 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 | +| Nix | `nix run github.com:yne/dzr` | latest | ## Usage diff --git a/dzr b/dzr index 58377ef..5e96953 100755 --- a/dzr +++ b/dzr @@ -2,6 +2,10 @@ 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