]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
40e87e9e | 2 | |
40e87e9e | 3 | import 'mocha' |
a2470c9f | 4 | import * as chai from 'chai' |
9639bd17 | 5 | import { |
a1587156 C |
6 | checkVideoFilesWereRemoved, |
7 | cleanupTests, | |
254d3579 | 8 | createMultipleServers, |
4c7e60bc | 9 | doubleFollow, |
254d3579 | 10 | PeerTubeServer, |
a2470c9f C |
11 | setAccessTokensToServers, |
12 | testCaptionFile, | |
a2470c9f C |
13 | wait, |
14 | waitJobs | |
15 | } from '@shared/extra-utils' | |
40e87e9e C |
16 | |
17 | const expect = chai.expect | |
18 | ||
19 | describe('Test video captions', function () { | |
6302d599 C |
20 | const uuidRegex = '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}' |
21 | ||
254d3579 | 22 | let servers: PeerTubeServer[] |
40e87e9e C |
23 | let videoUUID: string |
24 | ||
25 | before(async function () { | |
59fd824c | 26 | this.timeout(60000) |
40e87e9e | 27 | |
254d3579 | 28 | servers = await createMultipleServers(2) |
40e87e9e C |
29 | |
30 | await setAccessTokensToServers(servers) | |
31 | await doubleFollow(servers[0], servers[1]) | |
32 | ||
33 | await waitJobs(servers) | |
34 | ||
89d241a7 | 35 | const { uuid } = await servers[0].videos.upload({ attributes: { name: 'my video name' } }) |
d23dd9fb | 36 | videoUUID = uuid |
40e87e9e C |
37 | |
38 | await waitJobs(servers) | |
39 | }) | |
40 | ||
41 | it('Should list the captions and return an empty list', async function () { | |
42 | for (const server of servers) { | |
c63830f1 | 43 | const body = await server.captions.list({ videoId: videoUUID }) |
a2470c9f C |
44 | expect(body.total).to.equal(0) |
45 | expect(body.data).to.have.lengthOf(0) | |
40e87e9e C |
46 | } |
47 | }) | |
48 | ||
49 | it('Should create two new captions', async function () { | |
50 | this.timeout(30000) | |
51 | ||
c63830f1 | 52 | await servers[0].captions.add({ |
40e87e9e C |
53 | language: 'ar', |
54 | videoId: videoUUID, | |
55 | fixture: 'subtitle-good1.vtt' | |
56 | }) | |
57 | ||
c63830f1 | 58 | await servers[0].captions.add({ |
40e87e9e C |
59 | language: 'zh', |
60 | videoId: videoUUID, | |
2769e297 C |
61 | fixture: 'subtitle-good2.vtt', |
62 | mimeType: 'application/octet-stream' | |
40e87e9e C |
63 | }) |
64 | ||
65 | await waitJobs(servers) | |
66 | }) | |
67 | ||
68 | it('Should list these uploaded captions', async function () { | |
69 | for (const server of servers) { | |
c63830f1 | 70 | const body = await server.captions.list({ videoId: videoUUID }) |
a2470c9f C |
71 | expect(body.total).to.equal(2) |
72 | expect(body.data).to.have.lengthOf(2) | |
40e87e9e | 73 | |
a2470c9f | 74 | const caption1 = body.data[0] |
40e87e9e C |
75 | expect(caption1.language.id).to.equal('ar') |
76 | expect(caption1.language.label).to.equal('Arabic') | |
6302d599 | 77 | expect(caption1.captionPath).to.match(new RegExp('^/lazy-static/video-captions/' + uuidRegex + '-ar.vtt$')) |
40e87e9e C |
78 | await testCaptionFile(server.url, caption1.captionPath, 'Subtitle good 1.') |
79 | ||
a2470c9f | 80 | const caption2 = body.data[1] |
40e87e9e C |
81 | expect(caption2.language.id).to.equal('zh') |
82 | expect(caption2.language.label).to.equal('Chinese') | |
6302d599 | 83 | expect(caption2.captionPath).to.match(new RegExp('^/lazy-static/video-captions/' + uuidRegex + '-zh.vtt$')) |
40e87e9e C |
84 | await testCaptionFile(server.url, caption2.captionPath, 'Subtitle good 2.') |
85 | } | |
86 | }) | |
87 | ||
88 | it('Should replace an existing caption', async function () { | |
89 | this.timeout(30000) | |
90 | ||
c63830f1 | 91 | await servers[0].captions.add({ |
40e87e9e C |
92 | language: 'ar', |
93 | videoId: videoUUID, | |
94 | fixture: 'subtitle-good2.vtt' | |
95 | }) | |
96 | ||
97 | await waitJobs(servers) | |
98 | }) | |
99 | ||
100 | it('Should have this caption updated', async function () { | |
101 | for (const server of servers) { | |
c63830f1 | 102 | const body = await server.captions.list({ videoId: videoUUID }) |
a2470c9f C |
103 | expect(body.total).to.equal(2) |
104 | expect(body.data).to.have.lengthOf(2) | |
40e87e9e | 105 | |
a2470c9f | 106 | const caption1 = body.data[0] |
40e87e9e C |
107 | expect(caption1.language.id).to.equal('ar') |
108 | expect(caption1.language.label).to.equal('Arabic') | |
6302d599 | 109 | expect(caption1.captionPath).to.match(new RegExp('^/lazy-static/video-captions/' + uuidRegex + '-ar.vtt$')) |
40e87e9e C |
110 | await testCaptionFile(server.url, caption1.captionPath, 'Subtitle good 2.') |
111 | } | |
112 | }) | |
113 | ||
f4001cf4 C |
114 | it('Should replace an existing caption with a srt file and convert it', async function () { |
115 | this.timeout(30000) | |
116 | ||
c63830f1 | 117 | await servers[0].captions.add({ |
f4001cf4 C |
118 | language: 'ar', |
119 | videoId: videoUUID, | |
120 | fixture: 'subtitle-good.srt' | |
121 | }) | |
122 | ||
123 | await waitJobs(servers) | |
124 | ||
125 | // Cache invalidation | |
126 | await wait(3000) | |
127 | }) | |
128 | ||
129 | it('Should have this caption updated and converted', async function () { | |
130 | for (const server of servers) { | |
c63830f1 | 131 | const body = await server.captions.list({ videoId: videoUUID }) |
a2470c9f C |
132 | expect(body.total).to.equal(2) |
133 | expect(body.data).to.have.lengthOf(2) | |
f4001cf4 | 134 | |
a2470c9f | 135 | const caption1 = body.data[0] |
f4001cf4 C |
136 | expect(caption1.language.id).to.equal('ar') |
137 | expect(caption1.language.label).to.equal('Arabic') | |
6302d599 | 138 | expect(caption1.captionPath).to.match(new RegExp('^/lazy-static/video-captions/' + uuidRegex + '-ar.vtt$')) |
f4001cf4 C |
139 | |
140 | const expected = 'WEBVTT FILE\r\n' + | |
141 | '\r\n' + | |
142 | '1\r\n' + | |
143 | '00:00:01.600 --> 00:00:04.200\r\n' + | |
144 | 'English (US)\r\n' + | |
145 | '\r\n' + | |
146 | '2\r\n' + | |
147 | '00:00:05.900 --> 00:00:07.999\r\n' + | |
148 | 'This is a subtitle in American English\r\n' + | |
149 | '\r\n' + | |
150 | '3\r\n' + | |
151 | '00:00:10.000 --> 00:00:14.000\r\n' + | |
152 | 'Adding subtitles is very easy to do\r\n' | |
153 | await testCaptionFile(server.url, caption1.captionPath, expected) | |
154 | } | |
155 | }) | |
156 | ||
40e87e9e C |
157 | it('Should remove one caption', async function () { |
158 | this.timeout(30000) | |
159 | ||
c63830f1 | 160 | await servers[0].captions.delete({ videoId: videoUUID, language: 'ar' }) |
40e87e9e C |
161 | |
162 | await waitJobs(servers) | |
163 | }) | |
164 | ||
165 | it('Should only list the caption that was not deleted', async function () { | |
166 | for (const server of servers) { | |
c63830f1 | 167 | const body = await server.captions.list({ videoId: videoUUID }) |
a2470c9f C |
168 | expect(body.total).to.equal(1) |
169 | expect(body.data).to.have.lengthOf(1) | |
40e87e9e | 170 | |
a2470c9f | 171 | const caption = body.data[0] |
40e87e9e C |
172 | |
173 | expect(caption.language.id).to.equal('zh') | |
174 | expect(caption.language.label).to.equal('Chinese') | |
6302d599 | 175 | expect(caption.captionPath).to.match(new RegExp('^/lazy-static/video-captions/' + uuidRegex + '-zh.vtt$')) |
40e87e9e C |
176 | await testCaptionFile(server.url, caption.captionPath, 'Subtitle good 2.') |
177 | } | |
178 | }) | |
179 | ||
f4001cf4 | 180 | it('Should remove the video, and thus all video captions', async function () { |
83903cb6 C |
181 | const video = await servers[0].videos.get({ id: videoUUID }) |
182 | const { data: captions } = await servers[0].captions.list({ videoId: videoUUID }) | |
183 | ||
89d241a7 | 184 | await servers[0].videos.remove({ id: videoUUID }) |
f4001cf4 | 185 | |
83903cb6 | 186 | await checkVideoFilesWereRemoved({ server: servers[0], video, captions }) |
f4001cf4 C |
187 | }) |
188 | ||
7c3b7976 C |
189 | after(async function () { |
190 | await cleanupTests(servers) | |
40e87e9e C |
191 | }) |
192 | }) |