本文整理汇总了Python中babelfish.Language.fromtvsubtitles方法的典型用法代码示例。如果您正苦于以下问题:Python Language.fromtvsubtitles方法的具体用法?Python Language.fromtvsubtitles怎么用?Python Language.fromtvsubtitles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类babelfish.Language
的用法示例。
在下文中一共展示了Language.fromtvsubtitles方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: query
# 需要导入模块: from babelfish import Language [as 别名]
# 或者: from babelfish.Language import fromtvsubtitles [as 别名]
def query(self, series, season, episode, year=None):
# search the show id
show_id = self.search_show_id(series, year)
if show_id is None:
logger.error('No show id found for %r (%r)', series, {'year': year})
return []
# get the episode ids
episode_ids = self.get_episode_ids(show_id, season)
if episode not in episode_ids:
logger.error('Episode %d not found', episode)
return []
# get the episode page
logger.info('Getting the page for episode %d', episode_ids[episode])
r = self.session.get(self.server_url + 'episode-%d.html' % episode_ids[episode], timeout=10)
soup = ParserBeautifulSoup(r.content, ['lxml', 'html.parser'])
# loop over subtitles rows
subtitles = []
for row in soup.select('.subtitlen'):
# read the item
language = Language.fromtvsubtitles(row.h5.img['src'][13:-4])
subtitle_id = int(row.parent['href'][10:-5])
page_link = self.server_url + 'subtitle-%d.html' % subtitle_id
rip = row.find('p', title='rip').text.strip() or None
release = row.find('p', title='release').text.strip() or None
subtitle = TVsubtitlesSubtitle(language, page_link, subtitle_id, series, season, episode, year, rip,
release)
logger.debug('Found subtitle %s', subtitle)
subtitles.append(subtitle)
return subtitles
示例2: query
# 需要导入模块: from babelfish import Language [as 别名]
# 或者: from babelfish.Language import fromtvsubtitles [as 别名]
def query(self, series, season, episode, year=None):
# search the show id
show_id = self.search_show_id(series, year)
if show_id is None:
logger.error("No show id found for %r (%r)", series, {"year": year})
return []
# get the episode ids
episode_ids = self.get_episode_ids(show_id, season)
if episode not in episode_ids:
logger.error("Episode %d not found", episode)
return []
# get the episode page
logger.info("Getting the page for episode %d", episode_ids[episode])
r = self.session.get(self.server_url + "episode-%d.html" % episode_ids[episode], timeout=10)
soup = ParserBeautifulSoup(r.content, ["lxml", "html.parser"])
# loop over subtitles rows
subtitles = []
for row in soup.select(".subtitlen"):
# read the item
language = Language.fromtvsubtitles(row.h5.img["src"][13:-4])
subtitle_id = int(row.parent["href"][10:-5])
page_link = self.server_url + "subtitle-%d.html" % subtitle_id
rip = row.find("p", title="rip").text.strip() or None
release = row.find("p", title="release").text.strip() or None
subtitle = TVsubtitlesSubtitle(
language, page_link, subtitle_id, series, season, episode, year, rip, release
)
logger.debug("Found subtitle %s", subtitle)
subtitles.append(subtitle)
return subtitles