-
Notifications
You must be signed in to change notification settings - Fork 9.9k
feat(route): add iVoox podcast feed #22072
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
guillevc
wants to merge
20
commits into
DIYgod:master
Choose a base branch
from
guillevc:feat/ivoox-podcast-route
base: master
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.
+201
−1
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
c769de1
feat(route): add iVoox podcast feed
guillevc 16a0996
feat(route): cover en ivoox podcast urls
guillevc 5cdbcff
docs(route): clarify iVoox podcast description
guillevc 66252f0
feat(route): resolve iVoox audio urls
guillevc ac27e2d
fix(route): follow ivoox redirect to audio cdn
guillevc 9c3a298
feat: add channel-level itunes artwork
guillevc 673ba90
refactor(rss): split serializer helpers
guillevc f33a13c
Revert "refactor(rss): split serializer helpers"
guillevc c8f7c2c
refactor(route/ivoox): inline single-use selectors and ID validator
guillevc f8b33cb
refactor(route/ivoox): delegate item limiting to middleware
guillevc b4b2508
refactor(route/ivoox): remove unnecessary parseResponse and first() c…
guillevc 91508cc
fix(route/ivoox): use feeds.ivoox.com directly to skip redirect
guillevc 0a3d19d
refactor(route/ivoox): remove unnecessary first() on channel image el…
guillevc 4eb1429
refactor(route/ivoox): use guid directly and type helper params
guillevc d19aaba
refactor(route/ivoox): use non-deprecated xml option
guillevc afd75e0
refactor(route/ivoox): drop decodeHTML and hoist repeated childText c…
guillevc de9e257
fix(route/ivoox): restore first() on duplicate itunes:explicit element
guillevc 9eed658
refactor(route/ivoox): inline childText and childAttr helpers
guillevc 3a5ffa7
refactor(route/ivoox): inline normalizeEpisodeId logic
guillevc 21e9872
Merge branch 'DIYgod:master' into feat/ivoox-podcast-route
guillevc 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import type { Namespace } from '@/types'; | ||
|
|
||
| export const namespace: Namespace = { | ||
| name: 'iVoox', | ||
| url: 'www.ivoox.com', | ||
| categories: ['multimedia'], | ||
| lang: 'es', | ||
| }; |
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 |
|---|---|---|
| @@ -0,0 +1,188 @@ | ||
| import { load } from 'cheerio'; | ||
|
|
||
| import InvalidParameterError from '@/errors/types/invalid-parameter'; | ||
| import type { Data, DataItem, Route } from '@/types'; | ||
| import { ViewType } from '@/types'; | ||
| import cache from '@/utils/cache'; | ||
| import ofetch from '@/utils/ofetch'; | ||
| import { parseDate } from '@/utils/parse-date'; | ||
|
|
||
| const rootUrl = 'https://www.ivoox.com'; | ||
|
|
||
| export const route: Route = { | ||
| path: '/podcast/:id', | ||
| categories: ['multimedia'], | ||
| example: '/ivoox/podcast/11178419', | ||
| parameters: { | ||
| id: 'Podcast ID, can be found in the iVoox podcast URL after `_sq_f`, for example `11178419` or `f11178419`', | ||
| }, | ||
| features: { | ||
| requireConfig: false, | ||
| requirePuppeteer: false, | ||
| antiCrawler: false, | ||
| supportRadar: true, | ||
| supportBT: false, | ||
| supportPodcast: true, | ||
| supportScihub: false, | ||
| }, | ||
| radar: [ | ||
| { | ||
| source: ['www.ivoox.com/podcast-*_sq_f:id_1.html', 'www.ivoox.com/en/podcast-*_sq_f:id_1.html', 'www.ivoox.com/*_sq_f:id_1.html', 'www.ivoox.com/en/*_sq_f:id_1.html'], | ||
| target: (params) => `/podcast/${params.id}`, | ||
| }, | ||
| ], | ||
| name: 'Podcast', | ||
| url: 'www.ivoox.com', | ||
| maintainers: ['guillevc'], | ||
| handler, | ||
| description: 'Transforms an iVoox podcast page into an RSS feed that exposes the full episode audio enclosures instead of the short clip feed.', | ||
| view: ViewType.Audios, | ||
| }; | ||
|
|
||
| async function handler(ctx): Promise<Data> { | ||
| const rawId: string = ctx.req.param('id'); | ||
| const idMatch = /^f?(\d+)$/i.exec(rawId); | ||
| if (!idMatch) { | ||
| throw new InvalidParameterError(`Invalid iVoox podcast ID: ${rawId}`); | ||
| } | ||
| const id = idMatch[1]; | ||
| const feedUrl = `https://feeds.ivoox.com/feed_fg_f${id}_filtro_1.xml`; | ||
| const response = await ofetch(feedUrl); | ||
|
|
||
| const $ = load(response, { xml: true }); | ||
| const channel = $('channel'); | ||
| if (!channel.length) { | ||
| throw new Error(`Invalid iVoox podcast feed for ID ${id}`); | ||
| } | ||
|
|
||
| const items = ( | ||
| await Promise.all( | ||
| channel | ||
| .children('item') | ||
| .toArray() | ||
| .map(async (element): Promise<DataItem | undefined> => { | ||
| const itemElement = $(element); | ||
| const enclosure = itemElement.children('enclosure'); | ||
| const enclosureUrl = enclosure.attr('url'); | ||
| const guid = itemElement.children('guid').text(); | ||
| const itemIdMatch = /(?:_rf_|\/)(\d+)(?:_\d+)?(?:\.html)?/i.exec(guid) ?? /(\d+)/.exec(guid); | ||
| const itemId = itemIdMatch?.[1]; | ||
|
|
||
| if (!enclosureUrl) { | ||
| return; | ||
| } | ||
|
|
||
| const title = itemElement.children('title').text(); | ||
| const link = itemElement.children('link').text(); | ||
| const image = itemElement.children(String.raw`itunes\:image`).attr('href'); | ||
| const length = parseOptionalInteger(enclosure.attr('length')); | ||
| const resolvedEnclosureUrl = itemId ? await resolveEpisodeAudioUrl(itemId, enclosureUrl, link) : enclosureUrl; | ||
|
|
||
| return { | ||
| title, | ||
| description: itemElement.children('description').text() || undefined, | ||
| link: link || undefined, | ||
| pubDate: parseOptionalDate(itemElement.children('pubDate').text()), | ||
| guid: guid || undefined, | ||
| enclosure_url: resolvedEnclosureUrl, | ||
| enclosure_type: enclosure.attr('type') || mediaTypeFromUrl(resolvedEnclosureUrl), | ||
| enclosure_title: title, | ||
| ...(length !== undefined && { enclosure_length: length }), | ||
| itunes_duration: itemElement.children(String.raw`itunes\:duration`).text() || undefined, | ||
| itunes_item_image: image, | ||
| }; | ||
| }) | ||
| ) | ||
| ).filter((current): current is DataItem => current !== undefined); | ||
|
|
||
| const rssImageUrl = channel.children('image').children('url').text(); | ||
| const itunesImageUrl = channel.children(String.raw`itunes\:image`).attr('href'); | ||
|
|
||
| return { | ||
| title: channel.children('title').text(), | ||
| description: channel.children('description').text() || undefined, | ||
| link: channel.children('link').text() || rootUrl, | ||
| item: items, | ||
| image: rssImageUrl || itunesImageUrl, | ||
| itunes_image: itunesImageUrl || rssImageUrl || undefined, | ||
| language: normalizeLanguage(channel.children('language').text()), | ||
| feedLink: feedUrl, | ||
| itunes_author: channel.children(String.raw`itunes\:author`).text() || undefined, | ||
| itunes_category: channel.children(String.raw`itunes\:category`).attr('text'), | ||
| itunes_explicit: | ||
| channel | ||
| .children(String.raw`itunes\:explicit`) | ||
| .first() | ||
| .text() || undefined, | ||
| }; | ||
| } | ||
|
|
||
| function resolveEpisodeAudioUrl(audioId: string, fallbackUrl: string, referer: string): Promise<string> { | ||
| return cache.tryGet(`ivoox:audio-url:${audioId}`, async () => { | ||
| try { | ||
| const response = await ofetch(`https://vcore-web.ivoox.com/v1/public/audios/${audioId}/download-url`); | ||
| const downloadUrl = response?.data?.downloadUrl; | ||
| if (typeof downloadUrl === 'string' && downloadUrl) { | ||
| const audioResponse = await ofetch.raw(new URL(downloadUrl, rootUrl).href, { | ||
| headers: { | ||
| Referer: referer, | ||
| }, | ||
| redirect: 'manual', | ||
| method: 'GET', | ||
| }); | ||
|
|
||
| if (audioResponse.status >= 300 && audioResponse.status < 400) { | ||
| const location = audioResponse.headers.get('location'); | ||
| if (location) { | ||
| return new URL(location, rootUrl).href; | ||
| } | ||
| } | ||
|
|
||
| if (audioResponse.url) { | ||
| return audioResponse.url; | ||
| } | ||
|
|
||
| return new URL(downloadUrl, rootUrl).href; | ||
| } | ||
| } catch { | ||
| // Fall back to the original feed enclosure when iVoox does not return a direct URL. | ||
| } | ||
|
|
||
| return fallbackUrl; | ||
| }); | ||
| } | ||
|
|
||
| function parseOptionalDate(value: string): Date | undefined { | ||
| return value ? parseDate(value) : undefined; | ||
| } | ||
|
|
||
| function parseOptionalInteger(value: string | undefined): number | undefined { | ||
| if (!value) { | ||
| return; | ||
| } | ||
|
|
||
| const number = Number.parseInt(value, 10); | ||
| return Number.isNaN(number) ? undefined : number; | ||
| } | ||
|
|
||
| function normalizeLanguage(value: string): Data['language'] | undefined { | ||
| const language = value.toLowerCase(); | ||
| return language ? ((language === 'es-es' ? 'es' : language) as Data['language']) : undefined; | ||
| } | ||
|
|
||
| function mediaTypeFromUrl(url: string): string { | ||
| const pathname = new URL(url).pathname.toLowerCase(); | ||
| if (pathname.endsWith('.m4a')) { | ||
| return 'audio/mp4'; | ||
| } | ||
|
|
||
| if (pathname.endsWith('.ogg') || pathname.endsWith('.opus')) { | ||
| return 'audio/ogg'; | ||
| } | ||
|
|
||
| if (pathname.endsWith('.aac')) { | ||
| return 'audio/aac'; | ||
| } | ||
|
|
||
| return 'audio/mpeg'; | ||
| } | ||
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
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.
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.
I kept
first()only here. Since for some reason the explicit element is returned twice which results in "truetrue" strings iffirst()is not used.