mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2024-12-01 21:09:17 -06:00
Add migration script
This commit is contained in:
parent
40298b0254
commit
ecb455b6c4
@ -10,13 +10,12 @@ import {
|
||||
RequestEndpoint,
|
||||
RequestVideoEventType,
|
||||
RequestVideoQaduType,
|
||||
JobState,
|
||||
VideoResolution
|
||||
JobState
|
||||
} from '../../shared/models'
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
const LAST_MIGRATION_VERSION = 70
|
||||
const LAST_MIGRATION_VERSION = 75
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
|
62
server/initializers/migrations/0075-video-resolutions.ts
Normal file
62
server/initializers/migrations/0075-video-resolutions.ts
Normal file
@ -0,0 +1,62 @@
|
||||
import * as Sequelize from 'sequelize'
|
||||
import * as Promise from 'bluebird'
|
||||
import { join } from 'path'
|
||||
|
||||
import { readdirPromise, renamePromise } from '../../helpers/core-utils'
|
||||
import { CONFIG } from '../../initializers/constants'
|
||||
|
||||
function up (utils: {
|
||||
transaction: Sequelize.Transaction,
|
||||
queryInterface: Sequelize.QueryInterface,
|
||||
sequelize: Sequelize.Sequelize,
|
||||
db: any
|
||||
}): Promise<void> {
|
||||
const torrentDir = CONFIG.STORAGE.TORRENTS_DIR
|
||||
const videoFileDir = CONFIG.STORAGE.VIDEOS_DIR
|
||||
|
||||
return readdirPromise(torrentDir)
|
||||
.then(torrentFiles => {
|
||||
const tasks: Promise<any>[] = []
|
||||
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)
|
||||
})
|
||||
.then(videoFiles => {
|
||||
const tasks: Promise<any>[] = []
|
||||
for (const videoFile of videoFiles) {
|
||||
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)
|
||||
if (matches === null) {
|
||||
console.log('Invalid video file name %s.', videoFile)
|
||||
continue
|
||||
}
|
||||
|
||||
const newVideoFileName = matches[1] + '-original.' + matches[2]
|
||||
const p = renamePromise(join(videoFileDir, videoFile), join(videoFileDir, newVideoFileName))
|
||||
tasks.push(p)
|
||||
}
|
||||
|
||||
return Promise.all(tasks).then(() => undefined)
|
||||
})
|
||||
}
|
||||
|
||||
function down (options) {
|
||||
throw new Error('Not implemented.')
|
||||
}
|
||||
|
||||
export {
|
||||
up,
|
||||
down
|
||||
}
|
@ -627,19 +627,13 @@ transcodeOriginalVideofile = function (this: VideoInstance, resolution: VideoRes
|
||||
videoId: this.id
|
||||
})
|
||||
const videoOutputPath = join(videosDirectory, this.getVideoFilename(newVideoFile))
|
||||
const resolutionWidthSizes = {
|
||||
1: '240x?',
|
||||
2: '360x?',
|
||||
3: '480x?',
|
||||
4: '720x?',
|
||||
5: '1080x?'
|
||||
}
|
||||
const resolutionOption = `${resolution}x?` // '720x?' for example
|
||||
|
||||
return new Promise<void>((res, rej) => {
|
||||
ffmpeg(videoInputPath)
|
||||
.output(videoOutputPath)
|
||||
.videoCodec('libx264')
|
||||
.size(resolutionWidthSizes[resolution])
|
||||
.size(resolutionOption)
|
||||
.outputOption('-threads ' + CONFIG.TRANSCODING.THREADS)
|
||||
.outputOption('-movflags faststart')
|
||||
.on('error', rej)
|
||||
|
@ -197,22 +197,22 @@ describe('Test multiple pods', function () {
|
||||
expect(originalFile.resolutionLabel).to.equal('original')
|
||||
expect(originalFile.size).to.equal(711327)
|
||||
|
||||
const file240p = video.files.find(f => f.resolution === 1)
|
||||
const file240p = video.files.find(f => f.resolution === 240)
|
||||
expect(file240p).not.to.be.undefined
|
||||
expect(file240p.resolutionLabel).to.equal('240p')
|
||||
expect(file240p.size).to.equal(139953)
|
||||
|
||||
const file360p = video.files.find(f => f.resolution === 2)
|
||||
const file360p = video.files.find(f => f.resolution === 360)
|
||||
expect(file360p).not.to.be.undefined
|
||||
expect(file360p.resolutionLabel).to.equal('360p')
|
||||
expect(file360p.size).to.equal(169926)
|
||||
|
||||
const file480p = video.files.find(f => f.resolution === 3)
|
||||
const file480p = video.files.find(f => f.resolution === 480)
|
||||
expect(file480p).not.to.be.undefined
|
||||
expect(file480p.resolutionLabel).to.equal('480p')
|
||||
expect(file480p.size).to.equal(206758)
|
||||
|
||||
const file720p = video.files.find(f => f.resolution === 4)
|
||||
const file720p = video.files.find(f => f.resolution === 720)
|
||||
expect(file720p).not.to.be.undefined
|
||||
expect(file720p.resolutionLabel).to.equal('720p')
|
||||
expect(file720p.size).to.equal(314913)
|
||||
|
Loading…
Reference in New Issue
Block a user