def __rebuild_context(self): options = fsdecode( subprocess.Popen( [self['path'], '-list-options'], stdout=subprocess.PIPE).communicate()[0]).splitlines() if options[-1].startswith('MPlayer2'): self['mplayer2'] = True option_end = -3 else: option_end = -4 # collect supported options self['option'] = defaultdict(int) for opt in options[3:option_end]: opt = opt.split() name = opt[0].split(':') # don't care sub-option if self['option'][name[0]]: continue self['option'][name[0]] = (2 if len(name) == 2 or opt[1] != 'Flag' else 1) # handle vf*/af*: mplayer reports option name as vf*/af*, which is a # family of options. del self['option']['af*'] del self['option']['vf*'] for extra in [ 'af', 'af-adv', 'af-add', 'af-pre', 'af-del', 'vf', 'vf-add', 'vf-pre', 'vf-del' ]: self['option'][extra] = 2 for extra in ['af-clr', 'vf-clr']: self['option'][extra] = 1 # it's awful to test if ass is supported. self['ass'] = True if not self['option']['ass']: self['ass'] = False else: libass_path = None for l in fsdecode(subprocess.check_output(['ldd', self['path'] ])).splitlines(): if 'libass' in l: libass_path = l.split()[2] if not libass_path: self['ass'] = False else: if not 'libfontconfig' in fsdecode( subprocess.check_output(['ldd', libass_path])): self['ass'] = False
def identify(self, args): args = [self.__context['path'] ] + '-vo null -ao null -frames 0 -identify'.split() + args log_debug('Entering MPlayerContext.identify() <call subprocess>\n {}'. format(' '.join(args))) output = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=DEVNULL).communicate()[0] return '\n'.join( [l for l in fsdecode(output).splitlines() if l.startswith('ID_')])
def __rebuild_context(self): options = fsdecode(subprocess.Popen([self['path'], '-list-options'], stdout=subprocess.PIPE).communicate()[0]).splitlines() if options[-1].startswith('MPlayer2'): self['mplayer2'] = True option_end = -3 else: option_end = -4 # collect supported options self['option'] = defaultdict(int) for opt in options[3:option_end]: opt = opt.split() name = opt[0].split(':') # don't care sub-option if self['option'][name[0]]: continue self['option'][name[0]] = (2 if len(name)==2 or opt[1]!='Flag' else 1) # handle vf*/af*: mplayer reports option name as vf*/af*, which is a # family of options. del self['option']['af*'] del self['option']['vf*'] for extra in ['af','af-adv','af-add','af-pre','af-del','vf','vf-add','vf-pre','vf-del']: self['option'][extra] = 2 for extra in ['af-clr','vf-clr']: self['option'][extra] = 1 # it's awful to test if ass is supported. self['ass'] = True if not self['option']['ass']: self['ass'] = False else: libass_path = None for l in fsdecode(subprocess.check_output(['ldd',self['path']])).splitlines(): if 'libass' in l: libass_path = l.split()[2] if not libass_path: self['ass'] = False else: if not 'libfontconfig' in fsdecode(subprocess.check_output(['ldd',libass_path])): self['ass'] = False
# * xset s off # * "not compiled in option" # * detect the language in embedded subtitles, which is guaranteed to be utf8 # * use ffprobe for better(?) metainfo detection? # * use defaultdict wisely import os, sys from aux import fsdecode from app import * if __name__ == '__main__': if sys.hexversion < 0x02070000: print('Please run the script with python>=2.7') else: args = [fsdecode(x) for x in sys.argv] name = os.path.basename(args.pop(0)) if 'mplayer' in name: app = Player if len(args) > 0: if 'fetch' == args[0]: args.pop(0) app = Fetcher elif 'identify' == args[0]: args.pop(0) app = Identifier elif 'play' == args[0]: args.pop(0) elif 'mfetch' in name: app = Fetcher
def identify(self, args): args = [ self.__context['path'] ] + '-vo null -ao null -frames 0 -identify'.split() + args log_debug('Entering MPlayerContext.identify() <call subprocess>\n {}'.format(' '.join(args))) output = subprocess.Popen(args,stdout=subprocess.PIPE,stderr=DEVNULL).communicate()[0] return '\n'.join([l for l in fsdecode(output).splitlines() if l.startswith('ID_')])