v2.1.0
===================================================================== --- New Scripts -------------------------- zsh ) database backup/restore - db/postgres/pg_dump - db/postgres/pg_restore - aws/rds/create-backup - aws/rds/load-backup redis-cached curl commands - redis/curl youtube download - youtube/download - youtube/get-audio-clip --- Changes ------------------------------ - 'scwrypts' executable now reloads upon execution to prevent staleness - added various options to improve api/cli; see 'scwrypts --help' for more --- Bug Fixes ---------------------------- - fixed an issue with .config settings' visibility to non-zsh scripts - fixed an issue with command arguments globbing too early
This commit is contained in:
5
zsh/youtube/README.md
Normal file
5
zsh/youtube/README.md
Normal file
@ -0,0 +1,5 @@
|
||||
# ZSH Scwrypts
|
||||
[](https://github.com/ytdl-org/youtube-dl)
|
||||
<br>
|
||||
|
||||
Quick wrappers for downloading and trimming YouTube videos.
|
45
zsh/youtube/common.zsh
Normal file
45
zsh/youtube/common.zsh
Normal file
@ -0,0 +1,45 @@
|
||||
_DEPENDENCIES+=(
|
||||
youtube-dl
|
||||
ffmpeg
|
||||
)
|
||||
_REQUIRED_ENV+=()
|
||||
source ${0:a:h}/../common.zsh
|
||||
#####################################################################
|
||||
|
||||
YT__GLOBAL_ARGS=(
|
||||
--no-call-home
|
||||
--restrict-filenames
|
||||
)
|
||||
|
||||
YT__OUTPUT_DIR="$SCWRYPTS_DATA_PATH/youtube"
|
||||
|
||||
YT__GET_INFO() {
|
||||
youtube-dl --dump-json ${YT__GLOBAL_ARGS[@]} $@
|
||||
}
|
||||
|
||||
YT__GET_FILENAME() {
|
||||
YT__GET_INFO $@ \
|
||||
| jq -r '._filename' \
|
||||
| sed 's/\.[^.]*$/\.mp4/' \
|
||||
;
|
||||
}
|
||||
|
||||
YT__DOWNLOAD() {
|
||||
local OUTPUT_DIR="$SCWRYPTS_DATA_PATH/youtube"
|
||||
[ ! -d $YT__OUTPUT_DIR ] && mkdir -p $YT__OUTPUT_DIR
|
||||
cd "$YT__OUTPUT_DIR"
|
||||
youtube-dl ${YT__GLOBAL_ARGS[@]} $@ \
|
||||
--format 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/mp4' \
|
||||
;
|
||||
}
|
||||
|
||||
GET_VIDEO_LENGTH() {
|
||||
local FILENAME="$1"
|
||||
|
||||
ffprobe \
|
||||
-v quiet \
|
||||
-show_entries format=duration \
|
||||
-of default=noprint_wrappers=1:nokey=1 \
|
||||
-i $FILENAME \
|
||||
;
|
||||
}
|
25
zsh/youtube/download
Executable file
25
zsh/youtube/download
Executable file
@ -0,0 +1,25 @@
|
||||
#!/bin/zsh
|
||||
_DEPENDENCIES+=()
|
||||
_REQUIRED_ENV+=()
|
||||
source ${0:a:h}/common.zsh
|
||||
#####################################################################
|
||||
|
||||
DOWNLOAD_VIDEO() {
|
||||
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'"
|
||||
|
||||
__SUCCESS "Found '$FILENAME'"
|
||||
__Yn "Proceed with download?" || return 1
|
||||
|
||||
YT__DOWNLOAD $URLS \
|
||||
&& __SUCCESS "downloaded to '$YT__OUTPUT_DIR/$FILENAME'" \
|
||||
|| { __ERROR "failed to download '$FILENAME'"; return 2; }
|
||||
}
|
||||
|
||||
#####################################################################
|
||||
DOWNLOAD_VIDEO $@
|
51
zsh/youtube/get-audio-clip
Executable file
51
zsh/youtube/get-audio-clip
Executable file
@ -0,0 +1,51 @@
|
||||
#!/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 $@
|
Reference in New Issue
Block a user