Options to ignore patterns in playlists full path
This commit is contained in:
+2
-1
@@ -14,7 +14,8 @@ user=deluan
|
|||||||
password=wordpass
|
password=wordpass
|
||||||
dbPath=./devDb
|
dbPath=./devDb
|
||||||
downsampleCommand=ffmpeg -i %s -map 0:0 -b:a %bk -v 0 -f mp3 -
|
downsampleCommand=ffmpeg -i %s -map 0:0 -b:a %bk -v 0 -f mp3 -
|
||||||
ignorePlsFolders = true
|
plsIgnoreFolders = true
|
||||||
|
plsIgnoredPatterns = ^iCloud;^CDs para;^Skipped;^Christian
|
||||||
|
|
||||||
[dev]
|
[dev]
|
||||||
disableValidation = true
|
disableValidation = true
|
||||||
|
|||||||
+4
-3
@@ -1,9 +1,10 @@
|
|||||||
package domain
|
package domain
|
||||||
|
|
||||||
type Playlist struct {
|
type Playlist struct {
|
||||||
Id string
|
Id string
|
||||||
Name string
|
Name string
|
||||||
Tracks []string
|
FullPath string
|
||||||
|
Tracks []string
|
||||||
}
|
}
|
||||||
|
|
||||||
type PlaylistRepository interface {
|
type PlaylistRepository interface {
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ import (
|
|||||||
|
|
||||||
"html"
|
"html"
|
||||||
|
|
||||||
|
"regexp"
|
||||||
|
|
||||||
"github.com/astaxie/beego"
|
"github.com/astaxie/beego"
|
||||||
"github.com/deluan/gosonic/domain"
|
"github.com/deluan/gosonic/domain"
|
||||||
"github.com/deluan/itl"
|
"github.com/deluan/itl"
|
||||||
@@ -23,9 +25,16 @@ type ItunesScanner struct {
|
|||||||
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
|
playlists map[string]*domain.Playlist
|
||||||
|
pplaylists map[string]plsRelation
|
||||||
lastModifiedSince time.Time
|
lastModifiedSince time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type plsRelation struct {
|
||||||
|
pID string
|
||||||
|
parentPID string
|
||||||
|
name string
|
||||||
|
}
|
||||||
|
|
||||||
func (s *ItunesScanner) ScanLibrary(lastModifiedSince time.Time, path string) (int, error) {
|
func (s *ItunesScanner) ScanLibrary(lastModifiedSince time.Time, path string) (int, error) {
|
||||||
beego.Info("Starting iTunes import from:", path)
|
beego.Info("Starting iTunes import from:", path)
|
||||||
beego.Info("Checking for updates since", lastModifiedSince.String())
|
beego.Info("Checking for updates since", lastModifiedSince.String())
|
||||||
@@ -41,6 +50,7 @@ func (s *ItunesScanner) ScanLibrary(lastModifiedSince time.Time, path string) (i
|
|||||||
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)
|
s.playlists = make(map[string]*domain.Playlist)
|
||||||
|
s.pplaylists = make(map[string]plsRelation)
|
||||||
|
|
||||||
i := 0
|
i := 0
|
||||||
for _, t := range l.Tracks {
|
for _, t := range l.Tracks {
|
||||||
@@ -55,13 +65,18 @@ func (s *ItunesScanner) ScanLibrary(lastModifiedSince time.Time, path string) (i
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ignFolders, _ := beego.AppConfig.Bool("ignorePlsFolders")
|
ignFolders, _ := beego.AppConfig.Bool("plsIgnoreFolders")
|
||||||
|
ignPatterns := beego.AppConfig.Strings("plsIgnoredPatterns")
|
||||||
for _, p := range l.Playlists {
|
for _, p := range l.Playlists {
|
||||||
if p.Master || p.Music || (ignFolders && p.Folder) {
|
rel := plsRelation{pID: p.PlaylistPersistentID, parentPID: p.ParentPersistentID, name: unescape(p.Name)}
|
||||||
|
s.pplaylists[p.PlaylistPersistentID] = rel
|
||||||
|
fullPath := s.fullPath(p.PlaylistPersistentID)
|
||||||
|
|
||||||
|
if s.skipPlaylist(&p, ignFolders, ignPatterns, fullPath) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
s.collectPlaylists(&p)
|
s.collectPlaylists(&p, fullPath)
|
||||||
}
|
}
|
||||||
beego.Debug("Processed", len(l.Playlists), "playlists.")
|
beego.Debug("Processed", len(l.Playlists), "playlists.")
|
||||||
|
|
||||||
@@ -81,10 +96,26 @@ func (s *ItunesScanner) Playlists() map[string]*domain.Playlist {
|
|||||||
return s.playlists
|
return s.playlists
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ItunesScanner) collectPlaylists(p *itl.Playlist) {
|
func (s *ItunesScanner) skipPlaylist(p *itl.Playlist, ignFolders bool, ignPatterns []string, fullPath string) bool {
|
||||||
|
if p.Master || p.Music || (ignFolders && p.Folder) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, p := range ignPatterns {
|
||||||
|
m, _ := regexp.MatchString(p, fullPath)
|
||||||
|
if m {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ItunesScanner) collectPlaylists(p *itl.Playlist, fullPath string) {
|
||||||
pl := &domain.Playlist{}
|
pl := &domain.Playlist{}
|
||||||
pl.Id = strconv.Itoa(p.PlaylistID)
|
pl.Id = strconv.Itoa(p.PlaylistID)
|
||||||
pl.Name = p.Name
|
pl.Name = unescape(p.Name)
|
||||||
|
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)
|
id := strconv.Itoa(item.TrackID)
|
||||||
@@ -97,6 +128,17 @@ func (s *ItunesScanner) collectPlaylists(p *itl.Playlist) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *ItunesScanner) fullPath(pID string) string {
|
||||||
|
rel, found := s.pplaylists[pID]
|
||||||
|
if !found {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
if rel.parentPID == "" {
|
||||||
|
return rel.name
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("%s > %s", s.fullPath(rel.parentPID), rel.name)
|
||||||
|
}
|
||||||
|
|
||||||
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 = strconv.Itoa(t.TrackID)
|
||||||
|
|||||||
Reference in New Issue
Block a user