#!/bin/bash if [[ ! -d "temp" ]]; then mkdir "temp" fi declare -A strings if [[ ! "$(which haruhi-dl)" ]]; then strings[error]='Could not load video' source templates/head.sh source "${cfg[namespace]}/templates/header.shs" render strings "${cfg[namespace]}/templates/themes/${cfg[template]}/watch_error.t" return fi if [[ "${get_data[v]}" ]]; then if [[ "${get_data[v]}" == '18l' || "${get_data[v]}" == '5eFdt6Y_34E' ]]; then strings[uploader]='MyMusicGroup' strings[title]='█▬█ █ ▀█▀ Jeden Osiem L - Jak Zapomnieć (Oficjalny Teledysk)' formats='[{ "format_id": "44", "url": "https://sakamoto.pl/tmp/videoplayback_.webm", "asr": 44100, "format_note": "480p", "fps": 25, "height": 480, "tbr": 867, "width": 640, "ext": "webm", "vcodec": "vp8", "acodec": "vorbis" }]' if [[ "${r[host]}" == "${cfg[flash_host]}" ]]; then url='http://f.sakamoto.pl/videoplayback_.flv' fi if [[ ${cfg[template]} == 'default' ]]; then meta[title]="${strings[title]}" source templates/head.sh fi else cd temp video=$(haruhi-dl --ie-key Youtube --write-pages --cookies "${cfg[_cookies]}" -J "http://youtube.com/watch?v=${get_data[v]}") if [[ $video == '' ]]; then # okay who did this random_hash=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 24 | head -n 1) video=$(haruhi-dl --ie-key Youtube --write-pages --cookies ${cfg[_cookies]} -J "http://youtube.com/watch?v=${get_data[v]}" 2> output$random_hash.log) if [[ $video == '' ]]; then # seriously WHO DID THIS if [[ "${cfg[regionlock_proxy]}" == true ]]; then # retrying w/ proxy! video=$(haruhi-dl --ie-key Youtube --write-pages --cookies ${cfg[_cookies]} --proxy "${cfg[regionlock_proxy_url]}" -J "http://youtube.com/watch?v=${get_data[v]}" 2> output$random_hash.log) fi output=$(cat output$random_hash.log) rm output$random_hash.log if [[ $video == '' ]]; then if [[ $output == 'ERROR: Video unavailable' ]]; then strings[error]='Video unavailable' elif [[ $output == *'ERROR: Incomplete YouTube ID'* ]]; then strings[error]='Incomplete YouTube ID' else strings[error]='Unexpected error has occured' fi cd .. source templates/head.sh source "${cfg[namespace]}/templates/header.shs" render strings "${cfg[namespace]}/templates/themes/${cfg[template]}/watch_error.t" return fi fi fi cd .. #echo "http://youtube.com/watch?v=${get_data[v]}" > /dev/stderr strings[channel_id]=$(jq -r '.channel_url' <<< "$video" | sed -s 's/http:\/\/www.youtube.com\/channel\///') strings[uploader]=$(jq -r '.uploader' <<< "$video") strings[title]=$(jq -r '.title' <<< "$video") if [[ ${cfg[template]} == 'default' ]]; then meta[title]="${strings[title]}" meta[description]="$(jq -r '.description' <<< "$video")" meta[unsafe]=" "'' source templates/head.sh fi formats=$(jq -c '[.formats[] | select(.protocol == "https") | {"format_id":.format_id,"url":.url,"ext":.ext,"width":.width,"height":.height,"acodec":.acodec,"vcodec":.vcodec,"abr":.abr,"fps":.fps}]' <<< "$video") fi if [[ "${r[host]}" == "${cfg[flash_host]}" ]]; then IFS=$'\n' urls=($(jq -r '.formats[] | select(.format_id == "22" or .format_id == "18").url' <<< "$video")) unset IFS if [[ "$url" == '' ]]; then if [[ ${urls[1]} != '' ]]; then url=${urls[1]} else url=${urls[0]} fi fi strings[player]=$(source "${cfg[namespace]}/webroot/player_flash.shs") else strings[player]=$(source "${cfg[namespace]}/webroot/player.shs") fi strings[upload_date]=$(date -d "$(echo $video | jq -r '.upload_date' | sed -E 's/..../&-/;s/....-../&-/')" "+%d %B %Y") strings[view_count]=$(echo $video | jq -r '.view_count' | xargs printf "%'d\n") like_count=$(echo $video | jq -r '.like_count' | xargs printf "%'d\n") dislike_count=$(echo $video | jq -r '.dislike_count' | xargs printf "%'d\n") if [[ ${cfg[template]} == 'default' ]]; then if [[ $like_count == 'null' && $dislike_count == 'null' ]]; then strings[like_dislike_count]="Likes are turned off" else strings[like_dislike_count]="$like_count likes, $dislike_count dislikes." fi fi strings[sub]='' # if [[ ${cookies[sh_session]} ]]; then if [[ $(grep $(session_get_username "${cookies[sh_session]}") storage/faves | grep "${get_data[v]}") == '' ]]; then if [[ ${cfg[template]} == 'default' ]]; then strings[fav]="Add to favourites
" fi else if [[ ${cfg[template]} == 'default' ]]; then strings[fav]="Remove from favourites
" fi fi if [[ $(grep $(session_get_username "${cookies[sh_session]}") storage/subscribed | grep "${strings[channel_id]}") == '' ]]; then if [[ ${cfg[template]} == 'default' ]]; then strings[sub]="Subscribe to ${strings[uploader]}!
" fi else if [[ ${cfg[template]} == 'default' ]]; then strings[sub]="Unsubscribe from ${strings[uploader]}
" fi fi else if [[ ${cfg[template]} == 'default' ]]; then strings[fav]="Log in to add this video to your favourites and/or subscribe to this channel!
" fi fi strings[description]=$(jq -r '.description' <<< "$video" | sed -E 's/$/
/g') vid="$(cat "temp/${get_data[v]}_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") 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 '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 "
${comment_nick[$i]} | ${comment_published[$i]} | ${comment_likes[$i]} liked
${comment_text[$i]}

") done strings[playlist]="" if [[ "${get_data[playlist]}" ]]; then playlist=$(haruhi-dl --ie-key YoutubePlaylist --cookies ${cfg[_cookies]} -j --flat-playlist "https://www.youtube.com/playlist?list=${get_data[playlist]}") IFS=$'\n' video_title=($(jq -r '.title' <<< $playlist)) video_id=($(jq -r '.id' <<< $playlist)) for (( i=0; i<${#video_id[@]}; i++ )); do if [[ "${video_id[$i]}" == "${get_data[v]}" ]]; then next="${video_id[$((i+1))]}" break fi done [[ "$next" == '' ]] && next='dQw4w9WgXcQ' strings[playlist]+="

Playlist

" for (( i=0; i<${#video_id[@]}; i++ )); do strings[playlist]+="
${video_title[$i]}

" done fi if [[ ! "${strings[recommended]}" ]]; then strings[recommended]='An error occurred during fetching recommended videos' fi if [[ ! "${strings[comments_list]}" ]]; then strings[comments_list]='An error ocurred during fetching comments.' fi source "${cfg[namespace]}/templates/header.shs" render_unsafe strings "${cfg[namespace]}/templates/themes/${cfg[template]}/watch.t" else source templates/head.sh echo "pls add ?v param i'm still WiP" fi