channel-import-videos.ts 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
  2. import { expect } from 'chai'
  3. import { FIXTURE_URLS } from '@server/tests/shared'
  4. import { areHttpImportTestsDisabled } from '@shared/core-utils'
  5. import {
  6. createSingleServer,
  7. getServerImportConfig,
  8. PeerTubeServer,
  9. setAccessTokensToServers,
  10. setDefaultVideoChannel,
  11. waitJobs
  12. } from '@shared/server-commands'
  13. describe('Test videos import in a channel', function () {
  14. if (areHttpImportTestsDisabled()) return
  15. function runSuite (mode: 'youtube-dl' | 'yt-dlp') {
  16. describe('Import using ' + mode, function () {
  17. let server: PeerTubeServer
  18. before(async function () {
  19. this.timeout(120_000)
  20. server = await createSingleServer(1, getServerImportConfig(mode))
  21. await setAccessTokensToServers([ server ])
  22. await setDefaultVideoChannel([ server ])
  23. await server.config.enableChannelSync()
  24. })
  25. it('Should import a whole channel without specifying the sync id', async function () {
  26. this.timeout(240_000)
  27. await server.channels.importVideos({ channelName: server.store.channel.name, externalChannelUrl: FIXTURE_URLS.youtubeChannel })
  28. await waitJobs(server)
  29. const videos = await server.videos.listByChannel({ handle: server.store.channel.name })
  30. expect(videos.total).to.equal(2)
  31. })
  32. it('These imports should not have a sync id', async function () {
  33. const { total, data } = await server.imports.getMyVideoImports()
  34. expect(total).to.equal(2)
  35. expect(data).to.have.lengthOf(2)
  36. for (const videoImport of data) {
  37. expect(videoImport.videoChannelSync).to.not.exist
  38. }
  39. })
  40. it('Should import a whole channel and specifying the sync id', async function () {
  41. this.timeout(240_000)
  42. {
  43. server.store.channel.name = 'channel2'
  44. const { id } = await server.channels.create({ attributes: { name: server.store.channel.name } })
  45. server.store.channel.id = id
  46. }
  47. {
  48. const attributes = {
  49. externalChannelUrl: FIXTURE_URLS.youtubeChannel,
  50. videoChannelId: server.store.channel.id
  51. }
  52. const { videoChannelSync } = await server.channelSyncs.create({ attributes })
  53. server.store.videoChannelSync = videoChannelSync
  54. await waitJobs(server)
  55. }
  56. await server.channels.importVideos({
  57. channelName: server.store.channel.name,
  58. externalChannelUrl: FIXTURE_URLS.youtubeChannel,
  59. videoChannelSyncId: server.store.videoChannelSync.id
  60. })
  61. await waitJobs(server)
  62. })
  63. it('These imports should have a sync id', async function () {
  64. const { total, data } = await server.imports.getMyVideoImports()
  65. expect(total).to.equal(4)
  66. expect(data).to.have.lengthOf(4)
  67. const importsWithSyncId = data.filter(i => !!i.videoChannelSync)
  68. expect(importsWithSyncId).to.have.lengthOf(2)
  69. for (const videoImport of importsWithSyncId) {
  70. expect(videoImport.videoChannelSync).to.exist
  71. expect(videoImport.videoChannelSync.id).to.equal(server.store.videoChannelSync.id)
  72. }
  73. })
  74. it('Should be able to filter imports by this sync id', async function () {
  75. const { total, data } = await server.imports.getMyVideoImports({ videoChannelSyncId: server.store.videoChannelSync.id })
  76. expect(total).to.equal(2)
  77. expect(data).to.have.lengthOf(2)
  78. for (const videoImport of data) {
  79. expect(videoImport.videoChannelSync).to.exist
  80. expect(videoImport.videoChannelSync.id).to.equal(server.store.videoChannelSync.id)
  81. }
  82. })
  83. it('Should limit max amount of videos synced on full sync', async function () {
  84. this.timeout(240_000)
  85. await server.kill()
  86. await server.run({
  87. import: {
  88. video_channel_synchronization: {
  89. full_sync_videos_limit: 1
  90. }
  91. }
  92. })
  93. const { id } = await server.channels.create({ attributes: { name: 'channel3' } })
  94. const channel3Id = id
  95. const { videoChannelSync } = await server.channelSyncs.create({
  96. attributes: {
  97. externalChannelUrl: FIXTURE_URLS.youtubeChannel,
  98. videoChannelId: channel3Id
  99. }
  100. })
  101. const syncId = videoChannelSync.id
  102. await waitJobs(server)
  103. await server.channels.importVideos({
  104. channelName: 'channel3',
  105. externalChannelUrl: FIXTURE_URLS.youtubeChannel,
  106. videoChannelSyncId: syncId
  107. })
  108. await waitJobs(server)
  109. const { total, data } = await server.videos.listByChannel({ handle: 'channel3' })
  110. expect(total).to.equal(1)
  111. expect(data).to.have.lengthOf(1)
  112. })
  113. after(async function () {
  114. await server?.kill()
  115. })
  116. })
  117. }
  118. runSuite('yt-dlp')
  119. // FIXME: With recent changes on youtube, youtube-dl doesn't fetch live replays which means the test suite fails
  120. // runSuite('youtube-dl')
  121. })