Permalink
Browse files

IMDB Watchlist importer (Issue #146)

  • Loading branch information...
1 parent 2628189 commit e514eb9c8c20bf63fcc36f15df73cf28438bee1a @lechat lechat committed Jan 6, 2012
Showing with 184 additions and 2 deletions.
  1. +2 −1 .gitignore
  2. +4 −0 app/config/configApp.py
  3. +5 −0 app/lib/cron/__init__.py
  4. +98 −0 app/lib/cron/imdbwatchlist.py
  5. +49 −0 app/lib/imdbwl.py
  6. +26 −1 app/views/config/index.html
View
@@ -28,6 +28,7 @@ WindowsUpdater.py
*.wpr
/.idea/
*.komodoproject
+*.sw?
# OS generated files #
######################
@@ -36,4 +37,4 @@ WindowsUpdater.py
desktop.ini
ehthumbs.db
Thumbs.db
-.directory
+.directory
View
@@ -173,6 +173,10 @@ def initConfig(self):
self.setDefault('Trakt', 'username', '')
self.setDefault('Trakt', 'password', '')
+ self.addSection('IMDBWatchlist')
+ self.setDefault('IMDBWatchlist', 'enabled', False)
+ self.setDefault('IMDBWatchlist', 'url', '')
+
self.addSection('XBMC')
self.setDefault('XBMC', 'enabled', False)
self.setDefault('XBMC', 'onSnatch', False)
View
@@ -4,6 +4,7 @@
from app.lib.cron.movierss import startMovieRSSCron
from app.lib.cron.kinepolisrss import startKinepolisRSSCron
from app.lib.cron.traktwatchlist import startTraktCron
+from app.lib.cron.imdbwatchlist import startImdbWlCron
from app.lib.cron.subtitle import subtitleQueue, startSubtitleCron
from app.lib.cron.trailer import startTrailerCron, trailerQueue
from app.lib.cron.yarr import startYarrCron
@@ -73,6 +74,10 @@ def start(self):
TraktCronJob = startTraktCron(config, self.searchers, self.debug)
self.threads['Trakt'] = TraktCronJob
+ #IMDB Watchlist cron
+ IMDBCronJob = startImdbWlCron(config, self.searchers, self.debug)
+ self.threads['IMDBWl'] = IMDBCronJob
+
#nzb cronjob
yarrCronJob = startYarrCron(config, self.debug, yarrSearch)
yarrCronJob.sabNzbd = sabNzbd(config)
@@ -0,0 +1,98 @@
+from app.config.cplog import CPLog
+from app.config.db import Session as Db, QualityTemplate, Movie
+from app.controllers.movie import MovieController
+from app.lib.cron.base import cronBase
+from app.lib.library import Library
+from app.lib.imdbwl import ImdbWl
+import time
+import traceback
+
+log = CPLog(__name__)
+
+class ImdbWlCron(cronBase, Library):
+ ''' Cronjob for getting imdb watchlist '''
+
+ lastChecked = 0
+ intervalSec = 1800
+ config = {}
+
+ def conf(self, option):
+ return self.config.get('IMDBWatchlist', option)
+
+ def run(self):
+ log.info('IMDB watchlist thread is running.')
+
+ wait = 0.1 if self.debug else 5
+
+ time.sleep(10)
+ while True and not self.abort:
+ now = time.time()
+
+ if (self.lastChecked + self.intervalSec) < now:
+ try:
+ self.running = True
+ self.lastChecked = now
+ self.doCsvCheck()
+ self.running = False
+ except:
+ log.error("!!Uncaught exception in IMDB Watchlist thread: %s" % traceback.format_exc())
+
+ time.sleep(wait)
+
+ def isDisabled(self):
+ return not self.conf('enabled')
+
+ def doCsvCheck(self):
+ '''
+ Go find movies and add them!
+ '''
+
+ if self.isDisabled():
+ log.debug('IMDB Watchlist has been disabled')
+ return
+
+ log.info('Starting IMDB Watchlist check')
+ wl = ImdbWl()
+ watchlist = wl.getWatchlist()
+ if not watchlist:
+ log.info("Could not get IMDB watchlist.")
+ return
+
+ MyMovieController = MovieController()
+
+ for movie in watchlist:
+ if self.abort: #this loop takes a while, stop when the program needs to close
+ log.info('Aborting IMDB watchlist check')
+ return
+
+ time.sleep(5) # give the system some slack
+
+ log.debug('Searching for movie: "%s".' % movie['title'])
+ result = False
+ try:
+ result = self.searcher['movie'].findByImdbId(movie['imdb'])
+ except Exception:
+ result = False
+ if not result:
+ log.info('Movie not found: "%s".' % movie['title'])
+ continue
+ try:
+ # Check and see if the movie is in CP already, if so, ignore it.
+ cpMovie = Db.query(Movie).filter_by(imdb = movie['imdb']).first()
+ if cpMovie:
+ log.info('IMDB Watchlist: Movie found in CP Database, ignore: "%s".' % movie['title'])
+ continue
+ log.info('Adding movie to queue: %s.' % movie['title'])
+ quality = Db.query(QualityTemplate).filter_by(name = self.config.get('Quality', 'default')).one()
+ MyMovieController._addMovie(result, quality.id)
+ except:
+ log.info('MovieController unable to add this movie: "%s". %s' % (movie['title'], traceback.format_exc()))
+
+def startImdbWlCron(config, searcher, debug):
+ cron = ImdbWlCron()
+ cron.config = config
+ cron.searcher = searcher
+ cron.debug = debug
+ cron.start()
+
+ return cron
View
@@ -0,0 +1,49 @@
+from app.config.cplog import CPLog
+import cherrypy
+import urllib
+import csv
+
+log = CPLog(__name__)
+
+def conf(options):
+ return cherrypy.config['config'].get('IMDBWatchlist', options)
+
+class ImdbWl:
+
+ def __init__(self):
+ self.enabled = conf('enabled')
+
+ def call(self, url = None):
+ log.debug("Call method")
+
+ if not url:
+ url = conf('url')
+
+ watchlist = []
+ try:
+ log.info('Retrieving IMDB Watchlist CSV from %s' % url)
+ 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)
+ except(IOError):
+ log.info("Failed calling downloading/parsing IMDB Watchlist CSV")
+ watchlist = None
+ 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()
+
+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'
@@ -409,7 +409,7 @@
</div>
</fieldset>
- <fieldset class="inlineLabels">
+ <fieldset class="inlineLabels">
<h3>#alt.binaries.hdtv.x264@EFnet</h3>
<div class="ctrlHolder checkbox">
<label>Enable</label>
@@ -443,6 +443,14 @@
</fieldset>
</div>
+ <div class="group imdb">
+ <fieldset class="inlineLabels">
+ <div>Got a jailbroken iPhone? Get the CouchPotato app on Cydia! <span>(search for "<strong>iCouchPotato</strong>")</span></div>
+ <img src="${baseUrl}media/images/iphone1.png" /><img src="${baseUrl}media/images/iphone2.png" /><img src="${baseUrl}media/images/iphone3.png" />
+ <div>Why isn't it in the normal Appstore you ask? Because Apple is being a bitch!</div>
+ </fieldset>
+ </div>
+
<div class="group iphone">
<fieldset class="inlineLabels">
<div>Got a jailbroken iPhone? Get the CouchPotato app on Cydia! <span>(search for "<strong>iCouchPotato</strong>")</span></div>
@@ -730,6 +738,23 @@
<input type="checkbox" name="MovieETA.enabled" value="True" ${' checked="checked"' if config.get('MovieETA', 'enabled') else ''} />
</div>
</fieldset>
+ <fieldset class="inlineLabels">
+ <h3>IMDB Watchlist</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.
+ </p>
+ </div>
+ <div class="ctrlHolder">
+ <label>IMDB Watchlist URL</label>
+ <input type="text" name="IMDBWatchlist.url" value="${config.get('IMDBWatchlist', 'url')}" class="textInput large"/>
+ <p class="formHint">
+ 'Export this list' URL of the public IMDB Watchlist
+ </p>
+ </div>
+ </fieldset>
</div>
<div class="group notifications">
<fieldset class="inlineLabels" id="xbmcFieldset">

0 comments on commit e514eb9

Please sign in to comment.