osx - How to get the lyrics of a song from the song file -


itunes lyrics information song file

itunes lyrics information song file, , want ask if there methods or apis lyrics song file(not use network!),in cocoa or carbon.thank much. :)

and there no easy way this.

you need use third-party library. and, while there third-party libraries transparently handle reading tags variety of different formats, handle "basic set" of tags way; else, have know formats.

for example, taglib, artist, this:

taglib::fileref f1("myfile.mp3"); cout << f1.tag()->artist(); taglib::fileref f2("myotherfile.aac"); cout << f2.tag()->artist(); 

but lyrics, it's this:

taglib::mpeg::file f1("myfile.mp3"); taglib::id3v2::framelist frames = f1.id3v2tag()->framelistmap()["uslt"]; if (!frames.isempty()) {   taglib::id3v2::unsynchronizedlyricsframe *frame =      dynamic_cast<taglib::id3v2::unsynchronizedlyricsframe *>(frames.front());   // there multiple frames here; may want @ language   // and/or description, instead of picking first.   if (frame) cout << frames->text; } taglib::mp4::file f2("myotherfile.aac"); taglib::mp4::item item = f2.tag()->itemlistmap()["\xa9lyr"]; taglib::stringlist strings = item.tostringlist(); if (!strings.isempty()) {   // above, there multiple strings.   cout << strings->front(); } 

that's off top of head, don't expect work as-is. , of course there's no error handling. big thing that's missing doesn't show how figure out type of file you're dealing with, , type of tag you'll out of it. (this pretty easy 2 examples above, file named ".flac" either ogg flac or raw flac, , have vorbiscomment, metaflac, id3, or ape tags.) taglib has stuff there well, it's still not trivial.

fortunately, if care getting same lyrics itunes 10.6.3, it's not hard; rules seem this:

  • if extension mp2 or mp3 (case-insensitive), , it's mpeg audio file id3v2.3 or id3v2.4 metadata, contents of first uslt tag (no matter description or language) lyrics.
  • if extension matches .m4?, .aac, .mp4, or maybe few others, , it's mpeg-4 file audio track imtf metadata, contents of first string in first ©lyr chunk lyrics.
  • in other case, there no lyrics.

and, since you're dealing id3v2 , itmf, may simpler use separate libraries each—for example, libmp4v2 handles mpeg4 files more taglib (because doesn't handle but mpeg4 files), this:

mp4filehandle f = mp4open("myotherfile.aac"); const mp4tags *tags = mp4tagsalloc(); mp4tagsfetch(tags, f); cout << tags->lyrics; mp4tagsfree(tags); mp4close(f); 

also, if doesn't have in native code (cocoa or carbon), there simpler libraries in other languages. example, in python, mutagen, can this:

def printlyrics(path):   f = mutagen.file(path)   key in f.keys():     if key.startswith('uslt') or key == u'\xa9lyr':       print f[key]       return printlyrics("myfile.mp3") printlyrics("myotherfile.aac") 

of course still had know id3v2 calls lyrics "uslt:my desc:'eng'" while itmf calls them "©lyr", because of dynamic nature of python, mutagen can hide of other details.


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -