WIP addition of interactive shell
This commit is contained in:
@@ -18,3 +18,4 @@ def windowed_query(query, column, window_size):
|
||||
last_id = chunk[-1][-1]
|
||||
for row in chunk:
|
||||
yield row
|
||||
|
||||
|
||||
+19
-4
@@ -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
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user