Commit 73dea49a authored by Felix Paul Kühne's avatar Felix Paul Kühne

set the type of files correctly and optimize the logic deciding to do a thumbnail or not

parent 185874de
......@@ -127,6 +127,12 @@
}
[file setTracks:tracksSet];
if (mediaHasVideo) {
if ([[_media length] intValue] > 600000) // 10min
file.type = kMLFileTypeMovie;
else
file.type = kMLFileTypeClip;
}
[file setDuration:[[_media length] numberValue]];
if ([file isAlbumTrack]) {
......@@ -161,19 +167,30 @@
}
if (!mediaHasVideo) {
file.type = kMLFileTypeAudio;
APLog(@"'%@' is an audio file, fetching artwork", file.title);
NSString *artist, *albumName, *title;
BOOL skipOperation = NO;
if (file.isAlbumTrack) {
artist = file.albumTrack.artist;
albumName = file.albumTrack.album.name;
if (!file.albumTrack.containsArtwork)
skipOperation = YES;
}
title = file.title;
file.computedThumbnail = [self scaleImage:[UIImage imageWithContentsOfFile:[self artworkPathForMediaItemWithTitle:title Artist:artist andAlbumName:albumName]]
toFitRect:(CGRect){CGPointZero, [[MLThumbnailerQueue sharedThumbnailerQueue] preferredThumbnailSizeForDevice]}];
if (file.computedThumbnail == nil)
file.albumTrack.containsArtwork = NO;
if (!skipOperation) {
title = file.title;
NSString *artworkPath = [self artworkPathForMediaItemWithTitle:title Artist:artist andAlbumName:albumName];
if ([[NSFileManager defaultManager] fileExistsAtPath:artworkPath]) {
file.computedThumbnail = [self scaleImage:[UIImage imageWithContentsOfFile:artworkPath]
toFitRect:(CGRect){CGPointZero, [[MLThumbnailerQueue sharedThumbnailerQueue] preferredThumbnailSizeForDevice]}];
}
if (file.computedThumbnail == nil)
file.albumTrack.containsArtwork = NO;
}
}
MLFileParserQueue *parserQueue = [MLFileParserQueue sharedFileParserQueue];
......
......@@ -364,11 +364,12 @@ static NSString *kDecrapifyTitles = @"MLDecrapifyTitles";
- (void)computeThumbnailForFile:(MLFile *)file
{
if (!file.computedThumbnail) {
if (!file.computedThumbnail && ![file isKindOfType:kMLFileTypeAudio]) {
APLog(@"Computing thumbnail for %@", file.title);
[[MLThumbnailerQueue sharedThumbnailerQueue] addFile:file];
}
}
- (void)errorWhenFetchingMetaDataForFile:(MLFile *)file
{
APLog(@"Error when fetching for '%@'", file.title);
......@@ -654,11 +655,12 @@ static NSString *kDecrapifyTitles = @"MLDecrapifyTitles";
NSDictionary *tvShowEpisodeInfo = [MLTitleDecrapifier tvShowEpisodeInfoFromString:file.title];
if (tvShowEpisodeInfo) {
file.type = kMLFileTypeTVShowEpisode;
[self addTVShowEpisodeWithInfo:tvShowEpisodeInfo andFile:file];
return;
}
if ([file isSupportedAudioFile]) {
if ([file isKindOfType:kMLFileTypeAudio]) {
NSDictionary *audioContentInfo = [MLTitleDecrapifier audioContentInfoFromFile:file];
if (audioContentInfo && ![file videoTrack]) {
[self addAudioContentWithInfo:audioContentInfo andFile:file];
......@@ -896,7 +898,7 @@ static NSString *kDecrapifyTitles = @"MLDecrapifyTitles";
[request setPredicate:[NSPredicate predicateWithFormat:@"isOnDisk == YES && hasFetchedInfo == 1 && artworkURL == nil"]];
results = [moc executeFetchRequest:request error:nil];
for (MLFile *file in results)
if (!file.computedThumbnail && ![file isAlbumTrack])
if (!file.computedThumbnail)
[self computeThumbnailForFile:file];
// Get to fetch meta data
......
......@@ -183,7 +183,9 @@ static inline NSString *hashFromFile(MLFile *file)
APLog(@"'%@' is unsafe and will crash, ignoring", file.title);
return;
}
if ([file isAlbumTrack]) {
file.type = kMLFileTypeAudio;
APLog(@"'%@' is an audio file, ignoring", file.title);
return;
}
......
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