Lots of bug fixes to actually get the thing working :-)

This commit is contained in:
rembo10
2012-08-14 22:56:31 +05:30
parent 144076c03d
commit b9ebde486e
6 changed files with 36 additions and 20 deletions

View File

@@ -33,7 +33,7 @@
else:
alternate_album_name = alternate_album['AlbumTitle'] + " (" + alternate_album['ReleaseCountry'] + ", " + alternate_album['ReleaseFormat'] + ")"
%>
<a href="switchAlbum?AlbumID=${album['AlbumID']}&ReleaseID=${alternate_albums['ReleaseID']}">${alternate_album_name}</a><br>
<a href="switchAlbum?AlbumID=${album['AlbumID']}&ReleaseID=${alternate_album['ReleaseID']}">${alternate_album_name}</a><br>
%endfor
%endif
</div>

View File

@@ -868,6 +868,11 @@ def dbcheck():
c.execute('SELECT ReleaseID from tracks')
except sqlite3.OperationalError:
c.execute('ALTER TABLE tracks ADD COLUMN ReleaseID TEXT DEFAULT NULL')
try:
c.execute('SELECT Matched from have')
except sqlite3.OperationalError:
c.execute('ALTER TABLE have ADD COLUMN Matched TEXT DEFAULT NULL')
conn.commit()
c.close()

View File

