@ -4,6 +4,7 @@ import os
import subprocess
import subprocess
import locale
import locale
from config import settings
from utils import get_binary
from utils import get_binary
class NotMKVAndNoFFprobe ( Exception ) :
class NotMKVAndNoFFprobe ( Exception ) :
@ -19,13 +20,24 @@ class EmbeddedSubsReader:
def list_languages ( self , file ) :
def list_languages ( self , file ) :
if self . ffprobe :
if self . ffprobe :
try :
try :
return subprocess . check_output ( [ self . ffprobe , " -loglevel " , " error " , " -select_streams " , " s " , " -show_entries " , " stream_tags=language " , " -of " , " csv=p=0 " , file . encode ( locale . getpreferredencoding ( ) ) ] , universal_newlines = True , stderr = subprocess . STDOUT ) . strip ( ) . split ( " \n " )
if not settings . general . getboolean ( ' ignore_pgs_subs ' ) :
subtitle_languages = subprocess . check_output ( [ self . ffprobe , " -loglevel " , " error " , " -select_streams " , " s " , " -show_entries " , " stream_tags=language " , " -of " , " csv=p=0 " , file . encode ( locale . getpreferredencoding ( ) ) ] , universal_newlines = True , stderr = subprocess . STDOUT ) . strip ( )
if not subtitle_languages :
return [ ]
return subtitle_languages . split ( ' \n ' )
subtitle_tracks = subprocess . check_output ( [ self . ffprobe , " -loglevel " , " error " , " -select_streams " , " s " , " -show_entries " , " stream=codec_name:stream_tags=language " , " -of " , " csv=p=0 " , file . encode ( locale . getpreferredencoding ( ) ) ] , universal_newlines = True , stderr = subprocess . STDOUT ) . strip ( )
if not subtitle_tracks :
return [ ]
subtitle_tracks = subtitle_tracks . split ( ' \n ' )
return [ lang for ( sub_type , lang ) in map ( lambda subtitle_track : subtitle_track . split ( ' , ' ) , subtitle_tracks ) if sub_type != ' hdmv_pgs_subtitle ' ]
except subprocess . CalledProcessError as e :
except subprocess . CalledProcessError as e :
raise FFprobeError ( e . output )
raise FFprobeError ( e . output )
if os . path . splitext ( file ) [ 1 ] != ' .mkv ' :
if os . path . splitext ( file ) [ 1 ] != ' .mkv ' :
raise NotMKVAndNoFFprobe ( )
raise NotMKVAndNoFFprobe ( )
with open ( file , ' rb ' ) as f :
with open ( file , ' rb ' ) as f :
mkv = enzyme . MKV ( f )
mkv = enzyme . MKV ( f )
return [ subtitle_track . language for subtitle_track in mkv . subtitle_tracks ]
if not settings . general . getboolean ( ' ignore_pgs_subs ' ) :
return [ subtitle_track . language for subtitle_track in mkv . subtitle_tracks ]
return [ subtitle_track . language for subtitle_track in mkv . subtitle_tracks if subtitle_track . codec_id != " S_HDMV/PGS " ]
embedded_subs_reader = EmbeddedSubsReader ( )
embedded_subs_reader = EmbeddedSubsReader ( )