From 56528f9655e7c017154275378800f6d3cbc9101d Mon Sep 17 00:00:00 2001 From: Jaidyn Ann Date: Thu, 14 Jan 2021 20:08:28 -0600 Subject: [PATCH] Init --- README.txt | 36 ++++++++++++++++++++++++++ yuja-dl | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+) create mode 100644 README.txt create mode 100755 yuja-dl diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..ff41b20 --- /dev/null +++ b/README.txt @@ -0,0 +1,36 @@ +=============================================================================== +YUJA-DL +=============================================================================== + +Download videos and subtitles from *.yuja.com with this script. +Useful if your web-browser doesn't support streaming, or your PC is too weak +to run one in the first place. Also useful for archival. + +I have a blog post on this over at https://xwx.moe/lib/ripping_hls_from_yuja.md + +---------------------------------------- +PRE-REQUISITES +---------------------------------------- +You'll need: + * curl + * jq + * ffmpeg + * a shell + + +---------------------------------------- +USAGE +---------------------------------------- +$ yuja-dl $VIDEO_URL $OUTPUT_NAME + +$VIDEO_URL should be in the format of "https://*.yuja.com/V/Video=?v=*". +$OUTPUT_NAME will be the basename of the mp4 and srt files. + + +---------------------------------------- +BORING STUFF +---------------------------------------- +License is CC-0 +Author is Jaidyn Ann +https://git.feneas.org/detruota/yuja-dl.git +https://github.com/JadedCtrl/yuja-dl.git diff --git a/yuja-dl b/yuja-dl new file mode 100755 index 0000000..aa97a7e --- /dev/null +++ b/yuja-dl @@ -0,0 +1,76 @@ +#!/bin/sh +# -------------------------------------- +# name: yuja-dl +# main: Jaidyn Ann +# 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 hls_key="$(get_metadata "$sub" "$id" | hls_file_key)" + local captions_key="$(get_metadata "$sub" "$id" | caption_file_key)" + + ffmpeg -i "$(m3u8_url "$hls_key")" "${output}.mp4" + curl -o "${output}.srt" "$(caption_url "$sub" "$captions_key")" +} + +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 caption_url { + local subdomain="$1" + local caption_key="$2" + echo \ + "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=%%' \ + | 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"