Fixed anilist changes

This commit is contained in:
Eduard Urbach 2017-07-09 15:56:40 +02:00
parent 839918e20e
commit 27b828578f
3 changed files with 16 additions and 13 deletions

View File

@ -4,6 +4,7 @@ import (
"net/http" "net/http"
"github.com/aerogo/aero" "github.com/aerogo/aero"
"github.com/animenotifier/anilist"
"github.com/animenotifier/arn" "github.com/animenotifier/arn"
"github.com/animenotifier/notify.moe/components" "github.com/animenotifier/notify.moe/components"
"github.com/animenotifier/notify.moe/utils" "github.com/animenotifier/notify.moe/utils"
@ -49,7 +50,7 @@ func Finish(ctx *aero.Context) string {
item := &arn.AnimeListItem{ item := &arn.AnimeListItem{
AnimeID: match.ARNAnime.ID, AnimeID: match.ARNAnime.ID,
Status: match.AniListItem.AnimeListStatus(), Status: arn.AniListAnimeListStatus(match.AniListItem),
Episodes: match.AniListItem.EpisodesWatched, Episodes: match.AniListItem.EpisodesWatched,
Notes: match.AniListItem.Notes, Notes: match.AniListItem.Notes,
Rating: &arn.AnimeRating{ Rating: &arn.AnimeRating{
@ -80,7 +81,7 @@ 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 := arn.AniList.Authorize() authErr := anilist.Authorize()
if authErr != nil { if authErr != nil {
return nil, 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)
@ -92,7 +93,7 @@ func getMatches(ctx *aero.Context) ([]*arn.AniListMatch, string) {
return nil, 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)
} }
anilistAnimeList, err := arn.AniList.GetAnimeList(user) anilistAnimeList, err := anilist.GetAnimeList(user.Accounts.AniList.Nick)
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)
@ -104,7 +105,7 @@ func getMatches(ctx *aero.Context) ([]*arn.AniListMatch, string) {
} }
// 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 *anilist.AnimeList) []*arn.AniListMatch {
matches := []*arn.AniListMatch{} matches := []*arn.AniListMatch{}
matches = importList(matches, allAnime, animeList.Lists.Watching) matches = importList(matches, allAnime, animeList.Lists.Watching)
@ -113,7 +114,7 @@ func findAllMatches(allAnime []*arn.Anime, animeList *arn.AniListAnimeList) []*a
matches = importList(matches, allAnime, animeList.Lists.OnHold) matches = importList(matches, allAnime, animeList.Lists.OnHold)
matches = importList(matches, allAnime, animeList.Lists.Dropped) matches = importList(matches, allAnime, animeList.Lists.Dropped)
custom, ok := animeList.CustomLists.(map[string][]*arn.AniListAnimeListItem) custom, ok := animeList.CustomLists.(map[string][]*anilist.AnimeListItem)
if !ok { if !ok {
return matches return matches
@ -127,7 +128,7 @@ func findAllMatches(allAnime []*arn.Anime, animeList *arn.AniListAnimeList) []*a
} }
// 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 []*arn.AniListAnimeListItem) []*arn.AniListMatch { func importList(matches []*arn.AniListMatch, allAnime []*arn.Anime, 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,

View File

@ -3,6 +3,7 @@ package main
import ( import (
"fmt" "fmt"
"github.com/animenotifier/anilist"
"github.com/animenotifier/arn" "github.com/animenotifier/arn"
"github.com/fatih/color" "github.com/fatih/color"
) )
@ -15,18 +16,18 @@ func init() {
} }
func main() { func main() {
arn.PanicOnError(arn.AniList.Authorize()) arn.PanicOnError(anilist.Authorize())
println(arn.AniList.AccessToken) println(anilist.AccessToken)
user, _ := arn.GetUserByNick(userName) user, _ := arn.GetUserByNick(userName)
animeList, err := arn.AniList.GetAnimeList(user) animeList, err := anilist.GetAnimeList(user.Accounts.AniList.Nick)
arn.PanicOnError(err) arn.PanicOnError(err)
importList(animeList.Lists.Watching) importList(animeList.Lists.Watching)
importList(animeList.Lists.Completed) importList(animeList.Lists.Completed)
} }
func importList(animeListItems []*arn.AniListAnimeListItem) { func importList(animeListItems []*anilist.AnimeListItem) {
imported := []*arn.Anime{} imported := []*arn.Anime{}
for _, item := range animeListItems { for _, item := range animeListItems {

View File

@ -3,19 +3,20 @@ package main
import ( import (
"fmt" "fmt"
"github.com/animenotifier/anilist"
"github.com/animenotifier/arn" "github.com/animenotifier/arn"
"github.com/fatih/color" "github.com/fatih/color"
) )
func main() { func main() {
arn.PanicOnError(arn.AniList.Authorize()) arn.PanicOnError(anilist.Authorize())
color.Green(arn.AniList.AccessToken) color.Green(anilist.AccessToken)
allAnime, err := arn.AllAnime() allAnime, err := arn.AllAnime()
arn.PanicOnError(err) arn.PanicOnError(err)
count := 0 count := 0
stream := arn.AniList.StreamAnime() stream := anilist.StreamAnime()
for aniListAnime := range stream { for aniListAnime := range stream {
anime := arn.FindAniListAnime(aniListAnime, allAnime) anime := arn.FindAniListAnime(aniListAnime, allAnime)