Delete src/lib/providers/youvideoProvider.ts
This commit is contained in:
@@ -1,135 +0,0 @@
|
||||
import { type ICommentList, type IProvider, type IVideoList, type Video } from "./iProvider";
|
||||
|
||||
class YouvideoVideoList implements IVideoList {
|
||||
videos: Video[];
|
||||
|
||||
constructor(initialVideos: Video[]) {
|
||||
this.videos = initialVideos;
|
||||
}
|
||||
|
||||
HasMore(): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
HasPrevious(): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
Next(): void {
|
||||
}
|
||||
|
||||
Previous(): void {
|
||||
}
|
||||
}
|
||||
|
||||
type unprocessedVideo = {
|
||||
cached: boolean
|
||||
description: string
|
||||
extension?: string
|
||||
id: string
|
||||
metadata: {
|
||||
duration: number
|
||||
fps: number
|
||||
size: number[]
|
||||
}
|
||||
name: string
|
||||
};
|
||||
|
||||
class YouvideoProvider implements IProvider {
|
||||
instanceURL: URL
|
||||
|
||||
constructor(url: string) {
|
||||
this.instanceURL = new URL(url);
|
||||
}
|
||||
|
||||
async GetVideos(): Promise<IVideoList | null> {
|
||||
const resp = await fetch(new URL("/api/videos", this.instanceURL))
|
||||
if (!resp.ok) {
|
||||
return null;
|
||||
}
|
||||
|
||||
let initalVideos: Video[] = [];
|
||||
|
||||
const json: unprocessedVideo[] = await resp.json();
|
||||
json.forEach(video => {
|
||||
let convertedVideo: Video = {
|
||||
description: video.description,
|
||||
hasVideo: true,
|
||||
id: video.id,
|
||||
mime: "",
|
||||
title: video.name,
|
||||
fps: video.metadata.fps,
|
||||
duration: video.metadata.duration,
|
||||
uploader: "Youvideo Provider"
|
||||
};
|
||||
initalVideos.push(convertedVideo);
|
||||
});
|
||||
return new YouvideoVideoList(initalVideos);
|
||||
}
|
||||
|
||||
async GetVideoInfo(id: string): Promise<Video | null> {
|
||||
const resp = await fetch(new URL("/video/" + id, this.instanceURL));
|
||||
if (!resp.ok) {
|
||||
return null;
|
||||
}
|
||||
const video: unprocessedVideo = await resp.json();
|
||||
if (video.extension == null) {
|
||||
return null;
|
||||
}
|
||||
let convertedVideo: Video = {
|
||||
description: video.description,
|
||||
hasVideo: true,
|
||||
id: video.id,
|
||||
mime: "",
|
||||
title: video.name,
|
||||
fps: video.metadata.fps,
|
||||
duration: video.metadata.duration,
|
||||
uploader: "Youvideo Provider",
|
||||
videoURL: new URL("/youvideo/api/videofile/with_extension/" + id + video.extension, this.instanceURL).toString()
|
||||
};
|
||||
return convertedVideo;
|
||||
}
|
||||
|
||||
async GetComments(id: string): Promise<ICommentList | null> {
|
||||
return null;
|
||||
}
|
||||
|
||||
async SearchVideos(query: string): Promise<IVideoList | null> {
|
||||
const resp = await fetch(new URL("/api/videos", this.instanceURL))
|
||||
if (!resp.ok) {
|
||||
return null;
|
||||
}
|
||||
|
||||
let initalVideos: Video[] = [];
|
||||
|
||||
const json: unprocessedVideo[] = await resp.json();
|
||||
json.forEach(video => {
|
||||
let contains = false;
|
||||
contains = video.description.includes(query) || video.name.includes(query);
|
||||
// This is like this to allow nicer things
|
||||
if (!contains) {
|
||||
return;
|
||||
}
|
||||
let convertedVideo: Video = {
|
||||
description: video.description,
|
||||
hasVideo: true,
|
||||
id: video.id,
|
||||
mime: "",
|
||||
title: video.name,
|
||||
fps: video.metadata.fps,
|
||||
duration: video.metadata.duration,
|
||||
uploader: "Youvideo Provider",
|
||||
width: video.metadata.size[0],
|
||||
height: video.metadata.size[1]
|
||||
};
|
||||
initalVideos.push(convertedVideo);
|
||||
});
|
||||
return new YouvideoVideoList(initalVideos);
|
||||
}
|
||||
|
||||
async CanUpload(): Promise<boolean> {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export { YouvideoProvider };
|
||||
Reference in New Issue
Block a user