示例#1
0
    def getComicMetadata(self, path):
        ca = ComicArchive(
            path, default_image_path=AppFolders.missingPath("page.png"))

        if ca.seemsToBeAComicArchive():

            if ca.hasMetadata(MetaDataStyle.CIX):
                style = MetaDataStyle.CIX
            elif ca.hasMetadata(MetaDataStyle.CBI):
                style = MetaDataStyle.CBI
            elif ca.hasMetadata(MetaDataStyle.COMET):
                style = MetaDataStyle.COMET
            elif ca.hasMetadata(MetaDataStyle.CBW):
                style = MetaDataStyle.CBW
            else:
                logging.warning(u"Library: File Has No ComicMeta Data")
                if ca.hasMetadata(MetaDataStyle.CALIBRE):
                    style = MetaDataStyle.CALIBRE
                elif ca.hasMetadata(MetaDataStyle.EPUB):
                    style = MetaDataStyle.EPUB
                else:
                    style = None

            if style is not None:
                md = ca.readMetadata(style)
                if md.isEmpty:
                    md = ca.metadataFromFilename()
            else:
                # No metadata in comic.  make some guesses from the filename
                md = ca.metadataFromFilename()

            # patch version 2
            if (md.title is None or md.title
                    == "") and md.issue is None and not md.series is None:
                md.title = md.series
                md.series = None

            md.fingerprint = ca.fingerprint()
            md.path = ca.path

            md.page_count = ca.page_count

            md.mod_ts = datetime.utcfromtimestamp(getmtime(ca.path))
            md.filesize = os.path.getsize(md.path)
            md.hash = ""

            #thumbnail generation
            image_data = ca.getPage(0, AppFolders.missingPath("cover.png"))

            #now resize it
            thumb = StringIO.StringIO()

            try:
                utils.resize(image_data, (400, 400), thumb)
                md.thumbnail = thumb.getvalue()
            except:
                md.thumbnail = None
            return md
        return None
示例#2
0
    def getComicMetadata(self, path):
        ca = ComicArchive(path,  default_image_path=AppFolders.missingPath("page.png"))

        
        if ca.seemsToBeAComicArchive():

            if ca.hasMetadata( MetaDataStyle.CIX ):
                style = MetaDataStyle.CIX
            elif ca.hasMetadata( MetaDataStyle.CBI ):
                style = MetaDataStyle.CBI
            elif ca.hasMetadata( MetaDataStyle.COMET ):
                style = MetaDataStyle.COMET
            elif ca.hasMetadata( MetaDataStyle.CBW ):
                style = MetaDataStyle.CBW
            else:
                logging.warning(u"Library: File Has No ComicMeta Data")
                if ca.hasMetadata( MetaDataStyle.CALIBRE ):
                    style = MetaDataStyle.CALIBRE
                elif ca.hasMetadata( MetaDataStyle.EPUB ):
                    style = MetaDataStyle.EPUB
                else:
                    style = None
                
            if style is not None:
                md = ca.readMetadata(style)
                if md.isEmpty:
                     md = ca.metadataFromFilename()
            else:
                # No metadata in comic.  make some guesses from the filename
                md = ca.metadataFromFilename()
            
            # patch version 2
            if (md.title is None or md.title == "") and md.issue is None and not md.series is None:
                md.title = md.series
                md.series = None
            
            md.fingerprint = ca.fingerprint()
            md.path = ca.path
            
            md.page_count = ca.page_count
            
            md.mod_ts = datetime.utcfromtimestamp(getmtime(ca.path))
            md.filesize = os.path.getsize(md.path)
            md.hash = ""

            #thumbnail generation
            image_data = ca.getPage(0, AppFolders.missingPath("cover.png"))
            
            #now resize it
            thumb = StringIO.StringIO()
            
            try:
                utils.resize(image_data, (400, 400), thumb)
                md.thumbnail = thumb.getvalue()
            except:
                md.thumbnail = None
            return md
        return None
