aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/invidious.cr4
-rw-r--r--src/invidious/videos.cr37
-rw-r--r--src/invidious/views/embed.ecr2
-rw-r--r--src/invidious/views/watch.ecr2
4 files changed, 30 insertions, 15 deletions
diff --git a/src/invidious.cr b/src/invidious.cr
index b560fcb9..315363d7 100644
--- a/src/invidious.cr
+++ b/src/invidious.cr
@@ -3649,7 +3649,7 @@ get "/api/v1/top" do |env|
3649 generate_thumbnails(json, video.id, config, Kemal.config) 3649 generate_thumbnails(json, video.id, config, Kemal.config)
3650 end 3650 end
3651 3651
3652 json.field "lengthSeconds", video.info["length_seconds"].to_i 3652 json.field "lengthSeconds", video.length_seconds
3653 json.field "viewCount", video.views 3653 json.field "viewCount", video.views
3654 3654
3655 json.field "author", video.author 3655 json.field "author", video.author
@@ -4494,7 +4494,7 @@ get "/api/manifest/dash/id/:id" do |env|
4494 XML.build(indent: " ", encoding: "UTF-8") do |xml| 4494 XML.build(indent: " ", encoding: "UTF-8") do |xml|
4495 xml.element("MPD", "xmlns": "urn:mpeg:dash:schema:mpd:2011", 4495 xml.element("MPD", "xmlns": "urn:mpeg:dash:schema:mpd:2011",
4496 "profiles": "urn:mpeg:dash:profile:full:2011", minBufferTime: "PT1.5S", type: "static", 4496 "profiles": "urn:mpeg:dash:profile:full:2011", minBufferTime: "PT1.5S", type: "static",
4497 mediaPresentationDuration: "PT#{video.info["length_seconds"]}S") do 4497 mediaPresentationDuration: "PT#{video.length_seconds}S") do
4498 xml.element("Period") do 4498 xml.element("Period") do
4499 i = 0 4499 i = 0
4500 4500
diff --git a/src/invidious/videos.cr b/src/invidious/videos.cr
index 41bf70df..7e2e0f5a 100644
--- a/src/invidious/videos.cr
+++ b/src/invidious/videos.cr
@@ -329,7 +329,7 @@ struct Video
329 329
330 json.field "subCountText", self.sub_count_text 330 json.field "subCountText", self.sub_count_text
331 331
332 json.field "lengthSeconds", self.info["length_seconds"].to_i 332 json.field "lengthSeconds", self.length_seconds
333 json.field "allowRatings", self.allow_ratings 333 json.field "allowRatings", self.allow_ratings
334 json.field "rating", self.info["avg_rating"].to_f32 334 json.field "rating", self.info["avg_rating"].to_f32
335 json.field "isListed", self.is_listed 335 json.field "isListed", self.is_listed
@@ -563,7 +563,14 @@ struct Video
563 fmt["clen"] = fmt_stream["contentLength"]?.try &.as_s || "0" 563 fmt["clen"] = fmt_stream["contentLength"]?.try &.as_s || "0"
564 fmt["bitrate"] = fmt_stream["bitrate"]?.try &.as_i.to_s || "0" 564 fmt["bitrate"] = fmt_stream["bitrate"]?.try &.as_i.to_s || "0"
565 fmt["itag"] = fmt_stream["itag"].as_i.to_s 565 fmt["itag"] = fmt_stream["itag"].as_i.to_s
566 fmt["url"] = fmt_stream["url"].as_s 566 if fmt_stream["url"]?
567 fmt["url"] = fmt_stream["url"].as_s
568 end
569 if fmt_stream["cipher"]?
570 HTTP::Params.parse(fmt_stream["cipher"].as_s).each do |key, value|
571 fmt[key] = value
572 end
573 end
567 fmt["quality"] = fmt_stream["quality"].as_s 574 fmt["quality"] = fmt_stream["quality"].as_s
568 575
569 if fmt_stream["width"]? 576 if fmt_stream["width"]?
@@ -635,8 +642,14 @@ struct Video
635 fmt["clen"] = adaptive_fmt["contentLength"]?.try &.as_s || "0" 642 fmt["clen"] = adaptive_fmt["contentLength"]?.try &.as_s || "0"
636 fmt["bitrate"] = adaptive_fmt["bitrate"]?.try &.as_i.to_s || "0" 643 fmt["bitrate"] = adaptive_fmt["bitrate"]?.try &.as_i.to_s || "0"
637 fmt["itag"] = adaptive_fmt["itag"].as_i.to_s 644 fmt["itag"] = adaptive_fmt["itag"].as_i.to_s
638 fmt["url"] = adaptive_fmt["url"].as_s 645 if adaptive_fmt["url"]?
639 646 fmt["url"] = adaptive_fmt["url"].as_s
647 end
648 if adaptive_fmt["cipher"]?
649 HTTP::Params.parse(adaptive_fmt["cipher"].as_s).each do |key, value|
650 fmt[key] = value
651 end
652 end
640 if index = adaptive_fmt["indexRange"]? 653 if index = adaptive_fmt["indexRange"]?
641 fmt["index"] = "#{index["start"]}-#{index["end"]}" 654 fmt["index"] = "#{index["start"]}-#{index["end"]}"
642 end 655 end
@@ -827,7 +840,7 @@ struct Video
827 end 840 end
828 841
829 def length_seconds 842 def length_seconds
830 return self.info["length_seconds"].to_i 843 self.player_response["videoDetails"]["lengthSeconds"].as_s.to_i
831 end 844 end
832 845
833 db_mapping({ 846 db_mapping({
@@ -1162,17 +1175,19 @@ def fetch_video(id, region)
1162 end 1175 end
1163 end 1176 end
1164 1177
1165 if info["errorcode"]?.try &.== "2" 1178 if info["errorcode"]?.try &.== "2" || !info["player_response"]
1166 raise "Video unavailable." 1179 raise "Video unavailable."
1167 end 1180 end
1168 1181
1169 if !info["title"]? || info["title"].empty? 1182 if info["reason"]?
1170 raise "Video unavailable." 1183 raise info["reason"]
1171 end 1184 end
1172 1185
1173 title = info["title"] 1186 player_json = JSON.parse(info["player_response"])
1174 author = info["author"]? || "" 1187
1175 ucid = info["ucid"]? || "" 1188 title = player_json["videoDetails"]["title"].as_s
1189 author = player_json["videoDetails"]["author"]?.try &.as_s || ""
1190 ucid = player_json["videoDetails"]["ucid"]?.try &.as_s || ""
1176 1191
1177 views = html.xpath_node(%q(//meta[@itemprop="interactionCount"])) 1192 views = html.xpath_node(%q(//meta[@itemprop="interactionCount"]))
1178 .try &.["content"].to_i64? || 0_i64 1193 .try &.["content"].to_i64? || 0_i64
diff --git a/src/invidious/views/embed.ecr b/src/invidious/views/embed.ecr
index 9a8a3262..1a253026 100644
--- a/src/invidious/views/embed.ecr
+++ b/src/invidious/views/embed.ecr
@@ -30,7 +30,7 @@
30var video_data = { 30var video_data = {
31 id: '<%= video.id %>', 31 id: '<%= video.id %>',
32 plid: '<%= plid %>', 32 plid: '<%= plid %>',
33 length_seconds: '<%= video.info["length_seconds"].to_f %>', 33 length_seconds: '<%= video.length_seconds.to_f %>',
34 video_series: <%= video_series.to_json %>, 34 video_series: <%= video_series.to_json %>,
35 params: <%= params.to_json %>, 35 params: <%= params.to_json %>,
36 preferences: <%= preferences.to_json %>, 36 preferences: <%= preferences.to_json %>,
diff --git a/src/invidious/views/watch.ecr b/src/invidious/views/watch.ecr
index a1239383..f8882c6e 100644
--- a/src/invidious/views/watch.ecr
+++ b/src/invidious/views/watch.ecr
@@ -30,7 +30,7 @@
30var video_data = { 30var video_data = {
31 id: '<%= video.id %>', 31 id: '<%= video.id %>',
32 plid: '<%= plid %>', 32 plid: '<%= plid %>',
33 length_seconds: <%= video.info["length_seconds"].to_f %>, 33 length_seconds: <%= video.length_seconds.to_f %>,
34 play_next: <%= !rvs.empty? && !plid && params.continue %>, 34 play_next: <%= !rvs.empty? && !plid && params.continue %>,
35 next_video: '<%= rvs.select { |rv| rv["id"]? }[0]?.try &.["id"] %>', 35 next_video: '<%= rvs.select { |rv| rv["id"]? }[0]?.try &.["id"] %>',
36 youtube_comments_text: '<%= HTML.escape(translate(locale, "View YouTube comments")) %>', 36 youtube_comments_text: '<%= HTML.escape(translate(locale, "View YouTube comments")) %>',