From 82df70eff06e7b44ee84283070d7f801f7fc1d92 Mon Sep 17 00:00:00 2001 From: Sam Chudnick Date: Sat, 6 Nov 2021 20:25:45 -0400 Subject: initial commit --- .local/bin/yt-fix | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100755 .local/bin/yt-fix (limited to '.local/bin/yt-fix') 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 @@ +#!/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 + -- cgit v1.2.3