Fixed zimuku provider to prevent unexpected exception. #1459

pull/1471/head v0.9.6-beta.42
morpheus65535 4 years ago
parent 8429087d8a
commit 8cdd362caa

@ -18,8 +18,8 @@ from subzero.language import Language
from guessit import guessit from guessit import guessit
from requests import Session from requests import Session
from six import text_type from six import text_type
from random import randint
from subliminal import __short_version__
from subliminal.providers import ParserBeautifulSoup from subliminal.providers import ParserBeautifulSoup
from subliminal_patch.providers import Provider from subliminal_patch.providers import Provider
from subliminal.subtitle import ( from subliminal.subtitle import (
@ -30,6 +30,7 @@ from subliminal_patch.subtitle import (
Subtitle, Subtitle,
guess_matches guess_matches
) )
from .utils import FIRST_THOUSAND_OR_SO_USER_AGENTS as AGENT_LIST
from subliminal.video import Episode, Movie from subliminal.video import Episode, Movie
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -89,8 +90,6 @@ class ZimukuProvider(Provider):
search_url = "/search?q={}" search_url = "/search?q={}"
download_url = "http://zimuku.org/" download_url = "http://zimuku.org/"
UserAgent = "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)"
subtitle_class = ZimukuSubtitle subtitle_class = ZimukuSubtitle
def __init__(self): def __init__(self):
@ -98,7 +97,7 @@ class ZimukuProvider(Provider):
def initialize(self): def initialize(self):
self.session = Session() self.session = Session()
self.session.headers["User-Agent"] = "Subliminal/{}".format(__short_version__) self.session.headers["User-Agent"] = AGENT_LIST[randint(0, len(AGENT_LIST) - 1)]
def terminate(self): def terminate(self):
self.session.close() self.session.close()
@ -258,9 +257,13 @@ class ZimukuProvider(Provider):
logger.info("Downloading subtitle %r", subtitle) logger.info("Downloading subtitle %r", subtitle)
self.session = subtitle.session self.session = subtitle.session
download_link = _get_archive_dowload_link(self.session, subtitle.page_link) download_link = _get_archive_dowload_link(self.session, subtitle.page_link)
r = self.session.get(download_link, timeout=30) r = self.session.get(download_link, headers={'Referer': subtitle.page_link}, timeout=30)
r.raise_for_status() r.raise_for_status()
filename = r.headers["Content-Disposition"] try:
filename = r.headers["Content-Disposition"]
except KeyError:
logger.debug("Unable to parse subtitles filename. Dropping this subtitles.")
return
if not r.content: if not r.content:
logger.debug("Unable to download subtitle. No data returned from provider") logger.debug("Unable to download subtitle. No data returned from provider")

Loading…
Cancel
Save