1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-09-19 19:01:03 +00:00

scandir for covers too

This commit is contained in:
Alban Féron 2019-06-30 17:32:26 +02:00
parent 007a6e139b
commit 0bb61b6c7d
No known key found for this signature in database
GPG Key ID: 8CE0313646D16165

View File

@ -7,11 +7,13 @@
# #
# Distributed under terms of the GNU AGPLv3 license. # Distributed under terms of the GNU AGPLv3 license.
import os, os.path import os.path
import re import re
from PIL import Image from PIL import Image
from .py23 import scandir
EXTENSIONS = (".jpg", ".jpeg", ".png", ".bmp") EXTENSIONS = (".jpg", ".jpeg", ".png", ".bmp")
NAMING_SCORE_RULES = ( NAMING_SCORE_RULES = (
("cover", 5), ("cover", 5),
@ -67,16 +69,11 @@ def find_cover_in_folder(path, album_name=None):
raise ValueError("Invalid path") raise ValueError("Invalid path")
candidates = [] candidates = []
for f in os.listdir(path): for entry in scandir(path):
try: if not is_valid_cover(entry.path):
file_path = os.path.join(path, f)
except UnicodeError:
continue continue
if not is_valid_cover(file_path): cover = CoverFile(entry.name, album_name)
continue
cover = CoverFile(f, album_name)
candidates.append(cover) candidates.append(cover)
if not candidates: if not candidates: