diff --git a/data/css/style.css b/data/css/style.css index 57735a2e..6ddd34c8 100644 --- a/data/css/style.css +++ b/data/css/style.css @@ -99,9 +99,18 @@ h1{ font-size: 16px; margin-left: 100px; } +.mediumcentered{ + font-size: 18px; + text-align: center; + } +.bluecenter{ + color: #0000FF; + text-align: center; + font-size: 14px; + } .logtext{ font-size: 14px; - padding: 4px + white-space: normal; } .bigtext{ font-size: 22px; diff --git a/headphones/__init__.py b/headphones/__init__.py index f3e47c4a..48481490 100644 --- a/headphones/__init__.py +++ b/headphones/__init__.py @@ -385,12 +385,22 @@ 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)') - 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)') + c.execute('CREATE TABLE IF NOT EXISTS artists (ArtistID TEXT UNIQUE, ArtistName TEXT, ArtistSortName TEXT, DateAdded TEXT, Status TEXT, IncludeExtras INTEGER)') + 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)') c.execute('CREATE TABLE IF NOT EXISTS tracks (ArtistID TEXT, ArtistName TEXT, AlbumTitle TEXT, AlbumASIN TEXT, AlbumID TEXT, TrackTitle TEXT, TrackDuration, TrackID TEXT)') c.execute('CREATE TABLE IF NOT EXISTS snatched (AlbumID TEXT, Title TEXT, Size INTEGER, URL TEXT, DateAdded TEXT, Status TEXT)') - c.execute('CREATE TABLE IF NOT EXISTS extras (ArtistID TEXT, ArtistName TEXT, AlbumTitle TEXT, AlbumASIN TEXT, ReleaseDate TEXT, DateAdded TEXT, AlbumID TEXT UNIQUE, Status 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)') + + try: + c.execute('SELECT IncludeExtras from artists') + except sqlite3.OperationalError: + c.execute('ALTER TABLE artists ADD COLUMN IncludeExtras INTEGER DEFAULT 0') + + try: + c.execute('SELECT Type from albums') + except sqlite3.OperationalError: + c.execute('ALTER TABLE albums ADD COLUMN Type TEXT DEFAULT "Album"') + conn.commit() c.close() diff --git a/headphones/importer.py b/headphones/importer.py index a5f8a584..9ef8eed1 100644 --- a/headphones/importer.py +++ b/headphones/importer.py @@ -121,7 +121,7 @@ def artistlist_to_mbids(artistlist): addArtisttoDB(artistid) -def addArtisttoDB(artistid): +def addArtisttoDB(artistid, extrasonly=False): # Can't add various artists - throws an error from MB if artistid == various_artists_mbid: @@ -130,7 +130,7 @@ def addArtisttoDB(artistid): myDB = db.DBConnection() - artist = mb.getArtist(artistid) + artist = mb.getArtist(artistid, extrasonly) if not artist: return @@ -189,6 +189,7 @@ def addArtisttoDB(artistid): "AlbumASIN": release['asin'], "ReleaseDate": release_dict['releasedate'], "DateAdded": helpers.today(), + "Type": rg['type'] } if release['date'] > helpers.today(): @@ -218,4 +219,5 @@ def addArtisttoDB(artistid): controlValueDict = {"ArtistID": artistid} newValueDict = {"Status": "Active"} - myDB.upsert("artists", newValueDict, controlValueDict) \ No newline at end of file + myDB.upsert("artists", newValueDict, controlValueDict) + logger.info(u"Updating complete for: " + artist['artist_name']) \ No newline at end of file diff --git a/headphones/mb.py b/headphones/mb.py index dca525af..20cf0d9d 100644 --- a/headphones/mb.py +++ b/headphones/mb.py @@ -66,7 +66,7 @@ def findArtist(name, limit=1): return artistlist -def getArtist(artistid): +def getArtist(artistid, extrasonly=False): with mb_lock: @@ -101,14 +101,54 @@ def getArtist(artistid): releasegroups = [] - for rg in artist.getReleaseGroups(): + if not extrasonly: + + for rg in artist.getReleaseGroups(): + + releasegroups.append({ + 'title': rg.title, + 'id': u.extractUuid(rg.id), + 'url': rg.id, + 'type': u.getReleaseTypeName(rg.type) + }) + + # See if we need to grab extras + myDB = db.DBConnection() + + try: + includeExtras = myDB.select('SELECT IncludeExtras from artists WHERE ArtistID=?', [artistid])[0][0] + except IndexError: + includeExtras = False + + if includeExtras: + includes = [m.Release.TYPE_COMPILATION, m.Release.TYPE_REMIX, m.Release.TYPE_SINGLE, m.Release.TYPE_LIVE, m.Release.TYPE_EP] + for include in includes: + inc = ws.ArtistIncludes(releases=(m.Release.TYPE_OFFICIAL, include), releaseGroups=True) + + artist = None + attempt = 0 - releasegroups.append({ - 'title': rg.title, - 'id': u.extractUuid(rg.id), - 'url': rg.id, - 'type': u.getReleaseTypeName(rg.type) - }) + while attempt < 5: + + try: + artist = q.getArtistById(artistid, inc) + break + except WebServiceError, e: + logger.warn('Attempt to retrieve artist information from MusicBrainz failed for artistid: %s. Sleeping 10 seconds' % artistid) + attempt += 1 + time.sleep(5) + + if not artist: + continue + + for rg in artist.getReleaseGroups(): + + releasegroups.append({ + 'title': rg.title, + 'id': u.extractUuid(rg.id), + 'url': rg.id, + 'type': u.getReleaseTypeName(rg.type) + }) artist_dict['releasegroups'] = releasegroups @@ -266,25 +306,4 @@ def findArtistbyAlbum(name): artist_dict['score'] = result.score return artist_dict - -def getExtras(artistid): - - types = [m.Release.TYPE_EP, m.Release.TYPE_SINGLE, m.Release.TYPE_LIVE, m.Release.TYPE_REMIX, - m.Release.TYPE_COMPILATION] - - for type in types: - - inc = ws.ArtistIncludes(releases=(m.Release.TYPE_OFFICIAL, type), releaseGroups=True) - artist = q.getArtistById(artistid, inc) - - for rg in artist.getReleaseGroups(): - - rgid = u.extractUuid(rg.id) - releaseid = getReleaseGroup(rgid) - - inc = ws.ReleaseIncludes(artist=True, releaseEvents= True, tracks= True, releaseGroup=True) - results = ws.Query().getReleaseById(releaseid, inc) - - print results.title - print u.getReleaseTypeName(results.releaseGroup.type) \ No newline at end of file diff --git a/headphones/templates.py b/headphones/templates.py index 993219b3..20eef8f5 100644 --- a/headphones/templates.py +++ b/headphones/templates.py @@ -1,3 +1,5 @@ +from headphones import db + _header = ''' @@ -16,13 +18,13 @@ _shutdownheader = ''' - +
''' _logobar = ''' - + -
''' \ No newline at end of file + ''' + + +def displayAlbums(ArtistID, Type=None): + + myDB = db.DBConnection() + + results = myDB.select('SELECT AlbumTitle, ReleaseDate, AlbumID, Status, ArtistName, AlbumASIN from albums WHERE ArtistID=? AND Type=? order by ReleaseDate DESC', [ArtistID, Type]) + + if not len(results): + return + + typeheadings = {'Album' : 'Official Albums', + 'Compilation': 'Compilations', + 'EP': 'EPs', + 'Live': 'Live Albums', + 'Remix': 'Remixes', + 'Single': 'Singles'} + + page = ['''

%s

+ + + + + + + + ''' % typeheadings[Type]] + i = 0 + while i < len(results): + totaltracks = len(myDB.select('SELECT TrackTitle from tracks WHERE AlbumID=?', [results[i][2]])) + havetracks = len(myDB.select('SELECT TrackTitle from have WHERE ArtistName like ? AND AlbumTitle like ?', [results[i][4], results[i][0]])) + try: + percent = (havetracks*100)/totaltracks + if percent > 100: + percent = 100 + except ZeroDivisionError: + percent = 100 + if results[i][3] == 'Skipped': + newStatus = '''%s [want]''' % (results[i][3], results[i][2], ArtistID) + elif results[i][3] == 'Wanted': + newStatus = '''%s[skip]''' % (results[i][3], results[i][2], ArtistID) + elif results[i][3] == 'Downloaded': + newStatus = '''%s[retry]''' % (results[i][3], results[i][2], ArtistID) + elif results[i][3] == 'Snatched': + newStatus = '''%s[retry][new]''' % (results[i][3], results[i][2], ArtistID, results[i][2], ArtistID) + else: + newStatus = '%s' % (results[i][3]) + page.append(''' + + + + + + ''' % (results[i][5], results[i][2], results[i][0], results[i][2], results[i][1], newStatus, percent, havetracks, totaltracks)) + i = i+1 + page.append('
Album NameRelease DateStatusHave
%s + (link)%s%s
%s/%s

') + + return ''.join(page) \ No newline at end of file diff --git a/headphones/webserve.py b/headphones/webserve.py index f8550055..cf083568 100644 --- a/headphones/webserve.py +++ b/headphones/webserve.py @@ -97,47 +97,25 @@ class WebInterface(object): page.append(templates._nav) myDB = db.DBConnection() - artist = myDB.select('SELECT ArtistName from artists WHERE ArtistID=?', [ArtistID]) - results = myDB.select('SELECT AlbumTitle, ReleaseDate, AlbumID, Status, ArtistName, AlbumASIN from albums WHERE ArtistID=? order by ReleaseDate DESC', [ArtistID]) + artist = myDB.select('SELECT ArtistName, IncludeExtras from artists WHERE ArtistID=?', [ArtistID]) - i = 0 - page.append('''
-

%s

- - - - - - - ''' % artist[0][0]) - while i < len(results): - totaltracks = len(myDB.select('SELECT TrackTitle from tracks WHERE AlbumID=?', [results[i][2]])) - havetracks = len(myDB.select('SELECT TrackTitle from have WHERE ArtistName like ? AND AlbumTitle like ?', [results[i][4], results[i][0]])) - try: - percent = (havetracks*100)/totaltracks - if percent > 100: - percent = 100 - except ZeroDivisionError: - percent = 100 - if results[i][3] == 'Skipped': - newStatus = '''%s [want]''' % (results[i][3], results[i][2], ArtistID) - elif results[i][3] == 'Wanted': - newStatus = '''%s[skip]''' % (results[i][3], results[i][2], ArtistID) - elif results[i][3] == 'Downloaded': - newStatus = '''%s[retry]''' % (results[i][3], results[i][2], ArtistID) - elif results[i][3] == 'Snatched': - newStatus = '''%s[retry][new]''' % (results[i][3], results[i][2], ArtistID, results[i][2], ArtistID) - else: - newStatus = '%s' % (results[i][3]) - page.append(''' - - - - ''' % (results[i][5], results[i][2], results[i][0], results[i][2], results[i][1], newStatus, percent, havetracks, totaltracks)) - i = i+1 + page.append('''
Album NameRelease DateStatusHave
%s - (link)%s%s
%s/%s

%s

+ ''' % artist[0][0]) + + page.append(templates.displayAlbums(ArtistID, 'Album')) + + releasetypes = ['Compilation', 'EP', 'Single', 'Live', 'Remix'] + + for type in releasetypes: + if templates.displayAlbums(ArtistID, type): + page.append(templates.displayAlbums(ArtistID, type)) + + page.append('
') + + if not artist[0][1]: + page.append('''
Get Extras for %s!
''' + % (ArtistID, artist[0][0])) - page.append('''
''') page.append(templates._footer % headphones.CURRENT_VERSION) return page artistPage.exposed = True @@ -247,6 +225,19 @@ class WebInterface(object): addArtist.exposed = True + def getExtras(self, ArtistID): + + myDB = db.DBConnection() + controlValueDict = {'ArtistID': ArtistID} + newValueDict = {'IncludeExtras': 1} + myDB.upsert("artists", newValueDict, controlValueDict) + + threading.Thread(target=importer.addArtisttoDB, args=[ArtistID, True]).start() + time.sleep(10) + raise cherrypy.HTTPRedirect("artistPage?ArtistID=%s" % ArtistID) + + getExtras.exposed = True + def pauseArtist(self, ArtistID): logger.info(u"Pausing artist: " + ArtistID)