Skip to content

Instantly share code, notes, and snippets.

@nidble
Created June 15, 2019 10:54
Show Gist options
  • Save nidble/42662a2427a998ee13ff5b450bd59f0b to your computer and use it in GitHub Desktop.
Save nidble/42662a2427a998ee13ff5b450bd59f0b to your computer and use it in GitHub Desktop.
Build m3u playlist magically
#!/bin/bash
dir=${1:-$PWD}
find "$dir" -type f -name "*.mp4" | sort | awk -F\/ '
$7 ~ /^[0-9]{1,2}/ {
folder=gensub(/^[^0-9]*([0-9]+).*$/,"\\1","G", $7)
idx=gensub(/^[^0-9]*([0-9]+).*$/,"\\1","G", $8)
# arr[folder][length(arr[folder])+1]=$0 #auto incremental idx
arr[folder][idx]=$0
}
END { for (i in arr) { for (j in arr[i]) { print arr[i][j] >> i".m3u" }}}
'
# | awk -v d="$dir" '{
# row = gensub([^\/]+(\/), "", "$0")
# print row
# }'
# awk -F\/ '$2 ~ /^[0-9]/ { arr[$2][length(arr[$2])+1]=$3 } END { for (i in arr) { for (j in arr[i]) {print i,"/",arr[i][j] } }}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment