diff options
-rw-r--r-- | download.nix | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/download.nix b/download.nix index 30202b1..fd122b2 100644 --- a/download.nix +++ b/download.nix @@ -1,6 +1,6 @@ let pkgs = import <nixpkgs> {}; - npkgs = import (builtins.fetchTarball "https://github.com/nixos/nixpkgs-channels/archive/nixos-unstable.tar.gz") {}; + npkgs = import (builtins.fetchTarball "https://github.com/nixos/nixpkgs/archive/master.tar.gz") {}; # add_link # download new music from source @@ -91,17 +91,17 @@ let ''; utils.download_stream = pkgs.writers.writeDash "utils.download_stream" '' - set -euf + set -xeuf ${common_header} cd "$target_folder" - new_links="$(cat "$meta_folder/links" | ${pkgs.gnugrep}/bin/grep -v -f "$meta_folder/finished" || :)" + new_links=$(cat "$meta_folder/links" | ${pkgs.gnugrep}/bin/grep -v -f "$meta_folder/finished") if test "$(echo "$new_links" | wc -l)" -gt 0; then echo "$new_links" | ${pkgs.findutils}/bin/xargs -n 1 ${utils.download_ogg} || : fi ''; utils.get_stream_links = pkgs.writers.writeDash "utils.get_stream_links" '' - set -euf + set -xeuf ${common_header} ${utils.extract_playlist} "$1" | ${pkgs.gnugrep}/bin/grep -v -f "$meta_folder/links" | tee -a "$meta_folder/links" ''; @@ -110,10 +110,15 @@ let set -xeuf ${common_header} + TMPDIR=$(mktemp -d) + mkdir -p $TMPDIR + trap "rm -rf $TMPDIR;" INT TERM EXIT + TARGET=$PWD + if ! test "$#" -eq 1; then echo "wrong number of args" else - if echo "$1.ogg" | ${pkgs.gnugrep}/bin/grep -qf "$meta_folder/finished"; then + if echo "$1" | ${pkgs.gnugrep}/bin/grep -qf "$meta_folder/finished"; then echo "already in finished: $1" fi @@ -122,18 +127,21 @@ let echo "file already exists: $1" else duration=$(${npkgs.youtube-dl}/bin/youtube-dl -J "$1" | ${pkgs.jq}/bin/jq .duration) - if [ "$duration" -le 1000 ]; then + if [ "$duration" -le 1000 ] && [ "$duration" -gt 60 ]; then + cd "$TMPDIR" ${npkgs.youtube-dl}/bin/youtube-dl \ -i -o "%(title)s-%(id)s.%(ext)s" \ --restrict-filenames --add-metadata \ --audio-format vorbis \ - -x "$1" + -x "$1" \ + --exec "mv {} $TARGET/" + cd "$TARGET" + fi fi echo "$1" >> "$target_folder/.meta/finished" fi - ''; in pkgs.stdenv.mkDerivation { @@ -142,6 +150,9 @@ in pkgs.stdenv.mkDerivation { commands.add_link commands.pull commands.add_new + (pkgs.writers.writeDashBin "dl-track" '' + ${utils.download_ogg} "$@" + '') npkgs.youtube-dl ]; } |