filter out corrupted video files
This commit is contained in:
@@ -13,7 +13,8 @@ from app.utils import utils
|
|||||||
requested_count = 0
|
requested_count = 0
|
||||||
pexels_api_keys = config.app.get("pexels_api_keys")
|
pexels_api_keys = config.app.get("pexels_api_keys")
|
||||||
if not pexels_api_keys:
|
if not pexels_api_keys:
|
||||||
raise ValueError(f"\n\n##### pexels_api_keys is not set #####\n\nPlease set it in the config.toml file: {config.config_file}\n\n{utils.to_json(config.app)}")
|
raise ValueError(
|
||||||
|
f"\n\n##### pexels_api_keys is not set #####\n\nPlease set it in the config.toml file: {config.config_file}\n\n{utils.to_json(config.app)}")
|
||||||
|
|
||||||
|
|
||||||
def round_robin_api_key():
|
def round_robin_api_key():
|
||||||
@@ -93,7 +94,7 @@ def save_video(video_url: str, save_dir: str = "") -> str:
|
|||||||
video_path = f"{save_dir}/{video_id}.mp4"
|
video_path = f"{save_dir}/{video_id}.mp4"
|
||||||
|
|
||||||
# if video already exists, return the path
|
# if video already exists, return the path
|
||||||
if os.path.exists(video_path):
|
if os.path.exists(video_path) and os.path.getsize(video_path) > 0:
|
||||||
logger.info(f"video already exists: {video_path}")
|
logger.info(f"video already exists: {video_path}")
|
||||||
return video_path
|
return video_path
|
||||||
|
|
||||||
@@ -102,7 +103,9 @@ def save_video(video_url: str, save_dir: str = "") -> str:
|
|||||||
with open(video_path, "wb") as f:
|
with open(video_path, "wb") as f:
|
||||||
f.write(requests.get(video_url, proxies=proxies, verify=False, timeout=(60, 240)).content)
|
f.write(requests.get(video_url, proxies=proxies, verify=False, timeout=(60, 240)).content)
|
||||||
|
|
||||||
|
if os.path.exists(video_path) and os.path.getsize(video_path) > 0:
|
||||||
return video_path
|
return video_path
|
||||||
|
return ""
|
||||||
|
|
||||||
|
|
||||||
def download_videos(task_id: str,
|
def download_videos(task_id: str,
|
||||||
@@ -146,6 +149,7 @@ def download_videos(task_id: str,
|
|||||||
try:
|
try:
|
||||||
logger.info(f"downloading video: {item.url}")
|
logger.info(f"downloading video: {item.url}")
|
||||||
saved_video_path = save_video(video_url=item.url, save_dir=material_directory)
|
saved_video_path = save_video(video_url=item.url, save_dir=material_directory)
|
||||||
|
if saved_video_path:
|
||||||
logger.info(f"video saved: {saved_video_path}")
|
logger.info(f"video saved: {saved_video_path}")
|
||||||
video_paths.append(saved_video_path)
|
video_paths.append(saved_video_path)
|
||||||
seconds = min(max_clip_duration, item.duration)
|
seconds = min(max_clip_duration, item.duration)
|
||||||
|
|||||||
Reference in New Issue
Block a user