def query(self, show_id, series, season, year=None, country=None): # patch: fix logging # get the page of the season of the show logger.info('Getting the page of show id %d, season %d', show_id, season) r = self.session.get(self.server_url + 'ajax_loadShow.php', params={'show': show_id, 'season': season}, timeout=10, headers={ "referer": "%sshow/%s" % (self.server_url, show_id), "X-Requested-With": "XMLHttpRequest" } ) r.raise_for_status() if r.status_code == 304: raise TooManyRequests() if not r.content: # Provider wrongful return a status of 304 Not Modified with an empty content # raise_for_status won't raise exception for that status code logger.error('No data returned from provider') return [] soup = ParserBeautifulSoup(r.content, ['lxml', 'html.parser']) # loop over subtitle rows subtitles = [] for row in soup.select('tr.epeven'): cells = row('td') # ignore incomplete subtitles status = cells[5].text if status != 'Completed': logger.debug('Ignoring subtitle with status %s', status) continue # read the item language = Language.fromaddic7ed(cells[3].text) hearing_impaired = bool(cells[6].text) page_link = self.server_url + cells[2].a['href'][1:] season = int(cells[0].text) episode = int(cells[1].text) title = cells[2].text version = cells[4].text download_link = cells[9].a['href'][1:] subtitle = self.subtitle_class(language, hearing_impaired, page_link, series, season, episode, title, year, version, download_link) logger.debug('Found subtitle %r', subtitle) subtitles.append(subtitle) soup.decompose() soup = None return subtitles
def query_movie(self, movie_id, title, year=None): # get the page of the movie logger.info('Getting the page of movie id %s', movie_id) r = self.session.get(self.server_url + 'movie/' + movie_id, timeout=10, headers={ "referer": self.server_url, "X-Requested-With": "XMLHttpRequest" } ) r.raise_for_status() if r.status_code == 304: raise TooManyRequests() if not r.text: # Provider wrongful return a status of 304 Not Modified with an empty content # raise_for_status won't raise exception for that status code logger.error('No data returned from provider') return [] soup = ParserBeautifulSoup(r.content, ['lxml', 'html.parser']) # loop over subtitle rows tables = [] subtitles = [] for table in soup.find_all('table', {'align': 'center', 'border': '0', 'class': 'tabel95', 'width': '100%'}): if table.find_all('td', {'class': 'NewsTitle'}): tables.append(table) for table in tables: row1 = table.contents[1] row2 = table.contents[4] row3 = table.contents[6] # other rows are useless # ignore incomplete subtitles status = row2.contents[6].text if "%" in status: logger.debug('Ignoring subtitle with status %s', status) continue # read the item try: language = Language.fromaddic7ed(row2.contents[4].text.strip('\n')) except babelfish.exceptions.LanguageReverseError as error: logger.debug("Language error: %s, Ignoring subtitle", error) continue hearing_impaired = bool(row3.contents[1].contents[1].attrs['src'].endswith('hi.jpg')) page_link = self.server_url + 'movie/' + movie_id # Seems like Addic7ed returns the first word in the language of the user (Version, Versión, etc) # As we can't match a regex, we will just strip the first word try: version = " ".join(str(row1.contents[1].contents[1]).split()[1:]) version_matches = re.search(r"(.+),.+", version) version = version_matches.group(1) if version_matches else None except IndexError: version = None try: download_link = row2.contents[8].contents[3].attrs['href'][1:] except IndexError: download_link = row2.contents[8].contents[2].attrs['href'][1:] uploader = row1.contents[2].contents[8].text.strip() # set subtitle language to hi if it's hearing_impaired if hearing_impaired: language = Language.rebuild(language, hi=True) subtitle = self.subtitle_class(language, hearing_impaired, page_link, None, None, None, title, year, version, download_link, uploader) logger.debug('Found subtitle %r', subtitle) subtitles.append(subtitle) soup.decompose() soup = None return subtitles