aliSaac510 commited on
Commit
4f83369
·
1 Parent(s): 73120a1

Include bgmusic in list-saved endpoint

Browse files
Files changed (2) hide show
  1. routers/video.py +22 -5
  2. video_processor.py +2 -16
routers/video.py CHANGED
@@ -18,6 +18,7 @@ BASE_DIR = "temp_videos"
18
  ORIGINALS_DIR = os.path.join(BASE_DIR, "originals")
19
  PROCESSED_DIR = os.path.join(BASE_DIR, "processed")
20
  AUDIO_DIR = os.path.join(BASE_DIR, "audio")
 
21
  TEMP_DIR = os.path.join(BASE_DIR, "temp")
22
 
23
  def build_file_url(request: Request, filename: str, file_type: str = "processed") -> str:
@@ -32,7 +33,7 @@ def build_file_url(request: Request, filename: str, file_type: str = "processed"
32
  return urljoin(base_url, url_path)
33
 
34
  # إنشاء الفولدرات
35
- for directory in [BASE_DIR, ORIGINALS_DIR, PROCESSED_DIR, AUDIO_DIR, TEMP_DIR]:
36
  os.makedirs(directory, exist_ok=True)
37
 
38
  def background_processing(
@@ -264,7 +265,7 @@ async def process_video(
264
 
265
  # Handle Background Music (n8n compatible - files only)
266
  if background_music:
267
- audio_path = os.path.join(BASE_DIR, f"bg_{task_id}_{background_music.filename}")
268
  with open(audio_path, "wb") as buffer:
269
  shutil.copyfileobj(background_music.file, buffer)
270
 
@@ -309,7 +310,8 @@ async def list_saved_files():
309
  files_data = {
310
  "temp": [],
311
  "processed": [],
312
- "originals": []
 
313
  }
314
 
315
  # Check temp folder
@@ -344,13 +346,25 @@ async def list_saved_files():
344
  "size_mb": round(os.path.getsize(file_path) / (1024 * 1024), 2),
345
  "created": os.path.getctime(file_path)
346
  })
 
 
 
 
 
 
 
 
 
 
 
347
 
348
  return {
349
  "status": "success",
350
  "counts": {
351
  "temp": len(files_data["temp"]),
352
  "processed": len(files_data["processed"]),
353
- "originals": len(files_data["originals"])
 
354
  },
355
  "files": files_data
356
  }
@@ -369,6 +383,7 @@ async def list_saved_files():
369
  "originals": ORIGINALS_DIR,
370
  "processed": PROCESSED_DIR,
371
  "audio": AUDIO_DIR,
 
372
  "temp": TEMP_DIR
373
  }
374
 
@@ -426,13 +441,15 @@ async def clear_temp_files(
426
  # نحدد الفولدرات المستهدفة
427
  target_folders = []
428
  if folder == "all":
429
- target_folders = [TEMP_DIR, PROCESSED_DIR, AUDIO_DIR] # مش هنمسح originals
430
  elif folder == "temp":
431
  target_folders = [TEMP_DIR]
432
  elif folder == "processed":
433
  target_folders = [PROCESSED_DIR]
434
  elif folder == "audio":
435
  target_folders = [AUDIO_DIR]
 
 
436
  elif folder == "originals":
437
  target_folders = [ORIGINALS_DIR]
438
  else:
 
18
  ORIGINALS_DIR = os.path.join(BASE_DIR, "originals")
19
  PROCESSED_DIR = os.path.join(BASE_DIR, "processed")
20
  AUDIO_DIR = os.path.join(BASE_DIR, "audio")
21
+ BG_MUSIC_DIR = os.path.join(BASE_DIR, "bgmusic")
22
  TEMP_DIR = os.path.join(BASE_DIR, "temp")
23
 
24
  def build_file_url(request: Request, filename: str, file_type: str = "processed") -> str:
 
33
  return urljoin(base_url, url_path)
34
 
35
  # إنشاء الفولدرات
36
+ for directory in [BASE_DIR, ORIGINALS_DIR, PROCESSED_DIR, AUDIO_DIR, BG_MUSIC_DIR, TEMP_DIR]:
37
  os.makedirs(directory, exist_ok=True)
38
 
39
  def background_processing(
 
265
 
266
  # Handle Background Music (n8n compatible - files only)
267
  if background_music:
268
+ audio_path = os.path.join(BG_MUSIC_DIR, f"bg_{task_id}_{background_music.filename}")
269
  with open(audio_path, "wb") as buffer:
270
  shutil.copyfileobj(background_music.file, buffer)
271
 
 
310
  files_data = {
311
  "temp": [],
312
  "processed": [],
313
+ "originals": [],
314
+ "bgmusic": []
315
  }
316
 
317
  # Check temp folder
 
346
  "size_mb": round(os.path.getsize(file_path) / (1024 * 1024), 2),
347
  "created": os.path.getctime(file_path)
348
  })
