add pexels.proxies
This commit is contained in:
@@ -12,6 +12,8 @@ with open(config_file, mode="rb") as fp:
|
|||||||
|
|
||||||
app = _cfg.get("app", {})
|
app = _cfg.get("app", {})
|
||||||
whisper = _cfg.get("whisper", {})
|
whisper = _cfg.get("whisper", {})
|
||||||
|
pexels = _cfg.get("pexels", {})
|
||||||
|
|
||||||
hostname = socket.gethostname()
|
hostname = socket.gethostname()
|
||||||
|
|
||||||
log_level = _cfg.get("log_level", "DEBUG")
|
log_level = _cfg.get("log_level", "DEBUG")
|
||||||
|
|||||||
@@ -33,12 +33,12 @@ def search_videos(search_term: str,
|
|||||||
headers = {
|
headers = {
|
||||||
"Authorization": round_robin_api_key()
|
"Authorization": round_robin_api_key()
|
||||||
}
|
}
|
||||||
|
proxies = config.pexels.get("proxies", None)
|
||||||
# Build URL
|
# Build URL
|
||||||
query_url = f"https://api.pexels.com/videos/search?query={search_term}&per_page=15&orientation={video_orientation}&locale={locale}"
|
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
|
# Send the request
|
||||||
r = requests.get(query_url, headers=headers)
|
r = requests.get(query_url, headers=headers, proxies=proxies, verify=False)
|
||||||
|
|
||||||
# Parse the response
|
# Parse the response
|
||||||
response = r.json()
|
response = r.json()
|
||||||
@@ -71,8 +71,9 @@ def search_videos(search_term: str,
|
|||||||
def save_video(video_url: str, save_dir: str) -> str:
|
def save_video(video_url: str, save_dir: str) -> str:
|
||||||
video_id = f"vid-{str(int(time.time() * 1000))}"
|
video_id = f"vid-{str(int(time.time() * 1000))}"
|
||||||
video_path = f"{save_dir}/{video_id}.mp4"
|
video_path = f"{save_dir}/{video_id}.mp4"
|
||||||
|
proxies = config.pexels.get("proxies", None)
|
||||||
with open(video_path, "wb") as f:
|
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
|
return video_path
|
||||||
|
|
||||||
|
|||||||
@@ -50,4 +50,13 @@
|
|||||||
model_size="large-v3"
|
model_size="large-v3"
|
||||||
# if you want to use GPU, set device="cuda"
|
# if you want to use GPU, set device="cuda"
|
||||||
device="CPU"
|
device="CPU"
|
||||||
compute_type="int8"
|
compute_type="int8"
|
||||||
|
|
||||||
|
[pexels]
|
||||||
|
[pexels.proxies]
|
||||||
|
### Use a proxy to access the Pexels API
|
||||||
|
### Format: "http://<username>:<password>@<proxy>:<port>"
|
||||||
|
### 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"
|
||||||
Reference in New Issue
Block a user