Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CogPlaylist/Sources/PlaylistEntry+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ extension PlaylistEntry {

/// A stored URL string, or a path as older playlists kept it, perhaps
/// with a cue track fragment ("/a/b.flac#01"); nothing is ten seconds of
/// silence.
static func url(forPath path: String?) -> URL? {
/// silence. The loader reads entries' stored strings with it.
@objc(urlForPath:) public static func url(forPath path: String?) -> URL? {
guard let path, !path.isEmpty else { return URL(string: "silence://10") }

if path.contains("://") {
Expand Down
9 changes: 9 additions & 0 deletions CogPlaylist/Tests/PlaylistEntryTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ final class PlaylistEntryTests: XCTestCase {
XCTAssertEqual(makeEntry(url: "/Music/#1 hits.mp3").url?.path, "/Music/#1 hits.mp3")
}

/// The loader reads stored strings through it from Objective-C.
func testURLForPathIsAvailableToObjectiveC() {
let selector = NSSelectorFromString("urlForPath:")
XCTAssertTrue(PlaylistEntry.responds(to: selector))
let url = (PlaylistEntry.self as AnyObject).perform(selector, with: "/Music/a.cue#02")?.takeUnretainedValue() as? URL
XCTAssertEqual(url?.path, "/Music/a.cue")
XCTAssertEqual(url?.fragment, "02")
}

func testNoURLIsSilence() {
XCTAssertEqual(makeEntry(url: nil).url?.absoluteString, "silence://10")
XCTAssertEqual(makeEntry(url: "").url?.absoluteString, "silence://10")
Expand Down
4 changes: 1 addition & 3 deletions Playlist/PlaylistLoader.m
Original file line number Diff line number Diff line change
Expand Up @@ -951,8 +951,6 @@ - (NSArray *)insertURLs:(NSArray *)urls atIndex:(NSInteger)index sort:(BOOL)sort
}
}

NSURL *_Nullable urlForPath(NSString *_Nullable path);

- (void)loadInfoForEntries:(NSArray *)entries {
NSMutableDictionary *queueThisJob = [NSMutableDictionary new];
for(PlaylistEntry *pe in entries) {
Expand Down Expand Up @@ -1046,7 +1044,7 @@ - (void)loadInfoForEntries:(NSArray *)entries {
[blockInputs removeObjectAtIndex:0];
[blockLock unlock];

NSURL *url = urlForPath(key);
NSURL *url = [PlaylistEntry urlForPath:key];

NSString *message = [NSString stringWithFormat:@"Loading metadata for %@", url];
DLog(@"%@", message);
Expand Down
4 changes: 1 addition & 3 deletions Utils/SQLiteStore.m
Original file line number Diff line number Diff line change
Expand Up @@ -507,8 +507,6 @@

const char *query_count_queue = "SELECT COUNT(*) FROM queue";

NSURL *_Nonnull urlForPath(NSString *_Nullable path);

@interface SQLiteStore (Private)
- (NSString *_Nullable)addString:(id _Nullable)string returnId:(int64_t *_Nonnull)stringId;
- (NSString *_Nonnull)getString:(int64_t)stringId;
Expand Down Expand Up @@ -1510,7 +1508,7 @@ - (PlaylistEntry *_Nonnull)getTrack:(int64_t)trackId {
uint64_t discNr = ((uint64_t)trackNr) >> 32;
trackNr &= (1UL << 32) - 1;

entry.url = urlForPath([self getString:urlId]);
entry.url = [PlaylistEntry urlForPath:[self getString:urlId]];

entry.album = [self getString:albumId];
entry.albumartist = [self getString:albumartistId];
Expand Down