🎨 style: Format Code

This commit is contained in:
yyhhyyyyyy
2024-12-10 10:34:56 +08:00
parent 809d6cabbb
commit afd064e15d
17 changed files with 123 additions and 95 deletions

View File

@@ -1,14 +1,14 @@
import os
import random
from typing import List
from urllib.parse import urlencode
import requests
from typing import List
from loguru import logger
from moviepy.video.io.VideoFileClip import VideoFileClip
from app.config import config
from app.models.schema import VideoAspect, VideoConcatMode, MaterialInfo
from app.models.schema import MaterialInfo, VideoAspect, VideoConcatMode
from app.utils import utils
requested_count = 0
@@ -42,7 +42,7 @@ def search_videos_pexels(
api_key = get_api_key("pexels_api_keys")
headers = {
"Authorization": api_key,
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36"
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36",
}
# Build URL
params = {"query": search_term, "per_page": 20, "orientation": video_orientation}
@@ -129,7 +129,7 @@ def search_videos_pixabay(
for video_type in video_files:
video = video_files[video_type]
w = int(video["width"])
h = int(video["height"])
# h = int(video["height"])
if w >= video_width:
item = MaterialInfo()
item.provider = "pixabay"
@@ -169,7 +169,11 @@ def save_video(video_url: str, save_dir: str = "") -> str:
with open(video_path, "wb") as f:
f.write(
requests.get(
video_url, headers=headers, proxies=config.proxy, verify=False, timeout=(60, 240)
video_url,
headers=headers,
proxies=config.proxy,
verify=False,
timeout=(60, 240),
).content
)
@@ -184,7 +188,7 @@ def save_video(video_url: str, save_dir: str = "") -> str:
except Exception as e:
try:
os.remove(video_path)
except Exception as e:
except Exception:
pass
logger.warning(f"invalid video file: {video_path} => {str(e)}")
return ""