Commit 9283b799 authored by Felix Paul Kühne's avatar Felix Paul Kühne

Thumbnail cache: expand internal API so we can also ask for artwork based on...

Thumbnail cache: expand internal API so we can also ask for artwork based on meta data in addition to MLFiles
parent 2b600629
......@@ -17,4 +17,6 @@
+ (UIImage *)thumbnailForMediaFile:(MLFile *)mediaFile;
+ (UIImage *)thumbnailForMediaItemWithTitle:(NSString *)title Artist:(NSString*)artist andAlbumName:(NSString*)albumname;
@end
......@@ -43,31 +43,42 @@ static NSCache *_thumbnailCache;
return [NSString stringWithString:output];
}
+ (NSString *)_getArtworkPathFromMedia:(MLFile *)file
+ (UIImage *)thumbnailForMediaItemWithTitle:(NSString *)title Artist:(NSString*)artist andAlbumName:(NSString*)albumname
{
NSString *artworkURL, *artist, *album, *title;
if (file.isAlbumTrack) {
artist = file.albumTrack.artist;
album = file.albumTrack.album.name;
}
title = file.title;
return [UIImage imageWithContentsOfFile:[self artworkPathForMediaItemWithTitle:title Artist:artist andAlbumName:albumname]];
}
+ (NSString *)artworkPathForMediaItemWithTitle:(NSString *)title Artist:(NSString*)artist andAlbumName:(NSString*)albumname
{
NSString *artworkURL;
NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *cacheDir = searchPaths[0];
cacheDir = [cacheDir stringByAppendingFormat:@"/%@", [[NSBundle mainBundle] bundleIdentifier]];
if (artist.length == 0 || album.length == 0) {
if (artist.length == 0 || albumname.length == 0) {
/* Use generated hash to find art */
artworkURL = [cacheDir stringByAppendingFormat:@"/art/arturl/%@/art.jpg", [self _md5FromString:title]];
} else {
/* Otherwise, it was cached by artist and album */
artworkURL = [cacheDir stringByAppendingFormat:@"/art/artistalbum/%@/%@/art.jpg", artist, album];
artworkURL = [cacheDir stringByAppendingFormat:@"/art/artistalbum/%@/%@/art.jpg", artist, albumname];
}
return artworkURL;
}
+ (NSString *)_getArtworkPathFromMedia:(MLFile *)file
{
NSString *artist, *album, *title;
if (file.isAlbumTrack) {
artist = file.albumTrack.artist;
album = file.albumTrack.album.name;
}
title = file.title;
return [self artworkPathForMediaItemWithTitle:title Artist:artist andAlbumName:album];
}
+ (UIImage *)thumbnailForMediaFile:(MLFile *)mediaFile
{
if (mediaFile == nil || mediaFile.objectID == nil)
......
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