- commit
- 49fb40614fc28f15e5c7940abf3e6862d28569d5
- parent
- d1dc7d13df506870aa0180a700dd286d5b2a400e
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2020-09-03 11:10
refactor: use scandir instead of listdir
Diffstat
| M | cplay.py | 21 | +++++++++++---------- |
1 files changed, 11 insertions, 10 deletions
diff --git a/cplay.py b/cplay.py
@@ -77,6 +77,13 @@ def resize(*args): 77 77 app.render() 78 78 79 79 -1 80 def listdir(path): -1 81 with os.scandir(path) as it: -1 82 for entry in sorted(it, key=lambda e: e.name): -1 83 if entry.name[0] != '.': -1 84 yield entry.path, entry.is_dir() -1 85 -1 86 80 87 class Player: 81 88 re_progress = re.compile(br'AV?: (\d+):(\d+):(\d+) / (\d+):(\d+):(\d+)') 82 89 @@ -255,12 +262,9 @@ class Filelist(List): 255 262 self.path = path 256 263 self.items = [] 257 264258 -1 for filename in sorted(os.listdir(path)):259 -1 if filename[0] == '.':260 -1 continue261 -1 p = os.path.join(path, filename)262 -1 ext = filename.rsplit('.', 1)[-1]263 -1 if os.path.isdir(p) or ext == 'm3u' or ext in AUDIO_EXTENSIONS:-1 265 for p, is_dir in listdir(path): -1 266 ext = p.rsplit('.', 1)[-1] -1 267 if is_dir or ext == 'm3u' or ext in AUDIO_EXTENSIONS: 264 268 self.items.append(p) 265 269 266 270 if prev: @@ -378,10 +382,7 @@ class Playlist(List): 378 382 379 383 def add_dir(self, path): 380 384 count = 0381 -1 for filename in sorted(os.listdir(path)):382 -1 if filename[0] == '.':383 -1 continue384 -1 p = os.path.join(path, filename)-1 385 for p, is_dir in listdir(path): 385 386 count += self.add(p, recursive=True) 386 387 return count 387 388