Unverified Commit 3cff1da8 authored by Colin Arnott's avatar Colin Arnott
Browse files

aaxtomp3: use resholve not PATH

Instead of wrapping out binary, we can patch the script to point
directly into /nix/store/. While doing this, we added a few dependencies
we missed and found an osh parsing bug that has been reported upstream.

See oilshell/oil#1446
parent 71a885bf
Loading
Loading
Loading
Loading
+49 −23
Original line number Diff line number Diff line
{ coreutils
{ bash
, bc
, coreutils
, fetchFromGitHub
, ffmpeg
, findutils
, gawk
, gnugrep
, gnused
, jq
, lame
, lib
, makeWrapper
, mediainfo
, mp4v2
, stdenv
, ncurses
, resholve
}:
let
  runtimeInputs = [
    coreutils
    ffmpeg
    findutils
    gnugrep
    gnused
    jq
    lame
    mediainfo
    mp4v2
  ];
in
stdenv.mkDerivation rec {

resholve.mkDerivation rec {
  pname = "aaxtomp3";
  version = "1.3";

@@ -36,17 +27,52 @@ stdenv.mkDerivation rec {
    hash = "sha256-7a9ZVvobWH/gPxa3cFiPL+vlu8h1Dxtcq0trm3HzlQg=";
  };

  dontBuild = false;
  # use whitespace to show osh arithmetic is not file redirection
  # see: https://github.com/oilshell/oil/issues/1446
  patches = [./osh.patch];

  nativeBuildInputs = [ makeWrapper ];
  postPatch = ''
    substituteInPlace AAXtoMP3 \
      --replace 'AAXtoMP3' 'aaxtomp3'
    substituteInPlace interactiveAAXtoMP3 \
      --replace 'AAXtoMP3' 'aaxtomp3' \
      --replace 'call="./aaxtomp3"' 'call="$AAXTOMP3"'
  '';

  installPhase = ''
    install -Dm 755 AAXtoMP3 $out/bin/aaxtomp3
    wrapProgram $out/bin/aaxtomp3 --prefix PATH : ${lib.makeBinPath runtimeInputs}
    install -Dm 755 interactiveAAXtoMP3 $out/bin/interactiveaaxtomp3
    wrapProgram $out/bin/interactiveaaxtomp3 --prefix PATH : ${lib.makeBinPath runtimeInputs}
  '';

  solutions.default = {
    scripts = [
      "bin/aaxtomp3"
      "bin/interactiveaaxtomp3"
    ];
    interpreter = "${bash}/bin/bash";
    inputs = [
      bc
      coreutils
      ffmpeg
      findutils
      gawk
      gnugrep
      gnused
      jq
      lame
      mediainfo
      mp4v2
      ncurses
    ];
    keep."$call" = true;
    fix = {
      "$AAXTOMP3" = [ "${placeholder "out"}/bin/aaxtomp3" ];
      "$FIND" = [ "find" ];
      "$GREP" = [ "grep" ];
      "$SED" = [ "sed" ];
    };
  };

  meta = with lib; {
    description = "Convert Audible's .aax filetype to MP3, FLAC, M4A, or OPUS";
    homepage = "https://krumpetpirate.github.io/AAXtoMP3";
+15 −0
Original line number Diff line number Diff line
diff --git a/AAXtoMP3 b/AAXtoMP3
index 90566ad..71e94da 100755
--- a/AAXtoMP3
+++ b/AAXtoMP3
@@ -200,8 +200,8 @@ progressbar() {
 
   #draw progressbar with one # for every 5% and blank spaces for the missing part.
   progressbar=""
-  for (( n=0; n<(percentage/5); n++ )) ; do progressbar="$progressbar#"; done
-  for (( n=0; n<(20-(percentage/5)); n++ )) ; do progressbar="$progressbar "; done
+  for (( n=0; n< (percentage/5); n++ )) ; do progressbar="$progressbar#"; done
+  for (( n=0; n< (20-(percentage/5)); n++ )) ; do progressbar="$progressbar "; done
 
   #print progressbar
   echo -ne "Chapter splitting: |$progressbar| $print_percentage% ($part/$total chapters)\r"