fix zeropadding

This commit is contained in:
iou1name 2025-02-12 12:48:19 -05:00
parent 9ef1cfb8f8
commit 7adba24fb1
2 changed files with 27 additions and 1 deletions

View File

@ -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)

26
fix_zpad.py Normal file
View File

@ -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())