Skip to content
This repository has been archived by the owner on Sep 20, 2023. It is now read-only.

Commit

Permalink
added typescript type definitions (#17)
Browse files Browse the repository at this point in the history
* added typescript type definitions

* Update typescript declarations

* Add isOfficialArtist to channel object

* Use multi-line comments

Co-authored-by: Alexandra <bug.graph@gmail.com>

* remove playlist url from getChannelVideos

* Squashed commit of the following:

commit 243483f
Author: SuperFurryCoder <100633427+SuperFurryCoder@users.noreply.github.com>
Date:   Tue Mar 15 20:07:14 2022 +0000

    Fix for channels with no secondary links (#61)

    * Update youtube-grabber.js

    * Update youtube-grabber.js

    * Update youtube-grabber.js

    * Update youtube-grabber.js

    * remove unnecessary space

    Co-authored-by: PikachuEXE <pikachuexe@gmail.com>

    Co-authored-by: ChunkyProgrammer <78101139+ChunkyProgrammer@users.noreply.github.com>
    Co-authored-by: PikachuEXE <pikachuexe@gmail.com>

commit 3291db3
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Sun Feb 13 14:02:57 2022 -0500

    Bump follow-redirects from 1.14.7 to 1.14.8 (#60)

    Bumps [follow-redirects](https://github.com/follow-redirects/follow-redirects) from 1.14.7 to 1.14.8.
    - [Release notes](https://github.com/follow-redirects/follow-redirects/releases)
    - [Commits](follow-redirects/follow-redirects@v1.14.7...v1.14.8)

    ---
    updated-dependencies:
    - dependency-name: follow-redirects
      dependency-type: indirect
    ...

    Signed-off-by: dependabot[bot] <support@github.com>

    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* add getChannelStats and getChannelHome

* fix HttpsProxyAgent reference

* include types file in "files"

Co-authored-by: ChunkyProgrammer <78101139+ChunkyProgrammer@users.noreply.github.com>
Co-authored-by: Alexandra <bug.graph@gmail.com>
  • Loading branch information
3 people authored Aug 24, 2022
1 parent 1edd78f commit fb63da4
Show file tree
Hide file tree
Showing 3 changed files with 259 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ ytch.getChannelVideosMore(payload).then((response) => {
- channelId (String) (Required) - The channel ID to grab playlists from
- sortBy (String) (Optional) - 'last' sort by last updated or 'newest' sort by creation date
- `last` - Grabs playlists from a channel sorted by the most recently updated playlist (Default option if none given)
- `oldest` - Grabs playlists from a channel sorted by the creation date (oldest first)
- `newest` - Grabs playlists from a channel sorted by the creation date (newest first)
- httpsAgent (Object) (Optional) - Same definition as 'httpsAgent' in `getChannelInfo()`
- channelIdType (Integer) (Optional) - Same definition as 'channelIdType' in `getChannelInfo()`
Expand Down Expand Up @@ -215,6 +216,7 @@ ytch.getChannelPlaylistsMore(payload).then((response) => {
- channelId (String) (Required) - The channel you want to search
- query (String) (Required) - The query you want to use
- httpsAgent (Object) (Optional) - Same definition as 'httpsAgent' in `getChannelInfo()`
- channelIdType (Integer) (Optional) - Same definition as 'channelIdType' `getChannelInfo()`

```javascript
const payload = {
Expand Down
254 changes: 254 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,254 @@
import { HttpsProxyAgent } from 'https-proxy-agent';

declare module "yt-channel-info" {

enum ChannelIdType {
Default = 0,
ChannelId,
LegacyName,
CustomURL
}

/**
* A abstract ChannelInfoResponse containing a continuation string if there are more responses which can be loaded
* and an array of items of the type T
*/
interface ChannelInfoResponseContinuation<T> {
items: T[];
/**
* Will be null if no more results can be found. Used with getChannelPlaylistsMore()
*/
continuation: string | null;
}

interface ChannelInfoResponse<T> extends ChannelInfoResponseContinuation<T> {
channelIdType: ChannelIdType;
alertMessage?: string;
}

interface ChannelCommunityPostsContinuationResponse extends ChannelInfoResponseContinuation<CommunityPost> {
innerTubeApi: string;
}
interface ChannelCommunityPostsResponse extends ChannelCommunityPostsContinuationResponse {
channelIdType: ChannelIdType;
}

interface RelatedChannel {
channelName: string;
channelId: string;
channelUrl: string;
thumbnail: Image[];
videoCount: number;
subscriberText: string;
subscriberCount: number;
verified: boolean;
officialArist: boolean;
}

interface ContinuationPayload {
continuation: string;
httpsAgent?: HttpsProxyAgent;
}
/**
* ChannelInfo payload passed into getChannelInfo
*/

interface ChannelInfoPayload {
channelId: string;
channelIdType?: ChannelIdType;
httpsAgent?: HttpsProxyAgent;
}

interface CommunityPostContinuationPayload extends ContinuationPayload {
innerTubeApi: string;
}
interface ChannelVideosPayload extends ChannelInfoPayload {
sortBy?: "newest" | "oldest" | "popular";
}

interface ChannelSearchPayload extends ChannelInfoPayload {
query: string;
}

interface ChannelPlaylistPayload extends ChannelInfoPayload {
sortBy?: "last" | "oldest" | "newest";
}

/**
* ChannelInfo type returned by getChannelVideos and getChannelInfoMore
*/
interface ChannelInfo {
author: string;
authorId: string;
authorUrl: string;
/**
* Is null if none exist
**/
authorBanners: Image[] | null;
/**
* Is null if none exist
**/
authorThumbnails: Image[] | null;
subscriberText: string;
subscriberCount: number;
description: string;
isFamilyFriendly: boolean;
relatedChannels: RelatedChannel[];
allowedRegions: string[];
isVerified: boolean;
isOfficialArtist: boolean;
tags: string[];
channelIdType: number;
alertMessage: string;
}

/**
* An Image which represents all banners and thumbnails
*/
interface Image {
url: string;
height: number;
width: number;
}

/**
* Video type returned by getChannelVideos and getChannelInfoMore
*/
interface Video {
author: string;
authorId: string;
durationText: string;
lengthSeconds: number;
liveNow: boolean;
premiere: boolean;
premium: boolean;
publishedText: string;
title: string;
type: "video";
videoId: string;
videoThumbnails: Image[] | null;
viewCount: number;
viewCountText: string;
}

/**
* Playlist type returned by getChannelPlaylistInfo and getChannelPlaylistsMore
*/
interface Playlist {
author: string;
authorId: string;
authorUrl: string;
playlistId: string;
playlistThumbnail: string;
playlistUrl: string;
title: string;
type: "playlist";
videoCount: number;
}

interface ImagePostContent {
type: "image";
content: Image[]
}

interface PollPostContent {
type: "poll";
content: {
choices: string[];
totalVotes: string
}
}

interface VideoPostContent {
type: "video";
content: {
videoId: string;
title: string;
description: string,
publishedText: string,
lengthText: string,
viewCountText: string,
ownerBadges: {
verified: boolean;
officialArtist: boolean;
},
author: string;
thumbnails: Image[];
}
}
interface PlaylistPostContent {
type: 'playlist',
content: {
playlistId: string;
title: string;
playlistVideoRenderer: VideoPostContent[];
videoCountText: string;
ownerBadges: {
verified: boolean;
officialArtist: boolean;
},
author: String,
thumbnails: Image[];
}
}
interface CommunityPost {
postText: string;
postId: string;
author: string;
authorThumbnails: string;
publishedText: string;
voteCount: string;
postContent: ImagePostContent | PollPostContent | VideoPostContent | PlaylistPostContent | null
}


interface ChannelStatsResponse {
joinedDate: number;
viewCount: number;
location: string;
}

interface Mix {
playlistId: string;
title: string;
description: string;
videoCount: number;
url: string;
thumbnails: Image[]
}
interface ChannelHomeResponse {
featuredVideo : Video
items: {
shelfName: string;
type: 'videos' | 'verticalVideoList' | 'playlist' | 'channels' | 'mix' | 'playlists' | 'video'
items: Video[] | RelatedChannel[] | Playlist[] | Mix
}
}
class YoutubeGrabber {
static getChannelInfo(payload: ChannelInfoPayload): Promise<ChannelInfo>;

static getChannelVideos(payload: ChannelVideosPayload): ChannelInfoResponse<Video>;

static getChannelVideosMore(payload: ContinuationPayload): Promise<ChannelInfoResponseContinuation<Video>>;

static getChannelPlaylistInfo(payload: ChannelPlaylistPayload): Promise<ChannelInfoResponse<Playlist>>;

static getChannelPlaylistsMore(payload: ContinuationPayload): Promise<ChannelInfoResponseContinuation<Playlist>>;

static searchChannel(payload: ChannelSearchPayload): Promise<ChannelInfoResponseContinuation<Video>>;

static searchChannelMore(payload: ContinuationPayload): Promise<ChannelInfoResponseContinuation<Video>>;

static getRelatedChannelsMore(payload: ContinuationPayload): Promise<ChannelInfoResponseContinuation<RelatedChannel>>;

static getChannelCommunityPosts(payload: ChannelInfoPayload): Promise<ChannelCommunityPostsResponse>

static getChannelCommunityPostsMore(payload: CommunityPostContinuationPayload): Promise<ChannelCommunityPostsContinuationResponse>

static getChannelStats(payload: ChannelInfoPayload): Promise<ChannelStatsResponse>

static getChannelHome(payload: ChannelInfoPayload): Promise<ChannelHomeResponse>
}

export = YoutubeGrabber;
}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"main": "index.js",
"files": [
"index.js",
"index.d.ts",
"app/"
],
"scripts": {
Expand Down Expand Up @@ -44,5 +45,6 @@
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"jest": "^27.0.4"
}
},
"types": "index.d.ts"
}

0 comments on commit fb63da4

Please sign in to comment.