[READ-ONLY] Mirror of https://github.com/probablykasper/my-bash-scripts. My personal bash scripts
cli
0

Configure Feed

Select the types of activity you want to include in your feed.

Added "to" script, replacing "to-mp4" and "to-mp3"

Kasper (Apr 3, 2019, 10:22 PM +0200) d39de30b d1b12f2a

+104 -16
+104
bin/to
··· 1 + #! /bin/bash 2 + 3 + FILENAME=${0##*/} 4 + 5 + help() { 6 + echo " 7 + `tput setaf 2`Usage:`tput setaf 7` 8 + `tput setaf 6`$FILENAME`tput setaf 7` <format> [options] <file1> [file2...] 9 + 10 + `tput setaf 2`Options:`tput setaf 7` 11 + `tput setaf 6`format`tput setaf 7` File format extension to convert to. 12 + `tput setaf 6` `tput setaf 7` - mp3s default to 320kbps 13 + `tput setaf 6`-v, --verbose`tput setaf 7` If you love logs. 14 + `tput setaf 6`-h, --help`tput setaf 7` Show this help message. 15 + `tput setaf 6``tput setaf 7` 16 + `tput setaf 6``tput setaf 7`FFmpeg options are supported too (see ffmpeg -h). Long 17 + `tput setaf 6``tput setaf 7`arguments need to be written with quotes (like \"-b:a 128k\") 18 + " 19 + } 20 + 21 + # if only 0 or 1 arguments 22 + if [[ "$#" < 2 ]]; then help; exit 0; fi 23 + 24 + FORMAT=$1 25 + # remove format argument 26 + shift 1 27 + 28 + FILES=() 29 + VERBOSE_FLAG=false 30 + USER_OPTIONS=false 31 + OPTIONS=() 32 + 33 + if [[ "$FORMAT" = "mp3" ]]; then 34 + OPTIONS+=("-b:a") 35 + OPTIONS+=("320k") 36 + fi 37 + 38 + # parse arguments 39 + while (( "$#" )); do 40 + case "$1" in 41 + -h|--help) 42 + if [[ "$HELP_FLAG" = true ]]; then help; exit 0; fi 43 + shift ;; 44 + -v|--verbose) 45 + VERBOSE_FLAG=true 46 + shift ;; 47 + *) 48 + if [[ -f "$1" ]]; then 49 + FILES+=("$1") 50 + elif [[ "$1" == -* ]]; then 51 + USER_OPTIONS=true 52 + OPTIONS+=("$1") 53 + else 54 + echo "Error: File does not exist (Skipping) or invalid argument: $1" 55 + fi 56 + shift ;; 57 + esac 58 + done 59 + 60 + if [[ "$VERBOSE_FLAG" = false ]]; then 61 + OPTIONS+=("-loglevel") 62 + OPTIONS+=("warning") 63 + fi 64 + 65 + if [[ ${#FILES[@]} = 0 ]]; then 66 + echo "Error: No files specified" 67 + help 68 + exit 1 69 + fi 70 + 71 + if [[ "$USER_OPTIONS" = true ]]; then 72 + echo "Passing the following options to ffmpeg: ${OPTIONS[@]}" 73 + fi 74 + 75 + for FILE in "${FILES[@]}"; do 76 + 77 + if [[ -f "$FILE" ]]; then # check if file exists 78 + echo "Converting $FILE" 79 + 80 + FILENAME=$(basename "$FILE") 81 + FILE_WITHOUT_EXT=${FILE%.*} # remove extension 82 + # echo "FILENAME $FILENAME" 83 + # echo "TEMPDIR $TEMPDIR" 84 + NEW_FILE_WIP="$FILE_WITHOUT_EXT CONVERTING... $((10000 + RANDOM)).$FORMAT" 85 + ffmpeg -i "${FILE}" ${OPTIONS[@]} "$NEW_FILE_WIP" 86 + 87 + NEW_FILE="$FILE_WITHOUT_EXT converted.$FORMAT" 88 + COUNT=1 89 + while [[ -f "$NEW_FILE" ]]; do 90 + if [[ -f "$NEW_FILE" ]]; then 91 + # echo "FILE EXISTS $NEW_FILE" 92 + NEW_FILE="$FILE_WITHOUT_EXT converted ($COUNT).$FORMAT" 93 + (( COUNT++ )) 94 + else 95 + # echo "FILE DOES NOT EXIST $NEW_FILE" 96 + break 97 + fi 98 + done 99 + mv "$NEW_FILE_WIP" "$NEW_FILE" 100 + else 101 + echo "Error: File no longer exists (Skipping): $FILE" 102 + fi 103 + 104 + done
-3
bin/to-mp3
··· 1 - #! /bin/bash 2 - 3 - ffmpeg -i "${1}" -ab 320k "${1%.*}.mp3"
-13
bin/to-mp4
··· 1 - #! /bin/bash 2 - 3 - FILENAME=${0##*/} 4 - 5 - if [[ -z "$1" ]]; then 6 - echo "Syntax: $FILENAME videofile [subtitles]" 7 - else 8 - if [[ -z "$2" ]]; then 9 - ffmpeg -i "${1}" -i "${2}" "${1%.*}.mp4" 10 - else 11 - ffmpeg -i "${1}" "${1%.*}.mp4" 12 - fi 13 - fi