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", "name": "piped-api",
"version": "1.0.5", "version": "1.1.0",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "piped-api", "name": "piped-api",
"version": "1.0.5", "version": "1.1.0",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"got": "^13.0.0" "got": "^13.0.0"

View file

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

View file

@ -5,6 +5,7 @@ import {
NextPageChannel, NextPageChannel,
NextPagePlaylist, NextPagePlaylist,
Playlist, Playlist,
Search,
Sponsors, Sponsors,
Streams, Streams,
Video, Video,
@ -137,4 +138,15 @@ export class PipedAPI {
`/sponsors/${id}?category=${JSON.stringify(category)}` `/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; isShort: boolean;
uploaded: number; uploaded: number;
shortDescription: string; shortDescription: string;
type?: string;
} }
export interface Channel { export interface Channel {
@ -104,6 +105,7 @@ export interface Channel {
relatedStreams: Video[]; relatedStreams: Video[];
subscriberCount: number; subscriberCount: number;
verified: boolean; verified: boolean;
type?: string;
} }
export interface NextPageChannel { export interface NextPageChannel {
@ -141,3 +143,10 @@ export interface Segments {
segment: string; segment: string;
videoDuration: number; videoDuration: number;
} }
export interface Search {
nextpage: string;
items: (Video | Channel)[];
corrected: boolean;
suggestion: string | null;
}