diff --git a/lib/v2/transcriptforest/index.js b/lib/v2/transcriptforest/index.js new file mode 100644 index 00000000000000..a83ce775e8be29 --- /dev/null +++ b/lib/v2/transcriptforest/index.js @@ -0,0 +1,116 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const { art } = require('@/utils/render'); +const path = require('path'); + +const bakeTimestamp = (seconds) => { + const hours = Math.floor(seconds / 3600); + const minutes = Math.floor((seconds % 3600) / 60); + const remainingSeconds = Math.floor(seconds % 60); + + const formattedHours = String(hours).padStart(2, '0'); + const formattedMinutes = String(minutes).padStart(2, '0'); + const formattedSeconds = String(remainingSeconds).padStart(2, '0'); + + return `${formattedHours}:${formattedMinutes}:${formattedSeconds}`; +}; + +module.exports = async (ctx) => { + const { channel } = ctx.params; + const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit, 10) : 10; + + const rootUrl = 'https://www.transcriptforest.com'; + + const { data: firstResponse } = await got(rootUrl); + + const data = JSON.parse(firstResponse.match(/({"props".*"scriptLoader":\[]})<\/script>/)?.[1]); + + const buildId = data.buildId; + const defaultLocale = data.defaultLocale; + const channels = data.props.pageProps.listChannel; + const selected = channel ? channels.find((c) => c.channel_id === channel || c.channel_name === channel) : undefined; + + const apiUrl = new URL(`_next/data/${buildId}/en${selected ? `/channel/${selected.channel_id}` : ''}.json`, rootUrl).href; + const currentUrl = new URL(selected ? `${defaultLocale}/channel/${selected.channel_id}` : '', rootUrl).href; + + const { data: response } = await got(apiUrl, { + searchParams: { + channelName: selected ? selected.channel_id : '', + offset: 0, + }, + }); + + let items = response.pageProps.listEpisode.data.slice(0, limit).map((item) => ({ + title: item.episode_name, + link: new URL(`${defaultLocale}/${item.channel_id}/${item.episode_id}`, rootUrl).href, + detailUrl: new URL(`_next/data/${buildId}/${defaultLocale}/${item.channel_id}/${item.episode_id}.json`, rootUrl).href, + description: art(path.join(__dirname, 'templates/description.art'), { + texts: item.episode_description.split(/\n\n/).map((text) => ({ + text, + })), + }), + author: item.channel_name, + guid: item.id, + pubDate: parseDate(item.published_at), + updated: parseDate(item.updated_at), + itunes_item_image: item.episode_cover.split(/\?/)[0], + itunes_duration: item.episode_duration, + enclosure_url: item.source_media, + enclosure_type: 'audio/mpeg', + })); + + items = await Promise.all( + items.map((item) => + ctx.cache.tryGet(item.link, async () => { + const { data: detailResponse } = await got(item.detailUrl); + const { data: textResponse } = await got(detailResponse.pageProps.currentEpisode.ps4_url); + + item.description = + art(path.join(__dirname, 'templates/description.art'), { + audios: [ + { + src: detailResponse.pageProps.currentEpisode.media, + type: 'audio/mpeg', + }, + ], + }) + + item.description + + art(path.join(__dirname, 'templates/description.art'), { + texts: textResponse.map((t) => ({ + startTime: bakeTimestamp(t.startTime), + endTime: bakeTimestamp(t.endTime), + text: t.readOnlyText, + })), + }); + + delete item.detailUrl; + + return item; + }) + ) + ); + + const { data: currentResponse } = await got(currentUrl); + + const $ = cheerio.load(currentResponse); + + const title = $('title').text(); + const image = $('meta[property="og:image"]').prop('content'); + const icon = new URL($('link[rel="apple-touch-icon"]').prop('href'), rootUrl).href; + const author = title.split(/\|/)[0].trim(); + + ctx.state.data = { + item: items, + title, + link: currentUrl, + description: $('meta[name="description"]').prop('content'), + language: $('html').prop('lang'), + image, + icon, + logo: icon, + author, + itunes_author: author, + allowEmpty: true, + }; +}; diff --git a/lib/v2/transcriptforest/maintainer.js b/lib/v2/transcriptforest/maintainer.js new file mode 100644 index 00000000000000..fb0da7f56057f0 --- /dev/null +++ b/lib/v2/transcriptforest/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/:channel?': ['nczitzk'], +}; diff --git a/lib/v2/transcriptforest/radar.js b/lib/v2/transcriptforest/radar.js new file mode 100644 index 00000000000000..db34f20be2dc5c --- /dev/null +++ b/lib/v2/transcriptforest/radar.js @@ -0,0 +1,307 @@ +module.exports = { + 'transcriptforest.com': { + _name: 'Transcript Forest', + www: [ + { + title: 'All', + docs: 'https://docs.rsshub.app/routes/multimedia#transcript-forest', + source: ['/en/channel'], + target: '/transcriptforest', + }, + { + title: 'a16z podcast', + docs: 'https://docs.rsshub.app/routes/multimedia#transcript-forest', + source: ['/en/channel/a16z-podcast'], + target: '/transcriptforest/a16z-podcast', + }, + { + title: "Aarthi and Sriram's Good Time Show", + docs: 'https://docs.rsshub.app/routes/multimedia#transcript-forest', + source: ['/en/channel/aarthi-and-srirams-good-time-show'], + target: '/transcriptforest/aarthi-and-srirams-good-time-show', + }, + { + title: 'Acquired', + docs: 'https://docs.rsshub.app/routes/multimedia#transcript-forest', + source: ['/en/channel/acquired'], + target: '/transcriptforest/acquired', + }, + { + title: 'All-In with Chamath, Jason, Sacks & Friedberg', + docs: 'https://docs.rsshub.app/routes/multimedia#transcript-forest', + source: ['/en/channel/all-in-with-chamath-jason-sacks-friedberg'], + target: '/transcriptforest/all-in-with-chamath-jason-sacks-friedberg', + }, + { + title: 'All the Hacks', + docs: 'https://docs.rsshub.app/routes/multimedia#transcript-forest', + source: ['/en/channel/all-the-hacks'], + target: '/transcriptforest/all-the-hacks', + }, + { + title: 'Breaking Points', + docs: 'https://docs.rsshub.app/routes/multimedia#transcript-forest', + source: ['/en/channel/breaking-points'], + target: '/transcriptforest/breaking-points', + }, + { + title: 'Cartoon Avatars', + docs: 'https://docs.rsshub.app/routes/multimedia#transcript-forest', + source: ['/en/channel/cartoon-avatars'], + target: '/transcriptforest/cartoon-avatars', + }, + { + title: 'Conversations With Coleman', + docs: 'https://docs.rsshub.app/routes/multimedia#transcript-forest', + source: ['/en/channel/conversations-with-coleman'], + target: '/transcriptforest/conversations-with-coleman', + }, + { + title: 'CSPI Podcast', + docs: 'https://docs.rsshub.app/routes/multimedia#transcript-forest', + source: ['/en/channel/cspi-podcast'], + target: '/transcriptforest/cspi-podcast', + }, + { + title: 'Culpable', + docs: 'https://docs.rsshub.app/routes/multimedia#transcript-forest', + source: ['/en/channel/culpable'], + target: '/transcriptforest/culpable', + }, + { + title: 'Dateline NBC', + docs: 'https://docs.rsshub.app/routes/multimedia#transcript-forest', + source: ['/en/channel/dateline-nbc'], + target: '/transcriptforest/dateline-nbc', + }, + { + title: 'Execs', + docs: 'https://docs.rsshub.app/routes/multimedia#transcript-forest', + source: ['/en/channel/execs'], + target: '/transcriptforest/execs', + }, + { + title: 'Exponent', + docs: 'https://docs.rsshub.app/routes/multimedia#transcript-forest', + source: ['/en/channel/exponent'], + target: '/transcriptforest/exponent', + }, + { + title: 'Freakonomics', + docs: 'https://docs.rsshub.app/routes/multimedia#transcript-forest', + source: ['/en/channel/freakonomics'], + target: '/transcriptforest/freakonomics', + }, + { + title: 'Future of StoryTelling', + docs: 'https://docs.rsshub.app/routes/multimedia#transcript-forest', + source: ['/en/channel/future-of-storytelling'], + target: '/transcriptforest/future-of-storytelling', + }, + { + title: 'Gamecraft', + docs: 'https://docs.rsshub.app/routes/multimedia#transcript-forest', + source: ['/en/channel/gamecraft'], + target: '/transcriptforest/gamecraft', + }, + { + title: 'Get WIRED', + docs: 'https://docs.rsshub.app/routes/multimedia#transcript-forest', + source: ['/en/channel/get-wired'], + target: '/transcriptforest/get-wired', + }, + { + title: 'Greymatter', + docs: 'https://docs.rsshub.app/routes/multimedia#transcript-forest', + source: ['/en/channel/greymatter'], + target: '/transcriptforest/greymatter', + }, + { + title: 'How I built this', + docs: 'https://docs.rsshub.app/routes/multimedia#transcript-forest', + source: ['/en/channel/how-I-built-this'], + target: '/transcriptforest/how-I-built-this', + }, + { + title: 'Huberman Lab', + docs: 'https://docs.rsshub.app/routes/multimedia#transcript-forest', + source: ['/en/channel/huberman-lab'], + target: '/transcriptforest/huberman-lab', + }, + { + title: 'ICYMI', + docs: 'https://docs.rsshub.app/routes/multimedia#transcript-forest', + source: ['/en/channel/icymi'], + target: '/transcriptforest/icymi', + }, + { + title: 'In Machines We Trust', + docs: 'https://docs.rsshub.app/routes/multimedia#transcript-forest', + source: ['/en/channel/in-machines-we-trust'], + target: '/transcriptforest/in-machines-we-trust', + }, + { + title: "Invest Like the Best with Patrick O'Shaughnessy", + docs: 'https://docs.rsshub.app/routes/multimedia#transcript-forest', + source: ['/en/channel/invest-like-the-best-with-patrick-o-shaughnessy'], + target: '/transcriptforest/invest-like-the-best-with-patrick-o-shaughnessy', + }, + { + title: 'Joe Rogan Experience Review podcast', + docs: 'https://docs.rsshub.app/routes/multimedia#transcript-forest', + source: ['/en/channel/joe-rogan-experience-review-podcast'], + target: '/transcriptforest/joe-rogan-experience-review-podcast', + }, + { + title: 'Land of Giants', + docs: 'https://docs.rsshub.app/routes/multimedia#transcript-forest', + source: ['/en/channel/land-of-giants'], + target: '/transcriptforest/land-of-giants', + }, + { + title: "Lenny's Podcast: Product | Growth | Career", + docs: 'https://docs.rsshub.app/routes/multimedia#transcript-forest', + source: ['/en/channel/lenny-podcast-product-growth-career'], + target: '/transcriptforest/lenny-podcast-product-growth-career', + }, + { + title: 'Lex Fridman Podcast', + docs: 'https://docs.rsshub.app/routes/multimedia#transcript-forest', + source: ['/en/channel/lex-fridman-podcast'], + target: '/transcriptforest/lex-fridman-podcast', + }, + { + title: 'Making Sense with Sam Harris', + docs: 'https://docs.rsshub.app/routes/multimedia#transcript-forest', + source: ['/en/channel/making-sense-with-sam-harris'], + target: '/transcriptforest/making-sense-with-sam-harris', + }, + { + title: 'Masters of Scale', + docs: 'https://docs.rsshub.app/routes/multimedia#transcript-forest', + source: ['/en/channel/masters-of-scale'], + target: '/transcriptforest/masters-of-scale', + }, + { + title: 'Modern Wisdom', + docs: 'https://docs.rsshub.app/routes/multimedia#transcript-forest', + source: ['/en/channel/modern-wisdom'], + target: '/transcriptforest/modern-wisdom', + }, + { + title: 'Moment of Zen', + docs: 'https://docs.rsshub.app/routes/multimedia#transcript-forest', + source: ['/en/channel/moment-of-zen'], + target: '/transcriptforest/moment-of-zen', + }, + { + title: 'Morbid', + docs: 'https://docs.rsshub.app/routes/multimedia#transcript-forest', + source: ['/en/channel/morbid'], + target: '/transcriptforest/morbid', + }, + { + title: 'My First Million', + docs: 'https://docs.rsshub.app/routes/multimedia#transcript-forest', + source: ['/en/channel/my-first-million'], + target: '/transcriptforest/my-first-million', + }, + { + title: 'Naval', + docs: 'https://docs.rsshub.app/routes/multimedia#transcript-forest', + source: ['/en/channel/naval'], + target: '/transcriptforest/naval', + }, + { + title: 'Newcomer Podcast', + docs: 'https://docs.rsshub.app/routes/multimedia#transcript-forest', + source: ['/en/channel/newcomer-podcast'], + target: '/transcriptforest/newcomer-podcast', + }, + { + title: 'Not investment advice', + docs: 'https://docs.rsshub.app/routes/multimedia#transcript-forest', + source: ['/en/channel/not-investment-advice'], + target: '/transcriptforest/not-investment-advice', + }, + { + title: 'Odd Lots', + docs: 'https://docs.rsshub.app/routes/multimedia#transcript-forest', + source: ['/en/channel/odd-lots'], + target: '/transcriptforest/odd-lots', + }, + { + title: 'On with Kara Swisher', + docs: 'https://docs.rsshub.app/routes/multimedia#transcript-forest', + source: ['/en/channel/on-with-kara-swisher'], + target: '/transcriptforest/on-with-kara-swisher', + }, + { + title: 'Proof: A True Crime Podcast', + docs: 'https://docs.rsshub.app/routes/multimedia#transcript-forest', + source: ['/en/channel/proof-a-true-crime-podcast'], + target: '/transcriptforest/proof-a-true-crime-podcast', + }, + { + title: 'Reply All', + docs: 'https://docs.rsshub.app/routes/multimedia#transcript-forest', + source: ['/en/channel/reply-all'], + target: '/transcriptforest/reply-all', + }, + { + title: 'Revisionist History', + docs: 'https://docs.rsshub.app/routes/multimedia#transcript-forest', + source: ['/en/channel/revisionist-history'], + target: '/transcriptforest/revisionist-history', + }, + { + title: 'Serial', + docs: 'https://docs.rsshub.app/routes/multimedia#transcript-forest', + source: ['/en/channel/serial-podcast'], + target: '/transcriptforest/serial-podcast', + }, + { + title: 'Slow Burn', + docs: 'https://docs.rsshub.app/routes/multimedia#transcript-forest', + source: ['/en/channel/slow-burn'], + target: '/transcriptforest/slow-burn', + }, + { + title: 'StrictlyVC Download', + docs: 'https://docs.rsshub.app/routes/multimedia#transcript-forest', + source: ['/en/channel/strictlyvc-download'], + target: '/transcriptforest/strictlyvc-download', + }, + { + title: 'Stuff You Should Know:', + docs: 'https://docs.rsshub.app/routes/multimedia#transcript-forest', + source: ['/en/channel/stuff-you-should-know'], + target: '/transcriptforest/stuff-you-should-know', + }, + { + title: 'Subversive w/Alex Kaschuta', + docs: 'https://docs.rsshub.app/routes/multimedia#transcript-forest', + source: ['/en/channel/subversive-w-alex-kaschuta'], + target: '/transcriptforest/subversive-w-alex-kaschuta', + }, + { + title: 'TED Radio Hour', + docs: 'https://docs.rsshub.app/routes/multimedia#transcript-forest', + source: ['/en/channel/ted-radio-hour'], + target: '/transcriptforest/ted-radio-hour', + }, + { + title: 'The Bootstrapped Founder', + docs: 'https://docs.rsshub.app/routes/multimedia#transcript-forest', + source: ['/en/channel/the-bootstrapped-founder'], + target: '/transcriptforest/the-bootstrapped-founder', + }, + { + title: 'The Boyscast with Ryan Long', + docs: 'https://docs.rsshub.app/routes/multimedia#transcript-forest', + source: ['/en/channel/the-boyscast-with-ryan-long'], + target: '/transcriptforest/the-boyscast-with-ryan-long', + }, + ], + }, +}; diff --git a/lib/v2/transcriptforest/router.js b/lib/v2/transcriptforest/router.js new file mode 100644 index 00000000000000..79163f9a7d72f9 --- /dev/null +++ b/lib/v2/transcriptforest/router.js @@ -0,0 +1,3 @@ +module.exports = (router) => { + router.get('/:channel?', require('./')); +}; diff --git a/lib/v2/transcriptforest/templates/description.art b/lib/v2/transcriptforest/templates/description.art new file mode 100644 index 00000000000000..c62849a7683ce7 --- /dev/null +++ b/lib/v2/transcriptforest/templates/description.art @@ -0,0 +1,23 @@ +{{ if audios }} + {{ each audios audio }} + {{ if audio?.src }} + + {{ /if }} + {{ /each }} +{{ /if }} + +{{ if texts }} + {{ each texts t }} + {{ if t.startTime && t.endTime }} + {{ t.startTime }} - {{ t.endTime }} + {{ /if }} +
{{ t.text }}
+ {{ /each }} +{{ /if }} \ No newline at end of file diff --git a/website/docs/routes/multimedia.mdx b/website/docs/routes/multimedia.mdx index df83a42914bcea..10a4cf96796123 100644 --- a/website/docs/routes/multimedia.mdx +++ b/website/docs/routes/multimedia.mdx @@ -1135,6 +1135,65 @@ Refer to [https://developers.themoviedb.org/3/getting-started/languages](https:/