diff options
author | Nicholas Piper <nicholas@users.sourceforge.net> | 2005-11-27 18:15:03 +0000 |
---|---|---|
committer | Nicholas Piper <nicholas@users.sourceforge.net> | 2005-11-27 18:15:03 +0000 |
commit | eaae392bc42cf1ebed7fbe1bdadb7660b7d77c35 (patch) | |
tree | fbda37478fc6041e37cce307ae24cb4d14af9b1f | |
parent | 5906cccf27a5e63ab45773170f80f3281b855b7e (diff) | |
download | libgpod-eaae392bc42cf1ebed7fbe1bdadb7660b7d77c35.tar.gz libgpod-eaae392bc42cf1ebed7fbe1bdadb7660b7d77c35.tar.xz libgpod-eaae392bc42cf1ebed7fbe1bdadb7660b7d77c35.zip |
Add a toy script to fetch images from Amazon
git-svn-id: https://gtkpod.svn.sf.net/svnroot/gtkpod/libgpod/trunk@1178 f01d2545-417e-4e96-918e-98f8d0dbbcb6
-rwxr-xr-x | bindings/python/examples/coverart_fetch.py | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/bindings/python/examples/coverart_fetch.py b/bindings/python/examples/coverart_fetch.py new file mode 100755 index 0000000..0df6451 --- /dev/null +++ b/bindings/python/examples/coverart_fetch.py @@ -0,0 +1,72 @@ +#!/usr/bin/python + +## Copyright (C) 2005 Nick Piper <nick-gtkpod at nickpiper co uk> +## Part of the gtkpod project. + +## URL: http://www.gtkpod.org/ +## URL: http://gtkpod.sourceforge.net/ + +## The code contained in this file is free software; you can redistribute +## it and/or modify it under the terms of the GNU Lesser General Public +## License as published by the Free Software Foundation; either version +## 2.1 of the License, or (at your option) any later version. + +## This file is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## Lesser General Public License for more details. + +## You should have received a copy of the GNU Lesser General Public +## License along with this code; if not, write to the Free Software +## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +## $Id$ + +import os, os.path +import gpod +import sys +import amazon +import urllib +import Image +import tempfile + +ipod_mount = '/mnt/ipod' +itdb = gpod.itdb_parse(ipod_mount, None) +if not itdb: + print "Failed to read %s" % dbname + sys.exit(2) + +# set your key here... +amazon.setLicense('') + +for track in gpod.sw_get_tracks(itdb): + output = ("/tmp/%s %s.jpg" % (track.artist, track.album)).replace(' ','_') + if not os.path.exists(output): + print "Searching for %s %s" % (track.artist, track.album) + try: + albums = amazon.searchByKeyword("%s %s" % (track.artist, track.album), + type="lite",product_line="music") + except amazon.AmazonError, e: + print e + albums = [] + + if len(albums) == 0: + continue + album = albums[0] + + i = urllib.urlopen(album.ImageUrlLarge) + o = open(output, "wb") + o.write(i.read()) + o.close() + img = Image.open(output) + if not (img.size[0] > 10 or img.size[1] > 10): + os.unlink(output) + else: + print "Fetched image!" + + if os.path.exists(output): + if gpod.itdb_track_set_thumbnail(track,output) != 0: + print "Failed to save image thumbnail" + +gpod.itdb_write(itdb, None) +print "Saved db" |