Added ability to do a "comprehensive" MusicBrainz update to emulate the original update process.

Fixed a bug when adding albums introduced in last commit.
This commit is contained in:
theguardian
2013-10-02 15:03:25 -07:00
parent af97f16c25
commit 7a19d08ab2
5 changed files with 52 additions and 35 deletions

View File

@@ -119,7 +119,8 @@
<legend>Force Search</legend>
<div class="links">
<a href="#" onclick="doAjaxCall('forceSearch',$(this))" data-success="Checking for wanted albums successful" data-error="Error checking wanted albums"><span class="ui-icon ui-icon-search"></span>Force Check for Wanted Albums</a>
<a href="#" onclick="doAjaxCall('forceUpdate',$(this))" data-success="Update active artists successful" data-error="Error forcing update artists"><span class="ui-icon ui-icon-heart"></span>Force Update Active Artists</a>
<a href="#" onclick="doAjaxCall('forceUpdate',$(this))" data-success="Update active artists successful" data-error="Error forcing update artists"><span class="ui-icon ui-icon-heart"></span>Force Update Active Artists [Fast]</a>
<a href="#" onclick="doAjaxCall('forceFullUpdate',$(this))" data-success="Update active artists successful" data-error="Error forcing update artists"><span class="ui-icon ui-icon-heart"></span>Force Update Active Artists [Comprehensive]</a>
<a href="#" onclick="doAjaxCall('forcePostProcess',$(this))" data-success="Post-Processor is being loaded" data-error="Error during Post-Processing"><span class="ui-icon ui-icon-wrench"></span>Force Post-Process Albums in Download Folder</a>
<a href="#" onclick="doAjaxCall('checkGithub',$(this))" data-success="Checking for update successful" data-error="Error checking for update"><span class="ui-icon ui-icon-refresh"></span>Check for Headphones Updates</a>
<a href="#" id="delete_empty_artists"><span class="ui-icon ui-icon-trash"></span>Delete empty Artists</a>

View File

@@ -109,7 +109,7 @@ def addArtistIDListToDB(artistidlist):
for artistid in artistidlist:
addArtisttoDB(artistid)
def addArtisttoDB(artistid, extrasonly=False):
def addArtisttoDB(artistid, extrasonly=False, forcefull=False):
# Putting this here to get around the circular import. We're using this to update thumbnails for artist/albums
from headphones import cache
@@ -224,31 +224,35 @@ def addArtisttoDB(artistid, extrasonly=False):
#Make a user configurable variable to skip update of albums with release dates older than this date (in days)
pause_delta = headphones.MB_IGNORE_AGE
check_release_date = myDB.action("SELECT ReleaseDate from albums WHERE ArtistID=? AND AlbumTitle=?", (artistid, al_title)).fetchone()
if check_release_date:
if check_release_date[0] is None:
logger.info("Now updating: " + rg['title'])
new_releases = mb.get_new_releases(rgid,includeExtras)
elif len(check_release_date[0])!=10:
logger.info("Now updating: " + rg['title'])
new_releases = mb.get_new_releases(rgid,includeExtras)
else:
if helpers.get_age(today) - helpers.get_age(check_release_date[0]) < pause_delta:
if not forcefull:
check_release_date = myDB.action("SELECT ReleaseDate from albums WHERE ArtistID=? AND AlbumTitle=?", (artistid, al_title)).fetchone()
if check_release_date:
if check_release_date[0] is None:
logger.info("Now updating: " + rg['title'])
new_releases = mb.get_new_releases(rgid,includeExtras)
new_releases = mb.get_new_releases(rgid,includeExtras)
elif len(check_release_date[0])!=10:
logger.info("Now updating: " + rg['title'])
new_releases = mb.get_new_releases(rgid,includeExtras)
else:
logger.info('%s is over %s days old; not updating' % (al_title, pause_delta))
skip_log = 1
new_releases = 0
if helpers.get_age(today) - helpers.get_age(check_release_date[0]) < pause_delta:
logger.info("Now updating: " + rg['title'])
new_releases = mb.get_new_releases(rgid,includeExtras)
else:
logger.info('%s is over %s days old; not updating' % (al_title, pause_delta))
skip_log = 1
new_releases = 0
else:
logger.info("Now adding/updating: " + rg['title'])
new_releases = mb.get_new_releases(rgid,includeExtras)
if force_repackage == 1:
new_releases = -1
logger.info('Forcing repackage of %s, since dB groups have been removed' % al_title)
else:
new_releases = new_releases
else:
logger.info("Now adding/updating: " + rg['title'])
new_releases = mb.get_new_releases(rgid,includeExtras)
if force_repackage == 1:
new_releases = -1
logger.info('Forcing repackage of %s, since dB groups have been removed' % al_title)
else:
new_releases = new_releases
new_releases = mb.get_new_releases(rgid,includeExtras,forcefull)
#What this does is adds new releases per artist to the allalbums + alltracks databases
#new_releases = mb.get_new_releases(rgid,includeExtras)
@@ -411,9 +415,12 @@ def addArtisttoDB(artistid, extrasonly=False):
newValueDict['Status'] = "Skipped"
#Only update albums table with hybrid release if user didn't choose an alternate release
check_alternate_release = myDB.action("SELECT AlbumID, ReleaseID FROM albums WHERE ArtistID=? AND AlbumID=?", ([artistid], [rg['id']])).fetchone()
if check_alternate_release[0] == check_alternate_release[1]:
myDB.upsert("albums", newValueDict, controlValueDict)
check_alternate_release = myDB.action("SELECT AlbumID, ReleaseID FROM albums WHERE ArtistID=? AND AlbumID=?", (artistid, rg['id'])).fetchone()
if check_alternate_release:
if check_alternate_release[0] == check_alternate_release[1]:
myDB.upsert("albums", newValueDict, controlValueDict)
else:
myDB.upsert("albums", newValueDict, controlValueDict)
myDB.action('DELETE from tracks WHERE AlbumID=?', [rg['id']])
tracks = myDB.action('SELECT * from alltracks WHERE ReleaseID=?', [releaseid]).fetchall()
@@ -441,9 +448,12 @@ def addArtisttoDB(artistid, extrasonly=False):
}
#Only update tracks table with hybrid release if user didn't choose an alternate release
check_alternate_release = myDB.action("SELECT AlbumID, ReleaseID FROM albums WHERE ArtistID=? AND AlbumID=?", ([artistid], [rg['id']])).fetchone()
if check_alternate_release[0] == check_alternate_release[1]:
myDB.upsert("tracks", newValueDict, controlValueDict)
check_alternate_release = myDB.action("SELECT AlbumID, ReleaseID FROM albums WHERE ArtistID=? AND AlbumID=?", (artistid, rg['id'])).fetchone()
if check_alternate_release:
if check_alternate_release[0] == check_alternate_release[1]:
myDB.upsert("tracks", newValueDict, controlValueDict)
else:
myDB.upsert("tracks", newValueDict, controlValueDict)
# Mark albums as downloaded if they have at least 80% (by default, configurable) of the album
have_track_count = len(myDB.select('SELECT * from tracks WHERE AlbumID=? AND Location IS NOT NULL', [rg['id']]))

