factorstudios commited on
Commit
295e164
·
verified ·
1 Parent(s): 73011a0

Update server.py

Browse files
Files changed (1) hide show
  1. server.py +20 -8
server.py CHANGED
@@ -1,4 +1,8 @@
1
-
 
 
 
 
2
 
3
  import os
4
  import sys
@@ -257,9 +261,14 @@ async def scan_and_compress_videos():
257
  video_files = []
258
  for f in files:
259
  if f.startswith(f"{READY_VIDEOS_FOLDER}/") and f.endswith(".mp4"):
 
 
 
 
 
260
  # Skip if already handled
261
  if f in compressed_files:
262
- print(f" ⊘ {f.split('/')[-1]} (already compressed)")
263
  continue
264
  if f in failed_files:
265
  print(f" ✗ {f.split('/')[-1]} (previously failed)")
@@ -398,7 +407,7 @@ async def scan_and_compress_videos():
398
 
399
  @app.on_event("startup")
400
  async def startup_event():
401
- """Start compression scan on server startup with 30s delay."""
402
  print("\n" + "="*80)
403
  print("STARTUP EVENT TRIGGERED")
404
  print("="*80)
@@ -415,11 +424,14 @@ async def startup_event():
415
  except Exception as e:
416
  print(f"✗ Error checking ffmpeg: {e}")
417
 
418
- # Wait 30 seconds before starting scan
419
- print("\nWaiting 30 seconds before starting compression scan...")
420
- await asyncio.sleep(30)
421
- print("Starting compression scan now...")
422
- await scan_and_compress_videos()
 
 
 
423
 
424
 
425
  @app.get("/")
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ FastAPI Video Compression Server
4
+ Continuously polls Hugging Face dataset for large videos and compresses them.
5
+ """
6
 
7
  import os
8
  import sys
 
261
  video_files = []
262
  for f in files:
263
  if f.startswith(f"{READY_VIDEOS_FOLDER}/") and f.endswith(".mp4"):
264
+ # Skip already compressed files
265
+ if "_compressed" in f:
266
+ print(f" ⊘ {f.split('/')[-1]} (already compressed file)")
267
+ continue
268
+
269
  # Skip if already handled
270
  if f in compressed_files:
271
+ print(f" ⊘ {f.split('/')[-1]} (already processed)")
272
  continue
273
  if f in failed_files:
274
  print(f" ✗ {f.split('/')[-1]} (previously failed)")
 
407
 
408
  @app.on_event("startup")
409
  async def startup_event():
410
+ """Schedule compression scan on server startup with 30s delay."""
411
  print("\n" + "="*80)
412
  print("STARTUP EVENT TRIGGERED")
413
  print("="*80)
 
424
  except Exception as e:
425
  print(f"✗ Error checking ffmpeg: {e}")
426
 
427
+ # Schedule scan as background task (don't wait for it)
428
+ async def delayed_scan():
429
+ print("\nWaiting 30 seconds before starting compression scan...")
430
+ await asyncio.sleep(30)
431
+ print("Starting compression scan now...")
432
+ await scan_and_compress_videos()
433
+
434
+ asyncio.create_task(delayed_scan())
435
 
436
 
437
  @app.get("/")