Episodes now have their own ID
This commit is contained in:
@ -37,10 +37,10 @@ func Get(ctx aero.Context) error {
|
||||
}
|
||||
|
||||
// Episodes
|
||||
episodes := anime.Episodes().Items
|
||||
episodes := anime.Episodes()
|
||||
|
||||
if len(episodes) > maxEpisodes {
|
||||
episodes = anime.Episodes().Last(maxEpisodesLongSeries)
|
||||
episodes = episodes[len(episodes)-maxEpisodesLongSeries:]
|
||||
}
|
||||
|
||||
// Friends watching
|
||||
|
@ -1,11 +1,11 @@
|
||||
component Anime(anime *arn.Anime, listItem *arn.AnimeListItem, tracks []*arn.SoundTrack, amvs []*arn.AMV, amvAppearances []*arn.AMV, episodes []*arn.AnimeEpisode, friends []*arn.User, listItems map[*arn.User]*arn.AnimeListItem, episodeToFriends map[int][]*arn.User, user *arn.User)
|
||||
component Anime(anime *arn.Anime, listItem *arn.AnimeListItem, tracks []*arn.SoundTrack, amvs []*arn.AMV, amvAppearances []*arn.AMV, episodes []*arn.Episode, friends []*arn.User, listItems map[*arn.User]*arn.AnimeListItem, episodeToFriends map[int][]*arn.User, user *arn.User)
|
||||
.anime
|
||||
.anime-main-column
|
||||
AnimeMainColumn(anime, listItem, tracks, amvs, amvAppearances, episodes, episodeToFriends, user)
|
||||
.anime-side-column
|
||||
AnimeSideColumn(anime, friends, listItems, user)
|
||||
|
||||
component AnimeMainColumn(anime *arn.Anime, listItem *arn.AnimeListItem, tracks []*arn.SoundTrack, amvs []*arn.AMV, amvAppearances []*arn.AMV, episodes []*arn.AnimeEpisode, episodeToFriends map[int][]*arn.User, user *arn.User)
|
||||
component AnimeMainColumn(anime *arn.Anime, listItem *arn.AnimeListItem, tracks []*arn.SoundTrack, amvs []*arn.AMV, amvAppearances []*arn.AMV, episodes []*arn.Episode, episodeToFriends map[int][]*arn.User, user *arn.User)
|
||||
.anime-header(data-id=anime.ID)
|
||||
a.anime-image-container.mountable(href=anime.ImageLink("original"), target="_blank", rel="noopener", data-mountable-type="header")
|
||||
img.anime-cover-image.lazy(data-src=anime.ImageLink("large"), data-webp="true", data-color=anime.AverageColor(), alt=anime.Title.ByUser(user), importance="high")
|
||||
|
@ -109,11 +109,12 @@ func Episodes(ctx aero.Context) error {
|
||||
return ctx.Error(http.StatusNotFound, "Anime not found", err)
|
||||
}
|
||||
|
||||
animeEpisodes, err := arn.GetAnimeEpisodes(id)
|
||||
// episodes := anime.Episodes()
|
||||
|
||||
if err != nil {
|
||||
return ctx.Error(http.StatusNotFound, "Anime episodes not found", err)
|
||||
}
|
||||
// if err != nil {
|
||||
// return ctx.Error(http.StatusNotFound, "Anime episodes not found", err)
|
||||
// }
|
||||
|
||||
return ctx.HTML(components.EditAnimeTabs(anime) + editform.Render(animeEpisodes, "Edit anime episodes", user))
|
||||
// editform.Render(episodes, "Edit anime episodes", user)
|
||||
return ctx.HTML(components.EditAnimeTabs(anime) + "<p class='no-data mountable'>Temporarily disabled.</p>")
|
||||
}
|
||||
|
@ -38,5 +38,5 @@ func Episodes(ctx aero.Context) error {
|
||||
return ctx.Error(http.StatusNotFound, "Anime not found", err)
|
||||
}
|
||||
|
||||
return ctx.HTML(components.AnimeEpisodes(anime, anime.Episodes().Items, episodeToFriends, user, true))
|
||||
return ctx.HTML(components.AnimeEpisodes(anime, anime.Episodes(), episodeToFriends, user, true))
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
component AnimeEpisodes(anime *arn.Anime, episodes []*arn.AnimeEpisode, episodeToFriends map[int][]*arn.User, user *arn.User, standAlonePage bool)
|
||||
component AnimeEpisodes(anime *arn.Anime, episodes []*arn.Episode, episodeToFriends map[int][]*arn.User, user *arn.User, standAlonePage bool)
|
||||
if standAlonePage
|
||||
h1.mountable
|
||||
a(href=anime.Link())= anime.Title.ByUser(user)
|
||||
@ -6,11 +6,11 @@ component AnimeEpisodes(anime *arn.Anime, episodes []*arn.AnimeEpisode, episodeT
|
||||
if len(episodes) > 0
|
||||
.anime-section.mountable
|
||||
h3.anime-section-name
|
||||
a(href=anime.Episodes().Link()) Episodes
|
||||
a(href=fmt.Sprintf("/anime/%s/episodes", anime.ID)) Episodes
|
||||
|
||||
.episodes
|
||||
each episode in episodes
|
||||
a.episode.mountable(href=anime.Link() + "/episode/" + strconv.Itoa(episode.Number), data-mountable-type="episode", data-available=episode.Available())
|
||||
a.episode.mountable(href=episode.Link(), data-mountable-type="episode", data-available=episode.Available())
|
||||
.episode-number
|
||||
if episode.Number != -1
|
||||
span= episode.Number
|
||||
|
@ -31,7 +31,7 @@ func Kitsu(ctx aero.Context) error {
|
||||
kitsuAnime := kitsuAnimeObj.(*kitsu.Anime)
|
||||
|
||||
// Convert
|
||||
anime, characters, relations, episodes := arn.NewAnimeFromKitsuAnime(kitsuAnime)
|
||||
anime, characters, relations := arn.NewAnimeFromKitsuAnime(kitsuAnime)
|
||||
|
||||
// Add user ID to the anime
|
||||
anime.CreatedBy = user.ID
|
||||
@ -40,7 +40,6 @@ func Kitsu(ctx aero.Context) error {
|
||||
anime.Save()
|
||||
characters.Save()
|
||||
relations.Save()
|
||||
episodes.Save()
|
||||
|
||||
// Log
|
||||
fmt.Println(color.GreenString("✔"), anime.ID, anime.Title.Canonical)
|
||||
|
@ -49,45 +49,43 @@ func Get(ctx aero.Context) error {
|
||||
}
|
||||
|
||||
// Add anime episodes to the days
|
||||
for animeEpisodes := range arn.StreamAnimeEpisodes() {
|
||||
if animeEpisodes.Anime().Status == "finished" {
|
||||
for episode := range arn.StreamEpisodes() {
|
||||
if episode.Anime().Status == "finished" {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, episode := range animeEpisodes.Items {
|
||||
if !validate.DateTime(episode.AiringDate.Start) {
|
||||
continue
|
||||
}
|
||||
|
||||
// Since we validated the date earlier, we can ignore the error value.
|
||||
airingDate, _ := time.Parse(time.RFC3339, episode.AiringDate.Start)
|
||||
|
||||
// Subtract from the starting date offset.
|
||||
since := airingDate.Sub(now)
|
||||
|
||||
// Ignore entries in the past and more than 1 week away.
|
||||
if since < 0 || since >= oneWeek {
|
||||
continue
|
||||
}
|
||||
|
||||
dayIndex := int(since / (24 * time.Hour))
|
||||
|
||||
entry := &utils.CalendarEntry{
|
||||
Anime: animeEpisodes.Anime(),
|
||||
Episode: episode,
|
||||
Added: false,
|
||||
}
|
||||
|
||||
if user != nil {
|
||||
animeListItem := user.AnimeList().Find(entry.Anime.ID)
|
||||
|
||||
if animeListItem != nil && (animeListItem.Status == arn.AnimeListStatusWatching || animeListItem.Status == arn.AnimeListStatusPlanned) {
|
||||
entry.Added = true
|
||||
}
|
||||
}
|
||||
|
||||
days[dayIndex].Entries = append(days[dayIndex].Entries, entry)
|
||||
if !validate.DateTime(episode.AiringDate.Start) {
|
||||
continue
|
||||
}
|
||||
|
||||
// Since we validated the date earlier, we can ignore the error value.
|
||||
airingDate, _ := time.Parse(time.RFC3339, episode.AiringDate.Start)
|
||||
|
||||
// Subtract from the starting date offset.
|
||||
since := airingDate.Sub(now)
|
||||
|
||||
// Ignore entries in the past and more than 1 week away.
|
||||
if since < 0 || since >= oneWeek {
|
||||
continue
|
||||
}
|
||||
|
||||
dayIndex := int(since / (24 * time.Hour))
|
||||
|
||||
entry := &utils.CalendarEntry{
|
||||
Anime: episode.Anime(),
|
||||
Episode: episode,
|
||||
Added: false,
|
||||
}
|
||||
|
||||
if user != nil {
|
||||
animeListItem := user.AnimeList().Find(entry.Anime.ID)
|
||||
|
||||
if animeListItem != nil && (animeListItem.Status == arn.AnimeListStatusWatching || animeListItem.Status == arn.AnimeListStatusPlanned) {
|
||||
entry.Added = true
|
||||
}
|
||||
}
|
||||
|
||||
days[dayIndex].Entries = append(days[dayIndex].Entries, entry)
|
||||
}
|
||||
|
||||
for i := 0; i < 7; i++ {
|
||||
|
@ -15,39 +15,34 @@ import (
|
||||
func Get(ctx aero.Context) error {
|
||||
user := utils.GetUser(ctx)
|
||||
id := ctx.Get("id")
|
||||
episodeNumber, err := ctx.GetInt("episode-number")
|
||||
|
||||
// Get episode
|
||||
episode, err := arn.GetEpisode(id)
|
||||
|
||||
if err != nil {
|
||||
return ctx.Error(http.StatusBadRequest, "Episode is not a number", err)
|
||||
return ctx.Error(http.StatusNotFound, "Episode not found", err)
|
||||
}
|
||||
|
||||
// Get anime
|
||||
anime, err := arn.GetAnime(id)
|
||||
anime := episode.Anime()
|
||||
|
||||
if err != nil {
|
||||
if anime == nil {
|
||||
return ctx.Error(http.StatusNotFound, "Anime not found", err)
|
||||
}
|
||||
|
||||
// Get anime episodes
|
||||
animeEpisodes, err := arn.GetAnimeEpisodes(id)
|
||||
|
||||
if err != nil {
|
||||
return ctx.Error(http.StatusNotFound, "Anime episodes not found", err)
|
||||
}
|
||||
|
||||
// Does the episode exist?
|
||||
uploaded := false
|
||||
|
||||
if arn.Spaces != nil {
|
||||
stat, err := arn.Spaces.StatObject("arn", fmt.Sprintf("videos/anime/%s/%d.webm", anime.ID, episodeNumber), minio.StatObjectOptions{})
|
||||
stat, err := arn.Spaces.StatObject("arn", fmt.Sprintf("videos/anime/%s/%d.webm", anime.ID, episode.Number), minio.StatObjectOptions{})
|
||||
uploaded = (err == nil) && (stat.Size > 0)
|
||||
}
|
||||
|
||||
episode, episodeIndex := animeEpisodes.Find(episodeNumber)
|
||||
_, episodeIndex := anime.Episodes().Find(episode.Number)
|
||||
|
||||
if episode == nil {
|
||||
return ctx.Error(http.StatusNotFound, "Anime episode not found")
|
||||
}
|
||||
|
||||
return ctx.HTML(components.AnimeEpisode(anime, episode, episodeIndex, uploaded, user))
|
||||
return ctx.HTML(components.Episode(anime, episode, episodeIndex, uploaded, user))
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
component AnimeEpisode(anime *arn.Anime, episode *arn.AnimeEpisode, episodeIndex int, uploaded bool, user *arn.User)
|
||||
component Episode(anime *arn.Anime, episode *arn.Episode, episodeIndex int, uploaded bool, user *arn.User)
|
||||
h1
|
||||
a(href=anime.Link())= anime.Title.ByUser(user)
|
||||
|
||||
.episode-navigation-container
|
||||
if episodeIndex > 0
|
||||
.episode-arrow.episode-arrow-previous
|
||||
a.light-button(href=anime.Link() + "/episode/" + strconv.Itoa(anime.Episodes().Items[episodeIndex - 1].Number), title="Previous episode")
|
||||
a.light-button(href=episode.Previous().Link(), title="Previous episode")
|
||||
RawIcon("chevron-left")
|
||||
|
||||
.episode-video
|
||||
@ -22,9 +22,9 @@ component AnimeEpisode(anime *arn.Anime, episode *arn.AnimeEpisode, episodeIndex
|
||||
//- a(href=anime.Link(), title=anime.Title.ByUser(user))
|
||||
//- img.anime-cover-image.lazy(data-src=anime.ImageLink("large"), data-webp="true", data-color=anime.AverageColor(), alt=anime.Title.ByUser(user))
|
||||
|
||||
if episodeIndex < len(anime.Episodes().Items) - 1
|
||||
if episodeIndex < len(anime.Episodes()) - 1
|
||||
.episode-arrow.episode-arrow-next
|
||||
a.light-button(href=anime.Link() + "/episode/" + strconv.Itoa(anime.Episodes().Items[episodeIndex + 1].Number), title="Next episode")
|
||||
a.light-button(href=episode.Next().Link(), title="Next episode")
|
||||
RawIcon("chevron-right")
|
||||
|
||||
h3.episode-view-number= "Episode " + strconv.Itoa(episode.Number)
|
||||
|
@ -13,23 +13,25 @@ import (
|
||||
func Subtitles(ctx aero.Context) error {
|
||||
id := ctx.Get("id")
|
||||
language := ctx.Get("language")
|
||||
episodeNumber, err := ctx.GetInt("episode-number")
|
||||
|
||||
// Get episode
|
||||
episode, err := arn.GetEpisode(id)
|
||||
|
||||
if err != nil {
|
||||
return ctx.Error(http.StatusBadRequest, "Episode is not a number", err)
|
||||
return ctx.Error(http.StatusNotFound, "Episode not found", err)
|
||||
}
|
||||
|
||||
// Get anime
|
||||
anime, err := arn.GetAnime(id)
|
||||
anime := episode.Anime()
|
||||
|
||||
if err != nil {
|
||||
if anime == nil {
|
||||
return ctx.Error(http.StatusNotFound, "Anime not found", err)
|
||||
}
|
||||
|
||||
ctx.Response().SetHeader("Access-Control-Allow-Origin", "*")
|
||||
ctx.Response().SetHeader("Content-Type", "text/vtt; charset=utf-8")
|
||||
|
||||
obj, err := arn.Spaces.GetObject("arn", fmt.Sprintf("videos/anime/%s/%d.%s.vtt", anime.ID, episodeNumber, language), minio.GetObjectOptions{})
|
||||
obj, err := arn.Spaces.GetObject("arn", fmt.Sprintf("videos/anime/%s/%d.%s.vtt", anime.ID, episode.Number, language), minio.GetObjectOptions{})
|
||||
|
||||
if err != nil {
|
||||
return ctx.Error(http.StatusInternalServerError, err)
|
||||
|
@ -19,8 +19,8 @@ func Register(app *aero.Application) {
|
||||
page.Get(app, "/anime/:id/tracks", anime.Tracks)
|
||||
page.Get(app, "/anime/:id/relations", anime.Relations)
|
||||
page.Get(app, "/anime/:id/comments", anime.Comments)
|
||||
page.Get(app, "/anime/:id/episode/:episode-number", episode.Get)
|
||||
app.Get("/anime/:id/episode/:episode-number/subtitles/:language", episode.Subtitles)
|
||||
page.Get(app, "/episode/:id", episode.Get)
|
||||
app.Get("/episode/:id/subtitles/:language", episode.Subtitles)
|
||||
|
||||
// Anime redirects
|
||||
page.Get(app, "/kitsu/anime/:id", anime.RedirectByMapping("kitsu/anime"))
|
||||
|
@ -52,7 +52,7 @@ func getAnimeStats() []*arn.PieChart {
|
||||
rating[fmt.Sprint(int(anime.Rating.Overall+0.5))]++
|
||||
|
||||
found := false
|
||||
for _, episode := range anime.Episodes().Items {
|
||||
for _, episode := range anime.Episodes() {
|
||||
if episode.Links != nil && episode.Links["twist.moe"] != "" {
|
||||
found = true
|
||||
break
|
||||
|
Reference in New Issue
Block a user