int Playlist::CreateCDMP3(void) { // Check & get global settings if (!gCoreContext->GetNumSetting("CDWriterEnabled")) { VERBOSE(VB_GENERAL, "CD Writer is not enabled."); return 1; } QString scsidev = MediaMonitor::defaultCDWriter(); if (scsidev.isEmpty()) { VERBOSE(VB_GENERAL, "No CD Writer device defined."); return 1; } int disksize = gCoreContext->GetNumSetting("CDDiskSize", 2); QString writespeed = gCoreContext->GetSetting("CDWriteSpeed", "2"); bool MP3_dir_flag = gCoreContext->GetNumSetting("CDCreateDir", 1); double size_in_MB = 0.0; QStringList reclist; SongList::const_iterator it = songs.begin(); for (; it != songs.end(); ++it) { if ((*it)->getCDFlag()) continue; if ((*it)->getValue() == 0) { VERBOSE(VB_IMPORTANT, kID0err); } else if ((*it)->getValue() > 0) { // Normal track Metadata *tmpdata = all_available_music->getMetadata((*it)->getValue()); if (tmpdata) { // check filename.. QFileInfo testit(tmpdata->Filename()); if (!testit.exists()) continue; size_in_MB += testit.size() / 1000000.0; QString outline; if (MP3_dir_flag) { if (tmpdata->Artist().length() > 0) outline += tmpdata->Artist() + "/"; if (tmpdata->Album().length() > 0) outline += tmpdata->Album() + "/"; } outline += "="; outline += tmpdata->Filename(); reclist += outline; } } else if ((*it)->getValue() < 0) { // FIXME: handle playlists } } int max_size; if (disksize == 0) max_size = 650; else max_size = 700; if (size_in_MB >= max_size) { VERBOSE(VB_GENERAL, "MP3 CD creation aborted -- cd size too big."); return 1; } // probably should tie stdout of mkisofs to stdin of cdrecord sometime QString tmptemplate("/tmp/mythmusicXXXXXX"); QString tmprecordlist = createTempFile(tmptemplate); if (tmprecordlist == tmptemplate) { VERBOSE(VB_IMPORTANT, "Unable to open temporary file"); return 1; } QString tmprecordisofs = createTempFile(tmptemplate); if (tmprecordisofs == tmptemplate) { VERBOSE(VB_IMPORTANT, "Unable to open temporary file"); return 1; } QFile reclistfile(tmprecordlist); if (!reclistfile.open(QIODevice::WriteOnly)) { VERBOSE(VB_IMPORTANT, "Unable to open temporary file"); return 1; } QTextStream recstream(&reclistfile); QStringList::Iterator iter; for (iter = reclist.begin(); iter != reclist.end(); ++iter) { recstream << *iter << "\n"; } reclistfile.close(); MythProgressDialog *progress; progress = new MythProgressDialog(QObject::tr("Creating CD File System"), 100); progress->setProgress(1); QStringList args("mkisofs"); args += "-graft-points"; args += "-path-list"; args += tmprecordlist; args += "-o"; args += tmprecordisofs; args += "-J"; args += "-R"; VERBOSE(VB_GENERAL, "Running: " + args.join(" ")); bool retval = 0; Q3Process isofs(args); if (isofs.start()) { while (1) { while (isofs.canReadLineStderr()) { QString buf = isofs.readLineStderr(); if (buf[6] == '%') { buf = buf.mid(0, 3); progress->setProgress(buf.trimmed().toInt()); } } if (isofs.isRunning()) { qApp->processEvents(); usleep(100000); } else { if (!isofs.normalExit()) { VERBOSE(VB_IMPORTANT, "Unable to run 'mkisofs'"); retval = 1; } break; } } } else { VERBOSE(VB_IMPORTANT, "Unable to run 'mkisofs'"); retval = 1; } progress->Close(); progress->deleteLater(); progress = new MythProgressDialog(QObject::tr("Burning CD"), 100); progress->setProgress(2); args = QStringList("cdrecord"); args += "-v"; //args += "-dummy"; args += "dev="; args += scsidev; if (writespeed.toInt() > 0) { args += "-speed="; args += writespeed; } args += "-data"; args += tmprecordisofs; VERBOSE(VB_GENERAL, "Running: " + args.join(" ")); Q3Process burn(args); if (burn.start()) { while (1) { while (burn.canReadLineStderr()) { QString err = burn.readLineStderr(); if (err == "cdrecord: Drive needs to reload the media" || err == "cdrecord: Input/output error." || err == "cdrecord: No disk / Wrong disk!") { VERBOSE(VB_IMPORTANT, err); burn.kill(); retval = 1; } } while (burn.canReadLineStdout()) { QString line = burn.readLineStdout(); if (line.mid(15, 2) == "of") { int mbdone = line.mid(10, 5).trimmed().toInt(); int mbtotal = line.mid(17, 5).trimmed().toInt(); if (mbtotal > 0) { progress->setProgress((mbdone * 100) / mbtotal); } } } if (burn.isRunning()) { qApp->processEvents(); usleep(10000); } else { if (!burn.normalExit()) { VERBOSE(VB_IMPORTANT, "Unable to run 'cdrecord'"); retval = 1; } break; } } } else { VERBOSE(VB_IMPORTANT, "Unable to run 'cdrecord'"); retval = 1; } progress->Close(); progress->deleteLater(); QFile::remove(tmprecordlist); QFile::remove(tmprecordisofs); return retval; }
bool operator==(const Metadata& a, const Metadata& b) { if (a.Filename() == b.Filename()) return true; return false; }
int Playlist::CreateCDMP3(void) { // Check & get global settings if (!gCoreContext->GetNumSetting("CDWriterEnabled")) { LOG(VB_GENERAL, LOG_ERR, "CD Writer is not enabled."); return 1; } QString scsidev = MediaMonitor::defaultCDWriter(); if (scsidev.isEmpty()) { LOG(VB_GENERAL, LOG_ERR, "No CD Writer device defined."); return 1; } int disksize = gCoreContext->GetNumSetting("CDDiskSize", 2); QString writespeed = gCoreContext->GetSetting("CDWriteSpeed", "2"); bool MP3_dir_flag = gCoreContext->GetNumSetting("CDCreateDir", 1); double size_in_MB = 0.0; QStringList reclist; SongList::const_iterator it = songs.begin(); for (; it != songs.end(); ++it) { if ((*it)->getCDFlag()) continue; if ((*it)->getValue() == 0) { LOG(VB_GENERAL, LOG_ERR, kID0err); } else if ((*it)->getValue() > 0) { // Normal track Metadata *tmpdata = all_available_music->getMetadata((*it)->getValue()); if (tmpdata) { // check filename.. QFileInfo testit(tmpdata->Filename()); if (!testit.exists()) continue; size_in_MB += testit.size() / 1000000.0; QString outline; if (MP3_dir_flag) { if (tmpdata->Artist().length() > 0) outline += tmpdata->Artist() + "/"; if (tmpdata->Album().length() > 0) outline += tmpdata->Album() + "/"; } outline += "="; outline += tmpdata->Filename(); reclist += outline; } } else if ((*it)->getValue() < 0) { // FIXME: handle playlists } } int max_size; if (disksize == 0) max_size = 650; else max_size = 700; if (size_in_MB >= max_size) { LOG(VB_GENERAL, LOG_ERR, "MP3 CD creation aborted -- cd size too big."); return 1; } // probably should tie stdout of mkisofs to stdin of cdrecord sometime QString tmptemplate("/tmp/mythmusicXXXXXX"); QString tmprecordlist = createTempFile(tmptemplate); if (tmprecordlist == tmptemplate) { LOG(VB_GENERAL, LOG_ERR, "Unable to open temporary file"); return 1; } QString tmprecordisofs = createTempFile(tmptemplate); if (tmprecordisofs == tmptemplate) { LOG(VB_GENERAL, LOG_ERR, "Unable to open temporary file"); return 1; } QFile reclistfile(tmprecordlist); if (!reclistfile.open(QIODevice::WriteOnly)) { LOG(VB_GENERAL, LOG_ERR, "Unable to open temporary file"); return 1; } QTextStream recstream(&reclistfile); QStringList::Iterator iter; for (iter = reclist.begin(); iter != reclist.end(); ++iter) { recstream << *iter << "\n"; } reclistfile.close(); progress = new MythProgressDialog(QObject::tr("Creating CD File System"), 100); progress->setProgress(1); QStringList args; QString command; command = "mkisofs"; args << "-graft-points"; args << "-path-list"; args << tmprecordlist; args << "-o"; args << tmprecordisofs; args << "-J"; args << "-R"; uint flags = kMSRunShell | kMSStdErr | kMSBuffered | kMSDontDisableDrawing | kMSDontBlockInputDevs | kMSRunBackground; proc = new MythSystem(command, args, flags); connect(proc, SIGNAL(readDataReady(int)), this, SLOT(mkisofsData(int)), Qt::DirectConnection); connect(proc, SIGNAL(finished()), this, SLOT(processExit()), Qt::DirectConnection); connect(proc, SIGNAL(error(uint)), this, SLOT(processExit(uint)), Qt::DirectConnection); procExitVal = GENERIC_EXIT_RUNNING; proc->Run(); while( procExitVal == GENERIC_EXIT_RUNNING ) usleep( 100000 ); uint retval = procExitVal; progress->Close(); progress->deleteLater(); proc->disconnect(); delete proc; if (retval) { LOG(VB_GENERAL, LOG_ERR, QString("Unable to run mkisofs: returns %1") .arg(retval)); } else { progress = new MythProgressDialog(QObject::tr("Burning CD"), 100); progress->setProgress(2); command = "cdrecord"; args = QStringList(); args << "-v"; //args << "-dummy"; args << QString("dev=%1").arg(scsidev); if (writespeed.toInt() > 0) { args << "-speed="; args << writespeed; } args << "-data"; args << tmprecordisofs; flags = kMSRunShell | kMSStdErr | kMSStdOut | kMSBuffered | kMSDontDisableDrawing | kMSDontBlockInputDevs | kMSRunBackground; proc = new MythSystem(command, args, flags); connect(proc, SIGNAL(readDataReady(int)), this, SLOT(cdrecordData(int)), Qt::DirectConnection); connect(proc, SIGNAL(finished()), this, SLOT(processExit()), Qt::DirectConnection); connect(proc, SIGNAL(error(uint)), this, SLOT(processExit(uint)), Qt::DirectConnection); procExitVal = GENERIC_EXIT_RUNNING; proc->Run(); while( procExitVal == GENERIC_EXIT_RUNNING ) usleep( 100000 ); retval = procExitVal; progress->Close(); progress->deleteLater(); proc->disconnect(); delete proc; if (retval) { LOG(VB_GENERAL, LOG_ERR, QString("Unable to run cdrecord: returns %1") .arg(retval)); } } QFile::remove(tmprecordlist); QFile::remove(tmprecordisofs); return retval; }