Commit 632cbd94 authored by Felix Paul Kühne's avatar Felix Paul Kühne

Audio File handling: robustify and optimize meta data retrieval by using the file parsing queue

No user-visible behavior changes except for increased stability
parent cb118503
......@@ -78,7 +78,7 @@
if (!album && createIfNeeded) {
*wasCreated = YES;
album = [[MLMediaLibrary sharedMediaLibrary] createObjectForEntity:@"Album"];
album.name = albumName;
album.name = albumName ? albumName : @"";
} else if (!album && !createIfNeeded)
return nil;
......
......@@ -102,6 +102,7 @@ NSString *kMLFileTypeAudio = @"audio";
- (NSString *)title
{
NSString *ret = @"";
if ([self isShowEpisode]) {
MLShowEpisode *episode = self.showEpisode;
NSMutableString *name = [[NSMutableString alloc] init];
......@@ -122,22 +123,26 @@ NSString *kMLFileTypeAudio = @"audio";
[name appendString:episode.name];
}
return [NSString stringWithString:name];
ret = [NSString stringWithString:name];
} else if ([self isAlbumTrack]) {
MLAlbumTrack *track = self.albumTrack;
NSMutableString *name = [[NSMutableString alloc] initWithString:track.title];
if (track && track.title.length > 0) {
NSMutableString *name = [[NSMutableString alloc] initWithString:track.title];
if (track.album.name)
[name appendFormat:@" - %@", track.album.name];
if (track.album.name.length > 0)
[name appendFormat:@" - %@", track.album.name];
if (track.artist)
[name appendFormat:@" - %@", track.artist];
if (track.artist.length > 0)
[name appendFormat:@" - %@", track.artist];
return [NSString stringWithString:name];
ret = [NSString stringWithString:name];
}
}
if (ret.length < 1) {
[self willAccessValueForKey:@"title"];
ret = [self primitiveValueForKey:@"title"];
[self didAccessValueForKey:@"title"];
}
[self willAccessValueForKey:@"title"];
NSString *ret = [self primitiveValueForKey:@"title"];
[self didAccessValueForKey:@"title"];
return ret;
}
......
......@@ -28,6 +28,9 @@
#import "MLFile.h"
#import "MLMediaLibrary.h"
#import "MLCrashPreventer.h"
#import "MLAlbumTrack.h"
#import "MLAlbum.h"
#import "MLTitleDecrapifier.h"
@interface MLParsingOperation : NSOperation
{
......@@ -65,6 +68,8 @@
APLog(@"Starting parsing %@", self.file);
[[MLCrashPreventer sharedPreventer] willParseFile:self.file];
NSLog(@"Parsing %@ of type %@", self.file, self.file.type);
_media = [[VLCMedia mediaWithURL:[NSURL URLWithString:self.file.url]] retain];
_media.delegate = self;
[_media parse];
......@@ -107,6 +112,39 @@
[self.file setTracks:tracksSet];
[self.file setDuration:[[_media length] numberValue]];
if ([self.file isAlbumTrack]) {
NSLog(@"'%@' is an audio file, adding specific meta data", self.file.title);
NSDictionary *audioContentInfo = [_media metaDictionary];
if (audioContentInfo && audioContentInfo.count > 0) {
NSString *title = audioContentInfo[VLCMetaInformationTitle];
NSString *artist = audioContentInfo[VLCMetaInformationArtist];
NSString *albumName = audioContentInfo[VLCMetaInformationAlbum];
NSString *releaseYear = audioContentInfo[VLCMetaInformationDate];
NSString *genre = audioContentInfo[VLCMetaInformationGenre];
NSString *trackNumber = audioContentInfo[VLCMetaInformationTrackNumber];
MLAlbum *album = nil;
BOOL wasCreated = NO;
MLAlbumTrack *track = [MLAlbumTrack trackWithAlbumName:albumName trackNumber:[NSNumber numberWithInteger:[trackNumber integerValue]] createIfNeeded:YES wasCreated:&wasCreated];
if (track) {
album = track.album;
track.title = title ? title : @"";
track.artist = artist ? artist : @"";
track.genre = genre ? genre : @"";
album.releaseYear = releaseYear ? releaseYear : @"";
if (!track.title || [track.title isEqualToString:@""])
track.title = [MLTitleDecrapifier decrapify:self.file.title];
[track addFilesObject:self.file];
self.file.albumTrack = track;
}
}
}
MLFileParserQueue *parserQueue = [MLFileParserQueue sharedFileParserQueue];
[[MLCrashPreventer sharedPreventer] didParseFile:self.file];
[parserQueue.queue setSuspended:NO];
......@@ -160,6 +198,7 @@ static inline NSString *hashFromFile(MLFile *file)
- (void)addFile:(MLFile *)file
{
NSLog(@"addFile:%@", file.title);
if (_fileDescriptionToOperation[hashFromFile(file)])
return;
if (![[MLCrashPreventer sharedPreventer] isFileSafe:file]) {
......
......@@ -450,39 +450,17 @@ static NSString *kLastTVDBUpdateServerTime = @"MLLastTVDBUpdateServerTime";
{
file.type = kMLFileTypeAudio;
NSString *title = audioContentInfo[VLCMetaInformationTitle];
NSString *artist = audioContentInfo[VLCMetaInformationArtist];
NSString *albumName = audioContentInfo[VLCMetaInformationAlbum];
NSString *releaseYear = audioContentInfo[VLCMetaInformationDate];
NSString *genre = audioContentInfo[VLCMetaInformationGenre];
NSString *trackNumber = audioContentInfo[VLCMetaInformationTrackNumber];
MLAlbum *album = nil;
BOOL wasCreated = NO;
MLAlbumTrack *track = [MLAlbumTrack trackWithAlbumName:albumName trackNumber:[NSNumber numberWithInteger:[trackNumber integerValue]] createIfNeeded:YES wasCreated:&wasCreated];
if (track)
album = track.album;
track.title = title;
track.artist = artist;
track.genre = genre;
album.releaseYear = releaseYear;
if (!track.title || [track.title isEqualToString:@""])
track.title = file.title;
[track addFilesObject:file];
file.albumTrack = track;
file.title = audioContentInfo[VLCMetaInformationTitle];
/* all further meta data is set by the FileParserQueue */
file.hasFetchedInfo = @YES;
}
/**
* MLFile auto detection
*/
#if !HAVE_BLOCK
- (void)movieInfoGrabber:(MLMovieInfoGrabber *)grabber didFailWithError:(NSError *)error
{
......@@ -730,7 +708,7 @@ static NSString *kLastTVDBUpdateServerTime = @"MLLastTVDBUpdateServerTime";
[request setPredicate:[NSPredicate predicateWithFormat:@"isOnDisk == YES && hasFetchedInfo == 1 && artworkURL == nil"]];
results = [[self managedObjectContext] executeFetchRequest:request error:nil];
for (MLFile *file in results)
if (!file.computedThumbnail)
if (!file.computedThumbnail && ![file isAlbumTrack])
[self computeThumbnailForFile:file];
// Get to fetch meta data
......
......@@ -162,6 +162,10 @@ static inline NSString *hashFromFile(MLFile *file)
APLog(@"'%@' is unsafe and will crash, ignoring", file.title);
return;
}
if ([file isAlbumTrack]) {
APLog(@"'%@' is an audio file, ignoring", file.title);
return;
}
ThumbnailOperation *op = [[ThumbnailOperation alloc] initWithFile:file];
[_fileDescriptionToOperation setValue:op forKey:hashFromFile(file)];
[self.queue addOperation:op];
......
......@@ -126,28 +126,15 @@ static inline NSNumber *numberFromTwoChars(char high, char low)
if (!file)
return nil;
VLCMedia *media = [VLCMedia mediaWithURL:[NSURL URLWithString:file.url]];
if (![media isParsed])
[media synchronousParse];
NSDictionary *rawMetaDict = [media metaDictionary];
if (!rawMetaDict)
return nil;
NSMutableDictionary *metaDictionary = [NSMutableDictionary dictionaryWithDictionary:rawMetaDict];
if ([metaDictionary objectForKey:VLCMetaInformationTitle] == nil) {
NSString *title = file.title;
NSArray *components = [title componentsSeparatedByString:@" "];
if (components.count > 0) {
if ([components[0] intValue] > 0)
title = [self decrapify:[title stringByReplacingOccurrencesOfString:components[0] withString:@""]];
} else
title = [self decrapify:title];
[metaDictionary setObject:title forKey:VLCMetaInformationTitle];
}
return metaDictionary;
NSString *title = file.title;
NSArray *components = [title componentsSeparatedByString:@" "];
if (components.count > 0) {
if ([components[0] intValue] > 0)
title = [self decrapify:[title stringByReplacingOccurrencesOfString:components[0] withString:@""]];
} else
title = [self decrapify:title];
return [NSDictionary dictionaryWithObject:title forKey:VLCMetaInformationTitle];
}
@end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment