- commit
- 09507f1f7af6c50c89431668c7cfa9bc22b71c8f
- parent
- 5c2145bce0cf453a6fd13cd593f51dc0ec0471ad
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2020-09-05 13:33
refactor listdir: get_ext
Diffstat
| M | cplay.py | 13 | ++++++++----- |
1 files changed, 8 insertions, 5 deletions
diff --git a/cplay.py b/cplay.py
@@ -99,12 +99,17 @@ def enable_ctrl_keys(): 99 99 termios.tcsetattr(fd, termios.TCSADRAIN, old) 100 100 101 101 -1 102 def get_ext(path): -1 103 return os.path.splitext(path)[1].lstrip('.') -1 104 -1 105 102 106 def listdir(path): 103 107 with os.scandir(path) as it: 104 108 for entry in sorted(it, key=lambda e: e.name): 105 109 if entry.name[0] != '.': 106 110 yield ( 107 111 entry.path, -1 112 get_ext(entry.name), 108 113 entry.is_dir(follow_symlinks=False), 109 114 ) 110 115 @@ -350,8 +355,7 @@ class Filelist(List): 350 355 self.all_items = [] 351 356 self.rsearch_str = '' 352 357353 -1 for p, is_dir in listdir(path):354 -1 ext = p.rsplit('.', 1)[-1]-1 358 for p, ext, is_dir in listdir(path): 355 359 if is_dir or ext == 'm3u' or ext in AUDIO_EXTENSIONS: 356 360 self.all_items.append(p) 357 361 @@ -365,8 +369,7 @@ class Filelist(List): 365 369 366 370 def build_search_cache(self, root): 367 371 results = []368 -1 for path, is_dir in listdir(root):369 -1 ext = path.rsplit('.', 1)[-1]-1 372 for path, ext, is_dir in listdir(root): 370 373 if is_dir: 371 374 children = self.build_search_cache(path) 372 375 if children: @@ -513,7 +516,7 @@ class Playlist(List): 513 516 514 517 def add_dir(self, path): 515 518 count = 0516 -1 for p, is_dir in listdir(path):-1 519 for p, ext, is_dir in listdir(path): 517 520 count += self.add(p, recursive=True) 518 521 return count 519 522