[mythtv-users] User Job to rip subtitles from each program

Raymond Wagner raymond at wagnerrp.com
Thu Feb 2 22:00:46 UTC 2012


On 2/2/2012 15:48, David Crawford wrote:
>
> On 31 January 2012 01:27, Raymond Wagner <raymond at wagnerrp.com 
> <mailto:raymond at wagnerrp.com>> wrote:
>
>     import os
>     from MythTV import MythBE, findfile
>     be = MythBE()
>     prog = be.getRecording(<chanid>, <starttime>)
>     oldbase = prog.basename.rsplit('.',1)[0]
>     newbase = prog.formatPath('...').rsplit('.',1)[0]
>     sg = findfile(prog.basename, prog.storagegroup)
>     if sg is None:
>         raise Exception('file not found')
>     for f in os.listdir(sg.dirname):
>         if not (f.startswith(oldbase) and f.endswith('srt')):
>             continue
>         os.rename(os.path.join(sg.dirname, f), os.path.join(sg.dirname,
>     newbase+'.'+f.split('.')[1]))
>
>
> Still havent figured quite how to make this script yet.... any 
> pointers? i just want the .srt subtitle file to be renamed and read:
> mm-dd_hh-mm-ss_Channel(BBC)_Program(BBC News).srt

The above script is crude, but it should work.  There may be some minor 
syntax issues because I never actually tested it.  That last argument in 
the last line should actually read "f.split('.',1)[1]".  For the name 
you have listed, you would want the format string to be ...

%m-%d_%H-%i-%s_%cN_%T

The chanid and starttime used to reference the recording would be 
supplied by the jobqueue on the command line, or you could use the jobid 
itself and pull the chanid and starttime out of the database.  You would 
need to do command line parsing to get either of those, but there are 
examples on the wiki of how to do that.  As for running the extractor 
itself, try...

from MythTV import System
from MythTV.static import INSTALL_PREFIX
ccextractor = System(path=os.path.join(INSTALL_PREFIX,'mythccextractor'))
ccextractor('--infile', os.path.join(sg.dirname, prog.basename))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.mythtv.org/pipermail/mythtv-users/attachments/20120202/419dad16/attachment.html 


More information about the mythtv-users mailing list