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

David Crawford davidcrawford83 at gmail.com
Fri Feb 3 17:23:47 UTC 2012


This is the script im trying right now and it just hangs, Trying it with
python /home/dave/uksub2srt/renamesrt.py %CHANID% %STARTTIME%

#!/usr/bin/env python

import sys
if len(sys.argv) != 3:
    chanid, starttime = sys.argv[1:3
import os
from MythTV import MythBE, findfile
be = MythBE()
prog = be.getRecording(<chanid>, <starttime>)
oldbase = prog.basename.rsplit('.',1)[0]
newbase = prog.formatPath('%m-%d_%H-%i-%s_%cN_%T').rsplit('.',1)[0]
sg = findfile(prog.basename, prog.storagegroup)
if sg is None:
    raise Exception('file not found')
from MythTV import System
ccextractor = System(path="/home/dave/uksub2srt/uksub2srt.py")
ccextractor('-i', os.path.join(sg.dirname, prog.basename),
            '-o', '/home/subtitles/{0}.srt'.format(newbase))

can anyone tell me what im doing wrong?

many thanks,
dave

On 3 February 2012 12:17, David Crawford <davidcrawford83 at gmail.com> wrote:

> like this sorry - didnt paste first time
>
> #!/usr/bin/env python
>
> from MythTV import System
> ccextractor = System(path="/home/dave/uksub2srt/uksub2srt.py")
> ccextractor('-i', os.path.join(sg.dirname, prog.basename),
>             '-o', '/home/subtitles/{0}.srt'.format(newbase))
>
> import os
> from MythTV import MythBE, findfile
> be = MythBE()
> prog = be.getRecording(<chanid>, <starttime>)
>
> import sys
> if len(sys.argv) != 3:
>     chanid, starttime = sys.argv[1:3]
>
> 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)[1]))
>
> On 3 February 2012 03:02, David Crawford <davidcrawford83 at gmail.com>wrote:
>
>> Should it be  more like this?
>>
>> #!/usr/bin/env python
>>
>> 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')
>>
>> import sys
>> if len(sys.argv) != 3:
>>     chanid, starttime = sys.argv[1:3]
>>
>> from MythTV import System
>> ccextractor = System(path="/home/dave/uksub2srt/uksub2srt.py")
>> ccextractor('-i', os.path.join(sg.dirname, prog.basename),
>>             '-o', '/home/subtitles/{0}.srt'.format(newbase))
>>
>> 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)[1]))
>>
>> On 3 February 2012 01:49, Raymond Wagner <raymond at wagnerrp.com> wrote:
>>
>>> And... a bit of python jumble...
>>>
>>>
>>> > #!/usr/bin/env python
>>>
>>> This needs to go at the top of the file... good.
>>>
>>> > import os
>>> > from MythTV import MythBE, findfile
>>> > be = MythBE()
>>> > prog = be.getRecording(<chanid>, <starttime>)
>>>
>>> When you look up the command line arguments for an application, usually
>>> required options are seen in diamond braces (<>).  I was going for the
>>> same thing here.  You need to give the getRecording() method the chanid
>>> and starttime of the recording you want it to find.
>>>
>>> > 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)[1]))
>>>
>>> This was supposed to rename the potential several resultant files coming
>>> out of `mythccextractor`.  Since you're not using `mythccextractor`,
>>>
>>> > from MythTV import System
>>> > ccextractor = System(path="/home/dave/uksub2srt/uksub2srt.py")
>>> > ccextractor('-i', os.path.join(sg.dirname, prog.basename),
>>> >             '-o', '/home/subtitles/{0}.srt'.format(newbase))
>>>
>>> this down here was supposed to replace it.  Additionally, unless you're
>>> trying to limit certain modules to certain scopes, either to keep the
>>> namespace clean or because that scope may never be entered and there not
>>> be any need to import it, it's better to do your imports at the top of
>>> the file just so you know where to look for them.
>>>
>>> > import sys
>>> > if len(sys.argv) != 3:
>>> >     chanid, starttime = sys.argv[1:3]
>>>
>>> You can't do anything until you get your recording from the backend, and
>>> you can't do that until you know what chanid and starttime you want the
>>> information for.  Pulling that information out of your command line
>>> variables at the end of the script isn't going to do you any good.
>>> _______________________________________________
>>> mythtv-users mailing list
>>> mythtv-users at mythtv.org
>>> http://www.mythtv.org/mailman/listinfo/mythtv-users
>>>
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.mythtv.org/pipermail/mythtv-users/attachments/20120203/f83e5f36/attachment.html 


More information about the mythtv-users mailing list