aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-10-03 16:04:14 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-10-03 17:16:47 +0200
commitecb455b6c42bd75c9d87294c2479fa53b739d0a8 (patch)
tree1d9ea1864e3877e1b48bf520e95cdc337d391311
parent40298b02546e8225dd21bf6048fe7f224aefc32a (diff)
downloadPeerTube-ecb455b6c42bd75c9d87294c2479fa53b739d0a8.tar.gz
PeerTube-ecb455b6c42bd75c9d87294c2479fa53b739d0a8.tar.zst
PeerTube-ecb455b6c42bd75c9d87294c2479fa53b739d0a8.zip
Add migration script
-rw-r--r--server/initializers/constants.ts5
-rw-r--r--server/initializers/migrations/0075-video-resolutions.ts62
-rw-r--r--server/models/video/video.ts10
-rw-r--r--server/tests/api/multiple-pods.ts8
4 files changed, 70 insertions, 15 deletions
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts
index 073fabd27..f87041a3f 100644
--- a/server/initializers/constants.ts
+++ b/server/initializers/constants.ts
@@ -10,13 +10,12 @@ import {
10 RequestEndpoint, 10 RequestEndpoint,
11 RequestVideoEventType, 11 RequestVideoEventType,
12 RequestVideoQaduType, 12 RequestVideoQaduType,
13 JobState, 13 JobState
14 VideoResolution
15} from '../../shared/models' 14} from '../../shared/models'
16 15
17// --------------------------------------------------------------------------- 16// ---------------------------------------------------------------------------
18 17
19const LAST_MIGRATION_VERSION = 70 18const LAST_MIGRATION_VERSION = 75
20 19
21// --------------------------------------------------------------------------- 20// ---------------------------------------------------------------------------
22 21
diff --git a/server/initializers/migrations/0075-video-resolutions.ts b/server/initializers/migrations/0075-video-resolutions.ts
new file mode 100644
index 000000000..6bc1e72ab
--- /dev/null
+++ b/server/initializers/migrations/0075-video-resolutions.ts
@@ -0,0 +1,62 @@
1import * as Sequelize from 'sequelize'
2import * as Promise from 'bluebird'
3import { join } from 'path'
4
5import { readdirPromise, renamePromise } from '../../helpers/core-utils'
6import { CONFIG } from '../../initializers/constants'
7
8function up (utils: {
9 transaction: Sequelize.Transaction,
10 queryInterface: Sequelize.QueryInterface,
11 sequelize: Sequelize.Sequelize,
12 db: any
13}): Promise<void> {
14 const torrentDir = CONFIG.STORAGE.TORRENTS_DIR
15 const videoFileDir = CONFIG.STORAGE.VIDEOS_DIR
16
17 return readdirPromise(torrentDir)
18 .then(torrentFiles => {
19 const tasks: Promise<any>[] = []
20 for (const torrentFile of torrentFiles) {
21 const matches = /^([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\.torrent/.exec(torrentFile)
22 if (matches === null) {
23 console.log('Invalid torrent file name %s.', torrentFile)
24 continue
25 }
26
27 const newTorrentName = matches[1] + '-original.torrent'
28 const p = renamePromise(join(torrentDir, torrentFile), join(torrentDir, newTorrentName))
29 tasks.push(p)
30 }
31
32 return Promise.all(tasks)
33 })
34 .then(() => {
35 return readdirPromise(videoFileDir)
36 })
37 .then(videoFiles => {
38 const tasks: Promise<any>[] = []
39 for (const videoFile of videoFiles) {
40 const matches = /^([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\.([a-z0-9]+)/.exec(videoFile)
41 if (matches === null) {
42 console.log('Invalid video file name %s.', videoFile)
43 continue
44 }
45
46 const newVideoFileName = matches[1] + '-original.' + matches[2]
47 const p = renamePromise(join(videoFileDir, videoFile), join(videoFileDir, newVideoFileName))
48 tasks.push(p)
49 }
50
51 return Promise.all(tasks).then(() => undefined)
52 })
53}
54
55function down (options) {
56 throw new Error('Not implemented.')
57}
58
59export {
60 up,
61 down
62}
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index 28df91a7b..b4a2b0c95 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -627,19 +627,13 @@ transcodeOriginalVideofile = function (this: VideoInstance, resolution: VideoRes
627 videoId: this.id 627 videoId: this.id
628 }) 628 })
629 const videoOutputPath = join(videosDirectory, this.getVideoFilename(newVideoFile)) 629 const videoOutputPath = join(videosDirectory, this.getVideoFilename(newVideoFile))
630 const resolutionWidthSizes = { 630 const resolutionOption = `${resolution}x?` // '720x?' for example
631 1: '240x?',
632 2: '360x?',
633 3: '480x?',
634 4: '720x?',
635 5: '1080x?'
636 }
637 631
638 return new Promise<void>((res, rej) => { 632 return new Promise<void>((res, rej) => {
639 ffmpeg(videoInputPath) 633 ffmpeg(videoInputPath)
640 .output(videoOutputPath) 634 .output(videoOutputPath)
641 .videoCodec('libx264') 635 .videoCodec('libx264')
642 .size(resolutionWidthSizes[resolution]) 636 .size(resolutionOption)
643 .outputOption('-threads ' + CONFIG.TRANSCODING.THREADS) 637 .outputOption('-threads ' + CONFIG.TRANSCODING.THREADS)
644 .outputOption('-movflags faststart') 638 .outputOption('-movflags faststart')
645 .on('error', rej) 639 .on('error', rej)
diff --git a/server/tests/api/multiple-pods.ts b/server/tests/api/multiple-pods.ts
index 9860935e5..c43793b30 100644
--- a/server/tests/api/multiple-pods.ts
+++ b/server/tests/api/multiple-pods.ts
@@ -197,22 +197,22 @@ describe('Test multiple pods', function () {
197 expect(originalFile.resolutionLabel).to.equal('original') 197 expect(originalFile.resolutionLabel).to.equal('original')
198 expect(originalFile.size).to.equal(711327) 198 expect(originalFile.size).to.equal(711327)
199 199
200 const file240p = video.files.find(f => f.resolution === 1) 200 const file240p = video.files.find(f => f.resolution === 240)
201 expect(file240p).not.to.be.undefined 201 expect(file240p).not.to.be.undefined
202 expect(file240p.resolutionLabel).to.equal('240p') 202 expect(file240p.resolutionLabel).to.equal('240p')
203 expect(file240p.size).to.equal(139953) 203 expect(file240p.size).to.equal(139953)
204 204
205 const file360p = video.files.find(f => f.resolution === 2) 205 const file360p = video.files.find(f => f.resolution === 360)
206 expect(file360p).not.to.be.undefined 206 expect(file360p).not.to.be.undefined
207 expect(file360p.resolutionLabel).to.equal('360p') 207 expect(file360p.resolutionLabel).to.equal('360p')
208 expect(file360p.size).to.equal(169926) 208 expect(file360p.size).to.equal(169926)
209 209
210 const file480p = video.files.find(f => f.resolution === 3) 210 const file480p = video.files.find(f => f.resolution === 480)
211 expect(file480p).not.to.be.undefined 211 expect(file480p).not.to.be.undefined
212 expect(file480p.resolutionLabel).to.equal('480p') 212 expect(file480p.resolutionLabel).to.equal('480p')
213 expect(file480p.size).to.equal(206758) 213 expect(file480p.size).to.equal(206758)
214 214
215 const file720p = video.files.find(f => f.resolution === 4) 215 const file720p = video.files.find(f => f.resolution === 720)
216 expect(file720p).not.to.be.undefined 216 expect(file720p).not.to.be.undefined
217 expect(file720p.resolutionLabel).to.equal('720p') 217 expect(file720p.resolutionLabel).to.equal('720p')
218 expect(file720p.size).to.equal(314913) 218 expect(file720p.size).to.equal(314913)