]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - scripts/regenerate-thumbnails.ts
Increase thumbnail size on server
[github/Chocobozzz/PeerTube.git] / scripts / regenerate-thumbnails.ts
1 import { registerTSPaths } from '../server/helpers/register-ts-paths'
2 registerTSPaths()
3
4 import * as Bluebird from 'bluebird'
5 import * as program from 'commander'
6 import { pathExists } from 'fs-extra'
7 import { processImage } from '@server/helpers/image-utils'
8 import { THUMBNAILS_SIZE } from '@server/initializers/constants'
9 import { VideoModel } from '@server/models/video/video'
10 import { MVideo } from '@server/types/models'
11 import { initDatabaseModels } from '@server/initializers/database'
12
13 program
14 .description('Regenerate local thumbnails using preview files')
15 .parse(process.argv)
16
17 run()
18 .then(() => process.exit(0))
19 .catch(err => console.error(err))
20
21 async function run () {
22 await initDatabaseModels(true)
23
24 const videos = await VideoModel.listLocal()
25
26 await Bluebird.map(videos, v => {
27 return processVideo(v)
28 .catch(err => console.error('Cannot process video %s.', v.url, err))
29 }, { concurrency: 20 })
30 }
31
32 async function processVideo (videoArg: MVideo) {
33 const video = await VideoModel.loadWithFiles(videoArg.id)
34
35 console.log('Processing video %s.', video.name)
36
37 const thumbnail = video.getMiniature()
38 const preview = video.getPreview()
39
40 const thumbnailPath = thumbnail.getPath()
41 const previewPath = preview.getPath()
42
43 if (!await pathExists(thumbnailPath)) {
44 throw new Error(`Thumbnail ${thumbnailPath} does not exist on disk`)
45 }
46
47 if (!await pathExists(previewPath)) {
48 throw new Error(`Preview ${previewPath} does not exist on disk`)
49 }
50
51 const size = {
52 width: THUMBNAILS_SIZE.width,
53 height: THUMBNAILS_SIZE.height
54 }
55 await processImage(previewPath, thumbnailPath, size, true)
56 }