From a5113387ccbdb973dff488b6b0880b1ba91b71aa Mon Sep 17 00:00:00 2001 From: medariox Date: Thu, 7 Apr 2016 18:00:39 +0200 Subject: [PATCH] Add back shooter and fixes --- lib/subliminal/core.py | 3 ++- lib/subliminal/providers/podnapisi.py | 2 +- lib/subliminal/providers/shooter.py | 1 + lib/subliminal/utils.py | 22 ++++++++++++++++++++++ 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/lib/subliminal/core.py b/lib/subliminal/core.py index aee352321c..6c1d537598 100644 --- a/lib/subliminal/core.py +++ b/lib/subliminal/core.py @@ -17,7 +17,7 @@ from .extensions import provider_manager, refiner_manager from .score import compute_score as default_compute_score from .subtitle import SUBTITLE_EXTENSIONS, get_subtitle_path -from .utils import hash_napiprojekt, hash_opensubtitles, hash_thesubdb, hash_itasa +from .utils import hash_itasa, hash_napiprojekt, hash_opensubtitles, hash_shooter, hash_thesubdb from .video import VIDEO_EXTENSIONS, Episode, Movie, Video #: Supported archive extensions @@ -385,6 +385,7 @@ def scan_video(path): logger.debug('Size is %d', video.size) video.hashes['itasa'] = hash_itasa(path) video.hashes['opensubtitles'] = hash_opensubtitles(path) + video.hashes['shooter'] = hash_shooter(path) video.hashes['thesubdb'] = hash_thesubdb(path) video.hashes['napiprojekt'] = hash_napiprojekt(path) logger.debug('Computed hashes %r', video.hashes) diff --git a/lib/subliminal/providers/podnapisi.py b/lib/subliminal/providers/podnapisi.py index f643682b90..f618a6b8cd 100644 --- a/lib/subliminal/providers/podnapisi.py +++ b/lib/subliminal/providers/podnapisi.py @@ -82,7 +82,7 @@ class PodnapisiProvider(Provider): """Podnapisi Provider.""" languages = ({Language('por', 'BR'), Language('srp', script='Latn')} | {Language.fromalpha2(l) for l in language_converters['alpha2'].codes}) - server_url = 'http://podnapisi.net/subtitles/' + server_url = 'http://podnapisi.eu/subtitles/' def initialize(self): self.session = Session() diff --git a/lib/subliminal/providers/shooter.py b/lib/subliminal/providers/shooter.py index 69d69bef32..5218cd0d53 100644 --- a/lib/subliminal/providers/shooter.py +++ b/lib/subliminal/providers/shooter.py @@ -24,6 +24,7 @@ def __init__(self, language, hash, download_link): self.hash = hash self.download_link = download_link + @property def id(self): return self.download_link diff --git a/lib/subliminal/utils.py b/lib/subliminal/utils.py index c370f19f12..e3fc660508 100644 --- a/lib/subliminal/utils.py +++ b/lib/subliminal/utils.py @@ -5,6 +5,7 @@ import re import struct + def hash_itasa(video_path): """Compute a hash using ItaSA's algorithm. @@ -49,6 +50,27 @@ def hash_opensubtitles(video_path): return returnedhash +def hash_shooter(video_path): + """Compute a hash using Shooter's algorithm + + :param string video_path: path of the video + :return: the hash + :rtype: string + + """ + filesize = os.path.getsize(video_path) + readsize = 4096 + if os.path.getsize(video_path) < readsize * 2: + return None + offsets = (readsize, filesize // 3 * 2, filesize // 3, filesize - readsize * 2) + filehash = [] + with open(video_path, 'rb') as f: + for offset in offsets: + f.seek(offset) + filehash.append(hashlib.md5(f.read(readsize)).hexdigest()) + return ';'.join(filehash) + + def hash_thesubdb(video_path): """Compute a hash using TheSubDB's algorithm.