ニジカ投稿局 https://tv.nizika.tv
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

create-generate-storyboard-job.ts 2.1 KiB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import { program } from 'commander'
  2. import { toCompleteUUID } from '@server/helpers/custom-validators/misc.js'
  3. import { initDatabaseModels } from '@server/initializers/database.js'
  4. import { JobQueue } from '@server/lib/job-queue/index.js'
  5. import { StoryboardModel } from '@server/models/video/storyboard.js'
  6. import { VideoModel } from '@server/models/video/video.js'
  7. import { buildStoryboardJobIfNeeded } from '@server/lib/video-jobs.js'
  8. program
  9. .description('Generate videos storyboard')
  10. .option('-v, --video [videoUUID]', 'Generate the storyboard of a specific video')
  11. .option('-a, --all-videos', 'Generate missing storyboards of local videos')
  12. .parse(process.argv)
  13. const options = program.opts()
  14. if (!options['video'] && !options['allVideos']) {
  15. console.error('You need to choose videos for storyboard generation.')
  16. process.exit(-1)
  17. }
  18. run()
  19. .then(() => process.exit(0))
  20. .catch(err => {
  21. console.error(err)
  22. process.exit(-1)
  23. })
  24. async function run () {
  25. await initDatabaseModels(true)
  26. JobQueue.Instance.init()
  27. let ids: number[] = []
  28. if (options['video']) {
  29. const video = await VideoModel.load(toCompleteUUID(options['video']))
  30. if (!video) {
  31. console.error('Unknown video ' + options['video'])
  32. process.exit(-1)
  33. }
  34. if (video.remote === true) {
  35. console.error('Cannot process a remote video')
  36. process.exit(-1)
  37. }
  38. if (video.isLive) {
  39. console.error('Cannot process live video')
  40. process.exit(-1)
  41. }
  42. ids.push(video.id)
  43. } else {
  44. ids = await listLocalMissingStoryboards()
  45. }
  46. for (const id of ids) {
  47. const videoFull = await VideoModel.load(id)
  48. if (videoFull.isLive) continue
  49. await JobQueue.Instance.createJob(buildStoryboardJobIfNeeded({ video: videoFull, federate: true }))
  50. console.log(`Created generate-storyboard job for ${videoFull.name}.`)
  51. }
  52. }
  53. async function listLocalMissingStoryboards () {
  54. const ids = await VideoModel.listLocalIds()
  55. const results: number[] = []
  56. for (const id of ids) {
  57. const storyboard = await StoryboardModel.loadByVideo(id)
  58. if (!storyboard) results.push(id)
  59. }
  60. return results
  61. }