summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authormorpheus65535 <[email protected]>2024-10-23 23:20:49 -0400
committermorpheus65535 <[email protected]>2024-10-23 23:20:49 -0400
commitc615f99f0635ab57e0de1015e4e4575821c074aa (patch)
tree0009b8373aa206c26b2b72d7e5645993aff6bf11
parenta186e64893fd71d986ef922d9d90cf0b9435ae41 (diff)
downloadbazarr-1.4.6-beta.11.tar.gz
bazarr-1.4.6-beta.11.zip
Improved guessing of video file properties by using file name and refining it with scene name if available. #2704v1.4.6-beta.11
-rw-r--r--bazarr/subtitles/refiners/ffprobe.py8
-rw-r--r--bazarr/subtitles/utils.py42
2 files changed, 31 insertions, 19 deletions
diff --git a/bazarr/subtitles/refiners/ffprobe.py b/bazarr/subtitles/refiners/ffprobe.py
index 3fc21bd92..0f1a7a98b 100644
--- a/bazarr/subtitles/refiners/ffprobe.py
+++ b/bazarr/subtitles/refiners/ffprobe.py
@@ -2,8 +2,10 @@
# fmt: off
import logging
+import json
from subliminal import Movie
+from guessit.jsonutils import GuessitEncoder
from utilities.path_mappings import path_mappings
from app.database import TableEpisodes, TableMovies, database, select
@@ -37,10 +39,12 @@ def refine_from_ffprobe(path, video):
return video
if data['ffprobe']:
- logging.debug('FFprobe found: %s', data['ffprobe'])
+ logging.debug('FFprobe found: %s', json.dumps(data['ffprobe'], cls=GuessitEncoder, indent=4,
+ ensure_ascii=False))
parser_data = data['ffprobe']
elif data['mediainfo']:
- logging.debug('Mediainfo found: %s', data['mediainfo'])
+ logging.debug('Mediainfo found: %s', json.dumps(data['mediainfo'], cls=GuessitEncoder, indent=4,
+ ensure_ascii=False))
parser_data = data['mediainfo']
else:
parser_data = {}
diff --git a/bazarr/subtitles/utils.py b/bazarr/subtitles/utils.py
index 436bc7b52..06f7b225b 100644
--- a/bazarr/subtitles/utils.py
+++ b/bazarr/subtitles/utils.py
@@ -3,9 +3,11 @@
import logging
import os
+import json
from subzero.language import Language
from subzero.video import parse_video
+from guessit.jsonutils import GuessitEncoder
from app.config import settings
from languages.custom_lang import CustomLanguage
@@ -26,33 +28,32 @@ def get_video(path, title, sceneName, providers=None, media_type="movie"):
:return: `Video` instance
"""
hints = {"title": title, "type": "movie" if media_type == "movie" else "episode"}
- used_scene_name = False
- original_path = path
- original_name = os.path.basename(path)
- hash_from = None
- if sceneName != "None":
- # use the sceneName but keep the folder structure for better guessing
- path = os.path.join(os.path.dirname(path), sceneName + os.path.splitext(path)[1])
- used_scene_name = True
- hash_from = original_path
try:
+ logging.debug(f'BAZARR guessing video object using video file path: {path}')
skip_hashing = settings.general.skip_hashing
- video = parse_video(path, hints=hints, skip_hashing=skip_hashing, dry_run=used_scene_name, providers=providers,
- hash_from=hash_from)
- video.used_scene_name = used_scene_name
- video.original_name = original_name
- video.original_path = original_path
+ video = parse_video(path, hints=hints, skip_hashing=skip_hashing, dry_run=False, providers=providers)
+ if sceneName != "None":
+ # refine the video object using the sceneName and update the video object accordingly
+ scenename_with_extension = sceneName + os.path.splitext(path)[1]
+ logging.debug(f'BAZARR guessing video object using scene name: {scenename_with_extension}')
+ scenename_video = parse_video(scenename_with_extension, hints=hints, dry_run=True)
+ refine_video_with_scenename(initial_video=video, scenename_video=scenename_video)
+
+ video.original_name = os.path.basename(path)
+ video.original_path = path
for key, refiner in registered_refiners.items():
logging.debug("Running refiner: %s", key)
- refiner(original_path, video)
+ refiner(path, video)
- logging.debug('BAZARR is using these video object properties: %s', vars(video))
+ logging.debug('BAZARR is using these video object properties: %s', json.dumps(vars(video),
+ cls=GuessitEncoder, indent=4,
+ ensure_ascii=False))
return video
except Exception as error:
- logging.exception("BAZARR Error (%s) trying to get video information for this file: %s", error, original_path)
+ logging.exception("BAZARR Error (%s) trying to get video information for this file: %s", error, path)
def _get_download_code3(subtitle):
@@ -100,3 +101,10 @@ def _set_forced_providers(pool, also_forced=False, forced_required=False):
"opensubtitles": {'also_foreign': also_forced, "only_foreign": forced_required}
}
)
+
+
+def refine_video_with_scenename(initial_video, scenename_video):
+ for key, value in vars(scenename_video).items():
+ if value:
+ setattr(initial_video, key, value)
+ return initial_video