Skip to content

Commit

Permalink
Cache the scanned files useful for when we scan for subtitles directl…
Browse files Browse the repository at this point in the history
…y after having scanned directory for video files
  • Loading branch information
thomaserlang committed Nov 6, 2023
1 parent 6f2a86e commit c82ef95
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions seplis_play_server/scanners/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class Play_scan:

SCANNER_NAME = 'Unnamed scanner'
SUPPORTED_EXTS = config.media_types
_cached_paths = {}

def __init__(self, scan_path: str, make_thumbnails: bool = False, cleanup_mode = False, parser = 'internal'):
if not os.path.exists(scan_path):
Expand Down Expand Up @@ -37,24 +38,30 @@ async def scan(self):
await self.save_item(title, f)

def get_files(self):
'''
Looks for files in the `self.scan_path` directory.
'''
files = []
for dirname, dirnames, filenames in os.walk(self.scan_path):
for file_ in filenames:
info = os.path.splitext(file_)
if file_.startswith('._'):
continue
if len(info) != 2:
continue
if info[1][1:].lower() not in self.SUPPORTED_EXTS:
continue
files.append(
os.path.join(dirname, file_)
)
for dirname, file_ in self._get_files(self.scan_path):
info = os.path.splitext(file_)
if file_.startswith('._'):
continue
if len(info) != 2:
continue
if info[1][1:].lower() not in self.SUPPORTED_EXTS:
continue
files.append(
os.path.join(dirname, file_)
)
return files


def _get_files(self, scan_path) -> tuple[str, str]:
if scan_path in self._cached_paths:
for r in self._cached_paths[scan_path]:
yield r
else:
self._cached_paths[scan_path] = []
for dirname, _, filenames in os.walk(scan_path):
for file_ in filenames:
self._cached_paths[scan_path].append((dirname, file_))
yield (dirname, file_)

async def get_metadata(self, path):
'''
Expand Down

0 comments on commit c82ef95

Please sign in to comment.