local: Reuse the mtime we already found in local scan
This commit is contained in:
parent
60aec2dc95
commit
f4c501a08f
@ -73,9 +73,6 @@ class ScanCommand(commands.Command):
|
|||||||
|
|
||||||
library = _get_library(args, config)
|
library = _get_library(args, config)
|
||||||
|
|
||||||
uris_to_update = set()
|
|
||||||
uris_to_remove = set()
|
|
||||||
|
|
||||||
file_mtimes, file_errors = path.find_mtimes(
|
file_mtimes, file_errors = path.find_mtimes(
|
||||||
media_dir, follow=config['local']['scan_follow_symlinks'])
|
media_dir, follow=config['local']['scan_follow_symlinks'])
|
||||||
|
|
||||||
@ -90,14 +87,19 @@ class ScanCommand(commands.Command):
|
|||||||
num_tracks = library.load()
|
num_tracks = library.load()
|
||||||
logger.info('Checking %d tracks from library.', num_tracks)
|
logger.info('Checking %d tracks from library.', num_tracks)
|
||||||
|
|
||||||
|
uris_to_update = set()
|
||||||
|
uris_to_remove = set()
|
||||||
|
uris_in_library = set()
|
||||||
|
|
||||||
for track in library.begin():
|
for track in library.begin():
|
||||||
abspath = translator.local_track_uri_to_path(track.uri, media_dir)
|
abspath = translator.local_track_uri_to_path(track.uri, media_dir)
|
||||||
mtime = file_mtimes.pop(abspath, None)
|
mtime = file_mtimes.get(abspath)
|
||||||
if mtime is None:
|
if mtime is None:
|
||||||
logger.debug('Missing file %s', track.uri)
|
logger.debug('Missing file %s', track.uri)
|
||||||
uris_to_remove.add(track.uri)
|
uris_to_remove.add(track.uri)
|
||||||
elif mtime > track.last_modified:
|
elif mtime > track.last_modified:
|
||||||
uris_to_update.add(track.uri)
|
uris_to_update.add(track.uri)
|
||||||
|
uris_in_library.add(track.uri)
|
||||||
|
|
||||||
logger.info('Removing %d missing tracks.', len(uris_to_remove))
|
logger.info('Removing %d missing tracks.', len(uris_to_remove))
|
||||||
for uri in uris_to_remove:
|
for uri in uris_to_remove:
|
||||||
@ -107,12 +109,11 @@ class ScanCommand(commands.Command):
|
|||||||
relpath = os.path.relpath(abspath, media_dir)
|
relpath = os.path.relpath(abspath, media_dir)
|
||||||
uri = translator.path_to_local_track_uri(relpath)
|
uri = translator.path_to_local_track_uri(relpath)
|
||||||
|
|
||||||
# TODO: move these to a "predicate" check in the finder?
|
|
||||||
if b'/.' in relpath:
|
if b'/.' in relpath:
|
||||||
logger.debug('Skipped %s: Hidden directory/file.', uri)
|
logger.debug('Skipped %s: Hidden directory/file.', uri)
|
||||||
elif relpath.lower().endswith(excluded_file_extensions):
|
elif relpath.lower().endswith(excluded_file_extensions):
|
||||||
logger.debug('Skipped %s: File extension excluded.', uri)
|
logger.debug('Skipped %s: File extension excluded.', uri)
|
||||||
else:
|
elif uri not in uris_in_library:
|
||||||
uris_to_update.add(uri)
|
uris_to_update.add(uri)
|
||||||
|
|
||||||
logger.info(
|
logger.info(
|
||||||
@ -134,8 +135,7 @@ class ScanCommand(commands.Command):
|
|||||||
logger.warning('Failed %s: Track shorter than %dms',
|
logger.warning('Failed %s: Track shorter than %dms',
|
||||||
uri, MIN_DURATION_MS)
|
uri, MIN_DURATION_MS)
|
||||||
else:
|
else:
|
||||||
# TODO: reuse mtime from above...
|
mtime = file_mtimes.get(os.path.join(media_dir, relpath))
|
||||||
mtime = os.path.getmtime(os.path.join(media_dir, relpath))
|
|
||||||
track = utils.convert_tags_to_track(tags).copy(
|
track = utils.convert_tags_to_track(tags).copy(
|
||||||
uri=uri, length=duration, last_modified=mtime)
|
uri=uri, length=duration, last_modified=mtime)
|
||||||
track = translator.add_musicbrainz_coverart_to_track(track)
|
track = translator.add_musicbrainz_coverart_to_track(track)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user