Skip to content

Support for video playback through fallback#287

Merged
n-ce merged 16 commits into
mainfrom
n-ce-patch-1
Feb 27, 2025
Merged

Support for video playback through fallback#287
n-ce merged 16 commits into
mainfrom
n-ce-patch-1

Conversation

@n-ce
Copy link
Copy Markdown
Owner

@n-ce n-ce commented Feb 27, 2025

Summary by CodeRabbit

  • New Features

    • Introduced enriched video stream details that include enhanced URL links, display resolution, and media type information to improve media playback handling.
    • Updated the component name from WatchOnYtify to WatchVideo for improved clarity in the ActionsMenu.
    • Added support for captions with structured labeling to enhance user accessibility during video playback.
  • Bug Fixes

    • Implemented error handling for video sources ending with '&fallback' to prevent further actions in case of issues.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 27, 2025

Warning

Rate limit exceeded

@n-ce has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 24 minutes and 28 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 954fb0d and 0c39b50.

📒 Files selected for processing (1)
  • netlify/edge-functions/fallback.ts (2 hunks)

Walkthrough

The update introduces a new property, videoStreams, into the exported object of the asynchronous function in netlify/edge-functions/fallback.ts. This property is derived from the adaptiveFormats array contained in the streamData object by filtering for entries whose mimeType begins with "video". Each matching entry is then transformed into an object containing a modified url, a resolution from qualityLabel, and a type from mimeType. Additionally, a new property, captions, is added as an empty array. The ActionsMenu component in src/components/ActionsMenu.tsx has been updated to rename a lazy-loaded component from WatchOnYtify to WatchVideo. The exported function in src/components/WatchVideo.tsx has also been renamed accordingly, and the dynamic import in src/lib/player.ts has been modified to reflect this change.

Changes

File Summary
netlify/edge-functions/fallback.ts Added properties videoStreams and captions to the exported object, with videoStreams filtering adaptiveFormats for video formats and mapping them, and captions added as an empty array. The fetcher function's return type is updated to include qualityLabel.
src/components/ActionsMenu.tsx Renamed lazy-loaded component from WatchOnYtify to WatchVideo and updated its usage within the ActionsMenu component.
src/components/WatchVideo.tsx Changed the exported function name from WatchOnYtify to WatchVideo. Added error handling for video sources ending with '&fallback'.
src/lib/player.ts Updated dynamic import statement from WatchOnYtify to WatchVideo in the player function.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant FallbackFunction
    Client->>FallbackFunction: Invoke asynchronous function with streamData
    FallbackFunction->>streamData: Access adaptiveFormats array
    FallbackFunction->>FallbackFunction: Filter entries where mimeType starts with "video"
    FallbackFunction->>FallbackFunction: Map each entry (modify url, set resolution and type)
    FallbackFunction->>FallbackFunction: Add empty captions array
    FallbackFunction->>Client: Return response with videoStreams and captions properties
Loading

Poem

I'm a rabbit coding in the night,
Hopping through streams with pure delight.
Video paths now shine so bright,
Each format dances, set just right,
In code meadows, our changes take flight!
🐇✨


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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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 do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration 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.

coderabbitai[bot]

This comment was marked as outdated.

coderabbitai[bot]

This comment was marked as outdated.

coderabbitai[bot]

This comment was marked as outdated.

@n-ce

This comment was marked as duplicate.

@coderabbitai

This comment was marked as resolved.

@n-ce
Copy link
Copy Markdown
Owner Author

n-ce commented Feb 27, 2025

@coderabbitai why does the the video src triggers the error handler? when i open the src in a new tab (outside the application) it works fine

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 27, 2025

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

@n-ce This issue is likely related to how HTML5 video elements handle cross-origin resources differently than direct browser access. When you open a video URL directly in a browser tab, the browser handles it as a standalone resource. However, when embedded in an application using the <video> element, the browser applies stricter security policies.

Common causes for this include:

  1. CORS restrictions: The video source might not include the necessary CORS headers to allow embedding within your application
  2. Content type differences: The browser might handle certain content types differently when embedded vs. direct access
  3. Range requests: HTML5 video players often use range requests which might not be properly supported by the source

To debug this further, could you check the browser console for specific error messages when the video fails to load? Also, could you share which video URL is causing the issue so I can help investigate the specific headers or response format?


🏁 Script executed:

#!/bin/bash
# Get the content of WatchVideo.tsx to examine the error handling logic
cat src/components/WatchVideo.tsx

Length of output: 5734


🏁 Script executed:

#!/bin/bash
# Get the content of player.ts to see how videos are loaded
cat src/lib/player.ts

# Check for any CORS headers or CSP settings that might affect video playback
grep -r "Content-Security-Policy" --include="*.ts" --include="*.tsx" .
grep -r "Access-Control-Allow-Origin" --include="*.ts" --include="*.tsx" .

# Find where video sources are generated/processed
grep -r "videoId" --include="*.ts" --include="*.tsx" .

Length of output: 3339


@n-ce Looking at your code, I can see why this might be happening. When a video is opened directly in a browser tab versus being embedded in an HTML5 <video> element, there are a few key differences in how it's handled:

  1. CORS restrictions: Your video element has crossorigin="anonymous" which requires proper CORS headers from the server. When opening directly in a browser, these restrictions don't apply.

  2. Error handling in your code: I noticed your video element has an error handler that attempts to switch to alternative proxies when errors occur:

onerror={() => {
  if (video.src.endsWith('&fallback')) return;
  const origin = new URL(video.src).origin;
  if (store.api.index < store.api.invidious.length) {
    const proxy = store.api.invidious[store.api.index];
    video.src = video.src.replace(origin, proxy);
    audio.src = audio.src.replace(origin, proxy);
    store.api.index++;
  }
}

To debug this further:

  1. Try temporarily removing the crossorigin="anonymous" attribute to see if this resolves the issue
  2. Add console logs in the error handler to see what specific error is occurring
  3. Check what &fallback is meant to do - it seems your code is specifically checking for this parameter

Could you share what browser console errors you're seeing when the video fails to load?

coderabbitai[bot]

This comment was marked as resolved.

@n-ce n-ce merged commit af3e0cb into main Feb 27, 2025
@n-ce n-ce deleted the n-ce-patch-1 branch February 27, 2025 04:36
@coderabbitai coderabbitai Bot mentioned this pull request Jul 31, 2025
@coderabbitai coderabbitai Bot mentioned this pull request Sep 7, 2025
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.

1 participant