mirror of
https://github.com/rembo10/headphones.git
synced 2026-07-21 08:24:00 +01:00
Lots of bug fixes to actually get the thing working :-)
This commit is contained in:
@@ -33,7 +33,7 @@
|
|||||||
else:
|
else:
|
||||||
alternate_album_name = alternate_album['AlbumTitle'] + " (" + alternate_album['ReleaseCountry'] + ", " + alternate_album['ReleaseFormat'] + ")"
|
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
|
%endfor
|
||||||
%endif
|
%endif
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -868,6 +868,11 @@ def dbcheck():
|
|||||||
c.execute('SELECT ReleaseID from tracks')
|
c.execute('SELECT ReleaseID from tracks')
|
||||||
except sqlite3.OperationalError:
|
except sqlite3.OperationalError:
|
||||||
c.execute('ALTER TABLE tracks ADD COLUMN ReleaseID TEXT DEFAULT NULL')
|
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()
|
conn.commit()
|
||||||
c.close()
|
c.close()
|
||||||
|
|||||||
@@ -22,10 +22,10 @@ def switch(AlbumID, ReleaseID):
|
|||||||
the albums & tracks table.
|
the albums & tracks table.
|
||||||
'''
|
'''
|
||||||
myDB = db.DBConnection()
|
myDB = db.DBConnection()
|
||||||
oldalbumdata = myDB.select('SELECT * from albums WHERE AlbumID=?', [AlbumID])
|
oldalbumdata = myDB.action('SELECT * from albums WHERE AlbumID=?', [AlbumID]).fetchone()
|
||||||
newalbumdata = myDB.select('SELECT * from allalbums WHERE ReleaseID=?', [ReleaseID])
|
newalbumdata = myDB.action('SELECT * from allalbums WHERE ReleaseID=?', [ReleaseID]).fetchone()
|
||||||
newtrackdata = myDB.select('SELECT * from alltracks WHERE ReleaseID=?', [ReleaseID])
|
newtrackdata = myDB.action('SELECT * from alltracks WHERE ReleaseID=?', [ReleaseID]).fetchall()
|
||||||
myDB.action('DELETE * from tracks WHERE AlbumID=?', [AlbumID])
|
myDB.action('DELETE from tracks WHERE AlbumID=?', [AlbumID])
|
||||||
|
|
||||||
controlValueDict = {"AlbumID": AlbumID}
|
controlValueDict = {"AlbumID": AlbumID}
|
||||||
|
|
||||||
@@ -45,7 +45,7 @@ def switch(AlbumID, ReleaseID):
|
|||||||
for track in newtrackdata:
|
for track in newtrackdata:
|
||||||
|
|
||||||
controlValueDict = {"TrackID": track['TrackID'],
|
controlValueDict = {"TrackID": track['TrackID'],
|
||||||
"AlbumID": AlbumID
|
"AlbumID": AlbumID}
|
||||||
|
|
||||||
newValueDict = {"ArtistID": track['ArtistID'],
|
newValueDict = {"ArtistID": track['ArtistID'],
|
||||||
"ArtistName": track['ArtistName'],
|
"ArtistName": track['ArtistName'],
|
||||||
@@ -64,14 +64,15 @@ def switch(AlbumID, ReleaseID):
|
|||||||
myDB.upsert("tracks", newValueDict, controlValueDict)
|
myDB.upsert("tracks", newValueDict, controlValueDict)
|
||||||
|
|
||||||
# Mark albums as downloaded if they have at least 80% (by default, configurable) of the album
|
# 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]))
|
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)):
|
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
|
# Update have track counts on index
|
||||||
totaltracks = len(myDB.select('SELECT TrackTitle from tracks WHERE ArtistID=?', [artistid]))
|
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', [artistid])) + len(myDB.select('SELECT TrackTitle from have WHERE ArtistName like ?', [artist['artist_name']]))
|
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']}
|
controlValueDict = {"ArtistID": newalbumdata['ArtistID']}
|
||||||
|
|
||||||
|
|||||||
+11
-9
@@ -153,6 +153,8 @@ def addArtisttoDB(artistid, extrasonly=False):
|
|||||||
|
|
||||||
for rg in artist['releasegroups']:
|
for rg in artist['releasegroups']:
|
||||||
|
|
||||||
|
logger.info("Now adding/updating: " + rg['title'])
|
||||||
|
|
||||||
rgid = rg['id']
|
rgid = rg['id']
|
||||||
|
|
||||||
# check if the album already exists
|
# check if the album already exists
|
||||||
@@ -177,7 +179,7 @@ def addArtisttoDB(artistid, extrasonly=False):
|
|||||||
try:
|
try:
|
||||||
releasedict = mb.getRelease(releaseid, include_artist_info=False)
|
releasedict = mb.getRelease(releaseid, include_artist_info=False)
|
||||||
except Exception, e:
|
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
|
continue
|
||||||
|
|
||||||
if not releasedict:
|
if not releasedict:
|
||||||
@@ -287,7 +289,7 @@ def addArtisttoDB(artistid, extrasonly=False):
|
|||||||
myDB.upsert("alltracks", newValueDict, controlValueDict)
|
myDB.upsert("alltracks", newValueDict, controlValueDict)
|
||||||
|
|
||||||
# Delete matched tracks from the have table
|
# 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'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)
|
# 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:
|
else:
|
||||||
releaseid = rg_exists['ReleaseID']
|
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']}
|
controlValueDict = {"AlbumID": rg['id']}
|
||||||
|
|
||||||
@@ -319,15 +321,15 @@ def addArtisttoDB(artistid, extrasonly=False):
|
|||||||
|
|
||||||
if headphones.AUTOWANT_ALL:
|
if headphones.AUTOWANT_ALL:
|
||||||
newValueDict['Status'] = "Wanted"
|
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"
|
newValueDict['Status'] = "Wanted"
|
||||||
else:
|
else:
|
||||||
newValueDict['Status'] = "Skipped"
|
newValueDict['Status'] = "Skipped"
|
||||||
|
|
||||||
myDB.upsert("albums", newValueDict, controlValueDict)
|
myDB.upsert("albums", newValueDict, controlValueDict)
|
||||||
|
|
||||||
myDB.action('DELETE * from tracks WHERE AlbumID=?', rg['id'])
|
myDB.action('DELETE from tracks WHERE AlbumID=?', [rg['id']])
|
||||||
tracks = myDB.select('SELECT * from alltracks WHERE ReleaseID=?', [releaseid])
|
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
|
# 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)
|
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)):
|
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']])
|
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'])
|
cache.getThumb(AlbumID=rg['id'])
|
||||||
|
|
||||||
latestalbum = myDB.action('SELECT AlbumTitle, ReleaseDate, AlbumID from albums WHERE ArtistID=? order by ReleaseDate DESC', [artistid]).fetchone()
|
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)
|
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)
|
cache.getThumb(ArtistID=artistid)
|
||||||
|
|
||||||
logger.info(u"Updating complete for: " + artist['artist_name'])
|
logger.info(u"Updating complete for: " + artist['artist_name'])
|
||||||
@@ -603,7 +605,7 @@ def getHybridRelease(fullreleaselist):
|
|||||||
for item in sortable_release_list:
|
for item in sortable_release_list:
|
||||||
item['trackscount_delta'] = abs(average_tracks - item['trackscount'])
|
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'],
|
release_dict = {'ReleaseDate' : sortable_release_list[0]['releasedate'],
|
||||||
'Tracks' : a[0]['tracks'],
|
'Tracks' : a[0]['tracks'],
|
||||||
|
|||||||
+9
-2
@@ -315,8 +315,15 @@ def getRelease(releaseid, include_artist_info=True):
|
|||||||
release['id'] = unicode(results['id'])
|
release['id'] = unicode(results['id'])
|
||||||
release['asin'] = unicode(results['asin']) if 'asin' in results else None
|
release['asin'] = unicode(results['asin']) if 'asin' in results else None
|
||||||
release['date'] = unicode(results['date'])
|
release['date'] = unicode(results['date'])
|
||||||
release['format'] = unicode(results['medium-list'][0]['format'])
|
try:
|
||||||
release['country'] = unicode(results['country'])
|
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:
|
if include_artist_info:
|
||||||
|
|||||||
@@ -218,6 +218,7 @@ class WebInterface(object):
|
|||||||
'''
|
'''
|
||||||
from headphones import albumswitcher
|
from headphones import albumswitcher
|
||||||
albumswitcher.switch(AlbumID, ReleaseID)
|
albumswitcher.switch(AlbumID, ReleaseID)
|
||||||
|
raise cherrypy.HTTPRedirect("albumPage?AlbumID=%s" % AlbumID)
|
||||||
switchAlbum.exposed = True
|
switchAlbum.exposed = True
|
||||||
|
|
||||||
def upcoming(self):
|
def upcoming(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user