View File

@@ -332,7 +332,7 @@ def getRelease(releaseid, include_artist_info=True):
return release
def get_new_releases(rgid,includeExtras=False):
def get_new_releases(rgid,includeExtras=False,forcefull=False):
myDB = db.DBConnection()
results = []
@@ -388,7 +388,7 @@ def get_new_releases(rgid,includeExtras=False):
artistid = unicode(releasedata['artist-credit'][0]['artist']['id'])
album_checker = myDB.action('SELECT * from allalbums WHERE ReleaseID=?', [rel_id_check]).fetchone()
if not album_checker:
if not album_checker or forcefull:
release['AlbumTitle'] = unicode(releasedata['title'])
release['AlbumID'] = unicode(rgid)
release['AlbumASIN'] = unicode(releasedata['asin']) if 'asin' in releasedata else None

View File

@@ -17,7 +17,7 @@ import headphones
from headphones import logger, db, importer
def dbUpdate():
def dbUpdate(forcefull=False):
myDB = db.DBConnection()
@@ -28,6 +28,6 @@ def dbUpdate():
for artist in activeartists:
artistid = artist[0]
importer.addArtisttoDB(artistid)
importer.addArtisttoDB(artistid=artistid, extrasonly=False, forcefull=forcefull)
logger.info('Update complete')

View File

@@ -150,7 +150,7 @@ class WebInterface(object):
newValueDict = {'IncludeExtras': 1,
'Extras': extras}
myDB.upsert("artists", newValueDict, controlValueDict)
threading.Thread(target=importer.addArtisttoDB, args=[ArtistID, True]).start()
threading.Thread(target=importer.addArtisttoDB, args=[ArtistID, True, False]).start()
raise cherrypy.HTTPRedirect("artistPage?ArtistID=%s" % ArtistID)
getExtras.exposed = True
@@ -403,10 +403,16 @@ class WebInterface(object):
def forceUpdate(self):
from headphones import updater
threading.Thread(target=updater.dbUpdate).start()
threading.Thread(target=updater.dbUpdate, args=[False]).start()
raise cherrypy.HTTPRedirect("home")
forceUpdate.exposed = True
def forceFullUpdate(self):
from headphones import updater
threading.Thread(target=updater.dbUpdate, args=[True]).start()
raise cherrypy.HTTPRedirect("home")
forceFullUpdate.exposed = True
def forceSearch(self):
from headphones import searcher
threading.Thread(target=searcher.searchforalbum).start()