generated from openpeeps/pistachio
-
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.
Signed-off-by: George Lemon <[email protected]>
- Loading branch information
1 parent
a201444
commit b7e9c4d
Showing
3 changed files
with
78 additions
and
2 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
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
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 |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# This package provides a Nim API client for the | ||
# Pexels.com API: https://www.pexels.com/api/ | ||
# | ||
# (c) 2024 George Lemon | MIT License | ||
# Made by Humans from OpenPeeps | ||
# https://github.com/openpeeps/pexels-nim | ||
import std/[strutils, colors] | ||
import pkg/jsony | ||
|
||
import ./metaclient | ||
|
||
type | ||
PexelsVideoQuality* = enum | ||
videoQualitySD = "sd" | ||
videoQualityHD = "hd" | ||
videoQualityHLS = "hls" | ||
videoQualityUHD = "uhd" | ||
|
||
PexelsVideographer* = object | ||
id*: uint | ||
name*, url*: string | ||
|
||
PexelsVideoFile* = object | ||
id*: uint | ||
quality*: PexelsVideoQuality | ||
file_type*: string | ||
width*, height*: uint | ||
fps: float | ||
link*: string | ||
|
||
PexelsVideoPicture* = object | ||
id*: uint | ||
picture*: string | ||
nr*: uint | ||
|
||
PexelsVideoResponse* = object | ||
id*, width*, height*: uint | ||
url*, image*: string | ||
duration*: uint | ||
user*: PexelsVideographer | ||
video_files*: seq[PexelsVideoFile] | ||
video_pictures*: seq[PexelsVideoPicture] | ||
|
||
PexelsVideosResponse* = object of PexelsListingResponse | ||
videos*: seq[PexelsVideoResponse] | ||
|
||
proc `$`*(videosResponse: PexelsVideosResponse): string = | ||
## Convert `PexelsVideosResponse` object to JSON | ||
videosResponse.toJson() | ||
|
||
proc `$`*(videoResponse: PexelsVideoPicture): string = | ||
## Convert `PexelsVideoPicture` object to JSON | ||
videoResponse.toJson() | ||
|
||
proc videos*(pexels: Pexels, query: string): Future[PexelsVideosResponse] {.async.} = | ||
## Search for videos by `query` | ||
pexels.query["query"] = query | ||
let res: AsyncResponse = await pexels.httpGet(PexelsEndpoint.epSearchVideos) | ||
let body = await res.body | ||
result = fromJson(body, PexelsVideosResponse) | ||
pexels.client.close() | ||
|
||
iterator items*(videosResponse: PexelsVideosResponse): PexelsVideoResponse = | ||
for v in videosResponse.videos: | ||
yield v |