Skip to content

Commit

Permalink
WIP: Fix opensubtitles
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrcnull committed Jan 22, 2024
1 parent 4d27b6d commit ff08895
Show file tree
Hide file tree
Showing 21 changed files with 2,928 additions and 3,016 deletions.
17 changes: 15 additions & 2 deletions subliminal/providers/opensubtitles.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@
logger = logging.getLogger(__name__)


class UATimeoutSafeTransport(TimeoutSafeTransport):
def set_user_agent(self, user_agent):
self._user_agent = user_agent

def send_headers(self, connection, headers):
if self._user_agent:
connection.putheader("User-Agent", self.user_agent)
super().send_headers(connection, headers)


class OpenSubtitlesSubtitle(Subtitle):
"""OpenSubtitles Subtitle."""
provider_name = 'opensubtitles'
Expand Down Expand Up @@ -113,10 +123,13 @@ class OpenSubtitlesProvider(Provider):
languages = {Language.fromopensubtitles(l) for l in language_converters['opensubtitles'].codes}
server_url = 'https://api.opensubtitles.org/xml-rpc'
subtitle_class = OpenSubtitlesSubtitle
user_agent = 'subliminal v%s' % __short_version__
user_agent = 'VLSub 0.11.1'
# user_agent = 'subliminal v%s' % __short_version__

def __init__(self, username=None, password=None):
self.server = ServerProxy(self.server_url, TimeoutSafeTransport(10))
transport = UATimeoutSafeTransport(10)
transport.set_user_agent('VLSub')
self.server = ServerProxy(self.server_url, transport)
if any((username, password)) and not all((username, password)):
raise ConfigurationError('Username and password must be specified')
# None values not allowed for logging in, so replace it by ''
Expand Down
1,763 changes: 889 additions & 874 deletions tests/cassettes/opensubtitles/test_download_subtitle.yaml

Large diffs are not rendered by default.

Loading

0 comments on commit ff08895

Please sign in to comment.