Anime episodes stored under a different table

This commit is contained in:
Eduard Urbach 2017-07-10 16:58:34 +02:00
parent 29842b3ccc
commit 8037edcb67
11 changed files with 112 additions and 63 deletions

View File

@ -1,21 +1,44 @@
package main package main
import ( import (
"fmt"
"os"
"sort" "sort"
"strings"
"time"
"github.com/animenotifier/arn" "github.com/animenotifier/arn"
"github.com/animenotifier/twist" "github.com/animenotifier/twist"
"github.com/fatih/color" "github.com/fatih/color"
) )
var rateLimiter = time.NewTicker(500 * time.Millisecond)
func main() { func main() {
// Replace this with ID list from twist.moe later // Replace this with ID list from twist.moe later
animeIDs := []string{ currentAnime, err := arn.FilterAnime(func(anime *arn.Anime) bool {
"13274", return anime.Status == "current"
"10902", })
} arn.PanicOnError(err)
for _, animeID := range animeIDs { color.Yellow("Refreshing twist.moe links for %d anime", len(currentAnime))
for count, anime := range currentAnime {
// Wait for rate limiter
<-rateLimiter.C
// anime, animeErr := arn.GetAnime(animeID)
// if animeErr != nil {
// color.Red("Error fetching anime from the database with ID %s: %v", animeID, animeErr)
// continue
// }
animeID := anime.ID
// Log
fmt.Fprintf(os.Stdout, "[%d / %d] ", count+1, len(currentAnime))
// Get twist.moe feed
feed, err := twist.GetFeedByKitsuID(animeID) feed, err := twist.GetFeedByKitsuID(animeID)
if err != nil { if err != nil {
@ -30,6 +53,22 @@ func main() {
return episodes[a].Number < episodes[b].Number return episodes[a].Number < episodes[b].Number
}) })
arn.PrettyPrint(episodes) for _, episode := range episodes {
arnEpisode := anime.EpisodeByNumber(episode.Number)
if arnEpisode == nil {
color.Red("Anime %s Episode %d not found", anime.ID, episode.Number)
continue
}
if arnEpisode.Links == nil {
arnEpisode.Links = map[string]string{}
}
arnEpisode.Links["twist.moe"] = strings.Replace(episode.Link, "https://test.twist.moe/", "https://twist.moe/", 1)
}
arn.PanicOnError(anime.Episodes().Save())
color.Green("Found %d episodes for anime %s", len(episodes), animeID)
} }
} }

View File

