common.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package tmdb
  2. import (
  3. "notabug.org/apiote/amuse/datastructure"
  4. "notabug.org/apiote/amuse/db"
  5. "notabug.org/apiote/amuse/network"
  6. "notabug.org/apiote/gott"
  7. )
  8. type Show interface {
  9. AddBasedOn(book datastructure.Book)
  10. }
  11. type ShowCastEntry struct {
  12. Character string
  13. Id int
  14. Name string
  15. Profile_path string `json:"profile_path"`
  16. }
  17. type ShowCrewEntry struct {
  18. Job string
  19. Id int
  20. Name string
  21. Profile_path string `json:"profile_path"`
  22. }
  23. type ShowCredits struct {
  24. Cast []ShowCastEntry
  25. Crew []ShowCrewEntry
  26. }
  27. func GetItemTypeFromShow(show Show) datastructure.ItemType {
  28. if _, ok := show.(*Film); ok {
  29. return datastructure.ItemTypeFilm
  30. } else if _, ok := show.(*TvSerie); ok {
  31. return datastructure.ItemTypeTvserie
  32. } else {
  33. return datastructure.ItemTypeUnkown
  34. }
  35. }
  36. func getCacheEntry(args ...interface{}) (interface{}, error) {
  37. result := args[1].(*network.Result)
  38. uri := result.Request.URL.String()
  39. entry, err := db.GetCacheEntry(uri)
  40. if err != nil || entry == nil {
  41. return gott.Tuple(args), err
  42. }
  43. result.Etag = entry.Etag
  44. result.Body = entry.Data
  45. return gott.Tuple(args), nil
  46. }
  47. func cleanCache(args ...interface{}) error {
  48. err := db.CleanCache()
  49. return err
  50. }
  51. func saveCacheEntry(args ...interface{}) error {
  52. result := args[1].(*network.Result)
  53. uri := result.Request.URL.String()
  54. err := db.SaveCacheEntry(uri, result.Etag, result.Body)
  55. return err
  56. }