Exemplo n.º 1
0
TEST_F(CoverArtUtilTest, extractEmbeddedCover) {
    QImage cover;
    QImage referencePNGImage = QImage(kReferencePNGLocationTest);
    QImage referenceJPGImage = QImage(kReferenceJPGLocationTest);

    // We never need to acquire security tokens for tests since we don't run
    // them in a sandboxed environment.

    SecurityTokenPointer pToken;

    if (isSupportedFileExtension("aiff")) {
        extractEmbeddedCover(
                kTestDir.absoluteFilePath("cover-test.aiff"), pToken, referencePNGImage);
    }

    if (isSupportedFileExtension("flac")) {
        extractEmbeddedCover(
                kTestDir.absoluteFilePath("cover-test.flac"), pToken, referencePNGImage);
    }

    if (isSupportedFileExtension("m4a")) {
        extractEmbeddedCover(
                kTestDir.absoluteFilePath("cover-test.m4a"), pToken, referencePNGImage);
    }

    if (isSupportedFileExtension("mp3")) {
        // PNG
        extractEmbeddedCover(
                kTestDir.absoluteFilePath("cover-test-png.mp3"), pToken, referencePNGImage);
        // JPEG
        extractEmbeddedCover(
                kTestDir.absoluteFilePath("cover-test-jpg.mp3"), pToken, referenceJPGImage);
    }

    if (isSupportedFileExtension("ogg")) {
        extractEmbeddedCover(
                kTestDir.absoluteFilePath("cover-test.ogg"), pToken, referencePNGImage);
    }

    if (isSupportedFileExtension("opus")) {
        // opus
        extractEmbeddedCover(
                kTestDir.absoluteFilePath("cover-test.opus"), pToken, referencePNGImage);
    }

    if (isSupportedFileExtension("wav")) {
        extractEmbeddedCover(
                kTestDir.absoluteFilePath("cover-test.wav"), pToken, referencePNGImage);
    }

    if (isSupportedFileExtension("wv")) {
        extractEmbeddedCover(
                kTestDir.absoluteFilePath("cover-test.wv"), pToken, referencePNGImage);
    }
}
Exemplo n.º 2
0
//static
CoverArt CoverArtUtils::guessCoverArt(TrackPointer pTrack) {
    CoverArt art;
    art.info.source = CoverInfo::GUESSED;

    if (pTrack.isNull()) {
        return art;
    }

    const QFileInfo fileInfo(pTrack->getFileInfo());
    art.image = extractEmbeddedCover(fileInfo, pTrack->getSecurityToken());
    if (!art.image.isNull()) {
        // TODO() here we my introduce a duplicate hash code
        art.info.hash = calculateHash(art.image);
        art.info.coverLocation = QString();
        art.info.type = CoverInfo::METADATA;
        qDebug() << "CoverArtUtils::guessCoverArt found metadata art" << art;
        return art;
    }

    QLinkedList<QFileInfo> possibleCovers = findPossibleCoversInFolder(
            fileInfo.absolutePath());
    art = selectCoverArtForTrack(pTrack.data(), possibleCovers);
    if (art.info.type == CoverInfo::FILE) {
        qDebug() << "CoverArtUtils::guessCoverArt found file art" << art;
    } else {
        qDebug() << "CoverArtUtils::guessCoverArt didn't find art" << art;
    }
    return art;
}
Exemplo n.º 3
0
//static
CoverInfo CoverArtUtils::guessCoverInfo(const Track& track) {
    CoverInfo coverInfo;

    coverInfo.trackLocation = track.getLocation();
    coverInfo.source = CoverInfo::GUESSED;

    const QFileInfo fileInfo(track.getFileInfo());
    QImage image = extractEmbeddedCover(fileInfo, track.getSecurityToken());
    if (!image.isNull()) {
        // TODO() here we my introduce a duplicate hash code
        coverInfo.hash = calculateHash(image);
        coverInfo.coverLocation = QString();
        coverInfo.type = CoverInfo::METADATA;
        qDebug() << "CoverArtUtils::guessCover found metadata art" << coverInfo;
        return coverInfo;
    }

    QLinkedList<QFileInfo> possibleCovers = findPossibleCoversInFolder(
            fileInfo.absolutePath());
    coverInfo = selectCoverArtForTrack(track, possibleCovers);
    if (coverInfo.type == CoverInfo::FILE) {
        qDebug() << "CoverArtUtils::guessCover found file art" << coverInfo;
    } else {
        qDebug() << "CoverArtUtils::guessCover didn't find art" << coverInfo;
    }
    return coverInfo;
}
Exemplo n.º 4
0
//static
QImage CoverArtUtils::extractEmbeddedCover(
        QFileInfo fileInfo) {
    SecurityTokenPointer pToken = Sandbox::openSecurityToken(
            QFileInfo(fileInfo), true);
    return extractEmbeddedCover(
            std::move(fileInfo), std::move(pToken));
}
Exemplo n.º 5
0
//static
QImage CoverArtUtils::loadCover(const CoverInfo& info) {
    if (info.type == CoverInfo::METADATA) {
        if (info.trackLocation.isEmpty()) {
            qDebug() << "CoverArtUtils::loadCover METADATA cover with empty trackLocation.";
            return QImage();
        }
        const QFileInfo fileInfo(info.trackLocation);
        return extractEmbeddedCover(fileInfo);
    } else if (info.type == CoverInfo::FILE) {
        if (info.trackLocation.isEmpty()) {
            qDebug() << "CoverArtUtils::loadCover FILE cover with empty trackLocation."
                     << "Relative paths will not work.";
            SecurityTokenPointer pToken = Sandbox::openSecurityToken(
                QFileInfo(info.coverLocation), true);
            return QImage(info.coverLocation);
        }

        QFileInfo track(info.trackLocation);
        QFileInfo cover(track.dir(), info.coverLocation);

        if (!cover.exists()) {
            qDebug() << "CoverArtUtils::loadCover FILE cover does not exist:"
                     << info.coverLocation << info.trackLocation;
            return QImage();
        }
        QString coverPath = cover.filePath();
        SecurityTokenPointer pToken = Sandbox::openSecurityToken(
            cover, true);
        return QImage(coverPath);
    } else if (info.type == CoverInfo::NONE) {
        return QImage();
    } else {
        qDebug() << "CoverArtUtils::loadCover unhandled type";
        DEBUG_ASSERT(false);
        return QImage();
    }
}
Exemplo n.º 6
0
//static
QImage CoverArtUtils::extractEmbeddedCover(
        const QFileInfo& fileInfo) {
    SecurityTokenPointer pToken(Sandbox::openSecurityToken(
        QFileInfo(fileInfo), true));
    return extractEmbeddedCover(fileInfo, pToken);
}