def __init__(self): super(MPlayerContext,self).__init__(bool) for p in ['/opt/bin/mplayer','/usr/local/bin/mplayer','/usr/bin/mplayer']: if which(p): self['path'] = p break
def parse_local_subtitles(self): info = self.__info raw = self.__raw_info['mplayer'] info['subtitle'] = defaultdict(bool) if raw['ID_SUBTITLE_ID']: # TODO: extract subtitles and combine to a bi-lingual sub # ffmpeg -i Seinfeld.2x01.The_Ex-Girlfriend.xvid-TLF.mkv -vn -an -scodec srt sub.srt info['subtitle']['embed'] = [] for i in raw['ID_SUBTITLE_ID']: info['subtitle']['embed'] += raw['ID_SID_{0}_LANG'.format(i)] if raw['ID_FILE_SUB_ID']: info['subtitle']['external'] = raw['ID_FILE_SUB_FILENAME'] log_debug('Converting the external subtitles to UTF-8...') from charset import guess_locale_and_convert for subfile in raw['ID_FILE_SUB_FILENAME']: # open in binary mode because we don't know the encoding with open(subfile,'r+b') as f: s = f.read() enc,_,s = guess_locale_and_convert(s) if not enc in ['utf_8','ascii']: f.seek(0) f.write(s) self.add_arg('-subcp utf8') if raw['ID_VOBSUB_ID']: info['subtitle']['vobsub'] = True unrar = which('unrar') if unrar: self.add_arg('-unrarexec {0}'.format(unrar))
def parse_local_subtitles(self): info = self.__info raw = self.__raw_info['mplayer'] info['subtitle'] = defaultdict(bool) if raw['ID_SUBTITLE_ID']: # TODO: extract subtitles and combine to a bi-lingual sub # ffmpeg -i Seinfeld.2x01.The_Ex-Girlfriend.xvid-TLF.mkv -vn -an -scodec srt sub.srt info['subtitle']['embed'] = [] for i in raw['ID_SUBTITLE_ID']: info['subtitle']['embed'] += raw['ID_SID_{0}_LANG'.format(i)] if raw['ID_FILE_SUB_ID']: info['subtitle']['external'] = raw['ID_FILE_SUB_FILENAME'] log_debug('Converting the external subtitles to UTF-8...') from charset import guess_locale_and_convert for subfile in raw['ID_FILE_SUB_FILENAME']: # open in binary mode because we don't know the encoding with open(subfile, 'r+b') as f: s = f.read() enc, _, s = guess_locale_and_convert(s) if not enc in ['utf_8', 'ascii']: f.seek(0) f.write(s) self.add_arg('-subcp utf8') if raw['ID_VOBSUB_ID']: info['subtitle']['vobsub'] = True unrar = which('unrar') if unrar: self.add_arg('-unrarexec {0}'.format(unrar))
def __detect_backend(self): check_list = ['/opt/bin/mpv','/usr/local/bin/mpv','/usr/bin/mpv', '/opt/bin/mplayer','/usr/local/bin/mplayer','/usr/bin/mplayer'] for p in check_list: if which(p): self.__path = p break
def __detect_backend(self): check_list = [ '/opt/bin/mpv', '/usr/local/bin/mpv', '/usr/bin/mpv', '/opt/bin/mplayer', '/usr/local/bin/mplayer', '/usr/bin/mplayer' ] for p in check_list: if which(p): self.__path = p break
def __init__(self): super(MPlayerContext, self).__init__(bool) for p in [ '/opt/bin/mplayer', '/usr/local/bin/mplayer', '/usr/bin/mplayer' ]: if which(p): self['path'] = p break
def check_screen_dim(): '''Select the maximal available screen dimension. ''' dim = (640, 480) if which('randr'): for l in subprocess.check_output(['randr']).splitlines(): if l.startswith('*'): # xrandr 1.1 _, w, _, h = l.split() elif '*' in l: # xrandr 1.2 and above w, h = l.split()[0].split('x') else: continue if w > dim[0]: dim = (w, h) return dim
def check_screen_dim(): '''Select the maximal available screen dimension. ''' dim = (640,480) if which('randr'): for l in subprocess.check_output(['randr']).splitlines(): if l.startswith('*'): # xrandr 1.1 _,w,_,h = l.split() elif '*' in l: # xrandr 1.2 and above w,h = l.split()[0].split('x') else: continue if w > dim[0]: dim = (w,h) return dim
def run_mpi(monitors, hosts): """ """ # determine the total number of pixels implied by args.perc num_nodes = len(hosts) num_procs = num_nodes * 8 host = hosts[0] # where the master resides hosts = [ h.strip() for h in hosts ] # give the user some output! print '' print '>> TRAPDOOR' print ' ... starting' print '-----------------------' print 'nodes: %d' % num_nodes print 'processors: %d' % num_procs print 'hosts: %s' % str(hosts) print '-----------------------' # we have to jump through some hoops in order to make this work # I'm going to follow Chris' lead and write a bash script to disk # that gets called later by mpirun trapdoor_dir = os.path.join(os.environ['HOME'], '.trapdoor') if not os.path.exists(trapdoor_dir): os.mkdir(trapdoor_dir) print 'Created: %s' % trapdoor_dir # (1) write the script MPI will execute mpi_script_path = os.path.join(trapdoor_dir, 'mpi_script.sh') mpi_script_text = """#!/bin/bash # THIS IS AN AUTOMATICALLY GENERATED SCRIPT # CREATED BY: trapdoor # USER: %s # DATE: %s pyscript="from trapdoor import guardian; guardian.run(%s)" source /reg/g/psdm/etc/ana_env.sh . /reg/g/psdm/bin/sit_setup.sh python -c "$pyscript" """ % (os.environ['USER'], datetime.datetime.now(), str(monitors)) f = open(mpi_script_path, 'w') f.write(mpi_script_text) f.close() # make that script chmod a+x st = os.stat(mpi_script_path) os.chmod(mpi_script_path, st.st_mode | 0111) print 'Wrote: %s' % mpi_script_path # (3) shell out the MPI command try: r = subprocess.check_call(['ssh', host, 'hostname']) except subprocess.CalledProcessError: raise IOError('No route to host: %s' % host) # try and find MPI mpi_bin = which('mpirun') if mpi_bin == None: raise RuntimeError('Could not find an MPI `mpirun` executable!') cmd = [mpi_bin, '-n', str(num_procs), '--host', ','.join(hosts), mpi_script_path] print '-----------------------' print '>> starting MPI' print 'cmd: %s' % ' '.join(cmd) # for some reason, NOT passing the kwargs stdout/stderr allows the stdout # to reach the running terminal pipe = subprocess.Popen(cmd, shell=False) print '-----------------------' return