<br><br><div class="gmail_quote">On 10 February 2012 15:44, David Crawford <span dir="ltr">&lt;<a href="mailto:davidcrawford83@gmail.com">davidcrawford83@gmail.com</a>&gt;</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 15:36, Raymond Wagner <span dir="ltr">&lt;<a href="mailto:raymond@wagnerrp.com" target="_blank">raymond@wagnerrp.com</a>&gt;</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>
&gt; path = &#39;%cn %cc %cN.srt&#39;<br>
<br>
</div>Doing this in Python means you&#39;ve stored that string to the variable<br>
&#39;path&#39;.  Now in Python, everything is object, and objects have methods.<br>
In this particular case, you want to use the &#39;replace&#39; method, which<br>
replaces one string with another, and outputs the result.  That is this...<br>
<div><br>
&gt;     path = path.replace(&#39;%&#39;+tag, tmp)<br>
<br>
</div>In Python, strings are &#39;mutable&#39;, 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&#39;t want that<br>
path string up there.  You want to use this one defined lower...<br>
<br>
&gt; &#39;%m-%d_%H-%i-%s_%cN_%T&#39;<br>
<br>
So define that to a variable, and replace whatever the bindings can&#39;t<br>
handle.  That&#39;s what this does down here.<br>
<div><br>
&gt; for (tag, data) in ((&#39;cn&#39;, &#39;channum&#39;),(&#39;cc&#39;,&#39;callsign&#39;),(&#39;cN&#39;,&#39;name&#39;)):<br>
&gt;     tmp = unicode(chan[data]).replace(&#39;/&#39;,&#39;-&#39;)<br>
&gt;     path = path.replace(&#39;%&#39;+tag, tmp)<br>
<br>
</div>It loops through those three sets of values, setting &#39;tag&#39; to &#39;cn&#39;, and<br>
&#39;data&#39; to &#39;channum&#39; 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 &#39;chan[data]&#39;, it is<br>
pulling the value mapped to the string currently stored in the &#39;data&#39;<br>
variable, which is &#39;channum&#39;, out of that associative array.<br>
<br>
Now you&#39;re only trying to use %cN, so there is no need for this<br>
construct.  You can just do the following directly...<br>
<br>
&gt; path = &#39;%m-%d_%H-%i-%s_%cN_%T&#39;<br>
&gt; chan = Channel(chanid)<br>
&gt; path = path.replace(&#39;%cN&#39;, <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>
&#39;.&#39;).  Remember, you still need to feed this new, modified path into the<br>
&#39;formatPath&#39; 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>Hi Raymond,<div><br></div><div>Thanks for the insights, i&#39;ve now changed the script around a bit. The thing is I still don&#39;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 = &#39;%m-%d_%H-%i-%sBBC ONE_%T&#39;</div><div><br></div><div>How to I feed this into </div><div>newbase = prog.formatPath(&#39;%m-%d_%H-%i-%s_%cN_%T&#39;).rsplit(&#39;.&#39;,1)[0] ?</div>
<div><br></div><div>This is the script up to date:</div><div><br></div><div><div>#!/usr/bin/python</div><div><br></div><div>import sys</div><div>import os</div><div>from MythTV import Channel</div><div>from MythTV import MythBE, findfile</div>
<div>from MythTV import System</div><div><br></div><div><br></div><div>if len(sys.argv) != 3:</div><div>    raise Exception(&#39;Invalid argument count&#39;)    </div><div>chanid, starttime = sys.argv[1:3]</div><div><br></div>
<div>be = MythBE()</div><div>prog = be.getRecording(chanid, starttime)</div><div>path = &#39;%m-%d_%H-%i-%s_%cN_%T&#39;</div><div>chan = Channel(chanid)</div><div>path = path.replace(&#39;%cN&#39;, <a href="http://chan.name">chan.name</a>)</div>
<div>oldbase = prog.filename.rsplit(&#39;.&#39;,1)[0]</div><div>newbase = prog.formatPath(&#39;%m-%d_%H-%i-%s_%cN_%T&#39;).rsplit(&#39;.&#39;,1)[0]</div><div>sg = findfile(prog.filename, prog.storagegroup)</div><div>if sg is None:</div>
<div>    raise Exception(&#39;file not found&#39;)</div><div><br></div><div><br></div><div>ccextractor = System(path=&quot;/home/dave/uksub2srt/uksub2srt.py&quot;)</div><div>ccextractor(&#39;-i&#39;, os.path.join(sg.dirname, prog.filename),</div>
<div>             &#39;-o&#39;, &#39;/home/dave/Downloads/subtitles/{0}.srt&#39;.format(newbase))</div><div>print path</div></div><div><br></div>