本文整理汇总了C++中MusicMetadata::dumpToDatabase方法的典型用法代码示例。如果您正苦于以下问题:C++ MusicMetadata::dumpToDatabase方法的具体用法?C++ MusicMetadata::dumpToDatabase怎么用?C++ MusicMetadata::dumpToDatabase使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MusicMetadata
的用法示例。
在下文中一共展示了MusicMetadata::dumpToDatabase方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: run
//.........这里部分代码省略.........
m_parent,
new RipStatusEvent(RipStatusEvent::kTrackPercentEvent, 0));
// do we need to start a new file?
if (m_tracks->at(trackno)->active)
{
titleTrack = track;
titleTrack->setLength(m_tracks->at(trackno)->length);
if (m_quality < 3)
{
if (encodertype == "mp3")
{
outfile = QString("track%1.mp3").arg(trackno);
encoder.reset(new LameEncoder(saveDir + outfile, m_quality,
titleTrack, mp3usevbr));
}
else // ogg
{
outfile = QString("track%1.ogg").arg(trackno);
encoder.reset(new VorbisEncoder(saveDir + outfile, m_quality,
titleTrack));
}
}
else
{
outfile = QString("track%1.flac").arg(trackno);
encoder.reset(new FlacEncoder(saveDir + outfile, m_quality,
titleTrack));
}
if (!encoder->isValid())
{
QApplication::postEvent(
m_parent,
new RipStatusEvent(
RipStatusEvent::kEncoderErrorEvent,
"Encoder failed to open file for writing"));
LOG(VB_GENERAL, LOG_ERR, "MythMusic: Encoder failed"
" to open file for writing");
RunEpilog();
return;
}
}
if (!encoder.get())
{
// This should never happen.
QApplication::postEvent(
m_parent,
new RipStatusEvent(RipStatusEvent::kEncoderErrorEvent,
"Failed to create encoder"));
LOG(VB_GENERAL, LOG_ERR, "MythMusic: No encoder, failing");
RunEpilog();
return;
}
ripTrack(m_CDdevice, encoder.get(), trackno + 1);
if (isCancelled())
{
RunEpilog();
return;
}
if (m_tracks->at(trackno)->active)
{
QString ext = QFileInfo(outfile).suffix();
QString destFile = filenameFromMetadata(titleTrack) + '.' + ext;
QUrl url(m_musicStorageDir);
// save the metadata to the DB
titleTrack->setFilename(destFile);
titleTrack->setHostname(url.host());
titleTrack->setFileSize((quint64)QFileInfo(outfile).size());
titleTrack->dumpToDatabase();
// this will delete the encoder which will write the metadata in it's dtor
encoder.reset();
// copy track to the BE
destFile = gCoreContext->GenMythURL(url.host(), 0, destFile, "Music");
QApplication::postEvent(m_parent, new RipStatusEvent(RipStatusEvent::kCopyStartEvent, 0));
RemoteFile::CopyFile(saveDir + outfile, destFile, true);
QApplication::postEvent(m_parent, new RipStatusEvent(RipStatusEvent::kCopyEndEvent, 0));
}
}
}
QString PostRipCDScript = gCoreContext->GetSetting("PostCDRipScript");
if (!PostRipCDScript.isEmpty())
myth_system(PostRipCDScript);
QApplication::postEvent(
m_parent, new RipStatusEvent(RipStatusEvent::kFinishedEvent, ""));
RunEpilog();
}
示例2: UpdateMeta
static int UpdateMeta(const MythUtilCommandLineParser &cmdline)
{
bool ok = true;
int result = GENERIC_EXIT_OK;
if (cmdline.toString("songid").isEmpty())
{
LOG(VB_GENERAL, LOG_ERR, "Missing --songid option");
return GENERIC_EXIT_INVALID_CMDLINE;
}
int songID = cmdline.toInt("songid");
MusicMetadata *mdata = MusicMetadata::createFromID(songID);
if (!mdata)
{
LOG(VB_GENERAL, LOG_ERR, QString("Cannot find metadata for trackid: %1").arg(songID));
return GENERIC_EXIT_NOT_OK;
}
if (!cmdline.toString("title").isEmpty())
mdata->setTitle(cmdline.toString("title"));
if (!cmdline.toString("artist").isEmpty())
mdata->setArtist(cmdline.toString("artist"));
if (!cmdline.toString("album").isEmpty())
mdata->setAlbum(cmdline.toString("album"));
if (!cmdline.toString("genre").isEmpty())
mdata->setGenre(cmdline.toString("genre"));
if (!cmdline.toString("trackno").isEmpty())
mdata->setTrack(cmdline.toInt("trackno"));
if (!cmdline.toString("year").isEmpty())
mdata->setYear(cmdline.toInt("year"));
if (!cmdline.toString("rating").isEmpty())
mdata->setRating(cmdline.toInt("rating"));
if (!cmdline.toString("playcount").isEmpty())
mdata->setPlaycount(cmdline.toInt("playcount"));
if (!cmdline.toString("lastplayed").isEmpty())
mdata->setLastPlay(cmdline.toDateTime("lastplayed"));
mdata->dumpToDatabase();
MetaIO *tagger = mdata->getTagger();
if (tagger)
{
ok = tagger->write(mdata->getLocalFilename(), mdata);
if (!ok)
LOG(VB_GENERAL, LOG_ERR, QString("Failed to write to tag for trackid: %1").arg(songID));
}
// tell any clients that the metadata for this track has changed
gCoreContext->SendMessage(QString("MUSIC_METADATA_CHANGED %1").arg(songID));
if (!ok)
result = GENERIC_EXIT_NOT_OK;
return result;
}
示例3: AddFileToDB
/*!
* \brief Insert file details into database.
* If it is an audio file, read the metadata and insert
* that information at the same time.
*
* If it is an image file, just insert the filename and
* type.
*
* \param filename Full path to file.
*
* \returns Nothing.
*/
void MusicFileScanner::AddFileToDB(const QString &filename)
{
QString extension = filename.section( '.', -1 ) ;
QString directory = filename;
directory.remove(0, m_startdir.length());
directory = directory.section( '/', 0, -2);
QString nameFilter = gCoreContext->GetSetting("AlbumArtFilter", "*.png;*.jpg;*.jpeg;*.gif;*.bmp");
// If this file is an image, insert the details into the music_albumart table
if (nameFilter.indexOf(extension.toLower()) > -1)
{
QString name = filename.section( '/', -1);
MSqlQuery query(MSqlQuery::InitCon());
query.prepare("INSERT INTO music_albumart SET filename = :FILE, "
"directory_id = :DIRID, imagetype = :TYPE;");
query.bindValue(":FILE", name);
query.bindValue(":DIRID", m_directoryid[directory]);
query.bindValue(":TYPE", AlbumArtImages::guessImageType(name));
if (!query.exec() || query.numRowsAffected() <= 0)
{
MythDB::DBError("music insert artwork", query);
}
return;
}
LOG(VB_FILE, LOG_INFO,
QString("Reading metadata from %1").arg(filename));
MusicMetadata *data = MetaIO::readMetadata(filename);
if (data)
{
data->setFileSize((quint64)QFileInfo(filename).size());
QString album_cache_string;
// Set values from cache
int did = m_directoryid[directory];
if (did > 0)
data->setDirectoryId(did);
int aid = m_artistid[data->Artist().toLower()];
if (aid > 0)
{
data->setArtistId(aid);
// The album cache depends on the artist id
album_cache_string = data->getArtistId() + "#"
+ data->Album().toLower();
if (m_albumid[album_cache_string] > 0)
data->setAlbumId(m_albumid[album_cache_string]);
}
int gid = m_genreid[data->Genre().toLower()];
if (gid > 0)
data->setGenreId(gid);
// Commit track info to database
data->dumpToDatabase();
// Update the cache
m_artistid[data->Artist().toLower()] =
data->getArtistId();
m_genreid[data->Genre().toLower()] =
data->getGenreId();
album_cache_string = data->getArtistId() + "#"
+ data->Album().toLower();
m_albumid[album_cache_string] = data->getAlbumId();
// read any embedded images from the tag
MetaIO *tagger = MetaIO::createTagger(filename);
if (tagger)
{
if (tagger->supportsEmbeddedImages())
{
AlbumArtList artList = tagger->getAlbumArtList(data->Filename());
data->setEmbeddedAlbumArt(artList);
data->getAlbumArtImages()->dumpToDatabase();
}
delete tagger;
}
delete data;
//.........这里部分代码省略.........
示例4: CalcTrackLength
//.........这里部分代码省略.........
if (musicFile.isEmpty() || !QFile::exists(musicFile))
{
LOG(VB_GENERAL, LOG_ERR, QString("Cannot find file for trackid: %1").arg(songID));
return GENERIC_EXIT_NOT_OK;
}
av_register_all();
AVFormatContext *inputFC = NULL;
AVInputFormat *fmt = NULL;
// Open track
LOG(VB_GENERAL, LOG_DEBUG, QString("CalcTrackLength: Opening '%1'")
.arg(musicFile));
QByteArray inFileBA = musicFile.toLocal8Bit();
int ret = avformat_open_input(&inputFC, inFileBA.constData(), fmt, NULL);
if (ret)
{
LOG(VB_GENERAL, LOG_ERR, "CalcTrackLength: Couldn't open input file" +
ENO);
return GENERIC_EXIT_NOT_OK;
}
// Getting stream information
ret = avformat_find_stream_info(inputFC, NULL);
if (ret < 0)
{
LOG(VB_GENERAL, LOG_ERR,
QString("CalcTrackLength: Couldn't get stream info, error #%1").arg(ret));
avformat_close_input(&inputFC);
inputFC = NULL;
return GENERIC_EXIT_NOT_OK;;
}
int duration = 0;
long long time = 0;
for (uint i = 0; i < inputFC->nb_streams; i++)
{
AVStream *st = inputFC->streams[i];
char buf[256];
avcodec_string(buf, sizeof(buf), st->codec, false);
switch (inputFC->streams[i]->codec->codec_type)
{
case AVMEDIA_TYPE_AUDIO:
{
AVPacket pkt;
av_init_packet(&pkt);
while (av_read_frame(inputFC, &pkt) >= 0)
{
if (pkt.stream_index == (int)i)
time = time + pkt.duration;
av_free_packet(&pkt);
}
duration = time * av_q2d(inputFC->streams[i]->time_base);
break;
}
default:
LOG(VB_GENERAL, LOG_ERR,
QString("Skipping unsupported codec %1 on stream %2")
.arg(inputFC->streams[i]->codec->codec_type).arg(i));
break;
}
}
// Close input file
avformat_close_input(&inputFC);
inputFC = NULL;
if (mdata->Length() / 1000 != duration)
{
LOG(VB_GENERAL, LOG_INFO, QString("The length of this track in the database was %1s "
"it is now %2s").arg(mdata->Length() / 1000).arg(duration));
// update the track length in the database
mdata->setLength(duration * 1000);
mdata->dumpToDatabase();
// tell any clients that the metadata for this track has changed
gCoreContext->SendMessage(QString("MUSIC_METADATA_CHANGED %1").arg(songID));
}
else
{
LOG(VB_GENERAL, LOG_INFO, QString("The length of this track is unchanged %1s")
.arg(mdata->Length() / 1000));
}
return GENERIC_EXIT_OK;
}