Proper subtitle support

This commit is contained in:
Ruud
2012-04-09 20:28:07 +02:00
parent 148e1940ac
commit be8749e472
7 changed files with 72 additions and 56 deletions
+42 -3
View File
@@ -7,6 +7,7 @@ from couchpotato.core.plugins.base import Plugin
from couchpotato.core.settings.model import File
from couchpotato.environment import Env
from enzyme.exceptions import NoParserError, ParseError
from subliminal.videos import scan
import enzyme
import logging
import os
@@ -208,7 +209,7 @@ class Scanner(Plugin):
for identifier, group in movie_files.iteritems():
if identifier not in group['identifiers'] and len(identifier) > 0: group['identifiers'].append(identifier)
log.debug('Grouping files for: %s' % identifier)
log.debug('Grouping files: %s' % identifier)
for file_path in group['unsorted_files']:
wo_ext = file_path[:-(len(getExt(file_path)) + 1)]
@@ -233,7 +234,7 @@ class Scanner(Plugin):
# Group the files based on the identifier
for identifier, group in movie_files.iteritems():
log.debug('Grouping files for: %s' % identifier)
log.debug('Grouping files on identifier: %s' % identifier)
found_files = set(self.path_identifiers.get(identifier, []))
group['unsorted_files'].extend(found_files)
@@ -262,7 +263,7 @@ class Scanner(Plugin):
file_too_new = tryInt(time.time() - file_time)
break
if file_too_new:
if file_too_new and not Env.get('dev'):
log.info('Files seem to be still unpacking or just unpacked (created on %s), ignoring for now: %s' % (time.ctime(file_time), identifier))
continue
@@ -291,6 +292,9 @@ class Scanner(Plugin):
log.debug('Getting metadata for %s' % identifier)
group['meta_data'] = self.getMetaData(group)
# Subtitle meta
group['subtitle_language'] = self.getSubtitleLanguage(group)
# Get parent dir from movie files
for movie_file in group['files']['movie']:
group['parentdir'] = os.path.dirname(movie_file)
@@ -381,6 +385,41 @@ class Scanner(Plugin):
return {}
def getSubtitleLanguage(self, group):
detected_languages = {}
# Subliminal scanner
try:
paths = group['files']['movie']
scan_result = []
for p in paths:
scan_result.extend(scan(p))
for video, detected_subtitles in scan_result:
for s in detected_subtitles:
if s.language and s.path not in paths:
detected_languages[s.path] = [s.language]
except:
log.error('Failed parsing subtitle languages for %s: %s' % (paths, traceback.format_exc()))
# IDX
for extra in group['files']['subtitle_extra']:
try:
if os.path.isfile(extra):
output = open(extra, 'r')
txt = output.read()
output.close()
idx_langs = re.findall('\nid: (\w+)', txt)
sub_file = '%s.sub' % os.path.splitext(extra)[0]
if len(idx_langs) > 0 and os.path.isfile(sub_file):
detected_languages[sub_file] = idx_langs
except:
log.error('Failed parsing subtitle idx for %s: %s' % (extra, traceback.format_exc()))
return detected_languages
def determineMovie(self, group):
imdb_id = None