From 0bb61b6c7dd39bf266c9201c5184c0f6532791ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alban=20F=C3=A9ron?= Date: Sun, 30 Jun 2019 17:32:26 +0200 Subject: [PATCH] scandir for covers too --- supysonic/covers.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/supysonic/covers.py b/supysonic/covers.py index e683d0b..ad532e5 100644 --- a/supysonic/covers.py +++ b/supysonic/covers.py @@ -7,11 +7,13 @@ # # Distributed under terms of the GNU AGPLv3 license. -import os, os.path +import os.path import re from PIL import Image +from .py23 import scandir + EXTENSIONS = (".jpg", ".jpeg", ".png", ".bmp") NAMING_SCORE_RULES = ( ("cover", 5), @@ -67,16 +69,11 @@ def find_cover_in_folder(path, album_name=None): raise ValueError("Invalid path") candidates = [] - for f in os.listdir(path): - try: - file_path = os.path.join(path, f) - except UnicodeError: + for entry in scandir(path): + if not is_valid_cover(entry.path): continue - if not is_valid_cover(file_path): - continue - - cover = CoverFile(f, album_name) + cover = CoverFile(entry.name, album_name) candidates.append(cover) if not candidates: