Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return actual height, width and fps for streams in /api/v1/videos #4586

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
69 changes: 40 additions & 29 deletions src/invidious/jsonify/api_v1/video_json.cr
Expand Up @@ -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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something's not right here, but I can't figure out what (from the video hxQwWEOOyU8 you provided):

{
  "size": "82x144",
  "qualityLabel": "82p",
  ...
  "size": "136x240",
  "qualityLabel": "136p",
  ...
  "size": "406x720",
  "qualityLabel": "406p",
  ...
  "size": "608x1080",
  "qualityLabel": "608p",
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is another vertical video you can try, with more normal dimensions: https://youtu.be/HgEiag5zZc0 (/api/v1/videos/HgEiag5zZc0)


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
Expand Down Expand Up @@ -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
Expand Down