Skip to content

Commit 3719e8a

Browse files
author
E.S. Rosenberg a.k.a. Keeper of the Keys
committed
Fix double file extension issue
1 parent 5d5966c commit 3719e8a

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

src/gpodder/coverart.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ def get_cover(self, podcast, download=False, episode = None):
6060
password = podcast.auth_password
6161

6262
# Return already existing files
63+
if os.path.exists(filename):
64+
return filename
65+
6366
for extension in self.EXTENSIONS:
6467
if os.path.exists(filename + extension):
6568
return filename + extension
@@ -85,10 +88,27 @@ def get_cover(self, podcast, download=False, episode = None):
8588
try:
8689
extension = None
8790

88-
for filetype, check in list(self.SUPPORTED_EXTENSIONS.items()):
89-
if check(data):
90-
extension = filetype
91-
break
91+
fname, ext = os.path.splitext(filename)
92+
93+
# Check if an extension is part of the filename and that it matches the filetype
94+
if ext != None and ext != '' :
95+
ext_unchanged = ext
96+
# Assume last part of filename parts is extension
97+
ext = ext.lower()
98+
# Deal with alternative extensions for supported format,
99+
# should more cases need to be added a mapping dictionary can be created.
100+
if ext == '.jpeg':
101+
ext = '.jpg'
102+
if ext in self.SUPPORTED_EXTENSIONS:
103+
if self.SUPPORTED_EXTENSIONS[ext](data):
104+
filename = fname
105+
extension = ext_unchanged
106+
# Filename did not include an extension or the extension did not match the filetype
107+
if extension is None:
108+
for filetype, check in list(self.SUPPORTED_EXTENSIONS.items()):
109+
if check(data):
110+
extension = filetype
111+
break
92112

93113
if extension is None:
94114
msg = 'Unknown file type: %s (%r)' % (cover_url, data[:6])

0 commit comments

Comments
 (0)