fix zeropadding
This commit is contained in:
parent
9ef1cfb8f8
commit
7adba24fb1
@ -30,7 +30,7 @@ def read_track(filepath):
|
|||||||
'title': t.title,
|
'title': t.title,
|
||||||
'date': t.year,
|
'date': t.year,
|
||||||
'discnumber': str(t.disc),
|
'discnumber': str(t.disc),
|
||||||
'tracknumber': str(t.track),
|
'tracknumber': str(t.track).zfill(2),
|
||||||
'genre': t.genre,
|
'genre': t.genre,
|
||||||
'duration': t.duration,
|
'duration': t.duration,
|
||||||
'last_modified': os.path.getmtime(filepath)
|
'last_modified': os.path.getmtime(filepath)
|
||||||
|
26
fix_zpad.py
Normal file
26
fix_zpad.py
Normal 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())
|
Loading…
x
Reference in New Issue
Block a user