diff --git a/build_library.py b/build_library.py index 0949ccf..5029e25 100644 --- a/build_library.py +++ b/build_library.py @@ -30,7 +30,7 @@ def read_track(filepath): 'title': t.title, 'date': t.year, 'discnumber': str(t.disc), - 'tracknumber': str(t.track), + 'tracknumber': str(t.track).zfill(2), 'genre': t.genre, 'duration': t.duration, 'last_modified': os.path.getmtime(filepath) diff --git a/fix_zpad.py b/fix_zpad.py new file mode 100644 index 0000000..ccd6f19 --- /dev/null +++ b/fix_zpad.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 +""" +TinyTag autocasts the tracknumber and discnumber tags to ints, which I fixed +by re-casting them to strs. I forgot to include the zeropadding when I did +that. This script fixes that in the database. +""" +import asyncio + +import asyncpg + +import config + + +async def fix_zpad(): + db_pool = await asyncpg.create_pool(**config.db) + async with db_pool.acquire() as conn: + tracks = await conn.fetch("SELECT filepath, tracknumber FROM track") + + data = [(t['filepath'], t['tracknumber'].zfill(2)) for t in tracks] + + stmt = await conn.prepare("UPDATE track SET tracknumber = $2 WHERE filepath = $1") + await stmt.executemany(data) + print("Done.") + +if __name__ == '__main__': + asyncio.run(fix_zpad())