1
0
Fork 0
mirror of https://github.com/sussy-code/smov.git synced 2024-12-20 14:37:43 +01:00

general bug fixing

This commit is contained in:
James Hawkins 2022-05-01 14:58:08 +01:00
parent 008c91b0fe
commit 281f6b82a7
7 changed files with 6306 additions and 6408 deletions

View file

@ -63,6 +63,6 @@
"prettier-plugin-tailwindcss": "^0.1.7",
"tailwind-scrollbar": "^1.3.1",
"tailwindcss": "^3.0.20",
"typescript": "^4.6.2"
"typescript": "^4.6.4"
}
}

View file

@ -3,6 +3,7 @@ import { Icons } from "components/Icon";
import { Loading } from "components/layout/Loading";
import { MWMediaCaption, MWMediaStream } from "providers";
import { ReactElement, useEffect, useRef, useState } from "react";
import Hls from "hls.js";
export interface VideoPlayerProps {
source: MWMediaStream;
@ -40,7 +41,34 @@ export function VideoPlayer(props: VideoPlayerProps) {
useEffect(() => {
setLoading(true);
setErrored(false);
}, [props.source.url]);
// hls support
if (mustUseHls) {
if (!videoRef.current)
return;
if (!Hls.isSupported()) {
setLoading(false);
setErrored(true);
return;
}
const hls = new Hls();
if (videoRef.current.canPlayType('application/vnd.apple.mpegurl')) {
videoRef.current.src = props.source.url;
return;
}
hls.attachMedia(videoRef.current);
hls.loadSource(props.source.url);
hls.on(Hls.Events.ERROR, (event, data) => {
setErrored(true);
console.error(data);
});
}
}, [props.source.url, videoRef, mustUseHls]);
let skeletonUi: null | ReactElement = null;
if (hasErrored) {
@ -53,8 +81,7 @@ export function VideoPlayer(props: VideoPlayerProps) {
<>
{skeletonUi}
<video
className={`bg-denim-500 w-full rounded-xl ${
!showVideo ? "hidden" : ""
className={`bg-denim-500 w-full rounded-xl ${!showVideo ? "hidden" : ""
}`}
ref={videoRef}
onProgress={(e) =>

View file

@ -4,7 +4,6 @@ import {
MWPortableMedia,
MWMediaStream,
MWQuery,
MWMediaSeasons,
MWProviderMediaResult
} from "providers/types";
@ -57,14 +56,13 @@ export const gDrivePlayerScraper: MWMediaProvider = {
async searchForMedia(query: MWQuery): Promise<MWProviderMediaResult[]> {
const searchRes = await fetch(`${CORS_PROXY_URL}https://api.gdriveplayer.us/v1/movie/search?title=${query.searchQuery}`).then((d) => d.json());
const results: MWProviderMediaResult[] = searchRes.map((item: any) => ({
const results: MWProviderMediaResult[] = (searchRes || []).map((item: any) => ({
title: item.title,
year: item.year,
mediaId: item.imdb,
}));
return results;
},
async getStream(media: MWPortableMedia): Promise<MWMediaStream> {
@ -89,8 +87,4 @@ export const gDrivePlayerScraper: MWMediaProvider = {
return { url: `https:${source.file}`, type: source.type, captions: [] };
},
async getSeasonDataFromMedia(media: MWPortableMedia): Promise<MWMediaSeasons> {
return {} as MWMediaSeasons;
}
};

View file

@ -4,7 +4,6 @@ import {
MWPortableMedia,
MWMediaStream,
MWQuery,
MWMediaSeasons,
MWProviderMediaResult
} from "providers/types";
@ -47,7 +46,7 @@ export const gomostreamScraper: MWMediaProvider = {
`${CORS_PROXY_URL}http://www.omdbapi.com/?${encodeURIComponent(params.toString())}`,
).then(d => d.json())
const results: MWProviderMediaResult[] = searchRes.Search.map((d: any) => ({
const results: MWProviderMediaResult[] = (searchRes.Search || []).map((d: any) => ({
title: d.Title,
year: d.Year,
mediaId: d.imdbID
@ -92,9 +91,5 @@ export const gomostreamScraper: MWMediaProvider = {
if (streamType !== "mp4" && streamType !== "m3u8") throw new Error("Unsupported stream type");
return { url: streamUrl, type: streamType, captions: [] };
},
async getSeasonDataFromMedia(media: MWPortableMedia): Promise<MWMediaSeasons> {
return {} as MWMediaSeasons;
}
};

View file

@ -1,6 +1,6 @@
import { SimpleCache } from "utils/cache";
import { MWPortableMedia } from "providers";
import { MWMediaSeasons } from "providers/types";
import { MWMediaSeasons, MWMediaType, MWMediaProviderSeries } from "providers/types";
import { getProviderFromId } from "./helpers";
// cache
@ -16,13 +16,19 @@ seasonCache.initialize();
export async function getSeasonDataFromMedia(
media: MWPortableMedia
): Promise<MWMediaSeasons> {
const provider = getProviderFromId(media.providerId);
const provider = getProviderFromId(media.providerId) as MWMediaProviderSeries;
if (!provider) {
return {
seasons: [],
};
}
if (!provider.type.includes(MWMediaType.SERIES) && !provider.type.includes(MWMediaType.ANIME)) {
return {
seasons: [],
};
}
if (seasonCache.has(media)) {
return seasonCache.get(media) as MWMediaSeasons;
}

View file

@ -57,7 +57,7 @@ export interface MWQuery {
type: MWMediaType;
}
export interface MWMediaProvider {
export interface MWMediaProviderBase {
id: string; // id of provider, must be unique
enabled: boolean;
type: MWMediaType[];
@ -66,9 +66,15 @@ export interface MWMediaProvider {
getMediaFromPortable(media: MWPortableMedia): Promise<MWProviderMediaResult>;
searchForMedia(query: MWQuery): Promise<MWProviderMediaResult[]>;
getStream(media: MWPortableMedia): Promise<MWMediaStream>;
getSeasonDataFromMedia(media: MWPortableMedia): Promise<MWMediaSeasons>;
getSeasonDataFromMedia?: (media: MWPortableMedia) => Promise<MWMediaSeasons>;
}
export type MWMediaProviderSeries = MWMediaProviderBase & {
getSeasonDataFromMedia: (media: MWPortableMedia) => Promise<MWMediaSeasons>;
};
export type MWMediaProvider = MWMediaProviderBase;
export interface MWMediaProviderMetadata {
exists: boolean;
id?: string;

12642
yarn.lock

File diff suppressed because it is too large Load diff