feat: trending

And all types
This commit is contained in:
Artemy 2023-08-03 20:36:16 +03:00
parent d407a14448
commit 7c363cd803
8 changed files with 2601 additions and 0 deletions

30
src/index.ts Normal file
View file

@ -0,0 +1,30 @@
import got from "got";
import { Video } from "./responses.interface";
export class PipedAPI {
host: string;
constructor(host: string = "https://pipedapi.kavin.rocks") {
this.host = host;
}
/**
* Retrieves data from the specified URL.
*
* @param {string} url - The URL from which to retrieve data.
* @return {Promise<any>} - A Promise that resolves to the parsed JSON data.
*/
private async _get(url: string) {
const data = await got.get(`${this.host}${url}`);
return JSON.parse(data.body);
}
/**
* Retrieves the trending videos for a specific region.
*
* @param {string} region - The region for which to retrieve trending videos.
* @return {Promise<Video[]>} - A promise that resolves to an array of Video objects representing the trending videos.
*/
async trending(region: string): Promise<Video[]> {
return await this._get(`/trending?region=${region}`);
}
}

140
src/responses.interface.ts Normal file
View file

@ -0,0 +1,140 @@
export interface Streams {
audioStreams: AudioStream[];
dash: string | null;
description: string;
dislikes: number;
duration: number;
hls: string | null;
lbryId: string;
likes: number;
livestream: boolean;
proxyUrl: string;
relatedStreams: Video[];
subtitles: Subtitle[];
thumbnailUrl: string;
title: string;
uploadedDate: string;
uploader: string;
uploaderUrl: string;
uploaderVerified: boolean;
videoStreams: VideoStream[];
views: number;
}
export interface AudioStream {
bitrate: number;
codec: string;
format: string;
indexEnd: number;
indexStart: number;
initStart: number;
initEnd: number;
mimeType: string;
quality: string;
url: string;
videoOnly: boolean;
}
export interface Subtitle {
autoGenerated: boolean;
code: string;
mimeType: string;
name: string;
url: string;
}
export interface VideoStream {
bitrate: number;
codec: string;
format: string;
fps: number;
height: number;
indexEnd: number;
indexStart: number;
initStart: number;
initEnd: number;
mimeType: string;
quality: string;
url: string;
videoOnly: boolean;
width: number;
}
export interface Comments {
comments: Comment[];
disabled: boolean;
nextpage: string;
}
export interface Comment {
author: string;
commentId: string;
commentText: string;
commentedTime: string;
commentorUrl: string;
hearted: boolean;
likeCount: number;
pinned: boolean;
thumbnail: string;
verified: boolean;
}
export interface Video {
duration: number;
thumbnail: string;
title: string;
uploadedDate: string;
uploaderAvatar: string;
uploaderUrl: string;
uploaderVerified: boolean;
url: string;
views: number;
}
export interface Channel {
avatarUrl: string;
bannerUrl: string;
description: string;
id: string;
name: string;
nextpage: string;
relatedStreams: Video[];
subscriberCount: number;
verified: boolean;
}
export interface NextPageChannel {
nextpage: string;
relatedStreams: Video[];
}
export interface Playlist {
bannerUrl: string;
name: string;
nextpage: string;
relatedStreams: Video[];
thumbnailUrl: string;
uploader: string;
uploaderAvatar: string;
uploaderUrl: string;
videos: number;
}
export interface NextPagePlaylist {
nextpage: string;
relatedStreams: Video[];
}
export interface Sponsors {
hash: string;
segments: Segments[];
videoId: string;
}
export interface Segments {
UUID: string;
actionType: string;
category: string;
segment: string;
videoDuration: number;
}