#!/bin/zsh _DEPENDENCIES+=() _REQUIRED_ENV+=() source ${0:a:h}/common.zsh ##################################################################### GET_AUDIO_CLIP() { local URLS=($@) [[ ${#URLS[@]} -eq 0 ]] && URLS=($(echo '' | __FZF_HEAD 'enter URL')) [[ ${#URLS[@]} -eq 0 ]] && __ABORT local FILENAME=$(YT__GET_FILENAME $URLS) [ ! $FILENAME ] && __ERROR "unable to download '$URLS'" INPUT_FILE="$YT__OUTPUT_DIR/$FILENAME" [ ! -f "$INPUT_FILE" ] && { __RUN_SCWRYPT youtube/download -- $URLS || return 1 } __SUCCESS "video download '$FILENAME' detected!" LENGTH=$(GET_VIDEO_LENGTH "$INPUT_FILE") [ ! $LENGTH ] && { __ERROR "unable to determine video length for '$INPUT_FILE'"; return 2; } START_TIME=$(echo 0 | __FZF_HEAD "enter start time (0 ≤ t < $LENGTH)") [ ! $START_TIME ] && __ABORT END_TIME=$(echo $LENGTH | __FZF_HEAD "enter end time ($START_TIME > t ≥ $LENGTH)") [ ! $END_TIME ] && __ABORT __STATUS __STATUS "video : $FILENAME" __STATUS "start time : $START_TIME" __STATUS "end time : $END_TIME" __STATUS OUTPUT_FILE=$(echo '' \ | __FZF_HEAD 'what should I call this clip? (.mp3)' \ | sed 's/\.mp3$//' \ ) [ ! $OUTPUT_FILE ] && __ABORT OUTPUT_FILE="$YT__OUTPUT_DIR/$OUTPUT_FILE.mp3" ffmpeg -i "$INPUT_FILE" -q:a 0 -map a \ -ss $START_TIME -t $(($END_TIME - $START_TIME))\ "$OUTPUT_FILE" \ && __SUCCESS "created clip '$OUTPUT_FILE'" \ || { __ERROR "error creating clip '$(basename $OUTPUT_FILE)' (see above)"; return 3; } } ##################################################################### GET_AUDIO_CLIP $@