update build_library to use relative fpaths
This commit is contained in:
parent
f5ac91b942
commit
886b6e017b
@ -20,10 +20,10 @@ def read_track(filepath):
|
|||||||
"""
|
"""
|
||||||
t = tinytag.TinyTag.get(filepath)
|
t = tinytag.TinyTag.get(filepath)
|
||||||
|
|
||||||
filepath = os.path.relpath(filepath, config.music_dir)
|
fpath_mod = os.path.relpath(filepath, config.music_dir)
|
||||||
|
|
||||||
d = {
|
d = {
|
||||||
'filepath': filepath,
|
'filepath': fpath_mod,
|
||||||
'artist': t.artist,
|
'artist': t.artist,
|
||||||
'albumartist': t.albumartist,
|
'albumartist': t.albumartist,
|
||||||
'album': t.album,
|
'album': t.album,
|
||||||
@ -41,7 +41,7 @@ def read_track(filepath):
|
|||||||
|
|
||||||
async def build_library(root_dir):
|
async def build_library(root_dir):
|
||||||
"""Walks the directory and builds a library from tracks discovered."""
|
"""Walks the directory and builds a library from tracks discovered."""
|
||||||
print("Building library")
|
print("Scanning library")
|
||||||
|
|
||||||
db_pool = await asyncpg.create_pool(**config.db)
|
db_pool = await asyncpg.create_pool(**config.db)
|
||||||
async with db_pool.acquire() as conn:
|
async with db_pool.acquire() as conn:
|
||||||
@ -65,13 +65,15 @@ async def build_library(root_dir):
|
|||||||
def worker(args):
|
def worker(args):
|
||||||
"""Worker for multi-processing tracks."""
|
"""Worker for multi-processing tracks."""
|
||||||
filepath, last_modified = args
|
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:
|
||||||
if track_prev['last_modified'] >= last_modified:
|
if track_prev['last_modified'] >= last_modified:
|
||||||
return
|
return
|
||||||
data = read_track(filepath)
|
data = read_track(filepath)
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
print("Processing...")
|
||||||
with multiprocessing.Pool() as pool:
|
with multiprocessing.Pool() as pool:
|
||||||
mapping = pool.imap(worker, filepaths)
|
mapping = pool.imap(worker, filepaths)
|
||||||
tracks = []
|
tracks = []
|
||||||
|
Loading…
x
Reference in New Issue
Block a user