349
+
350
+ # Check bgmusic folder
351
+ if os.path.exists(BG_MUSIC_DIR):
352
+ for filename in os.listdir(BG_MUSIC_DIR):
353
+ file_path = os.path.join(BG_MUSIC_DIR, filename)
354
+ if os.path.isfile(file_path):
355
+ files_data["bgmusic"].append({
356
+ "filename": filename,
357
+ "size_mb": round(os.path.getsize(file_path) / (1024 * 1024), 2),
358
+ "created": os.path.getctime(file_path)
359
+ })
360
 
361
  return {
362
  "status": "success",
363
  "counts": {
364
  "temp": len(files_data["temp"]),
365
  "processed": len(files_data["processed"]),
366
+ "originals": len(files_data["originals"]),
367
+ "bgmusic": len(files_data["bgmusic"])
368
  },
369
  "files": files_data
370
  }
 
383
  "originals": ORIGINALS_DIR,
384
  "processed": PROCESSED_DIR,
385
  "audio": AUDIO_DIR,
386
+ "bgmusic": BG_MUSIC_DIR,
387
  "temp": TEMP_DIR
388
  }
389
 
 
441
  # نحدد الفولدرات المستهدفة
442
  target_folders = []
443
  if folder == "all":
444
+ target_folders = [TEMP_DIR, PROCESSED_DIR, AUDIO_DIR, BG_MUSIC_DIR] # مش هنمسح originals
445
  elif folder == "temp":
446
  target_folders = [TEMP_DIR]
447
  elif folder == "processed":
448
  target_folders = [PROCESSED_DIR]
449
  elif folder == "audio":
450
  target_folders = [AUDIO_DIR]
451
+ elif folder == "bgmusic":
452
+ target_folders = [BG_MUSIC_DIR]
453
  elif folder == "originals":
454
  target_folders = [ORIGINALS_DIR]
455
  else:
video_processor.py CHANGED
@@ -105,14 +105,7 @@ def process_video_clips(video_path: str, timestamps, output_format: VideoFormat,
105
 
106
  # Extract subclip and process it
107
  with video.subclipped(ts.start_time, end) as subclip:
108
- # 1. Export Clean Audio (Transcript Source) if requested
109
- if export_audio and subclip.audio:
110
- audio_filename = f"clip_{clip_id}.mp3"
111
- audio_output_path = os.path.join(os.path.dirname(video_path), audio_filename)
112
- subclip.audio.write_audiofile(
113
- audio_output_path,
114
- logger=None
115
- )
116
 
117
  # Apply background music if available
118
  if bg_music:
@@ -329,15 +322,8 @@ def process_single_clip(ts, video_path, output_format, custom_dims, export_audio
329
  output_filename = f"clip_{clip_id}.mp4"
330
  output_path = os.path.join(os.path.dirname(video_path), output_filename)
331
 
332
- # 1. Export Clean Audio (Transcript Source) if requested
333
  audio_output_path = None
334
- if export_audio and subclip.audio:
335
- audio_filename = f"clip_{clip_id}.mp3"
336
- audio_output_path = os.path.join(os.path.dirname(video_path), audio_filename)
337
- subclip.audio.write_audiofile(
338
- audio_output_path,
339
- logger=None
340
- )
341
 
342
  # Apply background music if available
343
  if bg_music:
 
105
 
106
  # Extract subclip and process it
107
  with video.subclipped(ts.start_time, end) as subclip:
108
+ # (Removed automatic audio extraction to mp3)
 
 
 
 
 
 
 
109
 
110
  # Apply background music if available
111
  if bg_music:
 
322
  output_filename = f"clip_{clip_id}.mp4"
323
  output_path = os.path.join(os.path.dirname(video_path), output_filename)
324
 
325
+ # (Removed automatic audio extraction to mp3)
326
  audio_output_path = None
 
 
 
 
 
 
 
327
 
328
  # Apply background music if available
329
  if bg_music: