From ebc70c0128a78f87fc15fba81b4c2bd0f1e127a9 Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Thu, 5 Aug 2021 23:12:59 +1200 Subject: [PATCH] Fix reading filename written using --write-pages --- webroot/watch.shs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/webroot/watch.shs b/webroot/watch.shs index f17f147..f7a45d6 100755 --- a/webroot/watch.shs +++ b/webroot/watch.shs @@ -158,7 +158,15 @@ if [[ "${get_data[v]}" ]]; then fi strings[description]=$(jq -r '.description' <<< "$video" | sed -E 's/$/
/g') - vid="$(cat "temp/${get_data[v]}_https_-_"*"watch"*".dump")" + # youtube-dl modifies the filename when writing with --write-pages + # params restricted=True, is_id=False to https://github.com/ytdl-org/youtube-dl/blob/70d0d4f9beba0e5b6d95ee50ad62ae7ab5be9be1/youtube_dl/utils.py#L2079 + # this accurately replicates the algorithm without as much complexity + written_id="$(sed -E -e 's/__+/_/g' \ + -e 's/^_*(-_)?//' \ + -e 's/^-/_/' \ + <<< "${get_data[v]}")" + echo "Written id $written_id" + vid="$(cat "temp/${written_id}_https_-_"*"watch"*".dump")" vid_json="$(tr -d '\n' <<< "$vid" | grep -Poh "ytInitialData.*?" | sed 's/ytInitialData = //;s/<\/script>//')" strings[recommended]=$(jq -r '.contents.twoColumnWatchNextResults.secondaryResults.secondaryResults.results[] | .compactAutoplayRenderer.contents[0].compactVideoRenderer, .compactVideoRenderer | if .videoId != null then "
"+.title.simpleText+"
" else empty end' <<< "$vid_json")