Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Nix Flake to run with Nix #38

Open
wants to merge 4 commits into
base: nix
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 -` <br> `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
Expand Down Expand Up @@ -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/<commit-hash>`
31 changes: 19 additions & 12 deletions dzr
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#!/bin/sh

BINARY_NAME="$(basename "$0")"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this break usage form folder

./cgi-bin/dzr /track/117581954
xargs: dzr-url: No such file or directory


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
Expand All @@ -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}";}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need the \ddd tranform

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;

Expand All @@ -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
Expand Down
61 changes: 61 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 43 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -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");
}
);
}