void AnalyzeTask::retrieveCover(AudioFileModel &audioFile, cover_t coverType, const QByteArray &coverData) { qDebug("Retrieving cover!"); QString extension; switch(coverType) { case coverPng: extension = QString::fromLatin1("png"); break; case coverGif: extension = QString::fromLatin1("gif"); break; default: extension = QString::fromLatin1("jpg"); break; } if(!(QImage::fromData(coverData, extension.toUpper().toLatin1().constData()).isNull())) { QFile coverFile(QString("%1/%2.%3").arg(lamexp_temp_folder2(), lamexp_rand_str(), extension)); if(coverFile.open(QIODevice::WriteOnly)) { coverFile.write(coverData); coverFile.close(); audioFile.metaInfo().setCover(coverFile.fileName(), true); } } else { qWarning("Image data seems to be invalid :-("); } }
void CoverHelper::getPathForCover(std::string coverArtFilename) { QFile coverFile("covers/" + QString::fromStdString(coverArtFilename)); if (coverFile.exists()) { gotPathForCover(coverArtFilename); } else { downloadCover(coverArtFilename); } }
void WCoverArtMenu::slotChange() { QFileInfo fileInfo; if (!m_trackLocation.isEmpty()) { fileInfo = QFileInfo(m_trackLocation); } else if (!m_coverInfo.trackLocation.isEmpty()) { fileInfo = QFileInfo(m_coverInfo.trackLocation); } QString initialDir; if (m_coverInfo.type == CoverInfo::FILE) { QFileInfo coverFile(fileInfo.dir(), m_coverInfo.coverLocation); initialDir = coverFile.absolutePath(); } else { // Default to the track's directory if the cover is not // stored in a separate file. initialDir = fileInfo.absolutePath(); } QStringList extensions = CoverArtUtils::supportedCoverArtExtensions(); for (auto&& extension : extensions) { extension.prepend("*."); } QString supportedText = QString("%1 (%2)").arg(tr("Image Files")) .arg(extensions.join(" ")); // open file dialog QString selectedCoverPath = QFileDialog::getOpenFileName( this, tr("Change Cover Art"), initialDir, supportedText); if (selectedCoverPath.isEmpty()) { return; } // TODO(rryan): Ask if user wants to copy the file. CoverArt art; // Create a security token for the file. QFileInfo selectedCover(selectedCoverPath); SecurityTokenPointer pToken = Sandbox::openSecurityToken( selectedCover, true); art.image = QImage(selectedCoverPath); if (art.image.isNull()) { // TODO(rryan): feedback return; } art.info.type = CoverInfo::FILE; art.info.source = CoverInfo::USER_SELECTED; art.info.coverLocation = selectedCoverPath; // TODO() here we may introduce a duplicate hash code art.info.hash = CoverArtUtils::calculateHash(art.image); qDebug() << "WCoverArtMenu::slotChange emit" << art; emit(coverArtSelected(art)); }
QPixmap DB_QMDB_SQL::getCover(QString i, QString a) { QPixmap pixmap; QString filePath = QDir::homePath() + "/.config/Mike Gareiss/"; filePath = filePath + md5sum(i + a); //qDebug() << filePath; QFile coverFile(filePath); if (coverFile.exists()) { pixmap.load(filePath); //qDebug("covefile loaded"); return pixmap; } QSqlQuery query(db); query.exec("SELECT hasImage, image, t_album.name, t_artist.name FROM t_album " "INNER JOIN t_artist ON t_album.artist = t_artist.id " "WHERE " "t_album.name = '" + a + "' " "AND " "t_artist.name = '" + i + "'"); if(query.first()) { if(query.value(0).toInt() == 1) { QString image = query.value(1).toString(); QByteArray xcode; if(!image.contains("|end_stream|")) { qDebug("error sql - limit"); pixmap.load(":/images/noCover.png", "PNG"); return pixmap; } QStringList dat = image.split("|"); if (dat.size() > 0) { xcode.append(dat.at(0)); pixmap.loadFromData(QByteArray::fromBase64(xcode)); pixmap.save(filePath, "PNG"); return pixmap; } } } pixmap.load(":/images/noCover.png", "PNG"); return pixmap; }
//删除一条数据 bool DataOp::deleteRecord(QString id) { int lineBeginPos = countLineBeginPos(id); //计算以id为首的行的起点 if(lineBeginPos==-1){ qDebug() << "找不到该条记录:"<<id; return 0; }else{ fileText.remove(lineBeginPos,fileText.indexOf('\n',lineBeginPos)-lineBeginPos+1); //去掉这一行,注意长度+1以去掉\r if(coverFile(fileText)){ return 1; } } return 0; }
shared_ptr<ZLImage> OEBCoverReader::readCover(const ZLFile &file) { myPathPrefix = MiscUtil::htmlDirectoryPrefix(file.path()); myReadGuide = false; myImage = 0; myCoverXHTML.erase(); readDocument(file); myPathPrefix = MiscUtil::htmlDirectoryPrefix(myCoverXHTML); if (!myCoverXHTML.empty()) { ZLFile coverFile(myCoverXHTML); const std::string ext = coverFile.extension(); if (ext == "gif" || ext == "jpeg" || ext == "jpg") { myImage = new ZLFileImage(ZLFile(myCoverXHTML), 0); } else { XHTMLImageFinder(*this).readDocument(coverFile); } } return myImage; }
void AnalyzeTask::retrieveCover(AudioFileModel &audioFile, const QString &coverType, const QString &coverData) { const QByteArray content = QByteArray::fromBase64(coverData.toLatin1()); const QString type = m_mimeTypes.value(coverType.toLower()); qDebug("Retrieving cover! (mime=\"%s\", type=\"%s\", len=%d)", MUTILS_L1STR(coverType), MUTILS_L1STR(type), content.size()); if(!QImage::fromData(content, type.isEmpty() ? NULL : MUTILS_L1STR(type.toUpper())).isNull()) { QFile coverFile(QString("%1/%2.%3").arg(MUtils::temp_folder(), MUtils::next_rand_str(), type.isEmpty() ? QLatin1String("jpg") : type)); if(coverFile.open(QIODevice::WriteOnly)) { coverFile.write(content); coverFile.close(); audioFile.metaInfo().setCover(coverFile.fileName(), true); } } else { qWarning("Image data seems to be invalid! [Header:%s]", content.left(32).toHex().constData()); } }
void AnalyzeTask::retrieveCover(AudioFileModel &audioFile, const quint32 coverType, const QByteArray &coverData) { qDebug("Retrieving cover! (MIME_TYPES_MAX=%u)", MIME_TYPES_MAX); static const QString ext = QString::fromLatin1(MIME_TYPES[qBound(0U, coverType, MIME_TYPES_MAX)].ext[0]); if(!(QImage::fromData(coverData, ext.toUpper().toLatin1().constData()).isNull())) { QFile coverFile(QString("%1/%2.%3").arg(MUtils::temp_folder(), MUtils::rand_str(), ext)); if(coverFile.open(QIODevice::WriteOnly)) { coverFile.write(coverData); coverFile.close(); audioFile.metaInfo().setCover(coverFile.fileName(), true); } } else { qWarning("Image data seems to be invalid :-("); } }
QVariantMap MprisPlugin::metadata() const { QVariantMap metadataMap; Tomahawk::result_ptr track = AudioEngine::instance()->currentTrack(); if ( track ) { metadataMap.insert( "mpris:trackid", QVariant::fromValue(QDBusObjectPath(QString( "/track/" ) + track->id().replace( "-", "" ))) ); metadataMap.insert( "mpris:length", static_cast<qlonglong>(track->duration()) * 1000000 ); metadataMap.insert( "xesam:album", track->album()->name() ); metadataMap.insert( "xesam:artist", QStringList( track->artist()->name() ) ); metadataMap.insert( "xesam:title", track->track() ); // Only return art if tempfile exists, and if its name contains the same "artist_album_tomahawk_cover.png" if ( !m_coverTempFile.isEmpty() ) { QFile coverFile( m_coverTempFile ); if ( coverFile.exists() && coverFile.fileName().contains( track->artist()->name() + "_" + track->album()->name() + "_tomahawk_cover.png" ) ) metadataMap.insert( "mpris:artUrl", QString( QUrl::fromLocalFile( m_coverTempFile ).toEncoded() ) ); } } return metadataMap; }