Exemple #1
0
def get_comic_info(tmp_file_path, original_file_name, original_file_extension):
    archive = ComicArchive(tmp_file_path)
    if archive.seemsToBeAComicArchive():
        if archive.hasMetadata(MetaDataStyle.CIX):
            style = MetaDataStyle.CIX
        elif archive.hasMetadata(MetaDataStyle.CBI):
            style = MetaDataStyle.CBI
        else:
            style = None

        if style is not None:
            loadedMetadata = archive.readMetadata(style)

    lang = loadedMetadata.language
    if len(lang) == 2:
        loadedMetadata.language = isoLanguages.get(part1=lang).name
    elif len(lang) == 3:
        loadedMetadata.language = isoLanguages.get(part3=lang).name
    else:
        loadedMetadata.language = ""

    return uploader.BookMeta(
        file_path=tmp_file_path,
        extension=original_file_extension,
        title=loadedMetadata.title or original_file_name,
        author=" & ".join([
            credit["person"]
            for credit in loadedMetadata.credits if credit["role"] == "Writer"
        ]) or u"Unknown",
        cover=extractCover(tmp_file_path, original_file_extension),
        description=loadedMetadata.comments or "",
        tags="",
        series=loadedMetadata.series or "",
        series_id=loadedMetadata.issue or "",
        languages=loadedMetadata.language)
Exemple #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
Exemple #3
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
Exemple #4
0
def get_comic_info(tmp_file_path, original_file_name, original_file_extension,
                   rar_executable):
    if use_comic_meta:
        archive = ComicArchive(tmp_file_path, rar_exe_path=rar_executable)
        if archive.seemsToBeAComicArchive():
            if archive.hasMetadata(MetaDataStyle.CIX):
                style = MetaDataStyle.CIX
            elif archive.hasMetadata(MetaDataStyle.CBI):
                style = MetaDataStyle.CBI
            else:
                style = None

            # if style is not None:
            loaded_metadata = archive.readMetadata(style)

            lang = loaded_metadata.language or ""
            loaded_metadata.language = isoLanguages.get_lang3(lang)

            return BookMeta(file_path=tmp_file_path,
                            extension=original_file_extension,
                            title=loaded_metadata.title or original_file_name,
                            author=" & ".join([
                                credit["person"]
                                for credit in loaded_metadata.credits
                                if credit["role"] == "Writer"
                            ]) or 'Unknown',
                            cover=_extract_cover(tmp_file_path,
                                                 original_file_extension,
                                                 rar_executable),
                            description=loaded_metadata.comments or "",
                            tags="",
                            series=loaded_metadata.series or "",
                            series_id=loaded_metadata.issue or "",
                            languages=loaded_metadata.language,
                            publisher="",
                            pubdate="",
                            identifiers=[])

    return BookMeta(file_path=tmp_file_path,
                    extension=original_file_extension,
                    title=original_file_name,
                    author=u'Unknown',
                    cover=_extract_cover(tmp_file_path,
                                         original_file_extension,
                                         rar_executable),
                    description="",
                    tags="",
                    series="",
                    series_id="",
                    languages="",
                    publisher="",
                    pubdate="",
                    identifiers=[])
Exemple #5
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