@@ -114,12 +114,18 @@ def scan_videos(root):
114
114
db .session .commit ()
115
115
116
116
@cli .command ()
117
+ @click .pass_context
117
118
@click .option ("--path" , "-p" , help = "path to video to scan" , required = False )
118
- def scan_video (path ):
119
+ def scan_video (ctx , path ):
119
120
with create_app ().app_context ():
120
121
paths = current_app .config ['PATHS' ]
121
122
videos_path = paths ["video" ]
122
123
video_links = paths ["processed" ] / "video_links"
124
+ thumbnail_skip = current_app .config ['THUMBNAIL_VIDEO_LOCATION' ] or 0
125
+ if thumbnail_skip > 0 and thumbnail_skip <= 100 :
126
+ thumbnail_skip = thumbnail_skip / 100
127
+ else :
128
+ thumbnail_skip = 0
123
129
124
130
config_file = open (paths ["data" ] / "config.json" )
125
131
video_config = json .load (config_file )["app_config" ]["video_defaults" ]
@@ -169,7 +175,12 @@ def scan_video(path):
169
175
logger .info (f"{ dst } exists already" )
170
176
info = VideoInfo (video_id = v .video_id , title = Path (v .path ).stem , private = video_config ["private" ])
171
177
db .session .add (info )
172
-
178
+ db .session .commit ()
179
+
180
+ logger .info ("Syncing metadata" )
181
+ ctx .invoke (sync_metadata , video = video_id )
182
+ info = VideoInfo .query .filter (VideoInfo .video_id == video_id ).one ()
183
+
173
184
processed_root = Path (current_app .config ['PROCESSED_DIRECTORY' ])
174
185
logger .info (f"Checking for videos with missing posters..." )
175
186
derived_path = Path (processed_root , "derived" , info .video_id )
@@ -180,7 +191,7 @@ def scan_video(path):
180
191
if should_create_poster :
181
192
if not derived_path .exists ():
182
193
derived_path .mkdir (parents = True )
183
- poster_time = 0
194
+ poster_time = int ( info . duration * thumbnail_skip )
184
195
util .create_poster (video_path , derived_path / "poster.jpg" , poster_time )
185
196
else :
186
197
logger .debug (f"Skipping creation of poster for video { info .video_id } because it exists at { str (poster_path )} " )
@@ -216,10 +227,11 @@ def repair_symlinks():
216
227
logger .info (f"{ dst } exists already" )
217
228
218
229
@cli .command ()
219
- def sync_metadata ():
230
+ @click .option ("--video" , "-v" , help = "The video to sync metadata from" , default = None )
231
+ def sync_metadata (video ):
220
232
with create_app ().app_context ():
221
233
paths = current_app .config ['PATHS' ]
222
- videos = VideoInfo .query .filter (VideoInfo .info == None ).all ()
234
+ videos = VideoInfo .query .filter (VideoInfo .video_id == video ). all () if video else VideoInfo . query . filter ( VideoInfo . info == None ).all ()
223
235
logger .info (f'Found { len (videos ):,} videos without metadata' )
224
236
for v in videos :
225
237
vpath = paths ["processed" ] / "video_links" / str (v .video_id + v .video .extension )
@@ -352,6 +364,12 @@ def bulk_import(ctx, root):
352
364
return
353
365
util .create_lock (paths ["data" ])
354
366
367
+ thumbnail_skip = current_app .config ['THUMBNAIL_VIDEO_LOCATION' ] or 0
368
+ if thumbnail_skip > 0 and thumbnail_skip <= 100 :
369
+ thumbnail_skip = thumbnail_skip / 100
370
+ else :
371
+ thumbnail_skip = 0
372
+
355
373
timing = {}
356
374
s = time .time ()
357
375
ctx .invoke (scan_videos , root = root )
@@ -360,7 +378,7 @@ def bulk_import(ctx, root):
360
378
ctx .invoke (sync_metadata )
361
379
timing ['sync_metadata' ] = time .time () - s
362
380
s = time .time ()
363
- ctx .invoke (create_posters )
381
+ ctx .invoke (create_posters , skip = thumbnail_skip )
364
382
timing ['create_posters' ] = time .time () - s
365
383
366
384
logger .info (f"Finished bulk import. Timing info: { json .dumps (timing )} " )
0 commit comments