aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/videos/channel-import-videos.ts
blob: a66f88a0ec13f3777334f63c64d89322b32a6b51 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */

import { expect } from 'chai'
import { FIXTURE_URLS } from '@server/tests/shared'
import { areHttpImportTestsDisabled } from '@shared/core-utils'
import {
  createSingleServer,
  getServerImportConfig,
  PeerTubeServer,
  setAccessTokensToServers,
  setDefaultVideoChannel,
  waitJobs
} from '@shared/server-commands'

describe('Test videos import in a channel', function () {
  if (areHttpImportTestsDisabled()) return

  function runSuite (mode: 'youtube-dl' | 'yt-dlp') {

    describe('Import using ' + mode, function () {
      let server: PeerTubeServer

      before(async function () {
        this.timeout(120_000)

        server = await createSingleServer(1, getServerImportConfig(mode))

        await setAccessTokensToServers([ server ])
        await setDefaultVideoChannel([ server ])

        await server.config.enableChannelSync()
      })

      it('Should import a whole channel without specifying the sync id', async function () {
        this.timeout(240_000)

        await server.channels.importVideos({ channelName: server.store.channel.name, externalChannelUrl: FIXTURE_URLS.youtubeChannel })
        await waitJobs(server)

        const videos = await server.videos.listByChannel({ handle: server.store.channel.name })
        expect(videos.total).to.equal(2)
      })

      it('These imports should not have a sync id', async function () {
        const { total, data } = await server.imports.getMyVideoImports()

        expect(total).to.equal(2)
        expect(data).to.have.lengthOf(2)

        for (const videoImport of data) {
          expect(videoImport.videoChannelSync).to.not.exist
        }
      })

      it('Should import a whole channel and specifying the sync id', async function () {
        this.timeout(240_000)

        {
          server.store.channel.name = 'channel2'
          const { id } = await server.channels.create({ attributes: { name: server.store.channel.name } })
          server.store.channel.id = id
        }

        {
          const attributes = {
            externalChannelUrl: FIXTURE_URLS.youtubeChannel,
            videoChannelId: server.store.channel.id
          }

          const { videoChannelSync } = await server.channelSyncs.create({ attributes })
          server.store.videoChannelSync = videoChannelSync

          await waitJobs(server)
        }

        await server.channels.importVideos({
          channelName: server.store.channel.name,
          externalChannelUrl: FIXTURE_URLS.youtubeChannel,
          videoChannelSyncId: server.store.videoChannelSync.id
        })

        await waitJobs(server)
      })

      it('These imports should have a sync id', async function () {
        const { total, data } = await server.imports.getMyVideoImports()

        expect(total).to.equal(4)
        expect(data).to.have.lengthOf(4)

        const importsWithSyncId = data.filter(i => !!i.videoChannelSync)
        expect(importsWithSyncId).to.have.lengthOf(2)

        for (const videoImport of importsWithSyncId) {
          expect(videoImport.videoChannelSync).to.exist
          expect(videoImport.videoChannelSync.id).to.equal(server.store.videoChannelSync.id)
        }
      })

      it('Should be able to filter imports by this sync id', async function () {
        const { total, data } = await server.imports.getMyVideoImports({ videoChannelSyncId: server.store.videoChannelSync.id })

        expect(total).to.equal(2)
        expect(data).to.have.lengthOf(2)

        for (const videoImport of data) {
          expect(videoImport.videoChannelSync).to.exist
          expect(videoImport.videoChannelSync.id).to.equal(server.store.videoChannelSync.id)
        }
      })

      it('Should limit max amount of videos synced on full sync', async function () {
        this.timeout(240_000)

        await server.kill()
        await server.run({
          import: {
            video_channel_synchronization: {
              full_sync_videos_limit: 1
            }
          }
        })

        const { id } = await server.channels.create({ attributes: { name: 'channel3' } })
        const channel3Id = id

        const { videoChannelSync } = await server.channelSyncs.create({
          attributes: {
            externalChannelUrl: FIXTURE_URLS.youtubeChannel,
            videoChannelId: channel3Id
          }
        })
        const syncId = videoChannelSync.id

        await waitJobs(server)

        await server.channels.importVideos({
          channelName: 'channel3',
          externalChannelUrl: FIXTURE_URLS.youtubeChannel,
          videoChannelSyncId: syncId
        })

        await waitJobs(server)

        const { total, data } = await server.videos.listByChannel({ handle: 'channel3' })

        expect(total).to.equal(1)
        expect(data).to.have.lengthOf(1)
      })

      after(async function () {
        await server?.kill()
      })
    })
  }

  runSuite('yt-dlp')

  // FIXME: With recent changes on youtube, youtube-dl doesn't fetch live replays which means the test suite fails
  // runSuite('youtube-dl')
})