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

Embed Rumble Video #1191

Merged
merged 9 commits into from
May 28, 2024
Merged

Conversation

tsmith123
Copy link
Contributor

@tsmith123 tsmith123 commented May 26, 2024

Fixes #134

Description

This PR allows embedding of Rumble videos (using specific embed link). It also adds a util function that:

  • helps to clean up some existing code including hard to read regexes
  • uses the URL constructor for more reliable parsing of embed urls
  • makes code reusable so both text and item-full component can use it

Testing Notes

Rumble embed links have been tested (https://rumble.com/embed/12345/?pub=4)
YouTube traditional links have been tested (https://www.youtube.com/watch?v=12345)
YouTube short links have been tested (https://youtu.be/12345)
YouTube links with a start time have been tested (https://youtu.be/12345?feature=shared&t=30

Screenshots

Editor View
Screenshot 2024-05-26 at 10 03 49

Screenshot 2024-05-26 at 10 03 55

Screenshot 2024-05-26 at 10 04 22

Limitations

Rumble videos can only be embedded using the embed url specifically and not the video's webpage url. This is something that has been raised a few times already in different discussions so I won't go in to detail again.

There was a suggestion to use domino or something similar to make a request from the backend to the get the details required to support using webpage url like we do for autofilling titles etc. However, this wouldn't work because in the autofill scenario the request is done once and the title can be stored in the database. We don't really have that option for embed links and would make the whole process very messy.

I don't see a way around this unless Rumble starts adding the video id into the webpage url which might never happen. Still think embedding videos using the official embed link is a win though.

Questions

I noticed that Tweets (or should they be called Xs now 😄 ) are supported in the item-full.js component but not the text.js component. Is this intentional?

Notes

I've not tackled X/Twitter embeds as part of this PR.

Copy link
Contributor

coderabbitai bot commented May 26, 2024

Walkthrough

The changes introduce support for embedding Rumble videos alongside existing YouTube and Twitter embeds. This includes adding a new function parseEmbedUrl for URL parsing, updating CSS classes for video containers, and modifying the Content Security Policy to allow Rumble embeds.

Changes

Files Change Summary
components/item-full.js Added parseEmbedUrl import, refactored embed handling, added Rumble support.
components/text.js Added parseEmbedUrl for handling YouTube and Rumble embeds.
components/text.module.css Renamed .youtubeContainer to .videoContainer.
lib/url.js Added parseEmbedUrl for parsing YouTube and Rumble URLs.
middleware.js Updated CSP frame-src directive to include rumble.com.
styles/item.module.css Renamed classes for video elements, adjusted styling.

Sequence Diagram(s) (Beta)

sequenceDiagram
    participant User
    participant Frontend
    participant Backend
    User->>Frontend: Submit URL
    Frontend->>Backend: Parse URL with parseEmbedUrl
    Backend->>Frontend: Return embed details
    Frontend->>User: Display embedded video
Loading

Assessment against linked issues

Objective (Issue #) Addressed Explanation
Support for Rumble video embedding (#134)
Handling of YouTube and Twitter embeds (#134)

Tip

Early Access Features
  • gpt-4o model for chat

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to full the review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@tsmith123
Copy link
Contributor Author

Adding @benalleng

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

@@ -42,7 +42,7 @@ export function middleware (request) {
// unsafe-inline for styles is not ideal but okay if script-src is using nonces
"style-src 'self' a.stacker.news 'unsafe-inline'",
"manifest-src 'self'",
'frame-src www.youtube.com platform.twitter.com',
'frame-src www.youtube.com platform.twitter.com rumble.com',
Copy link
Contributor

Choose a reason for hiding this comment

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

Adding rumble.com to the CSP is necessary for embedding Rumble videos. Consider using template literals for consistency with other parts of the CSP.

- 'frame-src www.youtube.com platform.twitter.com rumble.com',
+ `frame-src www.youtube.com platform.twitter.com rumble.com`,

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
'frame-src www.youtube.com platform.twitter.com rumble.com',
`frame-src www.youtube.com platform.twitter.com rumble.com`,

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Outside diff range and nitpick comments (3)
lib/url.js (3)

Line range hint 3-5: Avoid reassigning function parameters and use template literals for string operations.

-  value = value.trim()
-  if (!/^([a-z0-9]+:\/\/|mailto:)/.test(value)) {
-    value = 'http://' + value
+  const trimmedValue = value.trim()
+  if (!/^([a-z0-9]+:\/\/|mailto:)/.test(trimmedValue)) {
+    return `http://${trimmedValue}`
+  }
+  return trimmedValue

Line range hint 21-21: Avoid reassigning function parameters to maintain clarity and prevent side effects.

-  value = expr.exec(value)?.groups.url ?? value
+  const newValue = expr.exec(value)?.groups.url ?? value
+  return newValue

Line range hint 101-101: Avoid reassigning function parameters to maintain clarity and prevent side effects.

-  walletConnectUrl = walletConnectUrl
+  const cleanedWalletConnectUrl = walletConnectUrl

lib/url.js Outdated
Comment on lines 55 to 92
export function parseEmbedUrl (href) {
const { hostname, pathname, searchParams } = new URL(href)

if (hostname.includes('youtube.com/watch')) {
return {
provider: 'youtube',
id: searchParams.get('v'),
meta: {
href,
start: searchParams.get('t')
}
}
}

if (hostname.includes('youtu.be/')) {
return {
provider: 'youtube',
id: pathname.slice(1), // remove leading slash
meta: {
href,
start: searchParams.get('t')
}
}
}

if (hostname.includes('rumble.com/embed')) {
return {
provider: 'rumble',
id: null, // not required
meta: {
href
}
}
}

// Important to return empty object as default
return {}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Great implementation of parseEmbedUrl. Consider enhancing the default return value for better error handling or debugging.

-  return {}
+  return { error: 'Unsupported video provider' }

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
export function parseEmbedUrl (href) {
const { hostname, pathname, searchParams } = new URL(href)
if (hostname.includes('youtube.com/watch')) {
return {
provider: 'youtube',
id: searchParams.get('v'),
meta: {
href,
start: searchParams.get('t')
}
}
}
if (hostname.includes('youtu.be/')) {
return {
provider: 'youtube',
id: pathname.slice(1), // remove leading slash
meta: {
href,
start: searchParams.get('t')
}
}
}
if (hostname.includes('rumble.com/embed')) {
return {
provider: 'rumble',
id: null, // not required
meta: {
href
}
}
}
// Important to return empty object as default
return {}
}
export function parseEmbedUrl (href) {
const { hostname, pathname, searchParams } = new URL(href)
if (hostname.includes('youtube.com/watch')) {
return {
provider: 'youtube',
id: searchParams.get('v'),
meta: {
href,
start: searchParams.get('t')
}
}
}
if (hostname.includes('youtu.be/')) {
return {
provider: 'youtube',
id: pathname.slice(1), // remove leading slash
meta: {
href,
start: searchParams.get('t')
}
}
}
if (hostname.includes('rumble.com/embed')) {
return {
provider: 'rumble',
id: null, // not required
meta: {
href
}
}
}
// Important to return empty object as default
return { error: 'Unsupported video provider' }
}

@huumn
Copy link
Member

huumn commented May 28, 2024

Code looks great. I'll QA first thing tomorrow

@huumn huumn merged commit 52f57f8 into stackernews:master May 28, 2024
6 checks passed
@huumn huumn mentioned this pull request May 28, 2024
@tsmith123 tsmith123 deleted the 981-embed-rumble-video branch November 21, 2024 08:47
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.

Rumble video embed like what was added for Youtube
2 participants