1
0
Fork 0
mirror of https://github.com/morpheus65535/bazarr synced 2024-12-28 10:38:26 +00:00
bazarr/libs/subliminal_patch/core_persistent.py
Vitiko 708fbfcd8e Add support for configurable scores (movies and episodes)
Currently only configurable via manual `data/config/config.ini`
text edition.

New configurable values are `series_scores` and `movie_scores`.

For each config section, the sum of the config values (except hash)
must be equal to the hash value plus one (1), otherwise default
values will be used (notified via debug log).

Hash values are not meant to be modified; the value is shown in
`config.ini` for reference. Modifying hash values would imply
breaking Bazarr's score logic.
2022-11-05 01:07:06 -04:00

84 lines
2.5 KiB
Python

# coding=utf-8
from __future__ import absolute_import
from collections import defaultdict
import logging
import time
from subliminal.core import check_video
logger = logging.getLogger(__name__)
# list_all_subtitles, list_supported_languages, list_supported_video_types, download_subtitles, download_best_subtitles
def list_all_subtitles(videos, languages, pool_instance):
listed_subtitles = defaultdict(list)
# return immediatly if no video passed the checks
if not videos:
return listed_subtitles
for video in videos:
logger.info("Listing subtitles for %r", video)
subtitles = pool_instance.list_subtitles(
video, languages - video.subtitle_languages
)
listed_subtitles[video].extend(subtitles)
logger.info("Found %d subtitle(s)", len(subtitles))
return listed_subtitles
def list_supported_languages(pool_instance):
return pool_instance.list_supported_languages()
def list_supported_video_types(pool_instance):
return pool_instance.list_supported_video_types()
def download_subtitles(subtitles, pool_instance):
for subtitle in subtitles:
logger.info("Downloading subtitle %r with score %s", subtitle, subtitle.score)
pool_instance.download_subtitle(subtitle)
def download_best_subtitles(
videos,
languages,
pool_instance,
min_score=0,
hearing_impaired=False,
only_one=False,
compute_score=None,
**kwargs
):
downloaded_subtitles = defaultdict(list)
# check videos
checked_videos = []
for video in videos:
if not check_video(video, languages=languages, undefined=only_one):
logger.info("Skipping video %r", video)
continue
checked_videos.append(video)
# return immediately if no video passed the checks
if not checked_videos:
return downloaded_subtitles
# download best subtitles
for video in checked_videos:
logger.info("Downloading best subtitles for %r", video)
subtitles = pool_instance.download_best_subtitles(
pool_instance.list_subtitles(video, languages - video.subtitle_languages),
video,
languages,
min_score=min_score,
hearing_impaired=hearing_impaired,
only_one=only_one,
compute_score=compute_score,
)
logger.info("Downloaded %d subtitle(s)", len(subtitles))
downloaded_subtitles[video].extend(subtitles)
return downloaded_subtitles