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

#1425: Use Open Graph to determine video orientation in HTML #1526

Merged
merged 4 commits into from
Sep 24, 2024

Conversation

joshuatbrown
Copy link
Contributor

Issues covered

#1425

Description

Maybe the last of #1425. This uses Open Graph to determine video orientation in HTML. Works for things like YouTube videos where there's an HTML document at the URL. For example: https://www.youtube.com/shorts/ZwlBxvnH-So

That's a YouTube short, and it should appear in portrait orientation in Nos because its height is greater than its width, as determined by the meta tags containing the Open Graph properties.

We can't do this for things like note16rs86sh4peyqu6gtppw2y4j88z0nrcmupeefnj5flnwxp3fzdfuqsln02y because it contains a direct link to a mp4 video, rather than a link to an HTML document.

How to test

  1. Enable new media display in Settings
  2. Navigate to a note with a YouTube video link to a portrait video. Here's one: note1awmfrttfmuqecqvxhstwpad88n3gk66f6zwy3xq88dnmaw0xqmgsga9q3r
  3. Observe that the video displays in portrait orientation inside of the note.
  4. Navigate to a note with a YouTube video link to a landscape video. Here's one: note12vlzgjvluewmf92ylxcuqdtqv70n0u6t5jqykj8u43kysf0kds4qmrwtt2
  5. Observe that the video displays in landscape orientation inside of the note.
  6. Navigate to a note with a link to a video on Nostr.build, which should end in .mp4. Here's one: note14h3u9pseydfpsxzwzqtr3uc6k5th4nhqwtf8fyuc2wpgud6zsvkqmhgdmd
  7. Observe that nothing special happens. Its type is video/mp4, so there's no Open Graph metadata.

Screenshots/Video

Simulator.Screen.Recording.-.iPhone.SE.3rd.generation.-.2024-09-19.at.18.13.19.mp4

Notes

There's some complexity in the logic here. Open Graph is a fallback; if the Nostr event contains imeta tags, those will be used and we won't fetch the Open Graph data. This is all to say: if you want to test this well, make sure your notes don't contain imeta tags. Nos doesn't post imeta tags (yet!), but Damus does. So post your test notes from Nos.

Copy link
Member

@mplorentz mplorentz left a comment

Choose a reason for hiding this comment

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

This looks great! I had one optional comment. Also I had two concerns that aren't directly related to this PR or ticket but I am reporting them here anyway:

  • Should we use OpenGraph metada for images orientation to? At least when we are rendering an image as a preview of an html page. I don't see a ticket for rendering opengraph previews of generic links, is that work not planned?
  • ok the other thing is a bug I found that happens with the old media viewer. Will report it separately.

XCTAssertEqual(mockParser.metadataCallCount, 1)
}

func test_fetchMetadata_when_content_is_mp4_does_not_call_parser() async throws {
Copy link
Member

Choose a reason for hiding this comment

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

Would it be easy to add a test that the user agent is set correctly? That seems like something that could get lost in a refactor.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

@joshuatbrown
Copy link
Contributor Author

  • Should we use OpenGraph metada for images orientation to? At least when we are rendering an image as a preview of an html page. I don't see a ticket for rendering opengraph previews of generic links, is that work not planned?

I'm open to it, but it looks like we don't have a ticket, probably because I edited others and failed to include a new one to cover this. There's a user story for it as well as a design in Figma, so I'll create a new ticket.

@joshuatbrown
Copy link
Contributor Author

@mplorentz #1539 covers the last part of this.

@joshuatbrown
Copy link
Contributor Author

Merging since this was approved and I made the requested changes.

@joshuatbrown joshuatbrown added this pull request to the merge queue Sep 24, 2024
Merged via the queue into main with commit 16e148b Sep 24, 2024
4 checks passed
@joshuatbrown joshuatbrown deleted the open-graph-determine-orientation branch September 24, 2024 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants