Exemplo n.º 1
0
    def which_type(self, path):
        """
        Analyzes the image provided and attempts to determine whether it is a poster or banner.
        
        returns: BANNER, POSTER if it concluded one or the other, or None if the image was neither (or didn't exist)
        
        path: full path to the image
        """

        if not ek.ek(os.path.isfile, path):
            logger.log(u"Couldn't check the type of " + str(path) + " cause it doesn't exist", logger.WARNING)
            return None

        # use hachoir to parse the image for us
        img_parser = createParser(path)
        img_metadata = extractMetadata(img_parser)

        if not img_metadata:
            logger.log(u"Unable to get metadata from " + str(path) + ", not using your existing image", logger.DEBUG)
            return None

        img_ratio = float(img_metadata.get('width')) / float(img_metadata.get('height'))

        img_parser.stream._input.close()

        # most posters are around 0.68 width/height ratio (eg. 680/1000)
        if 0.55 < img_ratio < 0.8:
            return self.POSTER

        # most banners are around 5.4 width/height ratio (eg. 758/140)
        elif 5 < img_ratio < 6:
            return self.BANNER
        else:
            logger.log(u"Image has size ratio of " + str(img_ratio) + ", unknown type", logger.WARNING)
            return None
Exemplo n.º 2
0
    def which_type(self, path):
        """
        Analyzes the image provided and attempts to determine whether it is a poster or banner.
        
        returns: BANNER, POSTER if it concluded one or the other, or None if the image was neither (or didn't exist)
        
        path: full path to the image
        """

        if not ek.ek(os.path.isfile, path):
            logger.log(u"Couldn't check the type of "+str(path)+" cause it doesn't exist", logger.WARNING)
            return None

        # use hachoir to parse the image for us
        img_parser = createParser(path)
        img_metadata = extractMetadata(img_parser)

        if not img_metadata:
            logger.log(u"Unable to get metadata from "+str(path)+", not using your existing image", logger.DEBUG)
            return None
        
        img_ratio = float(img_metadata.get('width'))/float(img_metadata.get('height'))

        img_parser.stream._input.close()

        # most posters are around 0.68 width/height ratio (eg. 680/1000)
        if 0.55 < img_ratio < 0.8:
            return self.POSTER
        
        # most banners are around 5.4 width/height ratio (eg. 758/140)
        elif 5 < img_ratio < 6:
            return self.BANNER
        else:
            logger.log(u"Image has size ratio of "+str(img_ratio)+", unknown type", logger.WARNING)
            return None
Exemplo n.º 3
0
    def which_type(self, path):
        if not ek.ek(os.path.isfile, path):
            logger.log(
                u"Couldn't check the type of " + str(path) +
                " cause it doesn't exist", logger.WARNING)
            return None
        img_parser = createParser(path)
        img_metadata = extractMetadata(img_parser)

        if not img_metadata:
            logger.log(
                u"Unable to get metadata from " + str(path) +
                ", not using your existing image", logger.DEBUG)
            return None

        img_ratio = float(img_metadata.get('width')) / float(
            img_metadata.get('height'))

        img_parser.stream._input.close()

        if 0.55 < img_ratio < 0.8:
            return self.POSTER
        elif 5 < img_ratio < 6:
            return self.BANNER
        else:
            logger.log(
                u"Image has size ratio of " + str(img_ratio) +
                ", unknown type", logger.WARNING)
            return None
Exemplo n.º 4
0
    def which_type(self, path):
        """
        Analyzes the image provided and attempts to determine whether it is a poster, banner or fanart.

        returns: BANNER, POSTER, FANART or None if image type is not detected or doesn't exist

        path: full path to the image
        """

        if not ek.ek(os.path.isfile, path):
            logger.log(
                u'File does not exist to determine image type of %s' % path,
                logger.WARNING)
            return None

        # use hachoir to parse the image for us
        img_parser = createParser(path)
        img_metadata = extractMetadata(img_parser)

        if not img_metadata:
            logger.log(
                u'Unable to extract metadata from %s, not using existing image'
                % path, logger.DEBUG)
            return None

        img_ratio = float(img_metadata.get('width')) / float(
            img_metadata.get('height'))

        img_parser.stream._input.close()

        msg_success = u'Treating image as %s'\
                      + u' with extracted aspect ratio from %s' % path.replace('%', '%%')
        # most posters are around 0.68 width/height ratio (eg. 680/1000)
        if 0.55 < img_ratio < 0.8:
            logger.log(msg_success % 'poster', logger.DEBUG)
            return self.POSTER

        # most banners are around 5.4 width/height ratio (eg. 758/140)
        elif 5 < img_ratio < 6:
            logger.log(msg_success % 'banner', logger.DEBUG)
            return self.BANNER

        # most fanart are around 1.7 width/height ratio (eg. 1280/720 or 1920/1080)
        elif 1.7 < img_ratio < 1.8:
            if 500 < img_metadata.get('width'):
                logger.log(msg_success % 'fanart', logger.DEBUG)
                return self.FANART

            logger.log(
                u'Image found with fanart aspect ratio but less than 500 pixels wide, skipped',
                logger.WARNING)
            return None
        else:
            logger.log(
                u'Image not useful with size ratio %s, skipping' % img_ratio,
                logger.WARNING)
            return None
Exemplo n.º 5
0
    def _verify_download(self, file_name=None):
        """
        Checks the saved file to see if it was actually valid, if not then consider the download a failure.
        """

        # primitive verification of torrents, just make sure we didn't get a text file or something
        if self.providerType == GenericProvider.TORRENT:
            parser = createParser(file_name)
            if not parser or parser._getMimeType() != 'application/x-bittorrent':
                logger.log(u"Result is not a valid torrent file", logger.WARNING)
                return False

        return True
Exemplo n.º 6
0
 def which_type(self, path):
     if not ek.ek(os.path.isfile, path):
         return None
     img_parser = createParser(path)
     img_metadata = extractMetadata(img_parser)
     img_ratio = float(img_metadata.get('width'))/float(img_metadata.get('height'))
     
     if 0.55 < img_ratio < 0.8:
         return self.POSTER
     elif 5 < img_ratio < 6:
         return self.BANNER
     else:
         logger.log(u"Image has size ratio of "+str(img_ratio)+", unknown type", logger.WARNING)
         return None
    def which_type(self, path):
        if not ek.ek(os.path.isfile, path):
            logger.log(u"Couldn't check the type of "+str(path)+" cause it doesn't exist", logger.WARNING)
            return None
        img_parser = createParser(path)
        img_metadata = extractMetadata(img_parser)

        if not img_metadata:
            logger.log(u"Unable to get metadata from "+str(path)+", not using your existing image", logger.DEBUG)
            return None
        
        img_ratio = float(img_metadata.get('width'))/float(img_metadata.get('height'))

        img_parser.stream._input.close()

        if 0.55 < img_ratio < 0.8:
            return self.POSTER
        elif 5 < img_ratio < 6:
            return self.BANNER
        else:
            logger.log(u"Image has size ratio of "+str(img_ratio)+", unknown type", logger.WARNING)
            return None