From ad62fbf87a159a796b1d0e0b615bbfbf09f5fa6c Mon Sep 17 00:00:00 2001 From: Heavy Date: Thu, 4 Nov 2021 08:10:30 +0100 Subject: [PATCH] Added functions to convert filename to URI and to enqueue urls to mediaplayer. --- dot_bashrc.d/executable_09.functions | 52 ++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/dot_bashrc.d/executable_09.functions b/dot_bashrc.d/executable_09.functions index 3df3de7..2f7da6a 100755 --- a/dot_bashrc.d/executable_09.functions +++ b/dot_bashrc.d/executable_09.functions @@ -52,4 +52,56 @@ epoch2date() { date -d "@$string" } +# inspired by +# https://unix.stackexchange.com/questions/59501/convert-file-path-to-uri-in-bash +# https://www.unix.com/shell-programming-and-scripting/159863-how-store-files-names-directory-array.html +file2uri() { + local root=${1:-.} + local filter=${2:-*} + + if ! python3 --version &> /dev/null + then + echo "python not available!" + return 2 + fi + + echo "get files for $root" + #for f in "$root/*"; do + # echo "checking $f" + # if [ -f $f ]; then + # echo "is a file: $f" + # python -c "import sys, pathlib; print(pathlib.Path(input()).resolve().as_uri())" <<< "$f" + # fi + #done + + # arr_uris=(`ls $root/*.ma4`) + + arr=() + for f in $root/*.m4a; do + echo "f: $f" + echo python3 -c "import sys, pathlib; print(pathlib.Path(input()).resolve().as_uri())" <<< "$f" + uri=$(python3 -c "import sys, pathlib; print(pathlib.Path(input()).resolve().as_uri())" <<< "$f") + arr[${#arr[@]}]="$uri" + done + for a in "${arr[@]}"; do + echo "$a" + done +} + +enqueueFiles() { + local root="${1:-.}" + + if ! rhythmbox-client --version &> /dev/null + then + echo "No rhythmbox-client available!" + return 3 + fi + + file2uri "$root" + # echo "Array is ${arr[*]}" + for a in "${arr[@]}"; do + echo rhythmbox-client --no-start --enqueue $a + done +} + PATH=$PATH:$HOME/bin