75 lines
1.2 KiB
Go
Raw Normal View History

2018-04-12 11:39:58 +00:00
package main
import (
"fmt"
"github.com/animenotifier/arn"
"github.com/animenotifier/mal"
"github.com/fatih/color"
)
2018-04-17 13:33:19 +00:00
const imageWidthThreshold = 225
2018-04-17 13:28:57 +00:00
2018-04-12 11:39:58 +00:00
var (
malDB = arn.Node.Namespace("mal").RegisterTypes((*mal.Anime)(nil))
characterFinder = arn.NewCharacterFinder("myanimelist/character")
)
func main() {
color.Yellow("Syncing with MAL DB")
defer color.Green("Finished.")
defer arn.Node.Close()
2018-04-12 17:05:05 +00:00
// Invoke via parameters
if InvokeShellArgs() {
return
}
2018-04-12 11:39:58 +00:00
// Sync the most important ones first
allAnime := arn.AllAnime()
arn.SortAnimeByQuality(allAnime)
for _, anime := range allAnime {
malID := anime.GetMapping("myanimelist/anime")
if malID == "" {
continue
}
sync(anime, malID)
}
}
func sync(anime *arn.Anime, malID string) {
obj, err := malDB.Get("Anime", malID)
if err != nil {
fmt.Println(err)
return
}
malAnime := obj.(*mal.Anime)
// Log title
fmt.Printf("%s %s\n", color.CyanString(anime.Title.Canonical), malID)
2018-04-26 19:36:26 +00:00
type syncFunction func(*arn.Anime, *mal.Anime)
2018-04-12 11:39:58 +00:00
2018-04-26 19:36:26 +00:00
syncFunctions := []syncFunction{
syncTitles,
syncDates,
syncEpisodes,
syncOthers,
syncImage,
syncCharacters,
2018-04-26 18:41:41 +00:00
}
2018-04-17 13:28:57 +00:00
2018-04-26 19:36:26 +00:00
for _, syncFunction := range syncFunctions {
syncFunction(anime, malAnime)
2018-04-17 13:28:57 +00:00
}
2018-04-26 19:36:26 +00:00
// Save in database
anime.Save()
2018-04-12 11:39:58 +00:00
}