Search in sources :

Example 1 with EbookMeta

use of com.foobnix.ext.EbookMeta in project LibreraReader by foobnix.

the class FileMetaCore method getEbookMeta.

public EbookMeta getEbookMeta(String path, CacheDir folder, boolean withPDF) {
    EbookMeta ebookMeta = EbookMeta.Empty();
    try {
        if (path.toLowerCase(Locale.US).endsWith(".zip")) {
            CacheZipUtils.cacheLock.lock();
            try {
                UnZipRes res = CacheZipUtils.extracIfNeed(path, folder);
                ebookMeta = getEbookMeta(path, res.unZipPath, res.entryName, withPDF);
                ebookMeta.setUnzipPath(res.unZipPath);
            } finally {
                CacheZipUtils.cacheLock.unlock();
            }
        } else {
            ebookMeta = getEbookMeta(path, path, null, withPDF);
            ebookMeta.setUnzipPath(path);
        }
    } catch (Exception e) {
        LOG.e(e);
    }
    return ebookMeta;
}
Also used : EbookMeta(com.foobnix.ext.EbookMeta) UnZipRes(com.foobnix.ext.CacheZipUtils.UnZipRes) IOException(java.io.IOException)

Example 2 with EbookMeta

use of com.foobnix.ext.EbookMeta in project LibreraReader by foobnix.

the class FileMetaCore method checkOrCreateMetaInfo.

public static void checkOrCreateMetaInfo(Activity a) {
    try {
        String path = CacheManager.getFilePathFromAttachmentIfNeed(a);
        if (!BookType.isSupportedExtByPath(path)) {
            path = a.getIntent().getData().getPath();
        }
        LOG.d("checkOrCreateMetaInfo", path);
        if (new File(path).isFile()) {
            FileMeta fileMeta = AppDB.get().getOrCreate(path);
            if (TxtUtils.isEmpty(fileMeta.getTitle())) {
                EbookMeta ebookMeta = FileMetaCore.get().getEbookMeta(path, CacheDir.ZipApp, false);
                FileMetaCore.get().upadteBasicMeta(fileMeta, new File(path));
                FileMetaCore.get().udpateFullMeta(fileMeta, ebookMeta);
                AppDB.get().update(fileMeta);
                LOG.d("checkOrCreateMetaInfo", "UPDATE", path);
            } else {
                LOG.d("checkOrCreateMetaInfo", "LOAD", path);
            }
        }
    } catch (Exception e) {
        LOG.e(e);
    }
}
Also used : EbookMeta(com.foobnix.ext.EbookMeta) File(java.io.File) FileMeta(com.foobnix.dao2.FileMeta) IOException(java.io.IOException)

Example 3 with EbookMeta

use of com.foobnix.ext.EbookMeta in project LibreraReader by foobnix.

the class BooksService method onHandleIntent.

