mirror of
https://github.com/navidrome/navidrome.git
synced 2025-06-10 20:32:27 +03:00
Using PersistentIDs instead of "Database" IDs
This commit is contained in:
parent
638f328330
commit
0e1618a6ac
@ -38,7 +38,7 @@ func (r *mediaFileRepository) Get(id string) (*domain.MediaFile, error) {
|
|||||||
|
|
||||||
func (r *mediaFileRepository) FindByAlbum(albumId string) (domain.MediaFiles, error) {
|
func (r *mediaFileRepository) FindByAlbum(albumId string) (domain.MediaFiles, error) {
|
||||||
var mfs = make(domain.MediaFiles, 0)
|
var mfs = make(domain.MediaFiles, 0)
|
||||||
err := r.loadChildren("album", albumId, &mfs)
|
err := r.loadChildren("album", albumId, &mfs, domain.QueryOptions{SortBy: "TrackNumber"})
|
||||||
sort.Sort(mfs)
|
sort.Sort(mfs)
|
||||||
return mfs, err
|
return mfs, err
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,10 @@ func (r *playlistRepository) Get(id string) (*domain.Playlist, error) {
|
|||||||
|
|
||||||
func (r *playlistRepository) GetAll(options domain.QueryOptions) (domain.Playlists, error) {
|
func (r *playlistRepository) GetAll(options domain.QueryOptions) (domain.Playlists, error) {
|
||||||
var as = make(domain.Playlists, 0)
|
var as = make(domain.Playlists, 0)
|
||||||
|
if options.SortBy == "" {
|
||||||
|
options.SortBy = "Name"
|
||||||
|
options.Alpha = true
|
||||||
|
}
|
||||||
err := r.loadAll(&as, options)
|
err := r.loadAll(&as, options)
|
||||||
return as, err
|
return as, err
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@ type ItunesScanner struct {
|
|||||||
artists map[string]*domain.Artist
|
artists map[string]*domain.Artist
|
||||||
playlists map[string]*domain.Playlist
|
playlists map[string]*domain.Playlist
|
||||||
pplaylists map[string]plsRelation
|
pplaylists map[string]plsRelation
|
||||||
|
pmediaFiles map[int]*domain.MediaFile
|
||||||
lastModifiedSince time.Time
|
lastModifiedSince time.Time
|
||||||
checksumRepo CheckSumRepository
|
checksumRepo CheckSumRepository
|
||||||
newSums map[string]string
|
newSums map[string]string
|
||||||
@ -61,6 +62,7 @@ func (s *ItunesScanner) ScanLibrary(lastModifiedSince time.Time, path string) (i
|
|||||||
s.artists = make(map[string]*domain.Artist)
|
s.artists = make(map[string]*domain.Artist)
|
||||||
s.playlists = make(map[string]*domain.Playlist)
|
s.playlists = make(map[string]*domain.Playlist)
|
||||||
s.pplaylists = make(map[string]plsRelation)
|
s.pplaylists = make(map[string]plsRelation)
|
||||||
|
s.pmediaFiles = make(map[int]*domain.MediaFile)
|
||||||
s.newSums = make(map[string]string)
|
s.newSums = make(map[string]string)
|
||||||
|
|
||||||
i := 0
|
i := 0
|
||||||
@ -144,14 +146,13 @@ func (s *ItunesScanner) skipPlaylist(p *itl.Playlist, ignFolders bool, ignPatter
|
|||||||
|
|
||||||
func (s *ItunesScanner) collectPlaylists(p *itl.Playlist, fullPath string) {
|
func (s *ItunesScanner) collectPlaylists(p *itl.Playlist, fullPath string) {
|
||||||
pl := &domain.Playlist{}
|
pl := &domain.Playlist{}
|
||||||
pl.Id = strconv.Itoa(p.PlaylistID)
|
pl.Id = p.PlaylistPersistentID
|
||||||
pl.Name = unescape(p.Name)
|
pl.Name = unescape(p.Name)
|
||||||
pl.FullPath = fullPath
|
pl.FullPath = fullPath
|
||||||
pl.Tracks = make([]string, 0, len(p.PlaylistItems))
|
pl.Tracks = make([]string, 0, len(p.PlaylistItems))
|
||||||
for _, item := range p.PlaylistItems {
|
for _, item := range p.PlaylistItems {
|
||||||
id := strconv.Itoa(item.TrackID)
|
if mf, found := s.pmediaFiles[item.TrackID]; found {
|
||||||
if mf, found := s.mediaFiles[id]; found {
|
pl.Tracks = append(pl.Tracks, mf.Id)
|
||||||
pl.Tracks = append(pl.Tracks, id)
|
|
||||||
pl.Duration += mf.Duration
|
pl.Duration += mf.Duration
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -186,7 +187,7 @@ func (s *ItunesScanner) lastChangedDate(t *itl.Track) time.Time {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *ItunesScanner) hasChanged(t *itl.Track) bool {
|
func (s *ItunesScanner) hasChanged(t *itl.Track) bool {
|
||||||
id := strconv.Itoa(t.TrackID)
|
id := t.PersistentID
|
||||||
oldSum, _ := s.checksumRepo.Get(id)
|
oldSum, _ := s.checksumRepo.Get(id)
|
||||||
newSum := s.newSums[id]
|
newSum := s.newSums[id]
|
||||||
return oldSum != newSum
|
return oldSum != newSum
|
||||||
@ -194,7 +195,7 @@ func (s *ItunesScanner) hasChanged(t *itl.Track) bool {
|
|||||||
|
|
||||||
// Calc sum of stats fields (whose changes are not reflected in DataModified)
|
// Calc sum of stats fields (whose changes are not reflected in DataModified)
|
||||||
func (s *ItunesScanner) calcCheckSum(t *itl.Track) string {
|
func (s *ItunesScanner) calcCheckSum(t *itl.Track) string {
|
||||||
id := strconv.Itoa(t.TrackID)
|
id := t.PersistentID
|
||||||
data := fmt.Sprint(t.DateModified, t.PlayCount, t.PlayDate, t.ArtworkCount, t.Loved, t.AlbumLoved,
|
data := fmt.Sprint(t.DateModified, t.PlayCount, t.PlayDate, t.ArtworkCount, t.Loved, t.AlbumLoved,
|
||||||
t.Rating, t.AlbumRating, t.SkipCount, t.SkipDate)
|
t.Rating, t.AlbumRating, t.SkipCount, t.SkipDate)
|
||||||
sum := fmt.Sprintf("%x", md5.Sum([]byte(data)))
|
sum := fmt.Sprintf("%x", md5.Sum([]byte(data)))
|
||||||
@ -204,7 +205,7 @@ func (s *ItunesScanner) calcCheckSum(t *itl.Track) string {
|
|||||||
|
|
||||||
func (s *ItunesScanner) collectMediaFiles(t *itl.Track) *domain.MediaFile {
|
func (s *ItunesScanner) collectMediaFiles(t *itl.Track) *domain.MediaFile {
|
||||||
mf := &domain.MediaFile{}
|
mf := &domain.MediaFile{}
|
||||||
mf.Id = strconv.Itoa(t.TrackID)
|
mf.Id = t.PersistentID
|
||||||
mf.Album = unescape(t.Album)
|
mf.Album = unescape(t.Album)
|
||||||
mf.AlbumId = albumId(t)
|
mf.AlbumId = albumId(t)
|
||||||
mf.ArtistId = artistId(t)
|
mf.ArtistId = artistId(t)
|
||||||
@ -240,6 +241,7 @@ func (s *ItunesScanner) collectMediaFiles(t *itl.Track) *domain.MediaFile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
s.mediaFiles[mf.Id] = mf
|
s.mediaFiles[mf.Id] = mf
|
||||||
|
s.pmediaFiles[t.TrackID] = mf
|
||||||
|
|
||||||
return mf
|
return mf
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user