From 7a5e0b9f7985c096234b5c248ce86957170c4ea1 Mon Sep 17 00:00:00 2001 From: Palli Date: Thu, 9 Feb 2012 22:55:10 +0000 Subject: [PATCH] Add a format column to albums, tracks and allow for fetching lossless if album quality is not. --- data/css/style.css | 9 +++++- data/interfaces/default/album.html | 10 +++++- data/interfaces/default/artist.html | 23 +++++++++++-- data/interfaces/remix/album.html | 2 +- data/interfaces/remix/artist.html | 23 +++++++++++-- data/interfaces/remix/style.css | 7 +++- headphones/__init__.py | 22 +++++++++++-- headphones/importer.py | 43 +++++++++++++++++++++---- headphones/librarysync.py | 12 +++---- headphones/postprocessor.py | 2 +- headphones/searcher.py | 50 ++++++++++++++++------------- headphones/webserve.py | 10 ++++-- 12 files changed, 164 insertions(+), 49 deletions(-) diff --git a/data/css/style.css b/data/css/style.css index 7641d431..5efc2acc 100755 --- a/data/css/style.css +++ b/data/css/style.css @@ -165,14 +165,19 @@ table#album_table th#reldate { width: 175px; text-align: center; min-width: 70px table#album_table th#status { width: 175px; text-align: center; min-width: 80px; } table#album_table th#type { width: 175px; text-align: center; min-width: 100px; } table#album_table th#bitrate { text-align: center; min-width: 60px; } +table#album_table th#albumformat { text-align: center; min-width: 60px; } +table#album_table th#wantlossless { width: 80px; text-align: center; min-width: 80px; } table#album_table td#select { vertical-align: middle; text-align: left; } table#album_table td#albumart { vertical-align: middle; text-align: left; } table#album_table td#albumname { vertical-align: middle; text-align: center; } table#album_table td#reldate { vertical-align: middle; text-align: center; } table#album_table td#status { vertical-align: middle; text-align: center; font-size: 13px; } +table#album_table td#status a#wantlossless { white-space: nowrap; } table#album_table td#type { vertical-align: middle; text-align: center; } table#album_table td#have { vertical-align: middle; } table#album_table td#bitrate { vertical-align: middle; text-align: center; font-size: 13px; } +table#album_table td#albumformat { vertical-align: middle; text-align: center; font-size: 13px; } +table#album_table td#wantlossless { vertical-align: middle; text-align: center; font-size: 13px; } img.albumArt { float: left; padding-right: 5px; } div#albumheader { padding-top: 48px; height: 200px; } @@ -183,12 +188,14 @@ table#track_table th#name { text-align: center; min-width: 350px; } table#track_table th#duration { width: 175px; text-align: center; min-width: 100px; } table#track_table th#location { text-align: center; width: 250px; } table#track_table th#bitrate { text-align: center; min-width: 75px; } +table#track_table th#format { text-align: center; min-width: 75px; } table#track_table td#number { vertical-align: middle; text-align: right; } table#track_table td#name { vertical-align: middle; text-align: center; font-size: 15px; } table#track_table td#duration { vertical-align: middle; text-align: center; } table#track_table td#location { vertical-align: middle; text-align: center; font-size: 11px; } table#track_table td#bitrate { vertical-align: middle; text-align: center; font-size: 12px; } +table#track_table td#format { vertical-align: middle; text-align: center; font-size: 12px; } table#history_table { background-color: white; width: 100%; font-size: 13px; } @@ -307,4 +314,4 @@ div#shutdown{ text-align: center; vertical-align: middle; } @page { margin: 0.5cm; } p, h2, h3 { orphans: 3; widows: 3; } h2, h3{ page-break-after: avoid; } -} \ No newline at end of file +} diff --git a/data/interfaces/default/album.html b/data/interfaces/default/album.html index 1e38f419..676fdb33 100644 --- a/data/interfaces/default/album.html +++ b/data/interfaces/default/album.html @@ -54,6 +54,7 @@ Duration Local File Bit Rate + Format @@ -75,6 +76,11 @@ trackduration = helpers.convert_milliseconds(track['TrackDuration']) except: trackduration = 'n/a' + + if not track['Format']: + format = 'Unknown' + else: + format = track['Format'] %> ${track['TrackNumber']} @@ -82,6 +88,7 @@ ${trackduration} ${location} ${bitrate} + ${format} %endfor <% @@ -98,6 +105,7 @@ ${duration} ${track['Location']} ${int(track['BitRate'])/1000} kbps + ${track['Format']} %endfor %endif @@ -125,4 +133,4 @@ }); }); - \ No newline at end of file + diff --git a/data/interfaces/default/artist.html b/data/interfaces/default/artist.html index 164658a2..a4d5089e 100644 --- a/data/interfaces/default/artist.html +++ b/data/interfaces/default/artist.html @@ -1,6 +1,7 @@ <%inherit file="base.html"/> <%! from headphones import db + import headphones %> <%def name="headerIncludes()"> @@ -50,6 +51,7 @@ Status Have Bitrate + Format @@ -81,7 +83,17 @@ bitrate = str(int(avgbitrate)/1000) + ' kbps' else: bitrate = '' - + + albumformatcount = myDB.action("SELECT COUNT(DISTINCT Format) FROM tracks WHERE AlbumID=?", [album['AlbumID']]).fetchone()[0] + if albumformatcount == 1: + albumformat = myDB.action("SELECT DISTINCT Format FROM tracks WHERE AlbumID=?", [album['AlbumID']]).fetchone()[0] + elif albumformatcount > 1: + albumformat = 'Mixed' + else: + albumformat = '' + + lossy_formats = [str.upper(fmt) for fmt in headphones.LOSSY_MEDIA_FORMATS] + %> @@ -92,14 +104,20 @@ ${album['Status']} %if album['Status'] == 'Skipped': [want] - %elif album['Status'] == 'Wanted': + %elif (album['Status'] == 'Wanted' or album['Status'] == 'Wanted Lossless'): [skip] %else: [retry][new] %endif + %if albumformat in lossy_formats and album['Status'] == 'Skipped': + [want lossless] + %elif albumformat in lossy_formats and (album['Status'] == 'Snatched' or album['Status'] == 'Downloaded'): + [retry lossless] + %endif
${havetracks}/${totaltracks}
${bitrate} + ${albumformat} %endfor @@ -129,6 +147,7 @@ null, null, { "sType": "title-numeric"}, + null, null ], "oLanguage": { diff --git a/data/interfaces/remix/album.html b/data/interfaces/remix/album.html index 1e38f419..9e23b211 100644 --- a/data/interfaces/remix/album.html +++ b/data/interfaces/remix/album.html @@ -125,4 +125,4 @@ }); }); - \ No newline at end of file + diff --git a/data/interfaces/remix/artist.html b/data/interfaces/remix/artist.html index fced33c4..2369dfea 100644 --- a/data/interfaces/remix/artist.html +++ b/data/interfaces/remix/artist.html @@ -1,6 +1,7 @@ <%inherit file="base.html"/> <%! from headphones import db + import headphones %> <%def name="headerIncludes()"> @@ -50,6 +51,7 @@ Status Have Bitrate + Format @@ -81,6 +83,16 @@ bitrate = str(int(avgbitrate)/1000) + ' kbps' else: bitrate = '' + + albumformatcount = myDB.action("SELECT COUNT(DISTINCT Format) FROM tracks WHERE AlbumID=?", [album['AlbumID']]).fetchone()[0] + if albumformatcount == 1: + albumformat = myDB.action("SELECT DISTINCT Format FROM tracks WHERE AlbumID=?", [album['AlbumID']]).fetchone()[0] + elif albumformatcount > 1: + albumformat = 'Mixed' + else: + albumformat = '' + + lossy_formats = [str.upper(fmt) for fmt in headphones.LOSSY_MEDIA_FORMATS] %> @@ -92,14 +104,20 @@ ${album['Status']} %if album['Status'] == 'Skipped': [want] - %elif album['Status'] == 'Wanted': + %elif (album['Status'] == 'Wanted' or album['Status'] == 'Wanted Lossless'): [skip] %else: [retry][new] %endif + %if albumformat in lossy_formats and album['Status'] == 'Skipped': + [want lossless] + %elif albumformat in lossy_formats and (album['Status'] == 'Snatched' or album['Status'] == 'Downloaded'): + [retry lossless] + %endif
${havetracks}/${totaltracks}
${bitrate} + ${albumformat} %endfor @@ -126,6 +144,7 @@ null, null, { "sType": "title-numeric"}, + null, null ], "oLanguage": { @@ -140,4 +159,4 @@ }); }); - \ No newline at end of file + diff --git a/data/interfaces/remix/style.css b/data/interfaces/remix/style.css index 28fc9c97..43941305 100755 --- a/data/interfaces/remix/style.css +++ b/data/interfaces/remix/style.css @@ -162,12 +162,17 @@ table#album_table th#albumname { text-align: center; min-width: 150px; } table#album_table th#reldate { width: 175px; text-align: center; min-width: 100px; } table#album_table th#status { width: 175px; text-align: center; min-width: 100px; } table#album_table th#type { width: 175px; text-align: center; min-width: 100px; } +table#album_table th#bitrate { width: 175px; text-align: center; min-width: 60px; } +table#album_table th#albumformat { width: 175px; text-align: center; min-width: 60px; } table#album_table td#select { vertical-align: middle; text-align: left; } table#album_table td#albumart { vertical-align: middle; text-align: left; } table#album_table td#albumname { vertical-align: middle; text-align: center; } table#album_table td#reldate { vertical-align: middle; text-align: center; } table#album_table td#status { vertical-align: middle; text-align: center; } +table#album_table td#status a#wantlossless { white-space: nowrap; } table#album_table td#type { vertical-align: middle; text-align: center; } +table#album_table td#bitrate { vertical-align: middle; text-align: center; } +table#album_table td#albumformat { vertical-align: middle; text-align: center; } table#album_table td#have { vertical-align: middle; } img.albumArt { float: left; padding-right: 5px; } @@ -295,4 +300,4 @@ div#shutdown{ text-align: center; vertical-align: middle; } @page { margin: 0.5cm; } p, h2, h3 { orphans: 3; widows: 3; } h2, h3{ page-break-after: avoid; } -} \ No newline at end of file +} diff --git a/headphones/__init__.py b/headphones/__init__.py index 9ced7560..9abfbb7c 100644 --- a/headphones/__init__.py +++ b/headphones/__init__.py @@ -108,7 +108,9 @@ NEWZBIN_PASSWORD = None LASTFM_USERNAME = None -MEDIA_FORMATS = ["mp3", "flac", "aac", "ogg", "ape", "m4a"] +LOSSY_MEDIA_FORMATS = ["mp3", "aac", "ogg", "ape", "m4a"] +LOSSLESS_MEDIA_FORMATS = ["flac"] +MEDIA_FORMATS = LOSSY_MEDIA_FORMATS + LOSSLESS_MEDIA_FORMATS TORRENTBLACKHOLE_DIR = None NUMBEROFSEEDERS = 10 @@ -529,9 +531,9 @@ def dbcheck(): c=conn.cursor() c.execute('CREATE TABLE IF NOT EXISTS artists (ArtistID TEXT UNIQUE, ArtistName TEXT, ArtistSortName TEXT, DateAdded TEXT, Status TEXT, IncludeExtras INTEGER, LatestAlbum TEXT, ReleaseDate TEXT, AlbumID TEXT, HaveTracks INTEGER, TotalTracks INTEGER)') c.execute('CREATE TABLE IF NOT EXISTS albums (ArtistID TEXT, ArtistName TEXT, AlbumTitle TEXT, AlbumASIN TEXT, ReleaseDate TEXT, DateAdded TEXT, AlbumID TEXT UNIQUE, Status TEXT, Type TEXT)') - c.execute('CREATE TABLE IF NOT EXISTS tracks (ArtistID TEXT, ArtistName TEXT, AlbumTitle TEXT, AlbumASIN TEXT, AlbumID TEXT, TrackTitle TEXT, TrackDuration, TrackID TEXT, TrackNumber INTEGER, Location TEXT, BitRate INTEGER, CleanName TEXT)') + c.execute('CREATE TABLE IF NOT EXISTS tracks (ArtistID TEXT, ArtistName TEXT, AlbumTitle TEXT, AlbumASIN TEXT, AlbumID TEXT, TrackTitle TEXT, TrackDuration, TrackID TEXT, TrackNumber INTEGER, Location TEXT, BitRate INTEGER, CleanName TEXT, Format TEXT)') c.execute('CREATE TABLE IF NOT EXISTS snatched (AlbumID TEXT, Title TEXT, Size INTEGER, URL TEXT, DateAdded TEXT, Status TEXT, FolderName 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, Location TEXT, CleanName 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, Location TEXT, CleanName TEXT, Format TEXT)') 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 releases (ReleaseID TEXT, ReleaseGroupID TEXT, UNIQUE(ReleaseID, ReleaseGroupID))') @@ -608,6 +610,20 @@ def dbcheck(): except sqlite3.OperationalError: c.execute('ALTER TABLE have ADD COLUMN CleanName TEXT') + # Add the Format column + try: + c.execute('SELECT Format from have') + except sqlite3.OperationalError: + c.execute('ALTER TABLE have ADD COLUMN Format TEXT DEFAULT NULL') + + try: + c.execute('SELECT Format from tracks') + except sqlite3.OperationalError: + c.execute('ALTER TABLE tracks ADD COLUMN Format TEXT DEFAULT NULL') + + # Update the Format of files in library, this won't do anything if all files have a known format + threading.Thread(target=importer.updateFormat).start() + conn.commit() c.close() diff --git a/headphones/importer.py b/headphones/importer.py index ca8c8134..57473af4 100644 --- a/headphones/importer.py +++ b/headphones/importer.py @@ -184,15 +184,16 @@ def addArtisttoDB(artistid, extrasonly=False): "CleanName": cleanname } - match = myDB.action('SELECT Location, BitRate from have WHERE CleanName=?', [cleanname]).fetchone() + match = myDB.action('SELECT Location, BitRate, Format from have WHERE CleanName=?', [cleanname]).fetchone() if not match: - match = myDB.action('SELECT Location, BitRate from have WHERE ArtistName LIKE ? AND AlbumTitle LIKE ? AND TrackTitle LIKE ?', [artist['artist_name'], rg['title'], track['title']]).fetchone() + match = myDB.action('SELECT Location, BitRate, Format from have WHERE ArtistName LIKE ? AND AlbumTitle LIKE ? AND TrackTitle LIKE ?', [artist['artist_name'], rg['title'], track['title']]).fetchone() if not match: - match = myDB.action('SELECT Location, BitRate from have WHERE TrackID=?', [track['id']]).fetchone() + match = myDB.action('SELECT Location, BitRate, Format from have WHERE TrackID=?', [track['id']]).fetchone() if match: 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) @@ -310,17 +311,18 @@ def addReleaseById(rid): "CleanName": cleanname } - match = myDB.action('SELECT Location, BitRate from have WHERE CleanName=?', [cleanname]).fetchone() + match = myDB.action('SELECT Location, BitRate, Format from have WHERE CleanName=?', [cleanname]).fetchone() if not match: - match = myDB.action('SELECT Location, BitRate from have WHERE ArtistName LIKE ? AND AlbumTitle LIKE ? AND TrackTitle LIKE ?', [release_dict['artist_name'], release_dict['rg_title'], track['title']]).fetchone() + match = myDB.action('SELECT Location, BitRate, Format from have WHERE ArtistName LIKE ? AND AlbumTitle LIKE ? AND TrackTitle LIKE ?', [release_dict['artist_name'], release_dict['rg_title'], track['title']]).fetchone() if not match: - match = myDB.action('SELECT Location, BitRate from have WHERE TrackID=?', [track['id']]).fetchone() + match = myDB.action('SELECT Location, BitRate, Format from have WHERE TrackID=?', [track['id']]).fetchone() if match: 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) @@ -333,3 +335,32 @@ def addReleaseById(rid): return else: logger.info('Release ' + str(rid) + " already exists in the database!") + +def updateFormat(): + myDB = db.DBConnection() + tracks = myDB.select('SELECT * from tracks WHERE Location IS NOT NULL and Format IS NULL') + if len(tracks) > 0: + logger.info('Finding media format for %s files' % len(tracks)) + for track in tracks: + try: + f = MediaFile(track['Location']) + except Exception, e: + logger.info("Exception from MediaFile for: " + downloaded_track + " : " + str(e)) + continue + controlValueDict = {"TrackID": track['TrackID']} + newValueDict = {"Format": f.format} + myDB.upsert("tracks", newValueDict, controlValueDict) + logger.info('Finished finding media format for %s files' % len(tracks)) + havetracks = myDB.select('SELECT * from have WHERE Location IS NOT NULL and Format IS NULL') + if len(havetracks) > 0: + logger.info('Finding media format for %s files' % len(havetracks)) + for track in havetracks: + try: + f = MediaFile(track['Location']) + except Exception, e: + logger.info("Exception from MediaFile for: " + downloaded_track + " : " + str(e)) + continue + controlValueDict = {"TrackID": track['TrackID']} + newValueDict = {"Format": f.format} + myDB.upsert("have", newValueDict, controlValueDict) + logger.info('Finished finding media format for %s files' % len(havetracks)) diff --git a/headphones/librarysync.py b/headphones/librarysync.py index b585c8b6..be87a4ac 100644 --- a/headphones/librarysync.py +++ b/headphones/librarysync.py @@ -27,7 +27,7 @@ def libraryScan(dir=None): for track in tracks: if not os.path.isfile(track['Location'].encode(headphones.SYS_ENCODING)): - myDB.action('UPDATE tracks SET Location=?, BitRate=? WHERE TrackID=?', [None, None, track['TrackID']]) + myDB.action('UPDATE tracks SET Location=?, BitRate=?, Format=? WHERE TrackID=?', [None, None, None, track['TrackID']]) logger.info('Scanning music directory: %s' % dir) @@ -72,7 +72,7 @@ def libraryScan(dir=None): track = myDB.action('SELECT TrackID from tracks WHERE ArtistName LIKE ? AND AlbumTitle LIKE ? AND TrackTitle LIKE ?', [f_artist, f.album, f.title]).fetchone() if track: - myDB.action('UPDATE tracks SET Location=?, BitRate=? WHERE TrackID=?', [file, f.bitrate, track['TrackID']]) + myDB.action('UPDATE tracks SET Location=?, BitRate=?, Format=? WHERE TrackID=?', [file, f.bitrate, f.format, track['TrackID']]) continue # Try to match on mbid if available and we couldn't find a match based on metadata @@ -83,14 +83,14 @@ def libraryScan(dir=None): track = myDB.action('SELECT TrackID from tracks WHERE TrackID=?', [f.mb_trackid]).fetchone() if track: - myDB.action('UPDATE tracks SET Location=?, BitRate=? WHERE TrackID=?', [file, f.bitrate, track['TrackID']]) + myDB.action('UPDATE tracks SET Location=?, BitRate=?, Format=? WHERE TrackID=?', [file, f.bitrate, f.format, track['TrackID']]) continue # if we can't find a match in the database on a track level, it might be a new artist or it might be on a non-mb release new_artists.append(f_artist) # The have table will become the new database for unmatched tracks (i.e. tracks with no associated links in the database - myDB.action('INSERT INTO have VALUES( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', [f_artist, f.album, f.track, f.title, f.length, f.bitrate, f.genre, f.date, f.mb_trackid, file, helpers.cleanName(f_artist+' '+f.album+' '+f.title)]) + myDB.action('INSERT INTO have (ArtistName, AlbumTitle, TrackNumber, TrackTitle, TrackLength, BitRate, Genre, Date, TrackID, Location, CleanName, Format) VALUES( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', [f_artist, f.album, f.track, f.title, f.length, f.bitrate, f.genre, f.date, f.mb_trackid, file, helpers.cleanName(f_artist+' '+f.album+' '+f.title), f.format]) logger.info('Completed scanning of directory: %s' % dir) logger.info('Checking filepaths to see if we can find any matches') @@ -169,7 +169,7 @@ def libraryScan(dir=None): f = MediaFile(match[0]) f.mb_trackid = track['TrackID'] f.save() - myDB.action('UPDATE tracks SET BitRate=? WHERE TrackID=?', [f.bitrate, track['TrackID']]) + myDB.action('UPDATE tracks SET BitRate=?, Format=? WHERE TrackID=?', [f.bitrate, f.format, track['TrackID']]) logger.debug('Wrote mbid to track: %s' % match[0]) @@ -204,4 +204,4 @@ def libraryScan(dir=None): headphones.NEW_ARTISTS = artist_list if headphones.DETECT_BITRATE: - headphones.PREFERRED_BITRATE = sum(bitrates)/len(bitrates)/1000 \ No newline at end of file + headphones.PREFERRED_BITRATE = sum(bitrates)/len(bitrates)/1000 diff --git a/headphones/postprocessor.py b/headphones/postprocessor.py index 16de4967..3eb29a05 100644 --- a/headphones/postprocessor.py +++ b/headphones/postprocessor.py @@ -509,7 +509,7 @@ def updateHave(albumpath): else: continue - myDB.action('UPDATE tracks SET Location=?, BitRate=? WHERE ArtistName LIKE ? AND AlbumTitle LIKE ? AND TrackTitle LIKE ?', [unicode(song, headphones.SYS_ENCODING, errors="replace"), f.bitrate, artist, f.album, f.title]) + myDB.action('UPDATE tracks SET Location=?, BitRate=?, Format=? WHERE ArtistName LIKE ? AND AlbumTitle LIKE ? AND TrackTitle LIKE ?', [unicode(song, headphones.SYS_ENCODING, errors="replace"), f.bitrate, f.format, artist, f.album, f.title]) def renameUnprocessedFolder(albumpath): diff --git a/headphones/searcher.py b/headphones/searcher.py index e8b1289b..15113714 100644 --- a/headphones/searcher.py +++ b/headphones/searcher.py @@ -62,40 +62,46 @@ def url_fix(s, charset='utf-8'): return urlparse.urlunsplit((scheme, netloc, path, qs, anchor)) -def searchforalbum(albumid=None, new=False): +def searchforalbum(albumid=None, new=False, lossless=False): if not albumid: myDB = db.DBConnection() - results = myDB.select('SELECT AlbumID from albums WHERE Status="Wanted"') + results = myDB.select('SELECT AlbumID, Status from albums WHERE Status="Wanted" OR Status="Wanted Lossless"') new = True for result in results: foundNZB = "none" if (headphones.NZBMATRIX or headphones.NEWZNAB or headphones.NZBSORG or headphones.NEWZBIN) and (headphones.SAB_HOST or headphones.BLACKHOLE): - foundNZB = searchNZB(result['AlbumID'], new) + if result['Status'] == "Wanted Lossless": + foundNZB = searchNZB(result['AlbumID'], new, losslessOnly=True) + else: + foundNZB = searchNZB(result['AlbumID'], new) if (headphones.KAT or headphones.ISOHUNT or headphones.MININOVA) and foundNZB == "none": - searchTorrent(result['AlbumID'], new) + if result['Status'] == "Wanted Lossless": + searchTorrent(result['AlbumID'], new, losslessOnly=True) + else: + searchTorrent(result['AlbumID'], new) else: foundNZB = "none" if (headphones.NZBMATRIX or headphones.NEWZNAB or headphones.NZBSORG or headphones.NEWZBIN) and (headphones.SAB_HOST or headphones.BLACKHOLE): - foundNZB = searchNZB(albumid, new) + foundNZB = searchNZB(albumid, new, lossless) if (headphones.KAT or headphones.ISOHUNT or headphones.MININOVA) and foundNZB == "none": - searchTorrent(albumid, new) + searchTorrent(albumid, new, lossless) -def searchNZB(albumid=None, new=False): +def searchNZB(albumid=None, new=False, losslessOnly=False): myDB = db.DBConnection() if albumid: - results = myDB.select('SELECT ArtistName, AlbumTitle, AlbumID, ReleaseDate from albums WHERE Status="Wanted" AND AlbumID=?', [albumid]) + results = myDB.select('SELECT ArtistName, AlbumTitle, AlbumID, ReleaseDate from albums WHERE AlbumID=?', [albumid]) else: - results = myDB.select('SELECT ArtistName, AlbumTitle, AlbumID, ReleaseDate from albums WHERE Status="Wanted"') + results = myDB.select('SELECT ArtistName, AlbumTitle, AlbumID, ReleaseDate from albums WHERE Status="Wanted" OR Status="Wanted Lossless"') new = True for albums in results: @@ -133,7 +139,7 @@ def searchNZB(albumid=None, new=False): if headphones.NZBMATRIX: provider = "nzbmatrix" - if headphones.PREFERRED_QUALITY == 3: + if headphones.PREFERRED_QUALITY == 3 or losslessOnly: categories = "23" maxsize = 10000000000 elif headphones.PREFERRED_QUALITY: @@ -183,7 +189,7 @@ def searchNZB(albumid=None, new=False): if headphones.NEWZNAB: provider = "newznab" - if headphones.PREFERRED_QUALITY == 3: + if headphones.PREFERRED_QUALITY == 3 or losslessOnly: categories = "3040" maxsize = 10000000000 elif headphones.PREFERRED_QUALITY: @@ -235,7 +241,7 @@ def searchNZB(albumid=None, new=False): if headphones.NZBSORG: provider = "nzbsorg" - if headphones.PREFERRED_QUALITY == 3: + if headphones.PREFERRED_QUALITY == 3 or losslessOnly: categories = "31" maxsize = 10000000000 elif headphones.PREFERRED_QUALITY: @@ -301,7 +307,7 @@ def searchNZB(albumid=None, new=False): if headphones.NEWZBIN: provider = "newzbin" providerurl = "https://www.newzbin.com/" - if headphones.PREFERRED_QUALITY == 3: + if headphones.PREFERRED_QUALITY == 3 or losslessOnly: categories = "7" #music format = "2" #flac maxsize = 10000000000 @@ -560,14 +566,14 @@ def preprocess(resultlist): -def searchTorrent(albumid=None, new=False): +def searchTorrent(albumid=None, new=False, losslessOnly=False): myDB = db.DBConnection() if albumid: - results = myDB.select('SELECT ArtistName, AlbumTitle, AlbumID, ReleaseDate from albums WHERE Status="Wanted" AND AlbumID=?', [albumid]) + results = myDB.select('SELECT ArtistName, AlbumTitle, AlbumID, ReleaseDate from albums WHERE AlbumID=?', [albumid]) else: - results = myDB.select('SELECT ArtistName, AlbumTitle, AlbumID, ReleaseDate from albums WHERE Status="Wanted"') + results = myDB.select('SELECT ArtistName, AlbumTitle, AlbumID, ReleaseDate from albums WHERE Status="Wanted" OR Status="Wanted Lossless"') new = True for albums in results: @@ -607,7 +613,7 @@ def searchTorrent(albumid=None, new=False): if headphones.KAT: provider = "Kick Ass Torrent" providerurl = url_fix("http://www.kat.ph/search/" + term) - if headphones.PREFERRED_QUALITY == 3: + if headphones.PREFERRED_QUALITY == 3 or losslessOnly: categories = "7" #music format = "2" #flac maxsize = 10000000000 @@ -668,7 +674,7 @@ def searchTorrent(albumid=None, new=False): resultlist.append((title, size, url, provider)) logger.info('Found %s. Size: %s' % (title, helpers.bytes_to_mb(size))) else: - logger.info('%s is larger than the maxsize, the wrong format or has to little seeders for this category, skipping. (Size: %i bytes)' % (title, size)) + logger.info('%s is larger than the maxsize, the wrong format or has to little seeders for this category, skipping. (Size: %i bytes, Seeders: %i, Format: %s)' % (title, size, int(seeders), rightformat)) except Exception, e: logger.error(u"An unknown error occured trying to parse the feed: %s" % e) @@ -677,7 +683,7 @@ def searchTorrent(albumid=None, new=False): if headphones.ISOHUNT: provider = "ISOhunt" providerurl = url_fix("http://isohunt.com/js/rss/" + term) - if headphones.PREFERRED_QUALITY == 3: + if headphones.PREFERRED_QUALITY == 3 or losslessOnly: categories = "7" #music format = "2" #flac maxsize = 10000000000 @@ -741,7 +747,7 @@ def searchTorrent(albumid=None, new=False): resultlist.append((title, size, url, provider)) logger.info('Found %s. Size: %s' % (title, helpers.bytes_to_mb(size))) else: - logger.info('%s is larger than the maxsize, the wrong format or has to little seeders for this category, skipping. (Size: %i bytes)' % (title, size)) + logger.info('%s is larger than the maxsize, the wrong format or has to little seeders for this category, skipping. (Size: %i bytes, Seeders: %i, Format: %s)' % (title, size, int(seeders), rightformat)) except Exception, e: logger.error(u"An unknown error occured trying to parse the feed: %s" % e) @@ -749,7 +755,7 @@ def searchTorrent(albumid=None, new=False): if headphones.MININOVA: provider = "Mininova" providerurl = url_fix("http://www.mininova.org/rss/" + term + "/5") - if headphones.PREFERRED_QUALITY == 3: + if headphones.PREFERRED_QUALITY == 3 or losslessOnly: categories = "7" #music format = "2" #flac maxsize = 10000000000 @@ -808,7 +814,7 @@ def searchTorrent(albumid=None, new=False): resultlist.append((title, size, url, provider)) logger.info('Found %s. Size: %s' % (title, helpers.bytes_to_mb(size))) else: - logger.info('%s is larger than the maxsize, the wrong format or has to little seeders for this category, skipping. (Size: %i bytes)' % (title, size)) + logger.info('%s is larger than the maxsize, the wrong format or has to little seeders for this category, skipping. (Size: %i bytes, Seeders: %i, Format: %s)' % (title, size, int(seeders), rightformat)) except Exception, e: logger.error(u"An unknown error occured trying to parse the feed: %s" % e) diff --git a/headphones/webserve.py b/headphones/webserve.py index c9386c64..af058ac7 100644 --- a/headphones/webserve.py +++ b/headphones/webserve.py @@ -156,11 +156,15 @@ class WebInterface(object): raise cherrypy.HTTPRedirect("home") addArtists.exposed = True - def queueAlbum(self, AlbumID, ArtistID=None, new=False, redirect=None): - logger.info(u"Marking album: " + AlbumID + "as wanted...") + def queueAlbum(self, AlbumID, ArtistID=None, new=False, redirect=None, lossless=False): + logger.info(u"Marking album: " + AlbumID + " as wanted...") myDB = db.DBConnection() controlValueDict = {'AlbumID': AlbumID} - newValueDict = {'Status': 'Wanted'} + if lossless: + newValueDict = {'Status': 'Wanted Lossless'} + logger.info("...lossless only!") + else: + newValueDict = {'Status': 'Wanted'} myDB.upsert("albums", newValueDict, controlValueDict) searcher.searchforalbum(AlbumID, new) if ArtistID: