本文整理汇总了Python中guessit.guessit方法的典型用法代码示例。如果您正苦于以下问题:Python guessit.guessit方法的具体用法?Python guessit.guessit怎么用?Python guessit.guessit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类guessit
的用法示例。
在下文中一共展示了guessit.guessit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: download
# 需要导入模块: import guessit [as 别名]
# 或者: from guessit import guessit [as 别名]
def download(self, video_file):
subtitle = None
settings = get_settings()
download_dir = settings.save_path
log.info("Downloading subtitle")
filepath = join(download_dir, video_file[0])
guess = guessit(filepath)
video = Video.fromguess(filepath, guess)
video.size = video_file[1]
try:
subtitles = download_best_subtitles([video], {Language(self.lang)},
only_one=True)
except ValueError:
pass
if subtitles is not None and len(subtitles):
subs = subtitles.values()[0]
if len(subs):
save_subtitles(video, subs, single=True, encoding="utf-8")
subtitle = get_subtitle_path(video.name, None)
log.info("video_file: %s, filepath: %s, guess: %s, video: %s, "
"subtitle: %s", video_file, filepath, guess, video, subtitle)
return subtitle
示例2: search
# 需要导入模块: import guessit [as 别名]
# 或者: from guessit import guessit [as 别名]
def search(self, name):
infos = guessit.guessit(name)
if not infos.get('title'):
return
try:
params = urlencode({'s': infos['title'], 'y': infos['year'], 'type': 'movie', 'r': 'json', 'apikey': settings.OMDB_API_KEY})
except KeyError:
params = urlencode({'s': infos['title'], 'type': 'movie', 'r': 'json', 'apikey': settings.OMDB_API_KEY})
url = 'http://www.omdbapi.com/?%s' % params
async with self.aiohttp_session.get(url) as resp:
data = await resp.text()
print(url, data)
resp = json.loads(data)
if "Search" in resp:
for res in resp['Search']:
poster = res['Poster'] if res['Poster'] != 'N/A' else ""
return Movie(
title=res['Title'],
imdbid=res['imdbID'],
poster=await save_poster(poster, self.loop, self.aiohttp_session),
)
示例3: fromguess
# 需要导入模块: import guessit [as 别名]
# 或者: from guessit import guessit [as 别名]
def fromguess(cls, name, guess):
if guess['type'] != 'episode':
raise ValueError('The guess must be an episode guess')
if 'title' not in guess or 'episode' not in guess:
raise ValueError('Insufficient data to process the guess')
# Currently we only have single-ep support (guessit returns a multi-ep as a list with int values)
# Most providers only support single-ep, so make sure it contains only 1 episode
# In case of multi-ep, take the lowest episode (subtitles will normally be available on lowest episode number)
episode_guess = guess.get('episode')
episode = min(episode_guess) if episode_guess and isinstance(episode_guess, list) else episode_guess
return cls(name, guess['title'], guess.get('season', 1), episode, title=guess.get('episode_title'),
year=guess.get('year'), format=guess.get('format'), original_series='year' not in guess,
release_group=guess.get('release_group'), resolution=guess.get('screen_size'),
video_codec=guess.get('video_codec'), audio_codec=guess.get('audio_codec'))
示例4: get_guess
# 需要导入模块: import guessit [as 别名]
# 或者: from guessit import guessit [as 别名]
def get_guess(self, video, scene_name):
"""
run guessit on scene_name
:param video:
:param scene_name:
:return:
"""
ext = os.path.splitext(video.name)[1]
guess_from = remove_crap_from_fn(scene_name + ext)
# guess
hints = {
"single_value": True,
"type": "episode",
}
return guess_from, guessit(guess_from, options=hints)
示例5: get_matches
# 需要导入模块: import guessit [as 别名]
# 或者: from guessit import guessit [as 别名]
def get_matches(self, video):
matches = set()
if isinstance(video, Movie):
# title
if video.title and sanitize(self.title) == sanitize(video.title):
matches.add('title')
# year
if video.year and self.year == video.year:
matches.add('year')
# imdb id
if video.imdb_id and self.imdb_id == video.imdb_id:
matches.add('imdb_id')
# fps
if video.fps and self.fps and not framerate_equal(video.fps, self.fps):
logger.warning("nekur: Wrong FPS (expected: %s, got: %s)", video.fps, self.fps)
# guess additional info from notes
matches |= guess_matches(video, guessit(self.notes, {'type': 'movie'}), partial=True)
self.matches = matches
return matches
示例6: get_matches
# 需要导入模块: import guessit [as 别名]
# 或者: from guessit import guessit [as 别名]
def get_matches(self, video):
matches = set()
video_filename = video.name
video_filename = os.path.basename(video_filename)
video_filename, _ = os.path.splitext(video_filename)
video_filename = sanitize_release_group(video_filename)
subtitle_filename = self.filename
subtitle_filename = os.path.basename(subtitle_filename)
subtitle_filename, _ = os.path.splitext(subtitle_filename)
subtitle_filename = sanitize_release_group(subtitle_filename)
if video_filename == subtitle_filename:
matches.add('hash')
if video.year and self.year == video.year:
matches.add('year')
matches |= guess_matches(video, guessit(self.title, {'type': self.type, 'allowed_countries': [None]}))
matches |= guess_matches(video, guessit(self.filename, {'type': self.type, 'allowed_countries': [None]}))
return matches
示例7: get_matches
# 需要导入模块: import guessit [as 别名]
# 或者: from guessit import guessit [as 别名]
def get_matches(self, video):
matches = set()
# episode
if isinstance(video, Episode):
# series name
if video.series and sanitize(self.series) in (
sanitize(name) for name in [video.series] + video.alternative_series):
matches.add('series')
# year
if video.original_series and self.year is None or video.year and video.year == self.year:
matches.add('year')
# release_group
if (video.release_group and self.version and
any(r in sanitize_release_group(self.version)
for r in get_equivalent_release_groups(sanitize_release_group(video.release_group)))):
matches.add('release_group')
# other properties
matches |= guess_matches(video, guessit(self.version, {'type': 'episode'}), partial=True)
return matches
示例8: get_matches
# 需要导入模块: import guessit [as 别名]
# 或者: from guessit import guessit [as 别名]
def get_matches(self, video):
matches = set()
# movie
if isinstance(video, Movie):
# title
if video.title and (sanitize(self.title) in (
sanitize(name) for name in [video.title] + video.alternative_titles)):
matches.add('title')
# year
if video.year and self.year == video.year:
matches.add('year')
# release_group
if (video.release_group and self.version and
any(r in sanitize_release_group(self.version)
for r in get_equivalent_release_groups(sanitize_release_group(video.release_group)))):
matches.add('release_group')
# other properties
matches |= guess_matches(video, guessit(self.version, {'type': 'movie'}), partial=True)
return matches
示例9: guess_subtitle
# 需要导入模块: import guessit [as 别名]
# 或者: from guessit import guessit [as 别名]
def guess_subtitle(sublist, video_detail):
"""
传入字幕列表,视频信息,返回得分最高字幕名
params:
sublist: list of str
video_detail: result of guessit
return:
success: bool
subname: str
"""
if not sublist:
return False, None
scores, subs = [], []
for one_sub in sublist:
_, ftype = path.splitext(one_sub)
if ftype not in SUB_FORMATS:
continue
subs.append(one_sub)
subname = path.split(one_sub)[-1] # extract subtitle name
try:
# zipfile:/Lib/zipfile.py:1211 Historical ZIP filename encoding
# try cp437 encoding
subname = subname.encode("cp437").decode("gbk")
except Exception:
pass
score = compute_subtitle_score(video_detail, subname)
scores.append(score)
max_score = max(scores)
max_pos = scores.index(max_score)
return max_score > 0, subs[max_pos]
示例10: __init__
# 需要导入模块: import guessit [as 别名]
# 或者: from guessit import guessit [as 别名]
def __init__(self, video_path, sub_store_path="", identifier=""):
self.name, self.type = splitext(basename(video_path))
self.path = abspath(dirname(video_path))
self.sub_store_path = abspath(sub_store_path) if sub_store_path else self.path
self.sub_identifier = identifier
self.has_subtitle = Video.sub_exists(
self.name, self.sub_store_path, self.sub_identifier
)
self.extracted_name = extract_name(self.name)
self.info = guessit(self.extracted_name + self.type)
示例11: use_guessit
# 需要导入模块: import guessit [as 别名]
# 或者: from guessit import guessit [as 别名]
def use_guessit(file_path):
return guessit.guessit(str(file_path))
示例12: guess
# 需要导入模块: import guessit [as 别名]
# 或者: from guessit import guessit [as 别名]
def guess(self, path):
if self._guess is None:
self._guess = guessit(path)
return self._guess
示例13: resolve
# 需要导入模块: import guessit [as 别名]
# 或者: from guessit import guessit [as 别名]
def resolve(self, path, movie):
if movie.title:
return movie
#Report.fail += 1
name, ext = os.path.splitext(os.path.basename(path))
infos = guessit.guessit(name)
if infos.get('title'):
return Movie(title=infos['title'])
else:
return Movie(title=name)
示例14: _parse_path_data
# 需要导入模块: import guessit [as 别名]
# 或者: from guessit import guessit [as 别名]
def _parse_path_data(self, file_path: Path):
options = {"type": getattr(self.media, "value", None)}
raw_data = dict(guessit(str(file_path), options))
if isinstance(raw_data.get("season"), list):
raw_data = dict(guessit(str(file_path.parts[-1]), options))
for k, v in raw_data.items():
if hasattr(v, "alpha3"):
self._path_data[k] = Language.parse(v)
elif isinstance(v, (int, str, date)):
self._path_data[k] = v
elif isinstance(v, list) and all(
[isinstance(_, (int, str)) for _ in v]
):
self._path_data[k] = v[0]
示例15: get_matches
# 需要导入模块: import guessit [as 别名]
# 或者: from guessit import guessit [as 别名]
def get_matches(self, video, hearing_impaired=False):
matches = set()
# episode
if isinstance(video, Episode) and self.type == 'episode':
# series
if video.series and (sanitize(self.title) in (
sanitize(name) for name in [video.series] + video.alternative_series)):
matches.add('series')
# year
if video.original_series and self.year is None or video.year and video.year == self.year:
matches.add('year')
# imdb_id
if video.series_imdb_id and self.imdb_id == video.series_imdb_id:
matches.add('series_imdb_id')
# movie
elif isinstance(video, Movie) and self.type == 'movie':
# title
if video.title and (sanitize(self.title) in (
sanitize(name) for name in [video.title] + video.alternative_titles)):
matches.add('title')
# year
if video.year and self.year == video.year:
matches.add('year')
# imdb_id
if video.imdb_id and self.imdb_id == video.imdb_id:
matches.add('imdb_id')
# name
matches |= guess_matches(video, guessit(self.name, {'type': self.type}))
return matches