示例#3
0
def _extractCover(tmp_file_name, original_file_extension, rarExceutable):
    cover_data = extension = None
    if use_comic_meta:
        archive = ComicArchive(tmp_file_name)
        for index, name in enumerate(archive.getPageNameList()):
            ext = os.path.splitext(name)
            if len(ext) > 1:
                extension = ext[1].lower()
                if extension == '.jpg' or extension == '.jpeg':
                    cover_data = archive.getPage(index)
                    break
    else:
        if original_file_extension.upper() == '.CBZ':
            cf = zipfile.ZipFile(tmp_file_name)
            for name in cf.namelist():
                ext = os.path.splitext(name)
                if len(ext) > 1:
                    extension = ext[1].lower()
                    if extension == '.jpg' or extension == '.jpeg':
                        cover_data = cf.read(name)
                        break
        elif original_file_extension.upper() == '.CBT':
            cf = tarfile.TarFile(tmp_file_name)
            for name in cf.getnames():
                ext = os.path.splitext(name)
                if len(ext) > 1:
                    extension = ext[1].lower()
                    if extension == '.jpg' or extension == '.jpeg':
                        cover_data = cf.extractfile(name).read()
                        break
        elif original_file_extension.upper() == '.CBR' and use_rarfile:
            try:
                rarfile.UNRAR_TOOL = rarExceutable
                cf = rarfile.RarFile(tmp_file_name)
                for name in cf.getnames():
                    ext = os.path.splitext(name)
                    if len(ext) > 1:
                        extension = ext[1].lower()
                        if extension == '.jpg' or extension == '.jpeg':
                            cover_data = cf.read(name)
                            break
            except Exception as e:
                log.debug('Rarfile failed with error: %s', e)

    prefix = os.path.dirname(tmp_file_name)
    if cover_data:
        tmp_cover_name = prefix + '/cover' + extension
        image = open(tmp_cover_name, 'wb')
        image.write(cover_data)
        image.close()
    else:
        tmp_cover_name = None
    return tmp_cover_name
示例#4
0
def _extract_cover(tmp_file_name, original_file_extension, rar_executable):
    cover_data = extension = None
    if use_comic_meta:
        archive = ComicArchive(tmp_file_name, rar_exe_path=rar_executable)
        for index, name in enumerate(archive.getPageNameList()):
            ext = os.path.splitext(name)
            if len(ext) > 1:
                extension = ext[1].lower()
                if extension in cover.COVER_EXTENSIONS:
                    cover_data = archive.getPage(index)
                    break
    else:
        cover_data, extension = _extract_cover_from_archive(
            original_file_extension, tmp_file_name, rar_executable)
    return cover.cover_processing(tmp_file_name, cover_data, extension)
示例#5
0
def extractCover(tmp_file_name, original_file_extension):
    archive = ComicArchive(tmp_file_name)
    cover_data = None
    ext = os.path.splitext(archive.getPageName(0))
    if len(ext) > 1:
        extension = ext[1].lower()
        if extension == '.jpg' or extension == '.jpeg':
            cover_data = archive.getPage(0)
    prefix = os.path.dirname(tmp_file_name)
    if cover_data:
        tmp_cover_name = prefix + '/cover' + extension
        image = open(tmp_cover_name, 'wb')
        image.write(cover_data)
        image.close()
    else:
        tmp_cover_name = None
    return tmp_cover_name
示例#6
0
def _extractCover(tmp_file_name, original_file_extension, rarExecutable):
    cover_data = extension = None
    if use_comic_meta:
        archive = ComicArchive(tmp_file_name, rar_exe_path=rarExecutable)
        for index, name in enumerate(archive.getPageNameList()):
            ext = os.path.splitext(name)
            if len(ext) > 1:
                extension = ext[1].lower()
                if extension in ('.jpg', '.jpeg', '.png', '.webp'):
                    cover_data = archive.getPage(index)
                    break
    else:
        if original_file_extension.upper() == '.CBZ':
            cf = zipfile.ZipFile(tmp_file_name)
            for name in cf.namelist():
                ext = os.path.splitext(name)
                if len(ext) > 1:
                    extension = ext[1].lower()
                    if extension in ('.jpg', '.jpeg', '.png', '.webp'):
                        cover_data = cf.read(name)
                        break
        elif original_file_extension.upper() == '.CBT':
            cf = tarfile.TarFile(tmp_file_name)
            for name in cf.getnames():
                ext = os.path.splitext(name)
                if len(ext) > 1:
                    extension = ext[1].lower()
                    if extension in ('.jpg', '.jpeg', '.png', '.webp'):
                        cover_data = cf.extractfile(name).read()
                        break
        elif original_file_extension.upper() == '.CBR' and use_rarfile:
            try:
                rarfile.UNRAR_TOOL = rarExecutable
                cf = rarfile.RarFile(tmp_file_name)
                for name in cf.getnames():
                    ext = os.path.splitext(name)
                    if len(ext) > 1:
                        extension = ext[1].lower()
                        if extension in ('.jpg', '.jpeg', '.png', '.webp'):
                            cover_data = cf.read(name)
                            break
            except Exception as e:
                log.debug('Rarfile failed with error: %s', e)
    return _cover_processing(tmp_file_name, cover_data, extension)
