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

music albums: add support for media with more than one disc (close #14650),...

music albums: add support for media with more than one disc (close #14650), add a future-proof MLAlbumTrack API and deprecate the existing
parent d7e992d4
...@@ -25,32 +25,48 @@ ...@@ -25,32 +25,48 @@
#import "MLAlbum.h" #import "MLAlbum.h"
extern NSString *const MLAlbumTrackAlbumName;
extern NSString *const MLAlbumTrackNumber;
extern NSString *const MLAlbumTrackTrackName;
extern NSString *const MLAlbumTrackDiscNumber;
@interface MLAlbumTrack : NSManagedObject @interface MLAlbumTrack : NSManagedObject
+ (NSArray *)allTracks; + (NSArray *)allTracks;
+ (MLAlbumTrack *)trackWithAlbum:(MLAlbum *)album + (MLAlbumTrack *)trackWithAlbum:(MLAlbum *)album
trackNumber:(NSNumber *)trackNumber trackNumber:(NSNumber *)trackNumber
createIfNeeded:(BOOL)createIfNeeded; createIfNeeded:(BOOL)createIfNeeded __attribute__((deprecated));
+ (MLAlbumTrack *)trackWithAlbum:(MLAlbum *)album + (MLAlbumTrack *)trackWithAlbum:(MLAlbum *)album
trackNumber:(NSNumber *)trackNumber trackNumber:(NSNumber *)trackNumber
trackName:(NSString *)trackName trackName:(NSString *)trackName
createIfNeeded:(BOOL)createIfNeeded; createIfNeeded:(BOOL)createIfNeeded __attribute__((deprecated));
+ (MLAlbumTrack *)trackWithAlbumName:(NSString *)albumName + (MLAlbumTrack *)trackWithAlbumName:(NSString *)albumName
trackNumber:(NSNumber *)trackNumber trackNumber:(NSNumber *)trackNumber
createIfNeeded:(BOOL)createIfNeeded createIfNeeded:(BOOL)createIfNeeded
wasCreated:(BOOL *)wasCreated; wasCreated:(BOOL *)wasCreated __attribute__((deprecated));
+ (MLAlbumTrack *)trackWithAlbumName:(NSString *)albumName + (MLAlbumTrack *)trackWithAlbumName:(NSString *)albumName
trackNumber:(NSNumber *)trackNumber trackNumber:(NSNumber *)trackNumber
trackName:(NSString *)trackName trackName:(NSString *)trackName
createIfNeeded:(BOOL)createIfNeeded createIfNeeded:(BOOL)createIfNeeded
wasCreated:(BOOL *)wasCreated; wasCreated:(BOOL *)wasCreated __attribute__((deprecated));
/* for available keys, see above */
+ (MLAlbumTrack *)trackWithAlbum:(MLAlbum *)album
metadata:(NSDictionary *)metadata
createIfNeeded:(BOOL)createIfNeeded
wasCreated:(BOOL *)wasCreated;
+ (MLAlbumTrack *)trackWithMetadata:(NSDictionary *)metadata
createIfNeeded:(BOOL)createIfNeeded
wasCreated:(BOOL *)wasCreated;
@property (nonatomic, strong) NSNumber *unread; @property (nonatomic, strong) NSNumber *unread;
@property (nonatomic, strong) NSString *artist; @property (nonatomic, strong) NSString *artist;
@property (nonatomic, strong) NSString *genre; @property (nonatomic, strong) NSString *genre;
@property (nonatomic, strong) NSString *title; @property (nonatomic, strong) NSString *title;
@property (nonatomic, strong) NSNumber *trackNumber; @property (nonatomic, strong) NSNumber *trackNumber;
@property (nonatomic, strong) NSNumber *discNumber;
@property (nonatomic, strong) MLAlbum *album; @property (nonatomic, strong) MLAlbum *album;
@property (nonatomic, strong) NSSet *files; @property (nonatomic, strong) NSSet *files;
......
...@@ -3,6 +3,6 @@ ...@@ -3,6 +3,6 @@
<plist version="1.0"> <plist version="1.0">
<dict> <dict>
<key>_XCCurrentVersionName</key> <key>_XCCurrentVersionName</key>
<string>MediaLibrary-2.6.xcdatamodel</string> <string>MediaLibrary-2.7.xcdatamodel</string>
</dict> </dict>
</plist> </plist>
...@@ -76,6 +76,7 @@ ...@@ -76,6 +76,7 @@
/* End PBXCopyFilesBuildPhase section */ /* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */ /* Begin PBXFileReference section */
7D0363A61B2F317500CC0343 /* MediaLibrary-2.7.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "MediaLibrary-2.7.xcdatamodel"; sourceTree = "<group>"; };
7D0EF49E170883940003ED47 /* libMediaLibraryKit.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libMediaLibraryKit.a; sourceTree = BUILT_PRODUCTS_DIR; }; 7D0EF49E170883940003ED47 /* libMediaLibraryKit.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libMediaLibraryKit.a; sourceTree = BUILT_PRODUCTS_DIR; };
7D0EF4A1170883940003ED47 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 7D0EF4A1170883940003ED47 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
7D0EF4DF170883D80003ED47 /* MediaLibraryKit_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MediaLibraryKit_Prefix.pch; sourceTree = "<group>"; }; 7D0EF4DF170883D80003ED47 /* MediaLibraryKit_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MediaLibraryKit_Prefix.pch; sourceTree = "<group>"; };
...@@ -559,11 +560,12 @@ ...@@ -559,11 +560,12 @@
DDC7BFAA1B03825F00160878 /* MediaLibrary.xcdatamodeld */ = { DDC7BFAA1B03825F00160878 /* MediaLibrary.xcdatamodeld */ = {
isa = XCVersionGroup; isa = XCVersionGroup;
children = ( children = (
7D0363A61B2F317500CC0343 /* MediaLibrary-2.7.xcdatamodel */,
DDC7BFAB1B03825F00160878 /* MediaLibrary-2.1.xcdatamodel */, DDC7BFAB1B03825F00160878 /* MediaLibrary-2.1.xcdatamodel */,
DDC7BFAC1B03825F00160878 /* MediaLibrary-2.5.xcdatamodel */, DDC7BFAC1B03825F00160878 /* MediaLibrary-2.5.xcdatamodel */,
DDC7BFAD1B03825F00160878 /* MediaLibrary-2.6.xcdatamodel */, DDC7BFAD1B03825F00160878 /* MediaLibrary-2.6.xcdatamodel */,
); );
currentVersion = DDC7BFAD1B03825F00160878 /* MediaLibrary-2.6.xcdatamodel */; currentVersion = 7D0363A61B2F317500CC0343 /* MediaLibrary-2.7.xcdatamodel */;
path = MediaLibrary.xcdatamodeld; path = MediaLibrary.xcdatamodeld;
sourceTree = "<group>"; sourceTree = "<group>";
versionGroupType = wrapper.xcdatamodel; versionGroupType = wrapper.xcdatamodel;
......
Version 2.6.0
-------------
Added Public APIs:
- MLAlbumTrack:
- new selectors: trackWithAlbum:metadata:createIfNeeded:wasCreated:
trackWithMetadata:createIfNeeded:wasCreated:
Deprecated Public APIs:
- MLAlbumTrack:
trackWithAlbum:trackNumber:createIfNeeded:
trackWithAlbum:trackNumber:trackName:createIfNeeded:
trackWithAlbumName:trackNumber:createIfNeeded:wasCreated:
trackWithAlbumName:trackNumber:trackName:createIfNeeded:wasCreated:
Version 2.5.1 Version 2.5.1
------------- -------------
Added Public APIs: Added Public APIs:
......
...@@ -77,7 +77,13 @@ ...@@ -77,7 +77,13 @@
[[NSSortDescriptor alloc] initWithKey:@"trackNumber" [[NSSortDescriptor alloc] initWithKey:@"trackNumber"
ascending:YES ascending:YES
selector:@selector(compare:)]; selector:@selector(compare:)];
return [tracks sortedArrayUsingDescriptors:@[trackNumberDescriptor]];
NSSortDescriptor *discNumberDescriptor =
[[NSSortDescriptor alloc] initWithKey:@"discNumber"
ascending:YES
selector:@selector(compare:)];
return [tracks sortedArrayUsingDescriptors:@[discNumberDescriptor, trackNumberDescriptor]];
} }
- (void)addTrack:(MLAlbumTrack *)track - (void)addTrack:(MLAlbumTrack *)track
......
...@@ -27,6 +27,12 @@ ...@@ -27,6 +27,12 @@
#import "MLAlbumTrack.h" #import "MLAlbumTrack.h"
#import "MLAlbum.h" #import "MLAlbum.h"
NSString *const MLAlbumTrackAlbum = @"MLAlbumTrackAlbum";
NSString *const MLAlbumTrackAlbumName = @"MLAlbumTrackAlbumName";
NSString *const MLAlbumTrackNumber = @"MLAlbumTrackNumber";
NSString *const MLAlbumTrackTrackName = @"MLAlbumTrackTrackName";
NSString *const MLAlbumTrackDiscNumber = @"MLAlbumTrackDiscNumber";
@interface MLAlbumTrack () @interface MLAlbumTrack ()
@property (nonatomic, strong) NSNumber *primitiveUnread; @property (nonatomic, strong) NSNumber *primitiveUnread;
@end @end
...@@ -54,23 +60,44 @@ ...@@ -54,23 +60,44 @@
+ (MLAlbumTrack *)trackWithAlbum:(MLAlbum *)album trackNumber:(NSNumber *)trackNumber createIfNeeded:(BOOL)createIfNeeded + (MLAlbumTrack *)trackWithAlbum:(MLAlbum *)album trackNumber:(NSNumber *)trackNumber createIfNeeded:(BOOL)createIfNeeded
{ {
return [MLAlbumTrack trackWithAlbum:album NSMutableDictionary *mutDict = [NSMutableDictionary dictionary];
trackNumber:trackNumber
trackName:@"" if (trackNumber)
createIfNeeded:createIfNeeded]; [mutDict setObject:trackNumber forKey:MLAlbumTrackNumber];
BOOL wasCreated = NO;
return [MLAlbumTrack trackWithAlbum:album metadata:[NSDictionary dictionaryWithDictionary:mutDict] createIfNeeded:createIfNeeded wasCreated:&wasCreated];
} }
+ (MLAlbumTrack *)trackWithAlbum:(MLAlbum *)album trackNumber:(NSNumber *)trackNumber trackName:(NSString *)trackName createIfNeeded:(BOOL)createIfNeeded + (MLAlbumTrack *)trackWithAlbum:(MLAlbum *)album trackNumber:(NSNumber *)trackNumber trackName:(NSString *)trackName createIfNeeded:(BOOL)createIfNeeded
{
NSMutableDictionary *mutDict = [NSMutableDictionary dictionary];
if (trackName)
[mutDict setObject:trackName forKey:MLAlbumTrackTrackName];
if (trackNumber)
[mutDict setObject:trackNumber forKey:MLAlbumTrackNumber];
BOOL wasCreated = NO;
return [MLAlbumTrack trackWithAlbum:album metadata:[NSDictionary dictionaryWithDictionary:mutDict] createIfNeeded:createIfNeeded wasCreated:&wasCreated];
}
+ (MLAlbumTrack *)trackWithAlbum:(MLAlbum *)album metadata:(NSDictionary *)metadata createIfNeeded:(BOOL)createIfNeeded wasCreated:(BOOL *)wasCreated
{ {
if (!album) if (!album)
return nil; return nil;
NSNumber *trackNumber = metadata[MLAlbumTrackNumber];
NSString *trackName = metadata[MLAlbumTrackTrackName];
NSNumber *discNumber = metadata[MLAlbumTrackDiscNumber];
NSSet *tracks = [album tracks]; NSSet *tracks = [album tracks];
MLAlbumTrack *track = nil; MLAlbumTrack *track = nil;
if (trackNumber) { if (trackNumber) {
for (MLAlbumTrack *trackIter in tracks) { for (MLAlbumTrack *trackIter in tracks) {
if ([trackIter.trackNumber intValue] == [trackNumber intValue]) { if ([trackIter.trackNumber intValue] == [trackNumber intValue]) {
track = trackIter; if (trackIter.discNumber == discNumber)
track = trackIter;
break; break;
} else if ([trackIter.title isEqualToString:trackName]) { } else if ([trackIter.title isEqualToString:trackName]) {
track = trackIter; track = trackIter;
...@@ -83,6 +110,9 @@ ...@@ -83,6 +110,9 @@
if (trackNumber.integerValue == 0) if (trackNumber.integerValue == 0)
trackNumber = @(tracks.count + 1); trackNumber = @(tracks.count + 1);
track.trackNumber = trackNumber; track.trackNumber = trackNumber;
track.title = trackName;
if (discNumber)
track.discNumber = discNumber;
[album addTrack:track]; [album addTrack:track];
} }
return track; return track;
...@@ -90,25 +120,45 @@ ...@@ -90,25 +120,45 @@
+ (MLAlbumTrack *)trackWithAlbumName:(NSString *)albumName trackNumber:(NSNumber *)trackNumber createIfNeeded:(BOOL)createIfNeeded wasCreated:(BOOL *)wasCreated + (MLAlbumTrack *)trackWithAlbumName:(NSString *)albumName trackNumber:(NSNumber *)trackNumber createIfNeeded:(BOOL)createIfNeeded wasCreated:(BOOL *)wasCreated
{ {
return [MLAlbumTrack trackWithAlbumName:albumName NSMutableDictionary *mutDict = [NSMutableDictionary dictionary];
trackNumber:trackNumber
trackName:@"" if (albumName)
createIfNeeded:createIfNeeded [mutDict setObject:albumName forKey:MLAlbumTrackAlbumName];
wasCreated:wasCreated]; if (trackNumber)
[mutDict setObject:trackNumber forKey:MLAlbumTrackNumber];
return [MLAlbumTrack trackWithMetadata:[NSDictionary dictionaryWithDictionary:mutDict] createIfNeeded:createIfNeeded wasCreated:wasCreated];
} }
+ (MLAlbumTrack *)trackWithAlbumName:(NSString *)albumName trackNumber:(NSNumber *)trackNumber trackName:(NSString *)trackName createIfNeeded:(BOOL)createIfNeeded wasCreated:(BOOL *)wasCreated + (MLAlbumTrack *)trackWithAlbumName:(NSString *)albumName trackNumber:(NSNumber *)trackNumber trackName:(NSString *)trackName createIfNeeded:(BOOL)createIfNeeded wasCreated:(BOOL *)wasCreated
{ {
NSMutableDictionary *mutDict = [NSMutableDictionary dictionary];
if (albumName)
[mutDict setObject:albumName forKey:MLAlbumTrackAlbumName];
if (trackNumber)
[mutDict setObject:trackNumber forKey:MLAlbumTrackNumber];
if (trackName)
[mutDict setObject:trackName forKey:MLAlbumTrackTrackName];
return [MLAlbumTrack trackWithMetadata:[NSDictionary dictionaryWithDictionary:mutDict] createIfNeeded:createIfNeeded wasCreated:wasCreated];
}
+ (MLAlbumTrack *)trackWithMetadata:(NSDictionary *)metadata createIfNeeded:(BOOL)createIfNeeded wasCreated:(BOOL *)wasCreated
{
NSString *albumName = metadata[MLAlbumTrackAlbumName];
MLAlbum *album = [MLAlbum albumWithName:albumName]; MLAlbum *album = [MLAlbum albumWithName:albumName];
*wasCreated = NO; *wasCreated = NO;
if (!album && createIfNeeded) { if (!album && createIfNeeded) {
*wasCreated = YES; *wasCreated = YES;
album = [[MLMediaLibrary sharedMediaLibrary] createObjectForEntity:@"Album"]; album = [[MLMediaLibrary sharedMediaLibrary] createObjectForEntity:@"Album"];
album.name = albumName ? albumName : @""; album.name = albumName ? albumName : @"";
} else if (!album && !createIfNeeded) }
if (!album && !createIfNeeded)
return nil; return nil;
return [MLAlbumTrack trackWithAlbum:album trackNumber:trackNumber trackName:trackName createIfNeeded:createIfNeeded]; return [MLAlbumTrack trackWithAlbum:album metadata:metadata createIfNeeded:createIfNeeded wasCreated:wasCreated];
} }
@dynamic primitiveUnread; @dynamic primitiveUnread;
...@@ -129,6 +179,7 @@ ...@@ -129,6 +179,7 @@
@dynamic genre; @dynamic genre;
@dynamic title; @dynamic title;
@dynamic trackNumber; @dynamic trackNumber;
@dynamic discNumber;
@dynamic album; @dynamic album;
@dynamic files; @dynamic files;
@dynamic containsArtwork; @dynamic containsArtwork;
......
...@@ -161,15 +161,25 @@ ...@@ -161,15 +161,25 @@
NSString *releaseYear = audioContentInfo[VLCMetaInformationDate]; NSString *releaseYear = audioContentInfo[VLCMetaInformationDate];
NSString *genre = audioContentInfo[VLCMetaInformationGenre]; NSString *genre = audioContentInfo[VLCMetaInformationGenre];
NSString *trackNumber = audioContentInfo[VLCMetaInformationTrackNumber]; NSString *trackNumber = audioContentInfo[VLCMetaInformationTrackNumber];
NSString *discNumber = audioContentInfo[VLCMetaInformationDiscNumber];
MLAlbum *album = nil; MLAlbum *album = nil;
BOOL wasCreated = NO; BOOL wasCreated = NO;
MLAlbumTrack *track = [MLAlbumTrack trackWithAlbumName:albumName
trackNumber:@([trackNumber integerValue]) NSMutableDictionary *mutDict = [NSMutableDictionary dictionary];
trackName:title if (albumName)
createIfNeeded:YES [mutDict setObject:albumName forKey:MLAlbumTrackAlbumName];
wasCreated:&wasCreated]; if (title)
[mutDict setObject:title forKey:MLAlbumTrackTrackName];
if (trackNumber)
[mutDict setObject:@([trackNumber integerValue]) forKey:MLAlbumTrackNumber];
if (discNumber)
[mutDict setObject:@([discNumber integerValue]) forKey:MLAlbumTrackDiscNumber];
MLAlbumTrack *track = [MLAlbumTrack trackWithMetadata:[NSDictionary dictionaryWithDictionary:mutDict]
createIfNeeded:YES
wasCreated:&wasCreated];
if (track) { if (track) {
album = track.album; album = track.album;
track.title = title ? title : @""; track.title = title ? title : @"";
......
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