TagLib: Add exception handling
The TagLib C++ code was missing generic try/catch handling which could result in any generic errors throwing straight to a full crash. Add exception handling and logging, which will fix a logged crash regardless of whether the tags are read correctly or not by the newer TagLib version. Fixes #415 Signed-off-by: Christopher Snowhill <kode54@gmail.com>
This commit is contained in:
parent
61165a022a
commit
e9a17a8ba5
3 changed files with 257 additions and 237 deletions
|
@ -14,6 +14,8 @@
|
||||||
#import <tag/tfilestream.h>
|
#import <tag/tfilestream.h>
|
||||||
#import <tag/tbytevectorstream.h>
|
#import <tag/tbytevectorstream.h>
|
||||||
|
|
||||||
|
#import "Logging.h"
|
||||||
|
|
||||||
@implementation TagLibID3v2Reader
|
@implementation TagLibID3v2Reader
|
||||||
|
|
||||||
+ (NSDictionary *)metadataForTag:(NSData *)tagBlock {
|
+ (NSDictionary *)metadataForTag:(NSData *)tagBlock {
|
||||||
|
@ -53,110 +55,115 @@
|
||||||
//
|
//
|
||||||
// }
|
// }
|
||||||
|
|
||||||
TagLib::ByteVector vector((const char *)[tagBlock bytes], (unsigned int)[tagBlock length]);
|
try {
|
||||||
TagLib::ByteVectorStream vectorStream(vector);
|
TagLib::ByteVector vector((const char *)[tagBlock bytes], (unsigned int)[tagBlock length]);
|
||||||
|
TagLib::ByteVectorStream vectorStream(vector);
|
||||||
|
|
||||||
TagLib::FileRef f((TagLib::IOStream *)&vectorStream, false);
|
TagLib::FileRef f((TagLib::IOStream *)&vectorStream, false);
|
||||||
if(!f.isNull()) {
|
if(!f.isNull()) {
|
||||||
const TagLib::Tag *tag = f.tag();
|
const TagLib::Tag *tag = f.tag();
|
||||||
|
|
||||||
if(tag) {
|
if(tag) {
|
||||||
TagLib::String artist, albumartist, composer, title, album, genre, comment, unsyncedlyrics;
|
TagLib::String artist, albumartist, composer, title, album, genre, comment, unsyncedlyrics;
|
||||||
int year, track, disc;
|
int year, track, disc;
|
||||||
float rgAlbumGain, rgAlbumPeak, rgTrackGain, rgTrackPeak;
|
float rgAlbumGain, rgAlbumPeak, rgTrackGain, rgTrackPeak;
|
||||||
TagLib::String cuesheet;
|
TagLib::String cuesheet;
|
||||||
TagLib::String soundcheck;
|
TagLib::String soundcheck;
|
||||||
|
|
||||||
artist = tag->artist();
|
artist = tag->artist();
|
||||||
//albumartist = tag->albumartist();
|
//albumartist = tag->albumartist();
|
||||||
//composer = tag->composer();
|
//composer = tag->composer();
|
||||||
title = tag->title();
|
title = tag->title();
|
||||||
album = tag->album();
|
album = tag->album();
|
||||||
genre = tag->genre();
|
genre = tag->genre();
|
||||||
comment = tag->comment();
|
comment = tag->comment();
|
||||||
//cuesheet = tag->cuesheet();
|
//cuesheet = tag->cuesheet();
|
||||||
//unsyncedlyrics = tag->unsyncedlyrics();
|
//unsyncedlyrics = tag->unsyncedlyrics();
|
||||||
|
|
||||||
year = tag->year();
|
year = tag->year();
|
||||||
[dict setObject:@(year) forKey:@"year"];
|
[dict setObject:@(year) forKey:@"year"];
|
||||||
|
|
||||||
track = tag->track();
|
track = tag->track();
|
||||||
[dict setObject:@(track) forKey:@"track"];
|
[dict setObject:@(track) forKey:@"track"];
|
||||||
|
|
||||||
/*disc = tag->disc();
|
/*disc = tag->disc();
|
||||||
[dict setObject:@(disc) forKey:@"disc"];*/
|
[dict setObject:@(disc) forKey:@"disc"];*/
|
||||||
|
|
||||||
/*rgAlbumGain = tag->rgAlbumGain();
|
/*rgAlbumGain = tag->rgAlbumGain();
|
||||||
rgAlbumPeak = tag->rgAlbumPeak();
|
rgAlbumPeak = tag->rgAlbumPeak();
|
||||||
rgTrackGain = tag->rgTrackGain();
|
rgTrackGain = tag->rgTrackGain();
|
||||||
rgTrackPeak = tag->rgTrackPeak();
|
rgTrackPeak = tag->rgTrackPeak();
|
||||||
[dict setObject:@(rgAlbumGain) forKey:@"replaygain_album_gain"];
|
[dict setObject:@(rgAlbumGain) forKey:@"replaygain_album_gain"];
|
||||||
[dict setObject:@(rgAlbumPeak) forKey:@"replaygain_album_peak"];
|
[dict setObject:@(rgAlbumPeak) forKey:@"replaygain_album_peak"];
|
||||||
[dict setObject:@(rgTrackGain) forKey:@"replaygain_track_gain"];
|
[dict setObject:@(rgTrackGain) forKey:@"replaygain_track_gain"];
|
||||||
[dict setObject:@(rgTrackPeak) forKey:@"replaygain_track_peak"];
|
[dict setObject:@(rgTrackPeak) forKey:@"replaygain_track_peak"];
|
||||||
|
|
||||||
soundcheck = tag->soundcheck();
|
soundcheck = tag->soundcheck();
|
||||||
if(!soundcheck.isEmpty()) {
|
if(!soundcheck.isEmpty()) {
|
||||||
TagLib::StringList tag = soundcheck.split(" ");
|
TagLib::StringList tag = soundcheck.split(" ");
|
||||||
TagLib::StringList wantedTag;
|
TagLib::StringList wantedTag;
|
||||||
for(int i = 0, count = tag.size(); i < count; i++) {
|
for(int i = 0, count = tag.size(); i < count; i++) {
|
||||||
if(tag[i].length() == 8)
|
if(tag[i].length() == 8)
|
||||||
wantedTag.append(tag[i]);
|
wantedTag.append(tag[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(wantedTag.size() >= 10) {
|
||||||
|
float volume1 = -log10((double)((uint32_t)wantedTag[0].toInt(16)) / 1000) * 10;
|
||||||
|
float volume2 = -log10((double)((uint32_t)wantedTag[1].toInt(16)) / 1000) * 10;
|
||||||
|
float volumeToUse = MIN(volume1, volume2);
|
||||||
|
float volumeScale = pow(10, volumeToUse / 20);
|
||||||
|
[dict setObject:@(volumeScale) forKey:@"volume"];
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
|
if(!artist.isEmpty())
|
||||||
|
[dict setObject:[NSString stringWithUTF8String:artist.toCString(true)] forKey:@"artist"];
|
||||||
|
|
||||||
|
if(!albumartist.isEmpty())
|
||||||
|
[dict setObject:[NSString stringWithUTF8String:albumartist.toCString(true)] forKey:@"albumartist"];
|
||||||
|
|
||||||
|
if(!composer.isEmpty())
|
||||||
|
[dict setObject:[NSString stringWithUTF8String:composer.toCString(true)] forKey:@"composer"];
|
||||||
|
|
||||||
|
if(!album.isEmpty())
|
||||||
|
[dict setObject:[NSString stringWithUTF8String:album.toCString(true)] forKey:@"album"];
|
||||||
|
|
||||||
|
if(!title.isEmpty())
|
||||||
|
[dict setObject:[NSString stringWithUTF8String:title.toCString(true)] forKey:@"title"];
|
||||||
|
|
||||||
|
if(!genre.isEmpty())
|
||||||
|
[dict setObject:[NSString stringWithUTF8String:genre.toCString(true)] forKey:@"genre"];
|
||||||
|
|
||||||
|
if(!cuesheet.isEmpty())
|
||||||
|
[dict setObject:[NSString stringWithUTF8String:cuesheet.toCString(true)] forKey:@"cuesheet"];
|
||||||
|
|
||||||
|
if(!comment.isEmpty())
|
||||||
|
[dict setObject:[NSString stringWithUTF8String:comment.toCString(true)] forKey:@"comment"];
|
||||||
|
|
||||||
|
if(!unsyncedlyrics.isEmpty())
|
||||||
|
[dict setObject:[NSString stringWithUTF8String:unsyncedlyrics.toCString(true)] forKey:@"unsyncedlyrics"];
|
||||||
|
|
||||||
|
// Try to load the image.
|
||||||
|
NSData *image = nil;
|
||||||
|
|
||||||
|
TagLib::MPEG::File *mf = dynamic_cast<TagLib::MPEG::File *>(f.file());
|
||||||
|
if(mf) {
|
||||||
|
TagLib::ID3v2::FrameList pictures = mf->ID3v2Tag()->frameListMap()["APIC"];
|
||||||
|
if(!pictures.isEmpty()) {
|
||||||
|
TagLib::ID3v2::AttachedPictureFrame *pic = static_cast<TagLib::ID3v2::AttachedPictureFrame *>(pictures.front());
|
||||||
|
|
||||||
|
image = [NSData dataWithBytes:pic->picture().data() length:pic->picture().size()];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(wantedTag.size() >= 10) {
|
if(nil != image) {
|
||||||
float volume1 = -log10((double)((uint32_t)wantedTag[0].toInt(16)) / 1000) * 10;
|
[dict setObject:image forKey:@"albumArt"];
|
||||||
float volume2 = -log10((double)((uint32_t)wantedTag[1].toInt(16)) / 1000) * 10;
|
|
||||||
float volumeToUse = MIN(volume1, volume2);
|
|
||||||
float volumeScale = pow(10, volumeToUse / 20);
|
|
||||||
[dict setObject:@(volumeScale) forKey:@"volume"];
|
|
||||||
}
|
}
|
||||||
}*/
|
|
||||||
|
|
||||||
if(!artist.isEmpty())
|
|
||||||
[dict setObject:[NSString stringWithUTF8String:artist.toCString(true)] forKey:@"artist"];
|
|
||||||
|
|
||||||
if(!albumartist.isEmpty())
|
|
||||||
[dict setObject:[NSString stringWithUTF8String:albumartist.toCString(true)] forKey:@"albumartist"];
|
|
||||||
|
|
||||||
if(!composer.isEmpty())
|
|
||||||
[dict setObject:[NSString stringWithUTF8String:composer.toCString(true)] forKey:@"composer"];
|
|
||||||
|
|
||||||
if(!album.isEmpty())
|
|
||||||
[dict setObject:[NSString stringWithUTF8String:album.toCString(true)] forKey:@"album"];
|
|
||||||
|
|
||||||
if(!title.isEmpty())
|
|
||||||
[dict setObject:[NSString stringWithUTF8String:title.toCString(true)] forKey:@"title"];
|
|
||||||
|
|
||||||
if(!genre.isEmpty())
|
|
||||||
[dict setObject:[NSString stringWithUTF8String:genre.toCString(true)] forKey:@"genre"];
|
|
||||||
|
|
||||||
if(!cuesheet.isEmpty())
|
|
||||||
[dict setObject:[NSString stringWithUTF8String:cuesheet.toCString(true)] forKey:@"cuesheet"];
|
|
||||||
|
|
||||||
if(!comment.isEmpty())
|
|
||||||
[dict setObject:[NSString stringWithUTF8String:comment.toCString(true)] forKey:@"comment"];
|
|
||||||
|
|
||||||
if(!unsyncedlyrics.isEmpty())
|
|
||||||
[dict setObject:[NSString stringWithUTF8String:unsyncedlyrics.toCString(true)] forKey:@"unsyncedlyrics"];
|
|
||||||
|
|
||||||
// Try to load the image.
|
|
||||||
NSData *image = nil;
|
|
||||||
|
|
||||||
TagLib::MPEG::File *mf = dynamic_cast<TagLib::MPEG::File *>(f.file());
|
|
||||||
if(mf) {
|
|
||||||
TagLib::ID3v2::FrameList pictures = mf->ID3v2Tag()->frameListMap()["APIC"];
|
|
||||||
if(!pictures.isEmpty()) {
|
|
||||||
TagLib::ID3v2::AttachedPictureFrame *pic = static_cast<TagLib::ID3v2::AttachedPictureFrame *>(pictures.front());
|
|
||||||
|
|
||||||
image = [NSData dataWithBytes:pic->picture().data() length:pic->picture().size()];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(nil != image) {
|
|
||||||
[dict setObject:image forKey:@"albumArt"];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
ALog(@"Exception caught processing ID3v2 tag with TagLib: %s", e.what());
|
||||||
|
return [NSDictionary dictionary];
|
||||||
}
|
}
|
||||||
|
|
||||||
return [NSDictionary dictionaryWithDictionary:dict];
|
return [NSDictionary dictionaryWithDictionary:dict];
|
||||||
|
|
|
@ -18,6 +18,8 @@
|
||||||
#import <tag/vorbisfile.h>
|
#import <tag/vorbisfile.h>
|
||||||
#import <tag/xiphcomment.h>
|
#import <tag/xiphcomment.h>
|
||||||
|
|
||||||
|
#import "Logging.h"
|
||||||
|
|
||||||
#import "SandboxBroker.h"
|
#import "SandboxBroker.h"
|
||||||
|
|
||||||
@implementation TagLibMetadataReader
|
@implementation TagLibMetadataReader
|
||||||
|
@ -68,114 +70,120 @@
|
||||||
//
|
//
|
||||||
// }
|
// }
|
||||||
|
|
||||||
TagLib::FileRef f((const char *)[[url path] UTF8String], false);
|
try {
|
||||||
if(!f.isNull()) {
|
TagLib::FileRef f((const char *)[[url path] UTF8String], false);
|
||||||
const TagLib::Tag *tag = f.tag();
|
if(!f.isNull()) {
|
||||||
|
const TagLib::Tag *tag = f.tag();
|
||||||
|
|
||||||
if(tag) {
|
|
||||||
TagLib::String artist, albumartist, composer, title, album, genre, comment, unsyncedlyrics;
|
|
||||||
int year, track, disc;
|
|
||||||
float rgAlbumGain, rgAlbumPeak, rgTrackGain, rgTrackPeak;
|
|
||||||
TagLib::String cuesheet;
|
|
||||||
TagLib::String soundcheck;
|
|
||||||
|
|
||||||
artist = tag->artist();
|
|
||||||
//albumartist = tag->albumartist();
|
|
||||||
//composer = tag->composer();
|
|
||||||
title = tag->title();
|
|
||||||
;
|
|
||||||
album = tag->album();
|
|
||||||
genre = tag->genre();
|
|
||||||
comment = tag->comment();
|
|
||||||
//cuesheet = tag->cuesheet();
|
|
||||||
|
|
||||||
//unsyncedlyrics = tag->unsyncedlyrics();
|
|
||||||
|
|
||||||
year = tag->year();
|
|
||||||
[dict setObject:@(year) forKey:@"year"];
|
|
||||||
|
|
||||||
track = tag->track();
|
|
||||||
[dict setObject:@(track) forKey:@"track"];
|
|
||||||
|
|
||||||
/*disc = tag->disc();
|
|
||||||
[dict setObject:@(disc) forKey:@"disc"];*/
|
|
||||||
|
|
||||||
/*rgAlbumGain = tag->rgAlbumGain();
|
|
||||||
rgAlbumPeak = tag->rgAlbumPeak();
|
|
||||||
rgTrackGain = tag->rgTrackGain();
|
|
||||||
rgTrackPeak = tag->rgTrackPeak();
|
|
||||||
[dict setObject:@(rgAlbumGain) forKey:@"replaygain_album_gain"];
|
|
||||||
[dict setObject:@(rgAlbumPeak) forKey:@"replaygain_album_peak"];
|
|
||||||
[dict setObject:@(rgTrackGain) forKey:@"replaygain_track_gain"];
|
|
||||||
[dict setObject:@(rgTrackPeak) forKey:@"replaygain_track_peak"];*/
|
|
||||||
|
|
||||||
/*soundcheck = tag->soundcheck();
|
|
||||||
if(!soundcheck.isEmpty()) {
|
|
||||||
TagLib::StringList tag = soundcheck.split(" ");
|
|
||||||
TagLib::StringList wantedTag;
|
|
||||||
for(int i = 0, count = tag.size(); i < count; i++) {
|
|
||||||
if(tag[i].length() == 8)
|
|
||||||
wantedTag.append(tag[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(wantedTag.size() >= 10) {
|
|
||||||
float volume1 = -log10((double)((uint32_t)wantedTag[0].toInt(16)) / 1000) * 10;
|
|
||||||
float volume2 = -log10((double)((uint32_t)wantedTag[1].toInt(16)) / 1000) * 10;
|
|
||||||
float volumeToUse = MIN(volume1, volume2);
|
|
||||||
float volumeScale = pow(10, volumeToUse / 20);
|
|
||||||
[dict setObject:@(volumeScale) forKey:@"volume"];
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
if(!artist.isEmpty())
|
|
||||||
[dict setObject:[NSString stringWithUTF8String:artist.toCString(true)] forKey:@"artist"];
|
|
||||||
|
|
||||||
if(!albumartist.isEmpty())
|
|
||||||
[dict setObject:[NSString stringWithUTF8String:albumartist.toCString(true)] forKey:@"albumartist"];
|
|
||||||
|
|
||||||
if(!composer.isEmpty())
|
|
||||||
[dict setObject:[NSString stringWithUTF8String:composer.toCString(true)] forKey:@"composer"];
|
|
||||||
|
|
||||||
if(!album.isEmpty())
|
|
||||||
[dict setObject:[NSString stringWithUTF8String:album.toCString(true)] forKey:@"album"];
|
|
||||||
|
|
||||||
if(!title.isEmpty())
|
|
||||||
[dict setObject:[NSString stringWithUTF8String:title.toCString(true)] forKey:@"title"];
|
|
||||||
|
|
||||||
if(!genre.isEmpty())
|
|
||||||
[dict setObject:[NSString stringWithUTF8String:genre.toCString(true)] forKey:@"genre"];
|
|
||||||
|
|
||||||
if(!cuesheet.isEmpty())
|
|
||||||
[dict setObject:[NSString stringWithUTF8String:cuesheet.toCString(true)] forKey:@"cuesheet"];
|
|
||||||
|
|
||||||
if(!comment.isEmpty())
|
|
||||||
[dict setObject:[NSString stringWithUTF8String:comment.toCString(true)] forKey:@"comment"];
|
|
||||||
|
|
||||||
if(!unsyncedlyrics.isEmpty())
|
|
||||||
[dict setObject:[NSString stringWithUTF8String:unsyncedlyrics.toCString(true)] forKey:@"unsyncedlyrics"];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Try to load the image.
|
|
||||||
NSData *image = nil;
|
|
||||||
|
|
||||||
// Try to load the image.
|
|
||||||
// WARNING: HACK
|
|
||||||
TagLib::MPEG::File *mf = dynamic_cast<TagLib::MPEG::File *>(f.file());
|
|
||||||
if(mf) {
|
|
||||||
TagLib::ID3v2::Tag *tag = mf->ID3v2Tag();
|
|
||||||
if(tag) {
|
if(tag) {
|
||||||
TagLib::ID3v2::FrameList pictures = mf->ID3v2Tag()->frameListMap()["APIC"];
|
TagLib::String artist, albumartist, composer, title, album, genre, comment, unsyncedlyrics;
|
||||||
if(!pictures.isEmpty()) {
|
int year, track, disc;
|
||||||
TagLib::ID3v2::AttachedPictureFrame *pic = static_cast<TagLib::ID3v2::AttachedPictureFrame *>(pictures.front());
|
float rgAlbumGain, rgAlbumPeak, rgTrackGain, rgTrackPeak;
|
||||||
|
TagLib::String cuesheet;
|
||||||
|
TagLib::String soundcheck;
|
||||||
|
|
||||||
image = [NSData dataWithBytes:pic->picture().data() length:pic->picture().size()];
|
artist = tag->artist();
|
||||||
|
//albumartist = tag->albumartist();
|
||||||
|
//composer = tag->composer();
|
||||||
|
title = tag->title();
|
||||||
|
;
|
||||||
|
album = tag->album();
|
||||||
|
genre = tag->genre();
|
||||||
|
comment = tag->comment();
|
||||||
|
//cuesheet = tag->cuesheet();
|
||||||
|
|
||||||
|
//unsyncedlyrics = tag->unsyncedlyrics();
|
||||||
|
|
||||||
|
year = tag->year();
|
||||||
|
[dict setObject:@(year) forKey:@"year"];
|
||||||
|
|
||||||
|
track = tag->track();
|
||||||
|
[dict setObject:@(track) forKey:@"track"];
|
||||||
|
|
||||||
|
/*disc = tag->disc();
|
||||||
|
[dict setObject:@(disc) forKey:@"disc"];*/
|
||||||
|
|
||||||
|
/*rgAlbumGain = tag->rgAlbumGain();
|
||||||
|
rgAlbumPeak = tag->rgAlbumPeak();
|
||||||
|
rgTrackGain = tag->rgTrackGain();
|
||||||
|
rgTrackPeak = tag->rgTrackPeak();
|
||||||
|
[dict setObject:@(rgAlbumGain) forKey:@"replaygain_album_gain"];
|
||||||
|
[dict setObject:@(rgAlbumPeak) forKey:@"replaygain_album_peak"];
|
||||||
|
[dict setObject:@(rgTrackGain) forKey:@"replaygain_track_gain"];
|
||||||
|
[dict setObject:@(rgTrackPeak) forKey:@"replaygain_track_peak"];*/
|
||||||
|
|
||||||
|
/*soundcheck = tag->soundcheck();
|
||||||
|
if(!soundcheck.isEmpty()) {
|
||||||
|
TagLib::StringList tag = soundcheck.split(" ");
|
||||||
|
TagLib::StringList wantedTag;
|
||||||
|
for(int i = 0, count = tag.size(); i < count; i++) {
|
||||||
|
if(tag[i].length() == 8)
|
||||||
|
wantedTag.append(tag[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(wantedTag.size() >= 10) {
|
||||||
|
float volume1 = -log10((double)((uint32_t)wantedTag[0].toInt(16)) / 1000) * 10;
|
||||||
|
float volume2 = -log10((double)((uint32_t)wantedTag[1].toInt(16)) / 1000) * 10;
|
||||||
|
float volumeToUse = MIN(volume1, volume2);
|
||||||
|
float volumeScale = pow(10, volumeToUse / 20);
|
||||||
|
[dict setObject:@(volumeScale) forKey:@"volume"];
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
|
if(!artist.isEmpty())
|
||||||
|
[dict setObject:[NSString stringWithUTF8String:artist.toCString(true)] forKey:@"artist"];
|
||||||
|
|
||||||
|
if(!albumartist.isEmpty())
|
||||||
|
[dict setObject:[NSString stringWithUTF8String:albumartist.toCString(true)] forKey:@"albumartist"];
|
||||||
|
|
||||||
|
if(!composer.isEmpty())
|
||||||
|
[dict setObject:[NSString stringWithUTF8String:composer.toCString(true)] forKey:@"composer"];
|
||||||
|
|
||||||
|
if(!album.isEmpty())
|
||||||
|
[dict setObject:[NSString stringWithUTF8String:album.toCString(true)] forKey:@"album"];
|
||||||
|
|
||||||
|
if(!title.isEmpty())
|
||||||
|
[dict setObject:[NSString stringWithUTF8String:title.toCString(true)] forKey:@"title"];
|
||||||
|
|
||||||
|
if(!genre.isEmpty())
|
||||||
|
[dict setObject:[NSString stringWithUTF8String:genre.toCString(true)] forKey:@"genre"];
|
||||||
|
|
||||||
|
if(!cuesheet.isEmpty())
|
||||||
|
[dict setObject:[NSString stringWithUTF8String:cuesheet.toCString(true)] forKey:@"cuesheet"];
|
||||||
|
|
||||||
|
if(!comment.isEmpty())
|
||||||
|
[dict setObject:[NSString stringWithUTF8String:comment.toCString(true)] forKey:@"comment"];
|
||||||
|
|
||||||
|
if(!unsyncedlyrics.isEmpty())
|
||||||
|
[dict setObject:[NSString stringWithUTF8String:unsyncedlyrics.toCString(true)] forKey:@"unsyncedlyrics"];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try to load the image.
|
||||||
|
NSData *image = nil;
|
||||||
|
|
||||||
|
// Try to load the image.
|
||||||
|
// WARNING: HACK
|
||||||
|
TagLib::MPEG::File *mf = dynamic_cast<TagLib::MPEG::File *>(f.file());
|
||||||
|
if(mf) {
|
||||||
|
TagLib::ID3v2::Tag *tag = mf->ID3v2Tag();
|
||||||
|
if(tag) {
|
||||||
|
TagLib::ID3v2::FrameList pictures = mf->ID3v2Tag()->frameListMap()["APIC"];
|
||||||
|
if(!pictures.isEmpty()) {
|
||||||
|
TagLib::ID3v2::AttachedPictureFrame *pic = static_cast<TagLib::ID3v2::AttachedPictureFrame *>(pictures.front());
|
||||||
|
|
||||||
|
image = [NSData dataWithBytes:pic->picture().data() length:pic->picture().size()];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if(nil != image) {
|
if(nil != image) {
|
||||||
[dict setObject:image forKey:@"albumArt"];
|
[dict setObject:image forKey:@"albumArt"];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
ALog(@"Exception caught reading file with TagLib: %s", e.what());
|
||||||
|
[sandboxBroker endFolderAccess:sbHandle];
|
||||||
|
return [NSDictionary dictionary];
|
||||||
}
|
}
|
||||||
|
|
||||||
[sandboxBroker endFolderAccess:sbHandle];
|
[sandboxBroker endFolderAccess:sbHandle];
|
||||||
|
|
|
@ -19,55 +19,60 @@
|
||||||
NSString *lArtist = @"", *lTitle = @"", *lAlbum = @"", *lGenre = @"";
|
NSString *lArtist = @"", *lTitle = @"", *lAlbum = @"", *lGenre = @"";
|
||||||
// int lYear = 0, lTrack = 0;
|
// int lYear = 0, lTrack = 0;
|
||||||
|
|
||||||
TagLib::FileRef f((const char *)[[url path] UTF8String], false);
|
try {
|
||||||
if(!f.isNull()) {
|
TagLib::FileRef f((const char *)[[url path] UTF8String], false);
|
||||||
const TagLib::Tag *tag = f.tag();
|
if(!f.isNull()) {
|
||||||
|
const TagLib::Tag *tag = f.tag();
|
||||||
|
|
||||||
if(tag) {
|
if(tag) {
|
||||||
const TagLib::String pArtist, pTitle, pAlbum, pGenre, pComment;
|
const TagLib::String pArtist, pTitle, pAlbum, pGenre, pComment;
|
||||||
|
|
||||||
lArtist = [tagData valueForKey:@"artist"];
|
lArtist = [tagData valueForKey:@"artist"];
|
||||||
lTitle = [tagData valueForKey:@"title"];
|
lTitle = [tagData valueForKey:@"title"];
|
||||||
lAlbum = [tagData valueForKey:@"album"];
|
lAlbum = [tagData valueForKey:@"album"];
|
||||||
lGenre = [tagData valueForKey:@"genre"];
|
lGenre = [tagData valueForKey:@"genre"];
|
||||||
|
|
||||||
f.tag()->setTitle([lTitle UTF8String]);
|
f.tag()->setTitle([lTitle UTF8String]);
|
||||||
f.tag()->setArtist([lArtist UTF8String]);
|
f.tag()->setArtist([lArtist UTF8String]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
NSArray *keys = @[@"key1", @"key2", @"key3"];
|
||||||
|
NSArray *objects = @[@"value1", @"value2", @"value3"];
|
||||||
|
NSDictionary *dictionary = [NSDictionary dictionaryWithObjects:objects forKeys:keys];
|
||||||
|
|
||||||
|
for (id key in dictionary)
|
||||||
|
{
|
||||||
|
DLog(@"key: %@, value: %@", key, [dictionary objectForKey:key]);
|
||||||
|
}
|
||||||
|
|
||||||
|
pArtist = tag->artist();
|
||||||
|
pTitle = tag->title();;
|
||||||
|
pAlbum = tag->album();
|
||||||
|
pGenre = tag->genre();
|
||||||
|
pComment = tag->comment();
|
||||||
|
|
||||||
|
lYear = tag->year();
|
||||||
|
lTrack = tag->track();
|
||||||
|
lDisc = tag->disc();
|
||||||
|
|
||||||
|
if (!pArtist.isNull())
|
||||||
|
lArtist = [NSString stringWithUTF8String:pArtist.toCString(true)];
|
||||||
|
|
||||||
|
if (!pAlbum.isNull())
|
||||||
|
lAlbum = [NSString stringWithUTF8String:pAlbum.toCString(true)];
|
||||||
|
|
||||||
|
if (!pTitle.isNull())
|
||||||
|
lTitle = [NSString stringWithUTF8String:pTitle.toCString(true)];
|
||||||
|
|
||||||
|
if (!pGenre.isNull())
|
||||||
|
lGenre = [NSString stringWithUTF8String:pGenre.toCString(true)];
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
} catch (std::exception &e) {
|
||||||
/*
|
ALog(@"Exception caught writing with TagLib: %s", e.what());
|
||||||
|
return -1;
|
||||||
NSArray *keys = @[@"key1", @"key2", @"key3"];
|
|
||||||
NSArray *objects = @[@"value1", @"value2", @"value3"];
|
|
||||||
NSDictionary *dictionary = [NSDictionary dictionaryWithObjects:objects forKeys:keys];
|
|
||||||
|
|
||||||
for (id key in dictionary)
|
|
||||||
{
|
|
||||||
DLog(@"key: %@, value: %@", key, [dictionary objectForKey:key]);
|
|
||||||
}
|
|
||||||
|
|
||||||
pArtist = tag->artist();
|
|
||||||
pTitle = tag->title();;
|
|
||||||
pAlbum = tag->album();
|
|
||||||
pGenre = tag->genre();
|
|
||||||
pComment = tag->comment();
|
|
||||||
|
|
||||||
lYear = tag->year();
|
|
||||||
lTrack = tag->track();
|
|
||||||
lDisc = tag->disc();
|
|
||||||
|
|
||||||
if (!pArtist.isNull())
|
|
||||||
lArtist = [NSString stringWithUTF8String:pArtist.toCString(true)];
|
|
||||||
|
|
||||||
if (!pAlbum.isNull())
|
|
||||||
lAlbum = [NSString stringWithUTF8String:pAlbum.toCString(true)];
|
|
||||||
|
|
||||||
if (!pTitle.isNull())
|
|
||||||
lTitle = [NSString stringWithUTF8String:pTitle.toCString(true)];
|
|
||||||
|
|
||||||
if (!pGenre.isNull())
|
|
||||||
lGenre = [NSString stringWithUTF8String:pGenre.toCString(true)];
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in a new issue