Compare commits
22 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 277b046b41 | |||
| c823eda245 | |||
| 6340de0ddb | |||
| 1ee700fa9d | |||
| 4f74dc9031 | |||
| b53fd0bd61 | |||
| 80e3514d56 | |||
| 3f1cac3ccc | |||
| 261e4e8f67 | |||
| bec7ec1901 | |||
| 69015293a4 | |||
| ca55e417ee | |||
| ed37415ee2 | |||
| 68dc99f7ab | |||
| 4d9cac8941 | |||
| fbd6fe00d6 | |||
| e491680dff | |||
| ffc8474918 | |||
| dd7f26e51e | |||
| f122e7e4ed | |||
| f4246de8a7 | |||
| 71c91bed29 |
@@ -1,6 +1,30 @@
|
||||
News
|
||||
====
|
||||
|
||||
0.6.4
|
||||
-----
|
||||
**release date:** 2013-05-19
|
||||
|
||||
* Fix requirements due to enzyme 0.3
|
||||
|
||||
0.6.3
|
||||
-----
|
||||
**release date:** 2013-01-17
|
||||
|
||||
* Fix requirements due to requests 1.0
|
||||
|
||||
0.6.2
|
||||
-----
|
||||
**release date:** 2012-09-15
|
||||
|
||||
* Fix BierDopje
|
||||
* Fix Addic7ed
|
||||
* Fix SubsWiki
|
||||
* Fix missing enzyme import
|
||||
* Add Catalan and Galician languages to Addic7ed
|
||||
* Add possible services in help message of the CLI
|
||||
* Allow existing filenames to be passed without the ./ prefix
|
||||
|
||||
0.6.1
|
||||
-----
|
||||
**release date:** 2012-06-24
|
||||
|
||||
+1
-1
Submodule docs/_themes updated: 4b7a0c3e43...78e39c975c
+2
-2
@@ -1,5 +1,5 @@
|
||||
beautifulsoup4>=4.0
|
||||
guessit>=0.4.1
|
||||
requests
|
||||
enzyme>=0.1
|
||||
requests<1.0
|
||||
enzyme<0.3
|
||||
html5lib
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ import sys
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description='Subtitles, faster than your thoughts')
|
||||
parser.add_argument('-l', '--language', action='append', dest='languages', help='wanted language (ISO 639-1)', metavar='LG')
|
||||
parser.add_argument('-s', '--service', action='append', dest='services', help='service to use', metavar='NAME')
|
||||
parser.add_argument('-s', '--service', action='append', dest='services', help='service to use (%s)' % ', '.join(subliminal.core.filter_services(subliminal.SERVICES)), metavar='NAME')
|
||||
parser.add_argument('-m', '--multi', action='store_true', help='download multiple subtitle languages')
|
||||
parser.add_argument('-f', '--force', action='store_true', help='replace existing subtitle file')
|
||||
parser.add_argument('-w', '--workers', action='store', help='use N threads (default: %(default)s)', metavar='N', type=int, default=4)
|
||||
|
||||
@@ -24,7 +24,7 @@ from setuptools import setup, find_packages
|
||||
def read(fname):
|
||||
return open(os.path.join(os.path.dirname(__file__), fname)).read()
|
||||
|
||||
required = ['beautifulsoup4 >= 4.0', 'guessit >= 0.4.1', 'requests', 'enzyme >= 0.1', 'html5lib']
|
||||
required = ['beautifulsoup4 >= 4.0', 'guessit >= 0.4.1', 'requests < 1.0', 'enzyme < 0.3', 'html5lib']
|
||||
if sys.hexversion < 0x20700f0:
|
||||
required.append('argparse >= 1.1')
|
||||
|
||||
|
||||
+1
-1
@@ -15,4 +15,4 @@
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with subliminal. If not, see <http://www.gnu.org/licenses/>.
|
||||
__version__ = '0.6.1'
|
||||
__version__ = '0.6.4'
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2012 Olivier Leveau <olifozzy@gmail.com>
|
||||
# Copyright 2012 Antoine Bertin <diaoulael@gmail.com>
|
||||
#
|
||||
# This file is part of subliminal.
|
||||
#
|
||||
@@ -20,7 +21,7 @@ from ..cache import cachedmethod
|
||||
from ..exceptions import DownloadFailedError
|
||||
from ..language import Language, language_set
|
||||
from ..subtitles import get_subtitle_path, ResultSubtitle
|
||||
from ..utils import get_keywords
|
||||
from ..utils import get_keywords, split_keyword
|
||||
from ..videos import Episode
|
||||
from bs4 import BeautifulSoup
|
||||
import logging
|
||||
@@ -31,97 +32,32 @@ import re
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def match(pattern, string):
|
||||
try:
|
||||
return re.search(pattern, string).group(1)
|
||||
except AttributeError:
|
||||
logger.debug(u'Could not match %r on %r' % (pattern, string))
|
||||
return None
|
||||
|
||||
|
||||
def matches(pattern, string):
|
||||
try:
|
||||
return re.search(pattern, string).group(1, 2)
|
||||
except AttributeError:
|
||||
logger.debug(u'Could not match %r on %r' % (pattern, string))
|
||||
return None
|
||||
|
||||
|
||||
class Addic7ed(ServiceBase):
|
||||
server_url = 'http://www.addic7ed.com'
|
||||
api_based = False
|
||||
#TODO: Complete this
|
||||
languages = language_set(['ar', 'ca', 'de', 'el', 'en', 'es', 'eu', 'fr', 'ga', 'he', 'hr', 'hu', 'it',
|
||||
'pl', 'pt', 'ro', 'ru', 'se', 'pt-br'])
|
||||
languages = language_set(['ar', 'ca', 'de', 'el', 'en', 'es', 'eu', 'fr', 'ga', 'gl', 'he', 'hr', 'hu',
|
||||
'it', 'pl', 'pt', 'ro', 'ru', 'se', 'pt-br'])
|
||||
language_map = {'Portuguese (Brazilian)': Language('por-BR'), 'Greek': Language('gre'),
|
||||
'Spanish (Latin America)': Language('spa'), }
|
||||
'Spanish (Latin America)': Language('spa'), 'Galego': Language('glg'),
|
||||
u'Català': Language('cat')}
|
||||
videos = [Episode]
|
||||
require_video = False
|
||||
required_features = ['permissive']
|
||||
|
||||
@cachedmethod
|
||||
def get_likely_series_id(self, name):
|
||||
def get_series_id(self, name):
|
||||
"""Get the show page and cache every show found in it"""
|
||||
r = self.session.get('%s/shows.php' % self.server_url)
|
||||
soup = BeautifulSoup(r.content, self.required_features)
|
||||
for elem in soup.find_all('h3'):
|
||||
show_name = elem.a.text.lower()
|
||||
show_id = int(match('show/([0-9]+)', elem.a['href']))
|
||||
# we could just return the id of the queried show, but as we
|
||||
# already downloaded the whole page we might as well fill in the
|
||||
# information for all the shows
|
||||
self.cache_for(self.get_likely_series_id, args=(show_name,), result=show_id)
|
||||
return self.cached_value(self.get_likely_series_id, args=(name,))
|
||||
|
||||
@cachedmethod
|
||||
def get_episode_url(self, series_id, season, number):
|
||||
"""Get the Addic7ed id for the given episode. Raises KeyError if none
|
||||
could be found
|
||||
|
||||
"""
|
||||
# download the page of the show, contains ids for all episodes all seasons
|
||||
r = self.session.get('%s/show/%d' % (self.server_url, series_id))
|
||||
soup = BeautifulSoup(r.content, self.required_features)
|
||||
form = soup.find('form', attrs={'name': 'multidl'})
|
||||
for table in form.find_all('table'):
|
||||
for row in table.find_all('tr'):
|
||||
cell = row.find('td', 'MultiDldS')
|
||||
if not cell:
|
||||
continue
|
||||
m = matches('/serie/.+/([0-9]+)/([0-9]+)/', cell.a['href'])
|
||||
if not m:
|
||||
continue
|
||||
episode_url = cell.a['href']
|
||||
season_number = int(m[0])
|
||||
episode_number = int(m[1])
|
||||
# we could just return the url of the queried episode, but as we
|
||||
# already downloaded the whole page we might as well fill in the
|
||||
# information for all the episodes of the show
|
||||
self.cache_for(self.get_episode_url, args=(series_id, season_number, episode_number), result=episode_url)
|
||||
# raises KeyError if not found
|
||||
return self.cached_value(self.get_episode_url, args=(series_id, season, number))
|
||||
|
||||
# Do not cache this method in order to always check for the most recent
|
||||
# subtitles
|
||||
def get_sub_urls(self, episode_url):
|
||||
suburls = []
|
||||
r = self.session.get('%s/%s' % (self.server_url, episode_url))
|
||||
epsoup = BeautifulSoup(r.content, self.required_features)
|
||||
for releaseTable in epsoup.find_all('table', 'tabel95'):
|
||||
releaseRow = releaseTable.find('td', 'NewsTitle')
|
||||
if not releaseRow:
|
||||
for html_series in soup.select('h3 > a'):
|
||||
series_name = html_series.text.lower()
|
||||
match = re.search('show/([0-9]+)', html_series['href'])
|
||||
if match is None:
|
||||
continue
|
||||
release = releaseRow.text.strip()
|
||||
for row in releaseTable.find_all('tr'):
|
||||
link = row.find('a', 'buttonDownload')
|
||||
if not link:
|
||||
continue
|
||||
if 'href' not in link.attrs or not (link['href'].startswith('/original') or link['href'].startswith('/updated')):
|
||||
continue
|
||||
suburl = link['href']
|
||||
lang = self.get_language(row.find('td', 'language').text.strip())
|
||||
result = {'suburl': suburl, 'language': lang, 'release': release}
|
||||
suburls.append(result)
|
||||
return suburls
|
||||
series_id = int(match.group(1))
|
||||
self.cache_for(self.get_series_id, args=(series_name,), result=series_id)
|
||||
return self.cached_value(self.get_series_id, args=(name,))
|
||||
|
||||
def list_checked(self, video, languages):
|
||||
return self.query(video.path or video.release, languages, get_keywords(video.guess), video.series, video.season, video.episode)
|
||||
@@ -130,25 +66,36 @@ class Addic7ed(ServiceBase):
|
||||
logger.debug(u'Getting subtitles for %s season %d episode %d with languages %r' % (series, season, episode, languages))
|
||||
self.init_cache()
|
||||
try:
|
||||
sid = self.get_likely_series_id(series.lower())
|
||||
series_id = self.get_series_id(series.lower())
|
||||
except KeyError:
|
||||
logger.debug(u'Could not find series id for %s' % series)
|
||||
return []
|
||||
try:
|
||||
ep_url = self.get_episode_url(sid, season, episode)
|
||||
except KeyError:
|
||||
logger.debug(u'Could not find episode id for %s season %d episode %d' % (series, season, episode))
|
||||
return []
|
||||
suburls = self.get_sub_urls(ep_url)
|
||||
# filter the subtitles with our queried languages
|
||||
r = self.session.get('%s/show/%d&season=%d' % (self.server_url, series_id, season))
|
||||
soup = BeautifulSoup(r.content, self.required_features)
|
||||
subtitles = []
|
||||
for suburl in suburls:
|
||||
language = suburl['language']
|
||||
if language not in languages:
|
||||
for row in soup('tr', {'class': 'epeven completed'}):
|
||||
cells = row('td')
|
||||
if int(cells[0].text.strip()) != season or int(cells[1].text.strip()) != episode:
|
||||
continue
|
||||
path = get_subtitle_path(filepath, language, self.config.multi)
|
||||
subtitle = ResultSubtitle(path, language, self.__class__.__name__.lower(), '%s/%s' % (self.server_url, suburl['suburl']),
|
||||
keywords=[suburl['release']])
|
||||
if cells[6].text.strip():
|
||||
logger.debug(u'Skipping hearing impaired')
|
||||
continue
|
||||
sub_status = cells[5].text.strip()
|
||||
if sub_status != 'Completed':
|
||||
logger.debug(u'Wrong subtitle status %s' % sub_status)
|
||||
continue
|
||||
sub_language = self.get_language(cells[3].text.strip())
|
||||
if sub_language not in languages:
|
||||
logger.debug(u'Language %r not in wanted languages %r' % (sub_language, languages))
|
||||
continue
|
||||
sub_keywords = split_keyword(cells[4].text.strip().lower())
|
||||
#TODO: Maybe allow empty keywords here? (same in Subtitulos)
|
||||
if not keywords & sub_keywords:
|
||||
logger.debug(u'None of subtitle keywords %r in %r' % (sub_keywords, keywords))
|
||||
continue
|
||||
sub_link = '%s/%s' % (self.server_url, cells[9].a['href'])
|
||||
sub_path = get_subtitle_path(filepath, sub_language, self.config.multi)
|
||||
subtitle = ResultSubtitle(sub_path, sub_language, self.__class__.__name__.lower(), sub_link, keywords=sub_keywords)
|
||||
subtitles.append(subtitle)
|
||||
return subtitles
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
class BierDopje(ServiceBase):
|
||||
server_url = 'http://api.bierdopje.com/A2B638AC5D804C2E/'
|
||||
user_agent = 'Subliminal/0.6'
|
||||
api_based = True
|
||||
languages = language_set(['eng', 'dut'])
|
||||
videos = [Episode]
|
||||
|
||||
@@ -19,11 +19,10 @@ from . import ServiceBase
|
||||
from ..exceptions import ServiceError
|
||||
from ..language import language_set, Language
|
||||
from ..subtitles import get_subtitle_path, ResultSubtitle
|
||||
from ..utils import get_keywords, split_keyword
|
||||
from ..videos import Episode, Movie
|
||||
from bs4 import BeautifulSoup
|
||||
from subliminal.utils import get_keywords, split_keyword
|
||||
import logging
|
||||
import re
|
||||
import urllib
|
||||
|
||||
|
||||
@@ -40,7 +39,6 @@ class SubsWiki(ServiceBase):
|
||||
language_code = 'name'
|
||||
videos = [Episode, Movie]
|
||||
require_video = False
|
||||
release_pattern = re.compile('\nVersion (.+), ([0-9]+).([0-9])+ MBs')
|
||||
required_features = ['permissive']
|
||||
|
||||
def list_checked(self, video, languages):
|
||||
@@ -78,22 +76,22 @@ class SubsWiki(ServiceBase):
|
||||
soup = BeautifulSoup(r.content, self.required_features)
|
||||
subtitles = []
|
||||
for sub in soup('td', {'class': 'NewsTitle'}):
|
||||
sub_keywords = split_keyword(self.release_pattern.search(sub.contents[1]).group(1).lower())
|
||||
sub_keywords = split_keyword(sub.b.string.lower())
|
||||
if not keywords & sub_keywords:
|
||||
logger.debug(u'None of subtitle keywords %r in %r' % (sub_keywords, keywords))
|
||||
continue
|
||||
for html_language in sub.parent.parent.findAll('td', {'class': 'language'}):
|
||||
for html_language in sub.parent.parent.find_all('td', {'class': 'language'}):
|
||||
language = self.get_language(html_language.string.strip())
|
||||
if language not in languages:
|
||||
logger.debug(u'Language %r not in wanted languages %r' % (language, languages))
|
||||
continue
|
||||
html_status = html_language.findNextSibling('td')
|
||||
status = html_status.find('strong').string.strip()
|
||||
if status != 'Completed':
|
||||
html_status = html_language.find_next_sibling('td')
|
||||
status = html_status.strong.string.strip()
|
||||
if status != 'Completado':
|
||||
logger.debug(u'Wrong subtitle status %s' % status)
|
||||
continue
|
||||
path = get_subtitle_path(filepath, language, self.config.multi)
|
||||
subtitle = ResultSubtitle(path, language, self.__class__.__name__.lower(), '%s%s' % (self.server_url, html_status.findNext('td').find('a')['href']))
|
||||
subtitle = ResultSubtitle(path, language, self.__class__.__name__.lower(), '%s%s' % (self.server_url, html_status.find_next('td').find('a')['href']))
|
||||
subtitles.append(subtitle)
|
||||
return subtitles
|
||||
|
||||
|
||||
@@ -18,9 +18,9 @@
|
||||
from . import ServiceBase
|
||||
from ..language import language_set, Language
|
||||
from ..subtitles import get_subtitle_path, ResultSubtitle
|
||||
from ..utils import get_keywords, split_keyword
|
||||
from ..videos import Episode
|
||||
from bs4 import BeautifulSoup
|
||||
from subliminal.utils import get_keywords, split_keyword
|
||||
import logging
|
||||
import re
|
||||
import unicodedata
|
||||
|
||||
@@ -23,7 +23,7 @@ import os.path
|
||||
__all__ = ['Subtitle', 'EmbeddedSubtitle', 'ExternalSubtitle', 'ResultSubtitle', 'get_subtitle_path']
|
||||
|
||||
#: Subtitles extensions
|
||||
EXTENSIONS = ['.srt', '.sub', '.txt']
|
||||
EXTENSIONS = ['.srt', '.sub', '.txt', '.ass']
|
||||
|
||||
|
||||
class Subtitle(object):
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
from . import subtitles
|
||||
from .language import Language
|
||||
from .utils import to_unicode
|
||||
import enzyme
|
||||
import enzyme.core
|
||||
import guessit
|
||||
import hashlib
|
||||
import logging
|
||||
@@ -135,6 +135,8 @@ class Video(object):
|
||||
# brackets inside the filename, so we have to use basic string
|
||||
# startswith/endswith comparisons
|
||||
folder, basename = os.path.split(basepath)
|
||||
if folder == '':
|
||||
folder = '.'
|
||||
existing = [f for f in os.listdir(folder) if f.startswith(basename)]
|
||||
for path in existing:
|
||||
for ext in subtitles.EXTENSIONS:
|
||||
|
||||
@@ -136,7 +136,7 @@ class Addic7edTestCase(ServiceTestCase):
|
||||
# FIXME: this is the size of the first subtitle that appears on the page
|
||||
# which is the original one, not the most updated one. We should make
|
||||
# sure the Addic7ed service picks up the most recent one instead
|
||||
self.episode_subfilesizes = [33538, 33643]
|
||||
self.episode_subfilesizes = [33469]
|
||||
self.episode_keywords = set(['asap', 'hdtv'])
|
||||
self.series = 'The Big Bang Theory'
|
||||
self.wrong_series = 'No Existent Show Name'
|
||||
@@ -172,7 +172,7 @@ class BierDopjeTestCase(ServiceTestCase):
|
||||
self.config = ServiceConfig(multi=True, cache_dir=cache_dir)
|
||||
self.episode_path = u'The Big Bang Theory/Season 05/S05E06 - The Rhinitis Revelation - HD TV.mkv'
|
||||
self.episode_sublanguage = 'en'
|
||||
self.episode_subfilesizes = [33469]
|
||||
self.episode_subfilesizes = [28982]
|
||||
self.movie_path = u'Inception (2010)/Inception - 1080p.mkv'
|
||||
self.movie_sublanguage = 'en'
|
||||
self.movie_subfilesizes = []
|
||||
@@ -244,7 +244,7 @@ class OpenSubtitlesTestCase(ServiceTestCase):
|
||||
self.fake_file = u'/tmp/fake_file'
|
||||
self.episode_path = existing_video
|
||||
self.episode_sublanguage = 'en'
|
||||
self.episode_subfilesizes = [30374, 30358, 33585, 33547, 33563, 33601]
|
||||
self.episode_subfilesizes = [30374, 30358, 33585, 33547, 33563, 33601, 31413, 31429]
|
||||
self.movie = 'Inception'
|
||||
self.imdbid = '1375666'
|
||||
self.wrong_imdbid = '9999999'
|
||||
|
||||
@@ -51,6 +51,7 @@ class ApiTestCase(unittest.TestCase):
|
||||
self.assertTrue(video.release == test_video)
|
||||
self.assertTrue(len(subtitles) == 1)
|
||||
for subtitle in subtitles:
|
||||
self.assertTrue(subtitle.path == os.path.splitext(os.path.basename(test_video))[0] + '.srt')
|
||||
self.assertTrue(os.path.exists(subtitle.path))
|
||||
os.remove(subtitle.path)
|
||||
|
||||
@@ -118,6 +119,7 @@ class AsyncTestCase(unittest.TestCase):
|
||||
self.assertTrue(video.release == test_video)
|
||||
self.assertTrue(len(subtitles) == 1)
|
||||
for subtitle in subtitles:
|
||||
self.assertTrue(subtitle.path == os.path.splitext(os.path.basename(test_video))[0] + '.srt')
|
||||
self.assertTrue(os.path.exists(subtitle.path))
|
||||
os.remove(subtitle.path)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user