-
Notifications
You must be signed in to change notification settings - Fork 4
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
Support DeArrow for YouTube #41
Labels
feature request
New feature or request
Comments
shouya
added a commit
that referenced
this issue
Mar 6, 2024
This PR is to implement a simple fetch api for the JS runtime. It enables the user to request data from servers within any JavaScript code. Here's the API: ``` typescript type RequestParam = { method: "GET" | "POST" | "PUT" | "DELETE", headers: { [key: string]: string }, body: string? } fetch(url: string, params?: RequestParam): Promise<Response>; class Response { status: number, headers: { [key: string]: string }, body: string | null json(): Object } ``` Here's a sample endpoint that returns de-clickbait-ed youtube feed using [DeArrow](https://github.com/ajayyy/DeArrow) service: ```yaml - path: /kurtzgesagt-dearrow.xml source: https://www.youtube.com/feeds/videos.xml?channel_id=UCsXVk37bltHxD1rDPwtNM8Q filters: - modify_post: | const video_id = post.id.split(':').pop(); let resp = await fetch(`https://sponsor.ajay.app/api/branding?videoID=${video_id}`); if (resp.status == 200) { let [title] = resp.json().titles; post.title.value = title.title; } let thumbnail = post.extensions.media.group.filter(g => g.name == 'media:group')[0].children.thumbnail[0]; thumbnail.attrs.url = `https://dearrow-thumb.ajay.app/api/v1/getThumbnail?videoID=${video_id}`; ``` (Fixes #41) A few more subtle changes: - errors are handled and displayed more nicely: instead of throwing the error's internal struct at the user, now we display the error message instead - js syntax errors will now show the code context - exceptions raised within `modify_post` are now reported and ignored, so they won't break the feed - both `modify_post` and `modify_feed` can be defined as async functions - the `modify_post` function are now called concurrently for each post, this is especially useful when the function contains long-time async operations. --------- Co-authored-by: shouya <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
DeArrow is a crowdsourced service providing de-clickbait-ed video titles and thumbnail data. API doc: https://wiki.sponsor.ajay.app/w/API_Docs/DeArrow#GET_/api/branding/:sha256HashPrefix
I'm considering a general a way to support it: transform a YouTube RSS feed by replacing the title and thumbnail using the API data.
The best way to do this may be to provide an API in JS runtime that support async request of remote data. I should probably further add some security measures to limit (whitelist) the requested domains from JavaScript.
The text was updated successfully, but these errors were encountered: