From cb0eda5602a21d1626a7face32de6153ed07b5f9 Mon Sep 17 00:00:00 2001 From: Alecks Gates Date: Mon, 22 May 2023 09:00:05 -0500 Subject: Add Podcast RSS feeds (#5487) * Initial test implementation of Podcast RSS This is a pretty simple implementation to add support for The Podcast Namespace in RSS -- instead of affecting the existing RSS implementation, this adds a new UI option. I attempted to retain compatibility with the rest of the RSS feed implementation as much as possible and have created a temporary fork of the "pfeed" library to support this effort. * Update to pfeed-podcast 1.2.2 * Initial test implementation of Podcast RSS This is a pretty simple implementation to add support for The Podcast Namespace in RSS -- instead of affecting the existing RSS implementation, this adds a new UI option. I attempted to retain compatibility with the rest of the RSS feed implementation as much as possible and have created a temporary fork of the "pfeed" library to support this effort. * Update to pfeed-podcast 1.2.2 * Initial test implementation of Podcast RSS This is a pretty simple implementation to add support for The Podcast Namespace in RSS -- instead of affecting the existing RSS implementation, this adds a new UI option. I attempted to retain compatibility with the rest of the RSS feed implementation as much as possible and have created a temporary fork of the "pfeed" library to support this effort. * Update to pfeed-podcast 1.2.2 * Add correct feed image to RSS channel * Prefer HLS videos for podcast RSS Remove video/stream titles, add optional height attribute to podcast RSS * Prefix podcast RSS images with root server URL * Add optional video query support to include captions * Add transcripts & person images to podcast RSS feed * Prefer webseed/webtorrent files over HLS fragmented mp4s * Experimentally adding podcast fields to basic config page * Add validation for new basic config fields * Don't include "content" in podcast feed, use full description for "description" * Initial test implementation of Podcast RSS This is a pretty simple implementation to add support for The Podcast Namespace in RSS -- instead of affecting the existing RSS implementation, this adds a new UI option. I attempted to retain compatibility with the rest of the RSS feed implementation as much as possible and have created a temporary fork of the "pfeed" library to support this effort. * Update to pfeed-podcast 1.2.2 * Add correct feed image to RSS channel * Prefer HLS videos for podcast RSS Remove video/stream titles, add optional height attribute to podcast RSS * Prefix podcast RSS images with root server URL * Add optional video query support to include captions * Add transcripts & person images to podcast RSS feed * Prefer webseed/webtorrent files over HLS fragmented mp4s * Experimentally adding podcast fields to basic config page * Add validation for new basic config fields * Don't include "content" in podcast feed, use full description for "description" * Add medium/socialInteract to podcast RSS feeds. Use HTML for description * Change base production image to bullseye, install prosody in image * Add liveItem and trackers to Podcast RSS feeds Remove height from alternateEnclosure, replaced with title. * Clear Podcast RSS feed cache when live streams start/end * Upgrade to Node 16 * Refactor clearCacheRoute to use ApiCache * Remove unnecessary type hint * Update dockerfile to node 16, install python-is-python2 * Use new file paths for captions/playlists * Fix legacy videos in RSS after migration to object storage * Improve method of identifying non-fragmented mp4s in podcast RSS feeds * Don't include fragmented MP4s in podcast RSS feeds * Add experimental support for podcast:categories on the podcast RSS item * Fix undefined category when no videos exist Allows for empty feeds to exist (important for feeds that might only go live) * Add support for podcast:locked -- user has to opt in to show their email * Use comma for podcast:categories delimiter * Make cache clearing async * Fix merge, temporarily test with pfeed-podcast * Syntax changes * Add EXT_MIMETYPE constants for captions * Update & fix tests, fix enclosure mimetypes, remove admin email * Add test for podacst:socialInteract * Add filters hooks for podcast customTags * Remove showdown, updated to pfeed-podcast 6.1.2 * Add 'action:api.live-video.state.updated' hook * Avoid assigning undefined category to podcast feeds * Remove nvmrc * Remove comment * Remove unused podcast config * Remove more unused podcast config * Fix MChannelAccountDefault type hint missed in merge * Remove extra line * Re-add newline in config * Fix lint errors for isEmailPublic * Fix thumbnails in podcast feeds * Requested changes based on review * Provide podcast rss 2.0 only on video channels * Misc cleanup for a less messy PR * Lint fixes * Remove pfeed-podcast * Add peertube version to new hooks * Don't use query include, remove TODO * Remove film medium hack * Clear podcast rss cache before video/channel update hooks * Clear podcast rss cache before video uploaded/deleted hooks * Refactor podcast feed cache clearing * Set correct person name from video channel * Styling * Fix tests --------- Co-authored-by: Chocobozzz --- server/tests/client.ts | 4 +- server/tests/feeds/feeds.ts | 361 ++++++++++++++------- .../main.js | 82 +++++ .../package.json | 19 ++ server/tests/fixtures/peertube-plugin-test/main.js | 1 + server/tests/plugins/action-hooks.ts | 31 +- 6 files changed, 381 insertions(+), 117 deletions(-) create mode 100644 server/tests/fixtures/peertube-plugin-test-podcast-custom-tags/main.js create mode 100644 server/tests/fixtures/peertube-plugin-test-podcast-custom-tags/package.json (limited to 'server/tests') diff --git a/server/tests/client.ts b/server/tests/client.ts index 9a20c2a10..e84251561 100644 --- a/server/tests/client.ts +++ b/server/tests/client.ts @@ -172,7 +172,7 @@ describe('Test a client controllers', function () { expect(text).to.contain(``) expect(text).to.contain(``) expect(text).to.contain('') - expect(text).to.contain(``) + expect(text).to.contain(``) } async function channelPageTest (path: string) { @@ -182,7 +182,7 @@ describe('Test a client controllers', function () { expect(text).to.contain(``) expect(text).to.contain(``) expect(text).to.contain('') - expect(text).to.contain(``) + expect(text).to.contain(``) } async function watchVideoPageTest (path: string) { diff --git a/server/tests/feeds/feeds.ts b/server/tests/feeds/feeds.ts index ecd1badc1..57eefff6d 100644 --- a/server/tests/feeds/feeds.ts +++ b/server/tests/feeds/feeds.ts @@ -11,6 +11,7 @@ import { makeGetRequest, makeRawRequest, PeerTubeServer, + PluginsCommand, setAccessTokensToServers, setDefaultChannelAvatar, stopFfmpeg, @@ -26,12 +27,15 @@ const expect = chai.expect describe('Test syndication feeds', () => { let servers: PeerTubeServer[] = [] let serverHLSOnly: PeerTubeServer + let userAccessToken: string let rootAccountId: number let rootChannelId: number + let userAccountId: number let userChannelId: number let userFeedToken: string + let liveId: string before(async function () { @@ -93,7 +97,11 @@ describe('Test syndication feeds', () => { await servers[0].comments.createThread({ videoId: id, text: 'comment on unlisted video' }) } - await waitJobs(servers) + await serverHLSOnly.videos.upload({ attributes: { name: 'hls only video' } }) + + await waitJobs([ ...servers, serverHLSOnly ]) + + await servers[0].plugins.install({ path: PluginsCommand.getPluginTestPath('-podcast-custom-tags') }) }) describe('All feed', function () { @@ -108,6 +116,11 @@ describe('Test syndication feeds', () => { } }) + it('Should be well formed XML (covers Podcast endpoint)', async function () { + const podcast = await servers[0].feed.getPodcastXML({ ignoreCache: true, channelId: rootChannelId }) + expect(podcast).xml.to.be.valid() + }) + it('Should be well formed JSON (covers JSON feed 1.0 endpoint)', async function () { for (const feed of [ 'video-comments' as 'video-comments', 'videos' as 'videos' ]) { const jsonText = await servers[0].feed.getJSON({ feed, ignoreCache: true }) @@ -153,168 +166,290 @@ describe('Test syndication feeds', () => { describe('Videos feed', function () { - it('Should contain a valid enclosure (covers RSS 2.0 endpoint)', async function () { - for (const server of servers) { - const rss = await server.feed.getXML({ feed: 'videos', ignoreCache: true }) + describe('Podcast feed', function () { + + it('Should contain a valid podcast:alternateEnclosure', async function () { + // Since podcast feeds should only work on the server they originate on, + // only test the first server where the videos reside + const rss = await servers[0].feed.getPodcastXML({ ignoreCache: false, channelId: rootChannelId }) expect(XMLValidator.validate(rss)).to.be.true const parser = new XMLParser({ parseAttributeValue: true, ignoreAttributes: false }) const xmlDoc = parser.parse(rss) - const enclosure = xmlDoc.rss.channel.item[0].enclosure + const enclosure = xmlDoc.rss.channel.item.enclosure expect(enclosure).to.exist + const alternateEnclosure = xmlDoc.rss.channel.item['podcast:alternateEnclosure'] + expect(alternateEnclosure).to.exist + + expect(alternateEnclosure['@_type']).to.equal('video/webm') + expect(alternateEnclosure['@_length']).to.equal(218910) + expect(alternateEnclosure['@_lang']).to.equal('zh') + expect(alternateEnclosure['@_title']).to.equal('720p') + expect(alternateEnclosure['@_default']).to.equal(true) + + expect(alternateEnclosure['podcast:source'][0]['@_uri']).to.contain('-720.webm') + expect(alternateEnclosure['podcast:source'][0]['@_uri']).to.equal(enclosure['@_url']) + expect(alternateEnclosure['podcast:source'][1]['@_uri']).to.contain('-720.torrent') + expect(alternateEnclosure['podcast:source'][1]['@_contentType']).to.equal('application/x-bittorrent') + expect(alternateEnclosure['podcast:source'][2]['@_uri']).to.contain('magnet:?') + }) - expect(enclosure['@_type']).to.equal('video/webm') - expect(enclosure['@_length']).to.equal(218910) - expect(enclosure['@_url']).to.contain('-720.webm') - } - }) + it('Should contain a valid podcast:alternateEnclosure with HLS only', async function () { + const rss = await serverHLSOnly.feed.getPodcastXML({ ignoreCache: false, channelId: rootChannelId }) + expect(XMLValidator.validate(rss)).to.be.true - it('Should contain a valid \'attachments\' object (covers JSON feed 1.0 endpoint)', async function () { - for (const server of servers) { - const json = await server.feed.getJSON({ feed: 'videos', ignoreCache: true }) - const jsonObj = JSON.parse(json) - expect(jsonObj.items.length).to.be.equal(2) - expect(jsonObj.items[0].attachments).to.exist - expect(jsonObj.items[0].attachments.length).to.be.eq(1) - expect(jsonObj.items[0].attachments[0].mime_type).to.be.eq('application/x-bittorrent') - expect(jsonObj.items[0].attachments[0].size_in_bytes).to.be.eq(218910) - expect(jsonObj.items[0].attachments[0].url).to.contain('720.torrent') - } + const parser = new XMLParser({ parseAttributeValue: true, ignoreAttributes: false }) + const xmlDoc = parser.parse(rss) + + const enclosure = xmlDoc.rss.channel.item.enclosure + const alternateEnclosure = xmlDoc.rss.channel.item['podcast:alternateEnclosure'] + expect(alternateEnclosure).to.exist + + expect(alternateEnclosure['@_type']).to.equal('application/x-mpegURL') + expect(alternateEnclosure['@_lang']).to.equal('zh') + expect(alternateEnclosure['@_title']).to.equal('HLS') + expect(alternateEnclosure['@_default']).to.equal(true) + + expect(alternateEnclosure['podcast:source']['@_uri']).to.contain('-master.m3u8') + expect(alternateEnclosure['podcast:source']['@_uri']).to.equal(enclosure['@_url']) + }) + + it('Should contain a valid podcast:socialInteract', async function () { + const rss = await servers[0].feed.getPodcastXML({ ignoreCache: false, channelId: rootChannelId }) + expect(XMLValidator.validate(rss)).to.be.true + + const parser = new XMLParser({ parseAttributeValue: true, ignoreAttributes: false }) + const xmlDoc = parser.parse(rss) + + const item = xmlDoc.rss.channel.item + const socialInteract = item['podcast:socialInteract'] + expect(socialInteract).to.exist + expect(socialInteract['@_protocol']).to.equal('activitypub') + expect(socialInteract['@_uri']).to.exist + expect(socialInteract['@_accountUrl']).to.exist + }) + + it('Should contain a valid support custom tags for plugins', async function () { + const rss = await servers[0].feed.getPodcastXML({ ignoreCache: false, channelId: userChannelId }) + expect(XMLValidator.validate(rss)).to.be.true + + const parser = new XMLParser({ parseAttributeValue: true, ignoreAttributes: false }) + const xmlDoc = parser.parse(rss) + + const fooTag = xmlDoc.rss.channel.fooTag + expect(fooTag).to.exist + expect(fooTag['@_bar']).to.equal('baz') + expect(fooTag['#text']).to.equal(42) + + const bizzBuzzItem = xmlDoc.rss.channel['biz:buzzItem'] + expect(bizzBuzzItem).to.exist + + let nestedTag = bizzBuzzItem.nestedTag + expect(nestedTag).to.exist + expect(nestedTag).to.equal('example nested tag') + + const item = xmlDoc.rss.channel.item + const fizzTag = item.fizzTag + expect(fizzTag).to.exist + expect(fizzTag['@_bar']).to.equal('baz') + expect(fizzTag['#text']).to.equal(21) + + const bizzBuzz = item['biz:buzz'] + expect(bizzBuzz).to.exist + + nestedTag = bizzBuzz.nestedTag + expect(nestedTag).to.exist + expect(nestedTag).to.equal('example nested tag') + }) + + it('Should contain a valid podcast:liveItem for live streams', async function () { + this.timeout(120000) + + const { uuid } = await servers[0].live.create({ + fields: { + name: 'live-0', + privacy: VideoPrivacy.PUBLIC, + channelId: rootChannelId, + permanentLive: false + } + }) + liveId = uuid + + const ffmpeg = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveId, copyCodecs: true, fixtureName: 'video_short.mp4' }) + await servers[0].live.waitUntilPublished({ videoId: liveId }) + + const rss = await servers[0].feed.getPodcastXML({ ignoreCache: false, channelId: rootChannelId }) + expect(XMLValidator.validate(rss)).to.be.true + + const parser = new XMLParser({ parseAttributeValue: true, ignoreAttributes: false }) + const xmlDoc = parser.parse(rss) + const liveItem = xmlDoc.rss.channel['podcast:liveItem'] + expect(liveItem.title).to.equal('live-0') + expect(liveItem['@_status']).to.equal('live') + + const enclosure = liveItem.enclosure + const alternateEnclosure = liveItem['podcast:alternateEnclosure'] + expect(alternateEnclosure).to.exist + expect(alternateEnclosure['@_type']).to.equal('application/x-mpegURL') + expect(alternateEnclosure['@_title']).to.equal('HLS live stream') + expect(alternateEnclosure['@_default']).to.equal(true) + + expect(alternateEnclosure['podcast:source']['@_uri']).to.contain('/master.m3u8') + expect(alternateEnclosure['podcast:source']['@_uri']).to.equal(enclosure['@_url']) + + await stopFfmpeg(ffmpeg) + + await servers[0].live.waitUntilEnded({ videoId: liveId }) + + await waitJobs(servers) + }) }) - it('Should filter by account', async function () { - { - const json = await servers[0].feed.getJSON({ feed: 'videos', query: { accountId: rootAccountId }, ignoreCache: true }) - const jsonObj = JSON.parse(json) - expect(jsonObj.items.length).to.be.equal(1) - expect(jsonObj.items[0].title).to.equal('my super name for server 1') - expect(jsonObj.items[0].author.name).to.equal('Main root channel') - } + describe('JSON feed', function () { - { - const json = await servers[0].feed.getJSON({ feed: 'videos', query: { accountId: userAccountId }, ignoreCache: true }) - const jsonObj = JSON.parse(json) - expect(jsonObj.items.length).to.be.equal(1) - expect(jsonObj.items[0].title).to.equal('user video') - expect(jsonObj.items[0].author.name).to.equal('Main john channel') - } + it('Should contain a valid \'attachments\' object', async function () { + for (const server of servers) { + const json = await server.feed.getJSON({ feed: 'videos', ignoreCache: true }) + const jsonObj = JSON.parse(json) + expect(jsonObj.items.length).to.be.equal(2) + expect(jsonObj.items[0].attachments).to.exist + expect(jsonObj.items[0].attachments.length).to.be.eq(1) + expect(jsonObj.items[0].attachments[0].mime_type).to.be.eq('application/x-bittorrent') + expect(jsonObj.items[0].attachments[0].size_in_bytes).to.be.eq(218910) + expect(jsonObj.items[0].attachments[0].url).to.contain('720.torrent') + } + }) - for (const server of servers) { + it('Should filter by account', async function () { { - const json = await server.feed.getJSON({ feed: 'videos', query: { accountName: 'root@' + servers[0].host }, ignoreCache: true }) + const json = await servers[0].feed.getJSON({ feed: 'videos', query: { accountId: rootAccountId }, ignoreCache: true }) const jsonObj = JSON.parse(json) expect(jsonObj.items.length).to.be.equal(1) expect(jsonObj.items[0].title).to.equal('my super name for server 1') + expect(jsonObj.items[0].author.name).to.equal('Main root channel') } { - const json = await server.feed.getJSON({ feed: 'videos', query: { accountName: 'john@' + servers[0].host }, ignoreCache: true }) + const json = await servers[0].feed.getJSON({ feed: 'videos', query: { accountId: userAccountId }, ignoreCache: true }) const jsonObj = JSON.parse(json) expect(jsonObj.items.length).to.be.equal(1) expect(jsonObj.items[0].title).to.equal('user video') + expect(jsonObj.items[0].author.name).to.equal('Main john channel') } - } - }) - it('Should filter by video channel', async function () { - { - const json = await servers[0].feed.getJSON({ feed: 'videos', query: { videoChannelId: rootChannelId }, ignoreCache: true }) - const jsonObj = JSON.parse(json) - expect(jsonObj.items.length).to.be.equal(1) - expect(jsonObj.items[0].title).to.equal('my super name for server 1') - expect(jsonObj.items[0].author.name).to.equal('Main root channel') - } - - { - const json = await servers[0].feed.getJSON({ feed: 'videos', query: { videoChannelId: userChannelId }, ignoreCache: true }) - const jsonObj = JSON.parse(json) - expect(jsonObj.items.length).to.be.equal(1) - expect(jsonObj.items[0].title).to.equal('user video') - expect(jsonObj.items[0].author.name).to.equal('Main john channel') - } + for (const server of servers) { + { + const json = await server.feed.getJSON({ feed: 'videos', query: { accountName: 'root@' + servers[0].host }, ignoreCache: true }) + const jsonObj = JSON.parse(json) + expect(jsonObj.items.length).to.be.equal(1) + expect(jsonObj.items[0].title).to.equal('my super name for server 1') + } + + { + const json = await server.feed.getJSON({ feed: 'videos', query: { accountName: 'john@' + servers[0].host }, ignoreCache: true }) + const jsonObj = JSON.parse(json) + expect(jsonObj.items.length).to.be.equal(1) + expect(jsonObj.items[0].title).to.equal('user video') + } + } + }) - for (const server of servers) { + it('Should filter by video channel', async function () { { - const query = { videoChannelName: 'root_channel@' + servers[0].host } - const json = await server.feed.getJSON({ feed: 'videos', query, ignoreCache: true }) + const json = await servers[0].feed.getJSON({ feed: 'videos', query: { videoChannelId: rootChannelId }, ignoreCache: true }) const jsonObj = JSON.parse(json) expect(jsonObj.items.length).to.be.equal(1) expect(jsonObj.items[0].title).to.equal('my super name for server 1') + expect(jsonObj.items[0].author.name).to.equal('Main root channel') } { - const query = { videoChannelName: 'john_channel@' + servers[0].host } - const json = await server.feed.getJSON({ feed: 'videos', query, ignoreCache: true }) + const json = await servers[0].feed.getJSON({ feed: 'videos', query: { videoChannelId: userChannelId }, ignoreCache: true }) const jsonObj = JSON.parse(json) expect(jsonObj.items.length).to.be.equal(1) expect(jsonObj.items[0].title).to.equal('user video') + expect(jsonObj.items[0].author.name).to.equal('Main john channel') } - } - }) - it('Should correctly have videos feed with HLS only', async function () { - this.timeout(120000) - - await serverHLSOnly.videos.upload({ attributes: { name: 'hls only video' } }) + for (const server of servers) { + { + const query = { videoChannelName: 'root_channel@' + servers[0].host } + const json = await server.feed.getJSON({ feed: 'videos', query, ignoreCache: true }) + const jsonObj = JSON.parse(json) + expect(jsonObj.items.length).to.be.equal(1) + expect(jsonObj.items[0].title).to.equal('my super name for server 1') + } + + { + const query = { videoChannelName: 'john_channel@' + servers[0].host } + const json = await server.feed.getJSON({ feed: 'videos', query, ignoreCache: true }) + const jsonObj = JSON.parse(json) + expect(jsonObj.items.length).to.be.equal(1) + expect(jsonObj.items[0].title).to.equal('user video') + } + } + }) - await waitJobs([ serverHLSOnly ]) + it('Should correctly have videos feed with HLS only', async function () { + this.timeout(120000) - const json = await serverHLSOnly.feed.getJSON({ feed: 'videos', ignoreCache: true }) - const jsonObj = JSON.parse(json) - expect(jsonObj.items.length).to.be.equal(1) - expect(jsonObj.items[0].attachments).to.exist - expect(jsonObj.items[0].attachments.length).to.be.eq(4) - - for (let i = 0; i < 4; i++) { - expect(jsonObj.items[0].attachments[i].mime_type).to.be.eq('application/x-bittorrent') - expect(jsonObj.items[0].attachments[i].size_in_bytes).to.be.greaterThan(0) - expect(jsonObj.items[0].attachments[i].url).to.exist - } - }) + const json = await serverHLSOnly.feed.getJSON({ feed: 'videos', ignoreCache: true }) + const jsonObj = JSON.parse(json) + expect(jsonObj.items.length).to.be.equal(1) + expect(jsonObj.items[0].attachments).to.exist + expect(jsonObj.items[0].attachments.length).to.be.eq(4) - it('Should not display waiting live videos', async function () { - const { uuid } = await servers[0].live.create({ - fields: { - name: 'live', - privacy: VideoPrivacy.PUBLIC, - channelId: rootChannelId + for (let i = 0; i < 4; i++) { + expect(jsonObj.items[0].attachments[i].mime_type).to.be.eq('application/x-bittorrent') + expect(jsonObj.items[0].attachments[i].size_in_bytes).to.be.greaterThan(0) + expect(jsonObj.items[0].attachments[i].url).to.exist } }) - liveId = uuid - const json = await servers[0].feed.getJSON({ feed: 'videos', ignoreCache: true }) + it('Should not display waiting live videos', async function () { + const { uuid } = await servers[0].live.create({ + fields: { + name: 'live', + privacy: VideoPrivacy.PUBLIC, + channelId: rootChannelId + } + }) + liveId = uuid - const jsonObj = JSON.parse(json) - expect(jsonObj.items.length).to.be.equal(2) - expect(jsonObj.items[0].title).to.equal('my super name for server 1') - expect(jsonObj.items[1].title).to.equal('user video') - }) + const json = await servers[0].feed.getJSON({ feed: 'videos', ignoreCache: true }) + + const jsonObj = JSON.parse(json) + expect(jsonObj.items.length).to.be.equal(2) + expect(jsonObj.items[0].title).to.equal('my super name for server 1') + expect(jsonObj.items[1].title).to.equal('user video') + }) - it('Should display published live videos', async function () { - this.timeout(120000) + it('Should display published live videos', async function () { + this.timeout(120000) - const ffmpeg = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveId, copyCodecs: true, fixtureName: 'video_short.mp4' }) - await servers[0].live.waitUntilPublished({ videoId: liveId }) + const ffmpeg = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveId, copyCodecs: true, fixtureName: 'video_short.mp4' }) + await servers[0].live.waitUntilPublished({ videoId: liveId }) - const json = await servers[0].feed.getJSON({ feed: 'videos', ignoreCache: true }) + const json = await servers[0].feed.getJSON({ feed: 'videos', ignoreCache: true }) - const jsonObj = JSON.parse(json) - expect(jsonObj.items.length).to.be.equal(3) - expect(jsonObj.items[0].title).to.equal('live') - expect(jsonObj.items[1].title).to.equal('my super name for server 1') - expect(jsonObj.items[2].title).to.equal('user video') + const jsonObj = JSON.parse(json) + expect(jsonObj.items.length).to.be.equal(3) + expect(jsonObj.items[0].title).to.equal('live') + expect(jsonObj.items[1].title).to.equal('my super name for server 1') + expect(jsonObj.items[2].title).to.equal('user video') - await stopFfmpeg(ffmpeg) - }) + await stopFfmpeg(ffmpeg) + }) - it('Should have the channel avatar as feed icon', async function () { - const json = await servers[0].feed.getJSON({ feed: 'videos', query: { videoChannelId: rootChannelId }, ignoreCache: true }) + it('Should have the channel avatar as feed icon', async function () { + const json = await servers[0].feed.getJSON({ feed: 'videos', query: { videoChannelId: rootChannelId }, ignoreCache: true }) - const jsonObj = JSON.parse(json) - const imageUrl = jsonObj.icon - expect(imageUrl).to.include('/lazy-static/avatars/') - await makeRawRequest({ url: imageUrl, expectedStatus: HttpStatusCode.OK_200 }) + const jsonObj = JSON.parse(json) + const imageUrl = jsonObj.icon + expect(imageUrl).to.include('/lazy-static/avatars/') + await makeRawRequest({ url: imageUrl, expectedStatus: HttpStatusCode.OK_200 }) + }) }) }) @@ -470,6 +605,8 @@ describe('Test syndication feeds', () => { }) after(async function () { + await servers[0].plugins.uninstall({ npmName: 'peertube-plugin-test-podcast-custom-tags' }) + await cleanupTests([ ...servers, serverHLSOnly ]) }) }) diff --git a/server/tests/fixtures/peertube-plugin-test-podcast-custom-tags/main.js b/server/tests/fixtures/peertube-plugin-test-podcast-custom-tags/main.js new file mode 100644 index 000000000..ada4a70fe --- /dev/null +++ b/server/tests/fixtures/peertube-plugin-test-podcast-custom-tags/main.js @@ -0,0 +1,82 @@ +async function register ({ registerHook, registerSetting, settingsManager, storageManager, peertubeHelpers }) { + registerHook({ + target: 'filter:feed.podcast.rss.create-custom-xmlns.result', + handler: (result, params) => { + return result.concat([ + { + name: "biz", + value: "https://example.com/biz-xmlns", + }, + ]) + } + }) + + registerHook({ + target: 'filter:feed.podcast.channel.create-custom-tags.result', + handler: (result, params) => { + const { videoChannel } = params + return result.concat([ + { + name: "fooTag", + attributes: { "bar": "baz" }, + value: "42", + }, + { + name: "biz:videoChannel", + attributes: { "name": videoChannel.name, "id": videoChannel.id }, + }, + { + name: "biz:buzzItem", + value: [ + { + name: "nestedTag", + value: "example nested tag", + }, + ], + }, + ]) + } + }) + + registerHook({ + target: 'filter:feed.podcast.video.create-custom-tags.result', + handler: (result, params) => { + const { video, liveItem } = params + return result.concat([ + { + name: "fizzTag", + attributes: { "bar": "baz" }, + value: "21", + }, + { + name: "biz:video", + attributes: { "name": video.name, "id": video.id, "isLive": liveItem }, + }, + { + name: "biz:buzz", + value: [ + { + name: "nestedTag", + value: "example nested tag", + }, + ], + } + ]) + } + }) +} + +async function unregister () { + return +} + +module.exports = { + register, + unregister +} + +// ############################################################################ + +function addToCount (obj) { + return Object.assign({}, obj, { count: obj.count + 1 }) +} diff --git a/server/tests/fixtures/peertube-plugin-test-podcast-custom-tags/package.json b/server/tests/fixtures/peertube-plugin-test-podcast-custom-tags/package.json new file mode 100644 index 000000000..0f5a05a79 --- /dev/null +++ b/server/tests/fixtures/peertube-plugin-test-podcast-custom-tags/package.json @@ -0,0 +1,19 @@ +{ + "name": "peertube-plugin-test-podcast-custom-tags", + "version": "0.0.1", + "description": "Plugin test custom tags in Podcast RSS feeds", + "engine": { + "peertube": ">=1.3.0" + }, + "keywords": [ + "peertube", + "plugin" + ], + "homepage": "https://github.com/Chocobozzz/PeerTube", + "author": "Chocobozzz", + "bugs": "https://github.com/Chocobozzz/PeerTube/issues", + "library": "./main.js", + "staticDirs": {}, + "css": [], + "clientScripts": [] +} diff --git a/server/tests/fixtures/peertube-plugin-test/main.js b/server/tests/fixtures/peertube-plugin-test/main.js index 36dd08d27..17032f6d9 100644 --- a/server/tests/fixtures/peertube-plugin-test/main.js +++ b/server/tests/fixtures/peertube-plugin-test/main.js @@ -14,6 +14,7 @@ async function register ({ registerHook, registerSetting, settingsManager, stora 'action:api.video-channel.deleted', 'action:api.live-video.created', + 'action:live.video.state.updated', 'action:api.video-thread.created', 'action:api.video-comment-reply.created', diff --git a/server/tests/plugins/action-hooks.ts b/server/tests/plugins/action-hooks.ts index e8d03ee0f..34b4e1891 100644 --- a/server/tests/plugins/action-hooks.ts +++ b/server/tests/plugins/action-hooks.ts @@ -9,7 +9,9 @@ import { PeerTubeServer, PluginsCommand, setAccessTokensToServers, - setDefaultVideoChannel + setDefaultVideoChannel, + stopFfmpeg, + waitJobs } from '@shared/server-commands' describe('Test plugin action hooks', function () { @@ -17,8 +19,8 @@ describe('Test plugin action hooks', function () { let videoUUID: string let threadId: number - function checkHook (hook: ServerHookName, strictCount = true) { - return servers[0].servers.waitUntilLog('Run hook ' + hook, 1, strictCount) + function checkHook (hook: ServerHookName, strictCount = true, count = 1) { + return servers[0].servers.waitUntilLog('Run hook ' + hook, count, strictCount) } before(async function () { @@ -115,6 +117,29 @@ describe('Test plugin action hooks', function () { await checkHook('action:api.live-video.created') }) + + it('Should run action:live.video.state.updated', async function () { + this.timeout(60000) + + const attributes = { + name: 'live', + privacy: VideoPrivacy.PUBLIC, + channelId: servers[0].store.channel.id + } + + const { uuid: liveVideoId } = await servers[0].live.create({ fields: attributes }) + const ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoId }) + await servers[0].live.waitUntilPublished({ videoId: liveVideoId }) + await waitJobs(servers) + + await checkHook('action:live.video.state.updated', true, 1) + + await stopFfmpeg(ffmpegCommand) + await servers[0].live.waitUntilEnded({ videoId: liveVideoId }) + await waitJobs(servers) + + await checkHook('action:live.video.state.updated', true, 2) + }) }) describe('Comments hooks', function () { -- cgit v1.2.3