forgor linux allows like \ and ' in filenames

This commit is contained in:
Djairo Hougee 2025-02-06 23:17:38 +01:00
parent 57fa326da6
commit d5017045b7
1 changed files with 5 additions and 1 deletions

View File

@ -44,6 +44,7 @@ class ExportService():
re_re: path substitution (if necessary); real folder structure component.
"""
a = ExportService.get_annotations(db, user_id, re_nav, re_re)
print(f"Fetched {len(a)} annotations from db!")
ExportService.write_annotations(a)
@ -112,6 +113,7 @@ class ImportService():
re_re: path substitution (if necessary); real folder structure component.
"""
a = ImportService.get_annotations(path, re_nav, re_re)
print(f"Read {len(a)} annotations from files!")
ImportService.write_annotations(a, db, user_id)
@ -129,6 +131,7 @@ class ImportService():
realpath = os.path.realpath(path)
annos = {}
print(f"Reading files (this may take a while)...")
for dir,_,files in os.walk(realpath):
for mp3_file in files:
if mp3_file.endswith('.mp3'):
@ -169,7 +172,8 @@ class ImportService():
conn = sqlite3.connect(db)
cursor = conn.cursor()
# step 1: fetch path and item_id for existing annotations WHERE path IN annos.paths
cursor.execute(f"""SELECT path,id FROM media_file WHERE path IN ('{"','".join([ re.sub(re_re, re_nav, k) for k in annos.keys()])}')""")
escaped = "','".join([ re.sub(r'\\', r'\\\\', re.sub("'", "''", re.sub(re_re, re_nav, k))) for k in annos.keys()])
cursor.execute(f"""SELECT path,id FROM media_file WHERE path IN ('{escaped}')""")
# step 2: create list with item_ids
items = []