From 6605ff47ce9f0cfdfa21fe28fb137082390280b2 Mon Sep 17 00:00:00 2001 From: vwheezy22 Date: Tue, 27 Jul 2021 12:46:19 -0700 Subject: [PATCH 1/2] Get video id from new endpoint --- yuja-dl | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/yuja-dl b/yuja-dl index 11a29d1..e2d45d8 100755 --- a/yuja-dl +++ b/yuja-dl @@ -8,8 +8,8 @@ function download_url { local url="$1"; local output="$2" - local id="$(echo "$url" | video_id)" local sub="$(echo "$url" | subdomain)" + local id="$(video_metadata "$url" "$sub" | video_pid)" local captions_key="$(get_metadata "$sub" "$id" | caption_file_key)" local node_pid="$(get_metadata "$sub" "$id" | video_node_pid)" @@ -39,6 +39,10 @@ function video_node_pid { | jq -r .videoListNodePID } +function video_pid { + jq -r .videoPID +} + #--------------------------------------- function get_node_metadata { @@ -79,16 +83,23 @@ function caption_url { #--------------------------------------- -function video_id { - sed 's%.*v=%%' \ - | sed 's%&.*%%' -} - function subdomain { awk -F '.' '{print $1}' \ | sed 's%.*//%%' } +function video_uid { + sed 's%.*u=%%' \ + | sed 's%&.*%%' +} + +function video_metadata { + local url="$1"; local sub="$2" + local uid="$(echo "$url" | video_uid)" + curl -b "$COOKIES" -s \ + "https://${sub}.yuja.com/V/VideoDecryptLogicServlet?u=${uid}" +} + # INVOCATION # -------------------------------------- function usage { From d8fbb046025bdd7cc8dbaf9bbb30c1bdba0214d1 Mon Sep 17 00:00:00 2001 From: vwheezy22 Date: Thu, 29 Jul 2021 02:40:39 -0700 Subject: [PATCH 2/2] Made output argument default Revamped argument parsing system, `COOKIES` and `OUTPUT` are both flags now. Changed the script to bash because shellcheck was bothering me :^) --- yuja-dl | 43 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/yuja-dl b/yuja-dl index e2d45d8..2f55f10 100755 --- a/yuja-dl +++ b/yuja-dl @@ -1,4 +1,4 @@ -#!/bin/sh +#!/usr/bin/env bash # -------------------------------------- # name: yuja-dl # main: Jaidyn Ann @@ -7,9 +7,10 @@ # -------------------------------------- function download_url { - local url="$1"; local output="$2" + local url="$1" local sub="$(echo "$url" | subdomain)" 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 node_pid="$(get_metadata "$sub" "$id" | video_node_pid)" @@ -43,6 +44,11 @@ function video_pid { jq -r .videoPID } +function default_video_title { + jq -r .video \ + | jq -r .title +} + #--------------------------------------- function get_node_metadata { @@ -103,7 +109,7 @@ function video_metadata { # INVOCATION # -------------------------------------- function usage { - echo "usage: yuja-dl URL OUTPUT [cookies.txt]" + echo "usage: yuja-dl URL [-o OUTPUT] [-c cookies.txt]" echo echo " URL is a *.yuja.com URL with a video ID argument" echo " OUTPUT is the basename for the mp4 and srt files" @@ -112,10 +118,31 @@ function usage { exit 2 } -URL="$1" -OUTPUT="$2" -COOKIES="$3" +if [ "$#" -eq 0 ]; then + usage +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"