106 lines
2.2 KiB
Bash
Executable File
106 lines
2.2 KiB
Bash
Executable File
#!/bin/sh
|
|
# --------------------------------------
|
|
# name: yuja-dl
|
|
# main: Jaidyn Ann <jadedctrl@teknik.io>
|
|
# lisc: CC0
|
|
# date: 2021
|
|
# --------------------------------------
|
|
|
|
function download_url {
|
|
local url="$1"; local output="$2"
|
|
local id="$(echo "$url" | video_id)"
|
|
local sub="$(echo "$url" | subdomain)"
|
|
|
|
local captions_key="$(get_metadata "$sub" "$id" | caption_file_key)"
|
|
local node_pid="$(get_metadata "$sub" "$id" | video_node_pid)"
|
|
local flink="$(get_node_metadata "$id" "$node_pid" | video_filelink)"
|
|
local m3u8="$(get_video_source "$id" "$flink" | video_source_m3u8_link)"
|
|
|
|
curl -o "${output}.srt" "$(caption_url "$sub" "$captions_key")"
|
|
ffmpeg -i "$m3u8" "${output}.mp4"
|
|
}
|
|
|
|
|
|
#---------------------------------------
|
|
|
|
function get_metadata {
|
|
local sub="$1"; local id="$2"
|
|
curl -s \
|
|
"https://${sub}.yuja.com/P/Data/GetVideoListNodeInfo?videoPID=${id}"
|
|
}
|
|
|
|
function caption_file_key {
|
|
jq -r .video \
|
|
| jq -r .captionFileKey.value
|
|
}
|
|
|
|
function video_node_pid {
|
|
jq -r .node \
|
|
| jq -r .videoListNodePID
|
|
}
|
|
|
|
#---------------------------------------
|
|
|
|
function get_node_metadata {
|
|
local video_id="$1"
|
|
local video_node_pid="$2"
|
|
curl -s \
|
|
"https://dcccd.yuja.com/P/Data/VideoJSON" \
|
|
--data-raw "video=${video_id}&node=${video_node_pid}"
|
|
}
|
|
|
|
function video_filelink {
|
|
jq -r .video.videoLink
|
|
}
|
|
|
|
#---------------------------------------
|
|
|
|
function get_video_source {
|
|
local video_id="$1"
|
|
local video_filelink="$2"
|
|
curl -s \
|
|
"https://dcccd.yuja.com/P/Data/VideoSource?video=${video_filelink}&videoPID=${video_id}"
|
|
}
|
|
|
|
function video_source_m3u8_link {
|
|
jq -r .videoSources[]
|
|
}
|
|
|
|
#---------------------------------------
|
|
|
|
function caption_url {
|
|
local subdomain="$1"
|
|
local caption_key="$2"
|
|
echo \
|
|
"https://${subdomain}.yuja.com/P/DataPage/CaptionFile/${caption_key}"
|
|
}
|
|
|
|
#---------------------------------------
|
|
|
|
function video_id {
|
|
sed 's%.*v=%%' \
|
|
| sed 's%&.*%%'
|
|
}
|
|
|
|
function subdomain {
|
|
awk -F '.' '{print $1}' \
|
|
| sed 's%.*//%%'
|
|
}
|
|
|
|
# INVOCATION
|
|
# --------------------------------------
|
|
function usage {
|
|
echo "usage: yuja-dl URL OUTPUT"
|
|
echo
|
|
echo " URL is a *.yuja.com URL with a video ID argument"
|
|
echo " OUTPUT is the basename for the mp4 and srt files"
|
|
exit 2
|
|
}
|
|
|
|
URL="$1"
|
|
OUTPUT="$2"
|
|
|
|
if test -z "$URL" -o -z "$OUTPUT"; then usage; fi
|
|
|
|
download_url "$URL" "$OUTPUT"
|