Skip to content

Commit

Permalink
Merge pull request #5 from Lioness100/master
Browse files Browse the repository at this point in the history
Added typings
  • Loading branch information
Yimura authored Mar 25, 2021
2 parents 38566fc + cfd724a commit fe92847
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 0 deletions.
94 changes: 94 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
export interface SearchTypes {
ANY: "CAA%3D";
CHANNEL: "EgIQAg%3D%3D";
LIVE: "EgJAAQ%3D%3D";
MOVIE: "EgIQBA%3D%3D";
PLAYLIST: "EgIQAw%3D%3D";
VIDEO: "EgIQAQ%3D%3D";
}

const Constants = {
SearchTypes,
YoutubeURL: URL.prototype,
}

export interface Thumbnail {
url: string;
width: number;
height: number;
}

export interface GeneralData {
id: string;
link: string;
thumbnail: string;
title: string;
}

export interface ShareableGeneralData extends GeneralData {
shareLink: string;
}

export interface VideoPreview extends ShareableGeneralData {
duration: number;
views: number;
}

export interface ChannelPreview {
name: string;
link: string;
verified: boolean;
}

export interface Video extends ShareableGeneralData {
description: string;
duration: number;
uploaded: string;
views: number;
channel: ChannelPreview;
}

export interface Playlist extends GeneralData {
preview: VideoPreview[];
}

export interface Stream extends ShareableGeneralData {
watching: number;
channel: ChannelPreview;
}

export interface Channel {
channelId: string;
description: string;
link: string;
thumbnails: Thumbnail[];
subscribed: boolean;
uploadedVideos: number;
verified: boolean;
}

export interface Results {
channels: Channel[];
playlists: Playlist[];
streams: Stream[];
videos: Video[];
}

export interface SearchOptions {
searchType?: keyof SearchTypes;
language?: string;
}

class Scraper {
private _lang: string;

public constructor(language?: string);

private _extractData(json: Record<string, unknown>): Record<string, unknown>[];
private _fetch(search_query: string, searchType?: keyof SearchTypes, requestedLang?: string): Promise<string>;
private _getSearchData(webPage: string): Record<string, unknown>;
private _parseData(data: Record<string, unknown>[]): Results;

public async search(query: string, options?: SearchOptions): Promise<Results>;
public setLang(language?: string): void;
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "1.1.0",
"description": "A YouTube scraper using zero dependencies",
"main": "index.js",
"types": "index.d.ts",
"scripts": {
"test": "node test/index.js"
},
Expand Down

0 comments on commit fe92847

Please sign in to comment.