示例#1
0
    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))
示例#2
0
    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))
示例#3
0
    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