mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-15 11:40:36 +03:00
More playlists
This commit is contained in:
parent
0d8c6b58db
commit
4bb4fc0cb8
@ -95,8 +95,6 @@ type Playlist struct {
|
||||
<xs:sequence>
|
||||
<xs:element name="allowedUser" type="xs:string" minOccurs="0" maxOccurs="unbounded"/> <!--Added in 1.8.0-->
|
||||
</xs:sequence>
|
||||
<xs:attribute name="id" type="xs:string" use="required"/>
|
||||
<xs:attribute name="name" type="xs:string" use="required"/>
|
||||
<xs:attribute name="comment" type="xs:string" use="optional"/> <!--Added in 1.8.0-->
|
||||
<xs:attribute name="owner" type="xs:string" use="optional"/> <!--Added in 1.8.0-->
|
||||
<xs:attribute name="public" type="xs:boolean" use="optional"/> <!--Added in 1.8.0-->
|
||||
|
@ -19,6 +19,7 @@ type Scanner interface {
|
||||
MediaFiles() map[string]*domain.MediaFile
|
||||
Albums() map[string]*domain.Album
|
||||
Artists() map[string]*domain.Artist
|
||||
Playlists() map[string]*domain.Playlist
|
||||
}
|
||||
|
||||
type tempIndex map[string]domain.ArtistInfo
|
||||
@ -32,6 +33,7 @@ func StartImport() {
|
||||
albumRepo: persistence.NewAlbumRepository(),
|
||||
artistRepo: persistence.NewArtistRepository(),
|
||||
idxRepo: persistence.NewArtistIndexRepository(),
|
||||
plsRepo: persistence.NewPlaylistRepository(),
|
||||
propertyRepo: persistence.NewPropertyRepository(),
|
||||
}
|
||||
i.Run()
|
||||
@ -46,6 +48,7 @@ type Importer struct {
|
||||
albumRepo domain.AlbumRepository
|
||||
artistRepo domain.ArtistRepository
|
||||
idxRepo domain.ArtistIndexRepository
|
||||
plsRepo domain.PlaylistRepository
|
||||
propertyRepo engine.PropertyRepository
|
||||
lastScan time.Time
|
||||
}
|
||||
@ -59,7 +62,8 @@ func (i *Importer) Run() {
|
||||
beego.Debug("Found", total, "tracks,",
|
||||
len(i.scanner.MediaFiles()), "songs,",
|
||||
len(i.scanner.Albums()), "albums,",
|
||||
len(i.scanner.Artists()), "artists")
|
||||
len(i.scanner.Artists()), "artists",
|
||||
len(i.scanner.Playlists()), "playlists")
|
||||
}
|
||||
if err := i.importLibrary(); err != nil {
|
||||
beego.Error("Error persisting data:", err)
|
||||
@ -83,6 +87,7 @@ func (i *Importer) importLibrary() (err error) {
|
||||
mfs := make(domain.MediaFiles, len(i.scanner.MediaFiles()))
|
||||
als := make(domain.Albums, len(i.scanner.Albums()))
|
||||
ars := make(domain.Artists, len(i.scanner.Artists()))
|
||||
pls := make(domain.Playlists, len(i.scanner.Playlists()))
|
||||
|
||||
beego.Debug("Saving updated data")
|
||||
j := 0
|
||||
@ -119,6 +124,15 @@ func (i *Importer) importLibrary() (err error) {
|
||||
i.collectIndex(indexGroups, ar, artistIndex)
|
||||
}
|
||||
|
||||
j = 0
|
||||
for _, pl := range i.scanner.Playlists() {
|
||||
pls[j] = *pl
|
||||
j++
|
||||
if err := i.plsRepo.Put(pl); err != nil {
|
||||
beego.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
if err = i.saveIndex(artistIndex); err != nil {
|
||||
beego.Error(err)
|
||||
}
|
||||
@ -133,6 +147,9 @@ func (i *Importer) importLibrary() (err error) {
|
||||
if err := i.artistRepo.PurgeInactive(&ars); err != nil {
|
||||
beego.Error(err)
|
||||
}
|
||||
if err := i.plsRepo.PurgeInactive(&pls); err != nil {
|
||||
beego.Error(err)
|
||||
}
|
||||
|
||||
c, _ := i.artistRepo.CountAll()
|
||||
beego.Info("Total Artists in database:", c)
|
||||
@ -140,6 +157,8 @@ func (i *Importer) importLibrary() (err error) {
|
||||
beego.Info("Total Albums in database:", c)
|
||||
c, _ = i.mfRepo.CountAll()
|
||||
beego.Info("Total MediaFiles in database:", c)
|
||||
c, _ = i.plsRepo.CountAll()
|
||||
beego.Info("Total Playlists in database:", c)
|
||||
|
||||
if err == nil {
|
||||
millis := time.Now().UnixNano() / int64(time.Millisecond)
|
||||
|
@ -22,6 +22,7 @@ type ItunesScanner struct {
|
||||
mediaFiles map[string]*domain.MediaFile
|
||||
albums map[string]*domain.Album
|
||||
artists map[string]*domain.Artist
|
||||
playlists map[string]*domain.Playlist
|
||||
lastModifiedSince time.Time
|
||||
}
|
||||
|
||||
@ -39,6 +40,7 @@ func (s *ItunesScanner) ScanLibrary(lastModifiedSince time.Time, path string) (i
|
||||
s.mediaFiles = make(map[string]*domain.MediaFile)
|
||||
s.albums = make(map[string]*domain.Album)
|
||||
s.artists = make(map[string]*domain.Artist)
|
||||
s.playlists = make(map[string]*domain.Playlist)
|
||||
|
||||
i := 0
|
||||
for _, t := range l.Tracks {
|
||||
@ -52,6 +54,12 @@ func (s *ItunesScanner) ScanLibrary(lastModifiedSince time.Time, path string) (i
|
||||
beego.Debug("Processed", i, "tracks.", len(s.artists), "artists,", len(s.albums), "albums", len(s.mediaFiles), "songs")
|
||||
}
|
||||
}
|
||||
|
||||
for _, p := range l.Playlists {
|
||||
s.collectPlaylists(&p)
|
||||
}
|
||||
beego.Debug("Processed", len(l.Playlists), "playlists.")
|
||||
|
||||
return len(l.Tracks), nil
|
||||
}
|
||||
|
||||
@ -64,6 +72,28 @@ func (s *ItunesScanner) Albums() map[string]*domain.Album {
|
||||
func (s *ItunesScanner) Artists() map[string]*domain.Artist {
|
||||
return s.artists
|
||||
}
|
||||
func (s *ItunesScanner) Playlists() map[string]*domain.Playlist {
|
||||
return s.playlists
|
||||
}
|
||||
|
||||
func (s *ItunesScanner) collectPlaylists(p *itl.Playlist) {
|
||||
if p.Master || p.Music {
|
||||
return
|
||||
}
|
||||
pl := &domain.Playlist{}
|
||||
pl.Id = strconv.Itoa(p.PlaylistID)
|
||||
pl.Name = p.Name
|
||||
pl.Tracks = make([]string, 0, len(p.PlaylistItems))
|
||||
for _, item := range p.PlaylistItems {
|
||||
id := strconv.Itoa(item.TrackID)
|
||||
if _, found := s.mediaFiles[id]; found {
|
||||
pl.Tracks = append(pl.Tracks, id)
|
||||
}
|
||||
}
|
||||
if len(pl.Tracks) > 0 {
|
||||
s.playlists[pl.Id] = pl
|
||||
}
|
||||
}
|
||||
|
||||
func (s *ItunesScanner) collectMediaFiles(t *itl.Track) *domain.MediaFile {
|
||||
mf := &domain.MediaFile{}
|
||||
|
Loading…
x
Reference in New Issue
Block a user