subsunacs - download subtitles in 7zip format

pull/1247/head
josdion 5 years ago
parent 8a981553bf
commit a8258006b5

@ -21,10 +21,12 @@ from subliminal.video import Episode, Movie
from subliminal.subtitle import fix_line_ending from subliminal.subtitle import fix_line_ending
from subliminal.cache import region from subliminal.cache import region
from subzero.language import Language from subzero.language import Language
from py7zr import is_7zfile, SevenZipFile
from .utils import FIRST_THOUSAND_OR_SO_USER_AGENTS as AGENT_LIST from .utils import FIRST_THOUSAND_OR_SO_USER_AGENTS as AGENT_LIST
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
def fix_tv_naming(title): def fix_tv_naming(title):
"""Fix TV show titles with inconsistent naming using dictionary, but do not sanitize them. """Fix TV show titles with inconsistent naming using dictionary, but do not sanitize them.
@ -40,13 +42,13 @@ def fix_tv_naming(title):
"Doctor Who (2005)": "Doctor Who", "Doctor Who (2005)": "Doctor Who",
}, True) }, True)
class SubsUnacsSubtitle(Subtitle): class SubsUnacsSubtitle(Subtitle):
"""SubsUnacs Subtitle.""" """SubsUnacs Subtitle."""
provider_name = 'subsunacs' provider_name = 'subsunacs'
def __init__(self, langauge, filename, type, video, link, fps, num_cds): def __init__(self, language, filename, type, video, link, fps, num_cds):
super(SubsUnacsSubtitle, self).__init__(langauge) super(SubsUnacsSubtitle, self).__init__(language)
self.langauge = langauge
self.filename = filename self.filename = filename
self.page_link = link self.page_link = link
self.type = type self.type = type
@ -218,17 +220,32 @@ class SubsUnacsProvider(Provider):
def process_archive_subtitle_files(self, archiveStream, language, video, link, fps, num_cds): def process_archive_subtitle_files(self, archiveStream, language, video, link, fps, num_cds):
subtitles = [] subtitles = []
type = 'episode' if isinstance(video, Episode) else 'movie' type = 'episode' if isinstance(video, Episode) else 'movie'
for file_name in sorted(archiveStream.namelist()):
if file_name.lower().endswith(('.srt', '.sub', '.txt')): is_7zip = isinstance(archiveStream, SevenZipFile)
if is_7zip:
try:
file_content = archiveStream.readall()
file_list = sorted(file_content)
except:
return []
else:
file_list = sorted(archiveStream.namelist())
for file_name in file_list:
if file_name.lower().endswith(('srt', '.sub', '.txt')):
file_is_txt = True if file_name.lower().endswith('.txt') else False file_is_txt = True if file_name.lower().endswith('.txt') else False
if file_is_txt and re.search(r'subsunacs\.net|танете част|прочети|^read ?me|procheti', file_name, re.I): if file_is_txt and re.search(r'subsunacs\.net|танете част|прочети|^read ?me|procheti', file_name, re.I):
logger.info('Ignore readme txt file %r', file_name) logger.info('Ignore readme txt file %r', file_name)
continue continue
logger.info('Found subtitle file %r', file_name) logger.info('Found subtitle file %r', file_name)
subtitle = SubsUnacsSubtitle(language, file_name, type, video, link, fps, num_cds) subtitle = SubsUnacsSubtitle(language, file_name, type, video, link, fps, num_cds)
if is_7zip:
subtitle.content = fix_line_ending(file_content[file_name].read())
else:
subtitle.content = fix_line_ending(archiveStream.read(file_name)) subtitle.content = fix_line_ending(archiveStream.read(file_name))
if file_is_txt == False or subtitle.is_valid(): if subtitle.is_valid():
subtitles.append(subtitle) subtitles.append(subtitle)
return subtitles return subtitles
def download_archive_and_add_subtitle_files(self, link, language, video, fps, num_cds): def download_archive_and_add_subtitle_files(self, link, language, video, fps, num_cds):
@ -249,6 +266,8 @@ class SubsUnacsProvider(Provider):
return self.process_archive_subtitle_files(RarFile(archive_stream), language, video, link, fps, num_cds) return self.process_archive_subtitle_files(RarFile(archive_stream), language, video, link, fps, num_cds)
elif is_zipfile(archive_stream): elif is_zipfile(archive_stream):
return self.process_archive_subtitle_files(ZipFile(archive_stream), language, video, link, fps, num_cds) return self.process_archive_subtitle_files(ZipFile(archive_stream), language, video, link, fps, num_cds)
elif archive_stream.seek(0) == 0 and is_7zfile(archive_stream):
return self.process_archive_subtitle_files(SevenZipFile(archive_stream), language, video, link, fps, num_cds)
else: else:
logger.error('Ignore unsupported archive %r', request.headers) logger.error('Ignore unsupported archive %r', request.headers)
return [] return []

Loading…
Cancel
Save