More playlists
This commit is contained in:
parent
0d8c6b58db
commit
4bb4fc0cb8
|
@ -95,8 +95,6 @@ type Playlist struct {
|
||||||
<xs:sequence>
|
<xs:sequence>
|
||||||
<xs:element name="allowedUser" type="xs:string" minOccurs="0" maxOccurs="unbounded"/> <!--Added in 1.8.0-->
|
<xs:element name="allowedUser" type="xs:string" minOccurs="0" maxOccurs="unbounded"/> <!--Added in 1.8.0-->
|
||||||
</xs:sequence>
|
</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="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="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-->
|
<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
|
MediaFiles() map[string]*domain.MediaFile
|
||||||
Albums() map[string]*domain.Album
|
Albums() map[string]*domain.Album
|
||||||
Artists() map[string]*domain.Artist
|
Artists() map[string]*domain.Artist
|
||||||
|
Playlists() map[string]*domain.Playlist
|
||||||
}
|
}
|
||||||
|
|
||||||
type tempIndex map[string]domain.ArtistInfo
|
type tempIndex map[string]domain.ArtistInfo
|
||||||
|
@ -32,6 +33,7 @@ func StartImport() {
|
||||||
albumRepo: persistence.NewAlbumRepository(),
|
albumRepo: persistence.NewAlbumRepository(),
|
||||||
artistRepo: persistence.NewArtistRepository(),
|
artistRepo: persistence.NewArtistRepository(),
|
||||||
idxRepo: persistence.NewArtistIndexRepository(),
|
idxRepo: persistence.NewArtistIndexRepository(),
|
||||||
|
plsRepo: persistence.NewPlaylistRepository(),
|
||||||
propertyRepo: persistence.NewPropertyRepository(),
|
propertyRepo: persistence.NewPropertyRepository(),
|
||||||
}
|
}
|
||||||
i.Run()
|
i.Run()
|
||||||
|
@ -46,6 +48,7 @@ type Importer struct {
|
||||||
albumRepo domain.AlbumRepository
|
albumRepo domain.AlbumRepository
|
||||||
artistRepo domain.ArtistRepository
|
artistRepo domain.ArtistRepository
|
||||||
idxRepo domain.ArtistIndexRepository
|
idxRepo domain.ArtistIndexRepository
|
||||||
|
plsRepo domain.PlaylistRepository
|
||||||
propertyRepo engine.PropertyRepository
|
propertyRepo engine.PropertyRepository
|
||||||
lastScan time.Time
|
lastScan time.Time
|
||||||
}
|
}
|
||||||
|
@ -59,7 +62,8 @@ func (i *Importer) Run() {
|
||||||
beego.Debug("Found", total, "tracks,",
|
beego.Debug("Found", total, "tracks,",
|
||||||
len(i.scanner.MediaFiles()), "songs,",
|
len(i.scanner.MediaFiles()), "songs,",
|
||||||
len(i.scanner.Albums()), "albums,",
|
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 {
|
if err := i.importLibrary(); err != nil {
|
||||||
beego.Error("Error persisting data:", err)
|
beego.Error("Error persisting data:", err)
|
||||||
|
@ -83,6 +87,7 @@ func (i *Importer) importLibrary() (err error) {
|
||||||
mfs := make(domain.MediaFiles, len(i.scanner.MediaFiles()))
|
mfs := make(domain.MediaFiles, len(i.scanner.MediaFiles()))
|
||||||
als := make(domain.Albums, len(i.scanner.Albums()))
|
als := make(domain.Albums, len(i.scanner.Albums()))
|
||||||
ars := make(domain.Artists, len(i.scanner.Artists()))
|
ars := make(domain.Artists, len(i.scanner.Artists()))
|
||||||
|
pls := make(domain.Playlists, len(i.scanner.Playlists()))
|
||||||
|
|
||||||
beego.Debug("Saving updated data")
|
beego.Debug("Saving updated data")
|
||||||
j := 0
|
j := 0
|
||||||
|
@ -119,6 +124,15 @@ func (i *Importer) importLibrary() (err error) {
|
||||||
i.collectIndex(indexGroups, ar, artistIndex)
|
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 {
|
if err = i.saveIndex(artistIndex); err != nil {
|
||||||
beego.Error(err)
|
beego.Error(err)
|
||||||
}
|
}
|
||||||
|
@ -133,6 +147,9 @@ func (i *Importer) importLibrary() (err error) {
|
||||||
if err := i.artistRepo.PurgeInactive(&ars); err != nil {
|
if err := i.artistRepo.PurgeInactive(&ars); err != nil {
|
||||||
beego.Error(err)
|
beego.Error(err)
|
||||||
}
|
}
|
||||||
|
if err := i.plsRepo.PurgeInactive(&pls); err != nil {
|
||||||
|
beego.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
c, _ := i.artistRepo.CountAll()
|
c, _ := i.artistRepo.CountAll()
|
||||||
beego.Info("Total Artists in database:", c)
|
beego.Info("Total Artists in database:", c)
|
||||||
|
@ -140,6 +157,8 @@ func (i *Importer) importLibrary() (err error) {
|
||||||
beego.Info("Total Albums in database:", c)
|
beego.Info("Total Albums in database:", c)
|
||||||
c, _ = i.mfRepo.CountAll()
|
c, _ = i.mfRepo.CountAll()
|
||||||
beego.Info("Total MediaFiles in database:", c)
|
beego.Info("Total MediaFiles in database:", c)
|
||||||
|
c, _ = i.plsRepo.CountAll()
|
||||||
|
beego.Info("Total Playlists in database:", c)
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
millis := time.Now().UnixNano() / int64(time.Millisecond)
|
millis := time.Now().UnixNano() / int64(time.Millisecond)
|
||||||
|
|
|
@ -22,6 +22,7 @@ type ItunesScanner struct {
|
||||||
mediaFiles map[string]*domain.MediaFile
|
mediaFiles map[string]*domain.MediaFile
|
||||||
albums map[string]*domain.Album
|
albums map[string]*domain.Album
|
||||||
artists map[string]*domain.Artist
|
artists map[string]*domain.Artist
|
||||||
|
playlists map[string]*domain.Playlist
|
||||||
lastModifiedSince time.Time
|
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.mediaFiles = make(map[string]*domain.MediaFile)
|
||||||
s.albums = make(map[string]*domain.Album)
|
s.albums = make(map[string]*domain.Album)
|
||||||
s.artists = make(map[string]*domain.Artist)
|
s.artists = make(map[string]*domain.Artist)
|
||||||
|
s.playlists = make(map[string]*domain.Playlist)
|
||||||
|
|
||||||
i := 0
|
i := 0
|
||||||
for _, t := range l.Tracks {
|
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")
|
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
|
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 {
|
func (s *ItunesScanner) Artists() map[string]*domain.Artist {
|
||||||
return s.artists
|
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 {
|
func (s *ItunesScanner) collectMediaFiles(t *itl.Track) *domain.MediaFile {
|
||||||
mf := &domain.MediaFile{}
|
mf := &domain.MediaFile{}
|
||||||
|
|
Loading…
Reference in New Issue