mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-08-14 10:36:52 -07:00
Refactor subtitle utils to utils.subtitles
This commit is contained in:
parent
6a9ff96e8c
commit
2d4951267b
2 changed files with 32 additions and 28 deletions
|
@ -8,12 +8,10 @@ import shutil
|
|||
import stat
|
||||
import time
|
||||
|
||||
from babelfish import Language
|
||||
import beets
|
||||
import guessit
|
||||
import requests
|
||||
from six import text_type
|
||||
import subliminal
|
||||
|
||||
import core
|
||||
from core import extractor, logger
|
||||
|
@ -41,6 +39,7 @@ from core.utils.paths import (
|
|||
remove_read_only,
|
||||
)
|
||||
from core.utils.processes import RunningProcess
|
||||
from core.utils.subtitles import import_subs
|
||||
from core.utils.torrents import create_torrent_class, pause_torrent, remove_torrent, resume_torrent
|
||||
|
||||
try:
|
||||
|
@ -554,32 +553,6 @@ def extract_files(src, dst=None, keep_archive=None):
|
|||
logger.error('Unable to remove file {0} due to: {1}'.format(inputFile, e))
|
||||
|
||||
|
||||
def import_subs(filename):
|
||||
if not core.GETSUBS:
|
||||
return
|
||||
try:
|
||||
subliminal.region.configure('dogpile.cache.dbm', arguments={'filename': 'cachefile.dbm'})
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
languages = set()
|
||||
for item in core.SLANGUAGES:
|
||||
try:
|
||||
languages.add(Language(item))
|
||||
except Exception:
|
||||
pass
|
||||
if not languages:
|
||||
return
|
||||
|
||||
logger.info('Attempting to download subtitles for {0}'.format(filename), 'SUBTITLES')
|
||||
try:
|
||||
video = subliminal.scan_video(filename)
|
||||
subtitles = subliminal.download_best_subtitles({video}, languages)
|
||||
subliminal.save_subtitles(video, subtitles[video])
|
||||
except Exception as e:
|
||||
logger.error('Failed to download subtitles for {0} due to: {1}'.format(filename, e), 'SUBTITLES')
|
||||
|
||||
|
||||
def server_responding(base_url):
|
||||
logger.debug('Attempting to connect to server at {0}'.format(base_url), 'SERVER')
|
||||
try:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue