From 8e3042ad4e3e40182583fd83e9c877a77b0c15a6 Mon Sep 17 00:00:00 2001 From: fgau Date: Tue, 20 Jan 2009 13:35:57 +0000 Subject: [PATCH] add cover art git-svn-id: http://www.neo1973-germany.de/svn@233 46df4e5c-bc4e-4628-a0fc-830ba316316d --- epydial/audio_screen.py | 107 +++++++++++++----- .../data/themes/blackwhite/audio_screen.edc | 21 +++- epydial/epydial.py | 2 +- 3 files changed, 101 insertions(+), 29 deletions(-) diff --git a/epydial/audio_screen.py b/epydial/audio_screen.py index 4630441..5ac8c25 100644 --- a/epydial/audio_screen.py +++ b/epydial/audio_screen.py @@ -1,16 +1,22 @@ #!/usr/bin/env python2.5 # -*- coding: utf-8 -*- -__author__ = "Soeren Apel (abraxa@dar-clan.de), Frank Gau (fgau@gau-net.de), Thomas Gstaedner (thomas (a) gstaedtner (.) net)" +from __future__ import with_statement +__author__ = "M. Dietrich , F. Gau , Thomas Gstaedner (thomas (a) gstaedtner (.) net)" __version__ = "prototype" __copyright__ = "Copyright (c) 2008" __license__ = "GPL3" -LICENSE_KEY = "18C3VZN9HCECM5G3HQG2" -ASSOCIATE = "webservices-20" +AMAZON_HOST = 'ecs.amazonaws.de' +AMAZON_PATH = "/onca/xml" +AMAZON_ASSOCIATE = "webservices-20" +AMAZON_LICENSE_KEY = "18C3VZN9HCECM5G3HQG2" from epydial import * -import urllib -from xml.dom import minidom +from httplib import HTTPConnection +from urllib import urlencode +from urlparse import urlparse, urlunparse +from xml.dom.minidom import parseString +from pyneo.dns_support import DNSCache #require: export PYTHONPATH=/usr/share/pyneod class AudioScreen(EdjeGroup): toggle = 0 @@ -21,33 +27,81 @@ class AudioScreen(EdjeGroup): PyneoController.set_volume(self.volume) self.part_text_set("volume_label", "volume %d%%" % (self.volume*100)) + def get_text(self, nodelist): + return "".join([node.data for node in nodelist if node.nodeType == node.TEXT_NODE]) + + def get_content(self, scheme, netloc, path, parameters, query, fragment=None, ): + http_connection = HTTPConnection(netloc, getaddrinfo=DNSCache.getaddrinfo, timeout=12, ) + try: + http_connection.request("GET", '%s?%s'% (path, query, ), headers={ + 'User-Agent': 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)', + 'Connection': 'close', + }) + response = http_connection.getresponse() + if response.status != 200: + raise Exception(response.reason) + data = response.read() + finally: + http_connection.close() + return data + + def get_amazon_cover(self, artist, keywords): + content = self.get_content( + 'http', + AMAZON_HOST, + AMAZON_PATH, + None, + urlencode(( + ("Service", "AWSECommerceService", ), + ("AWSAccessKeyId", AMAZON_LICENSE_KEY, ), + ("AssociateTag", AMAZON_ASSOCIATE, ), + ("ResponseGroup", "Small, Images", ), + ("Operation", "ItemSearch", ), + ("SearchIndex", "Music", ), + ("ContentType", "text/xml", ), +# ("Album", album, ), + ("Artist", artist, ), + ("Keywords", keywords, ), #other search options are welcome +# ("Title", title,), + ))) + dom = parseString(content) + url = self.get_text(dom.getElementsByTagName("URL")[1].childNodes) + data = self.get_content(*urlparse(url)) + return data + def register_pyneo_callbacks(self): PyneoController.register_callback("on_get_mp3_tags", self.on_get_mp3_tags) def on_get_mp3_tags(self, status): - self.part_text_set("mp3_tags", "artist: %s
album: %s
title: %s" % (status['artist'], status['album'], status['title'])) - print 'cover url: ', self.get_amazon_cover(status['artist'] + " "+ status['album']) - - def getText(self, nodelist): - rc = "" - for node in nodelist: - if node.nodeType == node.TEXT_NODE: - rc = rc + node.data - return rc + try: + self.image.delete() + except: + pass - def get_amazon_cover(self, album): - AMAZON_URL = "http://ecs.amazonaws.de/onca/xml"\ - "?Service=AWSECommerceService"\ - "&AWSAccessKeyId=" + LICENSE_KEY +\ - "&AssociateTag=" + ASSOCIATE +\ - "&ResponseGroup=Images,ItemAttributes"\ - "&Operation=ItemSearch"\ - "&ItemSearch.Shared.SearchIndex=Music"\ - "&ItemSearch.1.Keywords=%s" + self.part_text_set("mp3_tags", "artist: %s
album: %s
title: %s" % (status['artist'], status['album'], status['title'])) + if not os.path.isfile(COVER_FILE_PATH + '%s_%s.jpeg' % (status['artist'], status['album'])): + try: + content = self.get_amazon_cover(status['artist'], status['album']) + with open(COVER_FILE_PATH + '%s_%s.jpeg' % (status['artist'], status['album']), 'w') as f: + f.write(content) + except: + pass # display a dummy cover - url = AMAZON_URL % (album) - dom = minidom.parse(urllib.urlopen(url)) - return self.getText(dom.getElementsByTagName("URL")[1].childNodes) + self.image = self.evas.Image(file=COVER_FILE_PATH + '%s_%s.jpeg' % (status['artist'], status['album'])) + x, y = self.image.image_size + dx, dy = self.part_size_get('icon') + if x * dy > y * dx: + y = y * dx / x + x = dx + else: + x = x * dy / y + y = dy + print 'x, y, dx, dy: ', x, y, dx, dy + self.image.fill = 0, 0, x, y + self.part_swallow('icon', self.image) + self.obj = self.part_object_get('clipper') + self.obj.size = x, y + self.obj.show() @edje.decorators.signal_callback("music_player_send", "*") def on_edje_signal_audio_screen_triggered(self, emission, source): @@ -68,7 +122,6 @@ class AudioScreen(EdjeGroup): self.signal_emit("key2", "") self.toggle = 0 PyneoController.stop_music() - PyneoController.get_mp3_tags() if source == "track_right": PyneoController.next_music() if source == "track_left": diff --git a/epydial/data/themes/blackwhite/audio_screen.edc b/epydial/data/themes/blackwhite/audio_screen.edc index b6c0f24..369f1ad 100755 --- a/epydial/data/themes/blackwhite/audio_screen.edc +++ b/epydial/data/themes/blackwhite/audio_screen.edc @@ -269,7 +269,26 @@ collections { fit: 1 1; } } - } + } + part { + name: "clipper"; + type: RECT; + description { + rel1 { relative: 1/2 1/2; offset: -80 -80; } + rel2 { relative: 1/2 1/2; offset: 80 80; } + } + } + part { + name: "icon"; + type: SWALLOW; + mouse_events: 0; + clip_to: "clipper"; + description { + /*fixed: 1 1;*/ + rel1 { relative: 1/2 1/2; offset: -80 -80; } + rel2 { relative: 1/2 1/2; offset: 80 80; } + } + } /*end icon swallow */ key("track_left", 0, 2) key("stop", 1, 2) key_play_pause("play_pause", "play", "pause", 2, 2) diff --git a/epydial/epydial.py b/epydial/epydial.py index 296aad1..80c9ca6 100755 --- a/epydial/epydial.py +++ b/epydial/epydial.py @@ -23,6 +23,7 @@ DB_FILE_PATH = "/media/card/epydialdb/epydial.sqlite" DB_PATH = "/media/card/epydialdb/" PIX_WEATHER_FILE_PATH = "data/themes_data/blackwhite/images/stardock_weather/" MP3_FILE_PATH = "/media/card/mp3/" +COVER_FILE_PATH = "/media/card/epydial/cover/" RINGTONE_FILE = "/usr/share/epydial/data/sounds/ringtone_simple02.mp3" DIALER_SCREEN_NAME = "pyneo/dialer/main" @@ -484,7 +485,6 @@ class PyneoController(object): except: print '--- NULL new sms' class_.gsm_sms.DeleteAll(dbus_interface=DIN_STORAGE) - PyneoController.stop_ringtone() #TODO: not the optimal break for the startup sound ;) @classmethod def show_sms_screen(class_):