diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-10-09 11:06:13 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-10-09 11:17:36 +0200 |
commit | 14d3270f363245d2c83fcc2ac109e39743b5627e (patch) | |
tree | 22a1d40675d372d53c35a4d7adf1fc1b4ceb1799 /server/initializers | |
parent | aa8b6df4a51c82eb91e6fd71a090b2128098af6b (diff) | |
download | PeerTube-14d3270f363245d2c83fcc2ac109e39743b5627e.tar.gz PeerTube-14d3270f363245d2c83fcc2ac109e39743b5627e.tar.zst PeerTube-14d3270f363245d2c83fcc2ac109e39743b5627e.zip |
Change how we handle resolution
It was an enum before, now we just use video height
Diffstat (limited to 'server/initializers')
-rw-r--r-- | server/initializers/constants.ts | 11 | ||||
-rw-r--r-- | server/initializers/migrations/0075-video-resolutions.ts | 43 |
2 files changed, 21 insertions, 33 deletions
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index f87041a3f..b11575b34 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts | |||
@@ -189,16 +189,6 @@ const VIDEO_LANGUAGES = { | |||
189 | 14: 'Italian' | 189 | 14: 'Italian' |
190 | } | 190 | } |
191 | 191 | ||
192 | // TODO: use VideoResolution when https://github.com/Microsoft/TypeScript/issues/13042 is fixed | ||
193 | const VIDEO_FILE_RESOLUTIONS: { [ id: number ]: string } = { | ||
194 | 0: 'original', | ||
195 | 240: '240p', | ||
196 | 360: '360p', | ||
197 | 480: '480p', | ||
198 | 720: '720p', | ||
199 | 1080: '1080p' | ||
200 | } | ||
201 | |||
202 | // --------------------------------------------------------------------------- | 192 | // --------------------------------------------------------------------------- |
203 | 193 | ||
204 | // Score a pod has when we create it as a friend | 194 | // Score a pod has when we create it as a friend |
@@ -385,7 +375,6 @@ export { | |||
385 | THUMBNAILS_SIZE, | 375 | THUMBNAILS_SIZE, |
386 | USER_ROLES, | 376 | USER_ROLES, |
387 | VIDEO_CATEGORIES, | 377 | VIDEO_CATEGORIES, |
388 | VIDEO_FILE_RESOLUTIONS, | ||
389 | VIDEO_LANGUAGES, | 378 | VIDEO_LANGUAGES, |
390 | VIDEO_LICENCES, | 379 | VIDEO_LICENCES, |
391 | VIDEO_RATE_TYPES | 380 | VIDEO_RATE_TYPES |
diff --git a/server/initializers/migrations/0075-video-resolutions.ts b/server/initializers/migrations/0075-video-resolutions.ts index 6bc1e72ab..e1d9fdacb 100644 --- a/server/initializers/migrations/0075-video-resolutions.ts +++ b/server/initializers/migrations/0075-video-resolutions.ts | |||
@@ -4,6 +4,7 @@ import { join } from 'path' | |||
4 | 4 | ||
5 | import { readdirPromise, renamePromise } from '../../helpers/core-utils' | 5 | import { readdirPromise, renamePromise } from '../../helpers/core-utils' |
6 | import { CONFIG } from '../../initializers/constants' | 6 | import { CONFIG } from '../../initializers/constants' |
7 | import { getVideoFileHeight } from '../../helpers/ffmpeg-utils' | ||
7 | 8 | ||
8 | function up (utils: { | 9 | function up (utils: { |
9 | transaction: Sequelize.Transaction, | 10 | transaction: Sequelize.Transaction, |
@@ -14,26 +15,7 @@ function up (utils: { | |||
14 | const torrentDir = CONFIG.STORAGE.TORRENTS_DIR | 15 | const torrentDir = CONFIG.STORAGE.TORRENTS_DIR |
15 | const videoFileDir = CONFIG.STORAGE.VIDEOS_DIR | 16 | const videoFileDir = CONFIG.STORAGE.VIDEOS_DIR |
16 | 17 | ||
17 | return readdirPromise(torrentDir) | 18 | return readdirPromise(videoFileDir) |
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 => { | 19 | .then(videoFiles => { |
38 | const tasks: Promise<any>[] = [] | 20 | const tasks: Promise<any>[] = [] |
39 | for (const videoFile of videoFiles) { | 21 | for (const videoFile of videoFiles) { |
@@ -43,8 +25,25 @@ function up (utils: { | |||
43 | continue | 25 | continue |
44 | } | 26 | } |
45 | 27 | ||
46 | const newVideoFileName = matches[1] + '-original.' + matches[2] | 28 | const uuid = matches[1] |
47 | const p = renamePromise(join(videoFileDir, videoFile), join(videoFileDir, newVideoFileName)) | 29 | const ext = matches[2] |
30 | |||
31 | const p = getVideoFileHeight(join(videoFileDir, videoFile)) | ||
32 | .then(height => { | ||
33 | const oldTorrentName = uuid + '.torrent' | ||
34 | const newTorrentName = uuid + '-' + height + '.torrent' | ||
35 | return renamePromise(join(torrentDir, oldTorrentName), join(torrentDir, newTorrentName)).then(() => height) | ||
36 | }) | ||
37 | .then(height => { | ||
38 | const newVideoFileName = uuid + '-' + height + '.' + ext | ||
39 | return renamePromise(join(videoFileDir, videoFile), join(videoFileDir, newVideoFileName)).then(() => height) | ||
40 | }) | ||
41 | .then(height => { | ||
42 | const query = 'UPDATE "VideoFiles" SET "resolution" = ' + height + | ||
43 | ' WHERE "videoId" = (SELECT "id" FROM "Videos" WHERE "uuid" = \'' + uuid + '\')' | ||
44 | return utils.sequelize.query(query) | ||
45 | }) | ||
46 | |||
48 | tasks.push(p) | 47 | tasks.push(p) |
49 | } | 48 | } |
50 | 49 | ||