Subliminal update
This commit is contained in:
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
+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.2'
|
||||
|
||||
Regular → Executable
Regular → Executable
Regular → Executable
+40
-93
@@ -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
|
||||
|
||||
|
||||
Regular → Executable
+1
@@ -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]
|
||||
|
||||
Regular → Executable
Regular → Executable
Regular → Executable
+7
-9
@@ -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
|
||||
|
||||
|
||||
Regular → Executable
+1
-1
@@ -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
|
||||
|
||||
Regular → Executable
Regular → Executable
Regular → Executable
+1
-1
@@ -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):
|
||||
|
||||
Regular → Executable
Regular → Executable
Regular → Executable
+3
-1
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user