This repository was archived by the owner on Dec 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel.go
211 lines (189 loc) · 5.54 KB
/
model.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
// Copyright (C) 2020 The Takeout Authors.
//
// This file is part of Takeout.
//
// Takeout is free software: you can redistribute it and/or modify it under the
// terms of the GNU Affero General Public License as published by the Free
// Software Foundation, either version 3 of the License, or (at your option)
// any later version.
//
// Takeout is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
// more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with Takeout. If not, see <https://www.gnu.org/licenses/>.
package music
import (
"fmt"
"github.com/defsub/takeout/lib/gorm"
"github.com/google/uuid"
g "gorm.io/gorm"
"time"
)
// Artist info from MusicBrainz.
type Artist struct {
gorm.Model
Name string `gorm:"uniqueIndex:idx_artist_name"`
SortName string
ARID string `gorm:"uniqueIndex:idx_artist_arid"`
Disambiguation string
Country string
Area string
Date time.Time
EndDate time.Time
Genre string
}
// Release info from MusicBrainz.
type Release struct {
gorm.Model
Artist string `gorm:"uniqueIndex:idx_release"`
Name string `gorm:"uniqueIndex:idx_release;index:idx_release_name" sql:"collate:nocase"`
RGID string `gorm:"index:idx_release_rgid"`
REID string `gorm:"uniqueIndex:idx_release;index:idx_release_reid"`
Disambiguation string
Asin string
Country string
Type string `gorm:"index:idx_release_type"`
SecondaryType string
Date time.Time `gorm:"index:idx_release_rgdate"` // rg first release
ReleaseDate time.Time `gorm:"index:idx_release_redate"` // re release date
Status string
TrackCount int
DiscCount int
Artwork bool
FrontArtwork bool
BackArtwork bool
OtherArtwork string
GroupArtwork bool
Media []Media `gorm:"-"`
SingleName string `gorm:"index:idx_release_single_name"`
}
func (r Release) official() bool {
return r.Status == "Official"
}
func (r Release) Cover(size string) string {
return Cover(r, size)
}
func (r Release) CoverSmall() string {
return Cover(r, "250")
}
// Release Media from MusicBrainz.
type Media struct {
gorm.Model
REID string `gorm:"uniqueIndex:idx_media"`
Name string `gorm:"uniqueIndex:idx_media"`
Position int `gorm:"uniqueIndex:idx_media"`
Format string
TrackCount int
}
// Popular tracks for an artist from Last.fm.
type Popular struct {
gorm.Model
Artist string `gorm:"uniqueIndex:idx_popular"`
Title string `gorm:"uniqueIndex:idx_popular"`
Rank int
}
func (Popular) TableName() string {
return "popular" // not populars
}
// Similar artist info from Last.fm
type Similar struct {
gorm.Model
Artist string `gorm:"uniqueIndex:idx_similar"`
ARID string `gorm:"uniqueIndex:idx_similar"`
Rank int
}
func (Similar) TableName() string {
return "similar" // not similars
}
// Artist tags from MusicBrainz.
type ArtistTag struct {
gorm.Model
Artist string `gorm:"uniqueIndex:idx_tag"`
Tag string `gorm:"uniqueIndex:idx_tag"`
Count int
}
// Tracks from S3 bucket object names. Naming is adjusted based on
// data from MusicBrainz.
type Track struct {
gorm.Model
UUID string `gorm:"index:idx_track_uuid"`
Artist string `spiff:"creator" gorm:"index:idx_track_artist"`
Release string `gorm:"index:idx_track_release"`
Date string `gorm:"index:idx_track_date"`
TrackNum int `spiff:"tracknum"`
DiscNum int
Title string `spiff:"title" gorm:"index:idx_track_title"`
Key string // TODO - unique constraint
Size int64
ETag string
LastModified time.Time
TrackCount int
DiscCount int
REID string `gorm:"index:idx_track_reid"`
RGID string `gorm:"index:idx_track_rgid"`
RID string `gorm:"index:idx_track_rid"` // recording id
MediaTitle string
ReleaseTitle string `spiff:"album"`
TrackArtist string // artist with featured artists
ReleaseDate time.Time
Artwork bool
FrontArtwork bool
BackArtwork bool
OtherArtwork string
GroupArtwork bool
}
func (t *Track) BeforeCreate(tx *g.DB) (err error) {
t.UUID = uuid.NewString()
return
}
func (t Track) releaseKey() string {
return fmt.Sprintf("%s/%s/%d/%d", t.Artist, t.Release, t.TrackCount, t.DiscCount)
}
// Prefer A feat. B instead of just A.
func (t Track) PreferredArtist() string {
if t.TrackArtist != "" && t.TrackArtist != t.Artist {
return t.TrackArtist
}
return t.Artist
}
type Playlist struct {
gorm.Model
User string `gorm:"uniqueIndex:idx_playlist"`
Playlist []byte
}
type Station struct {
gorm.Model
User string `gorm:"uniqueIndex:idx_station" json:"-"`
Name string `gorm:"uniqueIndex:idx_station"`
Creator string
Ref string `json:"-"`
Shared bool `json:"-"`
Type string
Image string
Playlist []byte `json:"-"`
}
type ArtistImage struct {
gorm.Model
Artist string `gorm:"uniqueIndex:idx_artist_img"`
URL string `gorm:"uniqueIndex:idx_artist_img"`
Source string `gorm:"uniqueIndex:idx_artist_img"`
Rank int
}
type ArtistBackground struct {
gorm.Model
Artist string `gorm:"uniqueIndex:idx_artist_bg"`
URL string `gorm:"uniqueIndex:idx_artist_bg"`
Source string `gorm:"uniqueIndex:idx_artist_bg"`
Rank int
}
// type Scrobble struct {
// gorm.Model
// User string
// Artist string
// Release string
// Title string
// Date time.Time
// }