mirror of
https://github.com/rembo10/headphones.git
synced 2026-05-16 00:25:31 +01:00
New feature: Download a new version or retry same version. Bug fixes: New albums not being marked as wanted, existing albums status changing to Skipped
This commit is contained in:
@@ -146,6 +146,9 @@ def addArtisttoDB(artistid):
|
||||
for rg in artist['releasegroups']:
|
||||
|
||||
rgid = rg['id']
|
||||
|
||||
# check if the album already exists
|
||||
rg_exists = myDB.select("SELECT * from albums WHERE AlbumID=?", [rg['id']])
|
||||
|
||||
try:
|
||||
releaseid = mb.getReleaseGroup(rgid)
|
||||
@@ -164,27 +167,32 @@ def addArtisttoDB(artistid):
|
||||
|
||||
logger.info(u"Now adding/updating album: " + rg['title'])
|
||||
controlValueDict = {"AlbumID": rg['id']}
|
||||
newValueDict = {"ArtistID": artistid,
|
||||
"ArtistName": artist['artist_name'],
|
||||
"AlbumTitle": rg['title'],
|
||||
"AlbumASIN": release['asin'],
|
||||
"ReleaseDate": release['date'],
|
||||
"DateAdded": helpers.today(),
|
||||
"Status": "Skipped"
|
||||
}
|
||||
|
||||
if len(rg_exists):
|
||||
|
||||
newValueDict = {"AlbumASIN": release['asin'],
|
||||
"ReleaseDate": release['date'],
|
||||
}
|
||||
|
||||
else:
|
||||
|
||||
newValueDict = {"ArtistID": artistid,
|
||||
"ArtistName": artist['artist_name'],
|
||||
"AlbumTitle": rg['title'],
|
||||
"AlbumASIN": release['asin'],
|
||||
"ReleaseDate": release['date'],
|
||||
"DateAdded": helpers.today(),
|
||||
}
|
||||
|
||||
if release['date'] > helpers.today():
|
||||
newValueDict['Status'] = "Wanted"
|
||||
else:
|
||||
newValueDict['Status'] = "Skipped"
|
||||
|
||||
myDB.upsert("albums", newValueDict, controlValueDict)
|
||||
|
||||
# I changed the albumid from releaseid -> rgid, so might need to delete albums that have a releaseid
|
||||
myDB.action('DELETE from albums WHERE AlbumID=?', [release['id']])
|
||||
|
||||
latestrelease = myDB.select("SELECT ReleaseDate, DateAdded from albums WHERE AlbumID=?", [rg['id']])
|
||||
|
||||
if latestrelease[0][0] > latestrelease[0][1]:
|
||||
logger.info(release['title'] + u" is an upcoming album. Setting its status to 'Wanted'...")
|
||||
controlValueDict = {"AlbumID": release['id']}
|
||||
newValueDict = {"Status": "Wanted"}
|
||||
myDB.upsert("albums", newValueDict, controlValueDict)
|
||||
myDB.action('DELETE from albums WHERE AlbumID=?', [release['id']])
|
||||
|
||||
for track in release['tracks']:
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import os, re
|
||||
import headphones
|
||||
from headphones import logger, db, helpers
|
||||
|
||||
def searchNZB(albumid=None):
|
||||
def searchNZB(albumid=None, new=False):
|
||||
|
||||
myDB = db.DBConnection()
|
||||
|
||||
@@ -185,7 +185,7 @@ def searchNZB(albumid=None):
|
||||
|
||||
if headphones.PREFERRED_QUALITY == 2 and headphones.PREFERRED_BITRATE:
|
||||
|
||||
logger.debug('Target bitrate: %i kbps' % headphones.PREFERRED_BITRATE)
|
||||
logger.debug('Target bitrate: %s kbps' % headphones.PREFERRED_BITRATE)
|
||||
|
||||
tracks = myDB.select('SELECT TrackDuration from tracks WHERE AlbumID=?', [albumid])
|
||||
|
||||
@@ -201,18 +201,38 @@ def searchNZB(albumid=None):
|
||||
delta = abs(targetsize - result[1])
|
||||
newlist.append((result[0], result[1], result[2], delta))
|
||||
|
||||
bestqual = sorted(newlist, key=lambda title: title[3])[0]
|
||||
nzblist = sorted(newlist, key=lambda title: title[3])
|
||||
|
||||
except Exception, e:
|
||||
|
||||
logger.debug('Error: %s' % str(e))
|
||||
logger.info('No track information for %s - %s. Defaulting to highest quality' % (albums[0], albums[1]))
|
||||
|
||||
bestqual = sorted(resultlist, key=lambda title: title[1], reverse=True)[0]
|
||||
nzblist = sorted(resultlist, key=lambda title: title[1], reverse=True)
|
||||
|
||||
else:
|
||||
|
||||
bestqual = sorted(resultlist, key=lambda title: title[1], reverse=True)[0]
|
||||
nzblist = sorted(resultlist, key=lambda title: title[1], reverse=True)
|
||||
|
||||
|
||||
if new:
|
||||
# Checks to see if it's already downloaded
|
||||
i = 0
|
||||
|
||||
while i < len(nzblist):
|
||||
alreadydownloaded = myDB.select('SELECT * from snatched WHERE URL=?', [nzblist[i][2]])
|
||||
|
||||
if len(alreadydownloaded) >= 1:
|
||||
logger.info('%s has already been downloaded. Skipping.' % nzblist[i][0])
|
||||
i += 1
|
||||
|
||||
else:
|
||||
bestqual = nzblist[i]
|
||||
break
|
||||
|
||||
else:
|
||||
bestqual = nzblist[0]
|
||||
|
||||
|
||||
logger.info(u"Found best result: %s (%s) - %s" % (bestqual[0], bestqual[2], helpers.bytes_to_mb(bestqual[1])))
|
||||
downloadurl = bestqual[2]
|
||||
|
||||
@@ -6,7 +6,7 @@ def dbUpdate():
|
||||
|
||||
myDB = db.DBConnection()
|
||||
|
||||
activeartists = myDB.select('SELECT ArtistID, ArtistName from artists WHERE Status="Active"')
|
||||
activeartists = myDB.select('SELECT ArtistID, ArtistName from artists WHERE Status="Active" or Status="Loading"')
|
||||
|
||||
logger.info('Starting update for %i active artists' % len(activeartists))
|
||||
|
||||
|
||||
@@ -126,7 +126,7 @@ class WebInterface(object):
|
||||
elif results[i][3] == 'Downloaded':
|
||||
newStatus = '''<b>%s</b>[<A class="external" href="queueAlbum?AlbumID=%s&ArtistID=%s">retry</a>]''' % (results[i][3], results[i][2], ArtistID)
|
||||
elif results[i][3] == 'Snatched':
|
||||
newStatus = '''<b>%s</b>[<A class="external" href="queueAlbum?AlbumID=%s&ArtistID=%s">retry</a>]''' % (results[i][3], results[i][2], ArtistID)
|
||||
newStatus = '''<b>%s</b>[<A class="external" href="queueAlbum?AlbumID=%s&ArtistID=%s">retry</a>][<A class="external" href="queueAlbum?AlbumID=%s&ArtistID=%s&new=True">new</a>]''' % (results[i][3], results[i][2], ArtistID, results[i][2], ArtistID)
|
||||
else:
|
||||
newStatus = '%s' % (results[i][3])
|
||||
page.append('''<tr><td align="left"><img src="http://ec1.images-amazon.com/images/P/%s.01.MZZZZZZZ.jpg" height="50" width="50"></td>
|
||||
@@ -283,7 +283,7 @@ class WebInterface(object):
|
||||
|
||||
deleteArtist.exposed = True
|
||||
|
||||
def queueAlbum(self, AlbumID, ArtistID):
|
||||
def queueAlbum(self, AlbumID, ArtistID, new=False):
|
||||
|
||||
logger.info(u"Marking album: " + AlbumID + "as wanted...")
|
||||
myDB = db.DBConnection()
|
||||
@@ -292,7 +292,7 @@ class WebInterface(object):
|
||||
myDB.upsert("albums", newValueDict, controlValueDict)
|
||||
|
||||
import searcher
|
||||
threading.Thread(target=searcher.searchNZB, args=[AlbumID]).start()
|
||||
threading.Thread(target=searcher.searchNZB, args=[AlbumID, new]).start()
|
||||
|
||||
raise cherrypy.HTTPRedirect("artistPage?ArtistID=%s" % ArtistID)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user