mirror of
https://github.com/iv-org/invidious.git
synced 2024-10-01 01:35:38 -04:00
Fix invalid viewCountText in related videos
This commit is contained in:
parent
3896230199
commit
512d82071e
@ -4867,7 +4867,6 @@ get "/videoplayback" do |env|
|
|||||||
host = "https://r#{fvip}---#{mn}.googlevideo.com"
|
host = "https://r#{fvip}---#{mn}.googlevideo.com"
|
||||||
client = make_client(URI.parse(host), region)
|
client = make_client(URI.parse(host), region)
|
||||||
rescue ex
|
rescue ex
|
||||||
pp ex
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -926,6 +926,33 @@ def get_video(id, db, refresh = true, region = nil, force_refresh = false)
|
|||||||
return video
|
return video
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def extract_recommended(recommended_videos)
|
||||||
|
rvs = [] of HTTP::Params
|
||||||
|
|
||||||
|
recommended_videos.try &.each do |compact_renderer|
|
||||||
|
if compact_renderer["compactRadioRenderer"]? || compact_renderer["compactPlaylistRenderer"]?
|
||||||
|
# TODO
|
||||||
|
elsif video_renderer = compact_renderer["compactVideoRenderer"]?
|
||||||
|
recommended_video = HTTP::Params.new
|
||||||
|
recommended_video["id"] = video_renderer["videoId"].as_s
|
||||||
|
recommended_video["title"] = video_renderer["title"]["simpleText"].as_s
|
||||||
|
recommended_video["author"] = video_renderer["shortBylineText"]["runs"].as_a[0]["text"].as_s
|
||||||
|
recommended_video["ucid"] = video_renderer["shortBylineText"]["runs"].as_a[0]["navigationEndpoint"]["browseEndpoint"]["browseId"].as_s
|
||||||
|
recommended_video["author_thumbnail"] = video_renderer["channelThumbnail"]["thumbnails"][0]["url"].as_s
|
||||||
|
|
||||||
|
if view_count = video_renderer["viewCountText"]?.try { |field| field["simpleText"]?.try &.as_s || field["runs"][0]?.try &.["text"].as_s }.try &.delete(", views watching").to_i64?.try &.to_s
|
||||||
|
recommended_video["view_count"] = view_count
|
||||||
|
recommended_video["short_view_count_text"] = "#{number_to_short_text(view_count.to_i64)} views"
|
||||||
|
end
|
||||||
|
recommended_video["length_seconds"] = decode_length_seconds(video_renderer["lengthText"]?.try &.["simpleText"]?.try &.as_s || "0:00").to_s
|
||||||
|
|
||||||
|
rvs << recommended_video
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
rvs
|
||||||
|
end
|
||||||
|
|
||||||
def extract_polymer_config(body, html)
|
def extract_polymer_config(body, html)
|
||||||
params = HTTP::Params.new
|
params = HTTP::Params.new
|
||||||
|
|
||||||
@ -956,34 +983,14 @@ def extract_polymer_config(body, html)
|
|||||||
params["ctoken"] = comment_continuation.try &.["continuation"]?.try &.as_s || ""
|
params["ctoken"] = comment_continuation.try &.["continuation"]?.try &.as_s || ""
|
||||||
params["itct"] = comment_continuation.try &.["clickTrackingParams"]?.try &.as_s || ""
|
params["itct"] = comment_continuation.try &.["clickTrackingParams"]?.try &.as_s || ""
|
||||||
|
|
||||||
recommended_videos = initial_data["contents"]?
|
rvs = initial_data["contents"]?
|
||||||
.try &.["twoColumnWatchNextResults"]?
|
.try &.["twoColumnWatchNextResults"]?
|
||||||
.try &.["secondaryResults"]?
|
.try &.["secondaryResults"]?
|
||||||
.try &.["secondaryResults"]?
|
.try &.["secondaryResults"]?
|
||||||
.try &.["results"]?
|
.try &.["results"]?
|
||||||
.try &.as_a
|
.try &.as_a
|
||||||
|
|
||||||
rvs = [] of String
|
params["rvs"] = extract_recommended(rvs).join(",")
|
||||||
|
|
||||||
recommended_videos.try &.each do |compact_renderer|
|
|
||||||
if compact_renderer["compactRadioRenderer"]? || compact_renderer["compactPlaylistRenderer"]?
|
|
||||||
# TODO
|
|
||||||
elsif video_renderer = compact_renderer["compactVideoRenderer"]?
|
|
||||||
recommended_video = HTTP::Params.new
|
|
||||||
recommended_video["id"] = video_renderer["videoId"].as_s
|
|
||||||
recommended_video["title"] = video_renderer["title"]["simpleText"].as_s
|
|
||||||
recommended_video["author"] = video_renderer["shortBylineText"]["runs"].as_a[0]["text"].as_s
|
|
||||||
recommended_video["ucid"] = video_renderer["shortBylineText"]["runs"].as_a[0]["navigationEndpoint"]["browseEndpoint"]["browseId"].as_s
|
|
||||||
recommended_video["author_thumbnail"] = video_renderer["channelThumbnail"]["thumbnails"][0]["url"].as_s
|
|
||||||
|
|
||||||
recommended_video["short_view_count_text"] = video_renderer["shortViewCountText"]?.try { |field| field["simpleText"]?.try &.as_s || field["runs"].as_a.map { |text| text["text"].as_s }.join("") } || "0"
|
|
||||||
recommended_video["view_count"] = video_renderer["viewCountText"]?.try { |field| field["simpleText"]?.try &.as_s || field["runs"].as_a.map { |text| text["text"].as_s }.join("") }.try &.delete(", views watching").to_i64?.try &.to_s || "0"
|
|
||||||
recommended_video["length_seconds"] = decode_length_seconds(video_renderer["lengthText"]?.try &.["simpleText"]?.try &.as_s || "0:00").to_s
|
|
||||||
|
|
||||||
rvs << recommended_video.to_s
|
|
||||||
end
|
|
||||||
end
|
|
||||||
params["rvs"] = rvs.join(",")
|
|
||||||
|
|
||||||
# TODO: Watching now
|
# TODO: Watching now
|
||||||
params["views"] = primary_results.try &.as_a.select { |object| object["videoPrimaryInfoRenderer"]? }[0]?
|
params["views"] = primary_results.try &.as_a.select { |object| object["videoPrimaryInfoRenderer"]? }[0]?
|
||||||
@ -1095,37 +1102,29 @@ def extract_player_config(body, html)
|
|||||||
|
|
||||||
if md = body.match(/'RELATED_PLAYER_ARGS': (?<json>.*?),\n/)
|
if md = body.match(/'RELATED_PLAYER_ARGS': (?<json>.*?),\n/)
|
||||||
recommended_json = JSON.parse(md["json"])
|
recommended_json = JSON.parse(md["json"])
|
||||||
|
rvs_params = recommended_json["rvs"].as_s.split(",").map { |params| HTTP::Params.parse(params) }
|
||||||
|
|
||||||
if watch_next_response = recommended_json["watch_next_response"]?
|
if watch_next_response = recommended_json["watch_next_response"]?
|
||||||
rvs = [] of String
|
|
||||||
watch_next_json = JSON.parse(watch_next_response.as_s)
|
watch_next_json = JSON.parse(watch_next_response.as_s)
|
||||||
recommended_videos = watch_next_json["contents"]?
|
rvs = watch_next_json["contents"]?
|
||||||
.try &.["twoColumnWatchNextResults"]?
|
.try &.["twoColumnWatchNextResults"]?
|
||||||
.try &.["secondaryResults"]?
|
.try &.["secondaryResults"]?
|
||||||
.try &.["secondaryResults"]?
|
.try &.["secondaryResults"]?
|
||||||
.try &.["results"]?
|
.try &.["results"]?
|
||||||
.try &.as_a
|
.try &.as_a
|
||||||
|
|
||||||
recommended_videos.try &.each do |compact_renderer|
|
rvs = extract_recommended(rvs)
|
||||||
if compact_renderer["compactRadioRenderer"]? || compact_renderer["compactPlaylistRenderer"]?
|
rvs.each_with_index do |rv, i|
|
||||||
# TODO
|
if !rv["view_count"]?
|
||||||
elsif video_renderer = compact_renderer["compactVideoRenderer"]?
|
rv_params = rvs_params.select { |rv_params| rv_params["id"] == rv["id"] }[0]?
|
||||||
recommended_video = HTTP::Params.new
|
if rv_params
|
||||||
recommended_video["id"] = video_renderer["videoId"].as_s
|
rvs[i]["short_view_count_text"] = rv_params["short_view_count_text"]
|
||||||
recommended_video["title"] = video_renderer["title"]["simpleText"].as_s
|
else
|
||||||
recommended_video["author"] = video_renderer["shortBylineText"]["runs"].as_a[0]["text"].as_s
|
rvs.delete_at(i)
|
||||||
recommended_video["ucid"] = video_renderer["shortBylineText"]["runs"].as_a[0]["navigationEndpoint"]["browseEndpoint"]["browseId"].as_s
|
|
||||||
recommended_video["author_thumbnail"] = video_renderer["channelThumbnail"]["thumbnails"][0]["url"].as_s
|
|
||||||
|
|
||||||
recommended_video["short_view_count_text"] = video_renderer["shortViewCountText"]?.try { |field| field["simpleText"]?.try &.as_s || field["runs"].as_a.map { |text| text["text"].as_s }.join("") } || "0"
|
|
||||||
recommended_video["view_count"] = video_renderer["viewCountText"]?.try { |field| field["simpleText"]?.try &.as_s || field["runs"].as_a.map { |text| text["text"].as_s }.join("") }.try &.delete(", views watching").to_i64?.try &.to_s || "0"
|
|
||||||
recommended_video["length_seconds"] = decode_length_seconds(video_renderer["lengthText"]?.try &.["simpleText"]?.try &.as_s || "0:00").to_s
|
|
||||||
|
|
||||||
rvs << recommended_video.to_s
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
params["rvs"] = rvs.join(",")
|
end
|
||||||
elsif recommended_json["rvs"]?
|
params["rvs"] = (rvs.map &.to_s).join(",")
|
||||||
params["rvs"] = recommended_json["rvs"].as_s
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user