@ -71,8 +71,8 @@ func configure(app *aero.Application) *aero.Application {
app.Ajax("/explore", explore.Get) app.Ajax("/explore", explore.Get)
app.Ajax("/forum", forums.Get) app.Ajax("/forum", forums.Get)
app.Ajax("/forum/:tag", forum.Get) app.Ajax("/forum/:tag", forum.Get)
app.Ajax("/threads/:id", threads.Get) app.Ajax("/thread/:id", threads.Get)
app.Ajax("/posts/:id", posts.Get) app.Ajax("/post/:id", posts.Get)
app.Ajax("/tracks/:id", tracks.Get) app.Ajax("/tracks/:id", tracks.Get)
app.Ajax("/new/thread", newthread.Get) app.Ajax("/new/thread", newthread.Get)
app.Ajax("/new/soundtrack", newsoundtrack.Get) app.Ajax("/new/soundtrack", newsoundtrack.Get)

View File

@ -6,7 +6,7 @@ component ThreadLink(thread *arn.Thread)
.thread-content .thread-content
if thread.Sticky != 0 if thread.Sticky != 0
Icon("thumb-tack") Icon("thumb-tack")
a.thread-link-title.ajax(href="/threads/" + thread.ID)= thread.Title a.thread-link-title.ajax(href="/thread/" + thread.ID)= thread.Title
.spacer .spacer
.thread-reply-count= len(thread.Posts) .thread-reply-count= len(thread.Posts)
.thread-icons .thread-icons

View File

@ -31,12 +31,12 @@ func Get(ctx *aero.Context) string {
episodesReversed := false episodesReversed := false
if len(anime.Episodes) > maxEpisodes { if len(anime.Episodes().Items) > maxEpisodes {
episodesReversed = true episodesReversed = true
anime.Episodes = anime.Episodes[len(anime.Episodes)-maxEpisodesLongSeries:] anime.Episodes().Items = anime.Episodes().Items[len(anime.Episodes().Items)-maxEpisodesLongSeries:]
for i, j := 0, len(anime.Episodes)-1; i < j; i, j = i+1, j-1 { for i, j := 0, len(anime.Episodes().Items)-1; i < j; i, j = i+1, j-1 {
anime.Episodes[i], anime.Episodes[j] = anime.Episodes[j], anime.Episodes[i] anime.Episodes().Items[i], anime.Episodes().Items[j] = anime.Episodes().Items[j], anime.Episodes().Items[i]
} }
} }

View File

@ -147,20 +147,23 @@ component Anime(anime *arn.Anime, tracks []*arn.SoundTrack, user *arn.User, epis
each track in tracks each track in tracks
SoundTrack(track) SoundTrack(track)
if len(anime.Episodes) > 0 if len(anime.Episodes().Items) > 0
if episodesReversed if episodesReversed
h3.anime-section-name Latest episodes h3.anime-section-name Latest episodes
else else
h3.anime-section-name Episodes h3.anime-section-name Episodes
table.episodes table.episodes
tbody tbody
each episode in anime.Episodes each episode in anime.Episodes().Items
tr.episode tr.episode
td.episode-number= episode.Number td.episode-number= episode.Number
td.episode-title= episode.Title.Japanese td.episode-title= episode.Title.Japanese
td.episode-actions td.episode-actions
a(href="https://translate.google.com/#ja/en/" + episode.Title.Japanese, target="_blank", rel="noopener") for name, link := range episode.Links
RawIcon("google") a(href=link, target="_blank", rel="noopener", title="Watch episode " + toString(episode.Number) + " on " + name)
RawIcon("eye")
//- a(href="https://translate.google.com/#ja/en/" + episode.Title.Japanese, target="_blank", rel="noopener")
//- RawIcon("google")
td.episode-airing-date-start.utc-airing-date(data-start-date=episode.AiringDate.Start, data-end-date=episode.AiringDate.End, data-episode-number=episode.Number)= episode.AiringDate.StartDateHuman() td.episode-airing-date-start.utc-airing-date(data-start-date=episode.AiringDate.Start, data-end-date=episode.AiringDate.End, data-episode-number=episode.Number)= episode.AiringDate.StartDateHuman()
//- h3.anime-section-name Reviews //- h3.anime-section-name Reviews

View File

@ -36,26 +36,25 @@ component AnimeLists(animeLists map[string]*arn.AnimeList, viewUser *arn.User, u
//- AnimeList(animeList, user) //- AnimeList(animeList, user)
component AnimeList(animeList *arn.AnimeList, viewUser *arn.User, user *arn.User) component AnimeList(animeList *arn.AnimeList, viewUser *arn.User, user *arn.User)
table.anime-list table
thead tbody.anime-list
tr
th.anime-list-item-name Anime
th.anime-list-item-airing-date Airing
th.anime-list-item-episodes Episodes
th.anime-list-item-rating Overall
//- th.anime-list-item-rating Story
//- th.anime-list-item-rating Visuals
//- th.anime-list-item-rating Soundtrack
if user != nil
th.anime-list-item-actions Actions
tbody
each item in animeList.Items each item in animeList.Items
tr.anime-list-item.mountable(title=item.Notes, data-api="/api/animelist/" + animeList.UserID + "/update/" + item.AnimeID) tr.anime-list-item(title=item.Notes, data-api="/api/animelist/" + animeList.UserID + "/update/" + item.AnimeID)
td.anime-list-item-name td.anime-list-item-name
a.ajax(href=item.Link(animeList.User().Nick))= item.Anime().Title.Canonical a.ajax(href=item.Link(animeList.User().Nick))= item.Anime().Title.Canonical
if user != nil && item.Status == arn.AnimeListStatusWatching && item.Anime().EpisodeByNumber(item.Episodes + 1) != nil
td.anime-list-item-actions
for _, link := range item.Anime().EpisodeByNumber(item.Episodes + 1).Links
a(href=link, title="Watch episode " + toString(item.Episodes + 1) + " on twist.moe", target="_blank", rel="noopener")
RawIcon("eye")
//- a(href=arn.Nyaa.GetLink(item.Anime()), title="Search on Nyaa", target="_blank", rel="noopener")
//- RawIcon("download")
td.anime-list-item-airing-date td.anime-list-item-airing-date
if item.Anime().UpcomingEpisode() != nil if item.Status == arn.AnimeListStatusWatching && item.Anime().UpcomingEpisode() != nil
span.utc-airing-date(data-start-date=item.Anime().UpcomingEpisode().Episode.AiringDate.Start, data-end-date=item.Anime().UpcomingEpisode().Episode.AiringDate.End, data-episode-number=item.Anime().UpcomingEpisode().Episode.Number) span.utc-airing-date(data-start-date=item.Anime().UpcomingEpisode().Episode.AiringDate.Start, data-end-date=item.Anime().UpcomingEpisode().Episode.AiringDate.End, data-episode-number=item.Anime().UpcomingEpisode().Episode.Number)
td.anime-list-item-episodes td.anime-list-item-episodes
.anime-list-item-episodes-watched .anime-list-item-episodes-watched
.action(contenteditable=utils.SameUser(user, viewUser), data-field="Episodes", data-type="number", data-trigger="focusout", data-action="save")= item.Episodes .action(contenteditable=utils.SameUser(user, viewUser), data-field="Episodes", data-type="number", data-trigger="focusout", data-action="save")= item.Episodes
@ -64,6 +63,7 @@ component AnimeList(animeList *arn.AnimeList, viewUser *arn.User, user *arn.User
//- .anime-list-item-episodes-edit //- .anime-list-item-episodes-edit
//- a.ajax(href=, title="Edit anime") //- a.ajax(href=, title="Edit anime")
//- RawIcon("pencil") //- RawIcon("pencil")
td.anime-list-item-rating(title="Overall rating") td.anime-list-item-rating(title="Overall rating")
.action(contenteditable=utils.SameUser(user, viewUser), data-field="Rating.Overall", data-type="number", data-trigger="focusout", data-action="save")= fmt.Sprintf("%.1f", item.Rating.Overall) .action(contenteditable=utils.SameUser(user, viewUser), data-field="Rating.Overall", data-type="number", data-trigger="focusout", data-action="save")= fmt.Sprintf("%.1f", item.Rating.Overall)
//- td.anime-list-item-rating(title="Story rating") //- td.anime-list-item-rating(title="Story rating")
@ -72,8 +72,3 @@ component AnimeList(animeList *arn.AnimeList, viewUser *arn.User, user *arn.User
//- .action(contenteditable=utils.SameUser(user, viewUser), data-field="Rating.Visuals", data-type="number", data-trigger="focusout", data-action="save")= fmt.Sprintf("%.1f", item.Rating.Visuals) //- .action(contenteditable=utils.SameUser(user, viewUser), data-field="Rating.Visuals", data-type="number", data-trigger="focusout", data-action="save")= fmt.Sprintf("%.1f", item.Rating.Visuals)
//- td.anime-list-item-rating(title="Soundtrack rating") //- td.anime-list-item-rating(title="Soundtrack rating")
//- .action(contenteditable=utils.SameUser(user, viewUser), data-field="Rating.Soundtrack", data-type="number", data-trigger="focusout", data-action="save")= fmt.Sprintf("%.1f", item.Rating.Soundtrack) //- .action(contenteditable=utils.SameUser(user, viewUser), data-field="Rating.Soundtrack", data-type="number", data-trigger="focusout", data-action="save")= fmt.Sprintf("%.1f", item.Rating.Soundtrack)
//- if user != nil
//- td.anime-list-item-actions
//- a(href=arn.Nyaa.GetLink(item.Anime()), title="Search on Nyaa", target="_blank", rel="noopener")
//- RawIcon("download")

View File

@ -8,11 +8,8 @@
.anime-list .anime-list
vertical vertical
tr .anime-list-item
horizontal horizontal
thead
display none
.anime-list-item-name .anime-list-item-name
flex 1 flex 1
@ -38,25 +35,16 @@
flex 0.4 flex 0.4
opacity 0.5 opacity 0.5
// .anime-list-item-episodes-edit .anime-list-item-rating
// flex 0.5 text-align right
.anime-list-item-actions
display none
flex-basis 30px
// // Beautify icon alignment // // Beautify icon alignment
// .raw-icon // .raw-icon
// margin-bottom -2px // margin-bottom -4px
.anime-list-item-rating
flex-basis 50px
text-align center
.anime-list-item-actions
flex-basis 40px
text-align right
display none
// Beautify icon alignment
.raw-icon
margin-bottom -4px
> 740px > 740px
.anime-list-item-actions .anime-list-item-actions
@ -68,6 +56,8 @@
> 700px > 700px
.anime-list-item-airing-date .anime-list-item-airing-date
display block display block
text-align right
flex-basis 100px
< 1100px < 1100px
.anime-list-item-rating .anime-list-item-rating

View File

@ -102,7 +102,7 @@ component Profile(viewUser *arn.User, user *arn.User, animeList *arn.AnimeList,
.profile-watching-list.mountable .profile-watching-list.mountable
each item in animeList.Items each item in animeList.Items
a.profile-watching-list-item.ajax(href=item.Anime().Link(), title=item.Anime().Title.Canonical + " (" + toString(item.Episodes) + " / " + arn.EpisodesToString(item.Anime().EpisodeCount) + ")") a.profile-watching-list-item.ajax(href=item.Anime().Link(), title=item.Anime().Title.Canonical + " (" + toString(item.Episodes) + " / " + arn.EpisodesToString(item.Anime().EpisodeCount) + ")")
img.anime-cover-image.profile-watching-list-item-image.lazy(data-src=item.Anime().Image.Tiny, alt=item.Anime().Title.Canonical) img.profile-watching-list-item-image.lazy(data-src=item.Anime().Image.Tiny, alt=item.Anime().Title.Canonical)
//- .profile-category.mountable //- .profile-category.mountable
//- h3 //- h3

View File

@ -9,6 +9,11 @@
width 55px !important width 55px !important
height 78px !important height 78px !important
border-radius 2px border-radius 2px
filter none
transition filter transition-speed ease
:hover
filter saturate(1.3)
// .status-tabs // .status-tabs
// position fixed // position fixed

View File

@ -0,0 +1,17 @@
package main
import (
"github.com/animenotifier/arn"
)
func main() {
for anime := range arn.MustStreamAnime() {
arn.PanicOnError(arn.DB.Set("AnimeEpisodes", anime.ID, &arn.AnimeEpisodes{
AnimeID: anime.ID,
Items: anime.Episodes,
}))
anime.Episodes = anime.Episodes[:0]
anime.MustSave()
}
}

View File

@ -59,12 +59,12 @@ var routeTests = map[string][]string{
"/anime/1", "/anime/1",
}, },
"/threads/:id": []string{ "/thread/:id": []string{
"/threads/HJgS7c2K", "/thread/HJgS7c2K",
}, },
"/posts/:id": []string{ "/post/:id": []string{
"/posts/B1RzshnK", "/post/B1RzshnK",
}, },
"/forum/:tag": []string{ "/forum/:tag": []string{