Fix subsunacs subtitle link (#384)

Fix subsunacs and subssabbz subtitle link and downloading button in manual search dialog.
This commit is contained in:
Adrian Dimitrov 2019-04-08 20:58:13 +03:00 committed by morpheus65535
parent 0dcb67b89e
commit 1681d5fc3c
2 changed files with 46 additions and 20 deletions

View File

@ -26,16 +26,22 @@ class SubsSabBzSubtitle(Subtitle):
"""SubsSabBz Subtitle."""
provider_name = 'subssabbz'
def __init__(self, langauge, filename, type):
def __init__(self, langauge, filename, type, video, link):
super(SubsSabBzSubtitle, self).__init__(langauge)
self.langauge = langauge
self.filename = filename
self.page_link = link
self.type = type
self.video = video
@property
def id(self):
return self.filename
def make_picklable(self):
self.content = None
return self
def get_matches(self, video):
matches = set()
@ -130,15 +136,22 @@ class SubsSabBzProvider(Provider):
return [s for l in languages for s in self.query(l, video)]
def download_subtitle(self, subtitle):
if subtitle.content:
pass
else:
seeking_subtitle_file = subtitle.filename
arch = self.download_archive_and_add_subtitle_files(subtitle.page_link, subtitle.language, subtitle.video)
for s in arch:
if s.filename == seeking_subtitle_file:
subtitle.content = s.content
def process_archive_subtitle_files(self, archiveStream, language, video):
def process_archive_subtitle_files(self, archiveStream, language, video, link):
subtitles = []
type = 'episode' if isinstance(video, Episode) else 'movie'
for file_name in archiveStream.namelist():
if file_name.lower().endswith(('.srt', '.sub')):
logger.info('Found subtitle file %r', file_name)
subtitle = SubsSabBzSubtitle(language, file_name, type)
subtitle = SubsSabBzSubtitle(language, file_name, type, video, link)
subtitle.content = archiveStream.read(file_name)
subtitles.append(subtitle)
return subtitles
@ -152,8 +165,8 @@ class SubsSabBzProvider(Provider):
archive_stream = io.BytesIO(request.content)
if is_rarfile(archive_stream):
return self.process_archive_subtitle_files( RarFile(archive_stream), language, video )
return self.process_archive_subtitle_files( RarFile(archive_stream), language, video, link )
elif is_zipfile(archive_stream):
return self.process_archive_subtitle_files( ZipFile(archive_stream), language, video )
return self.process_archive_subtitle_files( ZipFile(archive_stream), language, video, link )
else:
raise ValueError('Not a valid archive')

View File

@ -26,16 +26,22 @@ class SubsUnacsSubtitle(Subtitle):
"""SubsUnacs Subtitle."""
provider_name = 'subsunacs'
def __init__(self, langauge, filename, type):
def __init__(self, langauge, filename, type, video, link):
super(SubsUnacsSubtitle, self).__init__(langauge)
self.langauge = langauge
self.filename = filename
self.page_link = link
self.type = type
self.video = video
@property
def id(self):
return self.filename
def make_picklable(self):
self.content = None
return self
def get_matches(self, video):
matches = set()
@ -132,15 +138,22 @@ class SubsUnacsProvider(Provider):
return [s for l in languages for s in self.query(l, video)]
def download_subtitle(self, subtitle):
if subtitle.content:
pass
else:
seeking_subtitle_file = subtitle.filename
arch = self.download_archive_and_add_subtitle_files(subtitle.page_link, subtitle.language, subtitle.video)
for s in arch:
if s.filename == seeking_subtitle_file:
subtitle.content = s.content
def process_archive_subtitle_files(self, archiveStream, language, video):
def process_archive_subtitle_files(self, archiveStream, language, video, link):
subtitles = []
type = 'episode' if isinstance(video, Episode) else 'movie'
for file_name in archiveStream.namelist():
if file_name.lower().endswith(('.srt', '.sub')):
logger.info('Found subtitle file %r', file_name)
subtitle = SubsUnacsSubtitle(language, file_name, type)
subtitle = SubsUnacsSubtitle(language, file_name, type, video, link)
subtitle.content = archiveStream.read(file_name)
subtitles.append(subtitle)
return subtitles
@ -154,8 +167,8 @@ class SubsUnacsProvider(Provider):
archive_stream = io.BytesIO(request.content)
if is_rarfile(archive_stream):
return self.process_archive_subtitle_files( RarFile(archive_stream), language, video )
return self.process_archive_subtitle_files( RarFile(archive_stream), language, video, link )
elif is_zipfile(archive_stream):
return self.process_archive_subtitle_files( ZipFile(archive_stream), language, video )
return self.process_archive_subtitle_files( ZipFile(archive_stream), language, video, link )
else:
raise ValueError('Not a valid archive')