Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix old OpenSubtitles provider #1068

Merged
merged 1 commit into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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