diff --git a/headphones/__init__.py b/headphones/__init__.py index f3bfc597..a6ab5255 100644 --- a/headphones/__init__.py +++ b/headphones/__init__.py @@ -136,6 +136,8 @@ LOSSY_MEDIA_FORMATS = ["mp3", "aac", "ogg", "ape", "m4a"] LOSSLESS_MEDIA_FORMATS = ["flac"] MEDIA_FORMATS = LOSSY_MEDIA_FORMATS + LOSSLESS_MEDIA_FORMATS +ALBUM_COMPLETION_PCT = None # This is used in importer.py to determine how complete an album needs to be - to be considered "downloaded". Percentage from 0-100 + TORRENTBLACKHOLE_DIR = None NUMBEROFSEEDERS = 10 ISOHUNT = None @@ -242,7 +244,8 @@ def initialize(): NZBSORG, NZBSORG_UID, NZBSORG_HASH, NEWZBIN, NEWZBIN_UID, NEWZBIN_PASSWORD, LASTFM_USERNAME, INTERFACE, FOLDER_PERMISSIONS, \ ENCODERFOLDER, ENCODER, BITRATE, SAMPLINGFREQUENCY, MUSIC_ENCODER, ADVANCEDENCODER, ENCODEROUTPUTFORMAT, ENCODERQUALITY, ENCODERVBRCBR, \ ENCODERLOSSLESS, PROWL_ENABLED, PROWL_PRIORITY, PROWL_KEYS, PROWL_ONSNATCH, MIRRORLIST, MIRROR, CUSTOMHOST, CUSTOMPORT, \ - CUSTOMSLEEP, HPUSER, HPPASS, XBMC_ENABLED, XBMC_HOST, XBMC_USERNAME, XBMC_PASSWORD, XBMC_UPDATE, XBMC_NOTIFY, NMA_ENABLED, NMA_APIKEY, NMA_PRIORITY, SYNOINDEX_ENABLED + CUSTOMSLEEP, HPUSER, HPPASS, XBMC_ENABLED, XBMC_HOST, XBMC_USERNAME, XBMC_PASSWORD, XBMC_UPDATE, XBMC_NOTIFY, NMA_ENABLED, NMA_APIKEY, NMA_PRIORITY, SYNOINDEX_ENABLED, \ + ALBUM_COMPLETION_PCT if __INITIALIZED__: return False @@ -259,6 +262,7 @@ def initialize(): CheckSection('XBMC') CheckSection('NMA') CheckSection('Synoindex') + CheckSection('Advanced') # Set global variables based on config file or use defaults CONFIG_VERSION = check_setting_str(CFG, 'General', 'config_version', '0') @@ -383,8 +387,10 @@ def initialize(): CUSTOMHOST = check_setting_str(CFG, 'General', 'customhost', 'localhost') CUSTOMPORT = check_setting_int(CFG, 'General', 'customport', 5000) CUSTOMSLEEP = check_setting_int(CFG, 'General', 'customsleep', 1) - HPUSER = check_setting_str(CFG, 'General', 'hpuser', 'username') - HPPASS = check_setting_str(CFG, 'General', 'hppass', 'password') + HPUSER = check_setting_str(CFG, 'General', 'hpuser', '') + HPPASS = check_setting_str(CFG, 'General', 'hppass', '') + + ALBUM_COMPLETION_PCT = check_setting_int(CFG, 'Advanced', 'album_completion_pct', 80) # update folder formats in the config & bump up config version if CONFIG_VERSION == '0': @@ -662,6 +668,9 @@ def config_write(): new_config['General']['hpuser'] = HPUSER new_config['General']['hppass'] = HPPASS + new_config['Advanced'] = {} + new_config['Advanced']['album_completion_pct'] = ALBUM_COMPLETION_PCT + new_config.write() diff --git a/headphones/importer.py b/headphones/importer.py index 5a5efa75..143ebe78 100644 --- a/headphones/importer.py +++ b/headphones/importer.py @@ -156,7 +156,7 @@ def addArtisttoDB(artistid, extrasonly=False): rgid = rg['id'] # check if the album already exists - rg_exists = myDB.select("SELECT * from albums WHERE AlbumID=?", [rg['id']]) + rg_exists = myDB.action("SELECT * from albums WHERE AlbumID=?", [rg['id']]).fetchone() try: release_dict = mb.getReleaseGroup(rgid) @@ -180,7 +180,7 @@ def addArtisttoDB(artistid, extrasonly=False): } # Only change the status & add DateAdded if the album is not already in the database - if not len(rg_exists): + if not rg_exists: newValueDict['DateAdded']= helpers.today() @@ -193,6 +193,10 @@ def addArtisttoDB(artistid, extrasonly=False): myDB.upsert("albums", newValueDict, controlValueDict) + # This is used to see how many tracks you have from an album - to mark it as downloaded. Default is 80%, can be set in config as ALBUM_COMPLETION_PCT + total_track_count = len(release_dict['tracks']) + + for track in release_dict['tracks']: cleanname = helpers.cleanName(artist['artist_name'] + ' ' + rg['title'] + ' ' + track['title']) @@ -217,16 +221,29 @@ def addArtisttoDB(artistid, extrasonly=False): if not match: match = myDB.action('SELECT Location, BitRate, Format from have WHERE TrackID=?', [track['id']]).fetchone() if match: + have_track_count += 1 newValueDict['Location'] = match['Location'] newValueDict['BitRate'] = match['BitRate'] newValueDict['Format'] = match['Format'] myDB.action('DELETE from have WHERE Location=?', [match['Location']]) - + 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']])) + + if rg_exists: + if rg_exists['Status'] == 'Skipped' and ((have_track_count/float(total_track_count)) >= (headphones.ALBUM_COMPLETION_PCT/100.0)): + logger.info('album exists, marking as downloaded 1') + myDB.action('UPDATE albums SET Status=? WHERE AlbumID=?', ['Downloaded', rg['id']]) + else: + if ((have_track_count/float(total_track_count)) >= (headphones.ALBUM_COMPLETION_PCT/100.0)): + logger.info('album exists, marking as downloaded 2') + myDB.action('UPDATE albums SET Status=? WHERE AlbumID=?', ['Downloaded', rg['id']]) + logger.debug(u"Updating album cache for " + rg['title']) cache.getThumb(AlbumID=rg['id']) - + 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=?', [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']]))