mirror of
https://github.com/spl0k/supysonic.git
synced 2024-12-22 17:06:17 +00:00
Scanner: added a callback interface to report progress
This commit is contained in:
parent
faacf40008
commit
6f506243d7
@ -86,12 +86,12 @@ class FolderManager:
|
||||
return FolderManager.delete(folder.id)
|
||||
|
||||
@staticmethod
|
||||
def scan(uid, scanner):
|
||||
def scan(uid, scanner, progress_callback = None):
|
||||
status, folder = FolderManager.get(uid)
|
||||
if status != FolderManager.SUCCESS:
|
||||
return status
|
||||
|
||||
scanner.scan(folder)
|
||||
scanner.scan(folder, progress_callback)
|
||||
scanner.prune(folder)
|
||||
scanner.check_cover_art(folder)
|
||||
return FolderManager.SUCCESS
|
||||
|
15
scanner.py
15
scanner.py
@ -25,12 +25,17 @@ class Scanner:
|
||||
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:
|
||||
path = os.path.join(root, f)
|
||||
if self.__is_valid_path(path):
|
||||
def scan(self, folder, progress_callback = None):
|
||||
files = [ os.path.join(root, f) for root, _, fs in os.walk(folder.path) for f in fs if self.__is_valid_path(os.path.join(root, f)) ]
|
||||
total = len(files)
|
||||
current = 0
|
||||
|
||||
for path in files:
|
||||
self.__scan_file(path, folder)
|
||||
current += 1
|
||||
if progress_callback:
|
||||
progress_callback(current, total)
|
||||
|
||||
folder.last_scan = int(time.time())
|
||||
|
||||
def prune(self, folder):
|
||||
|
Loading…
Reference in New Issue
Block a user