Improve guessing if http fetch fails.

If the server doesn't support getting the http head for the feed a 501
may be generated the guess_mime function will in turn fail if the url
ends with "?arg=x" or similar. This does an extra parsing step trying to
remove such arguments.
pull/2389/head
Åke Forslund 2019-11-19 05:37:03 +01:00
parent f44165d35d
commit 5e90465267
1 changed files with 4 additions and 0 deletions

View File

@ -20,6 +20,7 @@ from mycroft.messagebus.message import Message
from mycroft.util.log import LOG
from mycroft.util import play_mp3, play_ogg, play_wav
import mimetypes
import re
from requests import Session
@ -31,6 +32,9 @@ def find_mime(path):
mime = response.headers['content-type']
if not mime:
mime = mimetypes.guess_type(path)[0]
# Remove any http address arguments
if not mime:
mime = mimetypes.guess_type(re.sub(r'\?.*$', '', path))[0]
if mime:
return mime.split('/')