mirror of
https://github.com/rembo10/headphones.git
synced 2026-07-22 08:53:59 +01:00
Keep a local cache of releaseID->releaseGroupID relationships so we
don't hammer MB unnecessarily when external programs addReleaseByID
This commit is contained in:
@@ -431,6 +431,7 @@ def dbcheck():
|
|||||||
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)')
|
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)')
|
||||||
c.execute('CREATE TABLE IF NOT EXISTS lastfmcloud (ArtistName TEXT, ArtistID TEXT, Count INTEGER)')
|
c.execute('CREATE TABLE IF NOT EXISTS lastfmcloud (ArtistName TEXT, ArtistID TEXT, Count INTEGER)')
|
||||||
c.execute('CREATE TABLE IF NOT EXISTS descriptions (ReleaseGroupID TEXT, ReleaseID TEXT, Summary TEXT, Content TEXT)')
|
c.execute('CREATE TABLE IF NOT EXISTS descriptions (ReleaseGroupID TEXT, ReleaseID TEXT, Summary TEXT, Content TEXT)')
|
||||||
|
c.execute('CREATE TABLE IF NOT EXISTS releases (ReleaseID TEXT, ReleaseGroupID TEXT, UNIQUE(ReleaseID, ReleaseGroupID))')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
c.execute('SELECT IncludeExtras from artists')
|
c.execute('SELECT IncludeExtras from artists')
|
||||||
|
|||||||
+19
-14
@@ -256,21 +256,26 @@ def addArtisttoDB(artistid, extrasonly=False):
|
|||||||
logger.info(u"Updating complete for: " + artist['artist_name'])
|
logger.info(u"Updating complete for: " + artist['artist_name'])
|
||||||
|
|
||||||
def addReleaseById(rid):
|
def addReleaseById(rid):
|
||||||
|
|
||||||
myDB = db.DBConnection()
|
myDB = db.DBConnection()
|
||||||
|
|
||||||
|
rgid = myDB.select("SELECT * from releases WHERE ReleaseID=?", [rid])
|
||||||
|
if not rgid:
|
||||||
|
#we have to make a call to get the release no matter what so we can get the RGID
|
||||||
|
#need a way around this - a local cache maybe in the future maybe?
|
||||||
|
try:
|
||||||
|
release_dict = mb.getRelease(rid)
|
||||||
|
#keep a local cache of these so that external programs that are adding releasesByID don't hammer MB
|
||||||
|
myDB.action('INSERT INTO releases VALUES( ?, ?)', [rid, release_dict['rgid']])
|
||||||
|
except Exception, e:
|
||||||
|
logger.info('Unable to get release information for Release: ' + str(rid) + " " + str(e))
|
||||||
|
return
|
||||||
|
if not release_dict:
|
||||||
|
logger.info('Unable to get release information for Release: ' + str(rid) + " no dict")
|
||||||
|
return
|
||||||
|
|
||||||
|
rgid = release_dict['rgid']
|
||||||
|
|
||||||
#we have to make a call to get the release no matter what so we can get the RGID
|
|
||||||
#need a way around this - a local cache maybe in the future maybe?
|
|
||||||
try:
|
|
||||||
release_dict = mb.getRelease(rid)
|
|
||||||
except Exception, e:
|
|
||||||
logger.info('Unable to get release information for Release: ' + str(rid) + " " + str(e))
|
|
||||||
return
|
|
||||||
if not release_dict:
|
|
||||||
logger.info('Unable to get release information for Release: ' + str(rid) + " no dict")
|
|
||||||
return
|
|
||||||
|
|
||||||
rgid = release_dict['rgid']
|
|
||||||
|
|
||||||
#we don't want to make more calls to MB here unless we have to, could be happening quite a lot
|
#we don't want to make more calls to MB here unless we have to, could be happening quite a lot
|
||||||
#TODO: why do I have to str() this here? I don't get it.
|
#TODO: why do I have to str() this here? I don't get it.
|
||||||
@@ -316,7 +321,7 @@ def addReleaseById(rid):
|
|||||||
for track in release_dict['tracks']:
|
for track in release_dict['tracks']:
|
||||||
|
|
||||||
controlValueDict = {"TrackID": track['id'],
|
controlValueDict = {"TrackID": track['id'],
|
||||||
"AlbumID": release_dict['rgid']}
|
"AlbumID": rgid}
|
||||||
newValueDict = {"ArtistID": release_dict['artist_id'],
|
newValueDict = {"ArtistID": release_dict['artist_id'],
|
||||||
"ArtistName": release_dict['artist_name'],
|
"ArtistName": release_dict['artist_name'],
|
||||||
"AlbumTitle": release_dict['rg_title'],
|
"AlbumTitle": release_dict['rg_title'],
|
||||||
|
|||||||
Reference in New Issue
Block a user