aboutsummaryrefslogtreecommitdiff
path: root/dataimport/converter.go
blob: 6a443841eb5a251170e0470b40f3d7463da41038 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package dataimport

import (
	"fmt"
	"strings"

	"fagott.pw/goanilist"
	"fagott.pw/grilist/models"
)

func ConvertGrilAnilist(char *goanilist.CharacterPageResult) *ImporterGril {
	gril := &ImporterGril{}
	gril.ID = char.ID
	gril.KanjiName = char.JapaneseName
	gril.RomajiName = strings.TrimSpace(fmt.Sprintf("%s %s", char.GivenName, char.FamilyName))
	gril.Order = char.Order
	if char.AlternativeName != "" {
		gril.OtherNames = append(gril.OtherNames, char.AlternativeName)
	}
	if char.ImageURL != "" {
		gril.Images = append(gril.Images, Image{
			Type: ImageTypeFull,
			URL:  char.ImageURL,
		})
	}
	if char.ThumbURL != "" {
		gril.Images = append(gril.Images, Image{
			Type: ImageTypeThumbnail,
			URL:  char.ThumbURL,
		})
	}
	for _, anime := range char.Anime {
		gril.Series = append(gril.Series, ConvertSeriesAnilist(anime.SeriesResult))
	}
	for _, manga := range char.Manga {
		gril.Series = append(gril.Series, ConvertSeriesAnilist(manga.SeriesResult))
	}
	return gril
}

func ConvertSeriesTypeAnilist(seriesType string) models.SeriesType {
	switch seriesType {
	}
	return models.SeriesTypeUnknown
}

func ConvertSeriesAnilist(series goanilist.SeriesResult) models.Series {
	return models.Series{
		ID:         series.ID,
		Type:       ConvertSeriesTypeAnilist(series.Type),
		Name:       series.TitleEnglish,
		KanjiName:  series.TitleJapanese,
		RomajiName: series.TitleRomaji,
		OtherNames: series.Synonyms,
	}
}