2005-06-02 18:16:43 +00:00
|
|
|
//
|
|
|
|
// PlaylistEntry.m
|
|
|
|
// Cog
|
|
|
|
//
|
|
|
|
// Created by Vincent Spader on 3/14/05.
|
2005-07-02 21:02:06 +00:00
|
|
|
// Copyright 2005 Vincent Spader All rights reserved.
|
2005-06-02 18:16:43 +00:00
|
|
|
//
|
|
|
|
|
2022-06-16 14:14:33 +00:00
|
|
|
#import <Foundation/Foundation.h>
|
2005-06-02 18:16:43 +00:00
|
|
|
|
2022-06-16 14:14:33 +00:00
|
|
|
#import <CoreData/CoreData.h>
|
2022-01-15 00:46:35 +00:00
|
|
|
|
2022-06-16 14:14:33 +00:00
|
|
|
#import "PlaylistEntry.h"
|
2013-10-02 09:30:04 +00:00
|
|
|
|
2022-06-16 14:14:33 +00:00
|
|
|
#import "AVIFDecoder.h"
|
|
|
|
#import "SHA256Digest.h"
|
|
|
|
#import "SecondsFormatter.h"
|
2013-10-04 11:16:09 +00:00
|
|
|
|
2022-06-21 07:01:07 +00:00
|
|
|
extern NSPersistentContainer *kPersistentContainer;
|
|
|
|
extern NSMutableDictionary<NSString *, AlbumArtwork *> *kArtworkDictionary;
|
2008-03-01 03:29:21 +00:00
|
|
|
|
2022-06-16 14:14:33 +00:00
|
|
|
@implementation PlaylistEntry (Extension)
|
2022-01-22 06:38:54 +00:00
|
|
|
|
2022-06-16 14:14:33 +00:00
|
|
|
// The following read-only keys depend on the values of other properties
|
2006-05-12 14:41:02 +00:00
|
|
|
|
2022-06-16 14:14:33 +00:00
|
|
|
+ (NSSet *)keyPathsForValuesAffectingUrl {
|
|
|
|
return [NSSet setWithObject:@"urlString"];
|
|
|
|
}
|
2009-03-06 04:46:42 +00:00
|
|
|
|
2022-06-16 14:14:33 +00:00
|
|
|
+ (NSSet *)keyPathsForValuesAffectingTrashUrl {
|
|
|
|
return [NSSet setWithObject:@"trashUrlString"];
|
|
|
|
}
|
2022-02-10 05:04:17 +00:00
|
|
|
|
2022-06-16 14:14:33 +00:00
|
|
|
+ (NSSet *)keyPathsForValuesAffectingTitle {
|
|
|
|
return [NSSet setWithObject:@"rawTitle"];
|
|
|
|
}
|
2008-02-29 21:54:09 +00:00
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
+ (NSSet *)keyPathsForValuesAffectingDisplay {
|
|
|
|
return [NSSet setWithObjects:@"artist", @"title", nil];
|
2008-02-29 21:54:09 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
+ (NSSet *)keyPathsForValuesAffectingLength {
|
2022-02-07 11:03:39 +00:00
|
|
|
return [NSSet setWithObjects:@"metadataLoaded", @"totalFrames", @"sampleRate", nil];
|
2006-05-12 14:41:02 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
+ (NSSet *)keyPathsForValuesAffectingPath {
|
2022-06-16 14:14:33 +00:00
|
|
|
return [NSSet setWithObject:@"url"];
|
2008-02-29 21:54:09 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
+ (NSSet *)keyPathsForValuesAffectingFilename {
|
2022-06-16 14:14:33 +00:00
|
|
|
return [NSSet setWithObject:@"url"];
|
2006-05-12 19:08:39 +00:00
|
|
|
}
|
|
|
|
|
2022-06-26 11:37:41 +00:00
|
|
|
+ (NSSet *)keyPathsForValuesAffectingFilenameFragment {
|
|
|
|
return [NSSet setWithObject:@"url"];
|
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
+ (NSSet *)keyPathsForValuesAffectingStatus {
|
|
|
|
return [NSSet setWithObjects:@"current", @"queued", @"error", @"stopAfter", nil];
|
2008-03-01 03:29:21 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
+ (NSSet *)keyPathsForValuesAffectingStatusMessage {
|
2008-03-01 03:35:27 +00:00
|
|
|
return [NSSet setWithObjects:@"current", @"queued", @"queuePosition", @"error", @"errorMessage", @"stopAfter", nil];
|
2008-03-01 03:29:21 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
+ (NSSet *)keyPathsForValuesAffectingSpam {
|
2022-06-16 14:14:33 +00:00
|
|
|
return [NSSet setWithObjects:@"albumartist", @"artist", @"rawTitle", @"album", @"track", @"disc", @"totalFrames", @"currentPosition", @"bitrate", nil];
|
2022-01-22 05:49:17 +00:00
|
|
|
}
|
|
|
|
|
2022-06-16 14:18:28 +00:00
|
|
|
+ (NSSet *)keyPathsForValuesAffectingIndexedSpam {
|
|
|
|
return [NSSet setWithObjects:@"albumartist", @"artist", @"rawTitle", @"album", @"track", @"disc", @"totalFrames", @"currentPosition", @"bitrate", @"index", nil];
|
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
+ (NSSet *)keyPathsForValuesAffectingTrackText {
|
|
|
|
return [NSSet setWithObjects:@"track", @"disc", nil];
|
2013-10-04 11:16:09 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
+ (NSSet *)keyPathsForValuesAffectingYearText {
|
|
|
|
return [NSSet setWithObject:@"year"];
|
2022-01-22 07:19:32 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
+ (NSSet *)keyPathsForValuesAffectingCuesheetPresent {
|
|
|
|
return [NSSet setWithObject:@"cuesheet"];
|
2022-01-22 07:19:32 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
+ (NSSet *)keyPathsForValuesAffectingPositionText {
|
|
|
|
return [NSSet setWithObject:@"currentPosition"];
|
2014-12-04 06:13:27 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
+ (NSSet *)keyPathsForValuesAffectingLengthText {
|
|
|
|
return [NSSet setWithObject:@"length"];
|
2014-12-04 06:13:27 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
+ (NSSet *)keyPathsForValuesAffectingAlbumArt {
|
2022-02-11 06:45:26 +00:00
|
|
|
return [NSSet setWithObjects:@"albumArtInternal", @"artId", nil];
|
2013-10-09 20:53:13 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
+ (NSSet *)keyPathsForValuesAffectingGainCorrection {
|
|
|
|
return [NSSet setWithObjects:@"replayGainAlbumGain", @"replayGainAlbumPeak", @"replayGainTrackGain", @"replayGainTrackPeak", @"volume", nil];
|
2022-01-22 07:49:07 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
+ (NSSet *)keyPathsForValuesAffectingGainInfo {
|
|
|
|
return [NSSet setWithObjects:@"replayGainAlbumGain", @"replayGainAlbumPeak", @"replayGainTrackGain", @"replayGainTrackPeak", @"volume", nil];
|
2022-01-23 04:44:06 +00:00
|
|
|
}
|
|
|
|
|
2022-06-17 00:05:52 +00:00
|
|
|
+ (NSSet *)keyPathsForValuesAffectingUnsigned {
|
|
|
|
return [NSSet setWithObject:@"unSigned"];
|
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (NSString *)description {
|
2022-06-16 14:14:33 +00:00
|
|
|
return [NSString stringWithFormat:@"PlaylistEntry %lli:(%@)", self.index, self.url];
|
2008-03-09 00:22:48 +00:00
|
|
|
}
|
|
|
|
|
2008-02-29 21:54:09 +00:00
|
|
|
// Get the URL if the title is blank
|
2022-06-16 14:14:33 +00:00
|
|
|
@dynamic title;
|
2022-02-07 05:49:27 +00:00
|
|
|
- (NSString *)title {
|
2022-06-16 14:14:33 +00:00
|
|
|
if((self.rawTitle == nil || [self.rawTitle isEqualToString:@""]) && self.url) {
|
|
|
|
return [[self.url path] lastPathComponent];
|
2022-02-07 05:49:27 +00:00
|
|
|
}
|
2022-06-16 14:14:33 +00:00
|
|
|
return self.rawTitle;
|
2008-02-29 21:54:09 +00:00
|
|
|
}
|
|
|
|
|
2022-06-16 14:14:33 +00:00
|
|
|
- (void)setTitle:(NSString *)title {
|
|
|
|
self.rawTitle = title;
|
2022-01-20 22:54:42 +00:00
|
|
|
}
|
|
|
|
|
2008-02-29 21:56:01 +00:00
|
|
|
@dynamic display;
|
2022-02-07 05:49:27 +00:00
|
|
|
- (NSString *)display {
|
|
|
|
if((self.artist == NULL) || ([self.artist isEqualToString:@""]))
|
2008-02-29 21:56:01 +00:00
|
|
|
return self.title;
|
|
|
|
else {
|
|
|
|
return [NSString stringWithFormat:@"%@ - %@", self.artist, self.title];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-16 14:18:28 +00:00
|
|
|
@dynamic indexedSpam;
|
|
|
|
- (NSString *)indexedSpam {
|
|
|
|
return [NSString stringWithFormat:@"%llu. %@", self.index, self.spam];
|
|
|
|
}
|
|
|
|
|
2013-10-04 11:16:09 +00:00
|
|
|
@dynamic spam;
|
2022-02-07 05:49:27 +00:00
|
|
|
- (NSString *)spam {
|
|
|
|
BOOL hasBitrate = (self.bitrate != 0);
|
|
|
|
BOOL hasArtist = (self.artist != nil) && (![self.artist isEqualToString:@""]);
|
|
|
|
BOOL hasAlbumArtist = (self.albumartist != nil) && (![self.albumartist isEqualToString:@""]);
|
2022-02-26 09:10:27 +00:00
|
|
|
BOOL hasTrackArtist = (hasArtist && hasAlbumArtist) && (![self.albumartist isEqualToString:self.artist]);
|
2022-02-07 05:49:27 +00:00
|
|
|
BOOL hasAlbum = (self.album != nil) && (![self.album isEqualToString:@""]);
|
2022-06-16 14:14:33 +00:00
|
|
|
BOOL hasTrack = (self.track != 0);
|
2022-02-07 05:49:27 +00:00
|
|
|
BOOL hasLength = (self.totalFrames != 0);
|
|
|
|
BOOL hasCurrentPosition = (self.currentPosition != 0) && (self.current);
|
|
|
|
BOOL hasExtension = NO;
|
2022-06-16 14:14:33 +00:00
|
|
|
BOOL hasTitle = (self.rawTitle != nil) && (![self.rawTitle isEqualToString:@""]);
|
2022-02-07 05:49:27 +00:00
|
|
|
BOOL hasCodec = (self.codec != nil) && (![self.codec isEqualToString:@""]);
|
|
|
|
|
2022-06-16 14:14:33 +00:00
|
|
|
NSMutableString *filename = [NSMutableString stringWithString:self.filename];
|
2022-02-07 05:49:27 +00:00
|
|
|
NSRange dotPosition = [filename rangeOfString:@"." options:NSBackwardsSearch];
|
|
|
|
NSString *extension = nil;
|
|
|
|
|
|
|
|
if(dotPosition.length > 0) {
|
|
|
|
dotPosition.location++;
|
|
|
|
dotPosition.length = [filename length] - dotPosition.location;
|
|
|
|
extension = [filename substringWithRange:dotPosition];
|
|
|
|
dotPosition.location--;
|
|
|
|
dotPosition.length++;
|
|
|
|
[filename deleteCharactersInRange:dotPosition];
|
|
|
|
hasExtension = YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
NSMutableArray *elements = [NSMutableArray array];
|
|
|
|
|
|
|
|
if(hasExtension) {
|
|
|
|
[elements addObject:@"["];
|
|
|
|
if(hasCodec) {
|
|
|
|
[elements addObject:self.codec];
|
|
|
|
} else {
|
|
|
|
[elements addObject:[extension uppercaseString]];
|
|
|
|
}
|
|
|
|
if(hasBitrate) {
|
|
|
|
[elements addObject:@"@"];
|
|
|
|
[elements addObject:[NSString stringWithFormat:@"%u", self.bitrate]];
|
|
|
|
[elements addObject:@"kbps"];
|
|
|
|
}
|
|
|
|
[elements addObject:@"] "];
|
|
|
|
}
|
|
|
|
|
|
|
|
if(hasArtist) {
|
|
|
|
if(hasAlbumArtist) {
|
|
|
|
[elements addObject:self.albumartist];
|
|
|
|
} else {
|
|
|
|
[elements addObject:self.artist];
|
|
|
|
}
|
|
|
|
[elements addObject:@" - "];
|
|
|
|
}
|
|
|
|
|
|
|
|
if(hasAlbum) {
|
|
|
|
[elements addObject:@"["];
|
|
|
|
[elements addObject:self.album];
|
|
|
|
if(hasTrack) {
|
|
|
|
[elements addObject:@" #"];
|
|
|
|
[elements addObject:self.trackText];
|
|
|
|
}
|
|
|
|
[elements addObject:@"] "];
|
|
|
|
}
|
|
|
|
|
|
|
|
if(hasTitle) {
|
2022-06-16 14:14:33 +00:00
|
|
|
[elements addObject:self.rawTitle];
|
2022-02-07 05:49:27 +00:00
|
|
|
} else {
|
|
|
|
[elements addObject:filename];
|
|
|
|
}
|
|
|
|
|
2022-02-26 09:10:27 +00:00
|
|
|
if(hasTrackArtist) {
|
2022-02-07 05:49:27 +00:00
|
|
|
[elements addObject:@" // "];
|
|
|
|
[elements addObject:self.artist];
|
|
|
|
}
|
|
|
|
|
|
|
|
if(hasCurrentPosition || hasLength) {
|
|
|
|
SecondsFormatter *secondsFormatter = [[SecondsFormatter alloc] init];
|
|
|
|
[elements addObject:@" ("];
|
|
|
|
if(hasCurrentPosition) {
|
2022-06-17 13:39:02 +00:00
|
|
|
[elements addObject:[secondsFormatter stringForObjectValue:@(self.currentPosition)]];
|
2022-02-07 05:49:27 +00:00
|
|
|
}
|
|
|
|
if(hasLength) {
|
|
|
|
if(hasCurrentPosition) {
|
|
|
|
[elements addObject:@" / "];
|
|
|
|
}
|
|
|
|
[elements addObject:[secondsFormatter stringForObjectValue:[self length]]];
|
|
|
|
}
|
|
|
|
[elements addObject:@")"];
|
|
|
|
}
|
|
|
|
|
|
|
|
return [elements componentsJoinedByString:@""];
|
2013-10-04 11:16:09 +00:00
|
|
|
}
|
|
|
|
|
2022-01-22 05:49:17 +00:00
|
|
|
@dynamic trackText;
|
2022-02-07 05:49:27 +00:00
|
|
|
- (NSString *)trackText {
|
2022-06-16 14:14:33 +00:00
|
|
|
if(self.track != 0) {
|
|
|
|
if(self.disc != 0) {
|
|
|
|
return [NSString stringWithFormat:@"%u.%02u", self.disc, self.track];
|
2022-02-07 05:49:27 +00:00
|
|
|
} else {
|
2022-06-16 14:14:33 +00:00
|
|
|
return [NSString stringWithFormat:@"%02u", self.track];
|
2022-02-07 05:49:27 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return @"";
|
|
|
|
}
|
2022-01-22 05:49:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@dynamic yearText;
|
2022-02-07 05:49:27 +00:00
|
|
|
- (NSString *)yearText {
|
2022-06-16 14:14:33 +00:00
|
|
|
if(self.year != 0) {
|
|
|
|
return [NSString stringWithFormat:@"%u", self.year];
|
2022-02-07 05:49:27 +00:00
|
|
|
} else {
|
|
|
|
return @"";
|
|
|
|
}
|
2022-01-22 05:49:17 +00:00
|
|
|
}
|
|
|
|
|
2022-01-22 07:19:32 +00:00
|
|
|
@dynamic cuesheetPresent;
|
2022-02-07 05:49:27 +00:00
|
|
|
- (NSString *)cuesheetPresent {
|
2022-06-16 14:14:33 +00:00
|
|
|
if(self.cuesheet && [self.cuesheet length]) {
|
2022-02-07 05:49:27 +00:00
|
|
|
return @"yes";
|
|
|
|
} else {
|
|
|
|
return @"no";
|
|
|
|
}
|
2022-01-22 07:19:32 +00:00
|
|
|
}
|
|
|
|
|
2022-01-22 07:49:07 +00:00
|
|
|
@dynamic gainCorrection;
|
2022-02-07 05:49:27 +00:00
|
|
|
- (NSString *)gainCorrection {
|
2022-06-16 14:14:33 +00:00
|
|
|
if(self.replayGainAlbumGain) {
|
|
|
|
if(self.replayGainAlbumPeak)
|
2022-06-19 06:45:18 +00:00
|
|
|
return NSLocalizedStringFromTableInBundle(@"GainAlbumGainPeak", nil, [NSBundle bundleForClass:[self class]], @"");
|
2022-02-07 05:49:27 +00:00
|
|
|
else
|
2022-06-19 06:45:18 +00:00
|
|
|
return NSLocalizedStringFromTableInBundle(@"GainAlbumGain", nil, [NSBundle bundleForClass:[self class]], @"");
|
2022-06-16 14:14:33 +00:00
|
|
|
} else if(self.replayGainTrackGain) {
|
|
|
|
if(self.replayGainTrackPeak)
|
2022-06-19 06:45:18 +00:00
|
|
|
return NSLocalizedStringFromTableInBundle(@"GainTrackGainPeak", nil, [NSBundle bundleForClass:[self class]], @"");
|
2022-02-07 05:49:27 +00:00
|
|
|
else
|
2022-06-19 06:45:18 +00:00
|
|
|
return NSLocalizedStringFromTableInBundle(@"GainTrackGain", nil, [NSBundle bundleForClass:[self class]], @"");
|
2022-06-16 14:14:33 +00:00
|
|
|
} else if(self.volume && self.volume != 1.0) {
|
2022-06-19 06:45:18 +00:00
|
|
|
return NSLocalizedStringFromTableInBundle(@"GainVolumeScale", nil, [NSBundle bundleForClass:[self class]], @"");
|
2022-02-07 05:49:27 +00:00
|
|
|
} else {
|
2022-06-19 06:45:18 +00:00
|
|
|
return NSLocalizedStringFromTableInBundle(@"GainNone", nil, [NSBundle bundleForClass:[self class]], @"");
|
2022-02-07 05:49:27 +00:00
|
|
|
}
|
2022-01-22 07:49:07 +00:00
|
|
|
}
|
|
|
|
|
2022-01-23 04:44:06 +00:00
|
|
|
@dynamic gainInfo;
|
2022-02-07 05:49:27 +00:00
|
|
|
- (NSString *)gainInfo {
|
|
|
|
NSMutableArray *gainItems = [[NSMutableArray alloc] init];
|
2022-06-16 14:14:33 +00:00
|
|
|
if(self.replayGainAlbumGain) {
|
2022-06-19 06:45:18 +00:00
|
|
|
[gainItems addObject:[NSString stringWithFormat:@"%@: %+.2f dB", NSLocalizedStringFromTableInBundle(@"GainAlbumGain", nil, [NSBundle bundleForClass:[self class]], @""), self.replayGainAlbumGain]];
|
2022-02-07 05:49:27 +00:00
|
|
|
}
|
2022-06-16 14:14:33 +00:00
|
|
|
if(self.replayGainAlbumPeak) {
|
2022-06-19 06:45:18 +00:00
|
|
|
[gainItems addObject:[NSString stringWithFormat:@"%@: %.6f", NSLocalizedStringFromTableInBundle(@"GainAlbumPeak", nil, [NSBundle bundleForClass:[self class]], @""), self.replayGainAlbumPeak]];
|
2022-02-07 05:49:27 +00:00
|
|
|
}
|
2022-06-16 14:14:33 +00:00
|
|
|
if(self.replayGainTrackGain) {
|
2022-06-19 06:45:18 +00:00
|
|
|
[gainItems addObject:[NSString stringWithFormat:@"%@: %+.2f dB", NSLocalizedStringFromTableInBundle(@"GainTrackGain", nil, [NSBundle bundleForClass:[self class]], @""), self.replayGainTrackGain]];
|
2022-02-07 05:49:27 +00:00
|
|
|
}
|
2022-06-16 14:14:33 +00:00
|
|
|
if(self.replayGainTrackPeak) {
|
2022-06-19 06:45:18 +00:00
|
|
|
[gainItems addObject:[NSString stringWithFormat:@"%@: %.6f", NSLocalizedStringFromTableInBundle(@"GainTrackPeak", nil, [NSBundle bundleForClass:[self class]], @""), self.replayGainTrackPeak]];
|
2022-02-07 05:49:27 +00:00
|
|
|
}
|
2022-06-16 14:14:33 +00:00
|
|
|
if(self.volume && self.volume != 1) {
|
2022-06-19 06:45:18 +00:00
|
|
|
[gainItems addObject:[NSString stringWithFormat:@"%@: %.2f%C", NSLocalizedStringFromTableInBundle(@"GainVolumeScale", nil, [NSBundle bundleForClass:[self class]], @""), self.volume, (unichar)0x00D7]];
|
2022-02-07 05:49:27 +00:00
|
|
|
}
|
|
|
|
return [gainItems componentsJoinedByString:@"\n"];
|
2022-01-23 04:44:06 +00:00
|
|
|
}
|
|
|
|
|
2014-12-04 06:13:27 +00:00
|
|
|
@dynamic positionText;
|
2022-02-07 05:49:27 +00:00
|
|
|
- (NSString *)positionText {
|
|
|
|
SecondsFormatter *secondsFormatter = [[SecondsFormatter alloc] init];
|
2022-06-17 13:39:02 +00:00
|
|
|
NSString *time = [secondsFormatter stringForObjectValue:@(self.currentPosition)];
|
2022-02-07 05:49:27 +00:00
|
|
|
return time;
|
2014-12-04 06:13:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@dynamic lengthText;
|
2022-02-07 05:49:27 +00:00
|
|
|
- (NSString *)lengthText {
|
|
|
|
SecondsFormatter *secondsFormatter = [[SecondsFormatter alloc] init];
|
2022-06-16 14:14:33 +00:00
|
|
|
NSString *time = [secondsFormatter stringForObjectValue:self.length];
|
2022-02-07 05:49:27 +00:00
|
|
|
return time;
|
2014-12-04 06:13:27 +00:00
|
|
|
}
|
|
|
|
|
2013-10-09 20:53:13 +00:00
|
|
|
@dynamic albumArt;
|
2022-02-07 05:49:27 +00:00
|
|
|
- (NSImage *)albumArt {
|
2022-06-16 14:14:33 +00:00
|
|
|
if(!self.albumArtInternal || ![self.albumArtInternal length]) return nil;
|
2022-02-07 05:49:27 +00:00
|
|
|
|
2022-06-16 14:14:33 +00:00
|
|
|
NSString *imageCacheTag = self.artHash;
|
2022-02-07 05:49:27 +00:00
|
|
|
NSImage *image = [NSImage imageNamed:imageCacheTag];
|
|
|
|
|
|
|
|
if(image == nil) {
|
2022-06-16 14:14:33 +00:00
|
|
|
if([AVIFDecoder isAVIFFormatForData:self.albumArtInternal]) {
|
|
|
|
CGImageRef imageRef = [AVIFDecoder createAVIFImageWithData:self.albumArtInternal];
|
2022-02-16 09:52:51 +00:00
|
|
|
if(imageRef) {
|
|
|
|
image = [[NSImage alloc] initWithCGImage:imageRef size:NSZeroSize];
|
|
|
|
CFRelease(imageRef);
|
|
|
|
}
|
|
|
|
} else {
|
2022-06-16 14:14:33 +00:00
|
|
|
image = [[NSImage alloc] initWithData:self.albumArtInternal];
|
2022-02-16 09:52:51 +00:00
|
|
|
}
|
2022-02-07 05:49:27 +00:00
|
|
|
[image setName:imageCacheTag];
|
|
|
|
}
|
|
|
|
|
|
|
|
return image;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setAlbumArt:(id)data {
|
|
|
|
if([data isKindOfClass:[NSData class]]) {
|
|
|
|
[self setAlbumArtInternal:data];
|
|
|
|
}
|
2013-10-09 20:53:13 +00:00
|
|
|
}
|
|
|
|
|
2022-06-16 14:14:33 +00:00
|
|
|
@dynamic albumArtInternal;
|
|
|
|
- (NSData *)albumArtInternal {
|
|
|
|
NSString *imageCacheTag = self.artHash;
|
2022-06-21 07:01:07 +00:00
|
|
|
return [kArtworkDictionary objectForKey:imageCacheTag].artData;
|
2022-06-16 14:14:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setAlbumArtInternal:(NSData *)albumArtInternal {
|
|
|
|
if(!albumArtInternal || [albumArtInternal length] == 0) return;
|
|
|
|
|
|
|
|
NSString *imageCacheTag = [SHA256Digest digestDataAsString:albumArtInternal];
|
|
|
|
|
|
|
|
self.artHash = imageCacheTag;
|
|
|
|
|
2022-06-21 07:01:07 +00:00
|
|
|
if(![kArtworkDictionary objectForKey:imageCacheTag]) {
|
|
|
|
AlbumArtwork *art = [NSEntityDescription insertNewObjectForEntityForName:@"AlbumArtwork" inManagedObjectContext:kPersistentContainer.viewContext];
|
2022-06-16 14:14:33 +00:00
|
|
|
art.artHash = imageCacheTag;
|
|
|
|
art.artData = albumArtInternal;
|
|
|
|
|
2022-06-21 07:01:07 +00:00
|
|
|
[kArtworkDictionary setObject:art forKey:imageCacheTag];
|
2022-06-16 14:14:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-29 20:09:59 +00:00
|
|
|
@dynamic length;
|
2022-02-07 05:49:27 +00:00
|
|
|
- (NSNumber *)length {
|
2022-06-17 13:39:02 +00:00
|
|
|
return (self.metadataLoaded) ? @(((double)self.totalFrames / self.sampleRate)) : @(0.0);
|
2008-02-20 00:44:40 +00:00
|
|
|
}
|
|
|
|
|
2022-06-16 14:14:33 +00:00
|
|
|
NSURL *_Nullable urlForPath(NSString *_Nullable path) {
|
|
|
|
if(!path || ![path length]) {
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
NSRange protocolRange = [path rangeOfString:@"://"];
|
|
|
|
if(protocolRange.location != NSNotFound) {
|
|
|
|
return [NSURL URLWithString:path];
|
|
|
|
}
|
|
|
|
|
|
|
|
NSMutableString *unixPath = [path mutableCopy];
|
|
|
|
|
|
|
|
// Get the fragment
|
|
|
|
NSString *fragment = @"";
|
|
|
|
NSScanner *scanner = [NSScanner scannerWithString:unixPath];
|
|
|
|
NSCharacterSet *characterSet = [NSCharacterSet characterSetWithCharactersInString:@"#1234567890"];
|
|
|
|
while(![scanner isAtEnd]) {
|
|
|
|
NSString *possibleFragment;
|
|
|
|
[scanner scanUpToString:@"#" intoString:nil];
|
|
|
|
|
|
|
|
if([scanner scanCharactersFromSet:characterSet intoString:&possibleFragment] && [scanner isAtEnd]) {
|
|
|
|
fragment = possibleFragment;
|
|
|
|
[unixPath deleteCharactersInRange:NSMakeRange([scanner scanLocation] - [possibleFragment length], [possibleFragment length])];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Append the fragment
|
|
|
|
NSURL *url = [NSURL URLWithString:[[[NSURL fileURLWithPath:unixPath] absoluteString] stringByAppendingString:fragment]];
|
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
|
|
|
@dynamic url;
|
|
|
|
- (NSURL *)url {
|
|
|
|
return urlForPath(self.urlString);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setUrl:(NSURL *)url {
|
|
|
|
self.urlString = url ? [url absoluteString] : nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
@dynamic trashUrl;
|
|
|
|
- (NSURL *)trashUrl {
|
|
|
|
return urlForPath(self.trashUrlString);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setTrashUrl:(NSURL *)trashUrl {
|
|
|
|
self.trashUrlString = trashUrl ? [trashUrl absoluteString] : nil;
|
|
|
|
}
|
|
|
|
|
2008-02-29 20:09:59 +00:00
|
|
|
@dynamic path;
|
2022-02-07 05:49:27 +00:00
|
|
|
- (NSString *)path {
|
2022-06-16 14:14:33 +00:00
|
|
|
if([self.url isFileURL])
|
|
|
|
return [[self.url path] stringByAbbreviatingWithTildeInPath];
|
2022-02-07 05:49:27 +00:00
|
|
|
else
|
2022-06-16 14:14:33 +00:00
|
|
|
return [self.url absoluteString];
|
2008-02-20 00:44:40 +00:00
|
|
|
}
|
|
|
|
|
2008-02-29 20:09:59 +00:00
|
|
|
@dynamic filename;
|
2022-02-07 05:49:27 +00:00
|
|
|
- (NSString *)filename {
|
2022-06-16 14:14:33 +00:00
|
|
|
return [[self.url path] lastPathComponent];
|
2007-11-24 20:16:27 +00:00
|
|
|
}
|
|
|
|
|
2022-06-26 11:37:41 +00:00
|
|
|
@dynamic filenameFragment;
|
|
|
|
- (NSString *)filenameFragment {
|
|
|
|
if([self.url fragment]) {
|
|
|
|
return [[[self.url path] lastPathComponent] stringByAppendingFormat:@"#%@", [self.url fragment]];
|
|
|
|
} else {
|
|
|
|
return self.filename;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-01 03:29:21 +00:00
|
|
|
@dynamic status;
|
2022-02-07 05:49:27 +00:00
|
|
|
- (NSString *)status {
|
|
|
|
if(self.stopAfter) {
|
2008-03-01 03:29:21 +00:00
|
|
|
return @"stopAfter";
|
2022-02-07 05:49:27 +00:00
|
|
|
} else if(self.current) {
|
2008-03-01 03:29:21 +00:00
|
|
|
return @"playing";
|
2022-02-07 05:49:27 +00:00
|
|
|
} else if(self.queued) {
|
2008-03-01 03:29:21 +00:00
|
|
|
return @"queued";
|
2022-02-07 05:49:27 +00:00
|
|
|
} else if(self.error) {
|
2008-03-01 03:29:21 +00:00
|
|
|
return @"error";
|
|
|
|
}
|
2022-02-07 05:49:27 +00:00
|
|
|
|
2008-03-01 03:29:21 +00:00
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
@dynamic statusMessage;
|
2022-02-07 05:49:27 +00:00
|
|
|
- (NSString *)statusMessage {
|
|
|
|
if(self.stopAfter) {
|
2008-03-01 03:29:21 +00:00
|
|
|
return @"Stopping once finished...";
|
2022-02-07 05:49:27 +00:00
|
|
|
} else if(self.current) {
|
2008-03-01 03:29:21 +00:00
|
|
|
return @"Playing...";
|
2022-02-07 05:49:27 +00:00
|
|
|
} else if(self.queued) {
|
2022-06-16 14:14:33 +00:00
|
|
|
return [NSString stringWithFormat:@"Queued: %lli", self.queuePosition + 1];
|
2022-02-07 05:49:27 +00:00
|
|
|
} else if(self.error) {
|
2022-06-16 14:14:33 +00:00
|
|
|
return self.errorMessage;
|
2008-03-01 03:29:21 +00:00
|
|
|
}
|
2022-02-07 05:49:27 +00:00
|
|
|
|
2008-03-01 03:29:21 +00:00
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2022-06-17 00:05:52 +00:00
|
|
|
// Gotta love that requirement of Core Data that everything starts with a lower case letter
|
|
|
|
@dynamic Unsigned;
|
|
|
|
- (BOOL)Unsigned {
|
|
|
|
return self.unSigned;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setUnsigned:(BOOL)Unsigned {
|
|
|
|
self.unSigned = Unsigned;
|
|
|
|
}
|
|
|
|
|
2022-06-17 00:43:48 +00:00
|
|
|
// More of the same
|
|
|
|
@dynamic URL;
|
|
|
|
- (NSURL *)URL {
|
|
|
|
return self.url;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setURL:(NSURL *)URL {
|
|
|
|
self.url = URL;
|
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (void)setMetadata:(NSDictionary *)metadata {
|
|
|
|
if(metadata == nil) {
|
|
|
|
self.error = YES;
|
2022-06-18 23:16:43 +00:00
|
|
|
self.errorMessage = NSLocalizedStringFromTableInBundle(@"ErrorMetadata", nil, [NSBundle bundleForClass:[self class]], @"");
|
2022-02-07 05:49:27 +00:00
|
|
|
} else {
|
2022-06-17 06:31:34 +00:00
|
|
|
self.volume = 1;
|
2009-03-06 04:46:42 +00:00
|
|
|
[self setValuesForKeysWithDictionary:metadata];
|
2022-02-07 05:49:27 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 11:03:39 +00:00
|
|
|
[self setMetadataLoaded:YES];
|
2009-03-06 04:46:42 +00:00
|
|
|
}
|
|
|
|
|
2022-06-19 06:00:08 +00:00
|
|
|
@dynamic playCountItem;
|
|
|
|
- (PlayCount *)playCountItem {
|
|
|
|
NSPredicate *albumPredicate = [NSPredicate predicateWithFormat:@"album == %@", self.album];
|
|
|
|
NSPredicate *artistPredicate = [NSPredicate predicateWithFormat:@"artist == %@", self.artist];
|
|
|
|
NSPredicate *titlePredicate = [NSPredicate predicateWithFormat:@"title == %@", self.title];
|
|
|
|
|
|
|
|
NSCompoundPredicate *predicate = [NSCompoundPredicate andPredicateWithSubpredicates:@[albumPredicate, artistPredicate, titlePredicate]];
|
|
|
|
|
|
|
|
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"PlayCount"];
|
|
|
|
request.predicate = predicate;
|
|
|
|
|
|
|
|
NSError *error = nil;
|
2022-06-21 07:01:07 +00:00
|
|
|
NSArray *results = [kPersistentContainer.viewContext executeFetchRequest:request error:&error];
|
2022-06-19 06:00:08 +00:00
|
|
|
|
|
|
|
if(!results || [results count] < 1) {
|
2022-06-26 11:37:41 +00:00
|
|
|
NSPredicate *filenamePredicate = [NSPredicate predicateWithFormat:@"filename == %@", self.filenameFragment];
|
2022-06-19 06:00:08 +00:00
|
|
|
|
|
|
|
request = [NSFetchRequest fetchRequestWithEntityName:@"PlayCount"];
|
|
|
|
request.predicate = filenamePredicate;
|
|
|
|
|
2022-06-21 07:01:07 +00:00
|
|
|
results = [kPersistentContainer.viewContext executeFetchRequest:request error:&error];
|
2022-06-19 06:00:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(!results || [results count] < 1) return nil;
|
|
|
|
|
|
|
|
return results[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
@dynamic playCount;
|
|
|
|
- (NSString *)playCount {
|
|
|
|
PlayCount *pc = self.playCountItem;
|
|
|
|
if(pc)
|
|
|
|
return [NSString stringWithFormat:@"%llu", pc.count];
|
|
|
|
else
|
|
|
|
return @"0";
|
|
|
|
}
|
|
|
|
|
|
|
|
@dynamic playCountInfo;
|
|
|
|
- (NSString *)playCountInfo {
|
|
|
|
PlayCount *pc = self.playCountItem;
|
|
|
|
if(pc) {
|
|
|
|
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
|
|
|
|
dateFormatter.dateStyle = NSDateFormatterMediumStyle;
|
|
|
|
dateFormatter.timeStyle = NSDateFormatterShortStyle;
|
|
|
|
|
|
|
|
if(pc.count) {
|
2022-06-19 06:44:29 +00:00
|
|
|
return [NSString stringWithFormat:@"%@: %@\n%@: %@", NSLocalizedStringFromTableInBundle(@"TimeFirstSeen", nil, [NSBundle bundleForClass:[self class]], @""), [dateFormatter stringFromDate:pc.firstSeen], NSLocalizedStringFromTableInBundle(@"TimeLastPlayed", nil, [NSBundle bundleForClass:[self class]], @""), [dateFormatter stringFromDate:pc.lastPlayed]];
|
2022-06-19 06:00:08 +00:00
|
|
|
} else {
|
|
|
|
return [NSString stringWithFormat:@"%@: %@", NSLocalizedStringFromTableInBundle(@"TimeFirstSeen", nil, [NSBundle bundleForClass:[self class]], @""), [dateFormatter stringFromDate:pc.firstSeen]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return @"";
|
|
|
|
}
|
|
|
|
|
2022-06-28 08:55:30 +00:00
|
|
|
@dynamic rating;
|
|
|
|
- (float)rating {
|
|
|
|
PlayCount *pc = self.playCountItem;
|
|
|
|
if(pc) {
|
|
|
|
return pc.rating;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-02 18:16:43 +00:00
|
|
|
@end
|