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 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 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 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 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 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 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 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 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 addToHistory(self, movie, file, key, data): key = self.getKey(key) movieId = 0 if not movie else movie.id new = SubtitleHistory() new.movie = movieId new.file = latinToAscii(file) new.subtitle = key new.status = u'downloaded' new.data = str(data) Db.add(new) 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 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.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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 __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 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 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 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): ''' 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 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 _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 renameFiles(self, movie): ''' rename files based on movie data & conf ''' multiple = False if len(movie['files']) > 1: multiple = True destination = self.conf('destination') folderNaming = self.conf('foldernaming') fileNaming = self.conf('filenaming') # Remove weird chars from moviename moviename = re.sub(r"[\x00\/\\:\*\?\"<>\|]", '', movie['info'].get('name')) # Put 'The' at the end namethe = moviename if moviename[:4].lower() == 'the ': namethe = moviename[4:] + ', The' replacements = { 'cd': '', 'cdNr': '', 'ext': 'mkv', 'namethe': namethe.strip(), 'thename': moviename.strip(), 'year': movie['info']['year'], 'first': namethe[0].upper(), 'quality': movie['info']['quality'], 'video': movie['info']['codec']['video'], 'audio': movie['info']['codec']['audio'], 'group': movie['info']['group'], 'resolution': movie['info']['resolution'], 'sourcemedia': movie['info']['sourcemedia'] } if multiple: cd = 1 justAdded = [] finalDestination = None #clean up post-processing script ppScriptName = movie['info'].get('ppScriptName') ppDirName = self.config.get('Sabnzbd', 'ppDir') if ppScriptName: if ppDirName: ppPath = os.path.join(ppDirName, ppScriptName) try: os.remove(ppPath) log.info("Removed post-processing script: %s" % ppPath) except: log.info("Couldn't remove post-processing script: %s" % ppPath) else: log.info("Don't know where the post processing script is located, not removing %s" % ppScriptName) filenames = [] for file in movie['files']: log.info('Trying to find a home for: %s' % latinToAscii(file['filename'])) replacements['ext'] = file['ext'] if multiple: replacements['cd'] = ' cd' + str(cd) replacements['cdNr'] = ' ' + str(cd) replacements['original'] = file['filename'] folder = self.doReplace(folderNaming, replacements) filename = self.doReplace(fileNaming, replacements) filenames.append(filename) old = os.path.join(movie['path'], file['filename']) dest = os.path.join(destination, folder, filename) finalDestination = os.path.dirname(dest) if not os.path.isdir(finalDestination): try: log.info('Creating directory %s' % finalDestination) os.makedirs(finalDestination) shutil.copymode(destination, finalDestination) except OSError: log.error('Failed changing permissions %s' % finalDestination) # Remove old if better quality removed = self.removeOld(os.path.join(destination, folder), justAdded, movie['info']['size']) if not os.path.isfile(dest) and removed: log.info('Moving file "%s" to %s.' % (latinToAscii(old), dest)) if not _move(old, dest): break justAdded.append(dest) else: try: log.error('File %s already exists or not better.' % latinToAscii(filename)) path = file['path'].split(os.sep) path.extend(['_EXISTS_' + path.pop()]) old = file['path'] dest = os.sep.join(path) _move(old, dest) except: log.error('Could not extend path name.') break #get subtitle if any & move for type in movie['subtitles']: if len(movie['subtitles'][type]) > 0: log.info('Moving matching subtitle.') subtitle = movie['subtitles'][type].pop(0) replacements['original'] = subtitle['filename'] replacements['ext'] = subtitle['ext'] subDest = os.path.join(destination, folder, self.doReplace(fileNaming, replacements)) old = os.path.join(movie['path'], subtitle['filename']) if not _move(old, subDest): break justAdded.append(subDest) # Add to ignore list when removing stuff. # Add to renaming history log.debug('renamehistory start') h = RenameHistory() Db.add(h) try: h.movieQueue = movie['queue'].id except: h.movieQueue = 0 h.old = unicode(old.decode('utf-8')) h.new = unicode(dest.decode('utf-8')) Db.flush() log.debug('renamehistory end') if multiple: cd += 1 # Mark movie downloaded log.debug('queue downloaded start') if movie['queue'] and movie['queue'].id > 0: if movie['queue'].markComplete: movie['movie'].status = u'downloaded' movie['queue'].completed = True Db.flush() log.debug('queue downloaded end') return { 'directory': finalDestination, 'filenames': filenames }
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
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 _search(self, movie, force=False): # Stop caching ffs! Db.expire_all() # Check release date and search for appropriate qualities preReleaseSearch = False dvdReleaseSearch = False now = int(time.time()) # Search all if ETA is unknow, but try update ETA for next time. log.debug('Calculate ETA') checkETA = False if not movie.eta: checkETA = True preReleaseSearch = True dvdReleaseSearch = True else: # Prerelease 1 week before theaters if movie.eta.theater <= now + 604800: preReleaseSearch = True # dvdRelease 6 weeks before dvd release if movie.eta.dvd <= now + 3628800: preReleaseSearch = True dvdReleaseSearch = True # Dvd date is unknown but movie is in theater already if movie.eta.dvd == 0 and movie.eta.theater > now: dvdReleaseSearch = False # Force ETA check if movie.eta.lastCheck < now: checkETA = True # Minimal week interval for ETA check if checkETA and self.config.get('MovieETA', 'enabled'): cherrypy.config.get('searchers').get('etaQueue').put( {'id': movie.id}) for queue in movie.queue: # Movie already found, don't search further if queue.completed: log.debug( '%s already completed for "%s". Not searching for any qualities below.' % (queue.qualityType, movie.name)) return True # only search for active and not completed, minimal 1 min since last search if queue.active and not queue.completed and not self.abort and not self.stop: #skip if no search is set log.debug('Needs a search?') if (not ((preReleaseSearch and queue.qualityType in Qualities.preReleases) or (dvdReleaseSearch and not queue.qualityType in Qualities.preReleases)) ) and not queue.lastCheck < (now - int( self.config.get('Intervals', 'search')) * 7200): continue log.debug('Start searching for movie: %s' % movie.name) highest = self.provider.find(movie, queue) log.debug('End searching for movie: %s' % movie.name) #send highest to SABnzbd & mark as snatched if highest: log.debug('Found highest') #update what I found queue.name = latinToAscii(highest.name) queue.link = highest.detailUrl Db.flush() waitFor = queue.waitFor * (60 * 60 * 24) if queue.markComplete or ( not queue.markComplete and highest.date + waitFor < time.time()): time.sleep(10) # Give these APIs air! if self.config.get( 'NZB', 'sendTo' ) == 'Sabnzbd' and highest.type == 'nzb': success = self.sabNzbd.send(highest, movie.imdb) elif self.config.get( 'NZB', 'sendTo' ) == 'Nzbget' and highest.type == 'nzb': success = self.nzbGet.send(highest) elif self.config.get( 'Torrents', 'sendTo' ) == 'Transmission' and highest.type == 'torrent': success = self.transmission.send( highest, movie.imdb) else: success = self.blackHole(highest) else: success = False log.info('Found %s but waiting for %d hours.' % (highest.name, ((highest.date + waitFor) - time.time()) / (60 * 60))) # Set status if success: log.debug('Success') movie.status = u'snatched' if queue.markComplete else u'waiting' movie.dateChanged = datetime.datetime.now() queue.lastCheck = now queue.completed = True Db.flush() # Add to history h = History() h.movie = movie.id h.value = str(highest.id) + '-' + str(highest.size) h.status = u'snatched' Db.add(h) Db.flush() # Notify PROWL if self.config.get('PROWL', 'onSnatch'): log.debug('PROWL') prowl = PROWL() prowl.notify(highest.name, 'Download Started') # Notify XBMC if self.config.get('XBMC', 'onSnatch'): log.debug('XBMC') xbmc = XBMC() xbmc.notify('Snatched %s' % highest.name) # Notify GROWL if self.config.get('GROWL', 'onSnatch'): log.debug('GROWL') growl = GROWL() growl.notify('Snatched %s' % highest.name, 'Download Started') # Notify Notifo if self.config.get('Notifo', 'onSnatch'): log.debug('Notifo') notifo = Notifo() notifo.notify('%s' % highest.name, "Snatched:") # Notify SNS if self.config.get('SNS', 'onSnatch'): log.debug('SNS') sns = SNS() sns.notify('%s' % highest.name, "Snatched:") # Notify Boxcar if self.config.get('Boxcar', 'onSnatch'): log.debug('Boxcar') boxcar = Boxcar() boxcar.notify('%s' % highest.name, "Snatched:") # Notify NotifyMyAndroid if self.config.get('NMA', 'onSnatch'): log.debug('NotifyMyAndroid') nma = NMA() nma.notify('Download Started', 'Snatched %s' % highest.name) # Notify NotifyMyWindowsPhone if self.config.get('NMWP', 'onSnatch'): log.debug('NotifyMyWindowsPhone') nmwp = NMWP() nmwp.notify('Download Started', 'Snatched %s' % highest.name) # Notify Twitter if self.config.get('Twitter', 'onSnatch'): log.debug('Twitter') twitter = Twitter() twitter.notify('Download Started', 'Snatched %s' % highest.name) return True queue.lastCheck = now Db.flush() return False
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})