Пример #1
0
 void testSetYear()
 {
   Ogg::XiphComment cmt;
   cmt.addField("YEAR", "2009");
   cmt.addField("DATE", "2008");
   cmt.setYear(1995);
   CPPUNIT_ASSERT(cmt.fieldListMap()["YEAR"].isEmpty());
   CPPUNIT_ASSERT_EQUAL(String("1995"), cmt.fieldListMap()["DATE"].front());
 }
Пример #2
0
  void testInvalidKeys()
  {
    PropertyMap map;
    map[""] = String("invalid key: empty string");
    map["A=B"] = String("invalid key: contains '='");
    map["A~B"] = String("invalid key: contains '~'");

    Ogg::XiphComment cmt;
    PropertyMap unsuccessful = cmt.setProperties(map);
    CPPUNIT_ASSERT_EQUAL((unsigned int)3, unsuccessful.size());
    CPPUNIT_ASSERT(cmt.properties().isEmpty());
  }
Пример #3
0
void VorbisReader::read()
{
	std::auto_ptr<Ogg::File> of;
	Ogg::XiphComment *tag;

	switch(mType) {
		case ReaderSelector::OGG_FLAC:
			of.reset(new Ogg::FLAC::File(mValues["file"].c_str()));
			break;

		default:
			of.reset(new Ogg::Vorbis::File(mValues["file"].c_str()));
			break;
	}

	tag = (Ogg::XiphComment *)of.get()->tag();

	if(tag) {
		const Ogg::FieldListMap *flm = &tag->fieldListMap();

		std::map<std::string, std::string>::iterator it =
				sMapping.begin();

		const StringList *sl;

		while(it != sMapping.end()) {

			sl = &(*flm)[sMapping[it->first]];

			if(!sl->isEmpty()) {
				mValues[it->first.c_str()] = (*sl)[0].toCString(true);
			}

			++it;
		}
	} else {
		mErr = 1;
	}

	int len;
	char buff[16];
	if(of->audioProperties()) {
		len = of->audioProperties()->length();
		sprintf(buff, "%d", len);
		mValues["length"] = buff;
	}
}
Пример #4
0
 void testSetTrack()
 {
   Ogg::XiphComment cmt;
   cmt.addField("TRACKNUM", "7");
   cmt.addField("TRACKNUMBER", "8");
   cmt.setTrack(3);
   CPPUNIT_ASSERT(cmt.fieldListMap()["TRACKNUM"].isEmpty());
   CPPUNIT_ASSERT_EQUAL(String("3"), cmt.fieldListMap()["TRACKNUMBER"].front());
 }
Пример #5
0
 void testTrack()
 {
   Ogg::XiphComment cmt;
   CPPUNIT_ASSERT_EQUAL((unsigned int)0, cmt.track());
   cmt.addField("TRACKNUM", "7");
   CPPUNIT_ASSERT_EQUAL((unsigned int)7, cmt.track());
   cmt.addField("TRACKNUMBER", "8");
   CPPUNIT_ASSERT_EQUAL((unsigned int)8, cmt.track());
 }
Пример #6
0
 void testYear()
 {
   Ogg::XiphComment cmt;
   CPPUNIT_ASSERT_EQUAL((unsigned int)0, cmt.year());
   cmt.addField("YEAR", "2009");
   CPPUNIT_ASSERT_EQUAL((unsigned int)2009, cmt.year());
   cmt.addField("DATE", "2008");
   CPPUNIT_ASSERT_EQUAL((unsigned int)2008, cmt.year());
 }
