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

Show more videos and consolidate media logic #791

Closed
wants to merge 16 commits into from

Conversation

carloscheddar
Copy link

@carloscheddar carloscheddar commented Oct 17, 2023

Given a Lemmy post containing media this will try to display the content inside the app. This uses the existing image and video renderers and adds a new iframe for video embeds.

Features

  • Render videos via embed_video_url
  • Automatically transform media urls into one that we can render or embed (.gifv -> .mp4, etc.)
  • Allow rendering .mov urls as videos
  • Add error handling for images and videos as well as fallbacks
  • Consolidate media logic into a single Media component used by both PostDetail and LargePost
  • Add isUrlMedia to easily check for media instead of manually checking for image, video or embed
  • Add tests for the url helpers. Helps with the url transformations since these can increase

Fallbacks

  • When an image url fails to load try rendering the thumbnail instead
  • When a video fails to load via embed_video_url, try rendering the url
  • When everything fails to load, display the url

@aeharding
Copy link
Owner

Thanks for the PR! I'll take a look as soon as I can

@aeharding
Copy link
Owner

Hi there, thanks again for the PR!

So, I have a couple concerns about the approach taken in this PR.

  1. We should never load iframes to content such as YouTube in the app without the user requesting to do so (for example, by tapping a static preview picture). This is the approach that Mastodon takes, and its best for security and privacy.
  2. Ideally tapping the preview picture would bring up the lightbox with the same behavior that images have. This is what Apollo does. Note, Apollo doesn't load iframes in the app. It somehow extracts the Youtube video data and puts it into its own player. This is a much better experience, and better for privacy reasons, but may be hard to implement.

Overall this isn't the approach I'd like to take for Voyager, but I do appreciate your efforts here! Let me know if you have any questions on the above.

@carloscheddar
Copy link
Author

@aeharding I think your concerns about iframes are valid I even forgot to add the sandbox attribute! I'll remove the embed logic from this PR and revisit that in the future.

I think the biggest benefit of this PR is the consolidation and error handling for images and videos as well as being able to render video files from the embed_video_url that Lemmy provides.

Let me know if you have any comments on those.

@aeharding
Copy link
Owner

There was a previous PR playing with support for embed_video_url in the past, see here: https://github.com/aeharding/voyager/pull/571/files

The problem with that at the time was a lot of embed_video_url returned by lemmy is invalid, which is why Voyager doesn't support it at the moment. I don't remember why exactly, maybe browsers had trouble handling the media files. Might be worth checking again though

@carloscheddar carloscheddar changed the title Show videos and embeds inside the app when possible Show more videos and consolidate media logic Oct 27, 2023
@carloscheddar
Copy link
Author

carloscheddar commented Oct 27, 2023

There was a previous PR playing with support for embed_video_url in the past, see here: https://github.com/aeharding/voyager/pull/571/files

The problem with that at the time was a lot of embed_video_url returned by lemmy is invalid, which is why Voyager doesn't support it at the moment. I don't remember why exactly, maybe browsers had trouble handling the media files. Might be worth checking again though

Yup that was my previous PR, this fixes that issue thanks to the fallback logic via the onError events. I just went a little overboard and tried to add embeds too 😆 . Just finished removing those so this is ready for review again.

@aeharding
Copy link
Owner

I see, thanks!

This fixes issues with embed links that could've been rendered using the
Video component
This fixes an issue on the LargePost where image would try to render
broken thumbnails instead of the working image url.
- This fixes an issue where .gifv would not be considered a video
This checks and renders media types and in the case of videos will try
the embed url as well as the normal url if one fails to play.

Videos and images render with the gallery created for the LargePost component

Embeds are sized in a 16/9 ratio since we can't fetch their size with
this implementation.

Communicates errors to parent component via callback to hide media if it
fails to play.
- Remove embed url helpers
- Improve error handling on PostDetail
// Transform known video platform urls into their embed counterparts
export const transformUrl = (inputUrl: string): string => {
// If the URL contains gifv replace it with mp4 in order for the video to play inline
const url = inputUrl.replace(/\.gifv/g, ".mp4");
Copy link
Owner

Choose a reason for hiding this comment

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

Is this fixing a particular site or set of sites? I would like to avoid changing any instance of .gifv in the url, that feels quite dangerous.

@aeharding
Copy link
Owner

I am closing this because it has become stale and there have been various fixes made to the video player over the past month or so. Thank you though for the PR!

@aeharding aeharding closed this Dec 12, 2023
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