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

Raymond Wagner raymond at wagnerrp.com
Tue Jan 31 01:27:55 UTC 2012


On 1/30/2012 20:03, Michael T. Dean wrote:
> fixed top-posting
>
> On 01/30/2012 07:09 PM, David Crawford wrote:
>> On 30 January 2012 23:33, Jeremy Jones wrote:
>>> On Mon, Jan 30, 2012 at 1:34 PM, David Crawford wrote:
>>>> I managed to get the script to work as a userjob in the end (whay hey!)
>>>>
>>>> only thing is the file names system of the recordings. I use an app to
>>>> search through the subtitles and its designed to work with files with a
>>>> particular format (basicially the one used in DVBVIewer).
>>>>
>>>> Is there a way that I can maybe add a script that can change the
>>>> filenames of the ripped subtitle files to read like:
>>>> %date%-%time%-%channel%-%programme% ?
>>> Take a look at mythlink.pl.  It is designed to create symbolic links
>>> of your recordings with *pretty* names like you described above, but
>>> with some string substitutions, I bet you can piece something together
>>> to work for your user created subtitle files. (If I understand what
>>> you are doing in your userjob correctly)
>> Yeah, I actually took a look at that. The thing is I want to actually
>> re-name the subtitle files only in this "pretty" format otherwise the
>> application I have wont be able to read them properly. Just not sure how to
>> piece together what i need..
> I was thinking your script is in Python, in which case you probably want
> to use the Python bindings' support for creating pretty names.  It works
> with the same formatting specifiers as the Perl bindings'/mythlink.pl ones.

Specifically 
http://www.mythtv.org/wiki/0.24_Python_bindings/Data_Handlers#formatPath

You could do something like...

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]))


More information about the mythtv-users mailing list