diff options
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/parse-log.ts | 23 | ||||
-rw-r--r-- | scripts/regenerate-thumbnails.ts | 54 |
2 files changed, 77 insertions, 0 deletions
diff --git a/scripts/parse-log.ts b/scripts/parse-log.ts index 3679dab74..5f4480c88 100755 --- a/scripts/parse-log.ts +++ b/scripts/parse-log.ts | |||
@@ -15,6 +15,8 @@ import { format as sqlFormat } from 'sql-formatter' | |||
15 | program | 15 | program |
16 | .option('-l, --level [level]', 'Level log (debug/info/warn/error)') | 16 | .option('-l, --level [level]', 'Level log (debug/info/warn/error)') |
17 | .option('-f, --files [file...]', 'Files to parse. If not provided, the script will parse the latest log file from config)') | 17 | .option('-f, --files [file...]', 'Files to parse. If not provided, the script will parse the latest log file from config)') |
18 | .option('-t, --tags [tags...]', 'Display only lines with these tags') | ||
19 | .option('-nt, --not-tags [tags...]', 'Donrt display lines containing these tags') | ||
18 | .parse(process.argv) | 20 | .parse(process.argv) |
19 | 21 | ||
20 | const options = program.opts() | 22 | const options = program.opts() |
@@ -24,6 +26,7 @@ const excludedKeys = { | |||
24 | message: true, | 26 | message: true, |
25 | splat: true, | 27 | splat: true, |
26 | timestamp: true, | 28 | timestamp: true, |
29 | tags: true, | ||
27 | label: true, | 30 | label: true, |
28 | sql: true | 31 | sql: true |
29 | } | 32 | } |
@@ -93,6 +96,14 @@ function run () { | |||
93 | rl.on('line', line => { | 96 | rl.on('line', line => { |
94 | try { | 97 | try { |
95 | const log = JSON.parse(line) | 98 | const log = JSON.parse(line) |
99 | if (options.tags && !containsTags(log.tags, options.tags)) { | ||
100 | return | ||
101 | } | ||
102 | |||
103 | if (options.notTags && containsTags(log.tags, options.notTags)) { | ||
104 | return | ||
105 | } | ||
106 | |||
96 | // Don't know why but loggerFormat does not remove splat key | 107 | // Don't know why but loggerFormat does not remove splat key |
97 | Object.assign(log, { splat: undefined }) | 108 | Object.assign(log, { splat: undefined }) |
98 | 109 | ||
@@ -131,3 +142,15 @@ function toTimeFormat (time: string) { | |||
131 | 142 | ||
132 | return new Date(timestamp).toISOString() | 143 | return new Date(timestamp).toISOString() |
133 | } | 144 | } |
145 | |||
146 | function containsTags (loggerTags: string[], optionsTags: string[]) { | ||
147 | if (!loggerTags) return false | ||
148 | |||
149 | for (const lt of loggerTags) { | ||
150 | for (const ot of optionsTags) { | ||
151 | if (lt === ot) return true | ||
152 | } | ||
153 | } | ||
154 | |||
155 | return false | ||
156 | } | ||
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 @@ | |||
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 | 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 | } | ||