aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFactiven <[email protected]>2023-05-18 15:46:10 +0700
committerFactiven <[email protected]>2023-05-18 15:46:10 +0700
commit759120279dbd83f787cc1005c0015955f8d64bc9 (patch)
treebe8d7dc74fe4a31d98dddbe59961e227649c49ec
parentUpdate [param].js (diff)
downloadmoopa-759120279dbd83f787cc1005c0015955f8d64bc9.tar.xz
moopa-759120279dbd83f787cc1005c0015955f8d64bc9.zip
Emergency Update
> Temporary switching to zoro as a source until the API works again
-rw-r--r--components/videoPlayer.js71
-rw-r--r--lib/Artplayer.js32
-rw-r--r--pages/anime/[...id].js43
-rw-r--r--pages/anime/watch/[...info].js6
4 files changed, 114 insertions, 38 deletions
diff --git a/components/videoPlayer.js b/components/videoPlayer.js
index b57799e..f34eab7 100644
--- a/components/videoPlayer.js
+++ b/components/videoPlayer.js
@@ -16,6 +16,8 @@ export default function VideoPlayer({
}) {
const [url, setUrl] = useState();
const [source, setSource] = useState([]);
+ const [subtitle, setSubtitle] = useState();
+ const [defSub, setDefSub] = useState();
const { markProgress } = useAniList(session);
useEffect(() => {
@@ -35,19 +37,40 @@ export default function VideoPlayer({
source.quality === "144p"
);
- const source = data.sources.map((items) => ({
- default: items.quality === "default" ? true : false,
- html: items.quality === "default" ? "adaptive" : items.quality,
- // url: `https://cors.moopa.my.id/${items.url}`,
- url: `https://cors.moopa.my.id/?url=${encodeURIComponent(items.url)}${
- referer ? `&referer=${encodeURIComponent(referer)}` : ""
- }`,
- }));
-
- // const defUrl = `https://cors.moopa.my.id/${sumber.url}`;
- const defUrl = `https://cors.moopa.my.id/?url=${encodeURIComponent(
- sumber.url
- )}${referer ? `&referer=${encodeURIComponent(referer)}` : ""}`;
+ const source = data.sources.map((items) => {
+ const isDefault =
+ items.quality === "default" || items.quality === "auto";
+ return {
+ ...(isDefault && { default: true }),
+ html: items.quality === "default" ? "adaptive" : items.quality,
+ url: `https://lerioproxy.herokuapp.com/${items.url}`,
+ };
+ // url: `https://cors.moopa.my.id/?url=${encodeURIComponent(items.url)}${
+ // referer ? `&referer=${encodeURIComponent(referer)}` : ""
+ // }`,
+ });
+
+ const defUrl = `https://lerioproxy.herokuapp.com/${sumber.url}`;
+ // const defUrl = `https://cors.moopa.my.id/?url=${encodeURIComponent(
+ // sumber.url
+ // )}${referer ? `&referer=${encodeURIComponent(referer)}` : ""}`;
+
+ const subtitle = data?.subtitles
+ .filter((subtitle) => subtitle.lang !== "Thumbnails")
+ .map((subtitle) => {
+ const isEnglish = subtitle.lang === "English";
+ return {
+ ...(isEnglish && { default: true }),
+ url: subtitle.url,
+ html: `${subtitle.lang}`,
+ };
+ });
+
+ const defSub = data?.subtitles.filter((i) => i.lang === "English");
+ setDefSub(defSub);
+
+ // console.log(subtitle);
+ setSubtitle(subtitle);
setUrl(defUrl);
setSource(source);
@@ -65,12 +88,22 @@ export default function VideoPlayer({
key={url}
option={{
url: `${url}`,
- quality: [source],
title: `${title}`,
- autoplay: true,
+ // autoplay: true,
+ subtitle: {
+ url: defSub ? defSub[0].url : "",
+ type: "vtt",
+ encoding: "utf-8",
+ name: "English",
+ style: {
+ color: "#FFFF",
+ },
+ },
screenshot: true,
poster: poster ? poster : "",
}}
+ quality={source}
+ subtitles={subtitle}
style={{
width: "100%",
height: "100%",
@@ -83,6 +116,14 @@ export default function VideoPlayer({
const duration = art.duration;
const percentage = seekTime / duration;
+ // if (defSub) {
+ // art.subtitle.url = defSub[0].url;
+ // art.subtitle.style({
+ // color: "white",
+ // // fontSize: "40px",
+ // });
+ // }
+
if (percentage >= 0.9) {
// use >= instead of >
art.currentTime = 0;
diff --git a/lib/Artplayer.js b/lib/Artplayer.js
index 74f9acd..5800527 100644
--- a/lib/Artplayer.js
+++ b/lib/Artplayer.js
@@ -2,7 +2,13 @@ import { useEffect, useRef } from "react";
import Artplayer from "artplayer";
import Hls from "hls.js";
-export default function Player({ option, getInstance, ...rest }) {
+export default function Player({
+ option,
+ quality,
+ subtitles,
+ getInstance,
+ ...rest
+}) {
const artRef = useRef();
function playM3u8(video, url, art) {
if (Hls.isSupported()) {
@@ -37,6 +43,30 @@ export default function Player({ option, getInstance, ...rest }) {
autoOrientation: true,
pip: true,
theme: "#f97316",
+ settings: [
+ {
+ html: "Subtitle",
+ width: 300,
+ tooltip: "English",
+ selector: subtitles,
+ onSelect: function (item) {
+ art.subtitle.switch(item.url, {
+ name: item.html,
+ });
+ return item.html;
+ },
+ },
+ {
+ html: "Quality",
+ width: 150,
+ tooltip: "auto",
+ selector: quality,
+ onSelect: function (item) {
+ art.switchQuality(item.url, item.html);
+ return item.html;
+ },
+ },
+ ],
});
if (getInstance && typeof getInstance === "function") {
diff --git a/pages/anime/[...id].js b/pages/anime/[...id].js
index a2c84a4..c273d65 100644
--- a/pages/anime/[...id].js
+++ b/pages/anime/[...id].js
@@ -207,7 +207,9 @@ export default function Info({ info, color }) {
setLoading(false);
try {
const [res] = await Promise.all([
- fetch(`https://api.moopa.my.id/meta/anilist/info/${id?.[0]}`),
+ fetch(
+ `https://api.moopa.my.id/meta/anilist/info/${id?.[0]}?provider=zoro`
+ ),
// fetch("https://graphql.anilist.co/", {
// method: "POST",
// headers: {
@@ -242,29 +244,30 @@ export default function Info({ info, color }) {
);
const datas = await res.json();
- if (datas) {
- const release = datas.results.map((i) => i.releaseDate);
- const match = closestMatch(info.startDate.year, release);
- const filter = datas.results.find((i) => i.releaseDate === match);
-
- // const found = filter.find((i) => i.title === info.title.romaji);
-
- // setLog(found);
-
- if (filter) {
- const res = await fetch(
- `https://api.moopa.my.id/anime/gogoanime/info/${filter.id}`
- );
- const dataA = await res.json();
- setEpisode(dataA.episodes);
- // setLog(dataA);
- }
- } else if (res.status === 500) {
+ // if (datas) {
+ // const release = datas.results.map((i) => i.releaseDate);
+ // const match = closestMatch(info.startDate.year, release);
+ // const filter = datas.results.find((i) => i.releaseDate === match);
+
+ // // const found = filter.find((i) => i.title === info.title.romaji);
+
+ // // setLog(found);
+
+ // if (filter) {
+ // const res = await fetch(
+ // `https://api.moopa.my.id/anime/gogoanime/info/${filter.id}`
+ // );
+ // const dataA = await res.json();
+ // setEpisode(dataA.episodes);
+ // // setLog(dataA);
+ // }
+ // }
+ if (res.status === 500) {
setEpisode(null);
setEpiStatus("error");
setError(datas.message);
} else {
- setEpisode(datas.episodes);
+ setEpisode([]);
}
// setColor({
// backgroundColor: `${data?.color || "#ffff"}`,
diff --git a/pages/anime/watch/[...info].js b/pages/anime/watch/[...info].js
index fd6afd8..999dd0e 100644
--- a/pages/anime/watch/[...info].js
+++ b/pages/anime/watch/[...info].js
@@ -32,6 +32,8 @@ export default function Info({ sessions, id, aniId, provider }) {
const router = useRouter();
+ // console.log(epiData);
+
useEffect(() => {
const defaultState = {
epiData: null,
@@ -74,7 +76,7 @@ export default function Info({ sessions, id, aniId, provider }) {
setEpiData(epiData);
} else {
const res = await fetch(
- `https://api.moopa.my.id/meta/anilist/watch/${id}`
+ `https://api.moopa.my.id/meta/anilist/watch/${id}?provider=zoro`
);
const epiData = await res.json();
setEpiData(epiData);
@@ -95,7 +97,7 @@ export default function Info({ sessions, id, aniId, provider }) {
setAniData(aniData);
} else {
const res2 = await fetch(
- `https://api.moopa.my.id/meta/anilist/info/${aniId}`
+ `https://api.moopa.my.id/meta/anilist/info/${aniId}?provider=zoro`
);
aniData = await res2.json();
setAniData(aniData);