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,24 +25,39 @@
#import "MLAlbum.h"
extern NSString *const MLAlbumTrackAlbumName;
extern NSString *const MLAlbumTrackNumber;
extern NSString *const MLAlbumTrackTrackName;
extern NSString *const MLAlbumTrackDiscNumber;
@interface MLAlbumTrack : NSManagedObject
+ (NSArray *)allTracks;
+ (MLAlbumTrack *)trackWithAlbum:(MLAlbum *)album
trackNumber:(NSNumber *)trackNumber
createIfNeeded:(BOOL)createIfNeeded;
createIfNeeded:(BOOL)createIfNeeded __attribute__((deprecated));
+ (MLAlbumTrack *)trackWithAlbum:(MLAlbum *)album
trackNumber:(NSNumber *)trackNumber
trackName:(NSString *)trackName
createIfNeeded:(BOOL)createIfNeeded;
createIfNeeded:(BOOL)createIfNeeded __attribute__((deprecated));
+ (MLAlbumTrack *)trackWithAlbumName:(NSString *)albumName
trackNumber:(NSNumber *)trackNumber
createIfNeeded:(BOOL)createIfNeeded
wasCreated:(BOOL *)wasCreated;
wasCreated:(BOOL *)wasCreated __attribute__((deprecated));
+ (MLAlbumTrack *)trackWithAlbumName:(NSString *)albumName
trackNumber:(NSNumber *)trackNumber
trackName:(NSString *)trackName
createIfNeeded:(BOOL)createIfNeeded
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;
......@@ -51,6 +66,7 @@
@property (nonatomic, strong) NSString *genre;
@property (nonatomic, strong) NSString *title;
@property (nonatomic, strong) NSNumber *trackNumber;
@property (nonatomic, strong) NSNumber *discNumber;
@property (nonatomic, strong) MLAlbum *album;
@property (nonatomic, strong) NSSet *files;
......
......@@ -3,6 +3,6 @@
<plist version="1.0">
<dict>
<key>_XCCurrentVersionName</key>
<string>MediaLibrary-2.6.xcdatamodel</string>
<string>MediaLibrary-2.7.xcdatamodel</string>
</dict>
</plist>
......@@ -76,6 +76,7 @@
/* End PBXCopyFilesBuildPhase 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; };
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>"; };
......@@ -559,11 +560,12 @@
DDC7BFAA1B03825F00160878 /* MediaLibrary.xcdatamodeld */ = {
isa = XCVersionGroup;
children = (
7D0363A61B2F317500CC0343 /* MediaLibrary-2.7.xcdatamodel */,
DDC7BFAB1B03825F00160878 /* MediaLibrary-2.1.xcdatamodel */,
DDC7BFAC1B03825F00160878 /* MediaLibrary-2.5.xcdatamodel */,
DDC7BFAD1B03825F00160878 /* MediaLibrary-2.6.xcdatamodel */,
);
currentVersion = DDC7BFAD1B03825F00160878 /* MediaLibrary-2.6.xcdatamodel */;
currentVersion = 7D0363A61B2F317500CC0343 /* MediaLibrary-2.7.xcdatamodel */;
path = MediaLibrary.xcdatamodeld;
sourceTree = "<group>";
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
-------------
Added Public APIs:
......
......@@ -77,7 +77,13 @@
[[NSSortDescriptor alloc] initWithKey:@"trackNumber"
ascending:YES
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
......
......@@ -27,6 +27,12 @@
#import "MLAlbumTrack.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 ()
@property (nonatomic, strong) NSNumber *primitiveUnread;
@end
......@@ -54,22 +60,43 @@
+ (MLAlbumTrack *)trackWithAlbum:(MLAlbum *)album trackNumber:(NSNumber *)trackNumber createIfNeeded:(BOOL)createIfNeeded
{
return [MLAlbumTrack trackWithAlbum:album
trackNumber:trackNumber
trackName:@""
createIfNeeded:createIfNeeded];
NSMutableDictionary *mutDict = [NSMutableDictionary dictionary];
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 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)
return nil;
NSNumber *trackNumber = metadata[MLAlbumTrackNumber];
NSString *trackName = metadata[MLAlbumTrackTrackName];
NSNumber *discNumber = metadata[MLAlbumTrackDiscNumber];
NSSet *tracks = [album tracks];
MLAlbumTrack *track = nil;
if (trackNumber) {
for (MLAlbumTrack *trackIter in tracks) {
if ([trackIter.trackNumber intValue] == [trackNumber intValue]) {
if (trackIter.discNumber == discNumber)
track = trackIter;
break;
} else if ([trackIter.title isEqualToString:trackName]) {
......@@ -83,6 +110,9 @@
if (trackNumber.integerValue == 0)
trackNumber = @(tracks.count + 1);
track.trackNumber = trackNumber;
track.title = trackName;
if (discNumber)
track.discNumber = discNumber;
[album addTrack:track];
}
return track;
......@@ -90,25 +120,45 @@
+ (MLAlbumTrack *)trackWithAlbumName:(NSString *)albumName trackNumber:(NSNumber *)trackNumber createIfNeeded:(BOOL)createIfNeeded wasCreated:(BOOL *)wasCreated
{
return [MLAlbumTrack trackWithAlbumName:albumName
trackNumber:trackNumber
trackName:@""
createIfNeeded:createIfNeeded
wasCreated:wasCreated];
NSMutableDictionary *mutDict = [NSMutableDictionary dictionary];
if (albumName)
[mutDict setObject:albumName forKey:MLAlbumTrackAlbumName];
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
{
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];
*wasCreated = NO;
if (!album && createIfNeeded) {
*wasCreated = YES;
album = [[MLMediaLibrary sharedMediaLibrary] createObjectForEntity:@"Album"];
album.name = albumName ? albumName : @"";
} else if (!album && !createIfNeeded)
}
if (!album && !createIfNeeded)
return nil;
return [MLAlbumTrack trackWithAlbum:album trackNumber:trackNumber trackName:trackName createIfNeeded:createIfNeeded];
return [MLAlbumTrack trackWithAlbum:album metadata:metadata createIfNeeded:createIfNeeded wasCreated:wasCreated];
}
@dynamic primitiveUnread;
......@@ -129,6 +179,7 @@
@dynamic genre;
@dynamic title;
@dynamic trackNumber;
@dynamic discNumber;
@dynamic album;
@dynamic files;
@dynamic containsArtwork;
......
......@@ -161,13 +161,23 @@
NSString *releaseYear = audioContentInfo[VLCMetaInformationDate];
NSString *genre = audioContentInfo[VLCMetaInformationGenre];
NSString *trackNumber = audioContentInfo[VLCMetaInformationTrackNumber];
NSString *discNumber = audioContentInfo[VLCMetaInformationDiscNumber];
MLAlbum *album = nil;
BOOL wasCreated = NO;
MLAlbumTrack *track = [MLAlbumTrack trackWithAlbumName:albumName
trackNumber:@([trackNumber integerValue])
trackName:title
NSMutableDictionary *mutDict = [NSMutableDictionary dictionary];
if (albumName)
[mutDict setObject:albumName forKey:MLAlbumTrackAlbumName];
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) {
......
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