From 2fb45f489ac3bc9b0687e04b956183be625f9c4c Mon Sep 17 00:00:00 2001 From: rembo10 Date: Thu, 25 Oct 2012 20:04:06 -0300 Subject: [PATCH] Mark new albums added to musicbrainz in the last 21 days as wanted (if AUTOWANT_UPCOMING is selected) --- headphones/helpers.py | 11 +++++++++++ headphones/importer.py | 10 ++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/headphones/helpers.py b/headphones/helpers.py index 89fb20cc..957d9717 100644 --- a/headphones/helpers.py +++ b/headphones/helpers.py @@ -118,6 +118,17 @@ def now(): now = datetime.datetime.now() return now.strftime("%Y-%m-%d %H:%M:%S") +def get_age(date): + + split_date = date.split('-') + + try: + days_old = int(split_date[0])*365 + int(split_date[1])*30 + int(split_date[2]) + except IndexError: + days_old = False + + return days_old + def bytes_to_mb(bytes): mb = int(bytes)/1048576 diff --git a/headphones/importer.py b/headphones/importer.py index 158d703f..67021a18 100644 --- a/headphones/importer.py +++ b/headphones/importer.py @@ -358,11 +358,17 @@ def addArtisttoDB(artistid, extrasonly=False): if not rg_exists: - newValueDict['DateAdded']= helpers.today() + today = helpers.today() + + newValueDict['DateAdded']= today if headphones.AUTOWANT_ALL: newValueDict['Status'] = "Wanted" - elif album['ReleaseDate'] > helpers.today() and headphones.AUTOWANT_UPCOMING: + elif album['ReleaseDate'] > today and headphones.AUTOWANT_UPCOMING: + newValueDict['Status'] = "Wanted" + # Sometimes "new" albums are added to musicbrainz after their release date, so let's try to catch these + # The first test just makes sure we have year-month-day + elif helpers.get_age(album['ReleaseDate']) and helpers.get_age(today) - helpers.get_age(album['ReleaseDate']) < 21 and headphones.AUTOWANT_UPCOMING: newValueDict['Status'] = "Wanted" else: newValueDict['Status'] = "Skipped"