From 5eddfbbc30acb0c606559db374b8aa3410c33b05 Mon Sep 17 00:00:00 2001 From: rembo10 Date: Sat, 23 Jun 2012 13:24:26 +0530 Subject: [PATCH] Added ThumbURLs to the artist & album tables in the DB, modfied API_REFERENCE to reflect --- API_REFERENCE | 2 +- headphones/__init__.py | 14 ++++++++++++-- headphones/cache.py | 7 +++++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/API_REFERENCE b/API_REFERENCE index 1798ff23..75e00d95 100644 --- a/API_REFERENCE +++ b/API_REFERENCE @@ -12,7 +12,7 @@ $commands¶meters[&optionalparameters]: getIndex (fetch data from index page. Returns: ArtistName, ArtistSortName, ArtistID, Status, DateAdded, [LatestAlbum, ReleaseDate, AlbumID], HaveTracks, TotalTracks, - IncludeExtras, LastUpdated, ArtworkURL: a remote url to the artwork. To get the cached image path, see getArtistArt command) + IncludeExtras, LastUpdated, [ArtworkURL, ThumbURL]: a remote url to the artwork/thumbnail. To get the cached image path, see getArtistArt command) getArtist&id=$artistid (fetch artist data. returns the artist object (see above) and album info: Status, AlbumASIN, DateAdded, AlbumTitle, ArtistName, ReleaseDate, AlbumID, ArtistID, Type, ArtworkURL: hosted image path. For cached image, see getAlbumArt command) diff --git a/headphones/__init__.py b/headphones/__init__.py index 49548405..ca184949 100644 --- a/headphones/__init__.py +++ b/headphones/__init__.py @@ -672,8 +672,8 @@ def dbcheck(): conn=sqlite3.connect(DB_FILE) c=conn.cursor() - c.execute('CREATE TABLE IF NOT EXISTS artists (ArtistID TEXT UNIQUE, ArtistName TEXT, ArtistSortName TEXT, DateAdded TEXT, Status TEXT, IncludeExtras INTEGER, LatestAlbum TEXT, ReleaseDate TEXT, AlbumID TEXT, HaveTracks INTEGER, TotalTracks INTEGER, LastUpdated TEXT, ArtworkURL TEXT)') - c.execute('CREATE TABLE IF NOT EXISTS albums (ArtistID TEXT, ArtistName TEXT, AlbumTitle TEXT, AlbumASIN TEXT, ReleaseDate TEXT, DateAdded TEXT, AlbumID TEXT UNIQUE, Status TEXT, Type TEXT, ArtworkURL TEXT)') + c.execute('CREATE TABLE IF NOT EXISTS artists (ArtistID TEXT UNIQUE, ArtistName TEXT, ArtistSortName TEXT, DateAdded TEXT, Status TEXT, IncludeExtras INTEGER, LatestAlbum TEXT, ReleaseDate TEXT, AlbumID TEXT, HaveTracks INTEGER, TotalTracks INTEGER, LastUpdated TEXT, ArtworkURL TEXT, ThumbURL TEXT)') + c.execute('CREATE TABLE IF NOT EXISTS albums (ArtistID TEXT, ArtistName TEXT, AlbumTitle TEXT, AlbumASIN TEXT, ReleaseDate TEXT, DateAdded TEXT, AlbumID TEXT UNIQUE, Status TEXT, Type TEXT, ArtworkURL TEXT, ThumbURL TEXT)') 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, Location TEXT, BitRate INTEGER, CleanName TEXT, Format TEXT)') 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, Location TEXT, CleanName TEXT, Format TEXT)') @@ -778,6 +778,16 @@ def dbcheck(): c.execute('SELECT ArtworkURL from albums') except sqlite3.OperationalError: c.execute('ALTER TABLE albums ADD COLUMN ArtworkURL TEXT DEFAULT NULL') + + try: + c.execute('SELECT ThumbURL from artists') + except sqlite3.OperationalError: + c.execute('ALTER TABLE artists ADD COLUMN ThumbURL TEXT DEFAULT NULL') + + try: + c.execute('SELECT ThumbURL from albums') + except sqlite3.OperationalError: + c.execute('ALTER TABLE albums ADD COLUMN ThumbURL TEXT DEFAULT NULL') conn.commit() c.close() diff --git a/headphones/cache.py b/headphones/cache.py index c95882f4..5fd9e64d 100644 --- a/headphones/cache.py +++ b/headphones/cache.py @@ -384,6 +384,13 @@ class Cache(object): # Grab the thumbnail as well if we're getting the full artwork (as long as it's missing/outdated if thumb_url and self.query_type in ['thumb','artwork'] and not (self.thumb_files and self._is_current(self.thumb_files[0])): + myDB = db.DBConnection() + + if self.id_type == 'artist': + myDB.action('UPDATE artists SET ThumbURL=? WHERE ArtistID=?', [thumb_url, self.id]) + else: + myDB.action('UPDATE albums SET ThumbURL=? WHERE AlbumID=?', [thumb_url, self.id]) + try: artwork = urllib2.urlopen(thumb_url).read() except Exception, e: