change filepath to relative
This commit is contained in:
parent
352f817dd5
commit
f5ac91b942
@ -20,6 +20,8 @@ def read_track(filepath):
|
|||||||
"""
|
"""
|
||||||
t = tinytag.TinyTag.get(filepath)
|
t = tinytag.TinyTag.get(filepath)
|
||||||
|
|
||||||
|
filepath = os.path.relpath(filepath, config.music_dir)
|
||||||
|
|
||||||
d = {
|
d = {
|
||||||
'filepath': filepath,
|
'filepath': filepath,
|
||||||
'artist': t.artist,
|
'artist': t.artist,
|
||||||
|
@ -74,7 +74,6 @@ async def get_tracks(request, albumartist, album, date):
|
|||||||
|
|
||||||
def convert_filepath(path):
|
def convert_filepath(path):
|
||||||
"""Convert a filepath to a URL."""
|
"""Convert a filepath to a URL."""
|
||||||
path = os.path.relpath(path, config.music_dir)
|
|
||||||
path = config.server_homepage + '/library/' + path
|
path = config.server_homepage + '/library/' + path
|
||||||
#path = parse.quote(path)
|
#path = parse.quote(path)
|
||||||
return path
|
return path
|
||||||
|
34
fix_fpath.py
Normal file
34
fix_fpath.py
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""
|
||||||
|
Makes all existing filepaths in the database relative to `config.music_dir`.
|
||||||
|
"""
|
||||||
|
import os
|
||||||
|
import asyncio
|
||||||
|
|
||||||
|
import asyncpg
|
||||||
|
|
||||||
|
import config
|
||||||
|
|
||||||
|
|
||||||
|
async def fix_fpaths():
|
||||||
|
"""
|
||||||
|
Makes all existing filepaths in the database relative to
|
||||||
|
`config.music_dir`.
|
||||||
|
"""
|
||||||
|
db_pool = await asyncpg.create_pool(**config.db)
|
||||||
|
async with db_pool.acquire() as conn:
|
||||||
|
tracks = await conn.fetch("SELECT filepath FROM track")
|
||||||
|
|
||||||
|
data = []
|
||||||
|
for track in tracks:
|
||||||
|
fpath = track['filepath']
|
||||||
|
fpath = os.path.relpath(fpath, config.music_dir)
|
||||||
|
entry = (fpath, track['filepath'])
|
||||||
|
data.append(entry)
|
||||||
|
|
||||||
|
stm = await conn.prepare("UPDATE track SET filepath = $1 WHERE filepath = $2")
|
||||||
|
await stm.executemany(data)
|
||||||
|
print("Done.")
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
asyncio.run(fix_fpaths())
|
Loading…
x
Reference in New Issue
Block a user