WIP addition of interactive shell

This commit is contained in:
evilchili
2022-11-27 18:42:46 -08:00
parent 7ca1f69100
commit 10122063f3
7 changed files with 202 additions and 6 deletions
+1
View File
@@ -18,3 +18,4 @@ def windowed_query(query, column, window_size):
last_id = chunk[-1][-1]
for row in chunk:
yield row
+19 -4
View File
@@ -1,7 +1,10 @@
import asyncio
import logging
import os
import sys
import music_tag
from pathlib import Path
from typing import Callable, Union, Iterable
from sqlalchemy import func
@@ -39,12 +42,24 @@ class MediaScanner:
return self.root.rglob(pattern) # pragma: no cover
def import_tracks(self, sources: Iterable) -> None:
for path in sources:
relpath = str(path.relative_to(self.root))
stmt = groove.db.track.insert({'relpath': relpath}).prefix_with('OR IGNORE')
self.db.execute(stmt)
async def _do_import():
logging.debug("Scanning filesystem (this may take a minute)...")
for path in sources:
asyncio.create_task(self._import_one_track(path))
asyncio.run(_do_import())
self.db.commit()
async def _import_one_track(self, path):
tags = music_tag.load_file(path)
relpath = str(path.relative_to(self.root))
stmt = groove.db.track.insert({
'relpath': relpath,
'artist': str(tags.resolve('album_artist')),
'title': str(tags['title']),
}).prefix_with('OR IGNORE')
logging.debug(f"{tags['artist']} - {tags['title']}")
self.db.execute(stmt)
def scan(self) -> int:
"""
Walk the media root and insert Track table entries for each media file
+2
View File
@@ -8,6 +8,8 @@ track = Table(
metadata,
Column("id", Integer, primary_key=True, autoincrement=True),
Column("relpath", UnicodeText, index=True, unique=True),
Column("artist", UnicodeText),
Column("title", UnicodeText),
)
playlist = Table(