Example #1
0
    def _checkMovieExists(self, movie):
        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()
                    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 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'))

        xbmc = XBMC()
        xbmcResults = xbmc.queryVideoDatabase(
            'select c09 from movie where c09="' + movie.imdb + '"')

        if xbmcResults:
            for xmbcResult in xbmcResults:
                c09 = xmbcResult.replace("<field>",
                                         "").replace("</field>", "").strip()
                if c09 == movie.imdb:
                    log.info(
                        'Movie already exists in XBMC (web API call), skipping.'
                    )
                    return True
#                log.info("'%s' %s" % (c09, c09==movie.imdb))

        return False
Example #2
0
    def _checkMovieExists(self, movie):
        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()
                    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 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'):
           xbmc = XBMC()
           xbmcResultsHosts = xbmc.queryVideoDatabase('select c09 from movie where c09="' + movie.imdb + '"')

           if xbmcResultsHosts:
              for xmbcResults in xbmcResultsHosts:
                   for xmbcResult in [x.strip() for x in xmbcResults.strip().split('\n')]:
                       if xmbcResult == "":
                           continue
                 
                       c09 = xmbcResult.replace("<record><field>", "").replace("</field></record>", "").replace("<field>", "").replace("</field>", "").strip()
                       if c09==movie.imdb:
                           log.info('Movie already exists in XBMC (web API call), skipping.')
                           return True

        return False
Example #3
0
    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
Example #4
0
    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
Example #5
0
    def _checkMovieExists(self, movie):
        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'):
            xbmc = XBMC()
            #sqlQuery = 'select c09 from movie where c09="' + movie.imdb + '"'
            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.strip()
                        xmbcResult = xmbcResult.replace("</record>", "")
                        #                        xmbcResult = xmbcResult.strip()

                        if xmbcResult == "":
                            continue

                        fields = filter(lambda x: x != "", [
                            field.replace("</field>", "")
                            for field in xmbcResult.split("<field>")
                        ])

                        log.debug("fields = %s" % fields)
                        c09 = fields[0]
                        if c09 == movie.imdb:
                            log.info(
                                'Movie already exists in XBMC (web API call), skipping.'
                            )
                            return True

        return False