From 76d5be0e77baab67b20c1692ec141e7748f239da Mon Sep 17 00:00:00 2001 From: e01 Date: Tue, 29 Jan 2019 15:25:24 +0200 Subject: [PATCH 01/12] Add subsunacs.net and subs.sab.bz providers --- libs/subliminal/providers/subssabbz.py | 156 ++++++++++++++++++++++++ libs/subliminal/providers/subsunacs.py | 158 +++++++++++++++++++++++++ 2 files changed, 314 insertions(+) create mode 100644 libs/subliminal/providers/subssabbz.py create mode 100644 libs/subliminal/providers/subsunacs.py diff --git a/libs/subliminal/providers/subssabbz.py b/libs/subliminal/providers/subssabbz.py new file mode 100644 index 000000000..23e5c3cc1 --- /dev/null +++ b/libs/subliminal/providers/subssabbz.py @@ -0,0 +1,156 @@ +# -*- coding: utf-8 -*- +import logging +import re +import io +import os + +from rarfile import RarFile, is_rarfile +from zipfile import ZipFile, is_zipfile + +from babelfish import Language +from requests import Session +from guessit import guessit + +from . import ParserBeautifulSoup, Provider +from ..utils import sanitize, sanitize_release_group +from ..subtitle import Subtitle, fix_line_ending, guess_matches +from ..video import Episode +from ..video import Movie + +logger = logging.getLogger(__name__) + +class SubsSabBzSubtitle(Subtitle): + """SubsSabBz Subtitle.""" + provider_name = 'subssabbz' + + def __init__(self, langauge, filename, type): + super(SubsSabBzSubtitle, self).__init__(langauge) + self.langauge = langauge + self.filename = filename + self.type = type + + @property + def id(self): + return self.filename + + def get_matches(self, video): + matches = set() + + video_filename = video.name + video_filename = os.path.basename(video_filename) + video_filename, _ = os.path.splitext(video_filename) + video_filename = sanitize_release_group(video_filename) + + subtitle_filename = self.filename + subtitle_filename = os.path.basename(subtitle_filename) + subtitle_filename, _ = os.path.splitext(subtitle_filename) + subtitle_filename = sanitize_release_group(subtitle_filename) + + if video_filename == subtitle_filename: + matches.add('hash') + + matches |= guess_matches(video, guessit(self.filename, {'type': self.type})) + + matches.add(id(self)) + return matches + + +class SubsSabBzProvider(Provider): + """SubsSabBz Provider.""" + languages = {Language('por', 'BR')} | {Language(l) for l in [ + 'bul', 'eng' + ]} + + def initialize(self): + self.session = Session() + self.session.headers['User-Agent'] = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36' + self.session.headers["Accept"] = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" + self.session.headers["Accept-Language"] = "en-US,en;q=0.5" + self.session.headers["Accept-Encoding"] = "gzip, deflate, br" + self.session.headers["DNT"] = "1" + self.session.headers["Connection"] = "keep-alive" + self.session.headers["Upgrade-Insecure-Requests"] = "1" + self.session.headers["Cache-Control"] = "max-age=0" + + def terminate(self): + self.session.close() + + def query(self, language, video): + subtitles = [] + isEpisode = isinstance(video, Episode) + + params = { + 'act': 'search', + 'movie': '', + 'select-language': '2', + 'upldr': '', + 'yr': '', + 'release': '' + } + + if isEpisode: + params['movie'] = "%s %02d %02d" % (sanitize(video.series), video.season, video.episode) + else: + params['yr'] = video.year + params['movie'] = (video.title) + + if language == 'en' or language == 'eng': + params['select-language'] = 1 + + logger.info('Searching subtitle %r', params) + response = self.session.post('http://subs.sab.bz/index.php?', params=params, allow_redirects=False, timeout=10, headers={ + 'Referer': 'http://subs.sab.bz/', + }) + + response.raise_for_status() + + if response.status_code != 200: + logger.debug('No subtitles found') + return subtitles + + soup = ParserBeautifulSoup(response.content, ['html.parser']) + rows = soup.findAll('tr', {'class': 'subs-row'}) + + # Search on first 10 rows only + for row in rows[:10]: + a_element_wrapper = row.find('td', { 'class': 'c2field' }) + if a_element_wrapper: + element = row.find('a') + if element: + link = element.get('href') + logger.info('Found subtitle link %r', link) + subtitles = subtitles + self.download_archive_and_add_subtitle_files(link, language, video) + + return subtitles + + def list_subtitles(self, video, languages): + return [s for l in languages for s in self.query(l, video)] + + def download_subtitle(self, subtitle): + pass + + def process_archive_subtitle_files(self, archiveStream, language, video): + subtitles = [] + type = 'episode' if isinstance(video, Episode) else 'movie' + for f in archiveStream.infolist(): + if f.filename.lower().endswith(('.srt', '.sub')): + logger.info('Found subtitle file %r', f.filename) + subtitle = SubsSabBzSubtitle(language, f.filename, type) + subtitle.content = archiveStream.read(f) + subtitles.append(subtitle) + return subtitles + + def download_archive_and_add_subtitle_files(self, link, language, video ): + logger.info('Downloading subtitle %r', link) + request = self.session.get(link, headers={ + 'Referer': 'http://subs.sab.bz/index.php?' + }) + request.raise_for_status() + + archive_stream = io.BytesIO(request.content) + if is_rarfile(archive_stream): + return self.process_archive_subtitle_files( RarFile(archive_stream), language, video ) + elif is_zipfile(archive_stream): + return self.process_archive_subtitle_files( ZipFile(archive_stream), language, video ) + else: + raise ValueError('Not a valid archive') diff --git a/libs/subliminal/providers/subsunacs.py b/libs/subliminal/providers/subsunacs.py new file mode 100644 index 000000000..e101fe23d --- /dev/null +++ b/libs/subliminal/providers/subsunacs.py @@ -0,0 +1,158 @@ +# -*- coding: utf-8 -*- +import logging +import re +import io +import os + +from rarfile import RarFile, is_rarfile +from zipfile import ZipFile, is_zipfile + +from babelfish import Language +from requests import Session +from guessit import guessit + +from . import ParserBeautifulSoup, Provider +from ..utils import sanitize, sanitize_release_group +from ..subtitle import Subtitle, fix_line_ending, guess_matches +from ..video import Episode +from ..video import Movie + +logger = logging.getLogger(__name__) + +class SubsUnacsSubtitle(Subtitle): + """SubsUnacs Subtitle.""" + provider_name = 'subsunacs' + + def __init__(self, langauge, filename, type): + super(SubsUnacsSubtitle, self).__init__(langauge) + self.langauge = langauge + self.filename = filename + self.type = type + + @property + def id(self): + return self.filename + + def get_matches(self, video): + matches = set() + + video_filename = video.name + video_filename = os.path.basename(video_filename) + video_filename, _ = os.path.splitext(video_filename) + video_filename = sanitize_release_group(video_filename) + + subtitle_filename = self.filename + subtitle_filename = os.path.basename(subtitle_filename) + subtitle_filename, _ = os.path.splitext(subtitle_filename) + subtitle_filename = sanitize_release_group(subtitle_filename) + + if video_filename == subtitle_filename: + matches.add('hash') + + matches |= guess_matches(video, guessit(self.filename, {'type': self.type})) + + matches.add(id(self)) + return matches + + +class SubsUnacsProvider(Provider): + """SubsUnacs Provider.""" + languages = {Language('por', 'BR')} | {Language(l) for l in [ + 'bul', 'eng' + ]} + + def initialize(self): + self.session = Session() + self.session.headers['User-Agent'] = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36' + self.session.headers["Accept"] = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" + self.session.headers["Accept-Language"] = "en-US,en;q=0.5" + self.session.headers["Accept-Encoding"] = "gzip, deflate, br" + self.session.headers["DNT"] = "1" + self.session.headers["Connection"] = "keep-alive" + self.session.headers["Upgrade-Insecure-Requests"] = "1" + self.session.headers["Cache-Control"] = "max-age=0" + + def terminate(self): + self.session.close() + + def query(self, language, video): + subtitles = [] + isEpisode = isinstance(video, Episode) + + params = { + 'm': '', + 'l': 0, + 'c': '', + 'y': '', + 'action': " Търси ", + 'a': '', + 'd': '', + 'u': '', + 'g': '', + 't': '', + 'imdbcheck': 1} + + if isEpisode: + params['m'] = "%s %02d %02d" % (sanitize(video.series), video.season, video.episode) + else: + params['y'] = video.year + params['m'] = (video.title) + + if language == 'en' or language == 'eng': + params['l'] = 1 + + logger.info('Searching subtitle %r', params) + response = self.session.post('https://subsunacs.net/search.php', params=params, allow_redirects=False, timeout=10, headers={ + 'Referer': 'https://subsunacs.net/index.php', + }) + + response.raise_for_status() + + if response.status_code != 200: + logger.debug('No subtitles found') + return subtitles + + soup = ParserBeautifulSoup(response.content, ['html.parser']) + rows = soup.findAll('td', {'class': 'tdMovie'}) + + # Search on first 10 rows only + for row in rows[:10]: + element = row.find('a', {'class': 'tooltip'}) + if element: + link = element.get('href') + logger.info('Found subtitle link %r', link) + subtitles = subtitles + self.download_archive_and_add_subtitle_files('https://subsunacs.net' + link, language, video) + + return subtitles + + def list_subtitles(self, video, languages): + return [s for l in languages for s in self.query(l, video)] + + def download_subtitle(self, subtitle): + pass + + def process_archive_subtitle_files(self, archiveStream, language, video): + subtitles = [] + type = 'episode' if isinstance(video, Episode) else 'movie' + for f in archiveStream.infolist(): + if f.filename.lower().endswith(('.srt', '.sub')): + logger.info('Found subtitle file %r', f.filename) + subtitle = SubsUnacsSubtitle(language, f.filename, type) + subtitle.content = archiveStream.read(f) + subtitles.append(subtitle) + return subtitles + + def download_archive_and_add_subtitle_files(self, link, language, video ): + logger.info('Downloading subtitle %r', link) + request = self.session.get(link, headers={ + 'Referer': 'https://subsunacs.net/search.php' + }) + request.raise_for_status() + + archive_stream = io.BytesIO(request.content) + if is_rarfile(archive_stream): + return self.process_archive_subtitle_files( RarFile(archive_stream), language, video ) + elif is_zipfile(archive_stream): + return self.process_archive_subtitle_files( ZipFile(archive_stream), language, video ) + else: + raise ValueError('Not a valid archive') From 8fd96a2dfd457bdca4392bcb3b9c4d70a6697a9a Mon Sep 17 00:00:00 2001 From: e01 Date: Tue, 29 Jan 2019 15:27:45 +0200 Subject: [PATCH 02/12] Add subsunacs.net and subs.sab.bz providers --- libs/subliminal/extensions.py | 4 +- libs/subliminal_patch/extensions.py | 3 +- libs/subliminal_patch/providers/subssabbz.py | 158 ++++++++++++++++++ libs/subliminal_patch/providers/subsunacs.py | 160 +++++++++++++++++++ views/settings.tpl | 30 ++++ 5 files changed, 353 insertions(+), 2 deletions(-) create mode 100644 libs/subliminal_patch/providers/subssabbz.py create mode 100644 libs/subliminal_patch/providers/subsunacs.py diff --git a/libs/subliminal/extensions.py b/libs/subliminal/extensions.py index 495b68efc..768c2e8d2 100644 --- a/libs/subliminal/extensions.py +++ b/libs/subliminal/extensions.py @@ -94,7 +94,9 @@ provider_manager = RegistrableExtensionManager('subliminal.providers', [ 'podnapisi = subliminal.providers.podnapisi:PodnapisiProvider', 'shooter = subliminal.providers.shooter:ShooterProvider', 'thesubdb = subliminal.providers.thesubdb:TheSubDBProvider', - 'tvsubtitles = subliminal.providers.tvsubtitles:TVsubtitlesProvider' + 'tvsubtitles = subliminal.providers.tvsubtitles:TVsubtitlesProvider', + 'subsunacs = subliminal.providers.subsunacs:SubsUnacsProvider', + 'subssabbz = subliminal.providers.subssabbz:SubsSabBzProvider' ]) #: Refiner manager diff --git a/libs/subliminal_patch/extensions.py b/libs/subliminal_patch/extensions.py index e155439a6..22198a24a 100644 --- a/libs/subliminal_patch/extensions.py +++ b/libs/subliminal_patch/extensions.py @@ -63,4 +63,5 @@ subliminal.refiner_manager.register('drone = subliminal_patch.refiners.drone:ref subliminal.refiner_manager.register('filebot = subliminal_patch.refiners.filebot:refine') subliminal.refiner_manager.register('file_info_file = subliminal_patch.refiners.file_info_file:refine') subliminal.refiner_manager.register('symlinks = subliminal_patch.refiners.symlinks:refine') - +subliminal.refiner_manager.register('subsunacs = subliminal.providers.subsunacs:SubsUnacsProvider') +subliminal.refiner_manager.register('subssabbz = subliminal.providers.subssabbz:SubsSabBzProvider') \ No newline at end of file diff --git a/libs/subliminal_patch/providers/subssabbz.py b/libs/subliminal_patch/providers/subssabbz.py new file mode 100644 index 000000000..22d8dc800 --- /dev/null +++ b/libs/subliminal_patch/providers/subssabbz.py @@ -0,0 +1,158 @@ +# -*- coding: utf-8 -*- +import logging +import re +import io +import os + +from bs4 import BeautifulSoup +from zipfile import ZipFile, is_zipfile +from rarfile import RarFile, is_rarfile +from requests import Session +from guessit import guessit +from subliminal_patch.providers import Provider +from subliminal_patch.subtitle import Subtitle +from subliminal_patch.utils import sanitize +from subliminal.exceptions import ProviderError +from subliminal.utils import sanitize_release_group +from subliminal.subtitle import guess_matches +from subliminal.video import Episode, Movie +from subliminal.subtitle import fix_line_ending +from subzero.language import Language + +logger = logging.getLogger(__name__) + +class SubsSabBzSubtitle(Subtitle): + """SubsSabBz Subtitle.""" + provider_name = 'subssabbz' + + def __init__(self, langauge, filename, type): + super(SubsSabBzSubtitle, self).__init__(langauge) + self.langauge = langauge + self.filename = filename + self.type = type + + @property + def id(self): + return self.filename + + def get_matches(self, video): + matches = set() + + video_filename = video.name + video_filename = os.path.basename(video_filename) + video_filename, _ = os.path.splitext(video_filename) + video_filename = sanitize_release_group(video_filename) + + subtitle_filename = self.filename + subtitle_filename = os.path.basename(subtitle_filename) + subtitle_filename, _ = os.path.splitext(subtitle_filename) + subtitle_filename = sanitize_release_group(subtitle_filename) + + if video_filename == subtitle_filename: + matches.add('hash') + + matches |= guess_matches(video, guessit(self.filename, {'type': self.type})) + + matches.add(id(self)) + return matches + + +class SubsSabBzProvider(Provider): + """SubsSabBz Provider.""" + languages = {Language('por', 'BR')} | {Language(l) for l in [ + 'bul', 'eng' + ]} + + def initialize(self): + self.session = Session() + self.session.headers['User-Agent'] = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36' + self.session.headers["Accept"] = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" + self.session.headers["Accept-Language"] = "en-US,en;q=0.5" + self.session.headers["Accept-Encoding"] = "gzip, deflate, br" + self.session.headers["DNT"] = "1" + self.session.headers["Connection"] = "keep-alive" + self.session.headers["Upgrade-Insecure-Requests"] = "1" + self.session.headers["Cache-Control"] = "max-age=0" + + def terminate(self): + self.session.close() + + def query(self, language, video): + subtitles = [] + isEpisode = isinstance(video, Episode) + + params = { + 'act': 'search', + 'movie': '', + 'select-language': '2', + 'upldr': '', + 'yr': '', + 'release': '' + } + + if isEpisode: + params['movie'] = "%s %02d %02d" % (sanitize(video.series), video.season, video.episode) + else: + params['yr'] = video.year + params['movie'] = (video.title) + + if language == 'en' or language == 'eng': + params['select-language'] = 1 + + logger.info('Searching subtitle %r', params) + response = self.session.post('http://subs.sab.bz/index.php?', params=params, allow_redirects=False, timeout=10, headers={ + 'Referer': 'http://subs.sab.bz/', + }) + + response.raise_for_status() + + if response.status_code != 200: + logger.debug('No subtitles found') + return subtitles + + soup = BeautifulSoup(response.content, 'html.parser') + rows = soup.findAll('tr', {'class': 'subs-row'}) + + # Search on first 10 rows only + for row in rows[:10]: + a_element_wrapper = row.find('td', { 'class': 'c2field' }) + if a_element_wrapper: + element = row.find('a') + if element: + link = element.get('href') + logger.info('Found subtitle link %r', link) + subtitles = subtitles + self.download_archive_and_add_subtitle_files(link, language, video) + + return subtitles + + def list_subtitles(self, video, languages): + return [s for l in languages for s in self.query(l, video)] + + def download_subtitle(self, subtitle): + pass + + def process_archive_subtitle_files(self, archiveStream, language, video): + 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.content = archiveStream.read(file_name) + subtitles.append(subtitle) + return subtitles + + def download_archive_and_add_subtitle_files(self, link, language, video ): + logger.info('Downloading subtitle %r', link) + request = self.session.get(link, headers={ + 'Referer': 'http://subs.sab.bz/index.php?' + }) + request.raise_for_status() + + archive_stream = io.BytesIO(request.content) + if is_rarfile(archive_stream): + return self.process_archive_subtitle_files( RarFile(archive_stream), language, video ) + elif is_zipfile(archive_stream): + return self.process_archive_subtitle_files( ZipFile(archive_stream), language, video ) + else: + raise ValueError('Not a valid archive') diff --git a/libs/subliminal_patch/providers/subsunacs.py b/libs/subliminal_patch/providers/subsunacs.py new file mode 100644 index 000000000..fa97e15b5 --- /dev/null +++ b/libs/subliminal_patch/providers/subsunacs.py @@ -0,0 +1,160 @@ +# -*- coding: utf-8 -*- +import logging +import re +import io +import os + +from bs4 import BeautifulSoup +from zipfile import ZipFile, is_zipfile +from rarfile import RarFile, is_rarfile +from requests import Session +from guessit import guessit +from subliminal_patch.providers import Provider +from subliminal_patch.subtitle import Subtitle +from subliminal_patch.utils import sanitize +from subliminal.exceptions import ProviderError +from subliminal.utils import sanitize_release_group +from subliminal.subtitle import guess_matches +from subliminal.video import Episode, Movie +from subliminal.subtitle import fix_line_ending +from subzero.language import Language + +logger = logging.getLogger(__name__) + +class SubsUnacsSubtitle(Subtitle): + """SubsUnacs Subtitle.""" + provider_name = 'subsunacs' + + def __init__(self, langauge, filename, type): + super(SubsUnacsSubtitle, self).__init__(langauge) + self.langauge = langauge + self.filename = filename + self.type = type + + @property + def id(self): + return self.filename + + def get_matches(self, video): + matches = set() + + video_filename = video.name + video_filename = os.path.basename(video_filename) + video_filename, _ = os.path.splitext(video_filename) + video_filename = sanitize_release_group(video_filename) + + subtitle_filename = self.filename + subtitle_filename = os.path.basename(subtitle_filename) + subtitle_filename, _ = os.path.splitext(subtitle_filename) + subtitle_filename = sanitize_release_group(subtitle_filename) + + if video_filename == subtitle_filename: + matches.add('hash') + + matches |= guess_matches(video, guessit(self.filename, {'type': self.type})) + + matches.add(id(self)) + return matches + + +class SubsUnacsProvider(Provider): + """SubsUnacs Provider.""" + languages = {Language('por', 'BR')} | {Language(l) for l in [ + 'bul', 'eng' + ]} + + def initialize(self): + self.session = Session() + self.session.headers['User-Agent'] = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36' + self.session.headers["Accept"] = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" + self.session.headers["Accept-Language"] = "en-US,en;q=0.5" + self.session.headers["Accept-Encoding"] = "gzip, deflate, br" + self.session.headers["DNT"] = "1" + self.session.headers["Connection"] = "keep-alive" + self.session.headers["Upgrade-Insecure-Requests"] = "1" + self.session.headers["Cache-Control"] = "max-age=0" + + def terminate(self): + self.session.close() + + def query(self, language, video): + subtitles = [] + isEpisode = isinstance(video, Episode) + + params = { + 'm': '', + 'l': 0, + 'c': '', + 'y': '', + 'action': " Търси ", + 'a': '', + 'd': '', + 'u': '', + 'g': '', + 't': '', + 'imdbcheck': 1} + + if isEpisode: + params['m'] = "%s %02d %02d" % (sanitize(video.series), video.season, video.episode) + else: + params['y'] = video.year + params['m'] = (video.title) + + if language == 'en' or language == 'eng': + params['l'] = 1 + + logger.info('Searching subtitle %r', params) + response = self.session.post('https://subsunacs.net/search.php', params=params, allow_redirects=False, timeout=10, headers={ + 'Referer': 'https://subsunacs.net/index.php', + }) + + response.raise_for_status() + + if response.status_code != 200: + logger.debug('No subtitles found') + return subtitles + + soup = BeautifulSoup(response.content, 'html.parser') + rows = soup.findAll('td', {'class': 'tdMovie'}) + + # Search on first 10 rows only + for row in rows[:10]: + element = row.find('a', {'class': 'tooltip'}) + if element: + link = element.get('href') + logger.info('Found subtitle link %r', link) + subtitles = subtitles + self.download_archive_and_add_subtitle_files('https://subsunacs.net' + link, language, video) + + return subtitles + + def list_subtitles(self, video, languages): + return [s for l in languages for s in self.query(l, video)] + + def download_subtitle(self, subtitle): + pass + + def process_archive_subtitle_files(self, archiveStream, language, video): + 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.content = archiveStream.read(file_name) + subtitles.append(subtitle) + return subtitles + + def download_archive_and_add_subtitle_files(self, link, language, video ): + logger.info('Downloading subtitle %r', link) + request = self.session.get(link, headers={ + 'Referer': 'https://subsunacs.net/search.php' + }) + request.raise_for_status() + + archive_stream = io.BytesIO(request.content) + if is_rarfile(archive_stream): + return self.process_archive_subtitle_files( RarFile(archive_stream), language, video ) + elif is_zipfile(archive_stream): + return self.process_archive_subtitle_files( ZipFile(archive_stream), language, video ) + else: + raise ValueError('Not a valid archive') diff --git a/views/settings.tpl b/views/settings.tpl index b22efc9e0..859575dc4 100644 --- a/views/settings.tpl +++ b/views/settings.tpl @@ -1271,6 +1271,36 @@ +
+
+ +
+
+
+ + +
+
+
+
+ +
+ +
+
+ +
+
+
+ + +
+
+
+
+ +
+
From 2e8cb7b1f515f2686db5b817e5e33e3dfa0521a8 Mon Sep 17 00:00:00 2001 From: e01 Date: Tue, 29 Jan 2019 15:28:37 +0200 Subject: [PATCH 03/12] Remove subsunacs and subssabbz providers from subliminal library. --- libs/subliminal/providers/subssabbz.py | 156 ------------------------ libs/subliminal/providers/subsunacs.py | 158 ------------------------- 2 files changed, 314 deletions(-) delete mode 100644 libs/subliminal/providers/subssabbz.py delete mode 100644 libs/subliminal/providers/subsunacs.py diff --git a/libs/subliminal/providers/subssabbz.py b/libs/subliminal/providers/subssabbz.py deleted file mode 100644 index 23e5c3cc1..000000000 --- a/libs/subliminal/providers/subssabbz.py +++ /dev/null @@ -1,156 +0,0 @@ -# -*- coding: utf-8 -*- -import logging -import re -import io -import os - -from rarfile import RarFile, is_rarfile -from zipfile import ZipFile, is_zipfile - -from babelfish import Language -from requests import Session -from guessit import guessit - -from . import ParserBeautifulSoup, Provider -from ..utils import sanitize, sanitize_release_group -from ..subtitle import Subtitle, fix_line_ending, guess_matches -from ..video import Episode -from ..video import Movie - -logger = logging.getLogger(__name__) - -class SubsSabBzSubtitle(Subtitle): - """SubsSabBz Subtitle.""" - provider_name = 'subssabbz' - - def __init__(self, langauge, filename, type): - super(SubsSabBzSubtitle, self).__init__(langauge) - self.langauge = langauge - self.filename = filename - self.type = type - - @property - def id(self): - return self.filename - - def get_matches(self, video): - matches = set() - - video_filename = video.name - video_filename = os.path.basename(video_filename) - video_filename, _ = os.path.splitext(video_filename) - video_filename = sanitize_release_group(video_filename) - - subtitle_filename = self.filename - subtitle_filename = os.path.basename(subtitle_filename) - subtitle_filename, _ = os.path.splitext(subtitle_filename) - subtitle_filename = sanitize_release_group(subtitle_filename) - - if video_filename == subtitle_filename: - matches.add('hash') - - matches |= guess_matches(video, guessit(self.filename, {'type': self.type})) - - matches.add(id(self)) - return matches - - -class SubsSabBzProvider(Provider): - """SubsSabBz Provider.""" - languages = {Language('por', 'BR')} | {Language(l) for l in [ - 'bul', 'eng' - ]} - - def initialize(self): - self.session = Session() - self.session.headers['User-Agent'] = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36' - self.session.headers["Accept"] = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" - self.session.headers["Accept-Language"] = "en-US,en;q=0.5" - self.session.headers["Accept-Encoding"] = "gzip, deflate, br" - self.session.headers["DNT"] = "1" - self.session.headers["Connection"] = "keep-alive" - self.session.headers["Upgrade-Insecure-Requests"] = "1" - self.session.headers["Cache-Control"] = "max-age=0" - - def terminate(self): - self.session.close() - - def query(self, language, video): - subtitles = [] - isEpisode = isinstance(video, Episode) - - params = { - 'act': 'search', - 'movie': '', - 'select-language': '2', - 'upldr': '', - 'yr': '', - 'release': '' - } - - if isEpisode: - params['movie'] = "%s %02d %02d" % (sanitize(video.series), video.season, video.episode) - else: - params['yr'] = video.year - params['movie'] = (video.title) - - if language == 'en' or language == 'eng': - params['select-language'] = 1 - - logger.info('Searching subtitle %r', params) - response = self.session.post('http://subs.sab.bz/index.php?', params=params, allow_redirects=False, timeout=10, headers={ - 'Referer': 'http://subs.sab.bz/', - }) - - response.raise_for_status() - - if response.status_code != 200: - logger.debug('No subtitles found') - return subtitles - - soup = ParserBeautifulSoup(response.content, ['html.parser']) - rows = soup.findAll('tr', {'class': 'subs-row'}) - - # Search on first 10 rows only - for row in rows[:10]: - a_element_wrapper = row.find('td', { 'class': 'c2field' }) - if a_element_wrapper: - element = row.find('a') - if element: - link = element.get('href') - logger.info('Found subtitle link %r', link) - subtitles = subtitles + self.download_archive_and_add_subtitle_files(link, language, video) - - return subtitles - - def list_subtitles(self, video, languages): - return [s for l in languages for s in self.query(l, video)] - - def download_subtitle(self, subtitle): - pass - - def process_archive_subtitle_files(self, archiveStream, language, video): - subtitles = [] - type = 'episode' if isinstance(video, Episode) else 'movie' - for f in archiveStream.infolist(): - if f.filename.lower().endswith(('.srt', '.sub')): - logger.info('Found subtitle file %r', f.filename) - subtitle = SubsSabBzSubtitle(language, f.filename, type) - subtitle.content = archiveStream.read(f) - subtitles.append(subtitle) - return subtitles - - def download_archive_and_add_subtitle_files(self, link, language, video ): - logger.info('Downloading subtitle %r', link) - request = self.session.get(link, headers={ - 'Referer': 'http://subs.sab.bz/index.php?' - }) - request.raise_for_status() - - archive_stream = io.BytesIO(request.content) - if is_rarfile(archive_stream): - return self.process_archive_subtitle_files( RarFile(archive_stream), language, video ) - elif is_zipfile(archive_stream): - return self.process_archive_subtitle_files( ZipFile(archive_stream), language, video ) - else: - raise ValueError('Not a valid archive') diff --git a/libs/subliminal/providers/subsunacs.py b/libs/subliminal/providers/subsunacs.py deleted file mode 100644 index e101fe23d..000000000 --- a/libs/subliminal/providers/subsunacs.py +++ /dev/null @@ -1,158 +0,0 @@ -# -*- coding: utf-8 -*- -import logging -import re -import io -import os - -from rarfile import RarFile, is_rarfile -from zipfile import ZipFile, is_zipfile - -from babelfish import Language -from requests import Session -from guessit import guessit - -from . import ParserBeautifulSoup, Provider -from ..utils import sanitize, sanitize_release_group -from ..subtitle import Subtitle, fix_line_ending, guess_matches -from ..video import Episode -from ..video import Movie - -logger = logging.getLogger(__name__) - -class SubsUnacsSubtitle(Subtitle): - """SubsUnacs Subtitle.""" - provider_name = 'subsunacs' - - def __init__(self, langauge, filename, type): - super(SubsUnacsSubtitle, self).__init__(langauge) - self.langauge = langauge - self.filename = filename - self.type = type - - @property - def id(self): - return self.filename - - def get_matches(self, video): - matches = set() - - video_filename = video.name - video_filename = os.path.basename(video_filename) - video_filename, _ = os.path.splitext(video_filename) - video_filename = sanitize_release_group(video_filename) - - subtitle_filename = self.filename - subtitle_filename = os.path.basename(subtitle_filename) - subtitle_filename, _ = os.path.splitext(subtitle_filename) - subtitle_filename = sanitize_release_group(subtitle_filename) - - if video_filename == subtitle_filename: - matches.add('hash') - - matches |= guess_matches(video, guessit(self.filename, {'type': self.type})) - - matches.add(id(self)) - return matches - - -class SubsUnacsProvider(Provider): - """SubsUnacs Provider.""" - languages = {Language('por', 'BR')} | {Language(l) for l in [ - 'bul', 'eng' - ]} - - def initialize(self): - self.session = Session() - self.session.headers['User-Agent'] = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36' - self.session.headers["Accept"] = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" - self.session.headers["Accept-Language"] = "en-US,en;q=0.5" - self.session.headers["Accept-Encoding"] = "gzip, deflate, br" - self.session.headers["DNT"] = "1" - self.session.headers["Connection"] = "keep-alive" - self.session.headers["Upgrade-Insecure-Requests"] = "1" - self.session.headers["Cache-Control"] = "max-age=0" - - def terminate(self): - self.session.close() - - def query(self, language, video): - subtitles = [] - isEpisode = isinstance(video, Episode) - - params = { - 'm': '', - 'l': 0, - 'c': '', - 'y': '', - 'action': " Търси ", - 'a': '', - 'd': '', - 'u': '', - 'g': '', - 't': '', - 'imdbcheck': 1} - - if isEpisode: - params['m'] = "%s %02d %02d" % (sanitize(video.series), video.season, video.episode) - else: - params['y'] = video.year - params['m'] = (video.title) - - if language == 'en' or language == 'eng': - params['l'] = 1 - - logger.info('Searching subtitle %r', params) - response = self.session.post('https://subsunacs.net/search.php', params=params, allow_redirects=False, timeout=10, headers={ - 'Referer': 'https://subsunacs.net/index.php', - }) - - response.raise_for_status() - - if response.status_code != 200: - logger.debug('No subtitles found') - return subtitles - - soup = ParserBeautifulSoup(response.content, ['html.parser']) - rows = soup.findAll('td', {'class': 'tdMovie'}) - - # Search on first 10 rows only - for row in rows[:10]: - element = row.find('a', {'class': 'tooltip'}) - if element: - link = element.get('href') - logger.info('Found subtitle link %r', link) - subtitles = subtitles + self.download_archive_and_add_subtitle_files('https://subsunacs.net' + link, language, video) - - return subtitles - - def list_subtitles(self, video, languages): - return [s for l in languages for s in self.query(l, video)] - - def download_subtitle(self, subtitle): - pass - - def process_archive_subtitle_files(self, archiveStream, language, video): - subtitles = [] - type = 'episode' if isinstance(video, Episode) else 'movie' - for f in archiveStream.infolist(): - if f.filename.lower().endswith(('.srt', '.sub')): - logger.info('Found subtitle file %r', f.filename) - subtitle = SubsUnacsSubtitle(language, f.filename, type) - subtitle.content = archiveStream.read(f) - subtitles.append(subtitle) - return subtitles - - def download_archive_and_add_subtitle_files(self, link, language, video ): - logger.info('Downloading subtitle %r', link) - request = self.session.get(link, headers={ - 'Referer': 'https://subsunacs.net/search.php' - }) - request.raise_for_status() - - archive_stream = io.BytesIO(request.content) - if is_rarfile(archive_stream): - return self.process_archive_subtitle_files( RarFile(archive_stream), language, video ) - elif is_zipfile(archive_stream): - return self.process_archive_subtitle_files( ZipFile(archive_stream), language, video ) - else: - raise ValueError('Not a valid archive') From aafc55f3cbfaa4b1ba8564d83840b67c0fd15607 Mon Sep 17 00:00:00 2001 From: e01 Date: Wed, 30 Jan 2019 09:14:17 +0200 Subject: [PATCH 04/12] Fix previously mess with providers registering on subssabbz and subsunacs --- .../providers/subssabbz.py | 16 ++++++++-------- .../providers/subsunacs.py | 0 libs/subliminal_patch/extensions.py | 2 -- 3 files changed, 8 insertions(+), 10 deletions(-) rename libs/{subliminal_patch => subliminal}/providers/subssabbz.py (98%) rename libs/{subliminal_patch => subliminal}/providers/subsunacs.py (100%) diff --git a/libs/subliminal_patch/providers/subssabbz.py b/libs/subliminal/providers/subssabbz.py similarity index 98% rename from libs/subliminal_patch/providers/subssabbz.py rename to libs/subliminal/providers/subssabbz.py index 22d8dc800..0cd8881ad 100644 --- a/libs/subliminal_patch/providers/subssabbz.py +++ b/libs/subliminal/providers/subssabbz.py @@ -37,7 +37,7 @@ class SubsSabBzSubtitle(Subtitle): def get_matches(self, video): matches = set() - + video_filename = video.name video_filename = os.path.basename(video_filename) video_filename, _ = os.path.splitext(video_filename) @@ -76,11 +76,11 @@ class SubsSabBzProvider(Provider): def terminate(self): self.session.close() - + def query(self, language, video): subtitles = [] isEpisode = isinstance(video, Episode) - + params = { 'act': 'search', 'movie': '', @@ -112,7 +112,7 @@ class SubsSabBzProvider(Provider): soup = BeautifulSoup(response.content, 'html.parser') rows = soup.findAll('tr', {'class': 'subs-row'}) - + # Search on first 10 rows only for row in rows[:10]: a_element_wrapper = row.find('td', { 'class': 'c2field' }) @@ -122,7 +122,7 @@ class SubsSabBzProvider(Provider): link = element.get('href') logger.info('Found subtitle link %r', link) subtitles = subtitles + self.download_archive_and_add_subtitle_files(link, language, video) - + return subtitles def list_subtitles(self, video, languages): @@ -130,7 +130,7 @@ class SubsSabBzProvider(Provider): def download_subtitle(self, subtitle): pass - + def process_archive_subtitle_files(self, archiveStream, language, video): subtitles = [] type = 'episode' if isinstance(video, Episode) else 'movie' @@ -141,11 +141,11 @@ class SubsSabBzProvider(Provider): subtitle.content = archiveStream.read(file_name) subtitles.append(subtitle) return subtitles - + def download_archive_and_add_subtitle_files(self, link, language, video ): logger.info('Downloading subtitle %r', link) request = self.session.get(link, headers={ - 'Referer': 'http://subs.sab.bz/index.php?' + 'Referer': 'http://subs.sab.bz/index.php?' }) request.raise_for_status() diff --git a/libs/subliminal_patch/providers/subsunacs.py b/libs/subliminal/providers/subsunacs.py similarity index 100% rename from libs/subliminal_patch/providers/subsunacs.py rename to libs/subliminal/providers/subsunacs.py diff --git a/libs/subliminal_patch/extensions.py b/libs/subliminal_patch/extensions.py index 22198a24a..5e20e8556 100644 --- a/libs/subliminal_patch/extensions.py +++ b/libs/subliminal_patch/extensions.py @@ -63,5 +63,3 @@ subliminal.refiner_manager.register('drone = subliminal_patch.refiners.drone:ref subliminal.refiner_manager.register('filebot = subliminal_patch.refiners.filebot:refine') subliminal.refiner_manager.register('file_info_file = subliminal_patch.refiners.file_info_file:refine') subliminal.refiner_manager.register('symlinks = subliminal_patch.refiners.symlinks:refine') -subliminal.refiner_manager.register('subsunacs = subliminal.providers.subsunacs:SubsUnacsProvider') -subliminal.refiner_manager.register('subssabbz = subliminal.providers.subssabbz:SubsSabBzProvider') \ No newline at end of file From 0bd2f2e68fa3969b4ae6069c9bc990d1bb459c29 Mon Sep 17 00:00:00 2001 From: e01 Date: Wed, 30 Jan 2019 19:36:32 +0200 Subject: [PATCH 05/12] Move providers to subliminal_patch --- libs/subliminal/extensions.py | 4 +--- libs/{subliminal => subliminal_patch}/providers/subssabbz.py | 5 +++-- libs/{subliminal => subliminal_patch}/providers/subsunacs.py | 5 +++-- 3 files changed, 7 insertions(+), 7 deletions(-) rename libs/{subliminal => subliminal_patch}/providers/subssabbz.py (96%) rename libs/{subliminal => subliminal_patch}/providers/subsunacs.py (96%) diff --git a/libs/subliminal/extensions.py b/libs/subliminal/extensions.py index 768c2e8d2..495b68efc 100644 --- a/libs/subliminal/extensions.py +++ b/libs/subliminal/extensions.py @@ -94,9 +94,7 @@ provider_manager = RegistrableExtensionManager('subliminal.providers', [ 'podnapisi = subliminal.providers.podnapisi:PodnapisiProvider', 'shooter = subliminal.providers.shooter:ShooterProvider', 'thesubdb = subliminal.providers.thesubdb:TheSubDBProvider', - 'tvsubtitles = subliminal.providers.tvsubtitles:TVsubtitlesProvider', - 'subsunacs = subliminal.providers.subsunacs:SubsUnacsProvider', - 'subssabbz = subliminal.providers.subssabbz:SubsSabBzProvider' + 'tvsubtitles = subliminal.providers.tvsubtitles:TVsubtitlesProvider' ]) #: Refiner manager diff --git a/libs/subliminal/providers/subssabbz.py b/libs/subliminal_patch/providers/subssabbz.py similarity index 96% rename from libs/subliminal/providers/subssabbz.py rename to libs/subliminal_patch/providers/subssabbz.py index 0cd8881ad..17df5b975 100644 --- a/libs/subliminal/providers/subssabbz.py +++ b/libs/subliminal_patch/providers/subssabbz.py @@ -3,7 +3,7 @@ import logging import re import io import os - +from random import randint from bs4 import BeautifulSoup from zipfile import ZipFile, is_zipfile from rarfile import RarFile, is_rarfile @@ -18,6 +18,7 @@ from subliminal.subtitle import guess_matches from subliminal.video import Episode, Movie from subliminal.subtitle import fix_line_ending from subzero.language import Language +from .utils import FIRST_THOUSAND_OR_SO_USER_AGENTS as AGENT_LIST logger = logging.getLogger(__name__) @@ -65,7 +66,7 @@ class SubsSabBzProvider(Provider): def initialize(self): self.session = Session() - self.session.headers['User-Agent'] = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36' + self.session.headers['User-Agent'] = AGENT_LIST[randint(0, len(AGENT_LIST) - 1)] self.session.headers["Accept"] = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" self.session.headers["Accept-Language"] = "en-US,en;q=0.5" self.session.headers["Accept-Encoding"] = "gzip, deflate, br" diff --git a/libs/subliminal/providers/subsunacs.py b/libs/subliminal_patch/providers/subsunacs.py similarity index 96% rename from libs/subliminal/providers/subsunacs.py rename to libs/subliminal_patch/providers/subsunacs.py index fa97e15b5..bbc41f520 100644 --- a/libs/subliminal/providers/subsunacs.py +++ b/libs/subliminal_patch/providers/subsunacs.py @@ -3,7 +3,7 @@ import logging import re import io import os - +from random import randint from bs4 import BeautifulSoup from zipfile import ZipFile, is_zipfile from rarfile import RarFile, is_rarfile @@ -18,6 +18,7 @@ from subliminal.subtitle import guess_matches from subliminal.video import Episode, Movie from subliminal.subtitle import fix_line_ending from subzero.language import Language +from .utils import FIRST_THOUSAND_OR_SO_USER_AGENTS as AGENT_LIST logger = logging.getLogger(__name__) @@ -65,7 +66,7 @@ class SubsUnacsProvider(Provider): def initialize(self): self.session = Session() - self.session.headers['User-Agent'] = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36' + self.session.headers['User-Agent'] = AGENT_LIST[randint(0, len(AGENT_LIST) - 1)] self.session.headers["Accept"] = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" self.session.headers["Accept-Language"] = "en-US,en;q=0.5" self.session.headers["Accept-Encoding"] = "gzip, deflate, br" From 1f8b5e84b8a2dc07fb0dde92ec8d579607e17d2d Mon Sep 17 00:00:00 2001 From: e01 Date: Wed, 30 Jan 2019 19:41:54 +0200 Subject: [PATCH 06/12] Add tooltips to provider checkboxes --- views/settings.tpl | 74 +++++++++++++++++++++++++++------------------- 1 file changed, 44 insertions(+), 30 deletions(-) diff --git a/views/settings.tpl b/views/settings.tpl index 859575dc4..ce23b5501 100644 --- a/views/settings.tpl +++ b/views/settings.tpl @@ -1271,36 +1271,6 @@
-
-
- -
-
-
- - -
-
-
-
- -
- -
-
- -
-
-
- - -
-
-
-
- -
-
@@ -1479,6 +1449,50 @@
+
+
+ +
+
+
+ + +
+
+ +
+
+ +
+ +
+
+ +
+
+
+ + +
+
+ +
+
+ +
+
+
+
+ +
+
+
+ + +
+
+ +
+
+ +
+
@@ -1404,6 +1426,28 @@
+
+
+ +
+
+
+ + +
+
+ +
+
+ +
+
@@ -1449,50 +1493,6 @@
-
-
- -
-
-
- - -
-
- -
-
- -
- -
-
- -
-
-
- - -
-
- -
-
- -
-