summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSamantaz Fox <coding@samantaz.fr>2024-07-21 14:08:52 +0200
committerSamantaz Fox <coding@samantaz.fr>2024-07-21 17:23:50 +0200
commite62d4db752f2c11ff5e2c6bc573aae8047da8783 (patch)
tree9461f206dc008797f0dd306820512c5d1dcd611a /src
parent8b1da2001ea1ae7a8e86923c7ac0ec412979291d (diff)
parent3b773c4f77c1469bcd158f7ab912fcb57af7b014 (diff)
downloadinvidious-e62d4db752f2c11ff5e2c6bc573aae8047da8783.tar.gz
invidious-e62d4db752f2c11ff5e2c6bc573aae8047da8783.tar.bz2
invidious-e62d4db752f2c11ff5e2c6bc573aae8047da8783.zip
API: Return actual stream height, width and fps (#4586)
At the moment Invidious will return hardcoded data for the 'size', 'qualityLabel' and 'fps' fields for streams, when such hardcoded data is available, otherwise it just omits those fields from the response (e.g. with the AV1 formats). Those issues are especially noticable when Invidious claims that 50fps streams have 60fps and when it claims that the dimensions for a vertical video are landscape. The DASH manifests that Invidious generates already use the correct information. This pull request corrects that issue by returning the information that YouTube provides instead of hardcoded values and also fixes the long standing bug of Invidious claiming that audio streams have 30 fps. Here are two test cases: 50/25/13fps: https://youtu.be/GbXYZwUigCM (/api/v1/videos/GbXYZwUigCM) vertical video: https://youtu.be/hxQwWEOOyU8 (/api/v1/videos/hxQwWEOOyU8) Originally these problems were going to be solved by the complete refactor of stream handling in 3620, but as that pull request got closed by the stale bot over a month ago and has such a massive scope that it would require a massive amount of work to complete it, I decided to open this pull request that takes a less radical approach of just fixing bugs instead of a full on refactoring. FreeTube generates it's own DASH manifests instead of using Invidious' one, so that it can support multiple audio tracks and HDR. Unfortunately due to the missing and inaccurate information in the API responses, FreeTube has to request the DASH manifest from Invidious to extract the height, width and fps. With this pull request FreeTube could rely just on the API response, saving that extra request to the Invidious instance. It would also make it possible for FreeTube to use the vp9 streams with Invidious, which would reduce the load on the video proxies. Closes issue 4131
Diffstat (limited to 'src')
-rw-r--r--src/invidious/jsonify/api_v1/video_json.cr69
1 files changed, 40 insertions, 29 deletions
diff --git a/src/invidious/jsonify/api_v1/video_json.cr b/src/invidious/jsonify/api_v1/video_json.cr
index 0dced80b..59714828 100644
--- a/src/invidious/jsonify/api_v1/video_json.cr
+++ b/src/invidious/jsonify/api_v1/video_json.cr
@@ -114,25 +114,31 @@ 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
- json.field "container", fmt_info["ext"]
- json.field "encoding", fmt_info["vcodec"]? || fmt_info["acodec"]
+ end
- if fmt_info["height"]?
- json.field "resolution", "#{fmt_info["height"]}p"
+ if height && width
+ json.field "size", "#{width}x#{height}"
+ json.field "resolution", "#{height}p"
- quality_label = "#{fmt_info["height"]}p"
- if fps > 30
- quality_label += "60"
- end
- json.field "qualityLabel", quality_label
+ quality_label = "#{width > height ? height : width}p"
- if fmt_info["width"]?
- json.field "size", "#{fmt_info["width"]}x#{fmt_info["height"]}"
- end
+ 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"]
end
# Livestream chunk infos
@@ -163,26 +169,31 @@ 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
- json.field "container", fmt_info["ext"]
- json.field "encoding", fmt_info["vcodec"]? || fmt_info["acodec"]
+ end
- if fmt_info["height"]?
- json.field "resolution", "#{fmt_info["height"]}p"
+ if height && width
+ json.field "size", "#{width}x#{height}"
+ json.field "resolution", "#{height}p"
- quality_label = "#{fmt_info["height"]}p"
- if fps > 30
- quality_label += "60"
- end
- json.field "qualityLabel", quality_label
+ quality_label = "#{width > height ? height : width}p"
- if fmt_info["width"]?
- json.field "size", "#{fmt_info["width"]}x#{fmt_info["height"]}"
- end
+ 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"]
end
end
end