aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-03-12 17:04:49 +0100
committerChocobozzz <me@florianbigard.com>2021-03-24 18:18:41 +0100
commitc2bd7a6fcff652b149b24a642314c88e56a07f48 (patch)
tree3e123d1e04b814cc94d1c7ef2526466352095ab5 /scripts
parenta784bd7fdef5a0b39d302c2a17aa1706148b2d2e (diff)
downloadPeerTube-c2bd7a6fcff652b149b24a642314c88e56a07f48.tar.gz
PeerTube-c2bd7a6fcff652b149b24a642314c88e56a07f48.tar.zst
PeerTube-c2bd7a6fcff652b149b24a642314c88e56a07f48.zip
Add regenrate thumbnails scripts
Diffstat (limited to 'scripts')
-rw-r--r--scripts/regenerate-thumbnails.ts54
1 files changed, 54 insertions, 0 deletions
diff --git a/scripts/regenerate-thumbnails.ts b/scripts/regenerate-thumbnails.ts
new file mode 100644
index 000000000..b0071efe0
--- /dev/null
+++ b/scripts/regenerate-thumbnails.ts
@@ -0,0 +1,54 @@
1import { registerTSPaths } from '../server/helpers/register-ts-paths'
2registerTSPaths()
3
4import * as Bluebird from 'bluebird'
5import * as program from 'commander'
6import { pathExists } from 'fs-extra'
7import { processImage } from '@server/helpers/image-utils'
8import { THUMBNAILS_SIZE } from '@server/initializers/constants'
9import { VideoModel } from '@server/models/video/video'
10import { MVideo } from '@server/types/models'
11import { initDatabaseModels } from '@server/initializers/database'
12
13program
14 .description('Regenerate local thumbnails using preview files')
15 .parse(process.argv)
16
17run()
18 .then(() => process.exit(0))
19 .catch(err => console.error(err))
20
21async 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
32async function processVideo (videoArg: MVideo) {
33 const video = await VideoModel.loadWithFiles(videoArg.id)
34
35 const thumbnail = video.getMiniature()
36 const preview = video.getPreview()
37
38 const thumbnailPath = thumbnail.getPath()
39 const previewPath = preview.getPath()
40
41 if (!await pathExists(thumbnailPath)) {
42 throw new Error(`Thumbnail ${thumbnailPath} does not exist on disk`)
43 }
44
45 if (!await pathExists(previewPath)) {
46 throw new Error(`Preview ${previewPath} does not exist on disk`)
47 }
48
49 const size = {
50 width: THUMBNAILS_SIZE.width,
51 height: THUMBNAILS_SIZE.height
52 }
53 await processImage(previewPath, thumbnailPath, size, true)
54}