def index(self): # Releases theater = Db.query(MovieETA) \ .join(MovieETA.Movie) \ .filter(MovieETA.theater <= time.time() + 1814400) \ .filter(MovieETA.theater >= time.time()) \ .filter(or_(Movie.status == 'want', Movie.status == 'waiting')) \ .order_by(MovieETA.theater) \ .all() dvd = Db.query(MovieETA) \ .join(MovieETA.Movie) \ .filter(MovieETA.dvd <= time.time() + 3628800) \ .filter(MovieETA.dvd >= time.time()) \ .filter(or_(Movie.status == 'want', Movie.status == 'waiting')) \ .order_by(MovieETA.dvd) \ .all() dvdNow = Db.query(MovieETA) \ .join(MovieETA.Movie) \ .filter(MovieETA.dvd <= time.time()) \ .filter(MovieETA.dvd > 0) \ .filter(or_(Movie.status == 'want', Movie.status == 'waiting')) \ .order_by(MovieETA.dvd) \ .all() return self.render({ 'dvd': dvd, 'theater': theater, 'dvdNow': dvdNow, 'running': self.cron.get('eta').isRunning() })
def index(self): # Releases theater = Db.query(MovieETA) \ .join(MovieETA.Movie) \ .filter(MovieETA.theater <= time.time() + 1814400) \ .filter(MovieETA.theater >= time.time()) \ .filter(or_(Movie.status == 'want', Movie.status == 'waiting')) \ .order_by(MovieETA.theater) \ .all() dvd = Db.query(MovieETA) \ .join(MovieETA.Movie) \ .filter(MovieETA.dvd <= time.time() + 3628800) \ .filter(MovieETA.dvd >= time.time()) \ .filter(or_(Movie.status == 'want', Movie.status == 'waiting')) \ .order_by(MovieETA.dvd) \ .all() dvdNow = Db.query(MovieETA) \ .join(MovieETA.Movie) \ .filter(MovieETA.dvd <= time.time()) \ .filter(MovieETA.dvd > 0) \ .filter(or_(Movie.status == 'want', Movie.status == 'waiting')) \ .order_by(MovieETA.dvd) \ .all() return self.render({'dvd': dvd, 'theater':theater, 'dvdNow': dvdNow, 'running': self.cron.get('eta').isRunning()})
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 _addMovie(self, movie, quality, year=None): if self._checkMovieExists(movie=movie, qualityId=quality): return log.info('Adding movie to database: %s' % movie.name) if movie.id: exists = Db.query(Movie).filter_by(movieDb=movie.id).first() else: exists = Db.query(Movie).filter_by(imdb=movie.imdb).first() if exists: log.info('Movie already exists, do update.') # Delete old qualities for x in exists.queue: x.active = False Db.flush() new = exists else: new = Movie() Db.add(new) # Update the stuff new.status = u'want' new.name = movie.name new.imdb = movie.imdb new.movieDb = movie.id new.quality = quality new.year = year if year and movie.year == 'None' else movie.year Db.flush() # Add qualities to the queue quality = Db.query(QualityTemplate).filter_by(id=quality).one() for type in quality.types: queue = MovieQueue() queue.qualityType = type.type queue.movieId = new.id queue.order = type.order queue.active = True queue.completed = False queue.waitFor = 0 if type.markComplete else quality.waitFor queue.markComplete = type.markComplete Db.add(queue) Db.flush() #Get xml from themoviedb and save to cache self.searchers.get('movie').getExtraInfo(new.id, overwrite=True) #gogo find nzb for added movie via Cron self.cron.get('yarr').forceCheck(new.id) self.flash.add('movie-' + str(new.id), '"%s" (%s) added.' % (new.name, new.year))
def _addMovie(self, movie, quality, year = None): if self._checkMovieExists(movie=movie): return log.info('Adding movie to database: %s' % movie.name) if movie.id: exists = Db.query(Movie).filter_by(movieDb = movie.id).first() else: exists = Db.query(Movie).filter_by(imdb = movie.imdb).first() if exists: log.info('Movie already exists, do update.') # Delete old qualities for x in exists.queue: x.active = False Db.flush() new = exists else: new = Movie() Db.add(new) # Update the stuff new.status = u'want' new.name = movie.name new.imdb = movie.imdb new.movieDb = movie.id new.quality = quality new.year = year if year and movie.year == 'None' else movie.year Db.flush() # Add qualities to the queue quality = Db.query(QualityTemplate).filter_by(id = quality).one() for type in quality.types: queue = MovieQueue() queue.qualityType = type.type queue.movieId = new.id queue.order = type.order queue.active = True queue.completed = False queue.waitFor = 0 if type.markComplete else quality.waitFor queue.markComplete = type.markComplete Db.add(queue) Db.flush() #Get xml from themoviedb and save to cache self.searchers.get('movie').getExtraInfo(new.id, overwrite = True) #gogo find nzb for added movie via Cron self.cron.get('yarr').forceCheck(new.id) self.flash.add('movie-' + str(new.id), '"%s" (%s) added.' % (new.name, new.year))
def determineMovie(self, files): ''' Try find movie based on folder names and MovieQueue table ''' for file in files['files']: dirnames = file['path'].split(os.path.sep) dirnames.append(file['filename']) dirnames.reverse() for dir in dirnames: dir = latinToAscii(dir) # check and see if name is in queue queue = Db.query(MovieQueue).filter_by(name = dir).first() if queue: log.info('Found movie via MovieQueue.') return { 'queue': queue, 'movie': queue.Movie } # last resort, match every word in path to db lastResort = {} dir = dir.replace('.', ' ').lower() dirSplit = dir.split(' ') for s in dirSplit: if s: results = Db.query(Movie).filter(Movie.name.like('%' + s + '%')).all() for r in results: lastResort[r.id] = r for x in lastResort: l = lastResort[x] wordCount = 0 words = l.name.lower().split(' ') for word in words: if word.lower() in dir: wordCount += 1 if wordCount == len(words) and len(words) > 0: log.info('Found via last resort searching.') return { 'queue': None, 'movie': l } # Try finding movie on theMovieDB # more checking here.. return False
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 run(self): log.info('ETA thread is running.') timeout = 0.1 if self.debug else 1 while True and not self.abort: try: queue = etaQueue.get(timeout=timeout) if queue.get('id'): movie = Db.query(Movie).filter_by( id=queue.get('id')).first() else: movie = queue.get('movie') if not cherrypy.config.get('debug'): #do a search self.running = True result = self.search(movie) if result: self.save(movie, result) self.running = False etaQueue.task_done() time.sleep(timeout) except Queue.Empty: pass log.info('ETA thread shutting down.')
def reAdd(self, id, **data): ''' Re-add movie and force search ''' movie = Db.query(Movie).filter_by(id = id).one() if data.get('failed'): for history in movie.history: if history.status == u'snatched': history.status = u'ignore' Db.flush() for x in movie.queue: if x.completed == True: x.completed = False Db.flush() break #set status movie.status = u'want' Db.flush() #gogo find nzb for added movie via Cron self.cron.get('yarr').forceCheck(id) self.searchers.get('etaQueue').put({'id':id}) self.flash.add('movie-' + str(movie.id), '"%s" re-added.' % (movie.name)) return redirect(url(controller = 'movie', action = 'index'))
def reAdd(self, id, **data): ''' Re-add movie and force search ''' movie = Db.query(Movie).filter_by(id=id).one() if data.get('failed'): for history in movie.history: if history.status == u'snatched': history.status = u'ignore' Db.flush() for x in movie.queue: if x.completed == True: x.completed = False Db.flush() break #set status movie.status = u'want' Db.flush() #gogo find nzb for added movie via Cron self.cron.get('yarr').forceCheck(id) self.searchers.get('etaQueue').put({'id': id}) self.flash.add('movie-' + str(movie.id), '"%s" re-added.' % (movie.name)) return redirect(url(controller='movie', action='index'))
def run(self): log.info('YarrCron thread is running.') self.setInterval(self.config.get('Intervals', 'search')) self.forceCheck() if not self.debug: time.sleep(10) wait = 0.1 if self.debug else 10 while True and not self.abort: #check single movie try: for movieId in self.checkTheseMovies: movie = Db.query(Movie).filter_by(id = movieId).one() self._search(movie, True) self.checkTheseMovies.pop(0) except Exception, e: log.error('Something went wrong with checkTheseMovies: %s' % e) #check all movies try: now = time.time() if (self.lastChecked + self.intervalSec) < now: # and not self.debug: self.lastChecked = now self.searchAll() except Exception, e: log.error('Something went wrong with searchAll: %s' % e)
def run(self): log.info('MovieETA thread is running.') timeout = 0.1 if self.debug else 1 while True and not self.abort: try: queue = etaQueue.get(timeout = timeout) if queue.get('id'): movie = Db.query(Movie).filter_by(id = queue.get('id')).first() else: movie = queue.get('movie') if not cherrypy.config.get('debug'): #do a search self.running = True result = self.search(movie) if result: self.save(movie, result) etaQueue.task_done() time.sleep(timeout) self.running = False except Queue.Empty: pass log.info('MovieETA thread shutting down.')
def run(self): log.info('TrailerCron thread is running.') self.tempdir = cherrypy.config.get('cachePath') # Sources self.sources.append(HdTrailers(self.config)) #self.sources.append(Youtube(self.config)) timeout = 0.1 if self.debug else 1 while True and not self.abort: try: movie = trailerQueue.get(timeout = timeout) # Thread fix if movie.get('movieId'): movie['movie'] = Db.query(Movie).filter_by(id = movie.get('movieId')).one() #do a search self.running = True self.search(movie['movie'], movie['destination']) self.running = False trailerQueue.task_done() except Queue.Empty: pass log.info('TrailerCron shutting down.')
def save(self, **data): ''' Save all config settings ''' config = cherrypy.config.get('config') # catch checkboxes for bool in ['Renamer.enabled', 'Renamer.trailerQuality', 'Renamer.cleanup', 'global.launchbrowser', 'Torrents.enabled', 'NZB.enabled', 'NZBMatrix.enabled', 'NZBsorg.enabled', 'newznab.enabled']: if not data.get(bool): data[bool] = False # Do quality order order = data.get('Quality.order').split(',') for id in order: qo = Db.query(QualityTemplate).filter_by(id = int(id)).one() qo.order = order.index(id) Db.flush() del data['Quality.order'] # Save templates if data.get('Quality.templates'): templates = json.loads(data.get('Quality.templates')) Qualities().saveTemplates(templates) del data['Quality.templates'] # Save post data for name in data: section = name.split('.')[0] var = name.split('.')[1] config.set(section, var, data[name]) # Change cron interval self.cron.get('yarr').setInterval(config.get('Intervals', 'search')) config.save()
def run(self): log.info('YarrCron thread is running.') self.setInterval(self.config.get('Intervals', 'search')) self.forceCheck() if not self.debug: time.sleep(10) wait = 0.1 if self.debug else 1 while True and not self.abort: #check single movie for movieId in self.checkTheseMovies: movie = Db.query(Movie).filter_by(id = movieId).one() self._search(movie, True) self.checkTheseMovies.pop(0) #check all movies now = time.time() if (self.lastChecked + self.intervalSec) < now: # and not self.debug: self.lastChecked = now self.searchAll() time.sleep(wait) log.info('YarrCron has shutdown.')
def imdbAdd(self, **data): ''' Add movie by imdbId ''' id = 'tt' + data.get('id').replace('tt', '') success = False result = Db.query(Movie).filter_by(imdb=id, status=u'want').first() if result: success = True if data.get('add'): result = self.searchers.get('movie').findByImdbId(id) self._addMovie(result, data.get('quality'), data.get('year')) log.info('Added : %s' % result.name) success = True return self.render({ 'id': id, 'result': result, 'success': success, 'year': data.get('year') })
def reAdd(self, id, **data): """ Re-add movie and force search """ movie = Db.query(Movie).filter_by(id=id).one() if data.get("failed"): for history in movie.history: if history.status == u"snatched": history.status = u"ignore" Db.flush() for x in movie.queue: if x.completed == True: x.completed = False Db.flush() break # set status movie.status = u"want" Db.flush() # gogo find nzb for added movie via Cron self.cron.get("yarr").forceCheck(id) self.searchers.get("etaQueue").put({"id": id}) self.flash.add("movie-" + str(movie.id), '"%s" re-added.' % (movie.name)) return redirect(url(controller="movie", action="index"))
def save(self, **data): ''' Save all config settings ''' config = cherrypy.config.get('config') # catch checkboxes bools = filter(lambda s: not data.get(s), [ 'global.launchbrowser', 'global.updater', 'XBMC.enabled', 'XBMC.onSnatch', 'NMJ.enabled', 'PLEX.enabled', 'PROWL.enabled', 'PROWL.onSnatch', 'GROWL.enabled', 'GROWL.onSnatch', 'Notifo.enabled', 'Notifo.onSnatch', 'NMA.enable', 'NMA.onSnatch', 'Meta.enabled', 'MovieETA.enabled', 'Renamer.enabled', 'Renamer.trailerQuality', 'Renamer.cleanup', 'Torrents.enabled', 'NZB.enabled', 'NZBMatrix.enabled', 'NZBMatrix.english', 'NZBMatrix.ssl', 'NZBsRUS.enabled', 'newzbin.enabled', 'NZBsorg.enabled', 'newznab.enabled', 'Subtitles.enabled', 'Subtitles.addLanguage', 'MovieRSS.enabled', ] ) data.update(data.fromkeys(bools, False)) # Do quality order order = data.get('Quality.order').split(',') for id in order: qo = Db.query(QualityTemplate).filter_by(id = int(id)).one() qo.order = order.index(id) Db.flush() del data['Quality.order'] # Save templates if data.get('Quality.templates'): templates = json.loads(data.get('Quality.templates')) Qualities().saveTemplates(templates) del data['Quality.templates'] # Save post data for name in data: section = name.split('.')[0] var = name.split('.')[1] config.set(section, var, data[name]) # Change cron interval self.cron.get('yarr').setInterval(config.get('Intervals', 'search')) config.save() self.flash.add('config', 'Settings successfully saved.') return redirect(cherrypy.request.headers.get('referer'))
def run(self): log.info('YarrCron thread is running.') self.setInterval(self.config.get('Intervals', 'search')) self.forceCheck() if not self.debug: time.sleep(10) wait = 0.1 if self.debug else 10 while True and not self.abort: #check single movie try: for movieId in self.checkTheseMovies: movie = Db.query(Movie).filter_by(id=movieId).one() self._search(movie, True) self.checkTheseMovies.pop(0) except Exception, e: log.error('Something went wrong with checkTheseMovies: %s' % e) #check all movies try: now = time.time() if (self.lastChecked + self.intervalSec) < now: # and not self.debug: self.lastChecked = now self.searchAll() except Exception, e: log.error('Something went wrong with searchAll: %s' % e)
def clear_downloaded(self): """Clear downloaded movies.""" qMovie = Db.query(Movie) downloaded = qMovie.filter_by(status=u"downloaded").all() for movie in downloaded: movie.status = u"deleted" Db.flush() return redirect(url(controller="movie", action="index"))
def saveTemplates(self, templates): log.debug('Saving Templates %s' % templates) # get all items delete = {'templates': [], 'types': []} for item in self.all(custom=True): delete['templates'].append(item.id) for type in item.types: delete['types'].append(type.id) for template in templates: # Don't delete try: delete['templates'].remove(int(template['id'])) except (ValueError, TypeError): pass if int(template['id']) == 0: template['id'] = template['name'] for type in template['types']: # Don't delete try: delete['types'].remove(int(type['id'])) except (ValueError, TypeError): pass self.create(template['id'], template['name'], template['types'], waitFor=template['waitFor']) # remove all non used custom if delete['templates']: [ Db.delete(x) for x in Db.query(QualityTemplate).filter( QualityTemplate.id.in_(delete['templates'])).all() ] Db.flush() if delete['types']: [ Db.delete(x) for x in Db.query(QualityTemplateType).filter( QualityTemplateType.id.in_(delete['types'])).all() ] Db.flush()
def getMovieByIMDB(self, imdbId): ''' Get movie based on IMDB id. If not in local DB, go fetch it from theMovieDb ''' m = Db.query(Movie).filter_by(imdb=imdbId).first() if m: return m
def getMovieByIMDB(self, imdbId): """ Get movie based on IMDB id. If not in local DB, go fetch it from theMovieDb """ m = Db.query(Movie).filter_by(imdb=imdbId).first() if m: return m
def clear_downloaded(self): """Clear downloaded movies.""" qMovie = Db.query(Movie) downloaded = qMovie.filter_by(status=u'downloaded').all() for movie in downloaded: movie.status = u'deleted' Db.flush() return redirect(url(controller='movie', action='index'))
def clear_downloaded(self): """Clear downloaded movies.""" qMovie = Db.query(Movie) downloaded = qMovie.filter_by(status = u'downloaded').all() for movie in downloaded: movie.status = u'deleted' Db.flush() return redirect(url(controller = 'movie', action = 'index'))
def saveExtra(self, id, name, value): exists = Db.query(MovieExtra).filter(and_(MovieExtra.movieId == id, MovieExtra.name == name)).first() if not exists: exists = MovieExtra() Db.add(exists) exists.movieId = id exists.name = name exists.value = value Db.flush()
def alreadyDownloaded(self, movie, file, key): key = self.getKey(key) movieId = 0 if not movie else movie.id results = Db.query(SubtitleHistory).filter(and_(SubtitleHistory.subtitle == key, SubtitleHistory.movie == movieId, SubtitleHistory.file == file)).all() for h in results: h.status = u'ignored' Db.flush() return len(results) > 0
def saveExtra(self, id, name, value): exists = Db.query(MovieExtra).filter(and_(MovieExtra.movieId == id, MovieExtra.name == name)).first() if not exists: exists = MovieExtra() Db.add(exists) exists.movieId = id exists.name = name exists.value = value Db.flush()
def index(self): ''' Show all wanted, snatched, downloaded movies ''' qMovie = Db.query(Movie) movies = qMovie.order_by(Movie.name).filter(or_(Movie.status == u'want', Movie.status == u'waiting')).all() snatched = qMovie.order_by(desc(Movie.dateChanged), Movie.name).filter_by(status = u'snatched').all() downloaded = qMovie.order_by(desc(Movie.dateChanged), Movie.name).filter_by(status = u'downloaded').all() return self.render({'movies': movies, 'snatched':snatched, 'downloaded':downloaded})
def searchAll(self): log.info('Searching for new downloads, for all movies.') self.doCheck() #get all wanted movies movies = Db.query(Movie).filter(or_(Movie.status == 'want', Movie.status == 'waiting')).all() for movie in movies: if not self.abort and not self.stop: self._search(movie) self.doCheck(False) log.info('Finished search.')
def save(self, **data): """ Save all config settings """ config = cherrypy.config.get("config") # catch checkboxes for bool in [ "XBMC.enabled", "Meta.enabled", "Renamer.enabled", "Renamer.trailerQuality", "Renamer.cleanup", "global.launchbrowser", "global.updater", "Torrents.enabled", "NZB.enabled", "NZBMatrix.enabled", "NZBsorg.enabled", "newznab.enabled", "Newzbin.enabled" "Subtitles.enabled", "Subtitles.addLanguage", ]: if not data.get(bool): data[bool] = False # Do quality order order = data.get("Quality.order").split(",") for id in order: qo = Db.query(QualityTemplate).filter_by(id=int(id)).one() qo.order = order.index(id) Db.flush() del data["Quality.order"] # Save templates if data.get("Quality.templates"): templates = json.loads(data.get("Quality.templates")) Qualities().saveTemplates(templates) del data["Quality.templates"] # Save post data for name in data: section = name.split(".")[0] var = name.split(".")[1] config.set(section, var, data[name]) # Change cron interval self.cron.get("yarr").setInterval(config.get("Intervals", "search")) config.save() self.flash.add("config", "Settings successfully saved.") return redirect(cherrypy.request.headers.get("referer"))
def getMovie(self, imdbId): ''' Get movie based on IMDB id. If not in local DB, go fetch it from theMovieDb ''' movie = Db.query(Movie).filter_by(imdb = imdbId).first() if not movie: movie = self.searcher.get('movie').findByImdbId(imdbId) return movie
def searchAll(self): log.info('Searching for new downloads, for all movies.') self.doCheck() #get all wanted movies movies = Db.query(Movie).filter(or_(Movie.status == 'want', Movie.status == 'waiting')).all() for movie in movies: if not self.abort and not self.stop: self._search(movie) self.doCheck(False) log.info('Finished search.')
def all(self, custom = None, enabled = None): q = Db.query(QualityTemplate).order_by(QualityTemplate.order) # Get only enabled if enabled: q = q.filter(~QualityTemplate.name.in_(self.conf('hide').split(','))) # Only show custom if custom != None: q = q.filter(QualityTemplate.custom == custom) return q.all()
def saveTemplates(self, templates): log.debug("Saving Templates %s" % templates) # get all items delete = {"templates": [], "types": []} for item in self.all(custom=True): delete["templates"].append(item.id) for type in item.types: delete["types"].append(type.id) for template in templates: # Don't delete try: delete["templates"].remove(int(template["id"])) except (ValueError, TypeError): pass if int(template["id"]) == 0: template["id"] = template["name"] for type in template["types"]: # Don't delete try: delete["types"].remove(int(type["id"])) except (ValueError, TypeError): pass self.create(template["id"], template["name"], template["types"], waitFor=template["waitFor"]) # remove all non used custom if delete["templates"]: [Db.delete(x) for x in Db.query(QualityTemplate).filter(QualityTemplate.id.in_(delete["templates"])).all()] Db.flush() if delete["types"]: [ Db.delete(x) for x in Db.query(QualityTemplateType).filter(QualityTemplateType.id.in_(delete["types"])).all() ] Db.flush()
def downloaded(self, id): """ Mark movie as downloaded """ movie = Db.query(Movie).filter_by(id=id).one() # set status movie.status = u"downloaded" Db.flush() self.flash.add("movie-" + str(movie.id), '"%s" marked as downloaded.' % (movie.name)) return redirect(url(controller="movie", action="index"))
def save(self, movie, result): row = Db.query(MovieETA).filter_by(movieId=movie.id).first() if not row: row = MovieETA() Db.add(row) row.movieId = movie.id row.theater = result.get('theater') row.dvd = result.get('dvd') row.bluray = result.get('bluray') row.lastCheck = result.get('expires') Db.flush()
def downloaded(self, id): ''' Mark movie as downloaded ''' movie = Db.query(Movie).filter_by(id = id).one() #set status movie.status = u'downloaded' Db.flush() self.flash.add('movie-' + str(movie.id), '"%s" marked as downloaded.' % (movie.name)) return redirect(url(controller = 'movie', action = 'index'))
def save(self, movie, result): row = Db.query(MovieETA).filter_by(movieId = movie.id).first() if not row: row = MovieETA() Db.add(row) row.movieId = movie.id row.theater = result.get('theater') row.dvd = result.get('dvd') row.bluray = result.get('bluray') row.lastCheck = result.get('expires') Db.flush()
def all(self, custom=None, enabled=None): q = Db.query(QualityTemplate).order_by(QualityTemplate.order) # Get only enabled if enabled: q = q.filter( ~QualityTemplate.name.in_(self.conf('hide').split(','))) # Only show custom if custom != None: q = q.filter(QualityTemplate.custom == custom) return q.all()
def create(self, name, label, types, waitFor=0, custom=True, order=0): newQ = QualityTemplate() exists = Db.query(QualityTemplate).filter( or_(QualityTemplate.name == name, QualityTemplate.id == name)).first() if not exists: log.info('Creating custom=%s quality: %s' % (custom, name)) newQ.name = name newQ.label = label newQ.custom = custom newQ.waitFor = waitFor newQ.order = order Db.add(newQ) Db.flush() exists = Db.query(QualityTemplate).filter_by(name=name).first() else: exists.label = label exists.waitFor = waitFor Db.flush() nr = 1 for type in types: # Update if needed newT = Db.query(QualityTemplateType).filter_by( quality=exists.id, type=type['type']).first() if not newT: newT = QualityTemplateType() newT.quality = exists.id newT.order = nr newT.type = type['type'] newT.markComplete = type['markComplete'] nr += 1 Db.add(newT) Db.flush() return True
def downloaded(self, id): ''' Mark movie as downloaded ''' movie = Db.query(Movie).filter_by(id=id).one() #set status movie.status = u'downloaded' Db.flush() self.flash.add('movie-' + str(movie.id), '"%s" marked as downloaded.' % (movie.name)) return redirect(url(controller='movie', action='index'))
def index(self): """ Show all wanted, snatched, downloaded movies """ if cherrypy.request.path_info == "/": return redirect("movie/") qMovie = Db.query(Movie) movies = qMovie.order_by(Movie.name).filter(or_(Movie.status == u"want", Movie.status == u"waiting")).all() snatched = qMovie.order_by(desc(Movie.dateChanged), Movie.name).filter_by(status=u"snatched").all() downloaded = qMovie.order_by(desc(Movie.dateChanged), Movie.name).filter_by(status=u"downloaded").all() return self.render({"movies": movies, "snatched": snatched, "downloaded": downloaded})
def save(self, movie, result): row = Db.query(MovieETA).filter_by(movieId = movie.id).first() if not row: row = MovieETA() Db.add(row) row.movieId = movie.id row.videoEtaId = result.get('id', 0) row.theater = result.get('theater', 0) row.dvd = result.get('dvd', 0) row.bluray = result.get('bluray', 0) row.lastCheck = int(time.time()) Db.flush()
def index(self): ''' Show all wanted, snatched, downloaded movies ''' if cherrypy.request.path_info == '/': return redirect('movie/') qMovie = Db.query(Movie) movies = qMovie.order_by(Movie.name).filter(or_(Movie.status == u'want', Movie.status == u'waiting')).all() snatched = qMovie.order_by(desc(Movie.dateChanged), Movie.name).filter_by(status = u'snatched').all() downloaded = qMovie.order_by(desc(Movie.dateChanged), Movie.name).filter_by(status = u'downloaded').all() return self.render({'movies': movies, 'snatched':snatched, 'downloaded':downloaded})
def alreadyDownloaded(self, movie, file, key): key = self.getKey(key) movieId = 0 if not movie else movie.id file = latinToAscii(file) results = Db.query(SubtitleHistory).filter(and_(SubtitleHistory.subtitle == key, SubtitleHistory.movie == movieId, SubtitleHistory.file == file)).all() if cherrypy.config.get('debug'): log.debug('%s already downloaded.' % results) return False else: for h in results: h.status = u'ignored' Db.flush() return len(results) > 0
def delete(self, id): ''' Mark movie as deleted ''' movie = Db.query(Movie).filter_by(id=id).one() previousStatus = movie.status #set status movie.status = u'deleted' Db.flush() if previousStatus == 'downloaded': self.flash.add('movie-' + str(movie.id), '"%s" deleted.' % (movie.name)) return redirect(url(controller='movie', action='index'))
def __init__(self, config): self.config = config # Config TheMovieDB self.theMovieDb = theMovieDb(self.config) self.sources.append(self.theMovieDb) # Config imdbWrapper self.imdb = imdbWrapper(self.config) self.sources.append(self.imdb) # Update the cache movies = Db.query(Movie).order_by(Movie.name).filter(or_(Movie.status == u'want', Movie.status == u'waiting')).all() for movie in movies: if not movie.extra: self.getExtraInfo(movie) # Fix db errors try: # Clear wrong value imdb_is_int = False try: imdb_is_int = float(movie.imdb) except ValueError: pass if not imdb_is_int and movie.imdb[:2] != 'tt': movie.imdb = None Db.flush() if movie.imdb and movie.imdb[:2] != 'tt': movie.imdb = 'tt%s' % movie.imdb Db.flush() elif not movie.imdb and movie.movieDb: results = self.findById(movie.movieDb) if results.get('imdb'): movie.imdb = results.get('imdb') Db.flush() if not movie.imdb: log.error('Errors in your database, try and remove & re-add: %s' % movie.name) except: pass
def index(self): ''' Show all wanted, snatched, downloaded movies ''' if cherrypy.request.path_info == '/': return redirect('movie/') qMovie = Db.query(Movie) movies = qMovie.order_by(Movie.name).filter( or_(Movie.status == u'want', Movie.status == u'waiting')).all() snatched = qMovie.order_by( desc(Movie.dateChanged), Movie.name).filter_by(status=u'snatched').all() downloaded = qMovie.order_by( desc(Movie.dateChanged), Movie.name).filter_by(status=u'downloaded').all() return self.render({ 'movies': movies, 'snatched': snatched, 'downloaded': downloaded })
def _addMovie(self, movie, quality, year=None): if cherrypy.config.get('config').get('XBMC', 'dbpath'): for root, dirs, files in os.walk( cherrypy.config.get('config').get('XBMC', 'dbpath')): for file in files: if file.startswith('MyVideos'): dbfile = os.path.join(root, file) if dbfile: #------Opening connection to XBMC DB------ connXbmc = MySqlite.connect(dbfile) if connXbmc: log.debug('Checking if movie exists in XBMC by IMDB id:' + movie.imdb) connXbmc.row_factory = MySqlite.Row cXbmc = connXbmc.cursor() cXbmc.execute('select c09 from movie where c09="' + movie.imdb + '"') #------End of Opening connection to XBMC DB------ inXBMC = False for rowXbmc in cXbmc: # do a final check just to be sure log.debug('Found in XBMC:' + rowXbmc["c09"]) if movie.imdb == rowXbmc["c09"]: inXBMC = True else: inXBMC = False cXbmc.close() if inXBMC: log.info('Movie already exists in XBMC, skipping.') return else: log.info( 'Could not connect to the XBMC database at ' + cherrypy.config.get('config').get('XBMC', 'dbpath')) else: log.info('Could not find the XBMC MyVideos db at ' + cherrypy.config.get('config').get('XBMC', 'dbpath')) log.info('Adding movie to database: %s' % movie.name) if movie.id: exists = Db.query(Movie).filter_by(movieDb=movie.id).first() else: exists = Db.query(Movie).filter_by(imdb=movie.imdb).first() if exists: log.info('Movie already exists, do update.') # Delete old qualities for x in exists.queue: x.active = False Db.flush() new = exists else: new = Movie() Db.add(new) # Update the stuff new.status = u'want' new.name = movie.name new.imdb = movie.imdb new.movieDb = movie.id new.quality = quality new.year = year if year and movie.year == 'None' else movie.year Db.flush() # Add qualities to the queue quality = Db.query(QualityTemplate).filter_by(id=quality).one() for type in quality.types: queue = MovieQueue() queue.qualityType = type.type queue.movieId = new.id queue.order = type.order queue.active = True queue.completed = False queue.waitFor = 0 if type.markComplete else quality.waitFor queue.markComplete = type.markComplete Db.add(queue) Db.flush() #Get xml from themoviedb and save to cache self.searchers.get('movie').getExtraInfo(new.id, overwrite=True) #gogo find nzb for added movie via Cron self.cron.get('yarr').forceCheck(new.id) self.flash.add('movie-' + str(new.id), '"%s" (%s) added.' % (new.name, new.year))
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 getExtraInfo(self, movie, overwrite = False): if(type(movie) in [int, str, unicode]): movie = Db.query(Movie).filter_by(id = movie).one() # Try and update if no tmdbId if not movie.movieDb: result = self.theMovieDb.findByImdbId(movie.imdb) if result: movie.movieDb = result.id Db.flush() if not movie.movieDb: log.error('Search failed for "%s", no TheMovieDB id.' % movie.name) return movieId = movie.id theMovieDbId = movie.movieDb self.cacheExtra(theMovieDbId, overwrite) xmlFile = os.path.join(cherrypy.config.get('cachePath'), 'xml', str(theMovieDbId) + '.xml') if os.path.isfile(xmlFile): if overwrite: log.info('Getting extra movie info for %s.' % movie.name) handle = open(xmlFile, 'r') movieInfo = self.theMovieDb.getItems(handle, 'movies/movie') if not movieInfo: return movieInfo = movieInfo[0] # rating rating = self.theMovieDb.gettextelement(movieInfo, 'rating') self.saveExtra(movieId, 'rating', rating) overview = self.theMovieDb.gettextelement(movieInfo, 'overview') if overview: overview = self.theMovieDb.toSaveString(overview) self.saveExtra(movieId, 'overview', overview) hasPosterThumb = False images = movieInfo.findall('images/image') hasPosterCover = False hasPosterMid = False hasPosterThumb = False for image in images: imageFile = str(theMovieDbId) + '-' + image.get('type') + '-' + image.get('size') + '.jpg' if image.get('type') == 'poster' and image.get('size') == 'cover' and not hasPosterCover: poster = self.theMovieDb.saveImage(image.get('url'), imageFile) if poster: self.saveExtra(movieId, 'poster_cover', poster) hasPosterCover = True if image.get('type') == 'poster' and image.get('size') == 'mid' and not hasPosterMid: poster = self.theMovieDb.saveImage(image.get('url'), imageFile) if poster: self.saveExtra(movieId, 'poster_mid', poster) hasPosterMid = True if image.get('type') == 'poster' and image.get('size') == 'thumb' and not hasPosterThumb: poster = self.theMovieDb.saveImage(image.get('url'), imageFile) if poster: self.saveExtra(movieId, 'poster_thumb', poster) hasPosterThumb = True handle.close()
def save(self, **data): ''' Save all config settings ''' config = cherrypy.config.get('config') # catch checkboxes bools = filter(lambda s: not data.get(s), [ 'global.launchbrowser', 'global.updater', 'XBMC.enabled', 'XBMC.onSnatch', 'NMJ.enabled', 'PLEX.enabled', 'PROWL.enabled', 'PROWL.onSnatch', 'GROWL.enabled', 'GROWL.onSnatch', 'Notifo.enabled', 'Notifo.onSnatch', 'Boxcar.enabled', 'Boxcar.onSnatch', 'NMA.enable', 'NMA.onSnatch', 'Twitter.enabled', 'Twitter.onSnatch', 'Trakt.notification_enabled', 'Trakt.watchlist_remove', 'Trakt.watchlist_enabled', 'Trakt.dontaddcollection', 'Meta.enabled', 'MovieETA.enabled', 'Renamer.enabled', 'Renamer.trailerQuality', 'Renamer.cleanup', 'Torrents.enabled', 'NZB.enabled', 'NZBMatrix.enabled', 'NZBMatrix.english', 'NZBMatrix.ssl', 'NZBsRUS.enabled', 'newzbin.enabled', 'NZBsorg.enabled', 'newznab.enabled', 'x264.enabled', 'Subtitles.enabled', 'Subtitles.addLanguage', 'MovieRSS.enabled', 'KinepolisRSS.enabled', ]) data.update(data.fromkeys(bools, False)) # Do quality order order = data.get('Quality.order').split(',') for id in order: qo = Db.query(QualityTemplate).filter_by(id=int(id)).one() qo.order = order.index(id) Db.flush() del data['Quality.order'] # Save templates if data.get('Quality.templates'): templates = json.loads(data.get('Quality.templates')) Qualities().saveTemplates(templates) del data['Quality.templates'] # Save post data for name in data: section = name.split('.')[0] var = name.split('.')[1] config.set(section, var, data[name]) # Change cron interval self.cron.get('yarr').setInterval(config.get('Intervals', 'search')) config.save() self.flash.add('config', 'Settings successfully saved.') return redirect(cherrypy.request.headers.get('referer'))
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 alreadyTried(self, nzb, movie): return Db.query(History).filter( and_(History.movie == movie, History.value == str(nzb.id) + '-' + str(nzb.size), History.status == u'ignore')).first()
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 all(self): activeMovies = Db.query(Movie).filter( or_(Movie.status == u'want', Movie.status == u'waiting')).all() for movie in activeMovies: etaQueue.put({'movie': movie})
def determineMovie(self, movie): result = False movieName = self.cleanName(movie['folder']) movieYear = self.findYear(movie['folder']) #check to see if the downloaded movie nfo file agrees with what we thought we were downloading if movie['info']['cpnfoImdb'] and movie['info']['imdb']: cpnfoimdb = 'tt' + movie['info']['cpnfoImdb'].replace("tt", '') nfoimdb = 'tt' + movie['info']['imdb'].replace("tt", '') if cpnfoimdb != nfoimdb: log.info( "Downloaded movie's nfo has imdb id that doesn't match what we though we downloaded" ) movie['info']['imdb'] = cpnfoimdb if movie['info']['imdb']: byImdb = self.getMovieByIMDB(movie['info']['imdb']) if byImdb: return byImdb else: result = cherrypy.config['searchers']['movie'].findByImdbId( movie['info']['imdb']) if not result: # Check and see if name is in queue try: queue = Db.query(MovieQueue).filter_by( name=movie['folder']).first() if queue: log.info('Found movie via MovieQueue.') return queue.Movie except: pass # Find movie via movie name try: m = Db.query(Movie).filter_by(name=movieName).first() if m: log.info('Found movie via moviename.') return m except: pass # Try and match the movies via filenaming for file in movie['files']: dirnames = movie['path'].lower().replace( unicode(self.config.get('Renamer', 'download')).lower(), '').split(os.path.sep) dirnames.append(file['filename']) dirnames.reverse() for dir in dirnames: dir = self.cleanName(dir) # last resort, match every word in path to db lastResort = {} dirSplit = re.split('\W+', dir.lower()) for s in dirSplit: if s: results = Db.query(Movie).filter( Movie.name.like('%' + s + '%')).filter_by( year=movieYear).all() for r in results: lastResort[r.id] = r for l in lastResort.itervalues(): wordCount = 0 for word in dirSplit: if word in l.name.lower(): wordCount += 1 if wordCount == len(dirSplit) and len(dirSplit) > 0: return l # Search tMDB if movieName and not movieName in ['movie']: log.info('Searching for "%s".' % movie['folder']) result = cherrypy.config['searchers']['movie'].find( movieName + ' ' + movieYear, limit=1) if result: movie = self.getMovieByIMDB(result.imdb) if not movie: new = Movie() Db.add(new) try: # Add found movie as downloaded new.status = u'downloaded' new.name = result.name new.imdb = result.imdb new.movieDb = result.id new.year = result.year Db.flush() return new except Exception, e: log.error('Movie could not be added to database %s. %s' % (result, e)) else: return movie
def _checkMovieExists(self, movie, qualityId): if cherrypy.config.get('config').get('XBMC', 'dbpath'): dbfile = None for root, dirs, files in os.walk( cherrypy.config.get('config').get('XBMC', 'dbpath')): for file in files: if file.startswith('MyVideos'): dbfile = os.path.join(root, file) if dbfile: #------Opening connection to XBMC DB------ connXbmc = MySqlite.connect(dbfile) if connXbmc: log.debug('Checking if movie exists in XBMC by IMDB id:' + movie.imdb) connXbmc.row_factory = MySqlite.Row cXbmc = connXbmc.cursor() #sqlQuery = 'select c09 from movie where c09="' + movie.imdb + '"' sqlQuery = self._generateSQLQuery(movie) cXbmc.execute(sqlQuery) #------End of Opening connection to XBMC DB------ inXBMC = False for rowXbmc in cXbmc: # do a final check just to be sure log.debug('Found in XBMC:' + rowXbmc["c09"]) if movie.imdb == rowXbmc["c09"]: inXBMC = True else: inXBMC = False cXbmc.close() if inXBMC: log.info('Movie already exists in XBMC, skipping.') return True else: log.info( 'Could not connect to the XBMC database at ' + cherrypy.config.get('config').get('XBMC', 'dbpath')) else: log.info('Could not find the XBMC MyVideos db at ' + cherrypy.config.get('config').get('XBMC', 'dbpath')) if cherrypy.config.get('config').get('XBMC', 'useWebAPIExistingCheck'): quality = Db.query(QualityTemplate).filter_by(id=qualityId).one() acceptableQualities = [ x.type for x in filter(lambda x: x.markComplete, quality.types) ] log.debug( "acceptableQualities = %s" % acceptableQualities ) # log.info(["%s %s %s %s %s" % (x.id, x.markComplete, x.order, x.quality, x.type) for x in sorted(quality.types, key=lambda x:x.order)]) xbmc = XBMC() sqlQuery = self._generateSQLQuery(movie) xbmcResultsHosts = xbmc.queryVideoDatabase(sqlQuery) if xbmcResultsHosts: for xmbcResults in xbmcResultsHosts: records = xmbcResults.strip().split("<record>") for xmbcResult in records: xmbcResult = xmbcResult.replace("</record>", "") if xmbcResult == "": continue fields = [ x.replace("<field>", "") for x in filter(lambda x: x.startswith("<field>"), xmbcResult.split("</field>")) ] log.debug("fields = %s" % fields) if len(fields) < 5: log.error("Invalid response: %s" % xmbcResult) continue imdbId, strVideoCodec, fVideoAspect, iVideoWidth, iVideoHeight = fields[: 5] if imdbId == movie.imdb: existingMovieQuality = self._classifyQuality( strVideoCodec, fVideoAspect, iVideoWidth, iVideoHeight) if existingMovieQuality == "Unknown": log.info( "Unable to classify movie: strVideoCodec=%s, fVideoAspect=%s, iVideoWidth=%s, iVideoHeight=%s" % (strVideoCodec, fVideoAspect, iVideoWidth, iVideoHeight)) treatUnknownAs = cherrypy.config.get('config').get( 'XBMC', 'unknown') if treatUnknownAs and treatUnknownAs != '': existingMovieQuality = treatUnknownAs if existingMovieQuality in acceptableQualities: log.info( 'Movie already exists in XBMC (web API call), with acceptable quality (%s), skipping.' % (existingMovieQuality)) return True else: log.info( 'Movie already exists in XBMC (web API call), but quality (%s) incorrect (require: %s).' % (existingMovieQuality, acceptableQualities)) return False