Commit cb118503 authored by Felix Paul Kühne's avatar Felix Paul Kühne

extended data model, processing and decrapification logic to support music albums

parent 2b37bfa3
......@@ -23,12 +23,14 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#import "MLFile.h"
@interface MLTitleDecrapifier : NSObject
{
}
+ (NSString *)decrapify:(NSString *)string;
+ (BOOL)isTVShowEpisodeTitle:(NSString *)string;
+ (NSDictionary *)tvShowEpisodeInfoFromString:(NSString *)string;
+ (NSDictionary *)audioContentInfoFromFile:(MLFile *)file;
@end
/*****************************************************************************
* MLAlbum.h
*****************************************************************************
* Copyright (C) 2010 Pierre d'Herbemont
* Copyright (C) 2013 Felix Paul Kühne
* $Id$
*
* Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
* Felix Paul Kühne <fkuehne # videolan.org>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
@interface MLAlbum : NSManagedObject
+ (NSArray *)allAlbums;
+ (MLAlbum *)albumWithName:(NSString *)name;
@property (nonatomic, retain) NSString *name;
@property (nonatomic, retain) NSString *releaseYear;
@property (nonatomic, retain) NSSet *tracks;
@property (nonatomic, retain, readonly) NSSet *unreadTracks;
@end
@interface MLAlbum (CoreDataGeneratedAccessors)
- (void)addTracksObject:(NSManagedObject *)value;
- (void)removeTracksObject:(NSManagedObject *)value;
- (void)addTracks:(NSSet *)value;
- (void)removeTracks:(NSSet *)value;
@end
/*****************************************************************************
* MLAlbumTrack.h
*****************************************************************************
* Copyright (C) 2010 Pierre d'Herbemont
* Copyright (C) 2013 Felix Paul Kühne
* $Id$
*
* Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
* Felix Paul Kühne <fkuehne # videolan.org>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#import "MLAlbum.h"
@interface MLAlbumTrack : NSManagedObject
+ (NSArray *)allTracks;
+ (MLAlbumTrack *)trackWithAlbum:(id)album trackNumber:(NSNumber *)trackNumber createIfNeeded:(BOOL)createIfNeeded;
+ (MLAlbumTrack *)trackWithAlbumName:(NSString *)albumName trackNumber:(NSNumber *)trackNumber createIfNeeded:(BOOL)createIfNeeded wasCreated:(BOOL *)wasCreated;
@property (nonatomic, retain) NSNumber *unread;
@property (nonatomic, retain) NSString *artist;
@property (nonatomic, retain) NSString *genre;
@property (nonatomic, retain) NSString *title;
@property (nonatomic, retain) NSNumber *trackNumber;
@property (nonatomic, retain) MLAlbum *album;
@property (nonatomic, retain) NSSet *files;
@end
@interface MLAlbumTrack (CoreDataGeneratedAccessors)
- (void)addFilesObject:(NSManagedObject *)value;
- (void)removeFilesObject:(NSManagedObject *)value;
- (void)addFiles:(NSSet *)value;
- (void)removeFiles:(NSSet *)value;
@end
......@@ -27,14 +27,14 @@
#import <CoreData/CoreData.h>
@class MLShowEpisode;
@class MLAlbumTrack;
extern NSString *kMLFileTypeMovie;
extern NSString *kMLFileTypeClip;
extern NSString *kMLFileTypeTVShowEpisode;
extern NSString *kMLFileTypeAudio;
@interface MLFile : NSManagedObject
{
}
+ (NSArray *)allFiles;
......@@ -42,6 +42,8 @@ extern NSString *kMLFileTypeTVShowEpisode;
- (BOOL)isMovie;
- (BOOL)isClip;
- (BOOL)isShowEpisode;
- (BOOL)isAlbumTrack;
- (BOOL)isSupportedAudioFile;
@property (nonatomic, retain) NSNumber *seasonNumber;
@property (nonatomic, retain) NSNumber *remainingTime;
......@@ -65,6 +67,11 @@ extern NSString *kMLFileTypeTVShowEpisode;
@property (nonatomic, retain) NSSet *tracks;
@property (nonatomic, retain) NSNumber *isOnDisk;
@property (nonatomic, retain) NSNumber *duration;
@property (nonatomic, retain) NSString *artist;
@property (nonatomic, retain) NSString *album;
@property (nonatomic, retain) NSNumber *albumTrackNumber;
@property (nonatomic, retain) NSString *genre;
@property (nonatomic, retain) MLAlbumTrack *albumTrack;
@property (nonatomic, retain) UIImage *computedThumbnail;
@property (nonatomic, assign) BOOL isSafe;
......
......@@ -28,8 +28,6 @@
@class MLShow;
@interface MLShowEpisode : NSManagedObject
{
}
+ (NSArray *)allEpisodes;
......
......@@ -20,14 +20,18 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#import <MediaLibraryKit/MLShowEpisode.h>
#import <MediaLibraryKit/MLFile.h>
#import <MediaLibraryKit/MLLabel.h>
#import <MediaLibraryKit/MLMediaLibrary.h>
#import <MediaLibraryKit/MLShow.h>
#import <MediaLibraryKit/MLShowEpisode.h>
#import <MediaLibraryKit/MLAlbum.h>
#import <MediaLibraryKit/MLAlbumTrack.h>
@class MLShowEpisode;
@class MLFile;
@class MLLabel;
@class MLMediaLibrary;
@class MLShow;
@class MLShowEpisode;
@class MLAlbum;
@class MLAlbumTrack;
......@@ -36,6 +36,10 @@
7D0EF55D170885300003ED47 /* MediaLibrary.xcdatamodel in Sources */ = {isa = PBXBuildFile; fileRef = 7D0EF55C170885300003ED47 /* MediaLibrary.xcdatamodel */; };
7D8ECFE21708FEAE00A989E9 /* CXHTMLDocument.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D8ECFE11708FEAE00A989E9 /* CXHTMLDocument.m */; };
7D8ECFE51708FEC000A989E9 /* CXMLNamespaceNode.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D8ECFE41708FEC000A989E9 /* CXMLNamespaceNode.m */; };
7D9E238617AEEA13008485E5 /* MLAlbumTrack.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D9E238517AEEA13008485E5 /* MLAlbumTrack.m */; };
7D9E238817AEEA71008485E5 /* MLAlbum.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D9E238717AEEA71008485E5 /* MLAlbum.m */; };
7D9E238917AF0711008485E5 /* MLAlbum.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 7D9E238117AEE9F2008485E5 /* MLAlbum.h */; };
7D9E238A17AF0711008485E5 /* MLAlbumTrack.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 7D9E238417AEEA13008485E5 /* MLAlbumTrack.h */; };
A7924688170F09A30036AAF2 /* MediaLibraryKit.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 7D0EF510170885130003ED47 /* MediaLibraryKit.h */; };
A7924689170F09A30036AAF2 /* MLFile.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 7D0EF511170885130003ED47 /* MLFile.h */; };
A792468A170F09A30036AAF2 /* MLLabel.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 7D0EF512170885130003ED47 /* MLLabel.h */; };
......@@ -52,6 +56,8 @@
dstPath = "include/${PRODUCT_NAME}";
dstSubfolderSpec = 16;
files = (
7D9E238917AF0711008485E5 /* MLAlbum.h in CopyFiles */,
7D9E238A17AF0711008485E5 /* MLAlbumTrack.h in CopyFiles */,
A7924688170F09A30036AAF2 /* MediaLibraryKit.h in CopyFiles */,
A7924689170F09A30036AAF2 /* MLFile.h in CopyFiles */,
A792468A170F09A30036AAF2 /* MLLabel.h in CopyFiles */,
......@@ -126,6 +132,10 @@
7D8ECFE11708FEAE00A989E9 /* CXHTMLDocument.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CXHTMLDocument.m; sourceTree = "<group>"; };
7D8ECFE31708FEC000A989E9 /* CXMLNamespaceNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CXMLNamespaceNode.h; sourceTree = "<group>"; };
7D8ECFE41708FEC000A989E9 /* CXMLNamespaceNode.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CXMLNamespaceNode.m; sourceTree = "<group>"; };
7D9E238117AEE9F2008485E5 /* MLAlbum.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MLAlbum.h; sourceTree = "<group>"; };
7D9E238417AEEA13008485E5 /* MLAlbumTrack.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MLAlbumTrack.h; sourceTree = "<group>"; };
7D9E238517AEEA13008485E5 /* MLAlbumTrack.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MLAlbumTrack.m; sourceTree = "<group>"; };
7D9E238717AEEA71008485E5 /* MLAlbum.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MLAlbum.m; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
......@@ -210,6 +220,8 @@
7D0EF513170885130003ED47 /* MLMediaLibrary.h */,
7D0EF514170885130003ED47 /* MLShow.h */,
7D0EF515170885130003ED47 /* MLShowEpisode.h */,
7D9E238117AEE9F2008485E5 /* MLAlbum.h */,
7D9E238417AEEA13008485E5 /* MLAlbumTrack.h */,
7D0EF521170885130003ED47 /* MLThumbnailerQueue.h */,
);
path = Public;
......@@ -228,6 +240,8 @@
7D0EF51E170885130003ED47 /* MLMovieInfoGrabber.m */,
7D0EF51F170885130003ED47 /* MLShow.m */,
7D0EF520170885130003ED47 /* MLShowEpisode.m */,
7D9E238717AEEA71008485E5 /* MLAlbum.m */,
7D9E238517AEEA13008485E5 /* MLAlbumTrack.m */,
7D0EF522170885130003ED47 /* MLThumbnailerQueue.m */,
7D0EF523170885130003ED47 /* MLTitleDecrapifier.m */,
7D0EF524170885130003ED47 /* MLTVShowEpisodesInfoGrabber.m */,
......@@ -361,6 +375,8 @@
7D0EF532170885130003ED47 /* MLTVShowEpisodesInfoGrabber.m in Sources */,
7D0EF533170885130003ED47 /* MLTVShowInfoGrabber.m in Sources */,
7D0EF534170885130003ED47 /* MLURLConnection.m in Sources */,
7D9E238617AEEA13008485E5 /* MLAlbumTrack.m in Sources */,
7D9E238817AEEA71008485E5 /* MLAlbum.m in Sources */,
7D0EF535170885130003ED47 /* NSXMLNode_Additions.m in Sources */,
7D0EF551170885230003ED47 /* CXMLDocument_CreationExtensions.m in Sources */,
7D0EF552170885230003ED47 /* CXMLNode_CreationExtensions.m in Sources */,
......@@ -373,9 +389,9 @@
7D0EF559170885230003ED47 /* CXMLNode_PrivateExtensions.m in Sources */,
7D0EF55A170885230003ED47 /* CXMLNode_XPathExtensions.m in Sources */,
7D0EF55B170885230003ED47 /* CTidy.m in Sources */,
7D0EF55D170885300003ED47 /* MediaLibrary.xcdatamodel in Sources */,
7D8ECFE21708FEAE00A989E9 /* CXHTMLDocument.m in Sources */,
7D8ECFE51708FEC000A989E9 /* CXMLNamespaceNode.m in Sources */,
7D0EF55D170885300003ED47 /* MediaLibrary.xcdatamodel in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......
......@@ -27,6 +27,8 @@
#import <Foundation/Foundation.h>
#endif
#import <CoreData/CoreData.h>
#if TARGET_OS_IPHONE
// FIXME
#define HAVE_BLOCK 0
......
2.2
---
Features:
- added support for audio files and album organization
- improved episode title decrapification
- overall stability improvements
Added APIs:
Added Public APIs:
- MLAlbum:
- New class
- MLAlbumTrack:
- New class
- MLFile:
- new properties: lastAudioTrack, lastSubtitleTrack
......
/*****************************************************************************
* MLAlbum.m
*****************************************************************************
* Copyright (C) 2010 Pierre d'Herbemont
* Copyright (C) 2013 Felix Paul Kühne
* $Id$
*
* Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
* Felix Paul Kühne <fkuehne # videolan.org>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#import "MLAlbum.h"
#import "MLMediaLibrary.h"
@implementation MLAlbum
+ (NSArray *)allAlbums
{
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSManagedObjectContext *moc = [[MLMediaLibrary sharedMediaLibrary] managedObjectContext];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Album" inManagedObjectContext:moc];
[request setEntity:entity];
NSSortDescriptor *descriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:NO];
[request setSortDescriptors:@[descriptor]];
NSArray *albums = [moc executeFetchRequest:request error:nil];
[request release];
[descriptor release];
return albums;
}
+ (MLAlbum *)albumWithName:(NSString *)name
{
NSFetchRequest *request = [[MLMediaLibrary sharedMediaLibrary] fetchRequestForEntity:@"Album"];
[request setPredicate:[NSPredicate predicateWithFormat:@"name == %@", name]];
NSArray *dbResults = [[[MLMediaLibrary sharedMediaLibrary] managedObjectContext] executeFetchRequest:request error:nil];
NSAssert(dbResults, @"Can't execute fetch request");
if ([dbResults count] <= 0)
return nil;
return dbResults[0];
}
@dynamic name;
@dynamic releaseYear;
@dynamic tracks;
@dynamic unreadTracks;
@end
/*****************************************************************************
* MLAlbumTrack.m
*****************************************************************************
* Copyright (C) 2010 Pierre d'Herbemont
* Copyright (C) 2013 Felix Paul Kühne
* $Id$
*
* Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
* Felix Paul Kühne <fkuehne # videolan.org>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#import "MLMediaLibrary.h"
#import "MLAlbumTrack.h"
#import "MLAlbum.h"
@interface MLAlbumTrack ()
@property (nonatomic, retain) NSNumber *primitiveUnread;
@end
@implementation MLAlbumTrack
+ (NSArray *)allTracks
{
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSManagedObjectContext *moc = [[MLMediaLibrary sharedMediaLibrary] managedObjectContext];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"AlbumTrack" inManagedObjectContext:moc];
[request setEntity:entity];
NSSortDescriptor *descriptor = [[NSSortDescriptor alloc] initWithKey:@"title" ascending:NO];
[request setSortDescriptors:@[descriptor]];
[request setPredicate:[NSPredicate predicateWithFormat:@"files.@count > 0"]];
NSArray *tracks = [moc executeFetchRequest:request error:nil];
[request release];
[descriptor release];
return tracks;
}
+ (MLAlbumTrack *)trackWithAlbum:(id)album trackNumber:(NSNumber *)trackNumber createIfNeeded:(BOOL)createIfNeeded
{
NSMutableSet *tracks = [album mutableSetValueForKey:@"tracks"];
MLAlbumTrack *track = nil;
if (trackNumber) {
for (MLAlbumTrack *trackIter in tracks) {
if ([trackIter.trackNumber intValue] == [trackNumber intValue]) {
track = trackIter;
break;
}
}
}
if (!track && createIfNeeded) {
track = [[MLMediaLibrary sharedMediaLibrary] createObjectForEntity:@"AlbumTrack"];
track.trackNumber = trackNumber;
[tracks addObject:track];
}
return track;
}
+ (MLAlbumTrack *)trackWithAlbumName:(NSString *)albumName trackNumber:(NSNumber *)trackNumber createIfNeeded:(BOOL)createIfNeeded wasCreated:(BOOL *)wasCreated
{
MLAlbum *album = [MLAlbum albumWithName:albumName];
*wasCreated = NO;
if (!album && createIfNeeded) {
*wasCreated = YES;
album = [[MLMediaLibrary sharedMediaLibrary] createObjectForEntity:@"Album"];
album.name = albumName;
} else if (!album && !createIfNeeded)
return nil;
return [MLAlbumTrack trackWithAlbum:album trackNumber:trackNumber createIfNeeded:createIfNeeded];
}
@dynamic primitiveUnread;
@dynamic unread;
- (void)setUnread:(NSNumber *)unread
{
[self willChangeValueForKey:@"unread"];
[self setPrimitiveUnread:unread];
[self didChangeValueForKey:@"unread"];
[[[MLMediaLibrary sharedMediaLibrary] managedObjectContext] refreshObject:[self album] mergeChanges:YES];
[[[MLMediaLibrary sharedMediaLibrary] managedObjectContext] refreshObject:self mergeChanges:YES];
}
@dynamic artist;
@dynamic genre;
@dynamic title;
@dynamic trackNumber;
@dynamic album;
@dynamic files;
@end
......@@ -27,12 +27,15 @@
#import "MLFile.h"
#import "MLShow.h"
#import "MLShowEpisode.h"
#import "MLAlbum.h"
#import "MLAlbumTrack.h"
#import "MLMediaLibrary.h"
#import "MLThumbnailerQueue.h"
NSString *kMLFileTypeMovie = @"movie";
NSString *kMLFileTypeClip = @"clip";
NSString *kMLFileTypeTVShowEpisode = @"tvShowEpisode";
NSString *kMLFileTypeAudio = @"audio";
@implementation MLFile
......@@ -79,6 +82,16 @@ NSString *kMLFileTypeTVShowEpisode = @"tvShowEpisode";
{
return [self isKindOfType:kMLFileTypeTVShowEpisode];
}
- (BOOL)isAlbumTrack
{
return [self isKindOfType:kMLFileTypeAudio];
}
- (BOOL)isSupportedAudioFile
{
NSUInteger options = NSRegularExpressionSearch | NSCaseInsensitiveSearch;
return ([[self.url lastPathComponent] rangeOfString:@"\\.(aac|aiff|aif|amr|aob|ape|axa|flac|it|m2a|m4a|mka|mlp|mod|mp1|mp2|mp3|mpa|mpc|oga|oma|opus|rmi|s3m|spx|tta|voc|vqf|wav|wma|wv|xa|xm)$" options:options].location != NSNotFound);
}
- (NSString *)artworkURL
{
if ([self isShowEpisode]) {
......@@ -109,6 +122,17 @@ NSString *kMLFileTypeTVShowEpisode = @"tvShowEpisode";
[name appendString:episode.name];
}
return [NSString stringWithString:name];
} else if ([self isAlbumTrack]) {
MLAlbumTrack *track = self.albumTrack;
NSMutableString *name = [[NSMutableString alloc] initWithString:track.title];
if (track.album.name)
[name appendFormat:@" - %@", track.album.name];
if (track.artist)
[name appendFormat:@" - %@", track.artist];
return [NSString stringWithString:name];
}
[self willAccessValueForKey:@"title"];
......@@ -139,6 +163,11 @@ NSString *kMLFileTypeTVShowEpisode = @"tvShowEpisode";
@dynamic tracks;
@dynamic isOnDisk;
@dynamic duration;
@dynamic artist;
@dynamic album;
@dynamic albumTrackNumber;
@dynamic genre;
@dynamic albumTrack;
- (NSString *)thumbnailPath
{
......
......@@ -106,6 +106,7 @@
[self.file setTracks:tracksSet];
[self.file setDuration:[[_media length] numberValue]];
MLFileParserQueue *parserQueue = [MLFileParserQueue sharedFileParserQueue];
[[MLCrashPreventer sharedPreventer] didParseFile:self.file];
[parserQueue.queue setSuspended:NO];
......
......@@ -32,8 +32,10 @@
#import "MLFile.h"
#import "MLLabel.h"
#import "MLShowEpisode.h"
#import "MLThumbnailerQueue.h"
#import "MLShow.h"
#import "MLThumbnailerQueue.h"
#import "MLAlbumTrack.h"
#import "MLAlbum.h"
#import "MLFileParserQueue.h"
#import "MLCrashPreventer.h"
......@@ -130,8 +132,8 @@ static NSString *kLastTVDBUpdateServerTime = @"MLLastTVDBUpdateServerTime";
NSPersistentStoreCoordinator *coordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
NSNumber *yes = @YES;
NSDictionary *options = @{NSMigratePersistentStoresAutomaticallyOption: yes,
NSInferMappingModelAutomaticallyOption: yes};
NSDictionary *options = @{NSMigratePersistentStoresAutomaticallyOption : yes,
NSInferMappingModelAutomaticallyOption : yes};
NSError *error;
NSPersistentStore *persistentStore = [coordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:url options:options error:&error];
......@@ -444,6 +446,37 @@ static NSString *kLastTVDBUpdateServerTime = @"MLLastTVDBUpdateServerTime";
file.hasFetchedInfo = @YES;
}
- (void)addAudioContentWithInfo:(NSDictionary *)audioContentInfo andFile:(MLFile *)file
{
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.hasFetchedInfo = @YES;
}
/**
* MLFile auto detection
......@@ -495,6 +528,14 @@ static NSString *kLastTVDBUpdateServerTime = @"MLLastTVDBUpdateServerTime";
return;
}
if ([file isSupportedAudioFile]) {
NSDictionary *audioContentInfo = [MLTitleDecrapifier audioContentInfoFromFile:file];
if (audioContentInfo && ![file videoTrack]) {
[self addAudioContentWithInfo:audioContentInfo andFile:file];
return;
}
}
if (!_allowNetworkAccess)
return;
......@@ -654,8 +695,8 @@ static NSString *kLastTVDBUpdateServerTime = @"MLLastTVDBUpdateServerTime";
file.isSafe = YES; // It doesn't exists, it's safe.
#if TARGET_OS_IPHONE
NSString *thumbPath = [[[self thumbnailFolderPath] stringByAppendingPathComponent:[[file.objectID URIRepresentation] path]] stringByAppendingString:@".png"];
exists = [fileManager fileExistsAtPath:thumbPath];
if (exists)
bool thumbExists = [fileManager fileExistsAtPath:thumbPath];
if (thumbExists)
[fileManager removeItemAtPath:thumbPath error:nil];
[[self managedObjectContext] deleteObject:file];
#endif
......
......@@ -120,4 +120,34 @@ static inline NSNumber *numberFromTwoChars(char high, char low)
return nil;
}
+ (NSDictionary *)audioContentInfoFromFile:(MLFile *)file
{
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;
}
@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