This Gist was automatically created by Carbide, a free online programming environment.
Last active
September 7, 2016 12:17
-
-
Save cking/6ccd7faf1757ec7e4aa8f2cb8640a207 to your computer and use it in GitHub Desktop.
show counter
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
import ms from "ms" | |
const FILTER_DELTA = -1000 * 60 * 60 * 24 * 7 // filter out shows older then a week | |
const headers = new Headers() | |
headers.append("X-Client-Id", "") | |
const shows = await fetch("http://www.senpai.moe/export.php?type=json&src=raw&air=stream").then(data => data.json()) | |
const airing = await fetch("http://www.senpai.moe/export.php?type=json&src=episodes&air=stream").then(data => data.json()) | |
const now = Date.now() | |
const episodes = Promise.all(airing.map(ep => { | |
const show = shows.items.find(show => show.name === ep.name) | |
const delta = ep.utime * 1000 - now | |
const data = { | |
name: ep.name, mal: show? show.MALID: null, | |
airdate: ep.utime * 1000, | |
airdelta: delta, | |
tta: (delta < 0? "-": "") + ms(Math.abs(delta)), | |
} | |
if (!data.mal) return Promise.resolve(data) | |
return fetch("https://hummingbird.me/api/v2/anime/myanimelist:" + data.mal, { headers }) | |
.then(data => data.json()) | |
.then(hb => { | |
data.hb = hb.id | |
data.yt = hb.youtube_video_id? "https://youtu.be/" + hb.youtube_video_id: null | |
data.type = hb.show_type | |
data.poster = hb.poster_image | |
data.cover = hb.cover_image | |
return data | |
}) | |
})) | |
.filter(ep => ep.airdelta > FILTER_DELTA) | |
.sort((a, b) => a.airdate - b.airdate) | |
episodes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment