diff --git a/data/interfaces/default/album.html b/data/interfaces/default/album.html index 4da9323a..bec42cfb 100644 --- a/data/interfaces/default/album.html +++ b/data/interfaces/default/album.html @@ -41,6 +41,23 @@ %endfor %endif + + Edit Search Term + @@ -162,6 +179,10 @@ $('#dialog').dialog({ width: "500px" }); return false; }); + $('#edit_search_term').click(function() { + $('#dialog2').dialog({ width: "500px" }); + return false; + }); $('#refresh_artist').click(function() { $('#dialog').dialog("close"); }); diff --git a/headphones/__init__.py b/headphones/__init__.py index 8ea2597d..3f91e105 100644 --- a/headphones/__init__.py +++ b/headphones/__init__.py @@ -829,7 +829,7 @@ def dbcheck(): conn=sqlite3.connect(DB_FILE) 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, LastUpdated TEXT, ArtworkURL TEXT, ThumbURL TEXT, Extras TEXT)') - 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, ArtworkURL TEXT, ThumbURL TEXT, ReleaseID TEXT, ReleaseCountry TEXT, ReleaseFormat TEXT)') # ReleaseFormat here means CD,Digital,Vinyl, etc. If using the default Headphones hybrid release, ReleaseID will equal AlbumID (AlbumID is releasegroup id) + 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, ArtworkURL TEXT, ThumbURL TEXT, ReleaseID TEXT, ReleaseCountry TEXT, ReleaseFormat TEXT, SearchTerm TEXT)') # ReleaseFormat here means CD,Digital,Vinyl, etc. If using the default Headphones hybrid release, ReleaseID will equal AlbumID (AlbumID is releasegroup id) 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, ReleaseID TEXT)') # Format here means mp3, flac, etc. c.execute('CREATE TABLE IF NOT EXISTS allalbums (ArtistID TEXT, ArtistName TEXT, AlbumTitle TEXT, AlbumASIN TEXT, ReleaseDate TEXT, AlbumID TEXT, Type TEXT, ReleaseID TEXT, ReleaseCountry TEXT, ReleaseFormat TEXT)') c.execute('CREATE TABLE IF NOT EXISTS alltracks (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, ReleaseID TEXT)') @@ -1001,6 +1001,11 @@ def dbcheck(): c.execute('SELECT Kind from snatched') except sqlite3.OperationalError: c.execute('ALTER TABLE snatched ADD COLUMN Kind TEXT DEFAULT NULL') + + try: + c.execute('SELECT SearchTerm from albums') + except sqlite3.OperationalError: + c.execute('ALTER TABLE albums ADD COLUMN SearchTerm TEXT DEFAULT NULL') conn.commit() c.close() diff --git a/headphones/searcher.py b/headphones/searcher.py index 01ee5de7..e0054440 100644 --- a/headphones/searcher.py +++ b/headphones/searcher.py @@ -135,9 +135,9 @@ def searchNZB(albumid=None, new=False, losslessOnly=False): myDB = db.DBConnection() if albumid: - results = myDB.select('SELECT ArtistName, AlbumTitle, AlbumID, ReleaseDate, Type from albums WHERE AlbumID=?', [albumid]) + results = myDB.select('SELECT ArtistName, AlbumTitle, AlbumID, ReleaseDate, Type, SearchTerm from albums WHERE AlbumID=?', [albumid]) else: - results = myDB.select('SELECT ArtistName, AlbumTitle, AlbumID, ReleaseDate, Type from albums WHERE Status="Wanted" OR Status="Wanted Lossless"') + results = myDB.select('SELECT ArtistName, AlbumTitle, AlbumID, ReleaseDate, Type, SearchTerm from albums WHERE Status="Wanted" OR Status="Wanted Lossless"') new = True for albums in results: @@ -154,19 +154,25 @@ def searchNZB(albumid=None, new=False, losslessOnly=False): cleanalbum = helpers.latinToAscii(helpers.replace_all(albums[1], dic)) cleanartist = helpers.latinToAscii(helpers.replace_all(albums[0], dic)) - - # FLAC usually doesn't have a year for some reason so I'll leave it out - # Various Artist albums might be listed as VA, so I'll leave that out too - # Only use the year if the term could return a bunch of different albums, i.e. self-titled albums - if albums[0] in albums[1] or len(albums[0]) < 4 or len(albums[1]) < 4: - term = cleanartist + ' ' + cleanalbum + ' ' + year - elif albums[0] == 'Various Artists': - term = cleanalbum + ' ' + year + + # Use the provided search term if available, otherwise build a search term + if albums[5]: + term = albums[5] + else: - term = cleanartist + ' ' + cleanalbum + # FLAC usually doesn't have a year for some reason so I'll leave it out + # Various Artist albums might be listed as VA, so I'll leave that out too + # Only use the year if the term could return a bunch of different albums, i.e. self-titled albums + if albums[0] in albums[1] or len(albums[0]) < 4 or len(albums[1]) < 4: + term = cleanartist + ' ' + cleanalbum + ' ' + year + elif albums[0] == 'Various Artists': + term = cleanalbum + ' ' + year + else: + term = cleanartist + ' ' + cleanalbum # Replace bad characters in the term and unicode it term = re.sub('[\.\-\/]', ' ', term).encode('utf-8') + artistterm = re.sub('[\.\-\/]', ' ', cleanartist).encode('utf-8') logger.info("Searching for %s since it was marked as wanted" % term) @@ -740,9 +746,9 @@ def searchTorrent(albumid=None, new=False, losslessOnly=False): myDB = db.DBConnection() if albumid: - results = myDB.select('SELECT ArtistName, AlbumTitle, AlbumID, ReleaseDate from albums WHERE AlbumID=?', [albumid]) + results = myDB.select('SELECT ArtistName, AlbumTitle, AlbumID, ReleaseDate, SearchTerm from albums WHERE AlbumID=?', [albumid]) else: - results = myDB.select('SELECT ArtistName, AlbumTitle, AlbumID, ReleaseDate from albums WHERE Status="Wanted" OR Status="Wanted Lossless"') + results = myDB.select('SELECT ArtistName, AlbumTitle, AlbumID, ReleaseDate, SearchTerm from albums WHERE Status="Wanted" OR Status="Wanted Lossless"') new = True # rutracker login @@ -768,16 +774,22 @@ def searchTorrent(albumid=None, new=False, losslessOnly=False): cleanalbum = helpers.latinToAscii(semi_cleanalbum) semi_cleanartist = helpers.replace_all(albums[0], dic) cleanartist = helpers.latinToAscii(semi_cleanartist) - - # FLAC usually doesn't have a year for some reason so I'll leave it out - # Various Artist albums might be listed as VA, so I'll leave that out too - # Only use the year if the term could return a bunch of different albums, i.e. self-titled albums - if albums[0] in albums[1] or len(albums[0]) < 4 or len(albums[1]) < 4: - term = cleanartist + ' ' + cleanalbum + ' ' + year - elif albums[0] == 'Various Artists': - term = cleanalbum + ' ' + year + + # Use provided term if available, otherwise build our own (this code needs to be cleaned up since a lot + # of these torrent providers are just using cleanartist/cleanalbum terms + if albums[4]: + term = albums[4] + else: - term = cleanartist + ' ' + cleanalbum + # FLAC usually doesn't have a year for some reason so I'll leave it out + # Various Artist albums might be listed as VA, so I'll leave that out too + # Only use the year if the term could return a bunch of different albums, i.e. self-titled albums + if albums[0] in albums[1] or len(albums[0]) < 4 or len(albums[1]) < 4: + term = cleanartist + ' ' + cleanalbum + ' ' + year + elif albums[0] == 'Various Artists': + term = cleanalbum + ' ' + year + else: + term = cleanartist + ' ' + cleanalbum semi_clean_artist_term = re.sub('[\.\-\/]', ' ', semi_cleanartist).encode('utf-8', 'replace') semi_clean_album_term = re.sub('[\.\-\/]', ' ', semi_cleanalbum).encode('utf-8', 'replace') diff --git a/headphones/webserve.py b/headphones/webserve.py index f3af617d..4e9f3cdb 100644 --- a/headphones/webserve.py +++ b/headphones/webserve.py @@ -286,6 +286,15 @@ class WebInterface(object): albumswitcher.switch(AlbumID, ReleaseID) raise cherrypy.HTTPRedirect("albumPage?AlbumID=%s" % AlbumID) switchAlbum.exposed = True + + def editSearchTerm(self, AlbumID, SearchTerm): + logger.info(u"Updating search term for albumid: " + AlbumID) + myDB = db.DBConnection() + controlValueDict = {'AlbumID': AlbumID} + newValueDict = {'SearchTerm': SearchTerm} + myDB.upsert("albums", newValueDict, controlValueDict) + raise cherrypy.HTTPRedirect("albumPage?AlbumID=%s" % AlbumID) + editSearchTerm.exposed = True def upcoming(self): myDB = db.DBConnection()