mirror of
https://github.com/rembo10/headphones.git
synced 2026-07-20 16:03:59 +01:00
Merging sbusers changes
This commit is contained in:
@@ -441,6 +441,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')
|
||||||
|
|||||||
+42
-22
@@ -259,29 +259,39 @@ 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()
|
||||||
|
|
||||||
#we have to make a call to get the release no matter what so we can get the RGID
|
rgid = None
|
||||||
#need a way around this - a local cache maybe in the future maybe?
|
artistid = None
|
||||||
try:
|
release_dict = None
|
||||||
release_dict = mb.getRelease(rid)
|
results = myDB.select("SELECT albums.ArtistID, releases.ReleaseGroupID from releases, albums WHERE releases.ReleaseID=? and releases.ReleaseGroupID=albums.AlbumID LIMIT 1", [rid])
|
||||||
except Exception, e:
|
for result in results:
|
||||||
logger.info('Unable to get release information for Release: ' + str(rid) + " " + str(e))
|
rgid = result['ReleaseGroupID']
|
||||||
return
|
artistid = result['ArtistID']
|
||||||
if not release_dict:
|
logger.debug("Found a cached releaseid : releasegroupid relationship: " + rid + " : " + rgid)
|
||||||
logger.info('Unable to get release information for Release: ' + str(rid) + " no dict")
|
if not rgid:
|
||||||
return
|
#didn't find it in the cache, get the information from MB
|
||||||
|
logger.debug("Didn't find releaseID " + rid + " in the cache. Looking up its ReleaseGroupID")
|
||||||
rgid = release_dict['rgid']
|
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']
|
||||||
|
artistid = release_dict['artist_id']
|
||||||
|
|
||||||
#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.
|
|
||||||
rg_exists = myDB.select("SELECT * from albums WHERE AlbumID=?", [rgid])
|
rg_exists = myDB.select("SELECT * from albums WHERE AlbumID=?", [rgid])
|
||||||
|
|
||||||
#make sure the artist exists since I don't know what happens later if it doesn't
|
#make sure the artist exists since I don't know what happens later if it doesn't
|
||||||
artist_exists = myDB.select("SELECT * from artists WHERE ArtistID=?", [release_dict['artist_id']])
|
artist_exists = myDB.select("SELECT * from artists WHERE ArtistID=?", [artistid])
|
||||||
if not artist_exists:
|
|
||||||
|
if not artist_exists and release_dict:
|
||||||
if release_dict['artist_name'].startswith('The '):
|
if release_dict['artist_name'].startswith('The '):
|
||||||
sortname = release_dict['artist_name'][4:]
|
sortname = release_dict['artist_name'][4:]
|
||||||
else:
|
else:
|
||||||
@@ -299,8 +309,13 @@ def addReleaseById(rid):
|
|||||||
newValueDict['IncludeExtras'] = 1
|
newValueDict['IncludeExtras'] = 1
|
||||||
|
|
||||||
myDB.upsert("artists", newValueDict, controlValueDict)
|
myDB.upsert("artists", newValueDict, controlValueDict)
|
||||||
|
|
||||||
if not rg_exists:
|
elif not artist_exists and not release_dict:
|
||||||
|
logger.error("Artist does not exist in the database and did not get a valid response from MB. Skipping release.")
|
||||||
|
return
|
||||||
|
|
||||||
|
if not rg_exists and release_dict: #it should never be the case that we have an rg and not the artist
|
||||||
|
#but if it is this will fail
|
||||||
logger.info(u"Now adding-by-id album (" + release_dict['title'] + ") from id: " + rgid)
|
logger.info(u"Now adding-by-id album (" + release_dict['title'] + ") from id: " + rgid)
|
||||||
controlValueDict = {"AlbumID": rgid}
|
controlValueDict = {"AlbumID": rgid}
|
||||||
|
|
||||||
@@ -315,11 +330,14 @@ def addReleaseById(rid):
|
|||||||
}
|
}
|
||||||
|
|
||||||
myDB.upsert("albums", newValueDict, controlValueDict)
|
myDB.upsert("albums", newValueDict, controlValueDict)
|
||||||
|
|
||||||
|
#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']])
|
||||||
|
|
||||||
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'],
|
||||||
@@ -330,10 +348,12 @@ def addReleaseById(rid):
|
|||||||
}
|
}
|
||||||
|
|
||||||
myDB.upsert("tracks", newValueDict, controlValueDict)
|
myDB.upsert("tracks", newValueDict, controlValueDict)
|
||||||
|
|
||||||
|
|
||||||
#start a search for the album
|
#start a search for the album
|
||||||
import searcher
|
import searcher
|
||||||
searcher.searchNZB(rgid, False)
|
searcher.searchNZB(rgid, False)
|
||||||
|
elif not rg_exists and not release_dict:
|
||||||
|
logger.error("ReleaseGroup does not exist in the database and did not get a valid response from MB. Skipping release.")
|
||||||
|
return
|
||||||
else:
|
else:
|
||||||
logger.info('Release ' + str(rid) + " already exists in the database!")
|
logger.info('Release ' + str(rid) + " already exists in the database!")
|
||||||
@@ -443,7 +443,7 @@ def verifyresult(title, term):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def getresultNZB(result):
|
def getresultNZB(result):
|
||||||
if result[3] == 'Newzbin':
|
if result[3] == 'newzbin':
|
||||||
params = urllib.urlencode({"username": headphones.NEWZBIN_UID, "password": headphones.NEWZBIN_PASSWORD, "reportid": result[2]})
|
params = urllib.urlencode({"username": headphones.NEWZBIN_UID, "password": headphones.NEWZBIN_PASSWORD, "reportid": result[2]})
|
||||||
url = "https://www.newzbin.com" + "/api/dnzb/"
|
url = "https://www.newzbin.com" + "/api/dnzb/"
|
||||||
urllib._urlopener = NewzbinDownloader()
|
urllib._urlopener = NewzbinDownloader()
|
||||||
@@ -453,9 +453,9 @@ def getresultNZB(result):
|
|||||||
logger.warn('Error fetching nzb from url: %s. Error: %s' % (url, e))
|
logger.warn('Error fetching nzb from url: %s. Error: %s' % (url, e))
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
nzb = urllib2.urlopen(result[2], timeout=20).read()
|
nzb = urllib2.urlopen(result[2], timeout=30).read()
|
||||||
except Exception, e:
|
except urllib2.URLError, e:
|
||||||
logger.warn('Error fetching nzb from url: %s. Error: %s' % (result[2], e))
|
logger.warn('Error fetching nzb from url: ' + result[2] + ' %s' % e)
|
||||||
return nzb
|
return nzb
|
||||||
|
|
||||||
def preprocess(resultlist):
|
def preprocess(resultlist):
|
||||||
@@ -478,4 +478,4 @@ def preprocess(resultlist):
|
|||||||
return nzb, result
|
return nzb, result
|
||||||
else:
|
else:
|
||||||
logger.error("Couldn't retrieve the best nzb. Skipping.")
|
logger.error("Couldn't retrieve the best nzb. Skipping.")
|
||||||
return (False, False)
|
return (False, False)
|
||||||
Reference in New Issue
Block a user