forked from anime-vsub/app
-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
deac2f4
commit 9ee2df9
Showing
10 changed files
with
203 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
window.Http = { | ||
version: "0.0.21", | ||
get(options) { | ||
return fetch(options.url) | ||
.then((res) => res.text()) | ||
.then((text) => { | ||
return { | ||
data: text, | ||
} | ||
}) | ||
}, | ||
post(options) { | ||
return fetch(options.url, { | ||
method: "POST", | ||
body: JSON.stringify(options.data), | ||
}) | ||
.then((res) => res.text()) | ||
.then((text) => { | ||
return { | ||
data: text, | ||
} | ||
}) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,18 @@ | ||
export function AnimeEpisodes(html) {} | ||
import { parserDom } from "../__helpers__/parserDom" | ||
|
||
export default function AnimeEpisodes(html: string) { | ||
const $ = parserDom(html) | ||
|
||
return $(".episode-list-data") | ||
.toArray() | ||
.map((ep) => { | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
const number = $(ep).find(".episode-number").attr("data-raw")! | ||
const name = $(ep).find(".episode-title > a").text().trim() | ||
const japanese = $(ep).find(".di-ib").text().trim() | ||
const time = $(ep).find(".episode-aired").text().trim() | ||
const average = $(ep).find(".episode-aired").text() | ||
|
||
return { number, name, japanese, time, average } | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import { getEpisodesMyAnimeList } from "./episodes" | ||
|
||
describe("episodes", () => { | ||
describe("getEpisodesMyAnimeList", () => { | ||
test("should work in all of one page", async () => { | ||
expect( | ||
await getEpisodesMyAnimeList( | ||
"https://myanimelist.net/anime/41389/Tonikaku_Kawaii" | ||
).then((items) => | ||
items.map((item) => { | ||
delete item.japanese | ||
return item | ||
}) | ||
) | ||
).toEqual([ | ||
{ | ||
number: "1", | ||
name: "Marriage", | ||
time: "Oct 3, 2020", | ||
average: "Oct 3, 2020", | ||
}, | ||
{ | ||
number: "2", | ||
name: "The First Night", | ||
time: "Oct 10, 2020", | ||
average: "Oct 10, 2020", | ||
}, | ||
{ | ||
number: "3", | ||
name: "Sisters", | ||
time: "Oct 17, 2020", | ||
average: "Oct 17, 2020", | ||
}, | ||
{ | ||
number: "4", | ||
name: "Promise", | ||
time: "Oct 24, 2020", | ||
average: "Oct 24, 2020", | ||
}, | ||
{ | ||
number: "5", | ||
name: "Rings", | ||
time: "Oct 31, 2020", | ||
average: "Oct 31, 2020", | ||
}, | ||
{ | ||
number: "6", | ||
name: "News", | ||
time: "Nov 7, 2020", | ||
average: "Nov 7, 2020", | ||
}, | ||
{ | ||
number: "7", | ||
name: "Trip", | ||
time: "Nov 14, 2020", | ||
average: "Nov 14, 2020", | ||
}, | ||
{ | ||
number: "8", | ||
name: "Parents", | ||
time: "Nov 21, 2020", | ||
average: "Nov 21, 2020", | ||
}, | ||
{ | ||
number: "9", | ||
name: "Daily Life", | ||
time: "Nov 28, 2020", | ||
average: "Nov 28, 2020", | ||
}, | ||
{ | ||
number: "10", | ||
name: "The Way Home", | ||
time: "Dec 5, 2020", | ||
average: "Dec 5, 2020", | ||
}, | ||
{ | ||
number: "11", | ||
name: "Friends", | ||
time: "Dec 12, 2020", | ||
average: "Dec 12, 2020", | ||
}, | ||
{ | ||
number: "12", | ||
name: "Husband and Wife", | ||
time: "Dec 19, 2020", | ||
average: "Dec 19, 2020", | ||
}, | ||
{ | ||
number: "13", | ||
name: "SNS", | ||
time: "N/A", | ||
average: "N/A", | ||
}, | ||
]) | ||
}) | ||
|
||
test("should search by offset", async () => { | ||
const diff = await getEpisodesMyAnimeList( | ||
"https://myanimelist.net/anime/235/Detective_Conan", | ||
100 | ||
) | ||
|
||
expect(diff.length).toBe(100) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// first in query id anime | ||
|
||
import type MyAnimeListEpisodesParser from "src/apis/parser/myanimelist/episodes" | ||
import { get } from "src/logic/http" | ||
|
||
import { useCache } from "../../useCache" | ||
import Worker from "../../workers/myanimelist/episodes" | ||
import { PostWorker } from "../../wrap-worker" | ||
|
||
export async function getEpisodesMyAnimeList(url: string, offset: number = 0) { | ||
return await useCache(`${url}/episode`, async () => { | ||
const html = | ||
import.meta.env.MODE === "test" | ||
? await fetch(`${url}/episode?offset=${offset}`).then((res) => res.text()) | ||
: await ( | ||
await get(`${url}/episode?offset=${offset}`) | ||
).data | ||
|
||
if (import.meta.env.MODE === "test") { | ||
return import("../../parser/myanimelist/episodes").then((res) => | ||
res.default(html) | ||
) | ||
} | ||
|
||
return PostWorker<typeof MyAnimeListEpisodesParser>(Worker, html) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { WrapWorker } from "../..//wrap-worker" | ||
import Episodes from "../../parser/myanimelist/episodes" | ||
|
||
WrapWorker(Episodes) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,16 @@ | ||
import path from "path" | ||
import { defineConfig } from "vitest/config" | ||
|
||
export default defineConfig({ | ||
resolve: { | ||
alias: { | ||
boot: path.resolve(__dirname, "src/boot"), | ||
stores: path.resolve(__dirname, "src/stores"), | ||
}, | ||
}, | ||
test: { | ||
environment: "jsdom", | ||
globals: true, | ||
setupFiles: ["./setup.vitest.ts"], | ||
}, | ||
}) |