-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from Lioness100/master
Added typings
- Loading branch information
Showing
2 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters