def doJSONCheck(self): """ Go find movies and add them! """ if self.isDisabled(): log.debug("Trakt has been disabled") return log.info("Starting Trakt check") trakt = Trakt() watchlist = trakt.getWatchlist() if not watchlist: log.info("Could not get watchlist. Please add a password if you have a protected account") 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 trakt watchlist check") return time.sleep(5) # give the system some slack if self.conf("dontaddcollection"): if "in_collection" in movie: if movie.get("in_collection"): log.debug('Movie "%s" already in collection, ignoring' % movie.get("title")) continue log.debug('Searching for movie: "%s".' % movie.get("title")) result = False try: if movie.get("tmdb_id") != "": result = self.searcher["movie"].findById(movie.get("tmdb_id")) elif movie.get("imdb_id") != "": result = self.searcher["movie"].findByImdbId(movie.get("imdb_id")) else: log.info('Trakt has no tmdb or imdb Id for movie: "%s".' % movie.get("title")) continue except Exception: result = False if not result: log.info('Movie not found: "%s".' % movie.get("title")) continue log.debug("Checking movie: %s." % movie.get("title") + " (" + str(movie.get("year")) + ")") try: # Check and see if the movie is in CP already, if so, ignore it. cpMovie = Db.query(Movie).filter_by(imdb=movie.get("imdb_id")).first() if cpMovie: log.debug('Movie found in CP Database, ignore: "%s".' % movie.get("title")) continue log.info("Adding movie to queue: %s." % movie.get("title") + " (" + str(movie.get("year")) + ")") 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.get("title"), traceback.format_exc()) )
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() # Retrieve defined watchlists into one list watchlist = wl.getWatchlists() if not 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: 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())) log.info('Finished processing IMDB Watchlist(s)')
def setup(): mapper = cherrypy.dispatch.RoutesDispatcher() mapper.minimization = False mapper.explicit = False mapper.append_slash = True mapper.connect('main', '/', controller=MovieController(), action='index') for controller in [ MovieController, FeedController, ConfigController, CronController, ManageController, LogController ]: name = str(controller).split('.')[-2] mapper.connect(name, '/' + name + '/', controller=controller(), action='index') mapper.connect(name, '/' + name + '/:action/', controller=controller(), action='index') mapper.connect('userscript', '/CouchPotato.user.js', controller=ConfigController(), action='userscript') return mapper
def doRSSCheck(self): ''' Go find movies and add them! ''' if self.isDisabled(): log.info('Movie RSS has been disabled') return log.info('Starting Movies RSS check') if not self.isAvailable(self.MovieRSSUrl): log.info('Movie RSS is not available') return RSSData = self.urlopen(self.MovieRSSUrl) RSSItems = self.getItems(RSSData) RSSMovies = [] RSSMovie = {'name': 'test', 'year' : '2009'} MyMovieController = MovieController() for RSSItem in RSSItems: RSSMovie['name'] = self.gettextelement(RSSItem, "title").lower().split("blu-ray")[0].strip("(").rstrip() #strip Blu-ray and spaces RSSMovie['year'] = self.gettextelement(RSSItem, "description").split("|")[1].strip("(").strip() #find movie year in description if not RSSMovie['name'].find("/") == -1: # make sure it is not a double movie release continue if int(RSSMovie['year']) < int(self.conf('minyear')): #do year filtering continue for test in RSSMovies: if test.values() == RSSMovie.values(): # make sure we did not already include it... break else: log.info('Release found: %s.' % RSSMovie) RSSMovies.append(RSSMovie.copy()) if not RSSMovies: log.info('No movies found.') return log.info("Applying IMDB filter to found movies...") for RSSMovie in RSSMovies: if self.abort: #this loop takes a while, stop when the program needs to close return time.sleep(5) # give the system some slack log.debug('Searching for "%s".' % RSSMovie) result = self.searcher['movie'].find(RSSMovie['name'] + ' ' + RSSMovie['year'], limit = 1) if not result: log.info('Movie not found: "%s".' % RSSMovie) continue try: imdbmovie = self.searcher['movie'].imdb.findByImdbId(result.imdb, True) except: log.info('Cannot find movie on IMDB: "%s".' % RSSMovie) continue if not (imdbmovie.get('kind') == 'movie'): log.info('This is a ' + imdbmovie.get('kind') + ' not a movie: "%s"' % RSSMovie) continue if not imdbmovie.get('year'): log.info('IMDB has trouble with the year, skipping: "%s".' % RSSMovie) continue if not int(imdbmovie.get('year')) == int(RSSMovie['year']): log.info('IMDB movie year is wrong for: "%s".' % RSSMovie) continue if not imdbmovie.get('rating'): log.info('Rating is unknown for this movie: "%s".' % RSSMovie) continue if float(imdbmovie.get('rating')) < float(self.conf('minrating')): log.info('Rating is too low for this movie: "%s".' % RSSMovie) continue log.info('Adding movie to queue: %s.' % imdbmovie.get('title') + ' (' + str(imdbmovie.get('year')) + ') Rating: ' + str(imdbmovie.get('rating'))) try: # Check and see if the movie is in CP already, if so, ignore it. cpMovie = Db.query(Movie).filter_by(imdb = result.imdb).first() if cpMovie: log.info('Movie found in CP Database, ignore: "%s".' % RSSMovie) continue 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' % (RSSMovie, traceback.format_exc()))
def doRSSCheck(self): ''' Go find movies and add them! ''' if self.isDisabled(): log.info('Movie RSS has been disabled') return log.info('Starting Movies RSS check') if not self.isAvailable(self.MovieRSSUrl): log.info('Movie RSS is not available') return RSSData = self.urlopen(self.MovieRSSUrl) RSSItems = self.getItems(RSSData) RSSMovies = [] RSSMovie = {'name': 'test', 'year': '2009'} MyMovieController = MovieController() for RSSItem in RSSItems: RSSMovie['name'] = self.gettextelement( RSSItem, "title").lower().split("blu-ray")[0].strip( "(").rstrip() #strip Blu-ray and spaces RSSMovie['year'] = self.gettextelement( RSSItem, "description").split("|")[1].strip( "(").strip() #find movie year in description if not RSSMovie['name'].find( "/") == -1: # make sure it is not a double movie release continue if int(RSSMovie['year']) < int( self.conf('minyear')): #do year filtering continue for test in RSSMovies: if test.values() == RSSMovie.values( ): # make sure we did not already include it... break else: log.info('Release found: %s.' % RSSMovie) RSSMovies.append(RSSMovie.copy()) if not RSSMovies: log.info('No movies found.') return log.info("Applying IMDB filter to found movies...") for RSSMovie in RSSMovies: if self.abort: #this loop takes a while, stop when the program needs to close return time.sleep(5) # give the system some slack log.debug('Searching for "%s".' % RSSMovie) result = self.searcher['movie'].find(RSSMovie['name'] + ' ' + RSSMovie['year'], limit=1) if not result: log.info('Movie not found: "%s".' % RSSMovie) continue try: imdbmovie = self.searcher['movie'].imdb.findByImdbId( result.imdb, True) except: log.info('Cannot find movie on IMDB: "%s".' % RSSMovie) continue if not (imdbmovie.get('kind') == 'movie'): log.info('This is a ' + imdbmovie.get('kind') + ' not a movie: "%s"' % RSSMovie) continue if not imdbmovie.get('year'): log.info('IMDB has trouble with the year, skipping: "%s".' % RSSMovie) continue if not int(imdbmovie.get('year')) == int(RSSMovie['year']): log.info('IMDB movie year is wrong for: "%s".' % RSSMovie) continue if not imdbmovie.get('rating'): log.info('Rating is unknown for this movie: "%s".' % RSSMovie) continue if not imdbmovie.get('votes'): log.info('Number of votes is unknown for this movie: "%s".' % RSSMovie) continue if float(imdbmovie.get('rating')) < float(self.conf('minrating')): log.info('Rating is too low for this movie: "%s".' % RSSMovie) continue if float(imdbmovie.get('votes')) < float(self.conf('minvotes')): log.info('Number of votes is too low for this movie: "%s".' % RSSMovie) continue log.info('Adding movie to queue: %s.' % imdbmovie.get('title') + ' (' + str(imdbmovie.get('year')) + ') Rating: ' + str(imdbmovie.get('rating'))) try: # Check and see if the movie is in CP already, if so, ignore it. cpMovie = Db.query(Movie).filter_by(imdb=result.imdb).first() if cpMovie: log.info('Movie found in CP Database, ignore: "%s".' % RSSMovie) continue 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' % (RSSMovie, traceback.format_exc()))
def doJSONCheck(self): ''' Go find movies and add them! ''' if self.isDisabled(): log.debug('Trakt has been disabled') return log.info('Starting Trakt check') req = urllib2.Request(self.TraktUrl + self.conf('apikey') + "/" + self.conf('username')) if self.conf('password') != "": req.add_data( json.dumps({ 'username': self.conf('username'), 'password': sha1(self.conf('password')).hexdigest() })) req.add_header('content-type', 'application/json') try: url = urllib2.urlopen(req, timeout=10) watchlist = json.load(url) except (IOError, URLError): log.info('Trakt conection failed') return MyMovieController = MovieController() if not watchlist: log.info( 'No movies found. Please add a password if you have a protected account' ) return for movie in watchlist: if self.abort: #this loop takes a while, stop when the program needs to close log.info('Aborting trakt watchlist check') return time.sleep(5) # give the system some slack log.debug('Searching for movie: "%s".' % movie.get('title')) result = False try: if movie.get('tmdb_id') != "": result = self.searcher['movie'].findById( movie.get('tmdb_id')) elif movie.get('imdb_id') != "": result = self.searcher['movie'].findByImdbId( movie.get('imdb_id')) else: log.info('Trakt has no tmdb or imdb Id for movie: "%s".' % movie.get('title')) continue except Exception: result = False if not result: log.info('Movie not found: "%s".' % movie.get('title')) continue log.debug('Checking movie: %s.' % movie.get('title') + ' (' + str(movie.get('year')) + ')') try: # Check and see if the movie is in CP already, if so, ignore it. cpMovie = Db.query(Movie).filter_by( imdb=movie.get('imdb_id')).first() if cpMovie: log.debug('Movie found in CP Database, ignore: "%s".' % movie.get('title')) continue log.info('Adding movie to queue: %s.' % movie.get('title') + ' (' + str(movie.get('year')) + ')') 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.get('title'), traceback.format_exc()))
def doJSONCheck(self): ''' Go find movies and add them! ''' if self.isDisabled(): log.debug('Trakt has been disabled') return log.info('Starting Trakt check') req = urllib2.Request(self.TraktUrl + self.conf('apikey') + "/" + self.conf('username')) if self.conf('password') != "": req.add_data(json.dumps({'username' : self.conf('username'), 'password' : sha1(self.conf('password')).hexdigest()})) req.add_header('content-type', 'application/json') try: url = urllib2.urlopen(req, timeout = 10) watchlist = json.load(url) except (IOError, URLError): log.info('Trakt conection failed') return MyMovieController = MovieController() if not watchlist: log.info('No movies found. Please add a password if you have a protected account') return for movie in watchlist: if self.abort: #this loop takes a while, stop when the program needs to close log.info('Aborting trakt watchlist check') return time.sleep(5) # give the system some slack log.debug('Searching for movie: "%s".' % movie.get('title')) result = False try: if movie.get('tmdb_id') != "": result = self.searcher['movie'].findById(movie.get('tmdb_id')) elif movie.get('imdb_id') != "": result = self.searcher['movie'].findByImdbId(movie.get('imdb_id')) else: log.info('Trakt has no tmdb or imdb Id for movie: "%s".' % movie.get('title')) continue except Exception: result = False if not result: log.info('Movie not found: "%s".' % movie.get('title')) continue log.debug('Checking movie: %s.' % movie.get('title') + ' (' + str(movie.get('year')) + ')') try: # Check and see if the movie is in CP already, if so, ignore it. cpMovie = Db.query(Movie).filter_by(imdb = movie.get('imdb_id')).first() if cpMovie: log.debug('Movie found in CP Database, ignore: "%s".' % movie.get('title')) continue log.info('Adding movie to queue: %s.' % movie.get('title') + ' (' + str(movie.get('year')) + ')') 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.get('title'), traceback.format_exc()))
def doJSONCheck(self): ''' Go find movies and add them! ''' if self.isDisabled(): log.debug('Trakt has been disabled') return log.info('Starting Trakt check') trakt = Trakt() watchlist = trakt.getWatchlist() if not watchlist: log.info( "Could not get watchlist. Please add a password if you have a protected account" ) 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 trakt watchlist check') return time.sleep(5) # give the system some slack if (self.conf('dontaddcollection')): if ("in_collection" in movie): if (movie.get("in_collection")): log.debug( 'Movie "%s" already in collection, ignoring' % movie.get('title')) continue log.debug('Searching for movie: "%s".' % movie.get('title')) result = False try: if movie.get('tmdb_id') != "": result = self.searcher['movie'].findById( movie.get('tmdb_id')) elif movie.get('imdb_id') != "": result = self.searcher['movie'].findByImdbId( movie.get('imdb_id')) else: log.info('Trakt has no tmdb or imdb Id for movie: "%s".' % movie.get('title')) continue except Exception: result = False if not result: log.info('Movie not found: "%s".' % movie.get('title')) continue log.debug('Checking movie: %s.' % movie.get('title') + ' (' + str(movie.get('year')) + ')') try: # Check and see if the movie is in CP already, if so, ignore it. cpMovie = Db.query(Movie).filter_by( imdb=movie.get('imdb_id')).first() if cpMovie: log.debug('Movie found in CP Database, ignore: "%s".' % movie.get('title')) continue log.info('Adding movie to queue: %s.' % movie.get('title') + ' (' + str(movie.get('year')) + ')') 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.get('title'), traceback.format_exc()))
def doRSSCheck(self, rssurl): """ Go find movies and add them! """ if self.isDisabled(): log.info("Kinepolis RSS has been disabled") return log.info("Starting Kinepolis RSS check") if not self.isAvailable(self.KinepolisRSSUrl): log.info("Kinepolis RSS is not available") return RSSData = self.urlopen(rssurl) RSSItems = self.getItems(RSSData) RSSMovies = [] RSSMovie = {"name": "test", "year": "2009"} MyMovieController = MovieController() for RSSItem in RSSItems: if self.gettextelement(RSSItem, "title").find("Kinepolis Top 10") == -1: if rssurl == self.KinepolisRSSUrl: RSSMovie["name"] = self.gettextelement(RSSItem, "title").lower().split(".")[1].rstrip() else: RSSMovie["name"] = self.gettextelement(RSSItem, "title").lower().rstrip(" ov") currentYear = datetime.datetime.now().strftime("%Y") RSSMovie["year"] = currentYear if not RSSMovie["name"].find("/") == -1: # make sure it is not a double movie release continue if int(RSSMovie["year"]) < int(self.conf("minyear")): # do year filtering continue for test in RSSMovies: if test.values() == RSSMovie.values(): # make sure we did not already include it... break else: log.info("Release found: %s." % RSSMovie) RSSMovies.append(RSSMovie.copy()) if not RSSMovies: log.info("No movies found.") return log.info("Applying IMDB filter to found movies...") for RSSMovie in RSSMovies: if self.abort: # this loop takes a while, stop when the program needs to close return time.sleep(5) # give the system some slack log.debug('Searching for "%s".' % RSSMovie) result = self.searcher["movie"].find(RSSMovie["name"] + " " + RSSMovie["year"], limit=1) if not result: log.info('Movie not found: "%s".' % RSSMovie) continue try: imdbmovie = self.searcher["movie"].imdb.findByImdbId(result.imdb, True) except: log.info('Cannot find movie on IMDB: "%s".' % RSSMovie) continue if not (imdbmovie.get("kind") == "movie"): log.info("This is a " + imdbmovie.get("kind") + ' not a movie: "%s"' % RSSMovie) continue if not imdbmovie.get("year"): log.info('IMDB has trouble with the year, skipping: "%s".' % RSSMovie) continue if not int(imdbmovie.get("year")) == int(RSSMovie["year"]): log.info('IMDB movie year is wrong for: "%s".' % RSSMovie) continue if not imdbmovie.get("rating"): log.info('Rating is unknown for this movie: "%s".' % RSSMovie) continue if float(imdbmovie.get("rating")) < float(self.conf("minrating")): log.info('Rating is too low for this movie: "%s".' % RSSMovie) continue log.info( "Adding movie to queue: %s." % imdbmovie.get("title") + " (" + str(imdbmovie.get("year")) + ") Rating: " + str(imdbmovie.get("rating")) ) try: # Check and see if the movie is in CP already, if so, ignore it. cpMovie = Db.query(Movie).filter_by(imdb=result.imdb).first() if cpMovie: log.info('Movie found in CP Database, ignore: "%s".' % RSSMovie) continue 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' % (RSSMovie, traceback.format_exc()))