forked from FujiwaraChoki/MoneyPrinter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.py
52 lines (40 loc) · 1.2 KB
/
search.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import requests
from typing import List
from termcolor import colored
def search_for_stock_videos(query: str, api_key: str) -> List[str]:
"""
Searches for stock videos based on a query.
Args:
query (str): The query to search for.
api_key (str): The API key to use.
Returns:
List[str]: A list of stock videos.
"""
# Build headers
headers = {
"Authorization": api_key
}
# Build URL
url = f"https://api.pexels.com/videos/search?query={query}&per_page=1"
# Send the request
r = requests.get(url, headers=headers)
# Parse the response
response = r.json()
# Get first video url
video_urls = []
video_url = ""
try:
video_urls = response["videos"][0]["video_files"]
except:
print(colored("[-] No Videos found.", "red"))
print(colored(response, "red"))
# Loop through video urls
for video in video_urls:
# Check if video has a download link
if ".com/external" in video["link"]:
# Set video url
video_url = video["link"]
# Let user know
print(colored(f"\t=>{video_url}", "light_cyan"))
# Return the video url
return video_url