mirror of
https://github.com/morpheus65535/bazarr.git
synced 2025-01-06 06:52:07 +08:00
Improved Opensubtitles.com providers
This commit is contained in:
parent
75c003ab67
commit
bb842b92af
1 changed files with 17 additions and 2 deletions
|
@ -19,6 +19,7 @@ from subliminal.subtitle import fix_line_ending, SUBTITLE_EXTENSIONS
|
|||
from subliminal_patch.providers import Provider
|
||||
from subliminal_patch.utils import fix_inconsistent_naming
|
||||
from subliminal.cache import region
|
||||
from dogpile.cache.api import NO_VALUE
|
||||
from guessit import guessit
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
@ -121,7 +122,7 @@ class OpenSubtitlesComSubtitle(Subtitle):
|
|||
|
||||
class OpenSubtitlesComProvider(ProviderRetryMixin, Provider):
|
||||
"""OpenSubtitlesCom Provider"""
|
||||
server_url = 'https://www.opensubtitles.com/api/v1/'
|
||||
server_url = 'https://api.opensubtitles.com/api/v1/'
|
||||
|
||||
languages = {Language.fromopensubtitles(l) for l in language_converters['szopensubtitles'].codes}
|
||||
languages.update(set(Language.rebuild(l, forced=True) for l in languages))
|
||||
|
@ -144,8 +145,9 @@ class OpenSubtitlesComProvider(ProviderRetryMixin, Provider):
|
|||
self.use_hash = use_hash
|
||||
|
||||
def initialize(self):
|
||||
self.login()
|
||||
self.token = region.get("oscom_token")
|
||||
if self.token is NO_VALUE:
|
||||
self.login()
|
||||
|
||||
def terminate(self):
|
||||
self.session.close()
|
||||
|
@ -172,6 +174,8 @@ class OpenSubtitlesComProvider(ProviderRetryMixin, Provider):
|
|||
raise AuthenticationError('Login failed: {}'.format(r.reason))
|
||||
elif r.status_code == 429:
|
||||
raise TooManyRequests()
|
||||
elif r.status_code == 503:
|
||||
raise ProviderError(r.reason)
|
||||
else:
|
||||
raise ProviderError('Bad status code: {}'.format(r.status_code))
|
||||
finally:
|
||||
|
@ -205,8 +209,12 @@ class OpenSubtitlesComProvider(ProviderRetryMixin, Provider):
|
|||
|
||||
if results.status_code == 429:
|
||||
raise TooManyRequests()
|
||||
elif results.status_code == 503:
|
||||
raise ProviderError(results.reason)
|
||||
elif results.status_code == 429:
|
||||
raise TooManyRequests()
|
||||
elif results.status_code == 503:
|
||||
raise ProviderError(results.reason)
|
||||
|
||||
# deserialize results
|
||||
try:
|
||||
|
@ -267,6 +275,9 @@ class OpenSubtitlesComProvider(ProviderRetryMixin, Provider):
|
|||
if res.status_code == 429:
|
||||
raise TooManyRequests()
|
||||
|
||||
elif res.status_code == 503:
|
||||
raise ProviderError(res.reason)
|
||||
|
||||
subtitles = []
|
||||
|
||||
try:
|
||||
|
@ -328,6 +339,8 @@ class OpenSubtitlesComProvider(ProviderRetryMixin, Provider):
|
|||
raise TooManyRequests()
|
||||
elif res.status_code == 406:
|
||||
raise DownloadLimitExceeded("Daily download limit reached")
|
||||
elif res.status_code == 503:
|
||||
raise ProviderError(res.reason)
|
||||
else:
|
||||
try:
|
||||
subtitle.download_link = res.json()['link']
|
||||
|
@ -340,6 +353,8 @@ class OpenSubtitlesComProvider(ProviderRetryMixin, Provider):
|
|||
raise TooManyRequests()
|
||||
elif res.status_code == 406:
|
||||
raise DownloadLimitExceeded("Daily download limit reached")
|
||||
elif res.status_code == 503:
|
||||
raise ProviderError(res.reason)
|
||||
|
||||
subtitle_content = r.content
|
||||
|
||||
|
|
Loading…
Reference in a new issue