Finished anilist importer
This commit is contained in:
parent
788adcaf2d
commit
5774c51ced
3
main.go
3
main.go
@ -82,7 +82,8 @@ func configure(app *aero.Application) *aero.Application {
|
|||||||
app.Ajax("/settings", settings.Get)
|
app.Ajax("/settings", settings.Get)
|
||||||
app.Ajax("/music", music.Get)
|
app.Ajax("/music", music.Get)
|
||||||
app.Ajax("/import", listimport.Get)
|
app.Ajax("/import", listimport.Get)
|
||||||
app.Ajax("/import/anilist/animelist", listimportanilist.Get)
|
app.Ajax("/import/anilist/animelist", listimportanilist.Preview)
|
||||||
|
app.Ajax("/import/anilist/animelist/finish", listimportanilist.Finish)
|
||||||
app.Ajax("/admin", admin.Get)
|
app.Ajax("/admin", admin.Get)
|
||||||
app.Ajax("/search", search.Get)
|
app.Ajax("/search", search.Get)
|
||||||
app.Ajax("/search/:term", search.Get)
|
app.Ajax("/search/:term", search.Get)
|
||||||
|
@ -9,37 +9,89 @@ import (
|
|||||||
"github.com/animenotifier/notify.moe/utils"
|
"github.com/animenotifier/notify.moe/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Get ...
|
func getMatches(ctx *aero.Context) ([]*arn.AniListMatch, string) {
|
||||||
func Get(ctx *aero.Context) string {
|
|
||||||
user := utils.GetUser(ctx)
|
user := utils.GetUser(ctx)
|
||||||
|
|
||||||
if user == nil {
|
if user == nil {
|
||||||
return ctx.Error(http.StatusBadRequest, "Not logged in", nil)
|
return nil, ctx.Error(http.StatusBadRequest, "Not logged in", nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
authErr := arn.AniList.Authorize()
|
authErr := arn.AniList.Authorize()
|
||||||
|
|
||||||
if authErr != nil {
|
if authErr != nil {
|
||||||
return ctx.Error(http.StatusBadRequest, "Couldn't authorize the Anime Notifier app on AniList", authErr)
|
return nil, ctx.Error(http.StatusBadRequest, "Couldn't authorize the Anime Notifier app on AniList", authErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
allAnime, allErr := arn.AllAnime()
|
allAnime, allErr := arn.AllAnime()
|
||||||
|
|
||||||
if allErr != nil {
|
if allErr != nil {
|
||||||
return ctx.Error(http.StatusBadRequest, "Couldn't load notify.moe list of all anime", allErr)
|
return nil, ctx.Error(http.StatusBadRequest, "Couldn't load notify.moe list of all anime", allErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
animeList, err := arn.AniList.GetAnimeList(user)
|
anilistAnimeList, err := arn.AniList.GetAnimeList(user)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ctx.Error(http.StatusBadRequest, "Couldn't load your anime list from AniList", err)
|
return nil, ctx.Error(http.StatusBadRequest, "Couldn't load your anime list from AniList", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
matches := findAllMatches(allAnime, animeList)
|
matches := findAllMatches(allAnime, anilistAnimeList)
|
||||||
|
|
||||||
|
return matches, ""
|
||||||
|
}
|
||||||
|
|
||||||
|
// Preview ...
|
||||||
|
func Preview(ctx *aero.Context) string {
|
||||||
|
user := utils.GetUser(ctx)
|
||||||
|
matches, response := getMatches(ctx)
|
||||||
|
|
||||||
|
if response != "" {
|
||||||
|
return response
|
||||||
|
}
|
||||||
|
|
||||||
return ctx.HTML(components.ImportAnilist(user, matches))
|
return ctx.HTML(components.ImportAnilist(user, matches))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Finish ...
|
||||||
|
func Finish(ctx *aero.Context) string {
|
||||||
|
user := utils.GetUser(ctx)
|
||||||
|
matches, response := getMatches(ctx)
|
||||||
|
|
||||||
|
if response != "" {
|
||||||
|
return response
|
||||||
|
}
|
||||||
|
|
||||||
|
animeList := user.AnimeList()
|
||||||
|
|
||||||
|
for _, match := range matches {
|
||||||
|
if match.ARNAnime == nil || match.AniListItem == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
item := &arn.AnimeListItem{
|
||||||
|
AnimeID: match.ARNAnime.ID,
|
||||||
|
Status: match.AniListItem.AnimeListStatus(),
|
||||||
|
Episodes: match.AniListItem.EpisodesWatched,
|
||||||
|
Notes: match.AniListItem.Notes,
|
||||||
|
Rating: &arn.AnimeRating{
|
||||||
|
Overall: float64(match.AniListItem.ScoreRaw) / 10.0,
|
||||||
|
},
|
||||||
|
RewatchCount: match.AniListItem.Rewatched,
|
||||||
|
Created: arn.DateTimeUTC(),
|
||||||
|
Edited: arn.DateTimeUTC(),
|
||||||
|
}
|
||||||
|
|
||||||
|
animeList.Import(item)
|
||||||
|
}
|
||||||
|
|
||||||
|
err := animeList.Save()
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return ctx.Error(http.StatusInternalServerError, "Error saving your anime list", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return ctx.Redirect("/+" + user.Nick + "/animelist")
|
||||||
|
}
|
||||||
|
|
||||||
// findAllMatches returns all matches for the anime inside an anilist anime list.
|
// findAllMatches returns all matches for the anime inside an anilist anime list.
|
||||||
func findAllMatches(allAnime []*arn.Anime, animeList *arn.AniListAnimeList) []*arn.AniListMatch {
|
func findAllMatches(allAnime []*arn.Anime, animeList *arn.AniListAnimeList) []*arn.AniListMatch {
|
||||||
matches := []*arn.AniListMatch{}
|
matches := []*arn.AniListMatch{}
|
||||||
@ -67,8 +119,8 @@ func findAllMatches(allAnime []*arn.Anime, animeList *arn.AniListAnimeList) []*a
|
|||||||
func importList(matches []*arn.AniListMatch, allAnime []*arn.Anime, animeListItems []*arn.AniListAnimeListItem) []*arn.AniListMatch {
|
func importList(matches []*arn.AniListMatch, allAnime []*arn.Anime, animeListItems []*arn.AniListAnimeListItem) []*arn.AniListMatch {
|
||||||
for _, item := range animeListItems {
|
for _, item := range animeListItems {
|
||||||
matches = append(matches, &arn.AniListMatch{
|
matches = append(matches, &arn.AniListMatch{
|
||||||
AniListAnime: item.Anime,
|
AniListItem: item,
|
||||||
ARNAnime: arn.FindAniListAnime(item.Anime, allAnime),
|
ARNAnime: arn.FindAniListAnime(item.Anime, allAnime),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,14 +10,14 @@ component ImportAnilist(user *arn.User, matches []*arn.AniListMatch)
|
|||||||
each match in matches
|
each match in matches
|
||||||
tr
|
tr
|
||||||
td
|
td
|
||||||
a(href=match.AniListAnime.Link(), target="_blank", rel="noopener")= match.AniListAnime.TitleRomaji
|
a(href=match.AniListItem.Anime.Link(), target="_blank", rel="noopener")= match.AniListItem.Anime.TitleRomaji
|
||||||
td
|
td
|
||||||
if match.ARNAnime == nil
|
if match.ARNAnime == nil
|
||||||
span.import-error Not found on notify.moe
|
span.import-error Not found on notify.moe
|
||||||
else
|
else
|
||||||
a(href=match.ARNAnime.Link(), target="_blank", rel="noopener")= match.ARNAnime.Title.Canonical
|
a(href=match.ARNAnime.Link(), target="_blank", rel="noopener")= match.ARNAnime.Title.Canonical
|
||||||
|
|
||||||
.buttons
|
.buttons
|
||||||
.button.mountable.action(data-action="soon", data-trigger="click")
|
a.button.mountable(href="/import/anilist/animelist/finish")
|
||||||
Icon("refresh")
|
Icon("refresh")
|
||||||
span Import
|
span Import
|
@ -35,28 +35,6 @@ func Profile(ctx *aero.Context, viewUser *arn.User) string {
|
|||||||
user = utils.GetUser(ctx)
|
user = utils.GetUser(ctx)
|
||||||
}, func() {
|
}, func() {
|
||||||
animeList = viewUser.AnimeList()
|
animeList = viewUser.AnimeList()
|
||||||
}, func() {
|
|
||||||
// threads = viewUser.Threads()
|
|
||||||
|
|
||||||
// arn.SortThreadsLatestFirst(threads)
|
|
||||||
|
|
||||||
// if len(threads) > maxPosts {
|
|
||||||
// threads = threads[:maxPosts]
|
|
||||||
// }
|
|
||||||
}, func() {
|
|
||||||
// posts = viewUser.Posts()
|
|
||||||
// arn.SortPostsLatestFirst(posts)
|
|
||||||
|
|
||||||
// if len(posts) > maxPosts {
|
|
||||||
// posts = posts[:maxPosts]
|
|
||||||
// }
|
|
||||||
}, func() {
|
|
||||||
// tracks = viewUser.SoundTracks()
|
|
||||||
// arn.SortSoundTracksLatestFirst(tracks)
|
|
||||||
|
|
||||||
// if len(tracks) > maxTracks {
|
|
||||||
// tracks = tracks[:maxTracks]
|
|
||||||
// }
|
|
||||||
})
|
})
|
||||||
|
|
||||||
return ctx.HTML(components.Profile(viewUser, user, animeList, threads, posts, tracks))
|
return ctx.HTML(components.Profile(viewUser, user, animeList, threads, posts, tracks))
|
||||||
|
Loading…
Reference in New Issue
Block a user