summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authormorpheus65535 <[email protected]>2023-01-31 14:52:13 -0500
committermorpheus65535 <[email protected]>2023-01-31 14:52:13 -0500
commitf057a778203e9729b6a02ff137388de361c0406b (patch)
tree20e12723cf1da1435a2eafb43c16ce5466b480eb
parent738e10e075d8b6afce7836d3b7d5d38968693444 (diff)
downloadbazarr-f057a778203e9729b6a02ff137388de361c0406b.tar.gz
bazarr-f057a778203e9729b6a02ff137388de361c0406b.zip
Improved impact on opensubtitles.com provider by simplifying queries to improve cache usage.
-rw-r--r--libs/subliminal_patch/providers/opensubtitlescom.py21
1 files changed, 9 insertions, 12 deletions
diff --git a/libs/subliminal_patch/providers/opensubtitlescom.py b/libs/subliminal_patch/providers/opensubtitlescom.py
index 532998c0d..a1603d822 100644
--- a/libs/subliminal_patch/providers/opensubtitlescom.py
+++ b/libs/subliminal_patch/providers/opensubtitlescom.py
@@ -274,15 +274,6 @@ class OpenSubtitlesComProvider(ProviderRetryMixin, Provider):
return []
lang_strings = [str(lang.basename) for lang in languages]
- only_foreign = all([lang.forced for lang in languages])
- also_foreign = any([lang.forced for lang in languages])
- if only_foreign:
- forced = 'only'
- elif also_foreign:
- forced = 'include'
- else:
- forced = 'exclude'
-
langs = ','.join(lang_strings)
logging.debug(f'Searching for this languages: {lang_strings}')
@@ -292,7 +283,6 @@ class OpenSubtitlesComProvider(ProviderRetryMixin, Provider):
lambda: checked(
lambda: self.session.get(self.server_url + 'subtitles',
params=(('episode_number', self.video.episode),
- ('foreign_parts_only', forced),
('imdb_id', imdb_id if not title_id else None),
('languages', langs.lower()),
('moviehash', file_hash),
@@ -308,8 +298,7 @@ class OpenSubtitlesComProvider(ProviderRetryMixin, Provider):
res = self.retry(
lambda: checked(
lambda: self.session.get(self.server_url + 'subtitles',
- params=(('foreign_parts_only', forced),
- ('id', title_id if title_id else None),
+ params=(('id', title_id if title_id else None),
('imdb_id', imdb_id if not title_id else None),
('languages', langs.lower()),
('moviehash', file_hash)),
@@ -324,6 +313,14 @@ class OpenSubtitlesComProvider(ProviderRetryMixin, Provider):
result = res.json()
+ # filter out forced subtitles or not depending on the required languages
+ if all([lang.forced for lang in languages]): # only forced
+ result['data'] = [x for x in result['data'] if x['attributes']['foreign_parts_only']]
+ elif any([lang.forced for lang in languages]): # also forced
+ pass
+ else: # not forced
+ result['data'] = [x for x in result['data'] if not x['attributes']['foreign_parts_only']]
+
logging.debug(f"Query returned {len(result['data'])} subtitles")
if len(result['data']):