Fix a crash when the rating index is outside the bounds of the ratings codes. This happens when a users changes the ratings settings in the preferences.
This commit is contained in:
1 parent
acbc6a3f93
commit
0fdad0eebf
2 files changed
+49
-28
No files matched your search
+32
-22
@@ -1324,51 +1324,61 @@ static const genreType_t genreType_strings[] = {
|
||||
/* Rewrite extended metadata using the generic iTMF api */
|
||||
|
||||
if ([tagsDict valueForKey:@"Rating"]) {
|
||||
MP4ItmfItemList* list = MP4ItmfGetItemsByMeaning(fileHandle, "com.apple.iTunes", "iTunEXTC");
|
||||
MP4ItmfItemList *list = MP4ItmfGetItemsByMeaning(fileHandle, "com.apple.iTunes", "iTunEXTC");
|
||||
if (list) {
|
||||
uint32_t i;
|
||||
for (i = 0; i < list->size; i++) {
|
||||
MP4ItmfItem* item = &list->elements[i];
|
||||
for (uint32_t i = 0; i < list->size; i++) {
|
||||
MP4ItmfItem *item = &list->elements[i];
|
||||
MP4ItmfRemoveItem(fileHandle, item);
|
||||
}
|
||||
}
|
||||
MP4ItmfItemListFree(list);
|
||||
|
||||
MP4ItmfItem* newItem = MP4ItmfItemAlloc( "----", 1 );
|
||||
newItem->mean = strdup( "com.apple.iTunes" );
|
||||
newItem->name = strdup( "iTunEXTC" );
|
||||
MP4ItmfItem *newItem = MP4ItmfItemAlloc("----", 1);
|
||||
newItem->mean = strdup("com.apple.iTunes");
|
||||
newItem->name = strdup("iTunEXTC");
|
||||
|
||||
MP4ItmfData* data = &newItem->dataList.elements[0];
|
||||
MP4ItmfData *data = &newItem->dataList.elements[0];
|
||||
|
||||
NSString *ratingString = ratingiTunesCode;
|
||||
NSArray *iTunesCodes = [[MP42Ratings defaultManager] iTunesCodes];
|
||||
|
||||
// This whole thing is extremely convoluted and wrong in some cases.
|
||||
if (![[tagsDict valueForKey:@"Rating"] isKindOfClass:[NSNumber class]] ||
|
||||
[[tagsDict valueForKey:@"Rating"] unsignedIntegerValue] == [[MP42Ratings defaultManager] unknownIndex]) {
|
||||
if (!ratingiTunesCode) {
|
||||
ratingiTunesCode = [[[[MP42Ratings defaultManager] iTunesCodes] objectAtIndex:[[MP42Ratings defaultManager] unknownIndex]] retain];
|
||||
if (!ratingString) {
|
||||
ratingString = [iTunesCodes objectAtIndex:[[MP42Ratings defaultManager] unknownIndex]];
|
||||
}
|
||||
} else {
|
||||
ratingiTunesCode = [[[[MP42Ratings defaultManager] iTunesCodes] objectAtIndex:[[tagsDict valueForKey:@"Rating"] unsignedIntegerValue]] retain];
|
||||
NSUInteger index = [[tagsDict valueForKey:@"Rating"] unsignedIntegerValue];
|
||||
if (iTunesCodes.count > index) {
|
||||
ratingString = [iTunesCodes objectAtIndex:[[tagsDict valueForKey:@"Rating"] unsignedIntegerValue]];
|
||||
}
|
||||
}
|
||||
NSString *ratingString = ratingiTunesCode;
|
||||
|
||||
if ([[tagsDict valueForKey:@"Rating Annotation"] length] && [ratingString length]) {
|
||||
ratingString = [NSString stringWithFormat:@"%@%@", ratingString, [tagsDict valueForKey:@"Rating Annotation"]];
|
||||
}
|
||||
data->typeCode = MP4_ITMF_BT_UTF8;
|
||||
data->valueSize = strlen([ratingString UTF8String]);
|
||||
data->value = (uint8_t*)malloc( data->valueSize );
|
||||
memcpy( data->value, [ratingString UTF8String], data->valueSize );
|
||||
|
||||
MP4ItmfAddItem(fileHandle, newItem);
|
||||
if (ratingString) {
|
||||
data->typeCode = MP4_ITMF_BT_UTF8;
|
||||
data->valueSize = strlen([ratingString UTF8String]);
|
||||
data->value = (uint8_t*)malloc( data->valueSize );
|
||||
memcpy( data->value, [ratingString UTF8String], data->valueSize );
|
||||
|
||||
MP4ItmfAddItem(fileHandle, newItem);
|
||||
}
|
||||
|
||||
MP4ItmfItemFree(newItem);
|
||||
}
|
||||
else {
|
||||
|
||||
} else {
|
||||
MP4ItmfItemList* list = MP4ItmfGetItemsByMeaning(fileHandle, "com.apple.iTunes", "iTunEXTC");
|
||||
if (list) {
|
||||
uint32_t i;
|
||||
for (i = 0; i < list->size; i++) {
|
||||
MP4ItmfItem* item = &list->elements[i];
|
||||
for (uint32_t i = 0; i < list->size; i++) {
|
||||
MP4ItmfItem *item = &list->elements[i];
|
||||
MP4ItmfRemoveItem(fileHandle, item);
|
||||
}
|
||||
}
|
||||
|
||||
MP4ItmfItemListFree(list);
|
||||
}
|
||||
|
||||
|
||||
+17
-6
@@ -22,9 +22,9 @@
|
||||
return sharedRatingsManager;
|
||||
}
|
||||
|
||||
- (id) init {
|
||||
- (instancetype) init {
|
||||
if (self = [super init]) {
|
||||
NSString* ratingsJSON = [[NSBundle bundleForClass:[MP42Ratings class]] pathForResource:@"Ratings" ofType:@"json"];
|
||||
NSString *ratingsJSON = [[NSBundle bundleForClass:[MP42Ratings class]] pathForResource:@"Ratings" ofType:@"json"];
|
||||
if (!ratingsJSON) {
|
||||
[self release];
|
||||
return nil;
|
||||
@@ -32,28 +32,36 @@
|
||||
|
||||
JSONDecoder *jsonDecoder = [JSONDecoder decoder];
|
||||
ratingsDictionary = [[jsonDecoder objectWithData:[NSData dataWithContentsOfFile:ratingsJSON]] retain];
|
||||
|
||||
// construct movie ratings
|
||||
ratings = [[NSMutableArray alloc] init];
|
||||
iTunesCodes = [[NSMutableArray alloc] init];
|
||||
|
||||
// if a specific country is picked, include the USA ratings at the end
|
||||
NSString *selectedCountry = [[NSUserDefaults standardUserDefaults] valueForKey:@"SBRatingsCountry"];
|
||||
NSDictionary *usaRatings = nil;
|
||||
|
||||
for (NSDictionary *countryRatings in ratingsDictionary) {
|
||||
NSString *countryName = [countryRatings valueForKey:@"country"];
|
||||
|
||||
if ([countryName isEqualToString:@"USA"]) {
|
||||
usaRatings = countryRatings;
|
||||
}
|
||||
if (![[[NSUserDefaults standardUserDefaults] valueForKey:@"SBRatingsCountry"] isEqualToString:@"All countries"]) {
|
||||
if (![countryName isEqualToString:@"Unknown"] && ![countryName isEqualToString:[[NSUserDefaults standardUserDefaults] valueForKey:@"SBRatingsCountry"]]) {
|
||||
|
||||
if (![selectedCountry isEqualToString:@"All countries"]) {
|
||||
if (![countryName isEqualToString:@"Unknown"] && ![countryName isEqualToString:selectedCountry]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for (NSDictionary *rating in [countryRatings valueForKey:@"ratings"]) {
|
||||
[ratings addObject:[NSString stringWithFormat:@"%@ %@: %@", countryName, [rating valueForKey:@"media"], [rating valueForKey:@"description"]]];
|
||||
[iTunesCodes addObject:[NSString stringWithFormat:@"%@|%@|%@|", [rating valueForKey:@"prefix"], [rating valueForKey:@"itunes-code"], [rating valueForKey:@"itunes-value"]]];
|
||||
}
|
||||
}
|
||||
if (![[[NSUserDefaults standardUserDefaults] valueForKey:@"SBRatingsCountry"] isEqualToString:@"All countries"] && ![[[NSUserDefaults standardUserDefaults] valueForKey:@"SBRatingsCountry"] isEqualToString:@"USA"]) {
|
||||
|
||||
if (![selectedCountry isEqualToString:@"All countries"] && ![selectedCountry isEqualToString:@"USA"]) {
|
||||
if (usaRatings) {
|
||||
for (NSDictionary *rating in [usaRatings valueForKey:@"ratings"]) {
|
||||
[ratings addObject:[NSString stringWithFormat:@"%@ %@: %@", @"USA", [rating valueForKey:@"media"], [rating valueForKey:@"description"]]];
|
||||
@@ -113,9 +121,11 @@
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
if (aRatingString != nil) {
|
||||
NSLog(@"Unknown rating information: %@", target1);
|
||||
}
|
||||
}
|
||||
|
||||
for (NSDictionary *countryRatings in ratingsDictionary) {
|
||||
if ([[countryRatings valueForKey:@"country"] isEqualToString:aCountry]) {
|
||||
for (NSDictionary *rating in [countryRatings valueForKey:@"ratings"]) {
|
||||
@@ -125,6 +135,7 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [self unknownIndex];
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user