<br><br><div class="gmail_quote">On 10 February 2012 18:27, David Crawford <span dir="ltr"><<a href="mailto:davidcrawford83@gmail.com">davidcrawford83@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5"><br><br><div class="gmail_quote">On 10 February 2012 18:00, David Crawford <span dir="ltr"><<a href="mailto:davidcrawford83@gmail.com" target="_blank">davidcrawford83@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><div><br><br><div class="gmail_quote">On 10 February 2012 15:49, David Crawford <span dir="ltr"><<a href="mailto:davidcrawford83@gmail.com" target="_blank">davidcrawford83@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><div><br><br><div class="gmail_quote">On 10 February 2012 15:44, David Crawford <span dir="ltr"><<a href="mailto:davidcrawford83@gmail.com" target="_blank">davidcrawford83@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><div><br><br><div class="gmail_quote">On 10 February 2012 15:36, Raymond Wagner <span dir="ltr"><<a href="mailto:raymond@wagnerrp.com" target="_blank">raymond@wagnerrp.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>On 2/10/2012 09:12, David Crawford wrote:<br>
> path = '%cn %cc %cN.srt'<br>
<br>
</div>Doing this in Python means you've stored that string to the variable<br>
'path'. Now in Python, everything is object, and objects have methods.<br>
In this particular case, you want to use the 'replace' method, which<br>
replaces one string with another, and outputs the result. That is this...<br>
<div><br>
> path = path.replace('%'+tag, tmp)<br>
<br>
</div>In Python, strings are 'mutable', meaning they cannot be changed. The<br>
only way to modify the string stored to a variable is to store a new<br>
string to that variable, as described above. Except you don't want that<br>
path string up there. You want to use this one defined lower...<br>
<br>
> '%m-%d_%H-%i-%s_%cN_%T'<br>
<br>
So define that to a variable, and replace whatever the bindings can't<br>
handle. That's what this does down here.<br>
<div><br>
> for (tag, data) in (('cn', 'channum'),('cc','callsign'),('cN','name')):<br>
> tmp = unicode(chan[data]).replace('/','-')<br>
> path = path.replace('%'+tag, tmp)<br>
<br>
</div>It loops through those three sets of values, setting 'tag' to 'cn', and<br>
'data' to 'channum' on the first pass. The Channel class is configured<br>
to imitate a dictionary, or map, or associative array, depending on your<br>
programming language of preference. When it pulls 'chan[data]', it is<br>
pulling the value mapped to the string currently stored in the 'data'<br>
variable, which is 'channum', out of that associative array.<br>
<br>
Now you're only trying to use %cN, so there is no need for this<br>
construct. You can just do the following directly...<br>
<br>
> path = '%m-%d_%H-%i-%s_%cN_%T'<br>
> chan = Channel(chanid)<br>
> path = path.replace('%cN', <a href="http://chan.name" target="_blank">chan.name</a>)<br>
<br>
The Channel class makes all of those associative array values also<br>
available as class attributes. Attributes are just variables stored<br>
against an object, and accessed in the same manner as methods (with a<br>
'.'). Remember, you still need to feed this new, modified path into the<br>
'formatPath' method, to get out your desired result.<br>
<div><div><br>
_______________________________________________<br>
mythtv-users mailing list<br>
<a href="mailto:mythtv-users@mythtv.org" target="_blank">mythtv-users@mythtv.org</a><br>
<a href="http://www.mythtv.org/mailman/listinfo/mythtv-users" target="_blank">http://www.mythtv.org/mailman/listinfo/mythtv-users</a><br>
</div></div></blockquote></div><br>
</div></div></blockquote></div></div></div>Hi Raymond,<div><br></div><div>Thanks for the insights, i've now changed the script around a bit. The thing is I still don't know how to feed the replaced object in this case %cN into the format.path</div>
<div><br></div><div>it just gives me the same output and prints the path:</div><div> path = '%m-%d_%H-%i-%sBBC ONE_%T'</div><div><br></div><div>How to I feed this into </div><div>newbase = prog.formatPath('%m-%d_%H-%i-%s_%cN_%T').rsplit('.',1)[0] ?</div>
<div><br></div><div>This is the script up to date:</div><div><br></div><div><div><div>#!/usr/bin/python</div><div><br></div><div>import sys</div><div>import os</div></div><div>from MythTV import Channel</div><div>
<div>from MythTV import MythBE, findfile</div>
</div><div>from MythTV import System</div><div><div><br></div><div><br></div><div>if len(sys.argv) != 3:</div><div> raise Exception('Invalid argument count') </div><div>chanid, starttime = sys.argv[1:3]</div>
<div><br></div>
</div><div><div>be = MythBE()</div><div>prog = be.getRecording(chanid, starttime)</div></div><div><div>path = '%m-%d_%H-%i-%s_%cN_%T'</div><div>chan = Channel(chanid)</div><div>path = path.replace('%cN', <a href="http://chan.name" target="_blank">chan.name</a>)</div>
</div><div><div>oldbase = prog.filename.rsplit('.',1)[0]</div><div>newbase = prog.formatPath('%m-%d_%H-%i-%s_%cN_%T').rsplit('.',1)[0]</div><div>sg = findfile(prog.filename, prog.storagegroup)</div>
<div>if sg is None:</div>
<div> raise Exception('file not found')</div><div><br></div><div><br></div></div><div><div>ccextractor = System(path="/home/dave/uksub2srt/uksub2srt.py")</div><div>ccextractor('-i', os.path.join(sg.dirname, prog.filename),</div>
<div> '-o', '/home/dave/Downloads/subtitles/{0}.srt'.format(newbase))</div></div><div>print path</div></div><div><br></div>
</blockquote></div><span>Remember, you still need to feed this new, modified path into the</span><br><span>'formatPath' method, to get out your desired result.</span>
<div><span><br></span></div></div></div><div><span>Still can't figure this part out. Can anyone tell me how I can add this value:</span></div><div><div>path = path.replace('%cN', <a href="http://chan.name/" target="_blank">chan.name</a>)
</div><div><br></div></div><div>so it works with the 'formatPath'</div><div><br></div><div>Thought it might work just adding it all to one line but it gives me a syntax error. Is there a certain command i need to add?</div>
<div><br></div><div>cheers</div>
</blockquote></div><br></div></div><div>Ok changing the formatPath to:</div><div><br></div><div>newbase = prog.formatPath(path).rsplit('.',1)[0]</div><div><br></div><div>half works as half of the filename is missing and outputs the file up until where it says BBC, failing to output BBC ONE and the title.srt</div>
<div><br></div><div>Does anyone know what i need to add to make it give the full path here?</div><div><br></div><div>Dave</div>
</blockquote></div><br><div>Ok adding " " before and after %cN in the path seems to have done the trick. Looks like i got there in the end :S </div>