add cover art

git-svn-id: http://www.neo1973-germany.de/svn@233 46df4e5c-bc4e-4628-a0fc-830ba316316d
main
fgau 16 years ago
parent 1298e8817c
commit 8e3042ad4e

@ -1,16 +1,22 @@
#!/usr/bin/env python2.5 #!/usr/bin/env python2.5
# -*- coding: utf-8 -*- # -*- 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 <mdt@pyneo.org>, F. Gau <fgau@gau-net.de>, Thomas Gstaedner (thomas (a) gstaedtner (.) net)"
__version__ = "prototype" __version__ = "prototype"
__copyright__ = "Copyright (c) 2008" __copyright__ = "Copyright (c) 2008"
__license__ = "GPL3" __license__ = "GPL3"
LICENSE_KEY = "18C3VZN9HCECM5G3HQG2" AMAZON_HOST = 'ecs.amazonaws.de'
ASSOCIATE = "webservices-20" AMAZON_PATH = "/onca/xml"
AMAZON_ASSOCIATE = "webservices-20"
AMAZON_LICENSE_KEY = "18C3VZN9HCECM5G3HQG2"
from epydial import * from epydial import *
import urllib from httplib import HTTPConnection
from xml.dom import minidom 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): class AudioScreen(EdjeGroup):
toggle = 0 toggle = 0
@ -21,33 +27,81 @@ class AudioScreen(EdjeGroup):
PyneoController.set_volume(self.volume) PyneoController.set_volume(self.volume)
self.part_text_set("volume_label", "volume %d%%" % (self.volume*100)) 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): def register_pyneo_callbacks(self):
PyneoController.register_callback("on_get_mp3_tags", self.on_get_mp3_tags) PyneoController.register_callback("on_get_mp3_tags", self.on_get_mp3_tags)
def on_get_mp3_tags(self, status): def on_get_mp3_tags(self, status):
self.part_text_set("mp3_tags", "artist: %s<br>album: %s<br>title: %s" % (status['artist'], status['album'], status['title'])) try:
print 'cover url: ', self.get_amazon_cover(status['artist'] + " "+ status['album']) self.image.delete()
except:
def getText(self, nodelist): pass
rc = ""
for node in nodelist:
if node.nodeType == node.TEXT_NODE:
rc = rc + node.data
return rc
def get_amazon_cover(self, album): self.part_text_set("mp3_tags", "artist: %s<br>album: %s<br>title: %s" % (status['artist'], status['album'], status['title']))
AMAZON_URL = "http://ecs.amazonaws.de/onca/xml"\ if not os.path.isfile(COVER_FILE_PATH + '%s_%s.jpeg' % (status['artist'], status['album'])):
"?Service=AWSECommerceService"\ try:
"&AWSAccessKeyId=" + LICENSE_KEY +\ content = self.get_amazon_cover(status['artist'], status['album'])
"&AssociateTag=" + ASSOCIATE +\ with open(COVER_FILE_PATH + '%s_%s.jpeg' % (status['artist'], status['album']), 'w') as f:
"&ResponseGroup=Images,ItemAttributes"\ f.write(content)
"&Operation=ItemSearch"\ except:
"&ItemSearch.Shared.SearchIndex=Music"\ pass # display a dummy cover
"&ItemSearch.1.Keywords=%s"
url = AMAZON_URL % (album) self.image = self.evas.Image(file=COVER_FILE_PATH + '%s_%s.jpeg' % (status['artist'], status['album']))
dom = minidom.parse(urllib.urlopen(url)) x, y = self.image.image_size
return self.getText(dom.getElementsByTagName("URL")[1].childNodes) 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", "*") @edje.decorators.signal_callback("music_player_send", "*")
def on_edje_signal_audio_screen_triggered(self, emission, source): def on_edje_signal_audio_screen_triggered(self, emission, source):
@ -68,7 +122,6 @@ class AudioScreen(EdjeGroup):
self.signal_emit("key2", "") self.signal_emit("key2", "")
self.toggle = 0 self.toggle = 0
PyneoController.stop_music() PyneoController.stop_music()
PyneoController.get_mp3_tags()
if source == "track_right": if source == "track_right":
PyneoController.next_music() PyneoController.next_music()
if source == "track_left": if source == "track_left":

@ -269,7 +269,26 @@ collections {
fit: 1 1; 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("track_left", 0, 2)
key("stop", 1, 2) key("stop", 1, 2)
key_play_pause("play_pause", "play", "pause", 2, 2) key_play_pause("play_pause", "play", "pause", 2, 2)

@ -23,6 +23,7 @@ DB_FILE_PATH = "/media/card/epydialdb/epydial.sqlite"
DB_PATH = "/media/card/epydialdb/" DB_PATH = "/media/card/epydialdb/"
PIX_WEATHER_FILE_PATH = "data/themes_data/blackwhite/images/stardock_weather/" PIX_WEATHER_FILE_PATH = "data/themes_data/blackwhite/images/stardock_weather/"
MP3_FILE_PATH = "/media/card/mp3/" MP3_FILE_PATH = "/media/card/mp3/"
COVER_FILE_PATH = "/media/card/epydial/cover/"
RINGTONE_FILE = "/usr/share/epydial/data/sounds/ringtone_simple02.mp3" RINGTONE_FILE = "/usr/share/epydial/data/sounds/ringtone_simple02.mp3"
DIALER_SCREEN_NAME = "pyneo/dialer/main" DIALER_SCREEN_NAME = "pyneo/dialer/main"
@ -484,7 +485,6 @@ class PyneoController(object):
except: except:
print '--- NULL new sms' print '--- NULL new sms'
class_.gsm_sms.DeleteAll(dbus_interface=DIN_STORAGE) class_.gsm_sms.DeleteAll(dbus_interface=DIN_STORAGE)
PyneoController.stop_ringtone() #TODO: not the optimal break for the startup sound ;)
@classmethod @classmethod
def show_sms_screen(class_): def show_sms_screen(class_):

Loading…
Cancel
Save