def finalize_update(artistid, artistname, errors=False): # Moving this little bit to it's own function so we can update have tracks & latest album when deleting extras myDB = db.DBConnection() latestalbum = myDB.action('SELECT AlbumTitle, ReleaseDate, AlbumID from albums WHERE ArtistID=? order by ReleaseDate DESC', [artistid]).fetchone() totaltracks = len(myDB.select('SELECT TrackTitle from tracks WHERE ArtistID=? AND AlbumID IN (SELECT AlbumID FROM albums WHERE Status != "Ignored")', [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', [artistid])) + len(myDB.select('SELECT TrackTitle from have WHERE ArtistName like ? AND Matched = "Failed"', [artistname])) controlValueDict = {"ArtistID": artistid} if latestalbum: newValueDict = {"Status": "Active", "LatestAlbum": latestalbum['AlbumTitle'], "ReleaseDate": latestalbum['ReleaseDate'], "AlbumID": latestalbum['AlbumID'], "TotalTracks": totaltracks, "HaveTracks": havetracks} else: newValueDict = {"Status": "Active", "TotalTracks": totaltracks, "HaveTracks": havetracks} if not errors: newValueDict['LastUpdated'] = helpers.now() myDB.upsert("artists", newValueDict, controlValueDict)
def log(self, message, level): logger = logging.getLogger('headphones') threadname = threading.currentThread().getName() if level != 'DEBUG': headphones.LOG_LIST.insert(0, (helpers.now(), message, level, threadname)) message = threadname + ' : ' + message if level == 'DEBUG': logger.debug(message) elif level == 'INFO': logger.info(message) elif level == 'WARNING': logger.warn(message) else: logger.error(message)
controlValueDict = {"ArtistID": artistid} if latestalbum: newValueDict = { "Status": "Active", "LatestAlbum": latestalbum["AlbumTitle"], "ReleaseDate": latestalbum["ReleaseDate"], "AlbumID": latestalbum["AlbumID"], "TotalTracks": totaltracks, "HaveTracks": havetracks, } else: newValueDict = {"Status": "Active", "TotalTracks": totaltracks, "HaveTracks": havetracks} if not errors: newValueDict["LastUpdated"] = helpers.now() myDB.upsert("artists", newValueDict, controlValueDict) logger.info(u"Seeing if we need album art for: %s" % artist["artist_name"]) cache.getThumb(ArtistID=artistid) if errors: logger.info( "[%s] Finished updating artist: %s but with errors, so not marking it as updated in the database" % (artist["artist_name"], artist["artist_name"]) ) else: myDB.action("DELETE FROM newartists WHERE ArtistName = ?", [artist["artist_name"]]) logger.info(u"Updating complete for: %s" % artist["artist_name"])
controlValueDict = {"ArtistID": artistid} if latestalbum: newValueDict = {"Status": "Active", "LatestAlbum": latestalbum['AlbumTitle'], "ReleaseDate": latestalbum['ReleaseDate'], "AlbumID": latestalbum['AlbumID'], "TotalTracks": totaltracks, "HaveTracks": havetracks} else: newValueDict = {"Status": "Active", "TotalTracks": totaltracks, "HaveTracks": havetracks} if not errors: newValueDict['LastUpdated'] = helpers.now() myDB.upsert("artists", newValueDict, controlValueDict) logger.info(u"Seeing if we need album art for: " + artist['artist_name']) cache.getThumb(ArtistID=artistid) if errors: logger.info("Finished updating artist: " + artist['artist_name'] + " but with errors, so not marking it as updated in the database") else: logger.info(u"Updating complete for: " + artist['artist_name']) def addReleaseById(rid): myDB = db.DBConnection()
def test_notify(self): return self._notifyTwitter( "This is a test notification from Headphones at " + helpers.now(), force=True)
def notify_download(self, title): if headphones.CONFIG.TWITTER_ENABLED: self._notifyTwitter(common.notifyStrings[ common.NOTIFY_DOWNLOAD] + ': ' + title + ' at ' + helpers.now())
def notify_snatch(self, title): if headphones.CONFIG.TWITTER_ONSNATCH: self._notifyTwitter( common.notifyStrings[ common.NOTIFY_SNATCH] + ': ' + title + ' at ' + helpers.now())
def emit(self, record): message = self.format(record) message = message.replace("\n", "<br />") headphones.LOG_LIST.insert(0, (helpers.now(), message, record.levelname, record.threadName))
def notify_snatch(self, title): if headphones.CONFIG.TWITTER_ONSNATCH: self._notifyTwitter( common.notifyStrings[common.NOTIFY_SNATCH] + ': ' + title + ' at ' + helpers.now())
def test_notify(self): return self._notifyTwitter("This is a test notification from Headphones at " + helpers.now(), force=True)
def emit(self, record): message = self.format(record) message = message.replace("\n", "<br />") headphones.LOG_LIST.insert( 0, (helpers.now(), message, record.levelname, record.threadName))
"Status": "Active", "LatestAlbum": latestalbum['AlbumTitle'], "ReleaseDate": latestalbum['ReleaseDate'], "AlbumID": latestalbum['AlbumID'], "TotalTracks": totaltracks, "HaveTracks": havetracks } else: newValueDict = { "Status": "Active", "TotalTracks": totaltracks, "HaveTracks": havetracks } if not errors: newValueDict['LastUpdated'] = helpers.now() myDB.upsert("artists", newValueDict, controlValueDict) logger.info(u"Seeing if we need album art for: " + artist['artist_name']) cache.getThumb(ArtistID=artistid) if errors: logger.info( "Finished updating artist: " + artist['artist_name'] + " but with errors, so not marking it as updated in the database") else: logger.info(u"Updating complete for: " + artist['artist_name']) def addReleaseById(rid):