def extractCover(tmp_file_name, original_file_extension):
    if use_comic_meta:
        archive = ComicArchive(tmp_file_name)
        cover_data = None
        for index, name in enumerate(archive.getPageNameList()):
            ext = os.path.splitext(name)
            if len(ext) > 1:
                extension = ext[1].lower()
                if extension == '.jpg' or extension == '.jpeg':
                    cover_data = archive.getPage(index)
                    break
    else:
        if original_file_extension.upper() == '.CBZ':
            cf = zipfile.ZipFile(tmp_file_name)
            for name in cf.namelist():
                ext = os.path.splitext(name)
                if len(ext) > 1:
                    extension = ext[1].lower()
                    if extension == '.jpg' or extension == '.jpeg':
                        cover_data = cf.read(name)
                        break
        elif original_file_extension.upper() == '.CBT':
            cf = tarfile.TarFile(tmp_file_name)
            for name in cf.getnames():
                ext = os.path.splitext(name)
                if len(ext) > 1:
                    extension = ext[1].lower()
                    if extension == '.jpg' or extension == '.jpeg':
                        cover_data = cf.extractfile(name).read()
                        break
    prefix = os.path.dirname(tmp_file_name)
    if cover_data:
        tmp_cover_name = prefix + '/cover' + extension
        image = open(tmp_cover_name, 'wb')
        image.write(cover_data)
        image.close()
    else:
        tmp_cover_name = None
    return tmp_cover_name
示例#8
0
    def getComicMetadata(self, path):
        ca = ComicArchive(
            path, default_image_path=AppFolders.missingPath("page.png"))

        if ca.seemsToBeAComicArchive():

            if ca.hasMetadata(MetaDataStyle.CIX):
                style = MetaDataStyle.CIX
            elif ca.hasMetadata(MetaDataStyle.CBI):
                style = MetaDataStyle.CBI
            elif ca.hasMetadata(MetaDataStyle.COMET):
                style = MetaDataStyle.COMET
            elif ca.hasMetadata(MetaDataStyle.CBW):
                style = MetaDataStyle.CBW
            else:
                logging.warning(u"Library: File Has No ComicMeta Data")
                if ca.hasMetadata(MetaDataStyle.CALIBRE):
                    style = MetaDataStyle.CALIBRE
                elif ca.hasMetadata(MetaDataStyle.EPUB):
                    style = MetaDataStyle.EPUB
                else:
                    style = None

            if style is not None:
                md = ca.readMetadata(style)
                if md.isEmpty:
                    md = ca.metadataFromFilename()
            else:
                # No metadata in comic.  make some guesses from the filename
                md = ca.metadataFromFilename()

            # patch version 2
            if (md.title is None or md.title
                    == "") and md.issue is None and not md.series is None:
                md.title = md.series
                md.series = None

            md.fingerprint = ca.fingerprint()
            md.path = ca.path

            md.page_count = ca.page_count

            md.mod_ts = datetime.utcfromtimestamp(getmtime(ca.path))
            md.filesize = os.path.getsize(md.path)
            md.hash = ""

            #thumbnail generation
            image_data = ca.getPage(0, AppFolders.missingPath("cover.png"))

            #now resize it
            thumb = StringIO.StringIO()

            #Lets right thumbs to files. large libraries cause the database to bloat
            try:
                utils.resize(image_data, (400, 400), thumb)
                filename = md.fingerprint + ".png"
                foldername = filename[0]
                thumbSubFolder = AppFolders.appThumbFolder(foldername)
                if not os.path.exists(thumbSubFolder):
                    os.makedirs(thumbSubFolder)
                folderpath = AppFolders.appThumbPath(foldername, filename)
                with open(folderpath, 'wb') as f:
                    f.write(thumb.getvalue())

                print("Extracted thumb: " + filename)

            except:
                print("Thumbnail extraction failed")
            # print md
            return md
        return None