Пример #7
0
int main(int argc, char **argv) {
  if (argc != 2) {
    std::cout << "usage: " << argv[0] << " file.mp3" << std::endl;
    exit(1);
  }
  char *filename = argv[1];

  Vorbis::File file(filename);
  Ogg::XiphComment *tag = file.tag();

  tag->setTitle("Title");
  tag->setArtist("Artist");
  tag->setAlbum("Album");
  tag->setComment("Comment");
  tag->setGenre("Pop");
  tag->setYear(2011);
  tag->setTrack(7);

  tag->addField("VERSION", "original");
  tag->addField("PERFORMER", "Performer");
  tag->addField("COPYRIGHT", "2011 Me, myself and I");
  tag->addField("LICENSE", "Any Use Permitted");
  tag->addField("ORGANIZATION", "Organization");
  tag->addField("DESCRIPTION", "Test file");
  tag->addField("LOCATION", "Earth");
  tag->addField("CONTACT", "Contact");

  tag->addField("MULTIPLE", "A");
  tag->addField("MULTIPLE", "B", false);

  file.save();
}
Пример #8
0
bool TagEditor::save()
{
	if ( fRef )
	{
		bool mustSave = false, result = false;

		if ( !isChecked() )
			clearValues();

		File &file = *fRef->file();

		Tag &tag = getTag( *fRef, file );
		if ( titleE->text() != tag.title().toCString( true ) )
		{
			tag.setTitle( String( titleE->text().toUtf8().data(), String::UTF8 ) );
			mustSave = true;
		}
		if ( artistE->text() != tag.artist().toCString( true ) )
		{
			tag.setArtist( String( artistE->text().toUtf8().data(), String::UTF8 ) );
			mustSave = true;
		}
		if ( albumE->text() != tag.album().toCString( true ) )
		{
			tag.setAlbum( String( albumE->text().toUtf8().data(), String::UTF8 ) );
			mustSave = true;
		}
		if ( commentE->text() != tag.comment().toCString( true ) )
		{
			tag.setComment( String( commentE->text().toUtf8().data(), String::UTF8 ) );
			mustSave = true;
		}
		if ( genreE->text() != tag.genre().toCString( true ) )
		{
			tag.setGenre( String( genreE->text().toUtf8().data(), String::UTF8 ) );
			mustSave = true;
		}
		if ( ( uint )yearB->value() != tag.year() )
		{
			tag.setYear( yearB->value() );
			mustSave = true;
		}
		if ( ( uint )trackB->value() != tag.track() )
		{
			tag.setTrack( trackB->value() );
			mustSave = true;
		}

		if ( isChecked() && ( pictureModificated || pictureBChecked != pictureB->isChecked() ) )
		{
			const bool hasPicture = pictureB->isChecked() && !picture->isEmpty();
			if ( instanceOf( file, MPEG::File ) || instanceOf( file, RIFF::AIFF::File ) )
			{
				ID3v2::Tag *id3v2 = NULL;
				if ( instanceOf( file, MPEG::File ) )
					id3v2 = ( ( MPEG::File & )file ).ID3v2Tag( hasPicture );
				else if ( instanceOf( file, RIFF::AIFF::File ) )
					id3v2 = ( ( RIFF::AIFF::File & )file ).tag();
				if ( id3v2 )
				{
					id3v2->removeFrames( "APIC" );
					if ( hasPicture )
					{
						ID3v2::AttachedPictureFrame *pictureFrame = new ID3v2::AttachedPictureFrame;
						pictureFrame->setType( ID3v2::AttachedPictureFrame::FrontCover );
						pictureFrame->setMimeType( pictureMimeType.data() );
						pictureFrame->setPicture( *picture );
						id3v2->addFrame( pictureFrame );
					}
					mustSave = true;
				}
			}
			else if ( instanceOf( file, FLAC::File ) )
			{
				FLAC::File &flacF = ( FLAC::File & )file;
				flacF.removePictures();
				if ( hasPicture )
				{
					FLAC::Picture *flacPicture = new FLAC::Picture;
					flacPicture->setMimeType( pictureMimeType.data() );
					flacPicture->setType( FLAC::Picture::FrontCover );
					flacPicture->setData( *picture );
					flacF.addPicture( flacPicture );
				}
				mustSave = true;
			}
			else if ( instanceOf( file, MP4::File ) )
			{
				MP4::ItemListMap &itemListMap = ( ( MP4::File & )file ).tag()->itemListMap();
				if ( itemListMap.contains( "covr" ) )
					itemListMap.erase( "covr" );
				if ( hasPicture )
				{
					MP4::CoverArt::Format format = ( MP4::CoverArt::Format )0;
					if ( pictureMimeType == "image/jpeg" )
						format = MP4::CoverArt::JPEG;
					else if ( pictureMimeType == "image/png" )
						format = MP4::CoverArt::PNG;
#if TAGLIB18
					else if ( pictureMimeType == "image/bmp" )
						format = MP4::CoverArt::BMP;
					else if ( pictureMimeType == "image/gif" )
						format = MP4::CoverArt::GIF;
#endif
					if ( format )
					{
						MP4::CoverArtList coverArtList;
						coverArtList.append( MP4::CoverArt( format, *picture ) );
						itemListMap.insert( "covr", coverArtList );
					}
				}
				mustSave = true;
			}
			else if ( isOgg( file ) )
			{
				Ogg::XiphComment *xiphComment = getXiphComment( file );
				if ( xiphComment )
				{
					xiphComment->removeField( "METADATA_BLOCK_PICTURE" );
					if ( hasPicture )
					{
						FLAC::Picture flacPicture;
						flacPicture.setMimeType( pictureMimeType.data() );
						flacPicture.setType( FLAC::Picture::FrontCover );
						flacPicture.setData( *picture );
						const ByteVector pict_data = flacPicture.render();
						xiphComment->addField( "METADATA_BLOCK_PICTURE", QByteArray::fromRawData( pict_data.data(), pict_data.size() ).toBase64().data() );
					}
					mustSave = true;
				}
			}
		}
		else if ( !isChecked() ) //Usuwanie wszystkich znanych tagów
		{
			mustSave = true;

			if ( instanceOf( file, MPEG::File ) )
				( ( MPEG::File & )file ).strip();
			else if ( instanceOf( file, MPC::File ) )
				( ( MPC::File & )file ).strip();
			else if ( instanceOf( file, WavPack::File ) )
				( ( WavPack::File & )file ).strip();
			else if ( instanceOf( file, TrueAudio::File ) )
				( ( TrueAudio::File & )file ).strip();
			else if ( instanceOf( file, APE::File ) )
				( ( APE::File & )file ).strip();
			else if ( instanceOf( file, MP4::File ) )
				( ( MP4::File & )file ).tag()->itemListMap().clear();
			else if ( instanceOf( file, ASF::File ) )
				( ( ASF::File & )file ).tag()->attributeListMap().clear();
			else if ( isOgg( file ) )
				removeXiphComment( getXiphComment( file ) );
			else if ( instanceOf( file, FLAC::File ) )
			{
				FLAC::File &flacF = ( FLAC::File & )file;
				flacF.removePictures();
#if TAGLIB19
				if ( flacF.hasXiphComment() )
#endif
					removeXiphComment( flacF.xiphComment() );
			}
			else if ( instanceOf( file, RIFF::AIFF::File ) )
			{
				ID3v2::Tag *id3v2 = ( ( RIFF::AIFF::File & )file ).tag();
				if ( id3v2 )
				{
					ID3v2::FrameList frameList = id3v2->frameList();
					for ( ID3v2::FrameList::ConstIterator it = frameList.begin() ; it != frameList.end() ; ++it )
						id3v2->removeFrame( *it );
				}
			}
#if TAGLIB18
			else if ( instanceOf( file, Mod::File ) || instanceOf( file, S3M::File ) || instanceOf( file, IT::File ) || instanceOf( file, XM::File ) )
			{
				Mod::Tag *modTag = NULL;
				if ( instanceOf( file, Mod::File ) )
					modTag = ( ( Mod::File & )file ).tag();
				else if ( instanceOf( file, S3M::File ) )
					modTag = ( ( S3M::File & )file ).tag();
				else if ( instanceOf( file, IT::File ) )
					modTag = ( ( IT::File & )file ).tag();
				else if ( instanceOf( file, XM::File ) )
					modTag = ( ( XM::File & )file ).tag();
				if ( modTag )
					modTag->setTrackerName( String::null );
			}
#endif
		}

		/* FLAC::File writer BUG workaround - remove ID3 tags */
		if ( mustSave && instanceOf( file, FLAC::File ) )
		{
			FLAC::File &flacF = ( FLAC::File & )file;
#if TAGLIB19
			if ( flacF.hasID3v1Tag() || flacF.hasID3v2Tag() )
#else
			if ( flacF.ID3v1Tag() || flacF.ID3v2Tag() )
#endif
			{
				const FileName fName = fRef->file()->name();
				result = fRef->save();
				delete fRef;
				fRef = NULL;
				if ( result )
					result = MPEG::File( fName, false ).save( MPEG::File::NoTags );
				mustSave = false;
			}
		}

#if TAGLIB19
		/* No ID3v2 in WAV, only InfoTag */
		if ( mustSave && instanceOf( file, RIFF::WAV::File ) )
		{
			RIFF::WAV::File &wavF = ( RIFF::WAV::File & )file;
			wavF.save( wavF.InfoTag()->isEmpty() ? RIFF::WAV::File::NoTags : RIFF::WAV::File::Info );
			mustSave = false;
		}
#endif

		return mustSave ? fRef->save() : ( fRef ? true : result );
	}
	return false;
}