feat: search

This commit is contained in:
Artemy 2023-08-08 17:33:10 +03:00
parent d018ea89fc
commit c977203bfd
4 changed files with 24 additions and 3 deletions

4
package-lock.json generated
View file

@ -1,12 +1,12 @@
{
"name": "piped-api",
"version": "1.0.5",
"version": "1.1.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "piped-api",
"version": "1.0.5",
"version": "1.1.0",
"license": "MIT",
"dependencies": {
"got": "^13.0.0"

View file

@ -1,6 +1,6 @@
{
"name": "piped-api",
"version": "1.0.5",
"version": "1.1.0",
"description": "",
"main": "dist/index.js",
"type": "module",

View file

@ -5,6 +5,7 @@ import {
NextPageChannel,
NextPagePlaylist,
Playlist,
Search,
Sponsors,
Streams,
Video,
@ -137,4 +138,15 @@ export class PipedAPI {
`/sponsors/${id}?category=${JSON.stringify(category)}`
);
}
/**
* Searches videos for a given query with an optional filter.
*
* @param {string} query - The query to search for.
* @param {string} [filter="all"] - The optional filter to apply.
* @returns {Promise<Search>} - A Promise that resolves to the search results.
*/
async search(query: string, filter: string = "all"): Promise<Search> {
return await this._get(`/search?q=${query}&filter=${filter}`);
}
}

View file

@ -92,6 +92,7 @@ export interface Video {
isShort: boolean;
uploaded: number;
shortDescription: string;
type?: string;
}
export interface Channel {
@ -104,6 +105,7 @@ export interface Channel {
relatedStreams: Video[];
subscriberCount: number;
verified: boolean;
type?: string;
}
export interface NextPageChannel {
@ -141,3 +143,10 @@ export interface Segments {
segment: string;
videoDuration: number;
}
export interface Search {
nextpage: string;
items: (Video | Channel)[];
corrected: boolean;
suggestion: string | null;
}