Skip to content

Instantly share code, notes, and snippets.

@ci7lus
Created August 13, 2020 07:53
Show Gist options
  • Save ci7lus/ffd9f586ddd231290c3d90c1598ee9b8 to your computer and use it in GitHub Desktop.
Save ci7lus/ffd9f586ddd231290c3d90c1598ee9b8 to your computer and use it in GitHub Desktop.
https://mangacross.jp の更新情報を取得
import { defineComponent } from "ironpipe"
import axios from "axios"
/**
* mangacross.ts
* MIT License (c) 2020 ci7lus
*/
module.exports = defineComponent({
name: "mangacross",
version: "0.0.1",
props: {
titles: {
type: "string",
label: "Target title list",
description: "List of target titles (separate with ,)",
},
timer: {
type: "$.interface.timer",
default: {
cron: "30 1,3 * * *",
},
},
},
methods: {},
dedupe: "unique",
async run() {
const titles = this.titles.split(",")
for (let title of titles) {
try {
const r = await axios.get<{ comic: Comic }>(
`https://mangacross.jp/api/comics/${title}.json`,
{
validateStatus: () => true,
timeout: 5000,
}
)
if (r.status !== 200) {
console.warn(`${title}の取得に失敗しました: ${r.status}`)
continue
}
const comic = r.data.comic
const comic2 = Object.assign({}, comic)
delete comic2.episodes
comic.episodes
.filter((episode) => episode.status === "public")
.reverse()
.map((episode) => {
this.$emit(
{
...episode,
comic: comic2,
},
{
id: `https://mangacross.jp${episode.page_url}`,
summary: [comic.title, episode.volume, episode.title]
.filter((s) => typeof s === "string")
.join(" "),
ts: new Date(episode.publish_start).getTime(),
}
)
})
} catch (error) {
console.error(error)
}
}
},
})
type Comic = {
dir_name: string
title: string
author: string
caption: string
image_sp_url: string
icon_url: string
latest_episode_publish_start: string
episodes: Episode[]
}
type Episode = {
id: number
volume: string
title: string
page_url: string
publish_start: string
list_image_double_url: string
status: "public" | "private"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment