Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #423 from lechat/master

Support for multiple IMDB watchlists
  • Loading branch information...
commit ace92a3cb646de806a403fd82ca7600238ad241b 2 parents f218072 + b1e8562
@RuudBurger RuudBurger authored
View
8 app/lib/cron/imdbwatchlist.py
@@ -53,11 +53,14 @@ def doCsvCheck(self):
log.info('Starting IMDB Watchlist check')
wl = ImdbWl()
- watchlist = wl.getWatchlist()
+ # Retrieve defined watchlists into one list
+ watchlist = wl.getWatchlists()
if not watchlist:
- log.info("Could not get IMDB watchlist.")
+ log.info("Could not get any info from IMDB Watchlists. Check log for more information.")
return
+ # log.info('Watchlist is "%s"' % watchlist)
+
MyMovieController = MovieController()
for movie in watchlist:
@@ -87,6 +90,7 @@ def doCsvCheck(self):
MyMovieController._addMovie(result, quality.id)
except:
log.info('MovieController unable to add this movie: "%s". %s' % (movie['title'], traceback.format_exc()))
+ log.info('Finished processing IMDB Watchlist(s)')
def startImdbWlCron(config, searcher, debug):
cron = ImdbWlCron()
View
78 app/lib/imdbwl.py
@@ -2,6 +2,7 @@
import cherrypy
import urllib
import csv
+import time
log = CPLog(__name__)
@@ -9,41 +10,80 @@ def conf(options):
return cherrypy.config['config'].get('IMDBWatchlist', options)
class ImdbWl:
+ ''' Downloads and parses IMDB watchlist CSV into list of dicts: [{imdb, title}] '''
def __init__(self):
self.enabled = conf('enabled')
- def call(self, url = None):
- log.debug("Call method")
- if not url:
- url = conf('url')
+ def _get_watchlist(self, url):
+ temp_wl = []
- watchlist = []
try:
log.info('Retrieving IMDB Watchlist CSV from %s' % url)
+
+ # Just a sanity check in case of bogus parameters
+ if not url.startswith('http://'):
+ log.info('Incorrect IMDB watchlist URL: %s. Skipping.' % url)
+ return temp_wl
+
urllib._urlopener = ImdbUrlOpener()
tmp_csv, headers = urllib.urlretrieve(url)
csvwl = csv.reader(open(tmp_csv, 'rb'))
+
for row in csvwl:
- if row[0] != 'position':
- #log.info('Row is %s' % row)
- movie = {}
- movie['imdb'] = row[1]
- movie['title'] = '%s (%s)' % (row[5], row[10])
-
- watchlist.append(movie)
+ # Check if row is watchlist CSV - should have more than ten fields
+ if len(row) > 10:
+ if row[0] != 'position':
+ # log.info('Row is %s' % row)
+ movie = {}
+ movie['imdb'] = row[1]
+ movie['title'] = '%s (%s)' % (row[5], row[10])
+
+ temp_wl.append(movie)
+ else:
+ # Row is not from proper watchlist CSV, stop processing this URL
+ log.info('This does not look like a proper IMDB watchlist CSV, skipping.')
+ return temp_wl
+
except(IOError):
- log.info("Failed calling downloading/parsing IMDB Watchlist CSV")
- watchlist = None
+ log.info('Failed downloading/parsing IMDB Watchlist CSV from %s. Not adding that watchlist to CP' % url)
+
+ return temp_wl
+
+
+ def _call(self, urls = None):
+ if not self.enabled:
+ return []
+
+ if not urls:
+ urls = conf('url')
+
+ # If urls are not defined and not passed as parameters - there is nothing to do here
+ if not urls:
+ return []
+
+ # Clean urls string and convert it to a list
+ urls_list = urls.replace(' ', '').replace('\n','').split(',')
+
+ watchlist = []
+
+ for url in urls_list:
+ # Wait a bit, so IMDB will be happy
+ log.info('Sleeping before fetching IMDB Watchlist CSV')
+ time.sleep(10)
+
+ wl = self._get_watchlist(url)
+
+ # We don't need to have any empty entries in a list in case something went wrong
+ if len(wl):
+ watchlist.extend(wl)
+
return watchlist
- def test(self, url):
- wl = self.call('http://www.imdb.com/list/export?list_id=watchlist&author_id=ur0034213')
- print wl
- def getWatchlist(self):
- return self.call()
+ def getWatchlists(self):
+ return self._call()
class ImdbUrlOpener(urllib.FancyURLopener):
version = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.12 Safari/535.11'
View
10 app/views/config/index.html
@@ -731,19 +731,19 @@
</div>
</fieldset>
<fieldset class="inlineLabels">
- <h3>IMDB Watchlist</h3>
+ <h3>IMDB Watchlists</h3>
<div class="ctrlHolder checkbox">
<label>Enable</label>
<input type="checkbox" name="IMDBWatchlist.enabled" value="True" ${' checked="checked"' if config.get('IMDBWatchlist', 'enabled') else ''} />
<p class="formHint">
- This will magically add movies to your wanted list that appear in public IMDB Watchlist specified below.
+ This will magically add movies to your wanted list that appear in public IMDB Watchlist(s) specified below.
</p>
</div>
<div class="ctrlHolder">
- <label>IMDB Watchlist URL</label>
- <input type="text" name="IMDBWatchlist.url" value="${config.get('IMDBWatchlist', 'url')}" class="textInput large"/>
+ <label>IMDB Watchlist URL(s)</label>
+ <textarea name="IMDBWatchlist.url" cols="50" rows="5" class="textInput large">${config.get('IMDBWatchlist', 'url')}</textarea>
<p class="formHint">
- 'Export this list' URL of the public IMDB Watchlist
+ Comma separated list of 'Export this list' links from the public IMDB Watchlist pages
</p>
</div>
</fieldset>
Please sign in to comment.
Something went wrong with that request. Please try again.