===================================================================== --- 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
		
			
				
	
	
		
			52 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			52 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
| #!/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 $@
 |