1
0
Fork 0
mirror of https://github.com/sussy-code/smov.git synced 2024-12-29 16:07:40 +01:00

Merge pull request #29 from mansoor-roeen-glitch/master

Added subtitles accessibility for Lookmovie
This commit is contained in:
James Hawkins 2021-09-15 09:13:26 +01:00 committed by GitHub
commit 14d82dc558
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 73 additions and 18 deletions

View file

@ -24,6 +24,13 @@
margin-right: 0.5rem; margin-right: 0.5rem;
} }
.movieRow .left .titleWrapper {
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}
.movieRow .left .seasonEpisodeSubtitle, .movieRow .left .seasonEpisodeSubtitle,
.movieRow .left .year { .movieRow .left .year {
color: var(--text-secondary); color: var(--text-secondary);
@ -62,6 +69,14 @@
margin-right: 10px; margin-right: 10px;
} }
.subtitleIcon {
width: 30px;
display: flex;
justify-content: center;
align-items: center;
margin-right: 10px;
}
@media screen and (max-width: 400px) { @media screen and (max-width: 400px) {
.movieRow { .movieRow {
flex-direction: column; flex-direction: column;

View file

@ -21,10 +21,25 @@ export function MovieRow(props) {
return ( return (
<div className="movieRow" onClick={() => props.onClick && props.onClick()}> <div className="movieRow" onClick={() => props.onClick && props.onClick()}>
{ props.source === "lookmovie" && (
<div className="subtitleIcon">
<svg id="subtitleIcon" width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M20 4H4C2.897 4 2 4.897 2 6V18C2 19.103 2.897 20 4 20H20C21.103 20 22 19.103 22 18V6C22 4.897 21.103 4 20 4ZM11 10H8V14H11V16H8C6.897 16 6 15.103 6 14V10C6 8.897 6.897 8 8 8H11V10ZM18 10H15V14H18V16H15C13.897 16 13 15.103 13 14V10C13 8.897 13.897 8 15 8H18V10Z" fill="#EEEEEE"/>
</svg>
</div>
) }
<div className="left"> <div className="left">
{/* <Cross /> */} {/* <Cross /> */}
{props.title}<span className="seasonEpisodeSubtitle">{props.place ? ` - S${props.place.season}:E${props.place.episode}` : ''}</span>&nbsp; <div className="titleWrapper">
<span className="year">({props.year})</span> <div className="titleText">
{props.title}
&nbsp;
<span className="year">({props.year})</span>
<span className="seasonEpisodeSubtitle">{props.place ? ` - S${props.place.season}:E${props.place.episode}` : ''}</span>
</div>
</div>
</div> </div>
<div className="watch"> <div className="watch">

View file

@ -9,7 +9,7 @@ import './VideoElement.css'
// setProgress: (event: NativeEvent) => void // setProgress: (event: NativeEvent) => void
// videoRef: useRef // videoRef: useRef
// startTime: number // startTime: number
export function VideoElement({ streamUrl, loading, setProgress, videoRef, startTime }) { export function VideoElement({ streamUrl, loading, setProgress, videoRef, startTime, streamData }) {
const [error, setError] = React.useState(false); const [error, setError] = React.useState(false);
function onLoad() { function onLoad() {
@ -48,11 +48,14 @@ export function VideoElement({ streamUrl, loading, setProgress, videoRef, startT
if (!streamUrl.endsWith('.mp4')) { if (!streamUrl.endsWith('.mp4')) {
return ( return (
<video className="videoElement" ref={videoRef} controls autoPlay onProgress={setProgress} onLoadedData={onLoad} /> <video crossorigin="anonymous" className="videoElement" ref={videoRef} controls autoPlay onProgress={setProgress} onLoadedData={onLoad}>
{ streamData.subtitles && streamData.subtitles.map((sub, index) => <track key={index} kind="captions" label={sub.language} src={`${process.env.REACT_APP_CORS_PROXY_URL}https://lookmovie.io${sub.file}` } />) }
</video>
) )
} else { } else {
return ( return (
<video className="videoElement" ref={videoRef} controls autoPlay onProgress={setProgress} onLoadedData={onLoad}> <video crossorigin="anonymous" className="videoElement" ref={videoRef} controls autoPlay onProgress={setProgress} onLoadedData={onLoad}>
{ streamData.subtitles && streamData.subtitles.map((sub, index) => <track key={index} kind="captions" label={sub.language} src={`${process.env.REACT_APP_CORS_PROXY_URL}https://lookmovie.io${sub.file}` } />) }
<source src={streamUrl} type="video/mp4" /> <source src={streamUrl} type="video/mp4" />
</video> </video>
) )

View file

@ -50,9 +50,17 @@ async function findContent(searchTerm, type) {
} }
} }
async function getVideoUrl(config) { async function getVideoUrl(config) {
const accessToken = await getAccessToken(config); const { subtitles, token: accessToken } = await getAccessInfo(config);
const now = Math.floor(Date.now() / 1e3); const now = Math.floor(Date.now() / 1e3);
let subs;
if (config.type === "show") {
subs = await getEpisodeSubs(config);
} else if (config.type === "movie") {
subs = subtitles;
}
let url = ''; let url = '';
if (config.type === 'movie') { if (config.type === 'movie') {
@ -73,10 +81,17 @@ async function getVideoUrl(config) {
} }
} }
return videoUrl.startsWith("/") ? `${BASE_URL}${videoUrl}` : videoUrl; return {
videoUrl: videoUrl.startsWith("/") ? `${BASE_URL}${videoUrl}` : videoUrl,
subs,
};
} }
async function getAccessToken(config) { async function getEpisodeSubs (config) {
return await fetch(`${BASE_URL}/api/v1/shows/episode-subtitles/?id_episode=${config.id}`).then(res => res.json());
}
async function getAccessInfo(config) {
let url = ''; let url = '';
if (config.type === 'movie') { if (config.type === 'movie') {
@ -88,7 +103,9 @@ async function getAccessToken(config) {
const data = await fetch(url).then((d) => d.json()); const data = await fetch(url).then((d) => d.json());
const token = data?.data?.accessToken; const token = data?.data?.accessToken;
if (token) return token; const subtitles = data?.data?.subtitles;
if (token) return { token, subtitles };
return "Invalid type provided in config"; return "Invalid type provided in config";
} }
@ -153,11 +170,11 @@ async function getStreamUrl(slug, type, season, episode) {
slug: slug, slug: slug,
id: id, id: id,
type: type, type: type,
}); });
return { url: videoUrl } return { url: videoUrl.videoUrl, subtitles: videoUrl.subs };
} }
const lookMovie = { findContent, getStreamUrl, getEpisodes }; const lookMovie = { findContent, getStreamUrl, getEpisodes };
export default lookMovie; export default lookMovie;

View file

@ -56,10 +56,10 @@ export function MovieView(props) {
} }
setLoading(true); setLoading(true);
getStreamUrl(streamData.slug, streamData.type, streamData.source, season, episode) getStreamUrl(streamData.slug, streamData.type, streamData.source, season, episode)
.then(({url}) => { .then(({url, subtitles}) => {
if (cancel) return; if (cancel) return;
if (streamData.source === "lookmovie") streamData.subtitles = subtitles;
setStreamUrl(url) setStreamUrl(url)
setLoading(false); setLoading(false);
}) })
@ -131,7 +131,7 @@ export function MovieView(props) {
Season {season}: Episode {episode} Season {season}: Episode {episode}
</Title> : undefined} </Title> : undefined}
<VideoElement streamUrl={streamUrl} loading={loading} setProgress={setProgress} videoRef={videoRef} startTime={startTime} /> <VideoElement streamUrl={streamUrl} loading={loading} setProgress={setProgress} videoRef={videoRef} startTime={startTime} streamData={streamData} />
{streamData.type === "show" ? {streamData.type === "show" ?
<EpisodeSelector <EpisodeSelector

View file

@ -54,13 +54,17 @@ export function SearchView() {
} }
let realUrl = ''; let realUrl = '';
let subtitles = []
if (type === "movie") { if (type === "movie") {
const { url } = await getStreamUrl(slug, type, source); const { url, subtitles: subs } = await getStreamUrl(slug, type, source);
if (url === '') { if (url === '') {
return fail(`Not found: ${title}`) return fail(`Not found: ${title}`)
} }
realUrl = url; realUrl = url;
subtitles = subs
} }
setProgress(maxSteps); setProgress(maxSteps);
@ -72,7 +76,8 @@ export function SearchView() {
episodes, episodes,
slug, slug,
source, source,
year year,
subtitles
}) })
setText(`Streaming...`) setText(`Streaming...`)
navigate("movie") navigate("movie")