New Anilist importer
This commit is contained in:
parent
8acdcaeb38
commit
a4bbd5cbbc
@ -2,6 +2,7 @@ package listimportanilist
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"github.com/aerogo/aero"
|
"github.com/aerogo/aero"
|
||||||
"github.com/animenotifier/anilist"
|
"github.com/animenotifier/anilist"
|
||||||
@ -51,12 +52,13 @@ func Finish(ctx *aero.Context) string {
|
|||||||
item := &arn.AnimeListItem{
|
item := &arn.AnimeListItem{
|
||||||
AnimeID: match.ARNAnime.ID,
|
AnimeID: match.ARNAnime.ID,
|
||||||
Status: arn.AniListAnimeListStatus(match.AniListItem),
|
Status: arn.AniListAnimeListStatus(match.AniListItem),
|
||||||
Episodes: match.AniListItem.EpisodesWatched,
|
Episodes: match.AniListItem.Progress,
|
||||||
Notes: match.AniListItem.Notes,
|
Notes: match.AniListItem.Notes,
|
||||||
Rating: arn.AnimeListItemRating{
|
Rating: arn.AnimeListItemRating{
|
||||||
Overall: float64(match.AniListItem.ScoreRaw) / 10.0,
|
Overall: float64(match.AniListItem.ScoreRaw) / 10.0,
|
||||||
},
|
},
|
||||||
RewatchCount: match.AniListItem.Rewatched,
|
RewatchCount: match.AniListItem.Repeat,
|
||||||
|
Private: match.AniListItem.Private,
|
||||||
Created: arn.DateTimeUTC(),
|
Created: arn.DateTimeUTC(),
|
||||||
Edited: arn.DateTimeUTC(),
|
Edited: arn.DateTimeUTC(),
|
||||||
}
|
}
|
||||||
@ -77,53 +79,44 @@ func getMatches(ctx *aero.Context) ([]*arn.AniListMatch, string) {
|
|||||||
return nil, ctx.Error(http.StatusBadRequest, "Not logged in", nil)
|
return nil, ctx.Error(http.StatusBadRequest, "Not logged in", nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
authErr := anilist.Authorize()
|
// Get user
|
||||||
|
anilistUser, err := anilist.GetUser(user.Accounts.AniList.Nick)
|
||||||
|
|
||||||
if authErr != nil {
|
if err != nil {
|
||||||
return nil, ctx.Error(http.StatusBadRequest, "Couldn't authorize the Anime Notifier app on AniList", authErr)
|
return nil, ctx.Error(http.StatusBadRequest, "User doesn't exist on AniList", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
allAnime := arn.AllAnime()
|
// Get anime list
|
||||||
anilistAnimeList, err := anilist.GetAnimeList(user.Accounts.AniList.Nick)
|
anilistAnimeList, err := anilist.GetAnimeList(anilistUser.ID)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, 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, anilistAnimeList)
|
// Find matches
|
||||||
|
matches := findAllMatches(anilistAnimeList)
|
||||||
|
|
||||||
return matches, ""
|
return matches, ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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 *anilist.AnimeList) []*arn.AniListMatch {
|
func findAllMatches(animeList *anilist.AnimeList) []*arn.AniListMatch {
|
||||||
|
finder := arn.NewAniListAnimeFinder()
|
||||||
matches := []*arn.AniListMatch{}
|
matches := []*arn.AniListMatch{}
|
||||||
|
|
||||||
matches = importList(matches, allAnime, animeList.Lists.Watching)
|
for _, list := range animeList.Lists {
|
||||||
matches = importList(matches, allAnime, animeList.Lists.Completed)
|
matches = importList(matches, finder, list.Entries)
|
||||||
matches = importList(matches, allAnime, animeList.Lists.PlanToWatch)
|
|
||||||
matches = importList(matches, allAnime, animeList.Lists.OnHold)
|
|
||||||
matches = importList(matches, allAnime, animeList.Lists.Dropped)
|
|
||||||
|
|
||||||
custom, ok := animeList.CustomLists.(map[string][]*anilist.AnimeListItem)
|
|
||||||
|
|
||||||
if !ok {
|
|
||||||
return matches
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, list := range custom {
|
|
||||||
matches = importList(matches, allAnime, list)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return matches
|
return matches
|
||||||
}
|
}
|
||||||
|
|
||||||
// importList imports a single list inside an anilist anime list collection.
|
// importList imports a single list inside an anilist anime list collection.
|
||||||
func importList(matches []*arn.AniListMatch, allAnime []*arn.Anime, animeListItems []*anilist.AnimeListItem) []*arn.AniListMatch {
|
func importList(matches []*arn.AniListMatch, finder *arn.AniListAnimeFinder, animeListItems []*anilist.AnimeListItem) []*arn.AniListMatch {
|
||||||
for _, item := range animeListItems {
|
for _, item := range animeListItems {
|
||||||
matches = append(matches, &arn.AniListMatch{
|
matches = append(matches, &arn.AniListMatch{
|
||||||
AniListItem: item,
|
AniListItem: item,
|
||||||
ARNAnime: arn.FindAniListAnime(item.Anime, allAnime),
|
ARNAnime: finder.GetAnime(strconv.Itoa(item.Anime.ID), strconv.Itoa(item.Anime.MALID)),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ component ImportAnilist(user *arn.User, matches []*arn.AniListMatch)
|
|||||||
each match in matches
|
each match in matches
|
||||||
tr
|
tr
|
||||||
td
|
td
|
||||||
a(href=match.AniListItem.Anime.Link(), target="_blank", rel="noopener")= match.AniListItem.Anime.TitleRomaji
|
a(href=match.AniListItem.Anime.Link(), target="_blank", rel="noopener")= match.AniListItem.Anime.Title.Romaji
|
||||||
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
|
||||||
|
@ -16,9 +16,6 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
arn.PanicOnError(anilist.Authorize())
|
|
||||||
println(anilist.AccessToken)
|
|
||||||
|
|
||||||
user, _ := arn.GetUserByNick(userName)
|
user, _ := arn.GetUserByNick(userName)
|
||||||
animeList, err := anilist.GetAnimeList(user.Accounts.AniList.Nick)
|
animeList, err := anilist.GetAnimeList(user.Accounts.AniList.Nick)
|
||||||
arn.PanicOnError(err)
|
arn.PanicOnError(err)
|
||||||
|
@ -1,34 +1,28 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/animenotifier/anilist"
|
|
||||||
"github.com/animenotifier/arn"
|
|
||||||
"github.com/fatih/color"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
color.Yellow("Iterating through AniList anime to generate new mappings")
|
// color.Yellow("Iterating through AniList anime to generate new mappings")
|
||||||
defer arn.Node.Close()
|
// defer arn.Node.Close()
|
||||||
|
|
||||||
err := anilist.Authorize()
|
// err := anilist.Authorize()
|
||||||
arn.PanicOnError(err)
|
// arn.PanicOnError(err)
|
||||||
color.Green(anilist.AccessToken)
|
// color.Green(anilist.AccessToken)
|
||||||
|
|
||||||
allAnime := arn.AllAnime()
|
// allAnime := arn.AllAnime()
|
||||||
count := 0
|
// count := 0
|
||||||
|
|
||||||
for aniListAnime := range anilist.StreamAnime() {
|
// for aniListAnime := range anilist.StreamAnime() {
|
||||||
println(aniListAnime.TitleRomaji)
|
// println(aniListAnime.TitleRomaji)
|
||||||
|
|
||||||
anime := arn.FindAniListAnime(aniListAnime, allAnime)
|
// anime := arn.FindAniListAnime(aniListAnime, allAnime)
|
||||||
|
|
||||||
if anime != nil {
|
// if anime != nil {
|
||||||
color.Green("%s %s", anime.ID, anime)
|
// color.Green("%s %s", anime.ID, anime)
|
||||||
count++
|
// count++
|
||||||
} else {
|
// } else {
|
||||||
color.Red("Not found")
|
// color.Red("Not found")
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
color.Green("%d anime are connected with AniList", count)
|
// color.Green("%d anime are connected with AniList", count)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user