mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-07-09 03:04:20 -04:00
Scan directory on directory creation (used on directory rename)
This commit is contained in:
parent
d9d7fd5000
commit
fccc5b6ad9
@ -14,7 +14,7 @@ async def main():
|
||||
async with Publisher() as publisher, KyooClient() as client:
|
||||
path = os.environ.get("SCANNER_LIBRARY_ROOT", "/video")
|
||||
await asyncio.gather(
|
||||
monitor(path, publisher),
|
||||
scan(path, publisher, client),
|
||||
monitor(path, publisher, client),
|
||||
scan(path, publisher, client, remove_deleted=True),
|
||||
refresh(publisher, client),
|
||||
)
|
||||
|
@ -1,16 +1,21 @@
|
||||
from logging import getLogger
|
||||
from os.path import isdir
|
||||
from watchfiles import awatch, Change
|
||||
|
||||
from .publisher import Publisher
|
||||
from .scanner import scan
|
||||
from providers.kyoo_client import KyooClient
|
||||
|
||||
logger = getLogger(__name__)
|
||||
|
||||
|
||||
async def monitor(path: str, publisher: Publisher):
|
||||
async def monitor(path: str, publisher: Publisher, client: KyooClient):
|
||||
async for changes in awatch(path, ignore_permission_denied=True):
|
||||
for event, file in changes:
|
||||
if event == Change.added:
|
||||
await publisher.add(file)
|
||||
if isdir(file):
|
||||
await scan(file, publisher, client)
|
||||
else:
|
||||
await publisher.add(file)
|
||||
elif event == Change.deleted:
|
||||
await publisher.delete(file)
|
||||
elif event == Change.modified:
|
||||
|
@ -9,7 +9,7 @@ from providers.kyoo_client import KyooClient
|
||||
logger = getLogger(__name__)
|
||||
|
||||
|
||||
async def scan(path: str, publisher: Publisher, client: KyooClient):
|
||||
async def scan(path: str, publisher: Publisher, client: KyooClient, remove_deleted = False):
|
||||
logger.info("Starting the scan. It can take some times...")
|
||||
ignore_pattern = None
|
||||
try:
|
||||
@ -25,12 +25,14 @@ async def scan(path: str, publisher: Publisher, client: KyooClient):
|
||||
to_register = [
|
||||
p for p in videos if p not in registered and not ignore_pattern.match(p)
|
||||
]
|
||||
deleted = [x for x in registered if x not in videos]
|
||||
|
||||
if len(deleted) != len(registered):
|
||||
await asyncio.gather(*map(publisher.delete, deleted))
|
||||
elif len(deleted) > 0:
|
||||
logger.warning("All video files are unavailable. Check your disks.")
|
||||
if remove_deleted:
|
||||
deleted = [x for x in registered if x not in videos]
|
||||
if len(deleted) != len(registered):
|
||||
await asyncio.gather(*map(publisher.delete, deleted))
|
||||
elif len(deleted) > 0:
|
||||
logger.warning("All video files are unavailable. Check your disks.")
|
||||
|
||||
await asyncio.gather(*map(publisher.add, to_register))
|
||||
logger.info("Scan finished.")
|
||||
logger.info(f"Scan finished for {path}.")
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user