update build_library to use relative fpaths

This commit is contained in:
iou1name 2025-02-06 16:24:35 -05:00
parent f5ac91b942
commit 886b6e017b

View File

@ -20,10 +20,10 @@ def read_track(filepath):
"""
t = tinytag.TinyTag.get(filepath)
filepath = os.path.relpath(filepath, config.music_dir)
fpath_mod = os.path.relpath(filepath, config.music_dir)
d = {
'filepath': filepath,
'filepath': fpath_mod,
'artist': t.artist,
'albumartist': t.albumartist,
'album': t.album,
@ -41,7 +41,7 @@ def read_track(filepath):
async def build_library(root_dir):
"""Walks the directory and builds a library from tracks discovered."""
print("Building library")
print("Scanning library")
db_pool = await asyncpg.create_pool(**config.db)
async with db_pool.acquire() as conn:
@ -65,13 +65,15 @@ async def build_library(root_dir):
def worker(args):
"""Worker for multi-processing tracks."""
filepath, last_modified = args
track_prev = tracks_prev.get(filepath)
fpath_mod = os.path.relpath(filepath, config.music_dir)
track_prev = tracks_prev.get(fpath_mod)
if track_prev:
if track_prev['last_modified'] >= last_modified:
return
data = read_track(filepath)
return data
print("Processing...")
with multiprocessing.Pool() as pool:
mapping = pool.imap(worker, filepaths)
tracks = []