Plugins: albumart.4.2.py

File albumart.4.2.py, 86.2 kB (added by superwolfe2000@hotmail.com, 3 months ago)
Line 
1 <!DOCTYPE html
2     PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
3     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
4 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
5 <head>
6  <title>Plugins: albumart.4.py - Ex Falso / Quod Libet - Trac</title><link rel="start" href="/quodlibet/wiki" /><link rel="search" href="/quodlibet/search" /><link rel="help" href="/quodlibet/wiki/TracGuide" /><link rel="stylesheet" href="/quodlibet/chrome/common/css/trac.css" type="text/css" /><link rel="stylesheet" href="/quodlibet/chrome/common/css/code.css" type="text/css" /><link rel="icon" href="/~piman/images/2006/quodlibet.png" type="image/png" /><link rel="shortcut icon" href="/~piman/images/2006/quodlibet.png" type="image/png" /><link rel="up" href="/quodlibet/wiki/Plugins" title="Plugins" /><link rel="alternate" href="/quodlibet/attachment/wiki/Plugins/albumart.4.py?format=raw" title="Original Format" type="text/x-python; charset=utf-8" /><style type="text/css">
7
8 table.download { width: 60%; }
9
10 table.download thead {
11         text-align: left;
12         font-weight: bold;
13 }
14
15
16 body {
17  margin: 0;
18  padding: 0;
19 }
20
21 #proj-left {
22 /*  float: left; */
23  z-index: 2;
24  margin: 0;
25  margin-top: 20px;
26  margin-bottom: 20px;
27  max-width: 175px;
28  position: absolute;
29  top: 120px;
30  left: 0px;
31  width: 140px;
32 }
33
34 #proj-menu ul li a {
35  color: #333;
36  display: block;
37  text-decoration: none;
38  padding: 3px;
39  padding-left: 10px;
40  background: #fff;
41  border: none;
42  border-left: 9px solid #ebe;
43 }
44 #proj-menu ul li a:hover {
45  padding-left: 10px;
46  color: #000;
47  background: #f7f7f7;
48  border-left: 9px solid #a6a;
49 }
50 #proj-menu ul li:hover { border: 1px solid #660; }
51 #proj-menu ul { list-style: none; margin: 0; margin-bottom: 2em;
52 padding: 0;
53   border-top: 1px dotted #d7d7d7; 
54  }
55 #proj-menu ul li {
56  margin: 0;
57  padding: 0;
58  background-color: #f0f7f7;
59  border: 1px solid #fff;
60  border-left-color: #e5e5e5;
61  border-bottom: 1px dotted #d7d7d7;
62 }
63
64 #proj-left h2 {
65  margin: .5em 0;
66  margin-bottom: 0;
67  margin-left: 0px;
68  padding: .01em .5em;
69  font-size: 12px;
70  font-weight: bold;
71  background: #fbb200;
72  color: #000;
73 }
74
75 #proj-left .section {
76  padding-left: 12px;
77 }
78
79 #proj-left .section {
80  padding-left: 12px;
81 }
82
83 #proj-left .section a {
84  border-left: none !important;
85 }
86
87 #main { margin: 0; margin-left: 145px; padding: 0em; }
88
89 p.right { padding-right: 1em }
90 </style>
91  <script type="text/javascript" src="/quodlibet/chrome/common/js/trac.js"></script>
92 </head>
93 <body>
94
95
96 <div id="proj-left">
97
98  <div id="proj-menu">
99
100   <ul>
101    <li><a href="/quodlibet">Home</a></li>
102    <li><a href="/quodlibet/wiki/Guide">Guide</a></li>
103    <li><a href="/quodlibet/wiki/FAQ">FAQ</a></li>
104    <li><a href="/quodlibet/wiki/Download">Download</a></li>
105    <li><a href="/quodlibet/wiki/Development/Mutagen">Mutagen</a></li>
106    <li><a href="/quodlibet/wiki/Development">Development</a></li>
107    <li><a href="/quodlibet/wiki/Contact">Contact</a></li>
108   </ul>
109  </div>
110 </div>
111
112
113 <div id="banner">
114
115 <div id="header"><a id="logo" href="http://www.sacredchao.net/quodlibet"><img src="/~piman/images/2006/ql-site-logo.png" alt="" /></a><hr /></div>
116
117 <form id="search" action="/quodlibet/search" method="get">
118  <div>
119   <label for="proj-search">Search:</label>
120   <input type="text" id="proj-search" name="q" size="10" accesskey="f" value="" />
121   <input type="submit" value="Search" />
122   <input type="hidden" name="wiki" value="on" />
123   <input type="hidden" name="changeset" value="on" />
124   <input type="hidden" name="ticket" value="on" />
125  </div>
126 </form>
127
128
129
130 <div id="metanav" class="nav"><ul><li class="first"><a href="/quodlibet/login">Login</a></li><li><a href="/quodlibet/about">About Trac</a></li><li><a accesskey="6" href="/quodlibet/wiki/TracGuide">Help/Guide</a></li><li class="last"><a href="/quodlibet/settings">Settings</a></li></ul></div>
131 </div>
132
133 <div id="mainnav" class="nav"><ul><li class="active first"><a accesskey="1" href="/quodlibet/wiki">Wiki</a></li><li><a accesskey="2" href="/quodlibet/timeline">Timeline</a></li><li><a accesskey="3" href="/quodlibet/roadmap">Roadmap</a></li><li><a href="/quodlibet/browser">Browse Source</a></li><li><a href="/quodlibet/report">View Tickets</a></li><li class="last"><a accesskey="4" href="/quodlibet/search">Search</a></li></ul></div>
134 <div id="main">
135
136
137
138
139 <div id="ctxtnav" class="nav"></div>
140
141 <div id="content" class="attachment">
142
143
144  <h1><a href="/quodlibet/wiki/Plugins">Plugins</a>: albumart.4.py</h1>
145  <table id="info" summary="Description"><tbody><tr>
146    <th scope="col">
147     File albumart.4.py, 20.2 kB
148     (added by wxcover,  1 month ago)
149    </th></tr><tr>
150    <td class="message"><p>
151 New version (0.4) of albumart : uses pyAWS; searches on amazon, walmart, darktown and buy.com; search box available; few fixes.
152 </p>
153 </td>
154   </tr>
155  </tbody></table>
156  <div id="preview">
157    <table class="code"><thead><tr><th class="lineno">Line</th><th class="content">&nbsp;</th></tr></thead><tbody><tr><th id="L1"><a href="#L1">1</a></th>
158 <td><I><span class="code-comment">#Copyright 2005-2008 Eduardo Gonzalez, Niklas Janlert, Christoph Reiter, Antonio Riva</span></I></td>
159 </tr><tr><th id="L2"><a href="#L2">2</a></th>
160 <td><I><span class="code-comment"></span></I><I><span class="code-comment">#Amazon API code by Mark Pilgrim</span></I></td>
161 </tr><tr><th id="L3"><a href="#L3">3</a></th>
162 <td><I><span class="code-comment"></span></I><I><span class="code-comment">#</span></I></td>
163 </tr><tr><th id="L4"><a href="#L4">4</a></th>
164 <td><I><span class="code-comment"></span></I><I><span class="code-comment"># This program is free software; you can redistribute it and/or modify</span></I></td>
165 </tr><tr><th id="L5"><a href="#L5">5</a></th>
166 <td><I><span class="code-comment"></span></I><I><span class="code-comment"># it under the terms of the GNU General Public License version 2 as</span></I></td>
167 </tr><tr><th id="L6"><a href="#L6">6</a></th>
168 <td><I><span class="code-comment"></span></I><I><span class="code-comment"># published by the Free Software Foundation</span></I></td>
169 </tr><tr><th id="L7"><a href="#L7">7</a></th>
170 <td><I><span class="code-comment"></span></I></td>
171 </tr><tr><th id="L8"><a href="#L8">8</a></th>
172 <td><I><span class="code-comment"># Last Modified: Tue 2008-05-13 19:40:12 (+0200) by &lt;wxcover@users.sourceforge.net&gt;</span></I></td>
173 </tr><tr><th id="L9"><a href="#L9">9</a></th>
174 <td><I><span class="code-comment"></span></I><I><span class="code-comment"># -Added walmart, darktown and buy.com cover searching.</span></I></td>
175 </tr><tr><th id="L10"><a href="#L10">10</a></th>
176 <td><I><span class="code-comment"></span></I><I><span class="code-comment"># -Few fixes</span></I></td>
177 </tr><tr><th id="L11"><a href="#L11">11</a></th>
178 <td><I><span class="code-comment"></span></I><I><span class="code-comment"># -Updated version number (0.25 -&gt; 0.4)</span></I></td>
179 </tr><tr><th id="L12"><a href="#L12">12</a></th>
180 <td><I><span class="code-comment"></span></I></td>
181 </tr><tr><th id="L13"><a href="#L13">13</a></th>
182 <td><I><span class="code-comment"># Mon 2008-05-05 14:54:27 (-0400)</span></I></td>
183 </tr><tr><th id="L14"><a href="#L14">14</a></th>
184 <td><I><span class="code-comment"></span></I><I><span class="code-comment"># Updated for new Amazon API by Jeremy Cantrell &lt;jmcantrell@gmail.com&gt;</span></I></td>
185 </tr><tr><th id="L15"><a href="#L15">15</a></th>
186 <td><I><span class="code-comment"></span></I></td>
187 </tr><tr><th id="L16"><a href="#L16">16</a></th>
188 <td><B><span class="code-lang">import</span></B>&nbsp;os</td>
189 </tr><tr><th id="L17"><a href="#L17">17</a></th>
190 <td><B><span class="code-lang">import</span></B>&nbsp;sys</td>
191 </tr><tr><th id="L18"><a href="#L18">18</a></th>
192 <td><B><span class="code-lang">import</span></B>&nbsp;urllib</td>
193 </tr><tr><th id="L19"><a href="#L19">19</a></th>
194 <td><B><span class="code-lang">import</span></B>&nbsp;re</td>
195 </tr><tr><th id="L20"><a href="#L20">20</a></th>
196 <td><B><span class="code-lang">import</span></B>&nbsp;time</td>
197 </tr><tr><th id="L21"><a href="#L21">21</a></th>
198 <td><B><span class="code-lang">import</span></B>&nbsp;threading</td>
199 </tr><tr><th id="L22"><a href="#L22">22</a></th>
200 <td><B><span class="code-lang">from</span></B>&nbsp;cStringIO <B><span class="code-lang">import</span></B> StringIO</td>
201 </tr><tr><th id="L23"><a href="#L23">23</a></th>
202 <td><B><span class="code-lang">import</span></B>&nbsp;gtk</td>
203 </tr><tr><th id="L24"><a href="#L24">24</a></th>
204 <td><B><span class="code-lang">import</span></B>&nbsp;gobject</td>
205 </tr><tr><th id="L25"><a href="#L25">25</a></th>
206 <td><B><span class="code-lang">import</span></B>&nbsp;pango</td>
207 </tr><tr><th id="L26"><a href="#L26">26</a></th>
208 <td><B><span class="code-lang">import</span></B>&nbsp;util</td>
209 </tr><tr><th id="L27"><a href="#L27">27</a></th>
210 <td><B><span class="code-lang">import</span></B>&nbsp;qltk</td>
211 </tr><tr><th id="L28"><a href="#L28">28</a></th>
212 <td><B><span class="code-lang">import</span></B>&nbsp;config</td>
213 </tr><tr><th id="L29"><a href="#L29">29</a></th>
214 <td></td>
215 </tr><tr><th id="L30"><a href="#L30">30</a></th>
216 <td><B><span class="code-lang">from</span></B>&nbsp;plugins.songsmenu <B><span class="code-lang">import</span></B> SongsMenuPlugin</td>
217 </tr><tr><th id="L31"><a href="#L31">31</a></th>
218 <td></td>
219 </tr><tr><th id="L32"><a href="#L32">32</a></th>
220 <td><B><span class="code-lang">if</span></B>&nbsp;sys.version_info &lt; (2, 4): <B><span class="code-lang">from</span></B> sets <B><span class="code-lang">import</span></B> Set as set</td>
221 </tr><tr><th id="L33"><a href="#L33">33</a></th>
222 <td></td>
223 </tr><tr><th id="L34"><a href="#L34">34</a></th>
224 <td><B><span class="code-lang">from</span></B>&nbsp;pyaws <B><span class="code-lang">import</span></B> ecs</td>
225 </tr><tr><th id="L35"><a href="#L35">35</a></th>
226 <td></td>
227 </tr><tr><th id="L36"><a href="#L36">36</a></th>
228 <td><B><span class="code-lang">class</span></B>&nbsp;AlbumArtWindow(gtk.Window):</td>
229 </tr><tr><th id="L37"><a href="#L37">37</a></th>
230 <td>&nbsp; &nbsp; <B><span class="code-lang">def</span></B> <B><span class="code-func">__init__</span></B>(self, songs):</td>
231 </tr><tr><th id="L38"><a href="#L38">38</a></th>
232 <td>&nbsp; &nbsp; &nbsp; &nbsp; gtk.Window.__init__(self)</td>
233 </tr><tr><th id="L39"><a href="#L39">39</a></th>
234 <td>&nbsp; &nbsp; &nbsp; &nbsp; self.set_border_width(12)</td>
235 </tr><tr><th id="L40"><a href="#L40">40</a></th>
236 <td>&nbsp; &nbsp; &nbsp; &nbsp; self.set_title(<B><span class="code-string">&quot;AlbumArt&quot;</span></B>)</td>
237 </tr><tr><th id="L41"><a href="#L41">41</a></th>
238 <td>&nbsp; &nbsp; &nbsp; &nbsp; self.set_default_size(850, 550)</td>
239 </tr><tr><th id="L42"><a href="#L42">42</a></th>
240 <td></td>
241 </tr><tr><th id="L43"><a href="#L43">43</a></th>
242 <td>&nbsp; &nbsp; &nbsp; &nbsp; <I><span class="code-comment">#TreeView stuff</span></I></td>
243 </tr><tr><th id="L44"><a href="#L44">44</a></th>
244 <td><I><span class="code-comment"></span></I>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;self.liststore = liststore = gtk.ListStore(object, str)</td>
245 </tr><tr><th id="L45"><a href="#L45">45</a></th>
246 <td>&nbsp; &nbsp; &nbsp; &nbsp; treeview = gtk.TreeView(liststore)</td>
247 </tr><tr><th id="L46"><a href="#L46">46</a></th>
248 <td>&nbsp; &nbsp; &nbsp; &nbsp; treeview.set_headers_visible(False)</td>
249 </tr><tr><th id="L47"><a href="#L47">47</a></th>
250 <td>&nbsp; &nbsp; &nbsp; &nbsp; selection = treeview.get_selection()</td>
251 </tr><tr><th id="L48"><a href="#L48">48</a></th>
252 <td>&nbsp; &nbsp; &nbsp; &nbsp; selection.set_mode(gtk.SELECTION_SINGLE)</td>
253 </tr><tr><th id="L49"><a href="#L49">49</a></th>
254 <td>&nbsp; &nbsp; &nbsp; &nbsp; selection.connect(<B><span class="code-string">&quot;changed&quot;</span></B>, self.__preview)</td>
255 </tr><tr><th id="L50"><a href="#L50">50</a></th>
256 <td></td>
257 </tr><tr><th id="L51"><a href="#L51">51</a></th>
258 <td>&nbsp; &nbsp; &nbsp; &nbsp; self.url = url = gtk.Entry()</td>
259 </tr><tr><th id="L52"><a href="#L52">52</a></th>
260 <td>&nbsp; &nbsp; &nbsp; &nbsp; url.set_text(songs[0](<B><span class="code-string">&quot;artist&quot;</span></B>) + <B><span class="code-string">&quot; &quot;</span></B> + songs[0](<B><span class="code-string">&quot;album&quot;</span></B>))</td>
261 </tr><tr><th id="L53"><a href="#L53">53</a></th>
262 <td>&nbsp; &nbsp; &nbsp; &nbsp;</td>
263 </tr><tr><th id="L54"><a href="#L54">54</a></th>
264 <td>&nbsp; &nbsp; &nbsp; &nbsp; urlButton = gtk.Button(<B><span class="code-string">&quot;Search&quot;</span></B>)</td>
265 </tr><tr><th id="L55"><a href="#L55">55</a></th>
266 <td>&nbsp; &nbsp; &nbsp; &nbsp; urlButton.connect(<B><span class="code-string">&quot;clicked&quot;</span></B>, self.__start_search, url,liststore)</td>
267 </tr><tr><th id="L56"><a href="#L56">56</a></th>
268 <td>&nbsp; &nbsp; &nbsp; &nbsp; url.connect(<B><span class="code-string">&quot;key-release-event&quot;</span></B>, self.key_start_search, url,liststore)</td>
269 </tr><tr><th id="L57"><a href="#L57">57</a></th>
270 <td>&nbsp; &nbsp; &nbsp; </td>
271 </tr><tr><th id="L58"><a href="#L58">58</a></th>
272 <td>&nbsp; &nbsp; &nbsp; &nbsp; urlBox= gtk.HBox()</td>
273 </tr><tr><th id="L59"><a href="#L59">59</a></th>
274 <td>&nbsp; &nbsp; &nbsp; &nbsp; urlBox.pack_start(url, expand=True, fill=True)</td>
275 </tr><tr><th id="L60"><a href="#L60">60</a></th>
276 <td>&nbsp; &nbsp; &nbsp; &nbsp; urlBox.pack_start(urlButton, expand=False, fill=False)</td>
277 </tr><tr><th id="L61"><a href="#L61">61</a></th>
278 <td></td>
279 </tr><tr><th id="L62"><a href="#L62">62</a></th>
280 <td>&nbsp; &nbsp; &nbsp; &nbsp; rend = gtk.CellRendererPixbuf()</td>
281 </tr><tr><th id="L63"><a href="#L63">63</a></th>
282 <td>&nbsp; &nbsp; &nbsp; &nbsp; <B><span class="code-lang">def</span></B> <B><span class="code-func">cell_data</span></B>(column, cell, model, iter):</td>
283 </tr><tr><th id="L64"><a href="#L64">64</a></th>
284 <td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cell.set_property(<B><span class="code-string">&quot;pixbuf&quot;</span></B>, model[iter][0][<B><span class="code-string">&quot;thumb&quot;</span></B>])</td>
285 </tr><tr><th id="L65"><a href="#L65">65</a></th>
286 <td>&nbsp; &nbsp; &nbsp; &nbsp; tvcol1 = gtk.TreeViewColumn(<B><span class="code-string">&quot;Pixbuf&quot;</span></B>, rend)</td>
287 </tr><tr><th id="L66"><a href="#L66">66</a></th>
288 <td>&nbsp; &nbsp; &nbsp; &nbsp; tvcol1.set_cell_data_func(rend, cell_data)</td>
289 </tr><tr><th id="L67"><a href="#L67">67</a></th>
290 <td>&nbsp; &nbsp; &nbsp; &nbsp; tvcol1.set_sizing(gtk.TREE_VIEW_COLUMN_GROW_ONLY)</td>
291 </tr><tr><th id="L68"><a href="#L68">68</a></th>
292 <td>&nbsp; &nbsp; &nbsp; &nbsp; rend.set_property(<B><span class="code-string">'xpad'</span></B>, 2)</td>
293 </tr><tr><th id="L69"><a href="#L69">69</a></th>
294 <td>&nbsp; &nbsp; &nbsp; &nbsp; rend.set_property(<B><span class="code-string">'ypad'</span></B>, 2)</td>
295 </tr><tr><th id="L70"><a href="#L70">70</a></th>
296 <td>&nbsp; &nbsp; &nbsp; &nbsp; rend.set_property(<B><span class="code-string">'width'</span></B>, 56)</td>
297 </tr><tr><th id="L71"><a href="#L71">71</a></th>
298 <td>&nbsp; &nbsp; &nbsp; &nbsp; rend.set_property(<B><span class="code-string">'height'</span></B>, 56)</td>
299 </tr><tr><th id="L72"><a href="#L72">72</a></th>
300 <td>&nbsp; &nbsp; &nbsp; &nbsp; treeview.append_column(tvcol1)</td>
301 </tr><tr><th id="L73"><a href="#L73">73</a></th>
302 <td></td>
303 </tr><tr><th id="L74"><a href="#L74">74</a></th>
304 <td>&nbsp; &nbsp; &nbsp; &nbsp; rend = gtk.CellRendererText()</td>
305 </tr><tr><th id="L75"><a href="#L75">75</a></th>
306 <td>&nbsp; &nbsp; &nbsp; &nbsp; rend.set_property(<B><span class="code-string">&quot;ellipsize&quot;</span></B>, pango.ELLIPSIZE_END)</td>
307 </tr><tr><th id="L76"><a href="#L76">76</a></th>
308 <td>&nbsp; &nbsp; &nbsp; &nbsp; tvcol2 = gtk.TreeViewColumn(<B><span class="code-string">&quot;Info&quot;</span></B>, rend, markup=1)</td>
309 </tr><tr><th id="L77"><a href="#L77">77</a></th>
310 <td>&nbsp; &nbsp; &nbsp; &nbsp; treeview.append_column(tvcol2)</td>
311 </tr><tr><th id="L78"><a href="#L78">78</a></th>
312 <td></td>
313 </tr><tr><th id="L79"><a href="#L79">79</a></th>
314 <td>&nbsp; &nbsp; &nbsp; &nbsp; sw = gtk.ScrolledWindow()</td>
315 </tr><tr><th id="L80"><a href="#L80">80</a></th>
316 <td>&nbsp; &nbsp; &nbsp; &nbsp; sw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)</td>
317 </tr><tr><th id="L81"><a href="#L81">81</a></th>
318 <td>&nbsp; &nbsp; &nbsp; &nbsp; sw.set_shadow_type(gtk.SHADOW_IN)</td>
319 </tr><tr><th id="L82"><a href="#L82">82</a></th>
320 <td>&nbsp; &nbsp; &nbsp; &nbsp; sw.add(treeview)</td>
321 </tr><tr><th id="L83"><a href="#L83">83</a></th>
322 <td></td>
323 </tr><tr><th id="L84"><a href="#L84">84</a></th>
324 <td>&nbsp; &nbsp; &nbsp; &nbsp; <I><span class="code-comment">#Image frame and save button</span></I></td>
325 </tr><tr><th id="L85"><a href="#L85">85</a></th>
326 <td><I><span class="code-comment"></span></I>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;self.image = image = gtk.Image()</td>
327 </tr><tr><th id="L86"><a href="#L86">86</a></th>
328 <td>&nbsp; &nbsp; &nbsp; &nbsp; frame = gtk.Frame()</td>
329 </tr><tr><th id="L87"><a href="#L87">87</a></th>
330 <td>&nbsp; &nbsp; &nbsp; &nbsp; frame.set_shadow_type(gtk.SHADOW_IN)</td>
331 </tr><tr><th id="L88"><a href="#L88">88</a></th>
332 <td>&nbsp; &nbsp; &nbsp; &nbsp; frame.add(image)</td>
333 </tr><tr><th id="L89"><a href="#L89">89</a></th>
334 <td>&nbsp; &nbsp; &nbsp; &nbsp; scrolled = gtk.ScrolledWindow()</td>
335 </tr><tr><th id="L90"><a href="#L90">90</a></th>
336 <td>&nbsp; &nbsp; &nbsp; &nbsp; scrolled.add_with_viewport(frame)</td>
337 </tr><tr><th id="L91"><a href="#L91">91</a></th>
338 <td>&nbsp; &nbsp; &nbsp; &nbsp; scrolled.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)</td>
339 </tr><tr><th id="L92"><a href="#L92">92</a></th>
340 <td>&nbsp; &nbsp; &nbsp; &nbsp; vbox = gtk.VBox(spacing=5)</td>
341 </tr><tr><th id="L93"><a href="#L93">93</a></th>
342 <td>&nbsp; &nbsp; &nbsp; &nbsp; vbox.pack_start(scrolled)</td>
343 </tr><tr><th id="L94"><a href="#L94">94</a></th>
344 <td>&nbsp; &nbsp; &nbsp; &nbsp; self.button = button = gtk.Button(stock=gtk.STOCK_SAVE)</td>
345 </tr><tr><th id="L95"><a href="#L95">95</a></th>
346 <td>&nbsp; &nbsp; &nbsp; &nbsp; button.set_sensitive(False)</td>
347 </tr><tr><th id="L96"><a href="#L96">96</a></th>
348 <td>&nbsp; &nbsp; &nbsp; &nbsp; <B><span class="code-lang">def</span></B> <B><span class="code-func">save_cb</span></B>(button, combo):</td>
349 </tr><tr><th id="L97"><a href="#L97">97</a></th>
350 <td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; model, path = selection.get_selected()</td>
351 </tr><tr><th id="L98"><a href="#L98">98</a></th>
352 <td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; data = model[path][0][<B><span class="code-string">&quot;cover_data&quot;</span></B>]</td>
353 </tr><tr><th id="L99"><a href="#L99">99</a></th>
354 <td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fname = self.__get_fname(songs, combo)</td>
355 </tr><tr><th id="L100"><a href="#L100">100</a></th>
356 <td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.__save_cover(data, fname)</td>
357 </tr><tr><th id="L101"><a href="#L101">101</a></th>
358 <td>&nbsp; &nbsp; &nbsp; &nbsp; combo = gtk.combo_box_new_text()</td>
359 </tr><tr><th id="L102"><a href="#L102">102</a></th>
360 <td>&nbsp; &nbsp; &nbsp; &nbsp; <B><span class="code-lang">try</span></B>: set_fn = config.get(<B><span class="code-string">&quot;plugins&quot;</span></B>, <B><span class="code-string">&quot;cover_fn&quot;</span></B>)</td>
361 </tr><tr><th id="L103"><a href="#L103">103</a></th>
362 <td>&nbsp; &nbsp; &nbsp; &nbsp; <B><span class="code-lang">except</span></B>: set_fn = <B><span class="code-string">&quot;.folder.jpg&quot;</span></B></td>
363 </tr><tr><th id="L104"><a href="#L104">104</a></th>
364 <td>&nbsp; &nbsp; &nbsp; &nbsp; active = -1</td>
365 </tr><tr><th id="L105"><a href="#L105">105</a></th>
366 <td>&nbsp; &nbsp; &nbsp; &nbsp; <B><span class="code-lang">for</span></B> i, fn <B><span class="code-lang">in</span></B> enumerate([<B><span class="code-string">&quot;.folder.jpg&quot;</span></B>, <B><span class="code-string">&quot;folder.jpg&quot;</span></B>, <B><span class="code-string">&quot;cover.jpg&quot;</span></B>]):</td>
367 </tr><tr><th id="L106"><a href="#L106">106</a></th>
368 <td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; combo.append_text(fn)</td>
369 </tr><tr><th id="L107"><a href="#L107">107</a></th>
370 <td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <B><span class="code-lang">if</span></B> fn == set_fn: active = i</td>
371 </tr><tr><th id="L108"><a href="#L108">108</a></th>
372 <td>&nbsp; &nbsp; &nbsp; &nbsp; <B><span class="code-lang">if</span></B> active == -1:</td>
373 </tr><tr><th id="L109"><a href="#L109">109</a></th>
374 <td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; combo.append_text(set_fn)</td>
375 </tr><tr><th id="L110"><a href="#L110">110</a></th>
376 <td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; combo.set_active(len(combo.get_model()) - 1)</td>
377 </tr><tr><th id="L111"><a href="#L111">111</a></th>
378 <td>&nbsp; &nbsp; &nbsp; &nbsp; <B><span class="code-lang">else</span></B>: combo.set_active(active)</td>
379 </tr><tr><th id="L112"><a href="#L112">112</a></th>
380 <td>&nbsp; &nbsp; &nbsp; &nbsp; button.connect(<B><span class="code-string">&quot;clicked&quot;</span></B>, save_cb, combo)</td>
381 </tr><tr><th id="L113"><a href="#L113">113</a></th>
382 <td>&nbsp; &nbsp; &nbsp; &nbsp; bbox = gtk.HButtonBox()</td>
383 </tr><tr><th id="L114"><a href="#L114">114</a></th>
384 <td>&nbsp; &nbsp; &nbsp; &nbsp; bbox.pack_start(combo)</td>
385 </tr><tr><th id="L115"><a href="#L115">115</a></th>
386 <td>&nbsp; &nbsp; &nbsp; &nbsp; bbox.pack_start(button, expand=False, fill=False)</td>
387 </tr><tr><th id="L116"><a href="#L116">116</a></th>
388 <td>&nbsp; &nbsp; &nbsp; &nbsp; bbox.set_layout(gtk.BUTTONBOX_SPREAD)</td>
389 </tr><tr><th id="L117"><a href="#L117">117</a></th>
390 <td>&nbsp; &nbsp; &nbsp; &nbsp; vbox.pack_start(bbox, expand=False, fill=False)</td>
391 </tr><tr><th id="L118"><a href="#L118">118</a></th>
392 <td></td>
393 </tr><tr><th id="L119"><a href="#L119">119</a></th>
394 <td>&nbsp; &nbsp; &nbsp; &nbsp; hpaned = gtk.HPaned()</td>
395 </tr><tr><th id="L120"><a href="#L120">120</a></th>
396 <td>&nbsp; &nbsp; &nbsp; &nbsp; hpaned.pack1(sw)</td>
397 </tr><tr><th id="L121"><a href="#L121">121</a></th>
398 <td>&nbsp; &nbsp; &nbsp; &nbsp; hpaned.pack2(vbox)</td>
399 </tr><tr><th id="L122"><a href="#L122">122</a></th>
400 <td>&nbsp; &nbsp; &nbsp; &nbsp; hpaned.set_position(300)</td>
401 </tr><tr><th id="L123"><a href="#L123">123</a></th>
402 <td></td>
403 </tr><tr><th id="L124"><a href="#L124">124</a></th>
404 <td>&nbsp; &nbsp; &nbsp; &nbsp; vbox= gtk.VBox()</td>
405 </tr><tr><th id="L125"><a href="#L125">125</a></th>
406 <td>&nbsp; &nbsp; &nbsp; &nbsp; vbox.pack_start(urlBox, expand=False, fill=False)</td>
407 </tr><tr><th id="L126"><a href="#L126">126</a></th>
408 <td>&nbsp; &nbsp; &nbsp; &nbsp; vbox.pack_start(hpaned, expand=True, fill=True)</td>
409 </tr><tr><th id="L127"><a href="#L127">127</a></th>
410 <td>&nbsp; &nbsp; &nbsp; &nbsp; self.add(vbox)</td>
411 </tr><tr><th id="L128"><a href="#L128">128</a></th>
412 <td></td>
413 </tr><tr><th id="L129"><a href="#L129">129</a></th>
414 <td>&nbsp; &nbsp; &nbsp; &nbsp; <I><span class="code-comment">#define search engines</span></I></td>
415 </tr><tr><th id="L130"><a href="#L130">130</a></th>
416 <td><I><span class="code-comment"></span></I>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;self.engines = [self.__search_amazon, self.__search_walmart,</td>
417 </tr><tr><th id="L131"><a href="#L131">131</a></th>
418 <td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.__search_darktown, self.__search_buy]</td>
419 </tr><tr><th id="L132"><a href="#L132">132</a></th>
420 <td></td>
421 </tr><tr><th id="L133"><a href="#L133">133</a></th>
422 <td>&nbsp; &nbsp; &nbsp; &nbsp; <I><span class="code-comment">#max covers per site</span></I></td>
423 </tr><tr><th id="L134"><a href="#L134">134</a></th>
424 <td><I><span class="code-comment"></span></I>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;self.max_albums = 10</td>
425 </tr><tr><th id="L135"><a href="#L135">135</a></th>
426 <td>&nbsp; &nbsp; &nbsp; &nbsp;</td>
427 </tr><tr><th id="L136"><a href="#L136">136</a></th>
428 <td>&nbsp; &nbsp; &nbsp; &nbsp; <I><span class="code-comment">#for progress calculation</span></I></td>
429 </tr><tr><th id="L137"><a href="#L137">137</a></th>
430 <td><I><span class="code-comment"></span></I>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;self.progress = 0</td>
431 </tr><tr><th id="L138"><a href="#L138">138</a></th>
432 <td>&nbsp; &nbsp; &nbsp; &nbsp;</td>
433 </tr><tr><th id="L139"><a href="#L139">139</a></th>
434 <td>&nbsp; &nbsp; &nbsp; &nbsp; <I><span class="code-comment">#use albumartist if available</span></I></td>
435 </tr><tr><th id="L140"><a href="#L140">140</a></th>
436 <td><I><span class="code-comment"></span></I>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<B><span class="code-lang">if</span></B> songs[0](<B><span class="code-string">&quot;albumartist&quot;</span></B>):</td>
437 </tr><tr><th id="L141"><a href="#L141">141</a></th>
438 <td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; artist = songs[0](<B><span class="code-string">&quot;albumartist&quot;</span></B>)</td>
439 </tr><tr><th id="L142"><a href="#L142">142</a></th>
440 <td>&nbsp; &nbsp; &nbsp; &nbsp; <B><span class="code-lang">else</span></B>:</td>
441 </tr><tr><th id="L143"><a href="#L143">143</a></th>
442 <td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; artist = songs[0](<B><span class="code-string">&quot;artist&quot;</span></B>)</td>
443 </tr><tr><th id="L144"><a href="#L144">144</a></th>
444 <td>&nbsp; &nbsp; &nbsp; &nbsp; query = artist + <B><span class="code-string">&quot; &quot;</span></B> + songs[0](<B><span class="code-string">&quot;album&quot;</span></B>)</td>
445 </tr><tr><th id="L145"><a href="#L145">145</a></th>
446 <td>&nbsp; &nbsp; &nbsp; &nbsp; query = query.encode(<B><span class="code-string">&quot;latin1&quot;</span></B>, <B><span class="code-string">&quot;replace&quot;</span></B>)</td>
447 </tr><tr><th id="L146"><a href="#L146">146</a></th>
448 <td>&nbsp; &nbsp; &nbsp; &nbsp;</td>
449 </tr><tr><th id="L147"><a href="#L147">147</a></th>
450 <td>&nbsp; &nbsp; &nbsp; &nbsp; <I><span class="code-comment">#show search status row</span></I></td>
451 </tr><tr><th id="L148"><a href="#L148">148</a></th>
452 <td><I><span class="code-comment"></span></I>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;iter = self.liststore.insert(0)</td>
453 </tr><tr><th id="L149"><a href="#L149">149</a></th>
454 <td>&nbsp; &nbsp; &nbsp; &nbsp; self.liststore.set(iter, 0, {<B><span class="code-string">&quot;bag&quot;</span></B>:None,<B><span class="code-string">&quot;thumb&quot;</span></B>:None,<B><span class="code-string">&quot;thumb_data&quot;</span></B>:None})</td>
455 </tr><tr><th id="L150"><a href="#L150">150</a></th>
456 <td>&nbsp; &nbsp; &nbsp; &nbsp; self.liststore.set_value(iter, 1,</td>
457 </tr><tr><th id="L151"><a href="#L151">151</a></th>
458 <td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<B><span class="code-string">&quot;&lt;i&gt;&lt;b&gt;Searching progress: 0%&lt;/b&gt;&lt;/i&gt;&quot;</span></B>)</td>
459 </tr><tr><th id="L152"><a href="#L152">152</a></th>
460 <td></td>
461 </tr><tr><th id="L153"><a href="#L153">153</a></th>
462 <td>&nbsp; &nbsp; &nbsp; &nbsp; <I><span class="code-comment">#start all search engines in seperate threads</span></I></td>
463 </tr><tr><th id="L154"><a href="#L154">154</a></th>
464 <td><I><span class="code-comment"></span></I>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<B><span class="code-lang">for</span></B> i <B><span class="code-lang">in</span></B> xrange(len(self.engines)):</td>
465 </tr><tr><th id="L155"><a href="#L155">155</a></th>
466 <td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; thread = threading.Thread(target=self.__search,</td>
467 </tr><tr><th id="L156"><a href="#L156">156</a></th>
468 <td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; args=(query,i,iter,))</td>
469 </tr><tr><th id="L157"><a href="#L157">157</a></th>
470 <td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; thread.setDaemon(True)</td>
471 </tr><tr><th id="L158"><a href="#L158">158</a></th>
472 <td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; thread.start()</td>
473 </tr><tr><th id="L159"><a href="#L159">159</a></th>
474 <td></td>
475 </tr><tr><th id="L160"><a href="#L160">160</a></th>
476 <td>&nbsp; &nbsp; &nbsp; &nbsp; self.show_all()</td>
477 </tr><tr><th id="L161"><a href="#L161">161</a></th>
478 <td></td>
479 </tr><tr><th id="L162"><a href="#L162">162</a></th>
480 <td>&nbsp; &nbsp; <B><span class="code-lang">def</span></B> <B><span class="code-func">key_start_search</span></B>(self, widget,event, entry,liststore):</td>
481 </tr><tr><th id="L163"><a href="#L163">163</a></th>
482 <td>&nbsp; &nbsp; &nbsp; &nbsp; <B><span class="code-lang">if</span></B>(event.keyval==65293):</td>
483 </tr><tr><th id="L164"><a href="#L164">164</a></th>
484 <td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.__start_search( widget, entry,liststore)</td>
485 </tr><tr><th id="L165"><a href="#L165">165</a></th>
486 <td></td>
487 </tr><tr><th id="L166"><a href="#L166">166</a></th>
488 <td></td>
489 </tr><tr><th id="L167"><a href="#L167">167</a></th>
490 <td>&nbsp; &nbsp; <B><span class="code-lang">def</span></B> <B><span class="code-func">__start_search</span></B>(self, widget, entry,liststore):</td>
491 </tr><tr><th id="L168"><a href="#L168">168</a></th>
492 <td>&nbsp; &nbsp; &nbsp; &nbsp; liststore.clear()</td>
493 </tr><tr><th id="L169"><a href="#L169">169</a></th>
494 <td>&nbsp; &nbsp; &nbsp; &nbsp; self.progress = 0</td>
495 </tr><tr><th id="L170"><a href="#L170">170</a></th>
496 <td>&nbsp; &nbsp; &nbsp; &nbsp; entry_text = entry.get_text()</td>
497 </tr><tr><th id="L171"><a href="#L171">171</a></th>
498 <td>&nbsp; &nbsp; &nbsp; &nbsp; <B><span class="code-lang">print</span></B> <B><span class="code-string">&quot;Search: %s\n&quot;</span></B> % entry_text</td>
499 </tr><tr><th id="L172"><a href="#L172">172</a></th>
500 <td>&nbsp; &nbsp; &nbsp; &nbsp; </td>
501 </tr><tr><th id="L173"><a href="#L173">173</a></th>
502 <td>&nbsp; &nbsp; &nbsp; &nbsp; iter = liststore.insert(0)</td>
503 </tr><tr><th id="L174"><a href="#L174">174</a></th>
504 <td>&nbsp; &nbsp; &nbsp; &nbsp; liststore.set(iter, 0, {<B><span class="code-string">&quot;bag&quot;</span></B>:None,<B><span class="code-string">&quot;thumb&quot;</span></B>:None,<B><span class="code-string">&quot;thumb_data&quot;</span></B>:None})</td>
505 </tr><tr><th id="L175"><a href="#L175">175</a></th>
506 <td>&nbsp; &nbsp; &nbsp; &nbsp; liststore.set_value(iter, 1,</td>
507 </tr><tr><th id="L176"><a href="#L176">176</a></th>
508 <td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<B><span class="code-string">&quot;&lt;i&gt;&lt;b&gt;Searching progress: 0%&lt;/b&gt;&lt;/i&gt;&quot;</span></B>)</td>
509 </tr><tr><th id="L177"><a href="#L177">177</a></th>
510 <td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</td>
511 </tr><tr><th id="L178"><a href="#L178">178</a></th>
512 <td>&nbsp; &nbsp; &nbsp; &nbsp; <B><span class="code-lang">for</span></B> i <B><span class="code-lang">in</span></B> xrange(len(self.engines)):</td>
513 </tr><tr><th id="L179"><a href="#L179">179</a></th>
514 <td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; thread = threading.Thread(target=self.__search, args=(entry_text,i,iter,))</td>
515 </tr><tr><th id="L180"><a href="#L180">180</a></th>
516 <td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; thread.setDaemon(True)</td>
517 </tr><tr><th id="L181"><a href="#L181">181</a></th>
518 <td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; thread.start()</td>
519 </tr><tr><th id="L182"><a href="#L182">182</a></th>
520 <td></td>
521 </tr><tr><th id="L183"><a href="#L183">183</a></th>
522 <td>&nbsp; &nbsp; <B><span class="code-lang">def</span></B> <B><span class="code-func">__destroy_cb</span></B>(self, widget, *args):</td>
523 </tr><tr><th id="L184"><a href="#L184">184</a></th>
524 <td>&nbsp; &nbsp; &nbsp; &nbsp; widget.destroy()</td>
525 </tr><tr><th id="L185"><a href="#L185">185</a></th>
526 <td>&nbsp; &nbsp; &nbsp; &nbsp; <I><span class="code-comment">#self.destroy()</span></I></td>
527 </tr><tr><th id="L186"><a href="#L186">186</a></th>
528 <td><I><span class="code-comment"></span></I></td>
529 </tr><tr><th id="L187"><a href="#L187">187</a></th>
530 <td>&nbsp; &nbsp; <B><span class="code-lang">def</span></B> <B><span class="code-func">__search</span></B>(self, query, num, iter):</td>
531 </tr><tr><th id="L188"><a href="#L188">188</a></th>
532 <td></td>
533 </tr><tr><th id="L189"><a href="#L189">189</a></th>
534 <td>&nbsp; &nbsp; &nbsp; &nbsp; <B><span class="code-lang">try</span></B>:</td>
535 </tr><tr><th id="L190"><a href="#L190">190</a></th>
536 <td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bags = self.engines[num](query)</td>
537 </tr><tr><th id="L191"><a href="#L191">191</a></th>
538 <td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <B><span class="code-lang">for</span></B> bag <B><span class="code-lang">in</span></B> bags:</td>
539 </tr><tr><th id="L192"><a href="#L192">192</a></th>
540 <td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; gobject.idle_add(self.__add_bag, self.liststore, bag)</td>
541 </tr><tr><th id="L193"><a href="#L193">193</a></th>
542 <td>&nbsp; &nbsp; &nbsp; &nbsp; <B><span class="code-lang">except</span></B>:</td>
543 </tr><tr><th id="L194"><a href="#L194">194</a></th>
544 <td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <B><span class="code-lang">pass</span></B></td>
545 </tr><tr><th id="L195"><