tvqueue.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package datastructure
  2. import (
  3. "strconv"
  4. )
  5. func min(a, b int) int {
  6. if a > b {
  7. return b
  8. } else {
  9. return a
  10. }
  11. } // todo replicated code from libamuse/serie.go
  12. type TvQueueEntry struct {
  13. ItemInfo
  14. Id string
  15. HasPrevious bool
  16. WatchedEpisodes int
  17. SkippedEpisodes int
  18. }
  19. func (e TvQueueEntry) GetYears() string {
  20. if e.YearStart == 0 {
  21. return ""
  22. } else if e.Status == "Ended" || e.Status == "Canceled" {
  23. if e.YearEnd == e.YearStart || e.YearEnd == 0 {
  24. return strconv.FormatInt(int64(e.YearStart), 10)
  25. } else {
  26. return strconv.FormatInt(int64(e.YearStart), 10) + "–" + strconv.FormatInt(int64(e.YearEnd), 10)
  27. }
  28. } else {
  29. return strconv.FormatInt(int64(e.YearStart), 10) + "–"
  30. }
  31. }
  32. func (e TvQueueEntry) CalculateProgress() int { // todo replicated code from libamuse/serie.go
  33. if e.Episodes-e.SkippedEpisodes == 0 {
  34. return 0
  35. }
  36. return min(e.WatchedEpisodes*100/(e.Episodes-e.SkippedEpisodes), 100)
  37. }
  38. type TvQueue struct {
  39. List []TvQueueEntry
  40. Page int
  41. Pages int
  42. Genres map[int]string
  43. Query string
  44. }
  45. func (q *TvQueue) SetGenres(m map[int]string) {
  46. q.Genres = m
  47. }
  48. func (q *TvQueue) GetType() ItemType {
  49. return ItemTypeTvserie
  50. }
  51. func (q TvQueue) NextPage() int {
  52. if q.Page < q.Pages {
  53. return q.Page + 1
  54. } else {
  55. return q.Page
  56. }
  57. }
  58. func (q TvQueue) PrevPage() int {
  59. if q.Page > 1 {
  60. return q.Page - 1
  61. } else {
  62. return q.Page
  63. }
  64. }