1
0
Fork 0
mirror of https://github.com/morpheus65535/bazarr synced 2024-12-23 00:03:33 +00:00
This commit is contained in:
morpheus65535 2024-12-02 20:12:07 -05:00
parent 6e5f538ff0
commit 5e3797092a
2 changed files with 69 additions and 16 deletions

View file

@ -6,7 +6,7 @@ import io
from zipfile import ZipFile, is_zipfile from zipfile import ZipFile, is_zipfile
from urllib.parse import urljoin from urllib.parse import urljoin
from requests import Session from requests import Session, JSONDecodeError
from subzero.language import Language from subzero.language import Language
from subliminal import Episode, Movie from subliminal import Episode, Movie
@ -81,7 +81,7 @@ class SubsourceSubtitle(Subtitle):
class SubsourceProvider(ProviderRetryMixin, Provider): class SubsourceProvider(ProviderRetryMixin, Provider):
"""Subsource Provider""" """Subsource Provider"""
server_hostname = 'api.subsource.net' server_url = 'https://api.subsource.net/api/'
languages = {Language('por', 'BR')} | {Language(l) for l in [ languages = {Language('por', 'BR')} | {Language(l) for l in [
'ara', 'bul', 'ces', 'dan', 'deu', 'ell', 'eng', 'fin', 'fra', 'hun', 'ita', 'jpn', 'kor', 'nld', 'pol', 'por', 'ara', 'bul', 'ces', 'dan', 'deu', 'ell', 'eng', 'fin', 'fra', 'hun', 'ita', 'jpn', 'kor', 'nld', 'pol', 'por',
@ -92,13 +92,9 @@ class SubsourceProvider(ProviderRetryMixin, Provider):
video_types = (Episode, Movie) video_types = (Episode, Movie)
def __init__(self, api_key=None): def __init__(self):
if not api_key:
raise ConfigurationError('Api_key must be specified')
self.session = Session() self.session = Session()
self.session.headers = {'User-Agent': os.environ.get("SZ_USER_AGENT", "Sub-Zero/2")} self.session.headers = {'User-Agent': os.environ.get("SZ_USER_AGENT", "Sub-Zero/2")}
self.api_key = api_key
self.video = None self.video = None
self._started = None self._started = None
@ -108,8 +104,62 @@ class SubsourceProvider(ProviderRetryMixin, Provider):
def terminate(self): def terminate(self):
self.session.close() self.session.close()
def server_url(self): @staticmethod
return f'https://{self.server_hostname}/api/v1/' def parse_json(response):
try:
return response.json()
except JSONDecodeError:
logging.debug("Unable to parse server response")
return False
def searchMovie(self, imdb_id=None, title=None):
res = self.session.post(f"{self.server_url}searchMovie",
json={'query': imdb_id or title},
timeout=30)
results = self.parse_json(res)
if results and 'found' in results and isinstance(results['found'], list) and len(results['found']) > 0:
return results['found'][0]['linkName']
return False
def getMovie(self, title, season=None):
data = {'movieName': title}
if season:
data.update({'season': f"season-{season}"})
res = self.session.post(f"{self.server_url}getMovie",
json=data,
timeout=30)
results = self.parse_json(res)
if results and 'subs' in results and isinstance(results['subs'], list) and len(results['subs']) > 0:
subs_to_return = []
for sub in results['subs']:
subs_to_return.append({
'movie': sub['linkName'],
'lang': sub['lang'],
'id': sub['subId'],
})
return subs_to_return
return False
def getSub(self, title, season=None):
data = {'movieName': title}
if season:
data.update({'season': f"season-{season}"})
res = self.session.post(f"{self.server_url}getSub",
json=data,
timeout=30)
results = self.parse_json(res)
if results and 'subs' in results and isinstance(results['subs'], list) and len(results['subs']) > 0:
subs_to_return = []
for sub in results['subs']:
subs_to_return.append({
'page_link': f"https://subsource.net{sub['fullLink']}",
'uploader': sub['uploadedBy'],
'release_info': sub['releaseName'],
'file_id': sub['subId'],
'language': sub['lang'],
})
return results['found'][0]['linkName']
return False
def query(self, languages, video): def query(self, languages, video):
self.video = video self.video = video
@ -124,12 +174,13 @@ class SubsourceProvider(ProviderRetryMixin, Provider):
elif isinstance(self.video, Movie) and self.video.imdb_id: elif isinstance(self.video, Movie) and self.video.imdb_id:
imdb_id = self.video.imdb_id imdb_id = self.video.imdb_id
linkName = self.search(imdb_id=imdb_id, title=title)
# query the server # query the server
if isinstance(self.video, Episode): if isinstance(self.video, Episode):
res = self.retry( res = self.retry(
lambda: self.session.get(self.server_url() + 'subtitles', lambda: self.session.get(f"{self.server_url}subtitles",
params=(('api_key', self.api_key), params=(('episode_number', self.video.episode),
('episode_number', self.video.episode),
('film_name', title if not imdb_id else None), ('film_name', title if not imdb_id else None),
('imdb_id', imdb_id if imdb_id else None), ('imdb_id', imdb_id if imdb_id else None),
('season_number', self.video.season), ('season_number', self.video.season),
@ -145,11 +196,9 @@ class SubsourceProvider(ProviderRetryMixin, Provider):
) )
else: else:
res = self.retry( res = self.retry(
lambda: self.session.get(self.server_url() + 'subtitles', lambda: self.session.get(f"{self.server_url}subtitles",
params=(('api_key', self.api_key), params=(('film_name', title if not imdb_id else None),
('film_name', title if not imdb_id else None),
('imdb_id', imdb_id if imdb_id else None), ('imdb_id', imdb_id if imdb_id else None),
('languages', langs),
('subs_per_page', 30), ('subs_per_page', 30),
('type', 'movie'), ('type', 'movie'),
('comment', 1), ('comment', 1),

View file

@ -457,6 +457,10 @@ export const ProviderList: Readonly<ProviderInfo[]> = [
], ],
message: "Make sure to use a unique and credible user agent.", message: "Make sure to use a unique and credible user agent.",
}, },
{
key: "subsource",
name: "subsource.net",
},
{ {
key: "subssabbz", key: "subssabbz",
name: "Subs.sab.bz", name: "Subs.sab.bz",