-
Notifications
You must be signed in to change notification settings - Fork 1.5k
feat: Add initial support for YouTube clip links #9532
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
Open
radmorecameron
wants to merge
6
commits into
FreeTubeApp:development
Choose a base branch
from
radmorecameron:add-initial-support-for-clip-links
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
36f7eaf
Add initial support for clip links
radmorecameron 091e8bd
add link to Invidious PR to make clip api endpoint less expensive.
radmorecameron 9f06cb5
Parse params for clips using ClipParams from YouTube.js
radmorecameron a92ee52
update property name since I changed it in the youtubejs pr
radmorecameron 9675e80
fix invidious
radmorecameron 755a46d
Fix invidious for real
radmorecameron File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| import { ClientType, Constants, Innertube, Misc, Mixins, Parser, Platform, Player, Session, UniversalCache, Utils, YT, YTNodes } from 'youtubei.js' | ||
| import { ClipParams } from '../../../../node_modules/youtubei.js/dist/protos/generated/misc/params' | ||
| import Autolinker from 'autolinker' | ||
| import { parseLooseJSON } from 'bgutils-js/utils' | ||
|
|
||
|
|
@@ -2486,3 +2487,21 @@ export async function getLocalCommunityPostComments(postId, channelId) { | |
|
|
||
| return await innertube.getPostComments(postId, channelId) | ||
| } | ||
|
|
||
| export async function getLocalClip(clipId) { | ||
| const innertube = await createInnertube() | ||
|
|
||
| const clipResponse = await innertube.resolveURL('https://www.youtube.com/clip/' + clipId) | ||
|
|
||
| const videoId = clipResponse?.payload?.videoId | ||
|
|
||
| const parsedParams = ClipParams.decode(Utils.base64ToU8(decodeURIComponent(clipResponse.payload.params))) | ||
|
|
||
| return { | ||
| videoId, | ||
| startTime: parsedParams.clipParamData.startTime / 1000, // convert to seconds | ||
| endTime: parsedParams.clipParamData.endTime / 1000, // convert to seconds | ||
| clipTitle: parsedParams.clipParamData.clipTitle, | ||
| clipMetadata: parsedParams.clipParamData.clipMetadata | ||
| } | ||
|
Comment on lines
+2498
to
+2506
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As this section of the code is the same for the local and Invidious APIs apart from where the video ID and params string is read from, could you please extract it into a shared function that takes the video ID and params text as the input, decodes it and returns the object. |
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we cannot treeshake YouTube.js because of Options API components, we exclude the entire YouTube.js dependency in builds where
SUPPORTS_LOCAL_APIisfalse(that's also why we use therepairInvidiousManifestfunction in those builds instead of generating a DASH manifest with YouTube.js). So you either need to gate the Invidious functionality here behindSUPPORTS_LOCAL_APItoo or use the Invidious clips API endpoint (I know that you originally avoided it here because of performance concerns on their side but using it as a fallback is probably okay).