forked from FujiwaraChoki/MoneyPrinter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
710 additions
and
693 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,66 @@ | ||
import requests | ||
|
||
from typing import List | ||
from termcolor import colored | ||
|
||
def search_for_stock_videos(query: str, api_key: str, it: int) -> 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 | ||
qurl = f"https://api.pexels.com/videos/search?query={query}&per_page={it}" | ||
|
||
# Send the request | ||
r = requests.get(qurl, headers=headers) | ||
|
||
# Parse the response | ||
response = r.json() | ||
|
||
# Parse each video | ||
raw_urls = [] | ||
video_url = [] | ||
video_res = 0 | ||
try: | ||
# loop through each video in the result | ||
for i in range(it): | ||
raw_urls = response["videos"][i]["video_files"] | ||
temp_video_url = "" | ||
|
||
# loop through each url to determine the best quality | ||
for video in raw_urls: | ||
# Check if video has a valid download link | ||
if ".com/external" in video["link"]: | ||
# Only save the URL with the largest resolution | ||
if (video["width"]*video["height"]) > video_res: | ||
temp_video_url = video["link"] | ||
video_res = video["width"]*video["height"] | ||
|
||
# add the url to the return list if it's not empty | ||
if temp_video_url != "": | ||
video_url.append(temp_video_url) | ||
|
||
except Exception as e: | ||
print(colored("[-] No Videos found.", "red")) | ||
print(colored(e, "red")) | ||
|
||
# Let user know | ||
print(colored(f"\t=> \"{query}\" found {len(video_url)} Videos", "cyan")) | ||
|
||
# Return the video url | ||
return video_url | ||
import requests | ||
|
||
from typing import List | ||
from termcolor import colored | ||
|
||
def search_for_stock_videos(query: str, api_key: str, it: int, min_dur: int) -> 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 | ||
qurl = f"https://api.pexels.com/videos/search?query={query}&per_page={it}" | ||
|
||
# Send the request | ||
r = requests.get(qurl, headers=headers) | ||
|
||
# Parse the response | ||
response = r.json() | ||
|
||
# Parse each video | ||
raw_urls = [] | ||
video_url = [] | ||
video_res = 0 | ||
try: | ||
# loop through each video in the result | ||
for i in range(it): | ||
#check if video has desired minimum duration | ||
if response["videos"][i]["duration"] < min_dur: | ||
continue | ||
raw_urls = response["videos"][i]["video_files"] | ||
temp_video_url = "" | ||
|
||
# loop through each url to determine the best quality | ||
for video in raw_urls: | ||
# Check if video has a valid download link | ||
if ".com/external" in video["link"]: | ||
# Only save the URL with the largest resolution | ||
if (video["width"]*video["height"]) > video_res: | ||
temp_video_url = video["link"] | ||
video_res = video["width"]*video["height"] | ||
|
||
# add the url to the return list if it's not empty | ||
if temp_video_url != "": | ||
video_url.append(temp_video_url) | ||
|
||
except Exception as e: | ||
print(colored("[-] No Videos found.", "red")) | ||
print(colored(e, "red")) | ||
|
||
# Let user know | ||
print(colored(f"\t=> \"{query}\" found {len(video_url)} Videos", "cyan")) | ||
|
||
# Return the video url | ||
return video_url |
Oops, something went wrong.