mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-08-14 02:26:53 -07:00
Refactor utils.subtitles to plugins.subtitles
This commit is contained in:
parent
76b5c06a33
commit
b6db785c92
5 changed files with 4 additions and 4 deletions
31
core/plugins/subtitles.py
Normal file
31
core/plugins/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