Skip to content

Instantly share code, notes, and snippets.

@joachimesque
Created June 27, 2023 20:50
Show Gist options
  • Save joachimesque/43be03ff39e18a02a7b25bf926f64028 to your computer and use it in GitHub Desktop.
Save joachimesque/43be03ff39e18a02a7b25bf926f64028 to your computer and use it in GitHub Desktop.
Little bash script to display a M3U-ready file list. `m3u > list.m3u` to generate the list, ready to be ingested.
#!/usr/bin/env bash
SERVER="sftp://WHATEVER.local"
# https://askubuntu.com/questions/343727/filenames-with-spaces-breaking-for-loop-find-command#comment439889_343727
IFS=$'\n'
# https://stackoverflow.com/questions/37309551/how-to-urlencode-data-into-a-url-with-bash-or-curl
# converted to Python3 : urllib.quote => urllib.parse.quote
urlencode() {
python3 -c 'import urllib.parse, sys; print(urllib.parse.quote(sys.argv[1], sys.argv[2]))' \
"$1" "$urlencode_safe"
}
process() {
if [[ $(file --mime-type $1 | egrep "video") ]]; then
encoded=$(urlencode_safe='/' urlencode "$path")
echo "$SERVER$encoded"
fi
}
if [[ -z "$1" || "$1" == "." ]]; then
for path in $(find ~+ -type f | sort -t '\0' -n); do process "$path"; done
else
for path in $(realpath $(find "$1" -type f | sort -t '\0' -n)); do process "$path"; done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment