+ new comments API
This commit is contained in:
parent
5681a44e40
commit
116bd62371
16
webroot/comments.shs
Executable file
16
webroot/comments.shs
Executable file
|
@ -0,0 +1,16 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
vid="$(curl -b cookiejar_ -H "Cookie: CONSENT=YES+1337" -s "https://www.youtube.com/watch?v=${get_data[v]}" -c cookiejar_)" # broken comment support, we need this for now
|
||||||
|
|
||||||
|
cont="$(grep -Poh 'token":"Eg0S.*?"' <<< "$vid" | sed -E 's/token"://;s/"//g')" #'
|
||||||
|
comments="$(curl -s 'https://www.youtube.com/youtubei/v1/next?key=AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8' \
|
||||||
|
--compressed -H 'Content-Type: application/json' \
|
||||||
|
--data-raw '{"context":{"client":{"hl":"en","gl":"GB","clientName":"WEB","clientVersion":"2.20210719.00.00","mainAppWebInfo":{}},"adSignalsInfo":{"params":[]}},"continuation":"'"$cont"'"}' \
|
||||||
|
| jq '.onResponseReceivedEndpoints[].reloadContinuationItemsCommand.continuationItems[]')"
|
||||||
|
|
||||||
|
|
||||||
|
jq -r '"<h3>\(.commentsHeaderRenderer.countText.runs[0].text) Comments</h3>"' <<< "$comments" | head -1
|
||||||
|
jq -r '.commentThreadRenderer.comment.commentRenderer | select(.authorText.simpleText != null) |
|
||||||
|
"</div><div class='"'"'comment'"'"'><a href='"'"'\(.authorEndpoint.commandMetadata.webCommandMetadata.url)'"'"'><img src='"'"'\(.authorThumbnail.thumbnails[0].url)'"'"'>\(.authorText.simpleText)</a><br>",
|
||||||
|
(.contentText.runs[] | if .bold == true then "<b>\(.text)</b>" else .text end)' <<< "$comments" | sed -E 's/^$/<br>/g'
|
||||||
|
|
|
@ -4,6 +4,10 @@
|
||||||
pre {
|
pre {
|
||||||
white-space: pre-wrap;
|
white-space: pre-wrap;
|
||||||
}
|
}
|
||||||
|
.comment {
|
||||||
|
margin-top: 5px;
|
||||||
|
margin-bottom: 15px;
|
||||||
|
}
|
||||||
|
|
||||||
.hide-cursor {
|
.hide-cursor {
|
||||||
cursor: none;
|
cursor: none;
|
||||||
|
|
17
webroot/js/watch.js
Normal file
17
webroot/js/watch.js
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
window.addEventListener("load", () => {
|
||||||
|
const comments = document.querySelector(".comments");
|
||||||
|
const id = new URLSearchParams(document.location.search).get("v");
|
||||||
|
comments.innerText = "Loading...";
|
||||||
|
fetch("/comments.shs?v=" + id).then(
|
||||||
|
res => {
|
||||||
|
if (res.status !== 200) {
|
||||||
|
throw new Error('HTTP Error ' + res.status);
|
||||||
|
}
|
||||||
|
return res.text();
|
||||||
|
}
|
||||||
|
).then(
|
||||||
|
res => comments.innerHTML = res
|
||||||
|
).catch(
|
||||||
|
err => comments.innerText = 'Error during fetching comments: ' + err.message
|
||||||
|
)
|
||||||
|
})
|
|
@ -154,29 +154,7 @@ if [[ "${get_data[v]}" ]]; then
|
||||||
|
|
||||||
strings[recommended]=$(jq -r '.contents.twoColumnWatchNextResults.secondaryResults.secondaryResults.results[] | .compactAutoplayRenderer.contents[0].compactVideoRenderer, .compactVideoRenderer | if .videoId != null then "<div><a href='"'"'/watch?v="+.videoId+"'"'"'><img src='"'"'https://i.ytimg.com/vi/"+.videoId+"/mqdefault.jpg'"'"'>"+.title.simpleText+"</a></div>" else empty end' <<< "$vid_json")
|
strings[recommended]=$(jq -r '.contents.twoColumnWatchNextResults.secondaryResults.secondaryResults.results[] | .compactAutoplayRenderer.contents[0].compactVideoRenderer, .compactVideoRenderer | if .videoId != null then "<div><a href='"'"'/watch?v="+.videoId+"'"'"'><img src='"'"'https://i.ytimg.com/vi/"+.videoId+"/mqdefault.jpg'"'"'>"+.title.simpleText+"</a></div>" else empty end' <<< "$vid_json")
|
||||||
|
|
||||||
vid="$(curl -b cookiejar_ -H "Cookie: CONSENT=YES+1337" -s "https://www.youtube.com/watch?v=${get_data[v]}" -c cookiejar_)" # broken comment support, we need this for now
|
strings[comments_list]="<div class='comments'></div><script src='/js/watch.js'></script>"
|
||||||
|
|
||||||
cont="$(grep -Poh 'continuation":".*?"' <<< "$vid" | sed -E 's/.*":"//g;s/"//g')"
|
|
||||||
CSRF="$(grep -Poh 'XSRF_TOKEN":".*?"' <<< "$vid" | sed -E 's/XSRF_TOKEN":"//g;s/"//g;s/\\u00/%/g')"
|
|
||||||
itct="$(grep -Poh '","clickTrackingParams":".*?"' <<< "$vid" | sed -E 's/.*":"//g;s/"//g;s/\=/%3d/g')"
|
|
||||||
|
|
||||||
comments="$(curl -s 'https://www.youtube.com/comment_service_ajax?action_get_comments=1&pbj=1&ctoken='"$cont"'&continuation='"$cont"'&itct='"$itct" -H 'Accept: */*' -H 'Accept-Language: en-US,en;q=0.5' --compressed -H 'X-YouTube-Client-Name: 1' -H 'X-YouTube-Client-Version: 2.20201105.01.01' --data-raw 'session_token='"$CSRF" -b cookiejar_)"
|
|
||||||
|
|
||||||
IFS=$'\n'
|
|
||||||
comment_nick=($(jq -r '.response.continuationContents.itemSectionContinuation.contents[].commentThreadRenderer.comment.commentRenderer.authorText.simpleText' <<< "$comments"))
|
|
||||||
comment_published=($(jq -r '.response.continuationContents.itemSectionContinuation.contents[].commentThreadRenderer.comment.commentRenderer.publishedTimeText.runs[0].text' <<< "$comments"))
|
|
||||||
comment_likes=($(jq -r '.response.continuationContents.itemSectionContinuation.contents[].commentThreadRenderer.comment.commentRenderer.voteCount.simpleText' <<< "$comments"))
|
|
||||||
comment_avatar=($(jq -r '.response.continuationContents.itemSectionContinuation.contents[].commentThreadRenderer.comment.commentRenderer.authorThumbnail.thumbnails[1].url' <<< "$comments"))
|
|
||||||
unset IFS
|
|
||||||
x=$(jq '.response.continuationContents.itemSectionContinuation.contents[].commentThreadRenderer.comment.commentRenderer.contentText.runs | map(.text)' <<< "$comments")
|
|
||||||
IFS=']'
|
|
||||||
for i in $x; do
|
|
||||||
comment_text+=($(echo "$i]" | jq -r 'join("")')) # sincerely, fsck [] shell expansion
|
|
||||||
done
|
|
||||||
|
|
||||||
for (( i=0; i<${#comment_nick[@]}; i++ )); do
|
|
||||||
strings[comments_list]+=$(echo "<div><img src='${comment_avatar[$i]}'> <b>${comment_nick[$i]}</b> | ${comment_published[$i]} | ${comment_likes[$i]} liked<br><pre>${comment_text[$i]}</pre></div><hr>")
|
|
||||||
done
|
|
||||||
|
|
||||||
strings[playlist]=""
|
strings[playlist]=""
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue