1
0
Fork 0
mirror of https://github.com/morpheus65535/bazarr synced 2024-12-25 17:17:12 +00:00

Switching to pyprobe to refine video object.

This commit is contained in:
Louis Vézina 2019-08-25 22:12:01 -04:00
parent e4f4f9e357
commit bed978c88a

View file

@ -32,17 +32,16 @@ from notifier import send_notifications, send_notifications_movie
from get_providers import get_providers, get_providers_auth, provider_throttle, provider_pool
from get_args import args
from queueconfig import notifications
from pymediainfo import MediaInfo
from pyprobe.pyprobe import VideoFileParser
def get_video(path, title, sceneName, use_scenename, use_mediainfo, providers=None, media_type="movie"):
def get_video(path, title, sceneName, use_scenename, providers=None, media_type="movie"):
"""
Construct `Video` instance
:param path: path to video
:param title: series/movie title
:param sceneName: sceneName
:param use_scenename: use sceneName
:param use_mediainfo: use media info to refine the video
:param providers: provider list for selective hashing
:param media_type: movie/series
:return: `Video` instance
@ -64,10 +63,9 @@ def get_video(path, title, sceneName, use_scenename, use_mediainfo, providers=No
video.used_scene_name = used_scene_name
video.original_name = original_name
video.original_path = original_path
refine_from_db(original_path, video)
if platform.system() != "Linux" and use_mediainfo:
refine_from_mediainfo(original_path, video)
refine_from_db(original_path, video)
refine_from_ffprobe(original_path, video)
logging.debug('BAZARR is using those video object properties: %s', vars(video))
return video
@ -141,7 +139,6 @@ def download_subtitle(path, language, hi, forced, providers, providers_auth, sce
language_set.add(lang_obj)
use_scenename = settings.general.getboolean('use_scenename')
use_mediainfo = settings.general.getboolean('use_mediainfo')
minimum_score = settings.general.minimum_score
minimum_score_movie = settings.general.minimum_score_movie
use_postprocessing = settings.general.getboolean('use_postprocessing')
@ -157,7 +154,7 @@ def download_subtitle(path, language, hi, forced, providers, providers_auth, sce
post_download_hook=None,
language_hook=None
"""
video = get_video(force_unicode(path), title, sceneName, use_scenename, use_mediainfo, providers=providers,
video = get_video(force_unicode(path), title, sceneName, use_scenename, providers=providers,
media_type=media_type)
if video:
min_score, max_score, scores = get_scores(video, media_type, min_score_movie_perc=int(minimum_score_movie),
@ -281,6 +278,7 @@ def manual_search(path, language, hi, forced, providers, providers_auth, sceneNa
final_subtitles = []
initial_hi = True if hi == "True" else False
if hi == "True":
hi = "force HI"
else:
@ -309,13 +307,12 @@ def manual_search(path, language, hi, forced, providers, providers_auth, sceneNa
language_set.add(lang_obj)
use_scenename = settings.general.getboolean('use_scenename')
use_mediainfo = settings.general.getboolean('use_mediainfo')
minimum_score = settings.general.minimum_score
minimum_score_movie = settings.general.minimum_score_movie
use_postprocessing = settings.general.getboolean('use_postprocessing')
postprocessing_cmd = settings.general.postprocessing_cmd
if providers:
video = get_video(force_unicode(path), title, sceneName, use_scenename, use_mediainfo, providers=providers,
video = get_video(force_unicode(path), title, sceneName, use_scenename, providers=providers,
media_type=media_type)
else:
logging.info("BAZARR All providers are throttled")
@ -356,7 +353,10 @@ def manual_search(path, language, hi, forced, providers, providers_auth, sceneNa
logging.debug(u"BAZARR Skipping %s, because it doesn't match our series/episode", s)
continue
score = compute_score(matches, s, video, hearing_impaired=hi)
if s.hearing_impaired == initial_hi:
matches.add('hearing_impaired')
score = compute_score(matches, s, video, hearing_impaired=initial_hi)
not_matched = scores - matches
s.score = score
@ -387,11 +387,10 @@ def manual_download_subtitle(path, language, hi, forced, subtitle, provider, pro
subtitle = pickle.loads(codecs.decode(subtitle.encode(), "base64"))
use_scenename = settings.general.getboolean('use_scenename')
use_mediainfo = settings.general.getboolean('use_mediainfo')
use_postprocessing = settings.general.getboolean('use_postprocessing')
postprocessing_cmd = settings.general.postprocessing_cmd
single = settings.general.getboolean('single_language')
video = get_video(force_unicode(path), title, sceneName, use_scenename, use_mediainfo, providers={provider},
video = get_video(force_unicode(path), title, sceneName, use_scenename, providers={provider},
media_type=media_type)
if video:
min_score, max_score, scores = get_scores(video, media_type)
@ -889,31 +888,42 @@ def refine_from_db(path, video):
return video
def refine_from_mediainfo(path, video):
if video.fps:
return
exe = get_binary('mediainfo')
def refine_from_ffprobe(path, video):
exe = get_binary('ffprobe')
if not exe:
logging.debug('BAZARR MediaInfo library not found!')
logging.debug('BAZARR FFprobe not found!')
return
else:
logging.debug('BAZARR MediaInfo library used is %s', exe)
logging.debug('BAZARR FFprobe used is %s', exe)
media_info = MediaInfo.parse(path, library_file=exe)
parser = VideoFileParser(ffprobe=exe, includeMissing=True, rawMode=False)
data = parser.parseFfprobe(path)
video_track = next((t for t in media_info.tracks if t.track_type == 'Video'), None)
if not video_track:
logging.debug('BAZARR MediaInfo was unable to find video tracks in the file!')
return
logging.debug('FFprobe found: %s', data)
logging.debug('MediaInfo found: %s', video_track.to_data())
if 'videos' not in data:
logging.debug('BAZARR FFprobe was unable to find video tracks in the file!')
else:
if 'resolution' in data['videos'][0]:
if not video.resolution:
if data['videos'][0]['resolution'][0] >= 3200:
video.resolution = "2160p"
elif data['videos'][0]['resolution'][0] >= 1800:
video.resolution = "1080p"
elif data['videos'][0]['resolution'][0] >= 1200:
video.resolution = "720p"
elif data['videos'][0]['resolution'][0] >= 0:
video.resolution = "480p"
if 'codec' in data['videos'][0]:
if not video.video_codec:
video.video_codec = data['videos'][0]['codec']
if not video.fps:
if video_track.frame_rate:
video.fps = float(video_track.frame_rate)
elif video_track.framerate_num and video_track.framerate_den:
video.fps = round(float(video_track.framerate_num) / float(video_track.framerate_den), 3)
if 'audios' not in data:
logging.debug('BAZARR FFprobe was unable to find audio tracks in the file!')
else:
if 'codec' in data['audios'][0]:
if not video.audio_codec:
video.audio_codec = data['audios'][0]['codec'].upper()
def upgrade_subtitles():