@Override
protected void onHandleIntent(Intent intent) {
    if (intent == null) {
        return;
    }
    try {
        LOG.d(TAG, "BooksService", "Action", intent.getAction());
        if (ACTION_REMOVE_DELETED.equals(intent.getAction())) {
            List<FileMeta> list = AppDB.get().getAll();
            for (FileMeta meta : list) {
                File bookFile = new File(meta.getPath());
                if (!bookFile.exists()) {
                    AppDB.get().delete(meta);
                    LOG.d(TAG, "Delete meta", meta.getPath());
                }
            }
            sendFinishMessage();
            LOG.d("BooksService , searchDate", AppState.get().searchDate);
            if (AppState.get().searchDate != 0) {
                List<FileMeta> localMeta = new LinkedList<FileMeta>();
                for (final String path : AppState.get().searchPaths.split(",")) {
                    if (path != null && path.trim().length() > 0) {
                        final File root = new File(path);
                        if (root.isDirectory()) {
                            LOG.d(TAG, "Searcin in " + root.getPath());
                            SearchCore.search(localMeta, root, ExtUtils.seachExts);
                        }
                    }
                }
                for (FileMeta meta : localMeta) {
                    File file = new File(meta.getPath());
                    if (file.lastModified() >= AppState.get().searchDate) {
                        if (AppDB.get().getDao().hasKey(meta)) {
                            LOG.d(TAG, "Skip book", file.getPath());
                            continue;
                        }
                        FileMetaCore.get().upadteBasicMeta(meta, file);
                        EbookMeta ebookMeta = FileMetaCore.get().getEbookMeta(meta.getPath(), CacheDir.ZipService, true);
                        FileMetaCore.get().udpateFullMeta(meta, ebookMeta);
                        meta.setIsSearchBook(true);
                        AppDB.get().updateOrSave(meta);
                        LOG.d(TAG, "BooksService", "insert", meta.getPath());
                    }
                }
                AppState.get().searchDate = System.currentTimeMillis();
                sendFinishMessage();
            }
        } else if (ACTION_SEARCH_ALL.equals(intent.getAction())) {
            LOG.d(ACTION_SEARCH_ALL);
            IMG.clearDiscCache();
            IMG.clearMemoryCache();
            ImageExtractor.clearErrors();
            List<FileMeta> allWithTag = AppDB.get().getAllWithTag();
            LOG.d(TAG, "allWithTag", allWithTag.size());
            List<Uri> recent = AppSharedPreferences.get().getRecent();
            List<FileMeta> starsAndRecent = AppDB.get().deleteAllSafe();
            long time = Integer.MAX_VALUE;
            for (Uri uri : recent) {
                FileMeta item = new FileMeta(uri.getPath());
                item.setIsRecent(true);
                item.setIsStarTime(time--);
                starsAndRecent.add(item);
            }
            for (FileMeta m : starsAndRecent) {
                if (m.getCusType() != null && FileMetaAdapter.DISPLAY_TYPE_DIRECTORY == m.getCusType()) {
                    m.setIsSearchBook(false);
                } else {
                    m.setIsSearchBook(true);
                }
            }
            AppSharedPreferences.get().cleanRecent();
            itemsMeta.clear();
            handler.post(timer);
            for (final String path : AppState.get().searchPaths.split(",")) {
                if (path != null && path.trim().length() > 0) {
                    final File root = new File(path);
                    if (root.isDirectory()) {
                        LOG.d("Searcin in " + root.getPath());
                        SearchCore.search(itemsMeta, root, ExtUtils.seachExts);
                    }
                }
            }
            AppState.get().searchDate = System.currentTimeMillis();
            for (FileMeta meta : itemsMeta) {
                meta.setIsSearchBook(true);
            }
            itemsMeta.addAll(starsAndRecent);
            AppDB.get().saveAll(itemsMeta);
            handler.removeCallbacks(timer);
            sendFinishMessage();
            handler.post(timer2);
            for (FileMeta meta : itemsMeta) {
                File file = new File(meta.getPath());
                FileMetaCore.get().upadteBasicMeta(meta, file);
            }
            AppDB.get().updateAll(itemsMeta);
            for (FileMeta meta : itemsMeta) {
                EbookMeta ebookMeta = FileMetaCore.get().getEbookMeta(meta.getPath(), CacheDir.ZipService, true);
                LOG.d("BooksService getAuthor", meta.getPath(), ebookMeta.getAuthor());
                FileMetaCore.get().udpateFullMeta(meta, ebookMeta);
            }
            AppDB.get().updateAll(itemsMeta);
            AppDB.get().updateAll(allWithTag);
            itemsMeta.clear();
            handler.removeCallbacks(timer2);
            sendFinishMessage();
            CacheDir.ZipService.removeCacheContent();
        }
    } finally {
    }
}
Also used : EbookMeta(com.foobnix.ext.EbookMeta) List(java.util.List) LinkedList(java.util.LinkedList) File(java.io.File) Uri(android.net.Uri) FileMeta(com.foobnix.dao2.FileMeta) LinkedList(java.util.LinkedList)

Example 4 with EbookMeta

use of com.foobnix.ext.EbookMeta in project LibreraReader by foobnix.

the class ImageExtractor method proccessCoverPage.

public Bitmap proccessCoverPage(PageUrl pageUrl) {
    String path = pageUrl.getPath();
    if (pageUrl.getHeight() == 0) {
        pageUrl.setHeight((int) (pageUrl.getWidth() * 1.5));
    }
    FileMeta fileMeta = AppDB.get().load(path);
    EbookMeta ebookMeta = FileMetaCore.get().getEbookMeta(path, CacheDir.ZipApp, false);
    LOG.d("proccessCoverPage fileMeta", fileMeta, pageUrl);
    if (fileMeta == null) {
        fileMeta = new FileMeta(path);
        FileMetaCore.get().upadteBasicMeta(fileMeta, new File(path));
        FileMetaCore.get().udpateFullMeta(fileMeta, ebookMeta);
        AppDB.get().getDao().insert(fileMeta);
    }
    String unZipPath = ebookMeta.getUnzipPath();
    Bitmap cover = null;
    if (ebookMeta.coverImage != null) {
        cover = BaseExtractor.arrayToBitmap(ebookMeta.coverImage, pageUrl.getWidth());
    } else if (BookType.EPUB.is(unZipPath)) {
        cover = BaseExtractor.arrayToBitmap(EpubExtractor.get().getBookCover(unZipPath), pageUrl.getWidth());
    } else if (BookType.FB2.is(unZipPath)) {
        cover = BaseExtractor.arrayToBitmap(Fb2Extractor.get().getBookCover(unZipPath), pageUrl.getWidth());
    } else if (BookType.MOBI.is(unZipPath)) {
        cover = BaseExtractor.arrayToBitmap(MobiExtract.getBookCover(unZipPath), pageUrl.getWidth());
    } else if (BookType.RTF.is(unZipPath)) {
        cover = BaseExtractor.arrayToBitmap(RtfExtract.getImageCover(unZipPath), pageUrl.getWidth());
    } else if (BookType.PDF.is(unZipPath) || BookType.DJVU.is(unZipPath) || BookType.TIFF.is(unZipPath)) {
        cover = proccessOtherPage(pageUrl, fileMeta);
    } else if (BookType.CBZ.is(unZipPath) || BookType.CBR.is(unZipPath)) {
        cover = BaseExtractor.arrayToBitmap(CbzCbrExtractor.getBookCover(unZipPath), pageUrl.getWidth());
    } else if (ExtUtils.isFileArchive(unZipPath)) {
        String ext = ExtUtils.getFileExtension(unZipPath);
        cover = BaseExtractor.getBookCoverWithTitle("...", "  [" + ext.toUpperCase(Locale.US) + "]", true);
        pageUrl.tempWithWatermakr = true;
    } else if (ExtUtils.isFontFile(unZipPath)) {
        cover = BaseExtractor.getBookCoverWithTitle("font", "", true);
        pageUrl.tempWithWatermakr = true;
    }
    if (cover == null) {
        cover = BaseExtractor.getBookCoverWithTitle(fileMeta.getAuthor(), fileMeta.getTitle(), true);
        pageUrl.tempWithWatermakr = true;
    }
    LOG.d("udpateFullMeta ImageExtractor", fileMeta.getAuthor());
    AppDB.get().update(fileMeta);
    return cover;
}
Also used : RawBitmap(org.ebookdroid.common.bitmaps.RawBitmap) Bitmap(android.graphics.Bitmap) EbookMeta(com.foobnix.ext.EbookMeta) File(java.io.File) FileMeta(com.foobnix.dao2.FileMeta)

