Add option to disable .m3u auto-import

This commit is contained in:
Deluan 2020-08-02 23:17:13 -04:00
parent 696a0feb31
commit 28d1428c90
3 changed files with 18 additions and 10 deletions

View File

@ -83,6 +83,7 @@ func init() {
rootCmd.Flags().Bool("enabletranscodingconfig", viper.GetBool("enabletranscodingconfig"), "enables transcoding configuration in the UI") rootCmd.Flags().Bool("enabletranscodingconfig", viper.GetBool("enabletranscodingconfig"), "enables transcoding configuration in the UI")
rootCmd.Flags().String("transcodingcachesize", viper.GetString("transcodingcachesize"), "size of transcoding cache") rootCmd.Flags().String("transcodingcachesize", viper.GetString("transcodingcachesize"), "size of transcoding cache")
rootCmd.Flags().String("imagecachesize", viper.GetString("imagecachesize"), "size of image (art work) cache. set to 0 to disable cache") rootCmd.Flags().String("imagecachesize", viper.GetString("imagecachesize"), "size of image (art work) cache. set to 0 to disable cache")
rootCmd.Flags().Bool("autoimportplaylists", viper.GetBool("autoimportplaylists"), "enable/disable .m3u playlist auto-import`")
_ = viper.BindPFlag("address", rootCmd.Flags().Lookup("address")) _ = viper.BindPFlag("address", rootCmd.Flags().Lookup("address"))
_ = viper.BindPFlag("port", rootCmd.Flags().Lookup("port")) _ = viper.BindPFlag("port", rootCmd.Flags().Lookup("port"))

View File

@ -26,6 +26,7 @@ type configOptions struct {
EnableTranscodingConfig bool EnableTranscodingConfig bool
TranscodingCacheSize string TranscodingCacheSize string
ImageCacheSize string ImageCacheSize string
AutoImportPlaylists bool
IgnoredArticles string IgnoredArticles string
IndexGroups string IndexGroups string
@ -83,6 +84,7 @@ func init() {
viper.SetDefault("enabletranscodingconfig", false) viper.SetDefault("enabletranscodingconfig", false)
viper.SetDefault("transcodingcachesize", "100MB") viper.SetDefault("transcodingcachesize", "100MB")
viper.SetDefault("imagecachesize", "100MB") viper.SetDefault("imagecachesize", "100MB")
viper.SetDefault("autoimportplaylists", true)
// Config options only valid for file/env configuration // Config options only valid for file/env configuration
viper.SetDefault("ignoredarticles", "The El La Los Las Le Les Os As O A") viper.SetDefault("ignoredarticles", "The El La Los Las Le Les Os As O A")

View File

@ -8,6 +8,7 @@ import (
"strings" "strings"
"time" "time"
"github.com/deluan/navidrome/conf"
"github.com/deluan/navidrome/log" "github.com/deluan/navidrome/log"
"github.com/deluan/navidrome/model" "github.com/deluan/navidrome/model"
"github.com/deluan/navidrome/model/request" "github.com/deluan/navidrome/model/request"
@ -104,19 +105,23 @@ func (s *TagScanner) Scan(ctx context.Context, lastModifiedSince time.Time) erro
} }
} }
// Now that all mediafiles are imported/updated, search for and import playlists
u, _ := request.UserFrom(ctx)
plsCount := 0 plsCount := 0
for _, dir := range changedDirs { if conf.Server.AutoImportPlaylists {
info := allFSDirs[dir] // Now that all mediafiles are imported/updated, search for and import playlists
if info.hasPlaylist { u, _ := request.UserFrom(ctx)
if !u.IsAdmin { for _, dir := range changedDirs {
log.Warn("Playlists will not be imported, as there are no admin users yet, "+ info := allFSDirs[dir]
"Please create an admin user first, and then update the playlists for them to be imported", "dir", dir) if info.hasPlaylist {
} else { if !u.IsAdmin {
plsCount = s.plsSync.processPlaylists(ctx, dir) log.Warn("Playlists will not be imported, as there are no admin users yet, "+
"Please create an admin user first, and then update the playlists for them to be imported", "dir", dir)
} else {
plsCount = s.plsSync.processPlaylists(ctx, dir)
}
} }
} }
} else {
log.Debug("Playlist auto-import is disabled")
} }
err = s.ds.GC(log.NewContext(ctx)) err = s.ds.GC(log.NewContext(ctx))