From 71a821a7e65de56ba4816bb07380cebf9914c00a Mon Sep 17 00:00:00 2001 From: absidue <48293849+absidue@users.noreply.github.com> Date: Sat, 20 Apr 2024 18:50:17 +0200 Subject: [PATCH 1/4] Return actual height, width and fps for streams in /api/v1/videos --- src/invidious/jsonify/api_v1/video_json.cr | 75 ++++++++++++---------- 1 file changed, 42 insertions(+), 33 deletions(-) diff --git a/src/invidious/jsonify/api_v1/video_json.cr b/src/invidious/jsonify/api_v1/video_json.cr index 0dced80b..8c1f5c3c 100644 --- a/src/invidious/jsonify/api_v1/video_json.cr +++ b/src/invidious/jsonify/api_v1/video_json.cr @@ -114,25 +114,30 @@ module Invidious::JSONify::APIv1 json.field "projectionType", fmt["projectionType"] - if fmt_info = Invidious::Videos::Formats.itag_to_metadata?(fmt["itag"]) - fps = fmt_info["fps"]?.try &.to_i || fmt["fps"]?.try &.as_i || 30 + height = fmt["height"]?.try &.as_i + width = fmt["width"]?.try &.as_i + + fps = fmt["fps"]?.try &.as_i + + if fps json.field "fps", fps + end + + if height && width + json.field "size", "#{width}x#{height}" + + quality_label = "#{width > height ? height : width}" + + if fps && fps > 30 + quality_label += fps.to_s + end + + json.field "qualityLabel", quality_label + end + + if fmt_info = Invidious::Videos::Formats.itag_to_metadata?(fmt["itag"]) json.field "container", fmt_info["ext"] json.field "encoding", fmt_info["vcodec"]? || fmt_info["acodec"] - - if fmt_info["height"]? - json.field "resolution", "#{fmt_info["height"]}p" - - quality_label = "#{fmt_info["height"]}p" - if fps > 30 - quality_label += "60" - end - json.field "qualityLabel", quality_label - - if fmt_info["width"]? - json.field "size", "#{fmt_info["width"]}x#{fmt_info["height"]}" - end - end end # Livestream chunk infos @@ -163,26 +168,30 @@ module Invidious::JSONify::APIv1 json.field "bitrate", fmt["bitrate"].as_i.to_s if fmt["bitrate"]? - fmt_info = Invidious::Videos::Formats.itag_to_metadata?(fmt["itag"]) - if fmt_info - fps = fmt_info["fps"]?.try &.to_i || fmt["fps"]?.try &.as_i || 30 + height = fmt["height"]?.try &.as_i + width = fmt["width"]?.try &.as_i + + fps = fmt["fps"]?.try &.as_i + + if fps json.field "fps", fps + end + + if height && width + json.field "size", "#{width}x#{height}" + + quality_label = "#{width > height ? height : width}" + + if fps && fps > 30 + quality_label += fps.to_s + end + + json.field "qualityLabel", quality_label + end + + if fmt_info = Invidious::Videos::Formats.itag_to_metadata?(fmt["itag"]) json.field "container", fmt_info["ext"] json.field "encoding", fmt_info["vcodec"]? || fmt_info["acodec"] - - if fmt_info["height"]? - json.field "resolution", "#{fmt_info["height"]}p" - - quality_label = "#{fmt_info["height"]}p" - if fps > 30 - quality_label += "60" - end - json.field "qualityLabel", quality_label - - if fmt_info["width"]? - json.field "size", "#{fmt_info["width"]}x#{fmt_info["height"]}" - end - end end end end From f57aac5815e20bed2b495cb1994f4d8d50654b61 Mon Sep 17 00:00:00 2001 From: absidue <48293849+absidue@users.noreply.github.com> Date: Sun, 21 Apr 2024 14:58:12 +0200 Subject: [PATCH 2/4] Fix the missing `p` in the quality labels. Co-authored-by: Samantaz Fox --- src/invidious/jsonify/api_v1/video_json.cr | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/invidious/jsonify/api_v1/video_json.cr b/src/invidious/jsonify/api_v1/video_json.cr index 8c1f5c3c..7f17f35a 100644 --- a/src/invidious/jsonify/api_v1/video_json.cr +++ b/src/invidious/jsonify/api_v1/video_json.cr @@ -126,7 +126,7 @@ module Invidious::JSONify::APIv1 if height && width json.field "size", "#{width}x#{height}" - quality_label = "#{width > height ? height : width}" + quality_label = "#{width > height ? height : width}p" if fps && fps > 30 quality_label += fps.to_s @@ -180,7 +180,7 @@ module Invidious::JSONify::APIv1 if height && width json.field "size", "#{width}x#{height}" - quality_label = "#{width > height ? height : width}" + quality_label = "#{width > height ? height : width}p" if fps && fps > 30 quality_label += fps.to_s From 57e606cb43d43c627708f0538eddcde3b0f580a0 Mon Sep 17 00:00:00 2001 From: absidue <48293849+absidue@users.noreply.github.com> Date: Thu, 25 Apr 2024 21:38:51 +0200 Subject: [PATCH 3/4] Add back missing resolution field --- src/invidious/jsonify/api_v1/video_json.cr | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/invidious/jsonify/api_v1/video_json.cr b/src/invidious/jsonify/api_v1/video_json.cr index 7f17f35a..6e8c3a72 100644 --- a/src/invidious/jsonify/api_v1/video_json.cr +++ b/src/invidious/jsonify/api_v1/video_json.cr @@ -125,6 +125,7 @@ module Invidious::JSONify::APIv1 if height && width json.field "size", "#{width}x#{height}" + json.field "resolution" "#{height}p" quality_label = "#{width > height ? height : width}p" @@ -179,6 +180,7 @@ module Invidious::JSONify::APIv1 if height && width json.field "size", "#{width}x#{height}" + json.field "resolution" "#{height}p" quality_label = "#{width > height ? height : width}p" From 3b773c4f77c1469bcd158f7ab912fcb57af7b014 Mon Sep 17 00:00:00 2001 From: absidue <48293849+absidue@users.noreply.github.com> Date: Thu, 25 Apr 2024 21:51:19 +0200 Subject: [PATCH 4/4] Fix missing commas --- src/invidious/jsonify/api_v1/video_json.cr | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/invidious/jsonify/api_v1/video_json.cr b/src/invidious/jsonify/api_v1/video_json.cr index 6e8c3a72..59714828 100644 --- a/src/invidious/jsonify/api_v1/video_json.cr +++ b/src/invidious/jsonify/api_v1/video_json.cr @@ -125,7 +125,7 @@ module Invidious::JSONify::APIv1 if height && width json.field "size", "#{width}x#{height}" - json.field "resolution" "#{height}p" + json.field "resolution", "#{height}p" quality_label = "#{width > height ? height : width}p" @@ -180,7 +180,7 @@ module Invidious::JSONify::APIv1 if height && width json.field "size", "#{width}x#{height}" - json.field "resolution" "#{height}p" + json.field "resolution", "#{height}p" quality_label = "#{width > height ? height : width}p"