added id3 tag recognition to UploadFileWindow
This commit is contained in:
parent
a4c3aa0fc4
commit
e806ca5f3b
4 changed files with 76 additions and 48 deletions
|
@ -22,7 +22,7 @@
|
|||
|
||||
|
||||
Author : $Author: fgerlits $
|
||||
Version : $Revision: 1.27 $
|
||||
Version : $Revision: 1.28 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/AudioClip.cxx,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
@ -610,11 +610,18 @@ AudioClip :: readTag(Ptr<MetadataTypeContainer>::Ref metadataTypes)
|
|||
throw std::invalid_argument("audio clip has no uri field");
|
||||
}
|
||||
|
||||
if (!TagLib::File::isReadable(getUri()->c_str())) {
|
||||
std::string uri = *getUri();
|
||||
if (uri.substr(0,7) == "file://") {
|
||||
uri = uri.substr(7);
|
||||
} else if (uri.substr(0,5) == "file:") {
|
||||
uri = uri.substr(5);
|
||||
}
|
||||
|
||||
if (!TagLib::File::isReadable(uri.c_str())) {
|
||||
throw std::invalid_argument("binary sound file not found");
|
||||
}
|
||||
|
||||
TagLib::MPEG::File mpegFile(getUri()->c_str());
|
||||
TagLib::MPEG::File mpegFile(uri.c_str());
|
||||
TagLib::ID3v2::Tag* id3v2Tag = mpegFile.ID3v2Tag();
|
||||
if (id3v2Tag) {
|
||||
Ptr<const MetadataType>::Ref metadata;
|
||||
|
@ -641,7 +648,7 @@ AudioClip :: readTag(Ptr<MetadataTypeContainer>::Ref metadataTypes)
|
|||
return;
|
||||
}
|
||||
|
||||
TagLib::FileRef genericFileRef(getUri()->c_str());
|
||||
TagLib::FileRef genericFileRef(uri.c_str());
|
||||
TagLib::Tag* tag = genericFileRef.tag();
|
||||
if (tag) {
|
||||
TagLib::String stringValue;
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
|
||||
Author : $Author: fgerlits $
|
||||
Version : $Revision: 1.14 $
|
||||
Version : $Revision: 1.15 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/AudioClipTest.cxx,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
@ -210,6 +210,7 @@ void
|
|||
AudioClipTest :: tagTest(void)
|
||||
throw (CPPUNIT_NS::Exception)
|
||||
{
|
||||
// should work with either plain file path...
|
||||
Ptr<std::string>::Ref uri(new std::string("var/test10001.mp3"));
|
||||
audioClip->setUri(uri);
|
||||
try {
|
||||
|
@ -225,6 +226,21 @@ AudioClipTest :: tagTest(void)
|
|||
Ptr<const Glib::ustring>::Ref artist
|
||||
= audioClip->getMetadata("dc:creator");
|
||||
CPPUNIT_ASSERT(*artist == "The Muppets");
|
||||
|
||||
// ... or with URI
|
||||
uri.reset(new std::string("file:var/test10001.mp3"));
|
||||
audioClip->setUri(uri);
|
||||
try {
|
||||
audioClip->readTag(metadataTypes);
|
||||
} catch (std::invalid_argument &e) {
|
||||
CPPUNIT_FAIL(e.what());
|
||||
}
|
||||
|
||||
title = audioClip->getMetadata("dc:title");
|
||||
CPPUNIT_ASSERT(*title == "Theme Song");
|
||||
|
||||
artist = audioClip->getMetadata("dc:creator");
|
||||
CPPUNIT_ASSERT(*artist == "The Muppets");
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
|
||||
Author : $Author: fgerlits $
|
||||
Version : $Revision: 1.10 $
|
||||
Version : $Revision: 1.11 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/UploadFileWindow.cxx,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
@ -70,11 +70,10 @@ UploadFileWindow :: UploadFileWindow (Ptr<GLiveSupport>::Ref gLiveSupport,
|
|||
: WhiteWindow("",
|
||||
Colors::White,
|
||||
WidgetFactory::getInstance()->getWhiteWindowCorners()),
|
||||
LocalizedObject(bundle)
|
||||
LocalizedObject(bundle),
|
||||
gLiveSupport(gLiveSupport)
|
||||
{
|
||||
this->gLiveSupport = gLiveSupport;
|
||||
fileName.reset(new std::string());
|
||||
isFileGood = false;
|
||||
isAudioClipValid = false;
|
||||
|
||||
Ptr<WidgetFactory>::Ref wf = WidgetFactory::getInstance();
|
||||
|
||||
|
@ -224,29 +223,51 @@ UploadFileWindow :: onChooseFileButtonClicked(void) throw ()
|
|||
void
|
||||
UploadFileWindow :: updateFileInfo(void) throw ()
|
||||
{
|
||||
std::string newFileName = fileNameEntry->get_text().raw();
|
||||
std::string fileName = fileNameEntry->get_text().raw();
|
||||
Ptr<std::string>::Ref newUri(new std::string("file://"));
|
||||
newUri->append(fileName);
|
||||
|
||||
if (*fileName != newFileName) {
|
||||
if (!isAudioClipValid ||
|
||||
*audioClip->getUri() != *newUri) {
|
||||
// see if the file exists, and is readable
|
||||
std::ifstream file(newFileName.c_str());
|
||||
std::ifstream file(fileName.c_str());
|
||||
if (!file.good()) {
|
||||
isFileGood = false;
|
||||
isAudioClipValid = false;
|
||||
file.close();
|
||||
return;
|
||||
}
|
||||
file.close();
|
||||
isFileGood = true;
|
||||
fileName.reset(new std::string(newFileName));
|
||||
|
||||
fileURI.reset(new std::string("file://"));
|
||||
*fileURI += *fileName;
|
||||
isAudioClipValid = true;
|
||||
|
||||
Ptr<time_duration>::Ref playlength;
|
||||
try {
|
||||
playlength = readPlaylength(fileName);
|
||||
} catch (std::invalid_argument &e) {
|
||||
statusBar->set_text(e.what());
|
||||
playlength.reset(new time_duration(0,0,0,0));
|
||||
}
|
||||
|
||||
Ptr<const Glib::ustring>::Ref tempTitle(new const Glib::ustring);
|
||||
audioClip.reset(new AudioClip(tempTitle, playlength, newUri));
|
||||
|
||||
// read the id3 tags
|
||||
try {
|
||||
audioClip->readTag(gLiveSupport->getMetadataTypeContainer());
|
||||
} catch (std::invalid_argument &e) {
|
||||
statusBar->set_text(e.what());
|
||||
isAudioClipValid = false;
|
||||
return;
|
||||
}
|
||||
|
||||
titleEntry->set_text(*audioClip->getTitle());
|
||||
Ptr<const Glib::ustring>::Ref creator
|
||||
= audioClip->getMetadata("dc:creator");
|
||||
creatorEntry->set_text(creator ? *creator : "");
|
||||
|
||||
Ptr<const Glib::ustring>::Ref genre
|
||||
= audioClip->getMetadata("dc:type");
|
||||
genreEntry->set_text(genre ? *genre : "");
|
||||
|
||||
// display the new play length
|
||||
std::ostringstream lengthStr;
|
||||
lengthStr << std::setfill('0')
|
||||
|
@ -278,21 +299,15 @@ UploadFileWindow :: onUploadButtonClicked(void) throw ()
|
|||
{
|
||||
try {
|
||||
updateFileInfo();
|
||||
if (!isFileGood) {
|
||||
if (!isAudioClipValid) {
|
||||
// TODO: localize error message
|
||||
throw std::invalid_argument("file does not exist");
|
||||
}
|
||||
|
||||
Ptr<const Glib::ustring>::Ref ustrValue;
|
||||
|
||||
ustrValue.reset(new Glib::ustring(titleEntry->get_text()));
|
||||
|
||||
// create and upload an AudioClip object
|
||||
Ptr<AudioClip>::Ref audioClip(new AudioClip(ustrValue,
|
||||
playlength,
|
||||
fileURI));
|
||||
|
||||
// set the metadata available
|
||||
Ptr<const Glib::ustring>::Ref ustrValue(new Glib::ustring(
|
||||
titleEntry->get_text() ));
|
||||
audioClip->setTitle(ustrValue);
|
||||
ustrValue.reset(new Glib::ustring(creatorEntry->get_text()));
|
||||
audioClip->setMetadata(ustrValue, "dc:creator");
|
||||
ustrValue.reset(new Glib::ustring(genreEntry->get_text()));
|
||||
|
@ -300,6 +315,7 @@ UploadFileWindow :: onUploadButtonClicked(void) throw ()
|
|||
ustrValue.reset(new Glib::ustring(
|
||||
fileFormatComboBox->get_active_text()));
|
||||
audioClip->setMetadata(ustrValue, "dc:format");
|
||||
// TODO: is this really what we mean by dc:format?
|
||||
|
||||
// upload the audio clip
|
||||
gLiveSupport->uploadFile(audioClip);
|
||||
|
@ -335,10 +351,10 @@ UploadFileWindow :: onCloseButtonClicked(void) throw ()
|
|||
* Determine the length of an audio file
|
||||
*----------------------------------------------------------------------------*/
|
||||
Ptr<time_duration>::Ref
|
||||
UploadFileWindow :: readPlaylength(Ptr<const std::string>::Ref fileName)
|
||||
UploadFileWindow :: readPlaylength(const std::string & fileName)
|
||||
throw (std::invalid_argument)
|
||||
{
|
||||
TagLib::FileRef fileRef(fileName->c_str());
|
||||
TagLib::FileRef fileRef(fileName.c_str());
|
||||
TagLib::AudioProperties * audioProperties = fileRef.audioProperties();
|
||||
|
||||
if (audioProperties) {
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
|
||||
Author : $Author: fgerlits $
|
||||
Version : $Revision: 1.4 $
|
||||
Version : $Revision: 1.5 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/UploadFileWindow.h,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
@ -87,7 +87,7 @@ using namespace LiveSupport::Widgets;
|
|||
* </code></pre>
|
||||
*
|
||||
* @author $Author: fgerlits $
|
||||
* @version $Revision: 1.4 $
|
||||
* @version $Revision: 1.5 $
|
||||
*/
|
||||
class UploadFileWindow : public WhiteWindow, public LocalizedObject
|
||||
{
|
||||
|
@ -225,23 +225,12 @@ class UploadFileWindow : public WhiteWindow, public LocalizedObject
|
|||
/**
|
||||
* The name of the file to upload.
|
||||
*/
|
||||
Ptr<std::string>::Ref fileName;
|
||||
Ptr<AudioClip>::Ref audioClip;
|
||||
|
||||
/**
|
||||
* Signals if the file under fileName is good.
|
||||
* Signals if the audio clip is valid.
|
||||
*/
|
||||
bool isFileGood;
|
||||
|
||||
/**
|
||||
* The URI to the file to upload.
|
||||
* Basically same as fileName, with 'file://' prepended.
|
||||
*/
|
||||
Ptr<std::string>::Ref fileURI;
|
||||
|
||||
/**
|
||||
* The playling length of the file to upload.
|
||||
*/
|
||||
Ptr<time_duration>::Ref playlength;
|
||||
bool isAudioClipValid;
|
||||
|
||||
/**
|
||||
* Function to catch the event of the choose file button being
|
||||
|
@ -289,7 +278,7 @@ class UploadFileWindow : public WhiteWindow, public LocalizedObject
|
|||
* length could not be determined
|
||||
*/
|
||||
Ptr<time_duration>::Ref
|
||||
readPlaylength(Ptr<const std::string>::Ref fileName)
|
||||
readPlaylength(const std::string & fileName)
|
||||
throw (std::invalid_argument);
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue