本文整理汇总了Python中babelfish.Language.fromaddic7ed方法的典型用法代码示例。如果您正苦于以下问题:Python Language.fromaddic7ed方法的具体用法?Python Language.fromaddic7ed怎么用?Python Language.fromaddic7ed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类babelfish.Language
的用法示例。
在下文中一共展示了Language.fromaddic7ed方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: query
# 需要导入模块: from babelfish import Language [as 别名]
# 或者: from babelfish.Language import fromaddic7ed [as 别名]
def query(self, series, season, year=None, country=None):
# get the show id
show_id = self.get_show_id(series, year, country)
if show_id is None:
logger.error('No show id found for %r (%r)', series, {'year': year, 'country': country})
return []
# 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 + 'show/%d' % show_id, params={'season': season}, timeout=10)
r.raise_for_status()
if not r.content:
# Provider returns a status of 304 Not Modified with an empty content
# raise_for_status won't raise exception for that status code
logger.debug('No data returned from provider')
return []
soup = ParserBeautifulSoup(r.content, ['lxml', 'html.parser'])
# loop over subtitle rows
match = series_year_re.match(soup.select('#header font')[0].text.strip()[:-10])
series = match.group('series')
year = int(match.group('year')) if match.group('year') else None
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)
return subtitles
示例2: query
# 需要导入模块: from babelfish import Language [as 别名]
# 或者: from babelfish.Language import fromaddic7ed [as 别名]
def query(self, series, season, year=None, country=None):
# get the show id
show_id = self.get_show_id(series, year, country)
if show_id is None:
logger.error("No show id found for %r (%r)", series, {"year": year, "country": country})
return []
# 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 + "show/%d" % show_id, params={"season": season}, timeout=10)
r.raise_for_status()
if r.status_code == 304:
raise TooManyRequests()
soup = ParserBeautifulSoup(r.content, ["lxml", "html.parser"])
# loop over subtitle rows
match = series_year_re.match(soup.select("#header font")[0].text.strip()[:-10])
series = match.group("series")
year = int(match.group("year")) if match.group("year") else None
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 = Addic7edSubtitle(
language, hearing_impaired, page_link, series, season, episode, title, year, version, download_link
)
logger.debug("Found subtitle %r", subtitle)
subtitles.append(subtitle)
return subtitles