mirror of
https://github.com/artegoser/piped-api.git
synced 2024-11-21 18:56:22 +03:00
feat: all endpoints
This commit is contained in:
parent
7c363cd803
commit
feca5d499b
3 changed files with 134 additions and 2 deletions
21
README.md
Normal file
21
README.md
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
# Piped API
|
||||||
|
|
||||||
|
This is the API wrapper for Piped in Node.js (Typescript).
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm i piped-api
|
||||||
|
```
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import { PipedApi } from "piped-api";
|
||||||
|
|
||||||
|
const api = new PipedApi("https://ytapi.dc09.ru");
|
||||||
|
|
||||||
|
let trending = await api.trending("US");
|
||||||
|
|
||||||
|
console.log(trending[0].title);
|
||||||
|
```
|
|
@ -5,7 +5,8 @@
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "echo \"Error: no test specified\" && exit 1",
|
"test": "echo \"Error: no test specified\" && exit 1",
|
||||||
"build": "tsc"
|
"build": "tsc",
|
||||||
|
"prepublishOnly": "npm run build"
|
||||||
},
|
},
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"author": "artegoser",
|
"author": "artegoser",
|
||||||
|
|
112
src/index.ts
112
src/index.ts
|
@ -1,5 +1,14 @@
|
||||||
import got from "got";
|
import got from "got";
|
||||||
import { Video } from "./responses.interface";
|
import {
|
||||||
|
Channel,
|
||||||
|
Comments,
|
||||||
|
NextPageChannel,
|
||||||
|
NextPagePlaylist,
|
||||||
|
Playlist,
|
||||||
|
Sponsors,
|
||||||
|
Streams,
|
||||||
|
Video,
|
||||||
|
} from "./responses.interface";
|
||||||
|
|
||||||
export class PipedAPI {
|
export class PipedAPI {
|
||||||
host: string;
|
host: string;
|
||||||
|
@ -27,4 +36,105 @@ export class PipedAPI {
|
||||||
async trending(region: string): Promise<Video[]> {
|
async trending(region: string): Promise<Video[]> {
|
||||||
return await this._get(`/trending?region=${region}`);
|
return await this._get(`/trending?region=${region}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the streams for a given video ID.
|
||||||
|
*
|
||||||
|
* @param {string} videoId - The ID of the video.
|
||||||
|
* @return {Promise<Streams>} A promise that resolves to the streams for the given video ID.
|
||||||
|
*/
|
||||||
|
async streams(videoId: string): Promise<Streams> {
|
||||||
|
return await this._get(`/streams/${videoId}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves comments for a specific video.
|
||||||
|
*
|
||||||
|
* @param {string} videoId - The ID of the video for which to retrieve comments.
|
||||||
|
* @param {string} nextpage - The JSON encoded nextpage variable, to be sent as a query string (optional).
|
||||||
|
* @returns {Promise<Comments>} A Promise that resolves to the comments for the video.
|
||||||
|
*/
|
||||||
|
async comments(videoId: string, nextpage?: string): Promise<Comments> {
|
||||||
|
return nextpage
|
||||||
|
? await this._get(`/nextpage/comments/${videoId}?nextpage=${nextpage}`)
|
||||||
|
: await this._get(`/comments/${videoId}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves a channel by its ID.
|
||||||
|
*
|
||||||
|
* @param {string} id - The ID of the channel to retrieve.
|
||||||
|
* @param {string} nextpage - The JSON encoded nextpage variable, to be sent as a query string (optional).
|
||||||
|
* @return {Promise<Channel | NextPageChannel>} A Promise that resolves to the retrieved Channel object.
|
||||||
|
*/
|
||||||
|
async channel(
|
||||||
|
id: string,
|
||||||
|
nextpage?: string
|
||||||
|
): Promise<Channel | NextPageChannel> {
|
||||||
|
return nextpage
|
||||||
|
? await this._get(`/nextpage/channel/${id}?nextpage=${nextpage}`)
|
||||||
|
: await this._get(`/channel/${id}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves a channel by its name.
|
||||||
|
*
|
||||||
|
* @param {string} name - The name of the channel.
|
||||||
|
* @return {Promise<Channel>} A promise that resolves to the channel object.
|
||||||
|
*/
|
||||||
|
async channelByName(name: string): Promise<Channel> {
|
||||||
|
return await this._get(`/c/${name}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves a user by their name.
|
||||||
|
*
|
||||||
|
* @param {string} name - The name of the user.
|
||||||
|
* @return {Promise<Channel>} A Promise that resolves to the user's channel.
|
||||||
|
*/
|
||||||
|
async user(name: string): Promise<Channel> {
|
||||||
|
return await this._get(`/user/${name}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves a playlist based on its ID.
|
||||||
|
*
|
||||||
|
* @param {string} id - The ID of the playlist to retrieve.
|
||||||
|
* @param {string} nextpage - The token for the next page of results (optional).
|
||||||
|
* @return {Promise<Playlist | NextPagePlaylist>} A Promise that resolves to a Playlist or NextPagePlaylist object.
|
||||||
|
*/
|
||||||
|
async playlist(
|
||||||
|
id: string,
|
||||||
|
nextpage?: string
|
||||||
|
): Promise<Playlist | NextPagePlaylist> {
|
||||||
|
return nextpage
|
||||||
|
? await this._get(`/nextpage/playlists/${id}?nextpage=${nextpage}`)
|
||||||
|
: await this._get(`/playlists/${id}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves suggestions based on the given query.
|
||||||
|
*
|
||||||
|
* @param {string} query - The query string to search for suggestions.
|
||||||
|
* @return {Promise<string[]>} A promise that resolves to an array of string suggestions.
|
||||||
|
*/
|
||||||
|
async suggestions(query: string): Promise<string[]> {
|
||||||
|
return await this._get(`/suggestions?query=${query}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves sponsors based on the provided ID and category.
|
||||||
|
*
|
||||||
|
* @param {string} id - The ID of the video.
|
||||||
|
* @param {string[]} category - The category of sponsors you would like to skip. Example: ["sponsor"].
|
||||||
|
* @return {Promise<Sponsors>} A promise that resolves to the sponsors.
|
||||||
|
*/
|
||||||
|
async sponsors(
|
||||||
|
id: string,
|
||||||
|
category: string[] = ["sponsor"]
|
||||||
|
): Promise<Sponsors> {
|
||||||
|
return await this._get(
|
||||||
|
`/sponsors/${id}?category=${JSON.stringify(category)}`
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue