1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-09-19 19:01:03 +00:00

Added configurable extension whitelist on the scanner

Closes #8
This commit is contained in:
spl0k 2013-11-02 19:52:02 +01:00
parent 78eac108a4
commit 82992047dd
2 changed files with 16 additions and 2 deletions

View File

@ -42,6 +42,8 @@ Available settings are:
I personnaly use SQLite (`sqlite:////var/supysonic/supysonic.db`), but it might not be the brightest idea for large libraries.
* **cache_dir**: path to a cache folder. Mostly used for resized cover art images. Defaults to `<system temp dir>/supysonic`.
* **log_file**: path and base name of a rolling log file.
* **scanner_extensions**: space-separated list of file extensions the scanner is restricted to. If omitted, files will be scanned
regardless of their extension
* Section **lastfm**:
* **api_key**: Last.FM [API key](http://www.last.fm/api/accounts) to enable scrobbling
* **secret**: Last.FM API secret matching the key.

View File

@ -22,14 +22,19 @@ class Scanner:
self.__deleted_albums = 0
self.__deleted_tracks = 0
extensions = config.get('base', 'scanner_extensions')
self.__extensions = map(str.lower, extensions.split()) if extensions else None
def scan(self, folder):
for root, subfolders, files in os.walk(folder.path):
for f in files:
self.__scan_file(os.path.join(root, f), folder)
path = os.path.join(root, f)
if self.__is_valid_path(path):
self.__scan_file(path, folder)
folder.last_scan = int(time.time())
def prune(self, folder):
for track in [ t for t in self.__tracks if t.root_folder.id == folder.id and not os.path.exists(t.path) ]:
for track in [ t for t in self.__tracks if t.root_folder.id == folder.id and not self.__is_valid_path(t.path) ]:
self.__remove_track(track)
for album in [ album for artist in self.__artists for album in artist.albums if len(album.tracks) == 0 ]:
@ -48,6 +53,13 @@ class Scanner:
for f in folder.children:
self.check_cover_art(f)
def __is_valid_path(self, path):
if not os.path.exists(path):
return False
if not self.__extensions:
return True
return os.path.splitext(path)[1][1:].lower() in self.__extensions
def __scan_file(self, path, folder):
tr = filter(lambda t: t.path == path, self.__tracks)
if tr: