item.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package datastructure
  2. import (
  3. "strconv"
  4. "strings"
  5. )
  6. type ItemInfo struct {
  7. Cover string
  8. Status string
  9. Title string
  10. YearStart int
  11. YearEnd int
  12. BasedOn string
  13. Genres string
  14. Runtime int
  15. Collection int
  16. Part int
  17. Episodes int
  18. }
  19. func (i ItemInfo) IsUnreleased(itemType ItemType) bool {
  20. return (itemType == ItemTypeFilm && i.Status != "Released") ||
  21. (itemType == ItemTypeTvserie && i.Status != "Returning Series" && i.Status != "Ended")
  22. }
  23. func (i ItemInfo) GetGenres(genres map[int]string) string {
  24. genreIds := strings.Split(i.Genres, ",")
  25. genreNames := []string{}
  26. for _, genreId := range genreIds {
  27. if genreId != "" {
  28. genreIdInt, _ := strconv.ParseInt(genreId, 10, 64)
  29. if genres[int(genreIdInt)] != "" {
  30. genreNames = append(genreNames, genres[int(genreIdInt)])
  31. }
  32. }
  33. }
  34. return strings.Join(genreNames, ", ")
  35. }
  36. type Item interface {
  37. GetItemInfo() ItemInfo
  38. GetItemType() ItemType
  39. SetOnWantList(isOnList bool)
  40. }
  41. type ItemType string
  42. const (
  43. ItemTypeBook ItemType = "book"
  44. ItemTypeFilm = "film"
  45. ItemTypeTvserie = "tvserie"
  46. ItemTypeUnkown = "unknown"
  47. )