Merge remote-tracking branch 'wheezy/default_output'

This commit is contained in:
Jaidyn Ann 2021-07-31 21:10:20 -05:00
commit f37978f07c

45
yuja-dl
View File

@ -1,4 +1,4 @@
#!/bin/sh #!/usr/bin/env bash
# -------------------------------------- # --------------------------------------
# name: yuja-dl # name: yuja-dl
# main: Jaidyn Ann <jadedctrl@teknik.io> # main: Jaidyn Ann <jadedctrl@teknik.io>
@ -7,9 +7,10 @@
# -------------------------------------- # --------------------------------------
function download_url { function download_url {
local url="$1"; local output="$2" local url="$1"
local sub="$(echo "$url" | subdomain)" local sub="$(echo "$url" | subdomain)"
local id="$(video_metadata "$url" "$sub" | video_pid)" local id="$(video_metadata "$url" "$sub" | video_pid)"
local output="${OUTPUT:-$(get_metadata "$sub" "$id" | default_video_title)}"
local captions_key="$(get_metadata "$sub" "$id" | caption_file_key)" local captions_key="$(get_metadata "$sub" "$id" | caption_file_key)"
local node_pid="$(get_metadata "$sub" "$id" | video_node_pid)" local node_pid="$(get_metadata "$sub" "$id" | video_node_pid)"
@ -43,6 +44,11 @@ function video_pid {
jq -r .videoPID jq -r .videoPID
} }
function default_video_title {
jq -r .video \
| jq -r .title
}
#--------------------------------------- #---------------------------------------
function get_node_metadata { function get_node_metadata {
@ -103,7 +109,7 @@ function video_metadata {
# INVOCATION # INVOCATION
# -------------------------------------- # --------------------------------------
function usage { function usage {
echo "usage: yuja-dl URL OUTPUT [cookies.txt]" echo "usage: yuja-dl URL [-o OUTPUT] [-c cookies.txt]"
echo echo
echo " URL is a *.yuja.com URL with a video ID argument" echo " URL is a *.yuja.com URL with a video ID argument"
echo " OUTPUT is the basename for the mp4 and srt files" echo " OUTPUT is the basename for the mp4 and srt files"
@ -112,10 +118,31 @@ function usage {
exit 2 exit 2
} }
URL="$1" if [ "$#" -eq 0 ]; then
OUTPUT="$2" usage
COOKIES="$3" fi
if test -z "$URL" -o -z "$OUTPUT"; then usage; fi OPTIND=2
while getopts ":hc:o:" arg; do
case "$arg" in
h)
usage
;;
c)
COOKIES="$OPTARG"
;;
o)
OUTPUT="$OPTARG"
;;
:)
echo "$0: Must supply an argument to -$OPTARG."
exit 1
;;
?)
echo "Invalid option: -${OPTARG}"
usage
;;
esac
done
download_url "$URL" "$OUTPUT" download_url "$1"