diff --git a/data/interfaces/default/artist.html b/data/interfaces/default/artist.html index 01e43f68..a19b1146 100644 --- a/data/interfaces/default/artist.html +++ b/data/interfaces/default/artist.html @@ -70,6 +70,7 @@ Name Date Type + Score Status Have Bitrate @@ -125,6 +126,7 @@ ${album['AlbumTitle']} ${album['ReleaseDate']} ${album['Type']} + ${album['CriticScore']}/${album['UserScore']} ${album['Status']} %if album['Status'] == 'Skipped' or album['Status'] == 'Ignored': [want] @@ -218,7 +220,7 @@ $("li:gt(4)", this).hide(); /* :gt() is zero-indexed */ $("li:nth-child(5)", this).after("
  • More...
  • "); /* :nth-child() is one-indexed */ }); - $("li.more a").live("click", function() { + $("li.more").on("click", 'a', function() { var li = $(this).parents("li:first"); li.parent().children().show(); li.remove(); @@ -283,6 +285,7 @@ { "sType": "date" }, null, null, + null, { "sType": "title-numeric"}, null, null diff --git a/headphones/__init__.py b/headphones/__init__.py index 349416b8..a3c359e6 100644 --- a/headphones/__init__.py +++ b/headphones/__init__.py @@ -357,7 +357,7 @@ def dbcheck(): # 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)') + '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, CriticScore TEXT, UserScore TEXT)') # Format here means mp3, flac, etc. 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)') @@ -583,6 +583,16 @@ def dbcheck(): except sqlite3.OperationalError: c.execute('ALTER TABLE albums ADD COLUMN SearchTerm TEXT DEFAULT NULL') + try: + c.execute('SELECT CriticScore from albums') + except sqlite3.OperationalError: + c.execute('ALTER TABLE albums ADD COLUMN CriticScore TEXT DEFAULT NULL') + + try: + c.execute('SELECT UserScore from albums') + except sqlite3.OperationalError: + c.execute('ALTER TABLE albums ADD COLUMN UserScore TEXT DEFAULT NULL') + conn.commit() c.close() diff --git a/headphones/importer.py b/headphones/importer.py index c02f508f..16e5efac 100644 --- a/headphones/importer.py +++ b/headphones/importer.py @@ -13,7 +13,7 @@ # You should have received a copy of the GNU General Public License # along with Headphones. If not, see . -from headphones import logger, helpers, db, mb, lastfm +from headphones import logger, helpers, db, mb, lastfm, metacritic from beets.mediafile import MediaFile @@ -488,6 +488,9 @@ def addArtisttoDB(artistid, extrasonly=False, forcefull=False): logger.info(u"Seeing if we need album art for: %s" % artist['artist_name']) cache.getThumb(ArtistID=artistid) + logger.info(u"Fetching Metacritic reviews for: %s" % artist['artist_name']) + metacritic.update(artist['artist_name'], artist['releasegroups']) + 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: diff --git a/headphones/metacritic.py b/headphones/metacritic.py new file mode 100644 index 00000000..5df3d601 --- /dev/null +++ b/headphones/metacritic.py @@ -0,0 +1,59 @@ +# This file is part of Headphones. +# +# Headphones is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Headphones is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Headphones. If not, see . + +import re +import headphones + +from headphones import db, helpers, logger, request + +def update(artist_name,release_groups): + """ Pretty simple and crude function to find the artist page on metacritic, + then parse that page to get critic & user scores for albums""" + + # First let's modify the artist name to fit the metacritic convention. + # We could just do a search, then take the top result, but at least this will + # cut down on api calls. If it's ineffective then we'll switch to search + + replacements = {" & " : " "} + pattern = re.compile(r'\b(' + '|'.join(replacements.keys()) + r')\b') + mc_artist_name = pattern.sub(lambda x: replacements[x.group()], artist_name) + + mc_artist_name = artist_name.lower().replace(" ","-") + + url = "http://www.metacritic.com/person/" + mc_artist_name + "?filter-options=music&sort_options=date&num_items=100" + + res = request.request_soup(url, parser='html.parser') + + try: + rows = res.tbody.find_all('tr') + except: + logger.info("Unable to get metacritic scores for: %s" % artist_name) + return + + myDB = db.DBConnection() + + for row in rows: + title = row.a.string + for rg in release_groups: + if rg['title'].lower() == title.lower(): + scores = row.find_all("span") + critic_score = scores[0].string + user_score = scores[1].string + controlValueDict = {"AlbumID": rg['id']} + newValueDict = {'CriticScore':critic_score,'UserScore':user_score} + myDB.upsert("albums", newValueDict, controlValueDict) + + +