From 14d3270f363245d2c83fcc2ac109e39743b5627e Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 9 Oct 2017 11:06:13 +0200 Subject: Change how we handle resolution It was an enum before, now we just use video height --- .../migrations/0075-video-resolutions.ts | 43 +++++++++++----------- 1 file changed, 21 insertions(+), 22 deletions(-) (limited to 'server/initializers/migrations') 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' import { readdirPromise, renamePromise } from '../../helpers/core-utils' import { CONFIG } from '../../initializers/constants' +import { getVideoFileHeight } from '../../helpers/ffmpeg-utils' function up (utils: { transaction: Sequelize.Transaction, @@ -14,26 +15,7 @@ function up (utils: { const torrentDir = CONFIG.STORAGE.TORRENTS_DIR const videoFileDir = CONFIG.STORAGE.VIDEOS_DIR - return readdirPromise(torrentDir) - .then(torrentFiles => { - const tasks: Promise[] = [] - for (const torrentFile of torrentFiles) { - 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) - if (matches === null) { - console.log('Invalid torrent file name %s.', torrentFile) - continue - } - - const newTorrentName = matches[1] + '-original.torrent' - const p = renamePromise(join(torrentDir, torrentFile), join(torrentDir, newTorrentName)) - tasks.push(p) - } - - return Promise.all(tasks) - }) - .then(() => { - return readdirPromise(videoFileDir) - }) + return readdirPromise(videoFileDir) .then(videoFiles => { const tasks: Promise[] = [] for (const videoFile of videoFiles) { @@ -43,8 +25,25 @@ function up (utils: { continue } - const newVideoFileName = matches[1] + '-original.' + matches[2] - const p = renamePromise(join(videoFileDir, videoFile), join(videoFileDir, newVideoFileName)) + const uuid = matches[1] + const ext = matches[2] + + const p = getVideoFileHeight(join(videoFileDir, videoFile)) + .then(height => { + const oldTorrentName = uuid + '.torrent' + const newTorrentName = uuid + '-' + height + '.torrent' + return renamePromise(join(torrentDir, oldTorrentName), join(torrentDir, newTorrentName)).then(() => height) + }) + .then(height => { + const newVideoFileName = uuid + '-' + height + '.' + ext + return renamePromise(join(videoFileDir, videoFile), join(videoFileDir, newVideoFileName)).then(() => height) + }) + .then(height => { + const query = 'UPDATE "VideoFiles" SET "resolution" = ' + height + + ' WHERE "videoId" = (SELECT "id" FROM "Videos" WHERE "uuid" = \'' + uuid + '\')' + return utils.sequelize.query(query) + }) + tasks.push(p) } -- cgit v1.2.3