From d8517f545ac6b018eb9c608f4fc78c8cb67ea1ea Mon Sep 17 00:00:00 2001 From: Dominika Liberda Date: Thu, 18 Feb 2021 03:50:41 +0100 Subject: [PATCH] * tempfix for comments --- config.sh | 3 ++- webroot/fav.shs | 2 +- webroot/playlist.shs | 2 +- webroot/watch.shs | 17 ++++++++++------- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/config.sh b/config.sh index 0ea4b88..5f59400 100644 --- a/config.sh +++ b/config.sh @@ -1 +1,2 @@ -cfg[title]='BashTube' \ No newline at end of file +cfg[title]='BashTube' +cfg[_cookies]='cookiejar' diff --git a/webroot/fav.shs b/webroot/fav.shs index e5550f5..e3c7d7f 100644 --- a/webroot/fav.shs +++ b/webroot/fav.shs @@ -1,7 +1,7 @@ #!/bin/bash if session_verify "${cookies[sh_session]}" && [[ "${get_data[v]}" != '' ]]; then - title=$(haruhi-dl $([[ ${cfg[_cookies]} != "" ]] && echo -n -- "-c ${cfg[_cookies]}") -e "https://youtube.com/watch?v=${get_data[v]}") + title=$(haruhi-dl --cookies ${cfg[_cookies]} -e "https://youtube.com/watch?v=${get_data[v]}") if [[ $(grep -F "$title" storage/faves | grep "$(echo ${cookies[username]} | sed -E "s/\r//")") == '' ]]; then echo "$(session_get_username ${cookies[sh_session]}):${get_data[v]}:$title" >> storage/faves fi diff --git a/webroot/playlist.shs b/webroot/playlist.shs index d948872..3c53c75 100644 --- a/webroot/playlist.shs +++ b/webroot/playlist.shs @@ -4,7 +4,7 @@ meta[title]="$title" source templates/head.sh if [[ "${get_data[list]}" ]]; then - data=$(haruhi-dl $([[ ${cfg[_cookies]} != "" ]] && echo -n -- "-c ${cfg[_cookies]}") -j --flat-playlist "https://www.youtube.com/playlist?list=${get_data[list]}") + data=$(haruhi-dl --cookies ${cfg[_cookies]} -j --flat-playlist "https://www.youtube.com/playlist?list=${get_data[list]}") else echo "Please specify id" return diff --git a/webroot/watch.shs b/webroot/watch.shs index 82fbaad..36e132c 100755 --- a/webroot/watch.shs +++ b/webroot/watch.shs @@ -9,9 +9,9 @@ if [[ "${get_data[v]}" ]]; then source templates/head.sh else cd temp - video=$(haruhi-dl --write-pages $([[ ${cfg[_cookies]} != "" ]] && echo -n -- "-c ${cfg[_cookies]}") -J "http://youtube.com/watch?v=${get_data[v]}") + video=$(haruhi-dl --write-pages --cookies ${cfg[_cookies]} -J "http://youtube.com/watch?v=${get_data[v]}") if [[ $video == '' ]]; then # okay who did this - video=$(haruhi-dl --write-pages $([[ ${cfg[_cookies]} != "" ]] && echo -n -- "-c ${cfg[_cookies]}") -J "http://youtube.com/watch?v=${get_data[v]}") + video=$(haruhi-dl --write-pages --cookies ${cfg[_cookies]} -J "http://youtube.com/watch?v=${get_data[v]}") if [[ $video == '' ]]; then # seriously WHO DID THIS return fi @@ -69,24 +69,27 @@ if [[ "${get_data[v]}" ]]; then Description:
$(echo "$video" | jq -r '.description' | sed -E 's/$/
/g')
"; - vid="$(cat "temp/${get_data[v]}_https_-_"*"watch"*".dump" | tr -d '\n' | grep -Poh "ytInitialData.*?" | sed 's/ytInitialData = //;s/<\/script>//')" - + vid="$(cat "temp/${get_data[v]}_https_-_"*"watch"*".dump")" + vid_json="$(tr -d '\n' <<< "$vid" | grep -Poh "ytInitialData.*?" | sed 's/ytInitialData = //;s/<\/script>//')" echo "

Recommended

" - jq -r '.contents.twoColumnWatchNextResults.secondaryResults.secondaryResults.results[] | .compactAutoplayRenderer.contents[0].compactVideoRenderer, .compactVideoRenderer | if .videoId != null then "
"+.title.simpleText+"
" else empty end' <<< "$vid" + jq -r '.contents.twoColumnWatchNextResults.secondaryResults.secondaryResults.results[] | .compactAutoplayRenderer.contents[0].compactVideoRenderer, .compactVideoRenderer | if .videoId != null then "
"+.title.simpleText+"
" else empty end' <<< "$vid_json" #for i in $(grep -ohE "watch\?v\=[A-zaz0-9]{11}" <<< "$vid" | cut -c 9-19 | uniq); do # echo "

"; #done + vid="$(curl -s "https://www.youtube.com/watch?v=LACbVhgtx9I" -c cookiejar_)" # broken comment support, we need this for now + echo "

Comments

" cont="$(echo "$vid" | grep -Poh 'continuation":".*?"' | sed -E 's/.*":"//g;s/"//g')" CSRF="$(echo "$vid" | grep -Poh 'XSRF_TOKEN":".*?"' | sed -E 's/XSRF_TOKEN":"//g;s/"//g;s/\\u00/%/g')" - comments="$(curl -s 'https://www.youtube.com/comment_service_ajax?action_get_comments=1&pbj=1&ctoken='"$cont"'&continuation='"$cont" -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)" + + comments="$(curl -vvv 'https://www.youtube.com/comment_service_ajax?action_get_comments=1&pbj=1&ctoken='"$cont"'&continuation='"$cont" -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")) @@ -108,7 +111,7 @@ if [[ "${get_data[v]}" ]]; then done if [[ "${get_data[playlist]}" ]]; then - playlist=$(haruhi-dl $([[ ${cfg[_cookies]} != "" ]] && echo -n -- "-c ${cfg[_cookies]}") -j --flat-playlist "https://www.youtube.com/playlist?list=${get_data[playlist]}") + playlist=$(haruhi-dl --cookies ${cfg[_cookies]} -j --flat-playlist "https://www.youtube.com/playlist?list=${get_data[playlist]}") IFS=$'\n' video_title=($(jq -r '.title' <<< $playlist))