Skip to content

Commit

Permalink
Merge pull request #682 from ofir123/hotfix/subscenter_url
Browse files Browse the repository at this point in the history
Updated subscenter URLs and added redirection logic.
  • Loading branch information
Diaoul authored Sep 3, 2016
2 parents 12443b5 + 20082b8 commit 83f0d12
Show file tree
Hide file tree
Showing 12 changed files with 2,702 additions and 2,681 deletions.
25 changes: 16 additions & 9 deletions subliminal/providers/subscenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,20 @@ def get_matches(self, video):
class SubsCenterProvider(Provider):
"""SubsCenter Provider."""
languages = {Language.fromalpha2(l) for l in ['he']}
server_url = 'http://subscenter.cinemast.com/he/'
server_url = 'http://www.subscenter.co/he/'

def __init__(self, username=None, password=None):
if username is not None and password is None or username is None and password is not None:
raise ConfigurationError('Username and password must be specified')

self.session = None
self.username = username
self.password = password
self.logged_in = False

def initialize(self):
self.session = Session()
self.session.headers['User-Agent'] = 'Subliminal/%s' % __short_version__
self.session.headers['User-Agent'] = 'Subliminal/{}'.format(__short_version__)

# login
if self.username is not None and self.password is not None:
Expand Down Expand Up @@ -132,13 +133,19 @@ def _search_url_titles(self, title):
r = self.session.get(self.server_url + 'subtitle/search/', params={'q': title}, timeout=10)
r.raise_for_status()

# get the suggestions
soup = ParserBeautifulSoup(r.content, ['lxml', 'html.parser'])
links = soup.select('#processes div.generalWindowTop a')
logger.debug('Found %d suggestions', len(links))
# check for redirections
if r.history and all([h.status_code == 302 for h in r.history]):
logger.debug('Redirected to the subtitles page')
links = [r.url]
else:
# get the suggestions (if needed)
soup = ParserBeautifulSoup(r.content, ['lxml', 'html.parser'])
links = [link.attrs['href'] for link in soup.select('#processes div.generalWindowTop a')]
logger.debug('Found %d suggestions', len(links))

url_titles = defaultdict(list)
for link in links:
parts = link.attrs['href'].split('/')
parts = link.split('/')
url_titles[parts[-3]].append(parts[-2])

return url_titles
Expand All @@ -154,15 +161,15 @@ def query(self, title, season=None, episode=None):
return []
url_title = url_titles['series'][0]
logger.debug('Using series title %r', url_title)
url = self.server_url + 'cinemast/data/series/sb/{}/{}/{}/'.format(url_title, season, episode)
url = self.server_url + 'cst/data/series/sb/{}/{}/{}/'.format(url_title, season, episode)
page_link = self.server_url + 'subtitle/series/{}/{}/{}/'.format(url_title, season, episode)
else:
if 'movie' not in url_titles:
logger.error('No URL title found for movie %r', title)
return []
url_title = url_titles['movie'][0]
logger.debug('Using movie title %r', url_title)
url = self.server_url + 'cinemast/data/movie/sb/{}/'.format(url_title)
url = self.server_url + 'cst/data/movie/sb/{}/'.format(url_title)
page_link = self.server_url + 'subtitle/movie/{}/'.format(url_title)

# get the list of subtitles
Expand Down
465 changes: 233 additions & 232 deletions tests/cassettes/subscenter/test_download_subtitle.yaml

Large diffs are not rendered by default.

416 changes: 209 additions & 207 deletions tests/cassettes/subscenter/test_list_subtitles_episode.yaml

Large diffs are not rendered by default.

487 changes: 244 additions & 243 deletions tests/cassettes/subscenter/test_list_subtitles_movie.yaml

Large diffs are not rendered by default.

433 changes: 217 additions & 216 deletions tests/cassettes/subscenter/test_login.yaml

Large diffs are not rendered by default.

796 changes: 399 additions & 397 deletions tests/cassettes/subscenter/test_login_bad_password.yaml

Large diffs are not rendered by default.

788 changes: 395 additions & 393 deletions tests/cassettes/subscenter/test_logout.yaml

Large diffs are not rendered by default.

415 changes: 208 additions & 207 deletions tests/cassettes/subscenter/test_query_episode.yaml

Large diffs are not rendered by default.

441 changes: 221 additions & 220 deletions tests/cassettes/subscenter/test_query_movie.yaml

Large diffs are not rendered by default.

389 changes: 195 additions & 194 deletions tests/cassettes/subscenter/test_search_url_titles_episode.yaml

Large diffs are not rendered by default.

371 changes: 186 additions & 185 deletions tests/cassettes/subscenter/test_search_url_titles_movies.yaml

Large diffs are not rendered by default.

357 changes: 179 additions & 178 deletions tests/cassettes/subscenter/test_search_url_titles_no_suggestion.yaml

Large diffs are not rendered by default.

0 comments on commit 83f0d12

Please sign in to comment.