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

David Crawford davidcrawford83 at gmail.com
Fri Feb 3 20:14:10 UTC 2012


Thanks a lot Jeremy, you have made things clearer and now i can get past
that line in the command line without being told of a syntax error. However
now i get:

     raise Exception('Invalid argument count')
Exception: Invalid argument count

this is the script so far:

#!/usr/bin/env python

import sys
import os

if len(sys.argv) != 3:
    raise Exception('Invalid argument count')
chanid, starttime = sys.argv[1:3]

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


On 3 February 2012 20:00, Jeremy Jones <jeremy.dwain.jones at gmail.com> wrote:

> David,
>
> I am also a novice at python, so I can empathize.
>
> Remember that when you are learning new code: *search engines are your
> friend*.  I googled:"python sys.argv list" and the second link produced
> this:
> http://stackoverflow.com/questions/2626026/python-sys-argv-lists-and-indexes which
> explains what the line code below is doing very well.
>
>   chanid, starttime = sys.argv[1:3]
>
> I still did not understand why Raymond told you use [1:3] to populate two
> variables, so I again went to google with the search, "python use of colon
> in list".  The second item listed was:
> http://stackoverflow.com/questions/4012340/python-colon-in-list-index
>
> Now I know from reading that page that the list is using items1 to 3, but
> not including 3.  The items you passed from the command line were what you
> want for input as the channel Id and the start time.  The command:
>
>   chanid, starttime = sys.argv[1:3]
>
> is storing those passed parameters into variables named:
> chanid
> starttime
>
> Therefore the line:
>   prog = be.getRecording(<chanid>, <be>)
>
> should be:
> prog = be.getRecording(chanid, starttime)
>
> What Raymond was telling you about the brackets "< >" was that they are
> generic placeholders for which one would insert the required information
> into that function call, not an actual part of the syntax of the code.
>  Since you are passing that information from the command line, and not
> "hard coding" it in the script, you need to use the same variables that
> were used to store that information from the command line.
>
>
> Jeremy
>
>
>
>
>
> _______________________________________________
> 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/f9a3d5c1/attachment.html 


More information about the mythtv-users mailing list