diff --git a/app/config/config.py b/app/config/config.py index ab4aa6e..d05eb17 100644 --- a/app/config/config.py +++ b/app/config/config.py @@ -12,6 +12,8 @@ with open(config_file, mode="rb") as fp: app = _cfg.get("app", {}) whisper = _cfg.get("whisper", {}) +pexels = _cfg.get("pexels", {}) + hostname = socket.gethostname() log_level = _cfg.get("log_level", "DEBUG") diff --git a/app/services/material.py b/app/services/material.py index 8aa5900..2c0bbf7 100644 --- a/app/services/material.py +++ b/app/services/material.py @@ -33,12 +33,12 @@ def search_videos(search_term: str, headers = { "Authorization": round_robin_api_key() } - + proxies = config.pexels.get("proxies", None) # Build URL query_url = f"https://api.pexels.com/videos/search?query={search_term}&per_page=15&orientation={video_orientation}&locale={locale}" - logger.info(f"searching videos: {query_url}") + logger.info(f"searching videos: {query_url}, with proxies: {proxies}") # Send the request - r = requests.get(query_url, headers=headers) + r = requests.get(query_url, headers=headers, proxies=proxies, verify=False) # Parse the response response = r.json() @@ -71,8 +71,9 @@ def search_videos(search_term: str, def save_video(video_url: str, save_dir: str) -> str: video_id = f"vid-{str(int(time.time() * 1000))}" video_path = f"{save_dir}/{video_id}.mp4" + proxies = config.pexels.get("proxies", None) with open(video_path, "wb") as f: - f.write(requests.get(video_url).content) + f.write(requests.get(video_url, proxies=proxies, verify=False).content) return video_path diff --git a/config.example.toml b/config.example.toml index 7fc8ae5..7a669ec 100644 --- a/config.example.toml +++ b/config.example.toml @@ -50,4 +50,13 @@ model_size="large-v3" # if you want to use GPU, set device="cuda" device="CPU" - compute_type="int8" \ No newline at end of file + compute_type="int8" + +[pexels] + [pexels.proxies] + ### Use a proxy to access the Pexels API + ### Format: "http://:@:" + ### Example: "http://user:pass@proxy:1234" + ### Doc: https://requests.readthedocs.io/en/latest/user/advanced/#proxies + # http = "http://10.10.1.10:3128" + # https = "http://10.10.1.10:1080" \ No newline at end of file