add cover art
git-svn-id: http://www.neo1973-germany.de/svn@233 46df4e5c-bc4e-4628-a0fc-830ba316316d
This commit is contained in:
parent
1298e8817c
commit
8e3042ad4e
3 changed files with 101 additions and 29 deletions
|
@ -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):
|
||||||
|
try:
|
||||||
|
self.image.delete()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
self.part_text_set("mp3_tags", "artist: %s<br>album: %s<br>title: %s" % (status['artist'], status['album'], status['title']))
|
self.part_text_set("mp3_tags", "artist: %s<br>album: %s<br>title: %s" % (status['artist'], status['album'], status['title']))
|
||||||
print 'cover url: ', self.get_amazon_cover(status['artist'] + " "+ status['album'])
|
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
|
||||||
|
|
||||||
def getText(self, nodelist):
|
self.image = self.evas.Image(file=COVER_FILE_PATH + '%s_%s.jpeg' % (status['artist'], status['album']))
|
||||||
rc = ""
|
x, y = self.image.image_size
|
||||||
for node in nodelist:
|
dx, dy = self.part_size_get('icon')
|
||||||
if node.nodeType == node.TEXT_NODE:
|
if x * dy > y * dx:
|
||||||
rc = rc + node.data
|
y = y * dx / x
|
||||||
return rc
|
x = dx
|
||||||
|
else:
|
||||||
def get_amazon_cover(self, album):
|
x = x * dy / y
|
||||||
AMAZON_URL = "http://ecs.amazonaws.de/onca/xml"\
|
y = dy
|
||||||
"?Service=AWSECommerceService"\
|
print 'x, y, dx, dy: ', x, y, dx, dy
|
||||||
"&AWSAccessKeyId=" + LICENSE_KEY +\
|
self.image.fill = 0, 0, x, y
|
||||||
"&AssociateTag=" + ASSOCIATE +\
|
self.part_swallow('icon', self.image)
|
||||||
"&ResponseGroup=Images,ItemAttributes"\
|
self.obj = self.part_object_get('clipper')
|
||||||
"&Operation=ItemSearch"\
|
self.obj.size = x, y
|
||||||
"&ItemSearch.Shared.SearchIndex=Music"\
|
self.obj.show()
|
||||||
"&ItemSearch.1.Keywords=%s"
|
|
||||||
|
|
||||||
url = AMAZON_URL % (album)
|
|
||||||
dom = minidom.parse(urllib.urlopen(url))
|
|
||||||
return self.getText(dom.getElementsByTagName("URL")[1].childNodes)
|
|
||||||
|
|
||||||
@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":
|
||||||
|
|
|
@ -270,6 +270,25 @@ collections {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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…
Reference in a new issue