blob: 69e771af9575416a061f4dbe04d28e583e515ac7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
#!/bin/sh
# Takes files downloaded through youtube-dl and cleans up their filenames
stdin() {
while read -r infile
do
ext=".$(echo $infile | rev | cut -d '.' -f 1 | rev)"
ext_length=${#ext}
remove=$((12+$ext_length))
filename="$(echo $infile | rev | cut -c $remove- | rev)"
mv "$infile" "$filename$ext"
done
}
cli() {
for infile in "$@"
do
ext=".$(echo $infile | rev | cut -d '.' -f 1 | rev)"
ext_length=${#ext}
remove=$((12+$ext_length))
filename="$(echo $infile | rev | cut -c $remove- | rev)"
mv "$infile" "$filename$ext"
done
}
options=$(getopt -o 'hsx' -- "$@")
eval set -- "$options"
read_stdin=0
noext=0
while true
do
case "$1" in
'-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;;
'-s') read_stdin=1; shift; continue;;
'-x') noext=1; shift; continue;;
'--') shift; break;;
esac
done
[ $read_stdin -eq 0 ] && cli "$@" || stdin
|