Skip to content

Commit

Permalink
fix error if no file extension is found
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed Apr 26, 2017
1 parent 701c016 commit 48a5b11
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions gallery_dl/downloader/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@
import requests
import requests.exceptions as rexcepts
import mimetypes
import logging
from .common import BasicDownloader
from .. import config

log = logging.getLogger("http")


class Downloader(BasicDownloader):

Expand Down Expand Up @@ -63,8 +66,13 @@ def download_impl(self, url, pathfmt):
# set 'extension' keyword from Content-Type header
mtype = response.headers.get("Content-Type", "image/jpeg")
exts = mimetypes.guess_all_extensions(mtype, strict=False)
exts.sort()
pathfmt.set_extension(exts[-1][1:])
if exts:
exts.sort()
pathfmt.set_extension(exts[-1][1:])
else:
log.warning("No file extension found for MIME type '%s'",
mtype)
pathfmt.set_extension("txt")
if pathfmt.exists():
self.out.skip(pathfmt.path)
response.close()
Expand Down

0 comments on commit 48a5b11

Please sign in to comment.