Commit 0c829c57 authored by Tobias Conradi's avatar Tobias Conradi Committed by Felix Paul Kühne

add methods to retrieve MediaLibrary objects by their URIRepresentation

parent 0ffa3d3e
......@@ -39,6 +39,8 @@ extern NSString *kMLFileTypeAudio;
+ (NSArray *)allFiles;
+ (NSArray *)fileForURL:(NSString *)url;
+ (instancetype)fileForURIRepresentation:(NSURL *)uriRepresentation;
- (BOOL)isKindOfType:(NSString *)type;
- (BOOL)isMovie;
- (BOOL)isClip;
......
......@@ -48,6 +48,8 @@
- (NSString *)thumbnailFolderPath;
- (NSString *)documentFolderPath;
- (NSManagedObject *)objectForURIRepresentation:(NSURL *)uriRepresenation;
- (void)applicationWillStart;
- (void)applicationWillExit;
......
......@@ -89,6 +89,15 @@ NSString *kMLFileTypeAudio = @"audio";
return files;
}
+ (instancetype)fileForURIRepresentation:(NSURL *)uriRepresentation {
NSManagedObject *object = [[MLMediaLibrary sharedMediaLibrary] objectForURIRepresentation:uriRepresentation];
if ([object isKindOfClass:[MLFile class]]) {
return (MLFile *)object;
} else {
return nil;
}
}
- (BOOL)isKindOfType:(NSString *)type
{
return [self.type isEqualToString:type];
......
......@@ -311,6 +311,15 @@ static NSString *kDecrapifyTitles = @"MLDecrapifyTitles";
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
- (NSManagedObject *)objectForURIRepresentation:(NSURL *)uriRepresenation {
if (uriRepresenation == nil) {
return nil;
}
NSManagedObjectID *objectID = [self.persistentStoreCoordinator managedObjectIDForURIRepresentation:uriRepresenation];
NSManagedObject *managedObject = [self.managedObjectContext objectWithID:objectID];
return managedObject;
}
#pragma mark -
#pragma mark No meta data fallbacks
......
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