diff options
Diffstat (limited to '.local/bin/yt-fix')
| -rwxr-xr-x | .local/bin/yt-fix | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/.local/bin/yt-fix b/.local/bin/yt-fix new file mode 100755 index 0000000..69e771a --- /dev/null +++ b/.local/bin/yt-fix | |||
| @@ -0,0 +1,42 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # Takes files downloaded through youtube-dl and cleans up their filenames | ||
| 4 | |||
| 5 | stdin() { | ||
| 6 | while read -r infile | ||
| 7 | do | ||
| 8 | ext=".$(echo $infile | rev | cut -d '.' -f 1 | rev)" | ||
| 9 | ext_length=${#ext} | ||
| 10 | remove=$((12+$ext_length)) | ||
| 11 | filename="$(echo $infile | rev | cut -c $remove- | rev)" | ||
| 12 | mv "$infile" "$filename$ext" | ||
| 13 | done | ||
| 14 | } | ||
| 15 | |||
| 16 | cli() { | ||
| 17 | for infile in "$@" | ||
| 18 | do | ||
| 19 | ext=".$(echo $infile | rev | cut -d '.' -f 1 | rev)" | ||
| 20 | ext_length=${#ext} | ||
| 21 | remove=$((12+$ext_length)) | ||
| 22 | filename="$(echo $infile | rev | cut -c $remove- | rev)" | ||
| 23 | mv "$infile" "$filename$ext" | ||
| 24 | done | ||
| 25 | } | ||
| 26 | |||
| 27 | options=$(getopt -o 'hsx' -- "$@") | ||
| 28 | eval set -- "$options" | ||
| 29 | read_stdin=0 | ||
| 30 | noext=0 | ||
| 31 | while true | ||
| 32 | do | ||
| 33 | case "$1" in | ||
| 34 | '-h') echo "usage: yt-fix [options] [files]\n\th\tprint this help and exit\n\tx\tdo not include extension in output\n\ts\tread from stdin"; exit 0;; | ||
| 35 | '-s') read_stdin=1; shift; continue;; | ||
| 36 | '-x') noext=1; shift; continue;; | ||
| 37 | '--') shift; break;; | ||
| 38 | esac | ||
| 39 | done | ||
| 40 | |||
| 41 | [ $read_stdin -eq 0 ] && cli "$@" || stdin | ||
| 42 | |||
