models.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. class Model:
  2. def __init__(self, id_=None):
  3. self.id = id_
  4. def as_fields_and_values(self, exclude_id=False):
  5. fields, values = [], []
  6. for attr, val in self.__dict__.items():
  7. if attr[0] == '_' or val is None or (exclude_id and attr == 'id'):
  8. continue
  9. fields.append(attr)
  10. values.append(val)
  11. return fields, values
  12. class MusicFolder(Model):
  13. STATUS_UNKNOWN = 0
  14. STATUS_FOUND = 1
  15. STATUS_UNAVAILABLE = 2
  16. STATUS_DELETED = 3
  17. def __init__(self, id_=None, path_=None, last_scan=None, status=None):
  18. super().__init__(id_)
  19. self.path = path_
  20. self.last_scan = last_scan
  21. self.status = status if status is not None else MusicFolder.STATUS_UNKNOWN
  22. class Profile(Model):
  23. def __init__(self, id_=None, name=None, created_on=None):
  24. super().__init__(id_)
  25. self.name = name
  26. self.created_on = created_on
  27. class Tag(Model):
  28. def __init__(self, id_=None, label=None, color=None, deleted=0):
  29. super().__init__(id_)
  30. self.label = label
  31. self.color = color
  32. self.deleted = deleted
  33. class Track(Model):
  34. STATUS_UNKNOWN = 0
  35. STATUS_FOUND = 1
  36. STATUS_UNAVAILABLE = 2
  37. STATUS_UNREADABLE = 3
  38. def __init__(self, id_=None, profile_id=None, music_folder_id=None, title=None,
  39. format_=None, artist=None, album=None, track_num=None, year=None,
  40. duration=None, size=None, note=None, status=None, path_=None,
  41. hash_=None, origin=None):
  42. super().__init__(id_)
  43. self.profile_id = profile_id
  44. self.music_folder_id = music_folder_id
  45. self.title = title
  46. self.format = format_
  47. self.artist = artist
  48. self.album = album
  49. self.track_num = track_num
  50. self.year = year
  51. self.duration = duration
  52. self.size = size
  53. self.note = note
  54. self.status = status
  55. self.path = path_
  56. self.hash = hash_
  57. self.origin = origin
  58. class TrackTag(Model):
  59. def __init__(self, id_=None, track_id=None, tag_id=None):
  60. super().__init__(id_)
  61. self.track_id = track_id
  62. self.tag_id = tag_id
  63. class Session(Model):
  64. def __init__(self, id_=None, name=None, date_=None, notes=None):
  65. super().__init__(id_)
  66. self.name = name
  67. self.date = date_
  68. self.notes = notes