diff --git a/data/css/style.css b/data/css/style.css index 75925e84..3ae8ea48 100644 --- a/data/css/style.css +++ b/data/css/style.css @@ -163,8 +163,31 @@ div.progress-container { float: left; background: white; } +a.center { + color: blue; + text-align: center; + } div.progress-container > div { background-color: #ACE97C; height: 12px -} \ No newline at end of file +} +.cloud{ + padding: 0px; + font-size:16px; + } +#cloud a.tag1 { font-size: 0.7em; font-weight: 100; } +#cloud a.tag2 { font-size: 0.8em; font-weight: 200; } +#cloud a.tag3 { font-size: 0.9em; font-weight: 300; } +#cloud a.tag4 { font-size: 1.0em; font-weight: 400; } +#cloud a.tag5 { font-size: 1.2em; font-weight: 500; } +#cloud a.tag6 { font-size: 1.4em; font-weight: 600; } +#cloud a.tag7 { font-size: 1.6em; font-weight: 700; } +#cloud a.tag8 { font-size: 1.8em; font-weight: 800; } +#cloud a.tag9 { font-size: 2.2em; font-weight: 900; } +#cloud a.tag10 { font-size: 2.5em; font-weight: 900; } + +#cloud { padding: 2px; line-height: 1.5em; text-align: center; } +#cloud a { padding: 0px; } +#cloud { margin: 0; } +#cloud li { display: inline; } \ No newline at end of file diff --git a/headphones/__init__.py b/headphones/__init__.py index c931b444..d680a761 100644 --- a/headphones/__init__.py +++ b/headphones/__init__.py @@ -403,6 +403,7 @@ def dbcheck(): c.execute('CREATE TABLE IF NOT EXISTS tracks (ArtistID TEXT, ArtistName TEXT, AlbumTitle TEXT, AlbumASIN TEXT, AlbumID TEXT, TrackTitle TEXT, TrackDuration, TrackID TEXT, TrackNumber INTEGER)') c.execute('CREATE TABLE IF NOT EXISTS snatched (AlbumID TEXT, Title TEXT, Size INTEGER, URL TEXT, DateAdded TEXT, Status TEXT, FolderName TEXT)') c.execute('CREATE TABLE IF NOT EXISTS have (ArtistName TEXT, AlbumTitle TEXT, TrackNumber TEXT, TrackTitle TEXT, TrackLength TEXT, BitRate TEXT, Genre TEXT, Date TEXT, TrackID TEXT)') + c.execute('CREATE TABLE IF NOT EXISTS lastfmcloud (ArtistName TEXT, ArtistID TEXT, Count INTEGER)') try: c.execute('SELECT IncludeExtras from artists') diff --git a/headphones/importer.py b/headphones/importer.py index cf7456c7..232d4b66 100644 --- a/headphones/importer.py +++ b/headphones/importer.py @@ -4,7 +4,7 @@ import os from lib.beets.mediafile import MediaFile import headphones -from headphones import logger, helpers, db, mb, albumart +from headphones import logger, helpers, db, mb, albumart, lastfm various_artists_mbid = '89ad4ac3-39f7-470e-963a-56509c546377' @@ -130,6 +130,14 @@ def artistlist_to_mbids(artistlist): controlValueDict = {"ArtistID": artistid} newValueDict = {"HaveTracks": havetracks} myDB.upsert("artists", newValueDict, controlValueDict) + + # Update the cloud: + logger.info('Updating the cloud') + try: + lastfm.findSimilar() + except Exception, e: + logger.warn('Updating the cloud failed: %s' % e) + def addArtisttoDB(artistid, extrasonly=False): diff --git a/headphones/lastfm.py b/headphones/lastfm.py new file mode 100644 index 00000000..3a03bcec --- /dev/null +++ b/headphones/lastfm.py @@ -0,0 +1,53 @@ +import urllib +from xml.dom import minidom +from collections import defaultdict +import random + +from headphones import db + +api_key = '395e6ec6bb557382fc41fde867bce66f' + + +def getSimilar(): + + myDB = db.DBConnection() + results = myDB.select('SELECT ArtistID from artists ORDER BY HaveTracks DESC') + + artistlist = [] + + for result in results[:12]: + + url = 'http://ws.audioscrobbler.com/2.0/?method=artist.getsimilar&mbid=%s&api_key=%s' % (result['ArtistID'], api_key) + data = urllib.urlopen(url).read() + d = minidom.parseString(data) + node = d.documentElement + artists = d.getElementsByTagName("artist") + + for artist in artists: + namenode = artist.getElementsByTagName("name")[0].childNodes + mbidnode = artist.getElementsByTagName("mbid")[0].childNodes + + for node in namenode: + artist_name = node.data + for node in mbidnode: + artist_mbid = node.data + + if not any(artist_mbid in x for x in results): + artistlist.append((artist_name, artist_mbid)) + + count = defaultdict(int) + + for artist, mbid in artistlist: + count[artist, mbid] += 1 + + items = count.items() + + top_list = sorted(items, key=lambda x: x[1], reverse=True)[:25] + + random.shuffle(top_list) + + myDB.action('''DELETE from lastfmcloud''') + for tuple in top_list: + artist_name, artist_mbid = tuple[0] + count = tuple[1] + myDB.action('INSERT INTO lastfmcloud VALUES( ?, ?, ?)', [artist_name, artist_mbid, count]) \ No newline at end of file diff --git a/headphones/templates.py b/headphones/templates.py index df64e4ab..83dfbd82 100644 --- a/headphones/templates.py +++ b/headphones/templates.py @@ -34,6 +34,7 @@ _logobar = ''' _nav = '''