mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-08-19 12:59:36 -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 stat
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from babelfish import Language
|
|
||||||
import beets
|
import beets
|
||||||
import guessit
|
import guessit
|
||||||
import requests
|
import requests
|
||||||
from six import text_type
|
from six import text_type
|
||||||
import subliminal
|
|
||||||
|
|
||||||
import core
|
import core
|
||||||
from core import extractor, logger
|
from core import extractor, logger
|
||||||
|
@ -41,6 +39,7 @@ from core.utils.paths import (
|
||||||
remove_read_only,
|
remove_read_only,
|
||||||
)
|
)
|
||||||
from core.utils.processes import RunningProcess
|
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
|
from core.utils.torrents import create_torrent_class, pause_torrent, remove_torrent, resume_torrent
|
||||||
|
|
||||||
try:
|
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))
|
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):
|
def server_responding(base_url):
|
||||||
logger.debug('Attempting to connect to server at {0}'.format(base_url), 'SERVER')
|
logger.debug('Attempting to connect to server at {0}'.format(base_url), 'SERVER')
|
||||||
try:
|
try:
|
||||||
|
|
31
core/utils/subtitles.py
Normal file
31
core/utils/subtitles.py
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
from babelfish import Language
|
||||||
|
import subliminal
|
||||||
|
|
||||||
|
import core
|
||||||
|
from core import logger
|
||||||
|
|
||||||
|
|
||||||
|
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')
|
Loading…
Add table
Add a link
Reference in a new issue