]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
590fb506 C |
2 | |
3 | import * as chai from 'chai' | |
4 | import 'mocha' | |
ba6e9e8f | 5 | import { VideoDetails, VideoImport, VideoPrivacy, VideoCaption } from '../../../../shared/models/videos' |
590fb506 | 6 | import { |
7c3b7976 | 7 | cleanupTests, |
590fb506 C |
8 | doubleFollow, |
9 | flushAndRunMultipleServers, | |
10 | getMyUserInformation, | |
11 | getMyVideos, | |
12 | getVideo, | |
13 | getVideosList, | |
ba6e9e8f | 14 | listVideoCaptions, |
15 | testCaptionFile, | |
3e17515e | 16 | immutableAssign, |
590fb506 C |
17 | ServerInfo, |
18 | setAccessTokensToServers | |
94565d52 C |
19 | } from '../../../../shared/extra-utils' |
20 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' | |
a1587156 | 21 | import { getMagnetURI, getMyVideoImports, getYoutubeVideoUrl, importVideo } from '../../../../shared/extra-utils/videos/video-imports' |
b1770a0a | 22 | import { testImage } from '../../../../shared/extra-utils/miscs/miscs' |
590fb506 C |
23 | |
24 | const expect = chai.expect | |
25 | ||
26 | describe('Test video imports', function () { | |
27 | let servers: ServerInfo[] = [] | |
28 | let channelIdServer1: number | |
29 | let channelIdServer2: number | |
30 | ||
3e17515e C |
31 | async function checkVideosServer1 (url: string, idHttp: string, idMagnet: string, idTorrent: string) { |
32 | const resHttp = await getVideo(url, idHttp) | |
33 | const videoHttp: VideoDetails = resHttp.body | |
34 | ||
35 | expect(videoHttp.name).to.equal('small video - youtube') | |
f9b6d51f C |
36 | // FIXME: youtube-dl seems broken |
37 | // expect(videoHttp.category.label).to.equal('News & Politics') | |
3e17515e C |
38 | expect(videoHttp.licence.label).to.equal('Attribution') |
39 | expect(videoHttp.language.label).to.equal('Unknown') | |
40 | expect(videoHttp.nsfw).to.be.false | |
41 | expect(videoHttp.description).to.equal('this is a super description') | |
42 | expect(videoHttp.tags).to.deep.equal([ 'tag1', 'tag2' ]) | |
43 | expect(videoHttp.files).to.have.lengthOf(1) | |
17036be5 C |
44 | |
45 | const originallyPublishedAt = new Date(videoHttp.originallyPublishedAt) | |
46 | expect(originallyPublishedAt.getDate()).to.equal(14) | |
47 | expect(originallyPublishedAt.getMonth()).to.equal(0) | |
48 | expect(originallyPublishedAt.getFullYear()).to.equal(2019) | |
3e17515e C |
49 | |
50 | const resMagnet = await getVideo(url, idMagnet) | |
51 | const videoMagnet: VideoDetails = resMagnet.body | |
52 | const resTorrent = await getVideo(url, idTorrent) | |
53 | const videoTorrent: VideoDetails = resTorrent.body | |
54 | ||
55 | for (const video of [ videoMagnet, videoTorrent ]) { | |
56 | expect(video.category.label).to.equal('Misc') | |
57 | expect(video.licence.label).to.equal('Unknown') | |
58 | expect(video.language.label).to.equal('Unknown') | |
59 | expect(video.nsfw).to.be.false | |
60 | expect(video.description).to.equal('this is a super torrent description') | |
61 | expect(video.tags).to.deep.equal([ 'tag_torrent1', 'tag_torrent2' ]) | |
62 | expect(video.files).to.have.lengthOf(1) | |
63 | } | |
590fb506 | 64 | |
3e17515e C |
65 | expect(videoTorrent.name).to.contain('你好 世界 720p.mp4') |
66 | expect(videoMagnet.name).to.contain('super peertube2 video') | |
652c6416 C |
67 | |
68 | const resCaptions = await listVideoCaptions(url, idHttp) | |
69 | expect(resCaptions.body.total).to.equal(2) | |
590fb506 C |
70 | } |
71 | ||
72 | async function checkVideoServer2 (url: string, id: number | string) { | |
73 | const res = await getVideo(url, id) | |
652c6416 | 74 | const video: VideoDetails = res.body |
590fb506 C |
75 | |
76 | expect(video.name).to.equal('my super name') | |
77 | expect(video.category.label).to.equal('Entertainment') | |
78 | expect(video.licence.label).to.equal('Public Domain Dedication') | |
79 | expect(video.language.label).to.equal('English') | |
80 | expect(video.nsfw).to.be.false | |
81 | expect(video.description).to.equal('my super description') | |
82 | expect(video.tags).to.deep.equal([ 'supertag1', 'supertag2' ]) | |
83 | ||
84 | expect(video.files).to.have.lengthOf(1) | |
652c6416 C |
85 | |
86 | const resCaptions = await listVideoCaptions(url, id) | |
87 | expect(resCaptions.body.total).to.equal(2) | |
590fb506 C |
88 | } |
89 | ||
90 | before(async function () { | |
91 | this.timeout(30000) | |
92 | ||
93 | // Run servers | |
94 | servers = await flushAndRunMultipleServers(2) | |
95 | ||
96 | await setAccessTokensToServers(servers) | |
97 | ||
98 | { | |
99 | const res = await getMyUserInformation(servers[0].url, servers[0].accessToken) | |
a1587156 | 100 | channelIdServer1 = res.body.videoChannels[0].id |
590fb506 C |
101 | } |
102 | ||
103 | { | |
104 | const res = await getMyUserInformation(servers[1].url, servers[1].accessToken) | |
a1587156 | 105 | channelIdServer2 = res.body.videoChannels[0].id |
590fb506 C |
106 | } |
107 | ||
108 | await doubleFollow(servers[0], servers[1]) | |
109 | }) | |
110 | ||
3e17515e | 111 | it('Should import videos on server 1', async function () { |
590fb506 C |
112 | this.timeout(60000) |
113 | ||
3e17515e | 114 | const baseAttributes = { |
590fb506 C |
115 | channelId: channelIdServer1, |
116 | privacy: VideoPrivacy.PUBLIC | |
117 | } | |
3e17515e C |
118 | |
119 | { | |
120 | const attributes = immutableAssign(baseAttributes, { targetUrl: getYoutubeVideoUrl() }) | |
121 | const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) | |
122 | expect(res.body.video.name).to.equal('small video - youtube') | |
b1770a0a K |
123 | expect(res.body.video.thumbnailPath).to.equal(`/static/thumbnails/${res.body.video.uuid}.jpg`) |
124 | expect(res.body.video.previewPath).to.equal(`/static/previews/${res.body.video.uuid}.jpg`) | |
125 | await testImage(servers[0].url, 'video_import_thumbnail', res.body.video.thumbnailPath) | |
126 | await testImage(servers[0].url, 'video_import_preview', res.body.video.previewPath) | |
ba6e9e8f | 127 | |
128 | const resCaptions = await listVideoCaptions(servers[0].url, res.body.video.id) | |
652c6416 | 129 | const videoCaptions: VideoCaption[] = resCaptions.body.data |
ba6e9e8f | 130 | expect(videoCaptions).to.have.lengthOf(2) |
131 | ||
652c6416 C |
132 | const enCaption = videoCaptions.find(caption => caption.language.id === 'en') |
133 | expect(enCaption).to.exist | |
134 | expect(enCaption.language.label).to.equal('English') | |
ba6e9e8f | 135 | expect(enCaption.captionPath).to.equal(`/static/video-captions/${res.body.video.uuid}-en.vtt`) |
136 | await testCaptionFile(servers[0].url, enCaption.captionPath, `WEBVTT | |
652c6416 C |
137 | Kind: captions |
138 | Language: en | |
ba6e9e8f | 139 | |
652c6416 C |
140 | 00:00:01.600 --> 00:00:04.200 |
141 | English (US) | |
ba6e9e8f | 142 | |
652c6416 C |
143 | 00:00:05.900 --> 00:00:07.999 |
144 | This is a subtitle in American English | |
ba6e9e8f | 145 | |
652c6416 C |
146 | 00:00:10.000 --> 00:00:14.000 |
147 | Adding subtitles is very easy to do`) | |
ba6e9e8f | 148 | |
652c6416 C |
149 | const frCaption = videoCaptions.find(caption => caption.language.id === 'fr') |
150 | expect(frCaption).to.exist | |
151 | expect(frCaption.language.label).to.equal('French') | |
152 | expect(frCaption.captionPath).to.equal(`/static/video-captions/${res.body.video.uuid}-fr.vtt`) | |
ba6e9e8f | 153 | await testCaptionFile(servers[0].url, frCaption.captionPath, `WEBVTT |
652c6416 C |
154 | Kind: captions |
155 | Language: fr | |
ba6e9e8f | 156 | |
652c6416 C |
157 | 00:00:01.600 --> 00:00:04.200 |
158 | Français (FR) | |
ba6e9e8f | 159 | |
652c6416 C |
160 | 00:00:05.900 --> 00:00:07.999 |
161 | C'est un sous-titre français | |
ba6e9e8f | 162 | |
652c6416 C |
163 | 00:00:10.000 --> 00:00:14.000 |
164 | Ajouter un sous-titre est vraiment facile`) | |
3e17515e C |
165 | } |
166 | ||
167 | { | |
168 | const attributes = immutableAssign(baseAttributes, { | |
169 | magnetUri: getMagnetURI(), | |
170 | description: 'this is a super torrent description', | |
171 | tags: [ 'tag_torrent1', 'tag_torrent2' ] | |
172 | }) | |
173 | const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) | |
174 | expect(res.body.video.name).to.equal('super peertube2 video') | |
175 | } | |
176 | ||
177 | { | |
178 | const attributes = immutableAssign(baseAttributes, { | |
9a7fd960 | 179 | torrentfile: 'video-720p.torrent' as any, |
3e17515e C |
180 | description: 'this is a super torrent description', |
181 | tags: [ 'tag_torrent1', 'tag_torrent2' ] | |
182 | }) | |
183 | const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) | |
184 | expect(res.body.video.name).to.equal('你好 世界 720p.mp4') | |
185 | } | |
590fb506 C |
186 | }) |
187 | ||
3e17515e C |
188 | it('Should list the videos to import in my videos on server 1', async function () { |
189 | const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 5, 'createdAt') | |
590fb506 | 190 | |
3e17515e | 191 | expect(res.body.total).to.equal(3) |
590fb506 C |
192 | |
193 | const videos = res.body.data | |
3e17515e | 194 | expect(videos).to.have.lengthOf(3) |
590fb506 | 195 | expect(videos[0].name).to.equal('small video - youtube') |
3e17515e C |
196 | expect(videos[1].name).to.equal('super peertube2 video') |
197 | expect(videos[2].name).to.equal('你好 世界 720p.mp4') | |
590fb506 C |
198 | }) |
199 | ||
3e17515e C |
200 | it('Should list the videos to import in my imports on server 1', async function () { |
201 | const res = await getMyVideoImports(servers[0].url, servers[0].accessToken, '-createdAt') | |
202 | ||
203 | expect(res.body.total).to.equal(3) | |
204 | const videoImports: VideoImport[] = res.body.data | |
205 | expect(videoImports).to.have.lengthOf(3) | |
206 | ||
207 | expect(videoImports[2].targetUrl).to.equal(getYoutubeVideoUrl()) | |
208 | expect(videoImports[2].magnetUri).to.be.null | |
209 | expect(videoImports[2].torrentName).to.be.null | |
210 | expect(videoImports[2].video.name).to.equal('small video - youtube') | |
590fb506 | 211 | |
3e17515e C |
212 | expect(videoImports[1].targetUrl).to.be.null |
213 | expect(videoImports[1].magnetUri).to.equal(getMagnetURI()) | |
214 | expect(videoImports[1].torrentName).to.be.null | |
215 | expect(videoImports[1].video.name).to.equal('super peertube2 video') | |
590fb506 | 216 | |
3e17515e C |
217 | expect(videoImports[0].targetUrl).to.be.null |
218 | expect(videoImports[0].magnetUri).to.be.null | |
219 | expect(videoImports[0].torrentName).to.equal('video-720p.torrent') | |
220 | expect(videoImports[0].video.name).to.equal('你好 世界 720p.mp4') | |
590fb506 C |
221 | }) |
222 | ||
3e17515e | 223 | it('Should have the video listed on the two instances', async function () { |
590fb506 C |
224 | this.timeout(120000) |
225 | ||
226 | await waitJobs(servers) | |
227 | ||
228 | for (const server of servers) { | |
229 | const res = await getVideosList(server.url) | |
3e17515e C |
230 | expect(res.body.total).to.equal(3) |
231 | expect(res.body.data).to.have.lengthOf(3) | |
590fb506 | 232 | |
3e17515e C |
233 | const [ videoHttp, videoMagnet, videoTorrent ] = res.body.data |
234 | await checkVideosServer1(server.url, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid) | |
590fb506 C |
235 | } |
236 | }) | |
237 | ||
238 | it('Should import a video on server 2 with some fields', async function () { | |
239 | this.timeout(60000) | |
240 | ||
241 | const attributes = { | |
242 | targetUrl: getYoutubeVideoUrl(), | |
3e17515e | 243 | channelId: channelIdServer2, |
590fb506 C |
244 | privacy: VideoPrivacy.PUBLIC, |
245 | category: 10, | |
246 | licence: 7, | |
247 | language: 'en', | |
248 | name: 'my super name', | |
249 | description: 'my super description', | |
250 | tags: [ 'supertag1', 'supertag2' ] | |
251 | } | |
252 | const res = await importVideo(servers[1].url, servers[1].accessToken, attributes) | |
253 | expect(res.body.video.name).to.equal('my super name') | |
254 | }) | |
255 | ||
3e17515e | 256 | it('Should have the videos listed on the two instances', async function () { |
590fb506 C |
257 | this.timeout(120000) |
258 | ||
259 | await waitJobs(servers) | |
260 | ||
261 | for (const server of servers) { | |
262 | const res = await getVideosList(server.url) | |
3e17515e C |
263 | expect(res.body.total).to.equal(4) |
264 | expect(res.body.data).to.have.lengthOf(4) | |
590fb506 C |
265 | |
266 | await checkVideoServer2(server.url, res.body.data[0].uuid) | |
3e17515e | 267 | |
a1587156 | 268 | const [ , videoHttp, videoMagnet, videoTorrent ] = res.body.data |
3e17515e C |
269 | await checkVideosServer1(server.url, videoHttp.uuid, videoMagnet.uuid, videoTorrent.uuid) |
270 | } | |
271 | }) | |
272 | ||
273 | it('Should import a video that will be transcoded', async function () { | |
274 | this.timeout(120000) | |
275 | ||
276 | const attributes = { | |
277 | name: 'transcoded video', | |
278 | magnetUri: getMagnetURI(), | |
279 | channelId: channelIdServer2, | |
280 | privacy: VideoPrivacy.PUBLIC | |
281 | } | |
282 | const res = await importVideo(servers[1].url, servers[1].accessToken, attributes) | |
283 | const videoUUID = res.body.video.uuid | |
284 | ||
285 | await waitJobs(servers) | |
286 | ||
287 | for (const server of servers) { | |
288 | const res = await getVideo(server.url, videoUUID) | |
289 | const video: VideoDetails = res.body | |
290 | ||
291 | expect(video.name).to.equal('transcoded video') | |
292 | expect(video.files).to.have.lengthOf(4) | |
590fb506 C |
293 | } |
294 | }) | |
295 | ||
7c3b7976 C |
296 | after(async function () { |
297 | await cleanupTests(servers) | |
590fb506 C |
298 | }) |
299 | }) |