Skip to content

Commit

Permalink
add fn search myanimelist
Browse files Browse the repository at this point in the history
  • Loading branch information
tachibana-shin committed Apr 23, 2023
1 parent 2be63bc commit deac2f4
Show file tree
Hide file tree
Showing 5 changed files with 697 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/apis/parser/myanimelist/episodes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export function AnimeEpisodes(html) {}
37 changes: 37 additions & 0 deletions src/apis/parser/myanimelist/search.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { parserDom } from "../__helpers__/parserDom"

interface AnimeItem {
name_lower: string
search_name: string
id: number
type: string
name: string
url: string
image_url: string
}

export default function AnimeSearch(html: string) {
const $ = parserDom(html)

return $(".js-categories-seasonal tr")
.toArray()
.map((tr) => {
const url = $(tr).find(".hoverinfo_trigger").attr("href")
if (!url) return null

const indexParamAnime = url.indexOf("/anime/") + 7

if (indexParamAnime === -1) return null

const id = parseInt(
url.slice(indexParamAnime, url.indexOf("/", indexParamAnime))
)
const name = $(tr).find("strong").text()
// eslint-disable-next-line camelcase
const image_url = $(tr).find("img").attr("src")

// eslint-disable-next-line camelcase
return { id, type: "anime", name, url, image_url }
})
.filter(Boolean) as AnimeItem[]
}
Loading

0 comments on commit deac2f4

Please sign in to comment.