You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
4.2 KiB

13 years ago
# -*- coding: utf-8 -*-
# Copyright 2011-2012 Antoine Bertin <diaoulael@gmail.com>
#
# This file is part of subliminal.
#
# subliminal is free software; you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# subliminal is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with subliminal. If not, see <http://www.gnu.org/licenses/>.
from . import ServiceBase
13 years ago
from ..cache import cachedmethod
13 years ago
from ..exceptions import ServiceError
13 years ago
from ..language import language_set
13 years ago
from ..subtitles import get_subtitle_path, ResultSubtitle, EXTENSIONS
13 years ago
from ..utils import to_unicode
13 years ago
from ..videos import Episode
from bs4 import BeautifulSoup
13 years ago
import logging
import urllib
try:
import cPickle as pickle
except ImportError:
import pickle
logger = logging.getLogger(__name__)
class BierDopje(ServiceBase):
server_url = 'http://api.bierdopje.com/A2B638AC5D804C2E/'
13 years ago
user_agent = 'Subliminal/0.6'
13 years ago
api_based = True
13 years ago
languages = language_set(['eng', 'dut'])
13 years ago
videos = [Episode]
require_video = False
13 years ago
required_features = ['xml']
13 years ago
13 years ago
@cachedmethod
def get_show_id(self, series):
r = self.session.get('%sGetShowByName/%s' % (self.server_url, urllib.quote(series.lower())))
if r.status_code != 200:
logger.error(u'Request %s returned status code %d' % (r.url, r.status_code))
return None
soup = BeautifulSoup(r.content, self.required_features)
if soup.status.contents[0] == 'false':
logger.debug(u'Could not find show %s' % series)
return None
return int(soup.showid.contents[0])
13 years ago
def load_cache(self):
logger.debug(u'Loading showids from cache...')
with self.lock:
with open(self.showids_cache, 'r') as f:
self.showids = pickle.load(f)
13 years ago
def query(self, filepath, season, episode, languages, tvdbid=None, series=None):
self.init_cache()
13 years ago
if series:
13 years ago
request_id = self.get_show_id(series.lower())
if request_id is None:
return []
13 years ago
request_source = 'showid'
request_is_tvdbid = 'false'
elif tvdbid:
request_id = tvdbid
request_source = 'tvdbid'
request_is_tvdbid = 'true'
else:
raise ServiceError('One or more parameter missing')
subtitles = []
for language in languages:
13 years ago
logger.debug(u'Getting subtitles for %s %d season %d episode %d with language %s' % (request_source, request_id, season, episode, language.alpha2))
r = self.session.get('%sGetAllSubsFor/%s/%s/%s/%s/%s' % (self.server_url, request_id, season, episode, language.alpha2, request_is_tvdbid))
13 years ago
if r.status_code != 200:
logger.error(u'Request %s returned status code %d' % (r.url, r.status_code))
return []
13 years ago
soup = BeautifulSoup(r.content, self.required_features)
13 years ago
if soup.status.contents[0] == 'false':
13 years ago
logger.debug(u'Could not find subtitles for %s %d season %d episode %d with language %s' % (request_source, request_id, season, episode, language.alpha2))
13 years ago
continue
path = get_subtitle_path(filepath, language, self.config.multi)
for result in soup.results('result'):
13 years ago
release = to_unicode(result.filename.contents[0])
if not release.endswith(tuple(EXTENSIONS)):
release += '.srt'
subtitle = ResultSubtitle(path, language, self.__class__.__name__.lower(), result.downloadlink.contents[0],
release=release)
13 years ago
subtitles.append(subtitle)
return subtitles
13 years ago
def list_checked(self, video, languages):
return self.query(video.path or video.release, video.season, video.episode, languages, video.tvdbid, video.series)
13 years ago
Service = BierDopje