From b59a0f82ab631159919668568a05f3908ca3c288 Mon Sep 17 00:00:00 2001 From: mano3m Date: Sat, 19 Apr 2014 21:12:38 +0200 Subject: [PATCH 1/3] Add IMDB rentals list to charts This should add the IMDB rentals list to the charts and imdb automation. This is actually a nice list as you can download the movies right away instead of waiting until they release like with the rest of the imdb charts. The problem is that this does not work. And frankly I gave up. When I type this in my python command window it works: ''' from bs4 import BeautifulSoup import urllib2 data = urllib2.urlopen('http://www.imdb.com/boxoffice/rentals') html = BeautifulSoup(data) result_div = html.find('div', attrs = {'id': 'main'}) ''' Then result_div contains the list of movies. In the code from this PR result_div becomes None....?!?!?! @Ruudburger please help before I jump off my building ;) --- .../media/movie/providers/automation/imdb.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/couchpotato/core/media/movie/providers/automation/imdb.py b/couchpotato/core/media/movie/providers/automation/imdb.py index 0f2e2940..c0c2de88 100644 --- a/couchpotato/core/media/movie/providers/automation/imdb.py +++ b/couchpotato/core/media/movie/providers/automation/imdb.py @@ -104,16 +104,19 @@ class IMDBAutomation(IMDBBase): 'theater': 'http://www.imdb.com/movies-in-theaters/', 'top250': 'http://www.imdb.com/chart/top', 'boxoffice': 'http://www.imdb.com/chart/', + 'rentals': 'http://www.imdb.com/boxoffice/rentals', } chart_names = { 'theater': 'IMDB - Movies in Theaters', 'top250': 'IMDB - Top 250 Movies', 'boxoffice': 'IMDB - Box Office', + 'rentals': 'IMDB - Top DVD rentals', } chart_order = { 'theater': 2, - 'top250': 4, + 'top250': 5, 'boxoffice': 3, + 'rentals': 4, } first_table = ['boxoffice'] @@ -240,6 +243,13 @@ config = [{ 'description': 'New Movies In-Theaters chart', 'default': True, }, + { + 'name': 'automation_charts_rentals', + 'type': 'bool', + 'label': 'DVD Rentals', + 'description': 'Top DVD rentals chart', + 'default': True, + }, { 'name': 'automation_charts_top250', 'type': 'bool', @@ -282,6 +292,13 @@ config = [{ 'description': 'IMDB TOP 250 chart', 'default': False, }, + { + 'name': 'chart_display_rentals', + 'type': 'bool', + 'label': 'DVD Rentals', + 'description': 'Top DVD rentals chart', + 'default': True, + }, { 'name': 'chart_display_boxoffice', 'type': 'bool', From 0284fa9b0a11da37276734e0809ee16de1a77a0d Mon Sep 17 00:00:00 2001 From: Ruud Date: Tue, 6 May 2014 14:31:24 +0200 Subject: [PATCH 2/3] Load correct beautifulsoup module --- .../core/media/movie/providers/userscript/filmstarts.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/couchpotato/core/media/movie/providers/userscript/filmstarts.py b/couchpotato/core/media/movie/providers/userscript/filmstarts.py index 1e35be27..59027e03 100644 --- a/couchpotato/core/media/movie/providers/userscript/filmstarts.py +++ b/couchpotato/core/media/movie/providers/userscript/filmstarts.py @@ -1,8 +1,9 @@ -from BeautifulSoup import BeautifulSoup +from bs4 import BeautifulSoup from couchpotato.core.media._base.providers.userscript.base import UserscriptBase autoload = 'Filmstarts' + class Filmstarts(UserscriptBase): includes = ['*://www.filmstarts.de/kritiken/*'] From 7e4bc29b599f0ea25f88109da1766c73ef0103e0 Mon Sep 17 00:00:00 2001 From: Ruud Date: Tue, 6 May 2014 15:39:41 +0200 Subject: [PATCH 3/3] Chart cleanup --- .../media/movie/_base/static/movie.actions.js | 2 +- .../media/movie/providers/automation/imdb.py | 95 +++++++++++-------- 2 files changed, 57 insertions(+), 40 deletions(-) diff --git a/couchpotato/core/media/movie/_base/static/movie.actions.js b/couchpotato/core/media/movie/_base/static/movie.actions.js index 8ac3fe03..26ee2421 100644 --- a/couchpotato/core/media/movie/_base/static/movie.actions.js +++ b/couchpotato/core/media/movie/_base/static/movie.actions.js @@ -78,7 +78,7 @@ MA.IMDB = new Class({ create: function(){ 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', { 'title': 'Go to the IMDB page of ' + self.getTitle(), diff --git a/couchpotato/core/media/movie/providers/automation/imdb.py b/couchpotato/core/media/movie/providers/automation/imdb.py index c0c2de88..092c2718 100644 --- a/couchpotato/core/media/movie/providers/automation/imdb.py +++ b/couchpotato/core/media/movie/providers/automation/imdb.py @@ -100,23 +100,28 @@ class IMDBAutomation(IMDBBase): enabled_option = 'automation_providers_enabled' - chart_urls = { - 'theater': 'http://www.imdb.com/movies-in-theaters/', - 'top250': 'http://www.imdb.com/chart/top', - 'boxoffice': 'http://www.imdb.com/chart/', - 'rentals': 'http://www.imdb.com/boxoffice/rentals', - } - chart_names = { - 'theater': 'IMDB - Movies in Theaters', - 'top250': 'IMDB - Top 250 Movies', - 'boxoffice': 'IMDB - Box Office', - 'rentals': 'IMDB - Top DVD rentals', - } - chart_order = { - 'theater': 2, - 'top250': 5, - 'boxoffice': 3, - 'rentals': 4, + charts = { + 'theater': { + 'order': 1, + 'name': 'IMDB - Movies in Theaters', + 'url': 'http://www.imdb.com/movies-in-theaters/', + }, + 'boxoffice': { + 'order': 2, + 'name': 'IMDB - Box Office', + 'url': 'http://www.imdb.com/chart/', + }, + 'rentals': { + 'order': 3, + 'name': 'IMDB - Top DVD rentals', + 'url': 'http://m.imdb.com/boxoffice_json', + 'type': 'json', + }, + 'top250': { + 'order': 4, + 'name': 'IMDB - Top 250 Movies', + 'url': 'http://www.imdb.com/chart/top', + }, } first_table = ['boxoffice'] @@ -125,23 +130,30 @@ class IMDBAutomation(IMDBBase): movies = [] - for url in self.chart_urls: - if self.conf('automation_charts_%s' % url): - data = self.getHTMLData(self.chart_urls[url]) + for name in self.charts: + chart = self.charts[name] + url = chart.get('url') + + if self.conf('automation_charts_%s' % name): + data = self.getHTMLData(url) + if data: - html = BeautifulSoup(data) try: - result_div = html.find('div', attrs = {'id': 'main'}) - try: - if url in self.first_table: - table = result_div.find('table') - result_div = table if table else result_div - except: - pass + if chart.get('type', 'html') == 'html': + result_div = html.find('table') - 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: info = self.getInfo(imdb_id) @@ -158,14 +170,19 @@ class IMDBAutomation(IMDBBase): def getChartList(self): + # Nearly identical to 'getIMDBids', but we don't care about minimalMovie and return all movie data (not just id) 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: - if self.conf('chart_display_%s' % url): - 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]) + for name in self.charts: + chart = self.charts[name].copy() + + if self.conf('chart_display_%s' % name): + + chart['list'] = [] + + data = self.getHTMLData(chart.get('url')) if data: html = BeautifulSoup(data) @@ -173,7 +190,7 @@ class IMDBAutomation(IMDBBase): result_div = html.find('div', attrs = {'id': 'main'}) try: - if url in self.first_table: + if chart.get('url') in self.first_table: table = result_div.find('table') result_div = table if table else result_div except: @@ -183,15 +200,15 @@ class IMDBAutomation(IMDBBase): for imdb_id in imdb_ids[0:max_items]: info = self.getInfo(imdb_id) - movie_list['list'].append(info) + chart['list'].append(info) if self.shuttingDown(): break 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']: - movie_lists.append(movie_list) + if chart['list']: + movie_lists.append(chart) return movie_lists