summaryrefslogtreecommitdiff
path: root/.local/bin/yt-fix
diff options
context:
space:
mode:
authorSam Chudnick <sam@chudnick.com>2021-11-06 20:25:45 -0400
committerSam Chudnick <sam@chudnick.com>2021-11-06 20:25:45 -0400
commit82df70eff06e7b44ee84283070d7f801f7fc1d92 (patch)
treed17ea9cc6e012b16ff0cdeffcf4a97b5e5cd2d11 /.local/bin/yt-fix
initial commit
Diffstat (limited to '.local/bin/yt-fix')
-rwxr-xr-x.local/bin/yt-fix42
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
5stdin() {
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
16cli() {
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
27options=$(getopt -o 'hsx' -- "$@")
28eval set -- "$options"
29read_stdin=0
30noext=0
31while true
32do
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
39done
40
41[ $read_stdin -eq 0 ] && cli "$@" || stdin
42