@@ -22,10 +22,10 @@ def switch(AlbumID, ReleaseID):
the albums & tracks table.
'''
myDB = db.DBConnection()
oldalbumdata = myDB.select('SELECT * from albums WHERE AlbumID=?', [AlbumID])
newalbumdata = myDB.select('SELECT * from allalbums WHERE ReleaseID=?', [ReleaseID])
newtrackdata = myDB.select('SELECT * from alltracks WHERE ReleaseID=?', [ReleaseID])
myDB.action('DELETE * from tracks WHERE AlbumID=?', [AlbumID])
oldalbumdata = myDB.action('SELECT * from albums WHERE AlbumID=?', [AlbumID]).fetchone()
newalbumdata = myDB.action('SELECT * from allalbums WHERE ReleaseID=?', [ReleaseID]).fetchone()
newtrackdata = myDB.action('SELECT * from alltracks WHERE ReleaseID=?', [ReleaseID]).fetchall()
myDB.action('DELETE from tracks WHERE AlbumID=?', [AlbumID])
controlValueDict = {"AlbumID": AlbumID}
@@ -45,7 +45,7 @@ def switch(AlbumID, ReleaseID):
for track in newtrackdata:
controlValueDict = {"TrackID": track['TrackID'],
"AlbumID": AlbumID
"AlbumID": AlbumID}
newValueDict = {"ArtistID": track['ArtistID'],
"ArtistName": track['ArtistName'],
@@ -64,14 +64,15 @@ def switch(AlbumID, ReleaseID):
myDB.upsert("tracks", newValueDict, controlValueDict)
# Mark albums as downloaded if they have at least 80% (by default, configurable) of the album
total_track_count = len(newtrackdata)
have_track_count = len(myDB.select('SELECT * from tracks WHERE AlbumID=? AND Location IS NOT NULL', [AlbumID]))
if oldalbumdata['Status'] == 'Skipped' and ((have_track_count/float(total_track_count)) >= (headphones.ALBUM_COMPLETION_PCT/100.0)):
myDB.action('UPDATE albums SET Status=? WHERE AlbumID=?', ['Downloaded', rg['id']])
myDB.action('UPDATE albums SET Status=? WHERE AlbumID=?', ['Downloaded', AlbumID])
# Update have track counts on index
totaltracks = len(myDB.select('SELECT TrackTitle from tracks WHERE ArtistID=?', [artistid]))
havetracks = len(myDB.select('SELECT TrackTitle from tracks WHERE ArtistID=? AND Location IS NOT NULL', [artistid])) + len(myDB.select('SELECT TrackTitle from have WHERE ArtistName like ?', [artist['artist_name']]))
totaltracks = len(myDB.select('SELECT TrackTitle from tracks WHERE ArtistID=?', [newalbumdata['ArtistID']]))
havetracks = len(myDB.select('SELECT TrackTitle from tracks WHERE ArtistID=? AND Location IS NOT NULL', [newalbumdata['ArtistID']])) + len(myDB.select('SELECT TrackTitle from have WHERE ArtistName like ?', [newalbumdata['ArtistID']]))
controlValueDict = {"ArtistID": newalbumdata['ArtistID']}

View File

@@ -153,6 +153,8 @@ def addArtisttoDB(artistid, extrasonly=False):
for rg in artist['releasegroups']:
logger.info("Now adding/updating: " + rg['title'])
rgid = rg['id']
# check if the album already exists
@@ -177,7 +179,7 @@ def addArtisttoDB(artistid, extrasonly=False):
try:
releasedict = mb.getRelease(releaseid, include_artist_info=False)
except Exception, e:
logger.info('Unable to get release information for %s' % release['id'])
logger.info('Unable to get release information for %s: %s' % (release['id'], e))
continue
if not releasedict:
@@ -287,7 +289,7 @@ def addArtisttoDB(artistid, extrasonly=False):
myDB.upsert("alltracks", newValueDict, controlValueDict)
# Delete matched tracks from the have table
myDB.action('DELETE * from have WHERE Matched="True"')
myDB.action('DELETE from have WHERE Matched="True"')
# If there's no release in the main albums tables, add the default (hybrid)
# If there is a release, check the ReleaseID against the AlbumID to see if they differ (user updated)
@@ -298,7 +300,7 @@ def addArtisttoDB(artistid, extrasonly=False):
else:
releaseid = rg_exists['ReleaseID']
album = myDB.select('SELECT * from allallbums WHERE ReleaseID=?', releaseid)
album = myDB.action('SELECT * from allalbums WHERE ReleaseID=?', [releaseid]).fetchone()
controlValueDict = {"AlbumID": rg['id']}
@@ -319,15 +321,15 @@ def addArtisttoDB(artistid, extrasonly=False):
if headphones.AUTOWANT_ALL:
newValueDict['Status'] = "Wanted"
elif release_dict['releasedate'] > helpers.today() and headphones.AUTOWANT_UPCOMING:
elif album['ReleaseDate'] > helpers.today() and headphones.AUTOWANT_UPCOMING:
newValueDict['Status'] = "Wanted"
else:
newValueDict['Status'] = "Skipped"
myDB.upsert("albums", newValueDict, controlValueDict)
myDB.action('DELETE * from tracks WHERE AlbumID=?', rg['id'])
tracks = myDB.select('SELECT * from alltracks WHERE ReleaseID=?', [releaseid])
myDB.action('DELETE from tracks WHERE AlbumID=?', [rg['id']])
tracks = myDB.action('SELECT * from alltracks WHERE ReleaseID=?', [releaseid]).fetchall()
# This is used to see how many tracks you have from an album - to mark it as downloaded. Default is 80%, can be set in config as ALBUM_COMPLETION_PCT
total_track_count = len(tracks)
@@ -363,7 +365,7 @@ def addArtisttoDB(artistid, extrasonly=False):
if ((have_track_count/float(total_track_count)) >= (headphones.ALBUM_COMPLETION_PCT/100.0)):
myDB.action('UPDATE albums SET Status=? WHERE AlbumID=?', ['Downloaded', rg['id']])
logger.debug(u"Updating album cache for " + rg['title'])
logger.info(u"Seeing if we need album art for " + rg['title'])
cache.getThumb(AlbumID=rg['id'])
latestalbum = myDB.action('SELECT AlbumTitle, ReleaseDate, AlbumID from albums WHERE ArtistID=? order by ReleaseDate DESC', [artistid]).fetchone()
@@ -388,7 +390,7 @@ def addArtisttoDB(artistid, extrasonly=False):
myDB.upsert("artists", newValueDict, controlValueDict)
logger.debug(u"Updating cache for: " + artist['artist_name'])
logger.info(u"Seeing if we need album art for: " + artist['artist_name'])
cache.getThumb(ArtistID=artistid)
logger.info(u"Updating complete for: " + artist['artist_name'])
@@ -603,7 +605,7 @@ def getHybridRelease(fullreleaselist):
for item in sortable_release_list:
item['trackscount_delta'] = abs(average_tracks - item['trackscount'])
a = multikeysort(sortable_release_list, ['-hasasin', 'country', 'format', 'trackscount_delta'])
a = helpers.multikeysort(sortable_release_list, ['-hasasin', 'country', 'format', 'trackscount_delta'])
release_dict = {'ReleaseDate' : sortable_release_list[0]['releasedate'],
'Tracks' : a[0]['tracks'],

View File

@@ -315,8 +315,15 @@ def getRelease(releaseid, include_artist_info=True):
release['id'] = unicode(results['id'])
release['asin'] = unicode(results['asin']) if 'asin' in results else None
release['date'] = unicode(results['date'])
release['format'] = unicode(results['medium-list'][0]['format'])
release['country'] = unicode(results['country'])
try:
release['format'] = unicode(results['medium-list'][0]['format'])
except:
release['format'] = u'Unknown'
try:
release['country'] = unicode(results['country'])
except:
release['country'] = u'Unknown'
if include_artist_info:

View File

@@ -218,6 +218,7 @@ class WebInterface(object):
'''
from headphones import albumswitcher
albumswitcher.switch(AlbumID, ReleaseID)
raise cherrypy.HTTPRedirect("albumPage?AlbumID=%s" % AlbumID)
switchAlbum.exposed = True
def upcoming(self):