From 481b5d15e078a3b50e46abf98418957e9889227c Mon Sep 17 00:00:00 2001 From: Jaidyn Ann Date: Fri, 29 Jan 2021 15:42:48 -0600 Subject: [PATCH] Fix downloading for some videos --- yuja-dl | 75 +++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 52 insertions(+), 23 deletions(-) diff --git a/yuja-dl b/yuja-dl index aa97a7e..9064270 100755 --- a/yuja-dl +++ b/yuja-dl @@ -10,20 +10,64 @@ function download_url { local url="$1"; local output="$2" local id="$(echo "$url" | video_id)" local sub="$(echo "$url" | subdomain)" - local hls_key="$(get_metadata "$sub" "$id" | hls_file_key)" + 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)" - ffmpeg -i "$(m3u8_url "$hls_key")" "${output}.mp4" curl -o "${output}.srt" "$(caption_url "$sub" "$captions_key")" + ffmpeg -i "$m3u8" "${output}.mp4" } -function m3u8_url { - local hls_key="$1" - local fragment="${hls_key}/720p/${hls_key}.m3u8" - echo \ - "https://my.yuja.com/P/Data/VideoUrl/level${fragment}.m3u8?dist=yuja-edits&key=${fragment}" + +#--------------------------------------- + +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" @@ -31,21 +75,7 @@ function caption_url { "https://${subdomain}.yuja.com/P/DataPage/CaptionFile/${caption_key}" } -function get_metadata { - local sub="$1"; local id="$2" - curl -s \ - "https://${sub}.yuja.com/P/Data/GetVideoListNodeInfo?videoPID=${id}" -} - -function hls_file_key { - jq -r .video \ - | jq -r .videoHLSFileKey.value -} - -function caption_file_key { - jq -r .video \ - | jq -r .captionFileKey.value -} +#--------------------------------------- function video_id { sed 's%.*v=%%' \ @@ -57,7 +87,6 @@ function subdomain { | sed 's%.*//%%' } - # INVOCATION # -------------------------------------- function usage {