mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-26 04:33:00 -05:00
Fixed #3332
This commit is contained in:
1
changelog.d/audio/3332.bugfix.1.rst
Normal file
1
changelog.d/audio/3332.bugfix.1.rst
Normal file
@@ -0,0 +1 @@
|
|||||||
|
Fixed symbolic link folders not showing for local tracks.
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import contextlib
|
||||||
import ntpath
|
import ntpath
|
||||||
import os
|
import os
|
||||||
import posixpath
|
import posixpath
|
||||||
@@ -167,29 +168,51 @@ class LocalPath:
|
|||||||
modified.path = modified.path.joinpath(*args)
|
modified.path = modified.path.joinpath(*args)
|
||||||
return modified
|
return modified
|
||||||
|
|
||||||
def multiglob(self, *patterns):
|
def rglob(self, pattern, folder=False):
|
||||||
|
return list(glob.glob(f"{self.path}{os.sep}**{os.sep}{pattern}", recursive=True))
|
||||||
|
|
||||||
|
def glob(self, pattern, folder=False):
|
||||||
|
if folder:
|
||||||
|
return list(glob.glob(f"{self.path}{os.sep}*{os.sep}", recursive=False))
|
||||||
|
else:
|
||||||
|
return list(glob.glob(f"{self.path}{os.sep}*{pattern}", recursive=False))
|
||||||
|
|
||||||
|
def multiglob(self, *patterns, folder=False):
|
||||||
paths = []
|
paths = []
|
||||||
for p in patterns:
|
for p in patterns:
|
||||||
paths.extend(list(self.path.glob(p)))
|
paths.extend(self.glob(p, folder=folder))
|
||||||
|
if not folder:
|
||||||
for p in self._filtered(paths):
|
for p in self._filtered(paths):
|
||||||
yield p
|
yield p
|
||||||
|
else:
|
||||||
|
for p in paths:
|
||||||
|
p = LocalPath(p) if not isinstance(p, LocalPath) else p
|
||||||
|
yield p
|
||||||
|
|
||||||
def multirglob(self, *patterns):
|
def multirglob(self, *patterns, folder=False):
|
||||||
paths = []
|
paths = []
|
||||||
for p in patterns:
|
for p in patterns:
|
||||||
paths.extend(list(self.path.rglob(p)))
|
paths.extend(self.rglob(p, folder=folder))
|
||||||
|
if not folder:
|
||||||
for p in self._filtered(paths):
|
for p in self._filtered(paths):
|
||||||
yield p
|
yield p
|
||||||
|
else:
|
||||||
|
for p in paths:
|
||||||
|
p = LocalPath(p) if not isinstance(p, LocalPath) else p
|
||||||
|
yield p
|
||||||
|
|
||||||
def _filtered(self, paths: List[Path]):
|
def _filtered(self, paths: List[Path]):
|
||||||
for p in paths:
|
for p in paths:
|
||||||
|
p = LocalPath(p) if not isinstance(p, LocalPath) else p
|
||||||
if p.suffix in self._all_music_ext:
|
if p.suffix in self._all_music_ext:
|
||||||
yield p
|
yield p
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.to_string()
|
return self.to_string()
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return str(self)
|
||||||
|
|
||||||
def to_string(self):
|
def to_string(self):
|
||||||
try:
|
try:
|
||||||
return str(self.path.absolute())
|
return str(self.path.absolute())
|
||||||
@@ -213,11 +236,11 @@ class LocalPath:
|
|||||||
tracks = []
|
tracks = []
|
||||||
for track in self.multirglob(*[f"*{ext}" for ext in self._all_music_ext]):
|
for track in self.multirglob(*[f"*{ext}" for ext in self._all_music_ext]):
|
||||||
if track.exists() and track.is_file() and track.parent != self.localtrack_folder:
|
if track.exists() and track.is_file() and track.parent != self.localtrack_folder:
|
||||||
tracks.append(Query.process_input(LocalPath(str(track.absolute()))))
|
tracks.append(LocalPath(str(track.absolute())))
|
||||||
return sorted(tracks, key=lambda x: x.to_string_user().lower())
|
return sorted(tracks, key=lambda x: x.to_string_user().lower())
|
||||||
|
|
||||||
def subfolders_in_tree(self):
|
def subfolders_in_tree(self):
|
||||||
files = list(self.multirglob(*[f"*{ext}" for ext in self._all_music_ext]))
|
files = list(self.multirglob(*[f"*{ext}" for ext in self._all_music_ext], folder=True))
|
||||||
folders = []
|
folders = []
|
||||||
for f in files:
|
for f in files:
|
||||||
if f.exists() and f.parent not in folders and f.parent != self.localtrack_folder:
|
if f.exists() and f.parent not in folders and f.parent != self.localtrack_folder:
|
||||||
@@ -230,16 +253,18 @@ class LocalPath:
|
|||||||
|
|
||||||
def tracks_in_folder(self):
|
def tracks_in_folder(self):
|
||||||
tracks = []
|
tracks = []
|
||||||
for track in self.multiglob(*[f"*{ext}" for ext in self._all_music_ext]):
|
for track in self.multiglob(*[f"{ext}" for ext in self._all_music_ext]):
|
||||||
if track.exists() and track.is_file() and track.parent != self.localtrack_folder:
|
with contextlib.suppress(ValueError):
|
||||||
tracks.append(Query.process_input(LocalPath(str(track.absolute()))))
|
if track.exists() and track.is_file() and track.parent != self.localtrack_folder and track.path.relative_to(self.path):
|
||||||
|
tracks.append(LocalPath(str(track.absolute())))
|
||||||
return sorted(tracks, key=lambda x: x.to_string_user().lower())
|
return sorted(tracks, key=lambda x: x.to_string_user().lower())
|
||||||
|
|
||||||
def subfolders(self):
|
def subfolders(self):
|
||||||
files = list(self.multiglob(*[f"*{ext}" for ext in self._all_music_ext]))
|
files = list(self.multiglob(f"{os.sep}*", folder=True))
|
||||||
folders = []
|
folders = []
|
||||||
for f in files:
|
for f in files:
|
||||||
if f.exists() and f.parent not in folders and f.parent != self.localtrack_folder:
|
with contextlib.suppress(ValueError):
|
||||||
|
if f.exists() and f.parent not in folders and f.parent != self.localtrack_folder and f.path.relative_to(self.path):
|
||||||
folders.append(f.parent)
|
folders.append(f.parent)
|
||||||
return_folders = []
|
return_folders = []
|
||||||
for folder in folders:
|
for folder in folders:
|
||||||
|
|||||||
Reference in New Issue
Block a user