Example 5 with EbookMeta

use of com.foobnix.ext.EbookMeta in project LibreraReader by foobnix.

the class FileMetaCore method getEbookMeta.

private EbookMeta getEbookMeta(String path, String unZipPath, String child, boolean withDPF) throws IOException {
    EbookMeta ebookMeta = EbookMeta.Empty();
    String fileName = ExtUtils.getFileName(unZipPath);
    String fileNameOriginal = ExtUtils.getFileName(path);
    if (BookType.FB2.is(unZipPath)) {
        fileNameOriginal = TxtUtils.encode1251(fileNameOriginal);
        fileName = TxtUtils.encode1251(fileNameOriginal);
    }
    if (CalirbeExtractor.isCalibre(unZipPath)) {
        ebookMeta = CalirbeExtractor.getBookMetaInformation(unZipPath);
        LOG.d("isCalibre find", unZipPath);
    } else if (BookType.EPUB.is(unZipPath)) {
        ebookMeta = EpubExtractor.get().getBookMetaInformation(unZipPath);
    } else if (BookType.FB2.is(unZipPath)) {
        ebookMeta = Fb2Extractor.get().getBookMetaInformation(unZipPath);
    } else if (BookType.MOBI.is(unZipPath)) {
        ebookMeta = MobiExtract.getBookMetaInformation(unZipPath, true);
    } else if (withDPF && isNeedToExtractPDFMeta(unZipPath)) {
        ebookMeta = PdfExtract.getBookMetaInformation(unZipPath);
    } else if (BookType.CBR.is(unZipPath) || BookType.CBZ.is(unZipPath)) {
        ebookMeta.setPagesCount(CbzCbrExtractor.getPageCount(unZipPath));
    }
    if (TxtUtils.isEmpty(ebookMeta.getTitle())) {
        Pair<String, String> pair = TxtUtils.getTitleAuthorByPath(fileName);
        int count = ebookMeta.getPagesCount();
        ebookMeta = new EbookMeta(pair.first, TxtUtils.isNotEmpty(ebookMeta.getAuthor()) ? ebookMeta.getAuthor() : pair.second);
        ebookMeta.setPagesCount(count);
    }
    if (ebookMeta.getsIndex() == null && (path.contains("_") || path.contains(")"))) {
        for (int i = 20; i >= 1; i--) {
            if (path.contains("_" + i + "_") || path.contains(" " + i + ")") || path.contains(" 0" + i + ")")) {
                ebookMeta.setsIndex(i);
                break;
            }
        }
    }
    if (ebookMeta.getsIndex() != null) {
        ebookMeta.setTitle(ebookMeta.getTitle() + " [" + ebookMeta.getsIndex() + "]");
    }
    if (path.endsWith(".zip") && !path.endsWith("fb2.zip")) {
        ebookMeta.setTitle("{" + fileNameOriginal + "} " + ebookMeta.getTitle());
    }
    return ebookMeta;
}
Also used : EbookMeta(com.foobnix.ext.EbookMeta)

Aggregations

EbookMeta (com.foobnix.ext.EbookMeta)5 FileMeta (com.foobnix.dao2.FileMeta)3 File (java.io.File)3 IOException (java.io.IOException)2 Bitmap (android.graphics.Bitmap)1 Uri (android.net.Uri)1 UnZipRes (com.foobnix.ext.CacheZipUtils.UnZipRes)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 RawBitmap (org.ebookdroid.common.bitmaps.RawBitmap)1