Chart cleanup

This commit is contained in:
Ruud
2014-05-06 15:39:41 +02:00
parent 0284fa9b0a
commit 7e4bc29b59
2 changed files with 57 additions and 40 deletions
@@ -78,7 +78,7 @@ MA.IMDB = new Class({
create: function(){ create: function(){
var self = this; var self = this;
self.id = self.movie.getIdentifier(); self.id = self.movie.getIdentifier ? self.movie.getIdentifier() : self.get('imdb');
self.el = new Element('a.imdb', { self.el = new Element('a.imdb', {
'title': 'Go to the IMDB page of ' + self.getTitle(), 'title': 'Go to the IMDB page of ' + self.getTitle(),
@@ -100,23 +100,28 @@ class IMDBAutomation(IMDBBase):
enabled_option = 'automation_providers_enabled' enabled_option = 'automation_providers_enabled'
chart_urls = { charts = {
'theater': 'http://www.imdb.com/movies-in-theaters/', 'theater': {
'top250': 'http://www.imdb.com/chart/top', 'order': 1,
'boxoffice': 'http://www.imdb.com/chart/', 'name': 'IMDB - Movies in Theaters',
'rentals': 'http://www.imdb.com/boxoffice/rentals', 'url': 'http://www.imdb.com/movies-in-theaters/',
} },
chart_names = { 'boxoffice': {
'theater': 'IMDB - Movies in Theaters', 'order': 2,
'top250': 'IMDB - Top 250 Movies', 'name': 'IMDB - Box Office',
'boxoffice': 'IMDB - Box Office', 'url': 'http://www.imdb.com/chart/',
'rentals': 'IMDB - Top DVD rentals', },
} 'rentals': {
chart_order = { 'order': 3,
'theater': 2, 'name': 'IMDB - Top DVD rentals',
'top250': 5, 'url': 'http://m.imdb.com/boxoffice_json',
'boxoffice': 3, 'type': 'json',
'rentals': 4, },
'top250': {
'order': 4,
'name': 'IMDB - Top 250 Movies',
'url': 'http://www.imdb.com/chart/top',
},
} }
first_table = ['boxoffice'] first_table = ['boxoffice']
@@ -125,23 +130,30 @@ class IMDBAutomation(IMDBBase):
movies = [] movies = []
for url in self.chart_urls: for name in self.charts:
if self.conf('automation_charts_%s' % url): chart = self.charts[name]
data = self.getHTMLData(self.chart_urls[url]) url = chart.get('url')
if self.conf('automation_charts_%s' % name):
data = self.getHTMLData(url)
if data: if data:
html = BeautifulSoup(data)
try: try:
result_div = html.find('div', attrs = {'id': 'main'})
try: if chart.get('type', 'html') == 'html':
if url in self.first_table: result_div = html.find('table')
table = result_div.find('table')
result_div = table if table else result_div
except:
pass
imdb_ids = getImdb(str(result_div), multiple = True) try:
if url in self.first_table:
table = result_div.find('table')
result_div = table if table else result_div
except:
pass
imdb_ids = getImdb(str(result_div), multiple = True)
else:
imdb_ids = getImdb(str(data), multiple = True)
for imdb_id in imdb_ids: for imdb_id in imdb_ids:
info = self.getInfo(imdb_id) info = self.getInfo(imdb_id)
@@ -158,14 +170,19 @@ class IMDBAutomation(IMDBBase):
def getChartList(self): def getChartList(self):
# Nearly identical to 'getIMDBids', but we don't care about minimalMovie and return all movie data (not just id) # Nearly identical to 'getIMDBids', but we don't care about minimalMovie and return all movie data (not just id)
movie_lists = [] movie_lists = []
max_items = int(self.conf('max_items', section='charts', default=5)) max_items = int(self.conf('max_items', section = 'charts', default=5))
for url in self.chart_urls: for name in self.charts:
if self.conf('chart_display_%s' % url): chart = self.charts[name].copy()
movie_list = {'name': self.chart_names[url], 'url': self.chart_urls[url], 'order': self.chart_order[url], 'list': []}
data = self.getHTMLData(self.chart_urls[url]) if self.conf('chart_display_%s' % name):
chart['list'] = []
data = self.getHTMLData(chart.get('url'))
if data: if data:
html = BeautifulSoup(data) html = BeautifulSoup(data)
@@ -173,7 +190,7 @@ class IMDBAutomation(IMDBBase):
result_div = html.find('div', attrs = {'id': 'main'}) result_div = html.find('div', attrs = {'id': 'main'})
try: try:
if url in self.first_table: if chart.get('url') in self.first_table:
table = result_div.find('table') table = result_div.find('table')
result_div = table if table else result_div result_div = table if table else result_div
except: except:
@@ -183,15 +200,15 @@ class IMDBAutomation(IMDBBase):
for imdb_id in imdb_ids[0:max_items]: for imdb_id in imdb_ids[0:max_items]:
info = self.getInfo(imdb_id) info = self.getInfo(imdb_id)
movie_list['list'].append(info) chart['list'].append(info)
if self.shuttingDown(): if self.shuttingDown():
break break
except: except:
log.error('Failed loading IMDB chart results from %s: %s', (url, traceback.format_exc())) log.error('Failed loading IMDB chart results from %s: %s', (chart.get('url'), traceback.format_exc()))
if movie_list['list']: if chart['list']:
movie_lists.append(movie_list) movie_lists.append(chart)
return movie_lists return movie_lists