Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fixes issue butterscotchstallion#111 (opening streaming URLs)
  • Loading branch information
cottongin authored Nov 9, 2018
1 parent 8e90475 commit 9dc3f64
Showing 1 changed file with 28 additions and 27 deletions.
55 changes: 28 additions & 27 deletions SpiffyTitles/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1284,41 +1284,42 @@ def get_source_by_url(self, url, retries=1):

log.debug("SpiffyTitles: requesting %s" % (url))

request = requests.get(url, headers=headers, timeout=15, allow_redirects=True, verify=verify_ssl_certs)
with requests.get(url, headers=headers, timeout=15, allow_redirects=True,
verify=verify_ssl_certs, stream=True) as request:

is_redirect = False
if request.history:
# check the top two domain levels
link_domain = self.get_base_domain(request.history[0].url)
real_domain = self.get_base_domain(request.url)
if link_domain != real_domain:
is_redirect = True
is_redirect = False
if request.history:
# check the top two domain levels
link_domain = self.get_base_domain(request.history[0].url)
real_domain = self.get_base_domain(request.url)
if link_domain != real_domain:
is_redirect = True

for redir in request.history:
log.debug("SpiffyTitles: Redirect %s from %s" % (redir.status_code, redir.url))
log.debug("SpiffyTitles: Final url %s" % (request.url))
for redir in request.history:
log.debug("SpiffyTitles: Redirect %s from %s" % (redir.status_code, redir.url))
log.debug("SpiffyTitles: Final url %s" % (request.url))

if request.status_code == requests.codes.ok:
# Check the content type which comes in the format: "text/html; charset=UTF-8"
content_type = request.headers.get("content-type").split(";")[0].strip()
acceptable_types = self.registryValue("mimeTypes")
if request.status_code == requests.codes.ok:
# Check the content type which comes in the format: "text/html; charset=UTF-8"
content_type = request.headers.get("content-type").split(";")[0].strip()
acceptable_types = self.registryValue("mimeTypes")

log.debug("SpiffyTitles: content type %s" % (content_type))
log.debug("SpiffyTitles: content type %s" % (content_type))

if content_type in acceptable_types:
text = request.content
if content_type in acceptable_types:
text = request.content

if text:
return (text, is_redirect)
else:
log.debug("SpiffyTitles: empty content from %s" % (url))
if text:
return (text, is_redirect)
else:
log.debug("SpiffyTitles: empty content from %s" % (url))

else:
log.debug("SpiffyTitles: unacceptable mime type %s for url %s" %
(content_type, url))
else:
log.debug("SpiffyTitles: unacceptable mime type %s for url %s" %
(content_type, url))
else:
log.error("SpiffyTitles HTTP response code %s - %s" % (request.status_code,
request.content))
log.error("SpiffyTitles HTTP response code %s - %s" % (request.status_code,
request.content))

except timeout_decorator.TimeoutError:
log.error("SpiffyTitles: wall timeout!")
Expand Down

1 comment on commit 9dc3f64

@progval
Copy link

@progval progval commented on 9dc3f64 Nov 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not a perfect fix. It will not work on malicious servers that feed an infinite html page.

Please sign in to comment.