nixfiles/musicutil/utils/scan_for_music.py
2022-02-04 16:19:11 +00:00

22 lines
612 B
Python

from pathlib import Path
from os.path import relpath
from ..types import File
from ..meta import supported_formats
def file_from_path(path: Path, src: str) -> File:
file = File()
file.path_to = str(path.parent)
file.path_from_src = relpath(
str(path.parent), src)
file.filename = path.stem
file.extension = path.suffix.replace(".", "")
return file
def scan_for_music(src: str) -> list[File]:
files: list[File] = []
for format in supported_formats:
for path in Path(src).rglob("*." + format):
files.append(file_from_path(path, src))
return files