diff --git a/extras/package/macosx/VLC.xcodeproj/project.pbxproj b/extras/package/macosx/VLC.xcodeproj/project.pbxproj index 38aa696d996e46349108bb8d9dac310c19fa6285..3cd37876924d9a19c0947f2c92eb4ae92dbe0550 100644 --- a/extras/package/macosx/VLC.xcodeproj/project.pbxproj +++ b/extras/package/macosx/VLC.xcodeproj/project.pbxproj @@ -161,6 +161,7 @@ 7DB7F20920CC07FD00C2CAED /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7DB7F20820CC07FD00C2CAED /* WebKit.framework */; }; 7DB7F20B20CC082800C2CAED /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7DB7F20A20CC082800C2CAED /* QuartzCore.framework */; }; 7DBB7639227F3FBC002649E1 /* VLCLibraryCollectionViewSupplementaryElementView.m in Sources */ = {isa = PBXBuildFile; fileRef = 7DBB7638227F3FBC002649E1 /* VLCLibraryCollectionViewSupplementaryElementView.m */; }; + 7DBFDD4723DE1FBB00722E3D /* VLCPlaylistImageCache.m in Sources */ = {isa = PBXBuildFile; fileRef = 7DBFDD4623DE1FBB00722E3D /* VLCPlaylistImageCache.m */; }; 7DC21A7422049A6600F98A02 /* VLCOpenInputMetadata.m in Sources */ = {isa = PBXBuildFile; fileRef = 7DC21A7322049A6600F98A02 /* VLCOpenInputMetadata.m */; }; 7DD2F5C52081B73B007EE187 /* VLCRemoteControlService.m in Sources */ = {isa = PBXBuildFile; fileRef = 7DD2F5C42081B73B007EE187 /* VLCRemoteControlService.m */; }; 7DE2F0442282C84A0040DD0A /* VLCLibraryAudioDataSource.m in Sources */ = {isa = PBXBuildFile; fileRef = 7DE2F0432282C84A0040DD0A /* VLCLibraryAudioDataSource.m */; }; @@ -572,6 +573,8 @@ 7DBB06631CC2314D004C74D2 /* caopengllayer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = caopengllayer.m; path = ../../../modules/video_output/caopengllayer.m; sourceTree = "<group>"; }; 7DBB7637227F3FBC002649E1 /* VLCLibraryCollectionViewSupplementaryElementView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VLCLibraryCollectionViewSupplementaryElementView.h; sourceTree = "<group>"; }; 7DBB7638227F3FBC002649E1 /* VLCLibraryCollectionViewSupplementaryElementView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = VLCLibraryCollectionViewSupplementaryElementView.m; sourceTree = "<group>"; }; + 7DBFDD4523DE1FBB00722E3D /* VLCPlaylistImageCache.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VLCPlaylistImageCache.h; sourceTree = "<group>"; }; + 7DBFDD4623DE1FBB00722E3D /* VLCPlaylistImageCache.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = VLCPlaylistImageCache.m; sourceTree = "<group>"; }; 7DC21A7222049A6600F98A02 /* VLCOpenInputMetadata.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VLCOpenInputMetadata.h; sourceTree = "<group>"; }; 7DC21A7322049A6600F98A02 /* VLCOpenInputMetadata.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = VLCOpenInputMetadata.m; sourceTree = "<group>"; }; 7DD2F5C32081B73B007EE187 /* VLCRemoteControlService.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VLCRemoteControlService.h; sourceTree = "<group>"; }; @@ -1086,6 +1089,8 @@ 7D0F640B2202163E00FDB91F /* VLCPlaylistDataSource.m */, 7D445D822202524D00263D34 /* VLCPlaylistItem.h */, 7D445D832202524D00263D34 /* VLCPlaylistItem.m */, + 7DBFDD4523DE1FBB00722E3D /* VLCPlaylistImageCache.h */, + 7DBFDD4623DE1FBB00722E3D /* VLCPlaylistImageCache.m */, 7D445D8C2203375100263D34 /* VLCPlaylistMenuController.h */, 7D445D8D2203375100263D34 /* VLCPlaylistMenuController.m */, 7D1BF28B22A192000027C50F /* VLCPlaylistSortingMenuController.h */, @@ -1757,6 +1762,7 @@ 7DFBDCB7226CDFD600B700A5 /* VLCImageView.m in Sources */, 7D404ABF2281892C00B28EF4 /* NSView+VLCAdditions.m in Sources */, 7DE9C7DD220728420089108F /* VLCPlayerController.m in Sources */, + 7DBFDD4723DE1FBB00722E3D /* VLCPlaylistImageCache.m in Sources */, 7D93D8FC2316C2DC001C0063 /* VLCCustomCropArWindowController.m in Sources */, 1C3113941E508C6900D4DD76 /* VLCAddonsWindowController.m in Sources */, 7D92AF2123DDCA8D00D81EA3 /* VLCLibraryImageCache.m in Sources */, diff --git a/modules/gui/macosx/Makefile.am b/modules/gui/macosx/Makefile.am index f273ccb7cf286882ba073337bbec63b78eabb6ee..2b665a04a6c53ba88568a7c92b099c53d309b6ea 100644 --- a/modules/gui/macosx/Makefile.am +++ b/modules/gui/macosx/Makefile.am @@ -153,6 +153,8 @@ libmacosx_plugin_la_SOURCES = \ gui/macosx/playlist/VLCPlaylistController.m \ gui/macosx/playlist/VLCPlaylistDataSource.h \ gui/macosx/playlist/VLCPlaylistDataSource.m \ + gui/macosx/playlist/VLCPlaylistImageCache.h \ + gui/macosx/playlist/VLCPlaylistImageCache.m \ gui/macosx/playlist/VLCPlaylistItem.h \ gui/macosx/playlist/VLCPlaylistItem.m \ gui/macosx/playlist/VLCPlaylistMenuController.h \ diff --git a/modules/gui/macosx/playlist/VLCPlaylistImageCache.h b/modules/gui/macosx/playlist/VLCPlaylistImageCache.h new file mode 100644 index 0000000000000000000000000000000000000000..cb08ccec732904f7f574ae2927034ca4705b6880 --- /dev/null +++ b/modules/gui/macosx/playlist/VLCPlaylistImageCache.h @@ -0,0 +1,34 @@ +/***************************************************************************** +* VLCPlaylistImageCache.h: MacOS X interface module +***************************************************************************** +* Copyright (C) 2020 VLC authors and VideoLAN +* +* Authors: Felix Paul Kühne <fkuehne # videolan -dot- org> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. +*****************************************************************************/ + +#import <Cocoa/Cocoa.h> +#import <vlc_playlist.h> + +NS_ASSUME_NONNULL_BEGIN + +@interface VLCPlaylistImageCache : NSObject + ++ (nullable NSImage *)artworkForPlaylistItemWithURL:(NSURL *)artworkURL; + +@end + +NS_ASSUME_NONNULL_END diff --git a/modules/gui/macosx/playlist/VLCPlaylistImageCache.m b/modules/gui/macosx/playlist/VLCPlaylistImageCache.m new file mode 100644 index 0000000000000000000000000000000000000000..69404c4ef80401e165aa019ad039de635ede1fa4 --- /dev/null +++ b/modules/gui/macosx/playlist/VLCPlaylistImageCache.m @@ -0,0 +1,82 @@ +/***************************************************************************** +* VLCPlaylistImageCache.m: MacOS X interface module +***************************************************************************** +* Copyright (C) 2020 VLC authors and VideoLAN +* +* Authors: Felix Paul Kühne <fkuehne # videolan -dot- org> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. +*****************************************************************************/ + +#import "VLCPlaylistImageCache.h" +#import "extensions/NSString+Helpers.h" +#import <vlc_input.h> +#import <vlc_url.h> + +NSUInteger kVLCMaximumPlaylistImageCacheSize = 100; + +@interface VLCPlaylistImageCache() +{ + NSCache *_imageCache; +} +@end + +@implementation VLCPlaylistImageCache + +- (instancetype)init +{ + self = [super init]; + if (self) { + _imageCache = [[NSCache alloc] init]; + _imageCache.countLimit = kVLCMaximumPlaylistImageCacheSize; + } + return self; +} + ++ (instancetype)sharedImageCache +{ + static dispatch_once_t onceToken; + static VLCPlaylistImageCache *sharedImageCache; + dispatch_once(&onceToken, ^{ + sharedImageCache = [[VLCPlaylistImageCache alloc] init]; + }); + return sharedImageCache; +} + ++ (NSImage *)artworkForPlaylistItemWithURL:(NSURL *)artworkURL +{ + return [[VLCPlaylistImageCache sharedImageCache] imageForPlaylistItemWithArtworkURL:artworkURL]; +} + +- (NSImage *)imageForPlaylistItemWithArtworkURL:(NSURL *)artworkURL +{ + if (artworkURL == nil) { + return nil; + } + + NSImage *artwork = [_imageCache objectForKey:artworkURL]; + if (artwork) { + return artwork; + } + + artwork = [[NSImage alloc] initWithContentsOfURL:artworkURL]; + if (artwork) { + [_imageCache setObject:artwork forKey:artworkURL]; + } + + return artwork; +} + +@end diff --git a/modules/gui/macosx/playlist/VLCPlaylistItem.h b/modules/gui/macosx/playlist/VLCPlaylistItem.h index 96ff2efb758177808f3150f72672cdfd35f7ea70..227399f7d378614121867ecef0ab0ecf1e3fb443 100644 --- a/modules/gui/macosx/playlist/VLCPlaylistItem.h +++ b/modules/gui/macosx/playlist/VLCPlaylistItem.h @@ -43,7 +43,6 @@ extern NSString *VLCPlaylistItemPasteboardType; @property (readwrite, retain, nullable) NSString *artistName; @property (readwrite, retain, nullable) NSString *albumName; -@property (readwrite, retain, nullable) NSString *artworkURLString; @property (readonly, copy) NSImage *artworkImage; - (instancetype)initWithPlaylistItem:(vlc_playlist_item_t *)p_item; diff --git a/modules/gui/macosx/playlist/VLCPlaylistItem.m b/modules/gui/macosx/playlist/VLCPlaylistItem.m index cf13dca131ff1cfa0ab5a198362d4d760565654b..9f281719cb226db527fb0151093629c776ab2e92 100644 --- a/modules/gui/macosx/playlist/VLCPlaylistItem.m +++ b/modules/gui/macosx/playlist/VLCPlaylistItem.m @@ -25,12 +25,19 @@ #import <vlc_input.h> #import <vlc_url.h> +#import "playlist/VLCPlaylistImageCache.h" #import "extensions/NSString+Helpers.h" #import "library/VLCInputItem.h" #import "library/VLCLibraryDataTypes.h" NSString *VLCPlaylistItemPasteboardType = @"org.videolan.vlc.playlistitemtype"; +@interface VLCPlaylistItem() +{ + NSURL *_artworkURL; +} +@end + @implementation VLCPlaylistItem - (instancetype)initWithPlaylistItem:(vlc_playlist_item_t *)p_item @@ -87,7 +94,11 @@ NSString *VLCPlaylistItemPasteboardType = @"org.videolan.vlc.playlistitemtype"; if (p_media->p_meta) { _artistName = toNSStr(vlc_meta_Get(p_media->p_meta, vlc_meta_Artist)); _albumName = toNSStr(vlc_meta_Get(p_media->p_meta, vlc_meta_Album)); - _artworkURLString = toNSStr(vlc_meta_Get(p_media->p_meta, vlc_meta_ArtworkURL)); + + NSString *artworkURLString = toNSStr(vlc_meta_Get(p_media->p_meta, vlc_meta_ArtworkURL)); + if (artworkURLString.length > 1) { + _artworkURL = [NSURL URLWithString:artworkURLString]; + } } vlc_mutex_unlock(&p_media->lock); } @@ -133,14 +144,10 @@ NSString *VLCPlaylistItemPasteboardType = @"org.videolan.vlc.playlistitemtype"; - (NSImage *)artworkImage { - NSImage *image; - - if (_artworkURLString != nil && _artworkURLString.length > 0) { - image = [[NSImage alloc] initWithContentsOfURL: [NSURL URLWithString:_artworkURLString]]; - } else { + NSImage *image = [VLCPlaylistImageCache artworkForPlaylistItemWithURL:_artworkURL]; + if (!image) { image = [NSImage imageNamed: @"noart.png"]; } - return image; } diff --git a/po/POTFILES.in b/po/POTFILES.in index 21287b2f21a1a073c011cd2db067bc7543d9be3b..5a60e71ebc438e2b7c9cf527d8698a123183e221 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -558,6 +558,8 @@ modules/gui/macosx/playlist/VLCPlaylistController.h modules/gui/macosx/playlist/VLCPlaylistController.m modules/gui/macosx/playlist/VLCPlaylistDataSource.h modules/gui/macosx/playlist/VLCPlaylistDataSource.m +modules/gui/macosx/playlist/VLCPlaylistImageCache.h +modules/gui/macosx/playlist/VLCPlaylistImageCache.m modules/gui/macosx/playlist/VLCPlaylistItem.h modules/gui/macosx/playlist/VLCPlaylistItem.m modules/gui/macosx/playlist/VLCPlaylistMenuController.h