2022-02-04 13:32:22 +00:00
|
|
|
from pathlib import Path
|
|
|
|
from os.path import relpath
|
|
|
|
|
2022-02-04 13:35:01 +00:00
|
|
|
from ..types import File
|
|
|
|
from ..meta import supported_formats
|
2022-02-04 13:32:22 +00:00
|
|
|
|
2022-02-04 16:19:11 +00:00
|
|
|
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
|
2022-02-04 13:54:10 +00:00
|
|
|
|
2022-02-04 13:32:22 +00:00
|
|
|
def scan_for_music(src: str) -> list[File]:
|
2022-02-04 13:54:10 +00:00
|
|
|
files: list[File] = []
|
|
|
|
for format in supported_formats:
|
|
|
|
for path in Path(src).rglob("*." + format):
|
2022-02-04 16:19:11 +00:00
|
|
|
files.append(file_from_path(path, src))
|
2022-02-04 13:54:10 +00:00
|
|
|
return files
|