|
| 1 | +// |
| 2 | +// Assets.swift |
| 3 | +// MusicLibrary |
| 4 | +// |
| 5 | +// |
| 6 | + |
| 7 | +import Foundation |
| 8 | + |
| 9 | +// MARK: - Data Models |
| 10 | + |
| 11 | +public class Track: NSObject { |
| 12 | + public let id: String |
| 13 | + public let title: String |
| 14 | + public let artist: String? |
| 15 | + public let artwork: String? |
| 16 | + public let album: String? |
| 17 | + public let duration: Double |
| 18 | + public let url: String |
| 19 | + public let createdAt: Double? |
| 20 | + public let modifiedAt: Double? |
| 21 | + public let fileSize: Int64 |
| 22 | + |
| 23 | + public init(id: String, title: String, artist: String?, artwork: String?, album: String?, duration: Double, url: String, createdAt: Double?, modifiedAt: Double?, fileSize: Int64) { |
| 24 | + self.id = id |
| 25 | + self.title = title |
| 26 | + self.artist = artist |
| 27 | + self.artwork = artwork |
| 28 | + self.album = album |
| 29 | + self.duration = duration |
| 30 | + self.url = url |
| 31 | + self.createdAt = createdAt |
| 32 | + self.modifiedAt = modifiedAt |
| 33 | + self.fileSize = fileSize |
| 34 | + super.init() |
| 35 | + } |
| 36 | + |
| 37 | + public func toDictionary() -> [String: Any] { |
| 38 | + return [ |
| 39 | + "id": id, |
| 40 | + "title": title, |
| 41 | + "artist": artist ?? NSNull(), |
| 42 | + "artwork": artwork ?? NSNull(), |
| 43 | + "album": album ?? NSNull(), |
| 44 | + "duration": duration, |
| 45 | + "url": url, |
| 46 | + "createdAt": createdAt ?? NSNull(), |
| 47 | + "modifiedAt": modifiedAt ?? NSNull(), |
| 48 | + "fileSize": fileSize |
| 49 | + ] |
| 50 | + } |
| 51 | +} |
| 52 | + |
| 53 | +public class TrackMetadata: NSObject { |
| 54 | + public let id: String |
| 55 | + |
| 56 | + // AudioHeader |
| 57 | + public let duration: Double? |
| 58 | + public let bitrate: Int64? |
| 59 | + public let sampleRate: Int? |
| 60 | + public let channels: String? |
| 61 | + public let format: String? |
| 62 | + |
| 63 | + // Tag |
| 64 | + public let title: String? |
| 65 | + public let artist: String? |
| 66 | + public let album: String? |
| 67 | + public let year: Int? |
| 68 | + public let genre: String? |
| 69 | + public let track: Int? |
| 70 | + public let disc: Int? |
| 71 | + public let composer: String? |
| 72 | + public let lyricist: String? |
| 73 | + public let lyrics: String? |
| 74 | + public let albumArtist: String? |
| 75 | + public let comment: String? |
| 76 | + |
| 77 | + public init(id: String, duration: Double?, bitrate: Int64?, sampleRate: Int?, channels: String?, format: String?, title: String?, artist: String?, album: String?, year: Int?, genre: String?, track: Int?, disc: Int?, composer: String?, lyricist: String?, lyrics: String?, albumArtist: String?, comment: String?) { |
| 78 | + self.id = id |
| 79 | + self.duration = duration |
| 80 | + self.bitrate = bitrate |
| 81 | + self.sampleRate = sampleRate |
| 82 | + self.channels = channels |
| 83 | + self.format = format |
| 84 | + self.title = title |
| 85 | + self.artist = artist |
| 86 | + self.album = album |
| 87 | + self.year = year |
| 88 | + self.genre = genre |
| 89 | + self.track = track |
| 90 | + self.disc = disc |
| 91 | + self.composer = composer |
| 92 | + self.lyricist = lyricist |
| 93 | + self.lyrics = lyrics |
| 94 | + self.albumArtist = albumArtist |
| 95 | + self.comment = comment |
| 96 | + super.init() |
| 97 | + } |
| 98 | + |
| 99 | + public func toDictionary() -> [String: Any] { |
| 100 | + return [ |
| 101 | + "id": id, |
| 102 | + "duration": duration ?? NSNull(), |
| 103 | + "bitrate": bitrate ?? NSNull(), |
| 104 | + "sampleRate": sampleRate ?? NSNull(), |
| 105 | + "channels": channels ?? NSNull(), |
| 106 | + "format": format ?? NSNull(), |
| 107 | + "title": title ?? NSNull(), |
| 108 | + "artist": artist ?? NSNull(), |
| 109 | + "album": album ?? NSNull(), |
| 110 | + "year": year ?? NSNull(), |
| 111 | + "genre": genre ?? NSNull(), |
| 112 | + "track": track ?? NSNull(), |
| 113 | + "disc": disc ?? NSNull(), |
| 114 | + "composer": composer ?? NSNull(), |
| 115 | + "lyricist": lyricist ?? NSNull(), |
| 116 | + "lyrics": lyrics ?? NSNull(), |
| 117 | + "albumArtist": albumArtist ?? NSNull(), |
| 118 | + "comment": comment ?? NSNull() |
| 119 | + ] |
| 120 | + } |
| 121 | +} |
| 122 | + |
| 123 | +public class Album: NSObject { |
| 124 | + public let id: String |
| 125 | + public let title: String |
| 126 | + public let artist: String |
| 127 | + public let artwork: String? |
| 128 | + public let trackCount: Int |
| 129 | + public let year: Int? |
| 130 | + |
| 131 | + public init(id: String, title: String, artist: String, artwork: String?, trackCount: Int, year: Int?) { |
| 132 | + self.id = id |
| 133 | + self.title = title |
| 134 | + self.artist = artist |
| 135 | + self.artwork = artwork |
| 136 | + self.trackCount = trackCount |
| 137 | + self.year = year |
| 138 | + super.init() |
| 139 | + } |
| 140 | + |
| 141 | + public func toDictionary() -> [String: Any] { |
| 142 | + return [ |
| 143 | + "id": id, |
| 144 | + "title": title, |
| 145 | + "artist": artist, |
| 146 | + "artwork": artwork ?? NSNull(), |
| 147 | + "trackCount": trackCount, |
| 148 | + "year": year ?? NSNull() |
| 149 | + ] |
| 150 | + } |
| 151 | +} |
| 152 | + |
| 153 | +public class Artist: NSObject { |
| 154 | + public let id: String |
| 155 | + public let title: String |
| 156 | + public let albumCount: Int |
| 157 | + public let trackCount: Int |
| 158 | + |
| 159 | + public init(id: String, title: String, albumCount: Int, trackCount: Int) { |
| 160 | + self.id = id |
| 161 | + self.title = title |
| 162 | + self.albumCount = albumCount |
| 163 | + self.trackCount = trackCount |
| 164 | + super.init() |
| 165 | + } |
| 166 | + |
| 167 | + public func toDictionary() -> [String: Any] { |
| 168 | + return [ |
| 169 | + "id": id, |
| 170 | + "title": title, |
| 171 | + "albumCount": albumCount, |
| 172 | + "trackCount": trackCount |
| 173 | + ] |
| 174 | + } |
| 175 | +} |
| 176 | + |
| 177 | +public class Genre: NSObject { |
| 178 | + public let id: String |
| 179 | + public let title: String |
| 180 | + public let trackCount: Int |
| 181 | + |
| 182 | + public init(id: String, title: String, trackCount: Int) { |
| 183 | + self.id = id |
| 184 | + self.title = title |
| 185 | + self.trackCount = trackCount |
| 186 | + super.init() |
| 187 | + } |
| 188 | + |
| 189 | + public func toDictionary() -> [String: Any] { |
| 190 | + return [ |
| 191 | + "id": id, |
| 192 | + "title": title, |
| 193 | + "trackCount": trackCount |
| 194 | + ] |
| 195 | + } |
| 196 | +} |
0 commit comments