mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-05 04:53:01 +00:00
fix folders endpoint on windows
+ try/catch ffmpeg 404s in pydub
This commit is contained in:
+3
-4
@@ -78,7 +78,6 @@ def get_folder_tree(body: FolderTree):
|
|||||||
|
|
||||||
config = UserConfig()
|
config = UserConfig()
|
||||||
root_dirs = config.rootDirs
|
root_dirs = config.rootDirs
|
||||||
print("root_dirs", root_dirs)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if req_dir == "$home" and root_dirs[0] == "$home":
|
if req_dir == "$home" and root_dirs[0] == "$home":
|
||||||
@@ -122,11 +121,11 @@ def get_all_drives(is_win: bool = False):
|
|||||||
"""
|
"""
|
||||||
Returns a list of all the drives on a Windows machine.
|
Returns a list of all the drives on a Windows machine.
|
||||||
"""
|
"""
|
||||||
drives = psutil.disk_partitions(all=True)
|
drives_ = psutil.disk_partitions(all=True)
|
||||||
drives = [d.mountpoint for d in drives]
|
drives = [Path(d.mountpoint).as_posix() for d in drives_]
|
||||||
|
|
||||||
if is_win:
|
if is_win:
|
||||||
drives = [win_replace_slash(d) for d in drives]
|
return drives
|
||||||
else:
|
else:
|
||||||
remove = (
|
remove = (
|
||||||
"/boot",
|
"/boot",
|
||||||
|
|||||||
+8
-19
@@ -26,19 +26,6 @@ def create_folder(path: str, trackcount=0) -> Folder:
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def get_first_child_from_path(root: str, maybe_child: str):
|
|
||||||
"""
|
|
||||||
Given a root path and a path, returns the first child from the root path.
|
|
||||||
"""
|
|
||||||
if not maybe_child.startswith(root) or maybe_child == root:
|
|
||||||
return None
|
|
||||||
|
|
||||||
children = maybe_child.replace(root, "")
|
|
||||||
first = Path(children).parts[0]
|
|
||||||
|
|
||||||
return os.path.join(root, first)
|
|
||||||
|
|
||||||
|
|
||||||
def get_folders(paths: list[str]):
|
def get_folders(paths: list[str]):
|
||||||
"""
|
"""
|
||||||
Filters out folders that don't have any tracks and
|
Filters out folders that don't have any tracks and
|
||||||
@@ -68,7 +55,7 @@ def get_files_and_dirs(
|
|||||||
|
|
||||||
Can recursively call itself to skip through empty folders.
|
Can recursively call itself to skip through empty folders.
|
||||||
"""
|
"""
|
||||||
|
# TODO: Replace os.path with pathlib
|
||||||
try:
|
try:
|
||||||
entries = os.scandir(path)
|
entries = os.scandir(path)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
@@ -80,17 +67,19 @@ def get_files_and_dirs(
|
|||||||
|
|
||||||
dirs, files = [], []
|
dirs, files = [], []
|
||||||
|
|
||||||
for entry in entries:
|
for entry_ in entries:
|
||||||
ext = os.path.splitext(entry.name)[1].lower()
|
entry = Path(entry_.path)
|
||||||
|
ext = entry.suffix.lower()
|
||||||
|
|
||||||
if entry.is_dir() and not entry.name.startswith("."):
|
if entry.is_dir() and not entry.name.startswith("."):
|
||||||
dir = win_replace_slash(entry.path)
|
dir = (entry / "").as_posix()
|
||||||
|
|
||||||
# add a trailing slash to the folder path
|
# add a trailing slash to the folder path
|
||||||
# to avoid matching a folder starting with the same name as the root path
|
# to avoid matching a folder starting with the same name as the root path
|
||||||
# eg. .../Music and .../Music VideosI
|
# eg. .../Music and .../Music VideosI
|
||||||
dirs.append(os.path.join(dir, ""))
|
dirs.append(dir)
|
||||||
elif entry.is_file() and ext in SUPPORTED_FILES:
|
elif entry.is_file() and ext in SUPPORTED_FILES:
|
||||||
files.append(win_replace_slash(entry.path))
|
files.append(entry.as_posix())
|
||||||
|
|
||||||
files_ = []
|
files_ = []
|
||||||
|
|
||||||
|
|||||||
@@ -14,8 +14,11 @@ def get_leading_silence_end(filepath: str):
|
|||||||
Returns the leading silence of a track.
|
Returns the leading silence of a track.
|
||||||
"""
|
"""
|
||||||
format = filepath.split(".")[-1]
|
format = filepath.split(".")[-1]
|
||||||
|
try:
|
||||||
audio = AudioSegment.from_file(filepath, format=format)
|
audio = AudioSegment.from_file(filepath, format=format)
|
||||||
silence = detect_leading_silence(audio, silence_threshold=-40.0, chunk_size=10)
|
silence = detect_leading_silence(audio, silence_threshold=-40.0, chunk_size=10)
|
||||||
|
except Exception as e:
|
||||||
|
return 0
|
||||||
|
|
||||||
return silence if silence > 1000 else 0
|
return silence if silence > 1000 else 0
|
||||||
|
|
||||||
@@ -25,8 +28,11 @@ def get_trailing_silence_start(filepath: str):
|
|||||||
Returns the trailing silence of a track.
|
Returns the trailing silence of a track.
|
||||||
"""
|
"""
|
||||||
format = filepath.split(".")[-1]
|
format = filepath.split(".")[-1]
|
||||||
|
try:
|
||||||
audio = AudioSegment.from_file(filepath, format=format)
|
audio = AudioSegment.from_file(filepath, format=format)
|
||||||
duration = len(audio)
|
duration = len(audio)
|
||||||
|
except Exception as e:
|
||||||
|
return None
|
||||||
|
|
||||||
audio = audio[-30000:] if len(audio) > 30000 else audio
|
audio = audio[-30000:] if len(audio) > 30000 else audio
|
||||||
silence_groups = detect_silence(audio, silence_thresh=-40.0, seek_step=10)
|
silence_groups = detect_silence(audio, silence_thresh=-40.0, seek_step=10)
|
||||||
|
|||||||
@@ -63,7 +63,6 @@ class FolderStore:
|
|||||||
results = [
|
results = [
|
||||||
{"path": path, "trackcount": count} for path, count in zip(paths, res)
|
{"path": path, "trackcount": count} for path, count in zip(paths, res)
|
||||||
]
|
]
|
||||||
print("results", results)
|
|
||||||
|
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user