-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7de1558
commit 4176a55
Showing
41 changed files
with
1,014 additions
and
335 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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
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
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
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,85 @@ | ||
import { parseChapters } from "../../../utils/parseChapters"; | ||
import { APIProvider } from "../../types/api"; | ||
import { InvidiousInstance } from "../../types/instances"; | ||
import { SearchSuggestions, VideoFormat, VideoData } from "../../types/video"; | ||
import { InvidiousSearchResult, InvidiousVideo, InvidiousVideoData } from "./types"; | ||
|
||
export class InvidiousAPIProvider implements APIProvider { | ||
instance: InvidiousInstance; | ||
|
||
constructor( | ||
instance: InvidiousInstance, | ||
) { | ||
this.instance = instance; | ||
} | ||
|
||
request = async <T>(path: string, opts?: { | ||
query: Record<string, string>; | ||
signal?: AbortSignal; | ||
}) => { | ||
let url = new URL(this.instance.url + "/api/v1/" + path); | ||
|
||
for(let [k,v] of Object.entries(opts?.query || {})) | ||
url.searchParams.set(k, v); | ||
|
||
let res = await fetch(url, { | ||
signal: opts?.signal, | ||
headers: { | ||
"Content-Type": "application/json; utf-8", | ||
}, | ||
}); | ||
|
||
return await res.json() as T; | ||
} | ||
|
||
searchSuggestions = async (query: string, signal?: AbortSignal) => { | ||
let data: { suggestions: string[] } = await this.request("search/suggestions", { | ||
query: { q: query }, | ||
signal, | ||
}); | ||
|
||
return data.suggestions; | ||
}; | ||
|
||
async search(q: string) { | ||
let data: InvidiousSearchResult[] = await this.request("search", { query: { q } }); | ||
|
||
return { | ||
key: null, | ||
results: [], | ||
}; | ||
} | ||
|
||
getVideoInfo = async (id: string) => { | ||
let v: InvidiousVideoData = await this.request(`videos/${id}`); | ||
|
||
console.log(v); | ||
|
||
return { | ||
id, | ||
title: v.title, | ||
channel: { | ||
id: v.authorId, | ||
title: v.author, | ||
}, | ||
chapters: parseChapters(v.descriptionHtml), | ||
description: v.descriptionHtml, | ||
keywords: v.keywords, | ||
likeCount: v.likeCount, | ||
viewCount: v.viewCount, | ||
published: new Date(v.published), | ||
|
||
formats: [ | ||
...v.formatStreams.map(f => ({ | ||
itag: f.itag, | ||
url: f.url, | ||
mimeType: f.type, | ||
fps: f.fps, | ||
width: Number(f.size.split("x")[0]), | ||
height: Number(f.size.split("x")[1]), | ||
bitrate: Number(f.bitrate), | ||
} as VideoFormat)), | ||
], | ||
} as VideoData; | ||
}; | ||
}; |
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,125 @@ | ||
export interface InvidiousImage { | ||
url: string; | ||
width: number; | ||
height: number; | ||
}; | ||
|
||
export interface InvidiousThumbnail extends InvidiousImage { | ||
quality: string; | ||
}; | ||
|
||
export interface InvidiousVideo { | ||
type: "video"; | ||
title: string; | ||
videoId: string; | ||
|
||
author: string; | ||
authorId: string; | ||
authorUrl: string; | ||
authorVerified: boolean; | ||
authorThumbnails: InvidiousThumbnail[]; | ||
|
||
videoThumbnails: InvidiousThumbnail[]; | ||
|
||
description: string; | ||
descriptionHtml: string; | ||
|
||
viewCount: number; | ||
viewCountText: string; | ||
lengthSeconds: number; | ||
likeCount: number; | ||
dislikeCount: number; | ||
|
||
published: number; | ||
publishedText: string; | ||
keywords: string[]; | ||
|
||
paid: boolean; | ||
premium: boolean; | ||
isFamilyFriendly: boolean; | ||
allowedRegions: string[]; | ||
genre: string; | ||
genreUrl: string; | ||
|
||
subCountText: string; | ||
isListed: boolean; | ||
liveNow: boolean; | ||
isPostLiveDvr: boolean; | ||
isUpcoming: boolean; | ||
}; | ||
|
||
export interface InvidiousVideoData extends InvidiousVideo { | ||
dashUrl: string; | ||
adaptiveFormats: InvidiousAdaptiveFormat[]; | ||
formatStreams: InvidiousFormat[]; | ||
captions: any[]; | ||
recommendedVideos: any[]; | ||
}; | ||
|
||
export interface InvidiousAdaptiveFormat { | ||
itag: string; | ||
url: string; | ||
init: string; | ||
index: string; | ||
bitrate: string; | ||
type: string; | ||
clen: string; | ||
lmt: string; | ||
projectionType: string; | ||
fps: number; | ||
container: string; | ||
encoding: string; | ||
audioQuality: string; | ||
audioSampleRate: number; | ||
audioChannels: number; | ||
} | ||
|
||
export interface InvidiousFormat { | ||
url: string; | ||
itag: string; | ||
type: string; | ||
quality: string; | ||
bitrate: string; | ||
fps: number; | ||
container: string; | ||
encoding: string; | ||
resolution: string; | ||
qualityLabel: string; | ||
size: string; | ||
} | ||
|
||
export interface InvidiousChannel { | ||
type: "channel"; | ||
author: string; | ||
authorId: string; | ||
authorUrl: string; | ||
authorVerified: boolean; | ||
authorThumbnails: InvidiousThumbnail[]; | ||
autoGenerated: boolean; | ||
subCount: number; | ||
videoCount: number; | ||
description: string; | ||
descriptionHtml: string; | ||
}; | ||
|
||
export interface InvidiousPlaylist { | ||
type: "playlist"; | ||
title: string; | ||
playlistId: string; | ||
playlistThumbnail: string; | ||
author: string; | ||
authorId: string; | ||
authorUrl: string; | ||
authorVerified: boolean; | ||
videoCount: number; | ||
videos: InvidiousPlaylistEntry[]; | ||
}; | ||
|
||
export interface InvidiousPlaylistEntry { | ||
title: string; | ||
videoId: string; | ||
lengthSeconds: number; | ||
videoThumbnails: InvidiousThumbnail[]; | ||
}; | ||
|
||
export type InvidiousSearchResult = InvidiousVideo | InvidiousPlaylist | InvidiousChannel; |
Oops, something went wrong.