Skip to content

Instantly share code, notes, and snippets.

@cking
Last active September 7, 2016 12:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cking/6ccd7faf1757ec7e4aa8f2cb8640a207 to your computer and use it in GitHub Desktop.
Save cking/6ccd7faf1757ec7e4aa8f2cb8640a207 to your computer and use it in GitHub Desktop.
show counter
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