mirror of
https://github.com/movie-web/movie-web.git
synced 2024-12-24 18:21:53 +01:00
commit
This commit is contained in:
parent
765749a956
commit
0784695ae5
@ -28,7 +28,15 @@ export function VideoElement({ streamUrl, loading, setProgress }) {
|
|||||||
hls.attachMedia(videoRef.current);
|
hls.attachMedia(videoRef.current);
|
||||||
hls.loadSource(streamUrl);
|
hls.loadSource(streamUrl);
|
||||||
}
|
}
|
||||||
}, [videoRef, streamUrl, loading])
|
}, [videoRef, streamUrl, loading]);
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
console.log('running')
|
||||||
|
const element = document.getElementsByClassName('videoElement')[0];
|
||||||
|
if (!element) return;
|
||||||
|
|
||||||
|
element.onProgress = setProgress;
|
||||||
|
})
|
||||||
|
|
||||||
if (error)
|
if (error)
|
||||||
return (<VideoPlaceholder>Your browser is not supported</VideoPlaceholder>)
|
return (<VideoPlaceholder>Your browser is not supported</VideoPlaceholder>)
|
||||||
|
@ -20,6 +20,7 @@ export function MovieView(props) {
|
|||||||
const [ episodeLists, setEpisodeList ] = React.useState([]);
|
const [ episodeLists, setEpisodeList ] = React.useState([]);
|
||||||
const [ loading, setLoading ] = React.useState(false);
|
const [ loading, setLoading ] = React.useState(false);
|
||||||
const [ selectedSeason, setSelectedSeason ] = React.useState("1");
|
const [ selectedSeason, setSelectedSeason ] = React.useState("1");
|
||||||
|
let isVideoTimeSet = React.useRef(false)
|
||||||
|
|
||||||
const season = showRouteMatch?.params.season || "1";
|
const season = showRouteMatch?.params.season || "1";
|
||||||
const episode = showRouteMatch?.params.episode || "1";
|
const episode = showRouteMatch?.params.episode || "1";
|
||||||
@ -31,12 +32,12 @@ export function MovieView(props) {
|
|||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (streamData.type === "show" && !showRouteMatch) history.replace(`${baseRouteMatch.url}/season/1/episode/1`);
|
if (streamData.type === "show" && !showRouteMatch) history.replace(`${baseRouteMatch.url}/season/1/episode/1`);
|
||||||
}, [streamData, showRouteMatch, history, baseRouteMatch.url]);
|
}, [streamData.type, showRouteMatch, history, baseRouteMatch.url]);
|
||||||
|
|
||||||
React.useEffect(() => {
|
// React.useEffect(() => {
|
||||||
if (streamData.type === "show" && showRouteMatch) setSelectedSeason(showRouteMatch.params.season.toString());
|
// if (streamData.type === "show" && showRouteMatch) setSelectedSeason(showRouteMatch.params.season.toString());
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// // eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, []);
|
// }, []);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
let cancel = false;
|
let cancel = false;
|
||||||
@ -74,12 +75,10 @@ export function MovieView(props) {
|
|||||||
setSeasonList(streamData.seasons);
|
setSeasonList(streamData.seasons);
|
||||||
setEpisodeList(streamData.episodes[selectedSeason]);
|
setEpisodeList(streamData.episodes[selectedSeason]);
|
||||||
}
|
}
|
||||||
}, [streamData, selectedSeason])
|
}, [streamData.seasons, streamData.episodes, streamData.type, selectedSeason])
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
let cancel = false;
|
if (!isVideoTimeSet.current) {
|
||||||
|
|
||||||
if (!cancel) {
|
|
||||||
let ls = JSON.parse(localStorage.getItem("video-progress") || "{}")
|
let ls = JSON.parse(localStorage.getItem("video-progress") || "{}")
|
||||||
let key = streamData.type === "show" ? `${season}-${episode}` : "full"
|
let key = streamData.type === "show" ? `${season}-${episode}` : "full"
|
||||||
let time = ls?.[streamData.source]?.[streamData.type]?.[streamData.slug]?.[key]?.currentlyAt;
|
let time = ls?.[streamData.source]?.[streamData.type]?.[streamData.slug]?.[key]?.currentlyAt;
|
||||||
@ -88,7 +87,7 @@ export function MovieView(props) {
|
|||||||
const element = document.getElementsByClassName('videoElement')[0];
|
const element = document.getElementsByClassName('videoElement')[0];
|
||||||
|
|
||||||
if (!element) {
|
if (!element) {
|
||||||
return () => { cancel = false }
|
return () => { isVideoTimeSet.current = false }
|
||||||
}
|
}
|
||||||
|
|
||||||
element.currentTime = time;
|
element.currentTime = time;
|
||||||
@ -96,11 +95,12 @@ export function MovieView(props) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
cancel = true;
|
isVideoTimeSet.current = true;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const setProgress = (evt) => {
|
const setProgress = (evt) => {
|
||||||
|
console.log('setting progress')
|
||||||
let ls = JSON.parse(localStorage.getItem("video-progress") || "{}")
|
let ls = JSON.parse(localStorage.getItem("video-progress") || "{}")
|
||||||
|
|
||||||
if (!ls[streamData.source])
|
if (!ls[streamData.source])
|
||||||
|
@ -149,6 +149,11 @@ export function SearchView() {
|
|||||||
source
|
source
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// due to a constraint with incompatible localStorage data,
|
||||||
|
// we must quit here if episode and season data is not included
|
||||||
|
// in the show's data. watching the show will resolve.
|
||||||
|
if (!subselection.meta) continue;
|
||||||
|
|
||||||
if (entry.percentageDone < 90) {
|
if (entry.percentageDone < 90) {
|
||||||
newContinueWatching.push(entry)
|
newContinueWatching.push(entry)
|
||||||
// begin next episode logic
|
// begin next episode logic
|
||||||
@ -157,7 +162,7 @@ export function SearchView() {
|
|||||||
if (!subselection.show) continue;
|
if (!subselection.show) continue;
|
||||||
|
|
||||||
let newShow = {};
|
let newShow = {};
|
||||||
|
|
||||||
// if the current season has a next episode, load it
|
// if the current season has a next episode, load it
|
||||||
if (subselection.meta.episodes[subselection.show.season].includes(`${parseInt(subselection.show.episode) + 1}`)) {
|
if (subselection.meta.episodes[subselection.show.season].includes(`${parseInt(subselection.show.episode) + 1}`)) {
|
||||||
newShow.season = subselection.show.season;
|
newShow.season = subselection.show.season;
|
||||||
@ -189,6 +194,8 @@ export function SearchView() {
|
|||||||
return b.data.updatedAt - a.data.updatedAt
|
return b.data.updatedAt - a.data.updatedAt
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log(newContinueWatching);
|
||||||
|
|
||||||
setContinueWatching(newContinueWatching)
|
setContinueWatching(newContinueWatching)
|
||||||
})
|
})
|
||||||
}, []);
|
}, []);
|
||||||
|
Loading…
Reference in New Issue
Block a user