[vlc-commits] macosx/input item: expand API with metadata handling

Felix Paul Kühne git at videolan.org
Mon Jul 1 13:09:51 CEST 2019


vlc | branch: master | Felix Paul Kühne <felix at feepk.net> | Mon Jul  1 12:48:42 2019 +0200| [458916d08b9abafd6e8c27bce3ac330be26a4d0f] | committer: Felix Paul Kühne

macosx/input item: expand API with metadata handling

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=458916d08b9abafd6e8c27bce3ac330be26a4d0f
---

 modules/gui/macosx/library/VLCInputItem.h |  32 ++-
 modules/gui/macosx/library/VLCInputItem.m | 401 ++++++++++++++++++++++++++++++
 2 files changed, 432 insertions(+), 1 deletion(-)

diff --git a/modules/gui/macosx/library/VLCInputItem.h b/modules/gui/macosx/library/VLCInputItem.h
index 5b5f1d221c..997bd47de0 100644
--- a/modules/gui/macosx/library/VLCInputItem.h
+++ b/modules/gui/macosx/library/VLCInputItem.h
@@ -31,22 +31,52 @@ NS_ASSUME_NONNULL_BEGIN
 extern NSString *VLCInputItemParsingSucceeded;
 extern NSString *VLCInputItemParsingFailed;
 extern NSString *VLCInputItemSubtreeAdded;
+extern NSString *VLCInputItemPreparsingSkipped;
+extern NSString *VLCInputItemPreparsingFailed;
+extern NSString *VLCInputItemPreparsingTimeOut;
+extern NSString *VLCInputItemPreparsingSucceeded;
 
 @interface VLCInputItem : NSObject
 
 - (instancetype)initWithInputItem:(struct input_item_t *)p_inputItem;
 
 @property (readonly) struct input_item_t *vlcInputItem;
- at property (readonly) NSString *name;
 @property (readonly) NSString *MRL;
+ at property (readonly) NSString *decodedMRL;
+ at property (readwrite) NSString *name;
+ at property (readwrite) NSString *title;
+ at property (readwrite) NSString *artist;
+ at property (readwrite) NSString *albumName;
+ at property (readwrite) NSString *trackNumber;
+ at property (readwrite) NSString *genre;
+ at property (readwrite) NSString *copyright;
+ at property (readwrite) NSString *publisher;
+ at property (readonly) NSString *nowPlaying;
+ at property (readwrite) NSString *language;
+ at property (readwrite) NSString *date;
+ at property (readwrite) NSString *contentDescription;
+ at property (readonly) NSString *encodedBy;
+ at property (readonly) NSString *trackID;
+ at property (readonly) NSString *trackTotal;
+ at property (readwrite) NSString *director;
+ at property (readonly) NSString *season;
+ at property (readonly) NSString *episode;
+ at property (readwrite) NSString *showName;
+ at property (readwrite) NSString *actors;
+ at property (readonly) NSString *discNumber;
+ at property (readonly) NSString *totalNumberOfDiscs;
 @property (readonly) vlc_tick_t duration;
 @property (readonly) enum input_item_type_e inputType;
 @property (readonly) struct input_item_node_t *subTree;
 @property (readonly) NSURL *artworkURL;
+ at property (readonly) BOOL preparsed;
 
 - (void)parseInputItem;
 - (void)cancelParsing;
 
+- (int)preparseInputItem;
+- (int)writeMetadataToFile;
+
 @end
 
 @interface VLCInputNode : NSObject
diff --git a/modules/gui/macosx/library/VLCInputItem.m b/modules/gui/macosx/library/VLCInputItem.m
index 16e512cf70..656874ddc8 100644
--- a/modules/gui/macosx/library/VLCInputItem.m
+++ b/modules/gui/macosx/library/VLCInputItem.m
@@ -25,9 +25,15 @@
 #import "main/VLCMain.h"
 #import "extensions/NSString+Helpers.h"
 
+#import <vlc_url.h>
+
 NSString *VLCInputItemParsingSucceeded = @"VLCInputItemParsingSucceeded";
 NSString *VLCInputItemParsingFailed = @"VLCInputItemParsingFailed";
 NSString *VLCInputItemSubtreeAdded = @"VLCInputItemSubtreeAdded";
+NSString *VLCInputItemPreparsingSkipped = @"VLCInputItemPreparsingSkipped";
+NSString *VLCInputItemPreparsingFailed = @"VLCInputItemPreparsingFailed";
+NSString *VLCInputItemPreparsingTimeOut = @"VLCInputItemPreparsingTimeOut";
+NSString *VLCInputItemPreparsingSucceeded = @"VLCInputItemPreparsingSucceeded";
 
 @interface VLCInputItem()
 {
@@ -36,6 +42,7 @@ NSString *VLCInputItemSubtreeAdded = @"VLCInputItemSubtreeAdded";
 
 - (void)parsingEnded:(int)status;
 - (void)subTreeAdded:(input_item_node_t *)p_node;
+- (void)preparsingEnded:(enum input_item_preparse_status)status;
 
 @end
 
@@ -63,6 +70,20 @@ static const struct input_item_parser_cbs_t parserCallbacks =
     cb_subtree_added,
 };
 
+static void cb_preparse_ended(input_item_t *p_item, enum input_item_preparse_status status, void *p_data)
+{
+    VLC_UNUSED(p_item);
+    dispatch_async(dispatch_get_main_queue(), ^{
+        VLCInputItem *inputItem = (__bridge VLCInputItem *)p_data;
+        [inputItem preparsingEnded:status];
+    });
+}
+
+static const struct input_preparser_callbacks_t preparseCallbacks = {
+    cb_preparse_ended,
+    cb_subtree_added,
+};
+
 @implementation VLCInputItem
 
 - (instancetype)initWithInputItem:(struct input_item_t *)p_inputItem
@@ -90,6 +111,325 @@ static const struct input_item_parser_cbs_t parserCallbacks =
     }
     return @"";
 }
+- (void)setName:(NSString *)name
+{
+    if (_vlcInputItem) {
+        input_item_SetName(_vlcInputItem, [name UTF8String]);
+    }
+}
+
+- (NSString *)title
+{
+    if (!_vlcInputItem) {
+        return nil;
+    }
+    char *psz_title = input_item_GetTitle(_vlcInputItem);
+    if (!psz_title) {
+        return self.name;
+    }
+
+    NSString *returnValue = toNSStr(psz_title);
+    FREENULL(psz_title);
+    return returnValue;
+}
+-(void)setTitle:(NSString *)title
+{
+    if (_vlcInputItem) {
+        input_item_SetTitle(_vlcInputItem, [title UTF8String]);
+    }
+}
+
+- (NSString *)artist
+{
+    if (!_vlcInputItem) {
+        return nil;
+    }
+    char *psz_artist = input_item_GetArtist(_vlcInputItem);
+    NSString *returnValue = toNSStr(psz_artist);
+    FREENULL(psz_artist);
+    return returnValue;
+}
+- (void)setArtist:(NSString *)artist
+{
+    if (_vlcInputItem) {
+        input_item_SetArtist(_vlcInputItem, [artist UTF8String]);
+    }
+}
+
+- (NSString *)albumName
+{
+    if (!_vlcInputItem) {
+        return nil;
+    }
+    char *psz_album = input_item_GetAlbum(_vlcInputItem);
+    NSString *returnValue = toNSStr(psz_album);
+    FREENULL(psz_album);
+    return returnValue;
+}
+- (void)setAlbumName:(NSString *)albumName
+{
+    if (_vlcInputItem) {
+        input_item_SetAlbum(_vlcInputItem, [albumName UTF8String]);
+    }
+}
+
+- (NSString *)trackNumber
+{
+    if (!_vlcInputItem) {
+        return nil;
+    }
+    char *psz_trackNumber = input_item_GetTrackNumber(_vlcInputItem);
+    NSString *returnValue = toNSStr(psz_trackNumber);
+    FREENULL(psz_trackNumber);
+    return returnValue;
+}
+- (void)setTrackNumber:(NSString *)trackNumber
+{
+    if (_vlcInputItem) {
+        input_item_SetTrackNumber(_vlcInputItem, [trackNumber UTF8String]);
+    }
+}
+
+- (NSString *)genre
+{
+    if (!_vlcInputItem) {
+        return nil;
+    }
+    char *psz_genre = input_item_GetGenre(_vlcInputItem);
+    NSString *returnValue = toNSStr(psz_genre);
+    FREENULL(psz_genre);
+    return returnValue;
+}
+- (void)setGenre:(NSString *)genre
+{
+    if (_vlcInputItem) {
+        input_item_SetGenre(_vlcInputItem, [genre UTF8String]);
+    }
+}
+
+- (NSString *)copyright
+{
+    if (!_vlcInputItem) {
+        return nil;
+    }
+    char *psz_copyright = input_item_GetCopyright(_vlcInputItem);
+    NSString *returnValue = toNSStr(psz_copyright);
+    FREENULL(psz_copyright);
+    return returnValue;
+}
+- (void)setCopyright:(NSString *)copyright
+{
+    if (_vlcInputItem) {
+        input_item_SetCopyright(_vlcInputItem, [copyright UTF8String]);
+    }
+}
+
+- (NSString *)publisher
+{
+    if (!_vlcInputItem) {
+        return nil;
+    }
+    char *psz_publisher = input_item_GetPublisher(_vlcInputItem);
+    NSString *returnValue = toNSStr(psz_publisher);
+    FREENULL(psz_publisher);
+    return returnValue;
+}
+- (void)setPublisher:(NSString *)publisher
+{
+    if (_vlcInputItem) {
+        input_item_SetPublisher(_vlcInputItem, [publisher UTF8String]);
+    }
+}
+
+- (NSString *)nowPlaying
+{
+    if (!_vlcInputItem) {
+        return nil;
+    }
+    char *psz_nowPlaying = input_item_GetNowPlaying(_vlcInputItem);
+    NSString *returnValue = toNSStr(psz_nowPlaying);
+    FREENULL(psz_nowPlaying);
+    return returnValue;
+}
+
+- (NSString *)language
+{
+    if (!_vlcInputItem) {
+        return nil;
+    }
+    char *psz_language = input_item_GetLanguage(_vlcInputItem);
+    NSString *returnValue = toNSStr(psz_language);
+    FREENULL(psz_language);
+    return returnValue;
+}
+- (void)setLanguage:(NSString *)language
+{
+    if (_vlcInputItem) {
+        input_item_SetLanguage(_vlcInputItem, [language UTF8String]);
+    }
+}
+
+- (NSString *)date
+{
+    if (!_vlcInputItem) {
+        return nil;
+    }
+    char *psz_date = input_item_GetDate(_vlcInputItem);
+    NSString *returnValue = toNSStr(psz_date);
+    FREENULL(psz_date);
+    return returnValue;
+}
+- (void)setDate:(NSString *)date
+{
+    if (_vlcInputItem) {
+        input_item_SetDate(_vlcInputItem, [date UTF8String]);
+    }
+}
+
+- (NSString *)contentDescription
+{
+    if (!_vlcInputItem) {
+        return nil;
+    }
+    char *psz_description = input_item_GetDescription(_vlcInputItem);
+    NSString *returnValue = toNSStr(psz_description);
+    FREENULL(psz_description);
+    return returnValue;
+}
+- (void)setContentDescription:(NSString *)contentDescription
+{
+    if (_vlcInputItem) {
+        input_item_SetDescription(_vlcInputItem, [contentDescription UTF8String]);
+    }
+}
+
+- (NSString *)encodedBy
+{
+    if (!_vlcInputItem) {
+        return nil;
+    }
+    char *psz_encodedBy = input_item_GetEncodedBy(_vlcInputItem);
+    NSString *returnValue = toNSStr(psz_encodedBy);
+    FREENULL(psz_encodedBy);
+    return returnValue;
+}
+
+- (NSString *)trackID
+{
+    if (!_vlcInputItem) {
+        return nil;
+    }
+    char *psz_trackID = input_item_GetTrackID(_vlcInputItem);
+    NSString *returnValue = toNSStr(psz_trackID);
+    FREENULL(psz_trackID);
+    return returnValue;
+}
+
+- (NSString *)trackTotal
+{
+    if (!_vlcInputItem) {
+        return nil;
+    }
+    char *psz_trackTotal = input_item_GetTrackTotal(_vlcInputItem);
+    NSString *returnValue = toNSStr(psz_trackTotal);
+    FREENULL(psz_trackTotal);
+    return returnValue;
+}
+
+- (NSString *)director
+{
+    if (!_vlcInputItem) {
+        return nil;
+    }
+    char *psz_director = input_item_GetDirector(_vlcInputItem);
+    NSString *returnValue = toNSStr(psz_director);
+    FREENULL(psz_director);
+    return returnValue;
+}
+- (void)setDirector:(NSString *)director
+{
+    if (_vlcInputItem) {
+        input_item_SetDirector(_vlcInputItem, [director UTF8String]);
+    }
+}
+
+- (NSString *)season
+{
+    if (!_vlcInputItem) {
+        return nil;
+    }
+    char *psz_season = input_item_GetSeason(_vlcInputItem);
+    NSString *returnValue = toNSStr(psz_season);
+    FREENULL(psz_season);
+    return returnValue;
+}
+
+- (NSString *)episode
+{
+    if (!_vlcInputItem) {
+        return nil;
+    }
+    char *psz_episode = input_item_GetEpisode(_vlcInputItem);
+    NSString *returnValue = toNSStr(psz_episode);
+    FREENULL(psz_episode);
+    return returnValue;
+}
+
+- (NSString *)showName
+{
+    if (!_vlcInputItem) {
+        return nil;
+    }
+    char *psz_showName = input_item_GetShowName(_vlcInputItem);
+    NSString *returnValue = toNSStr(psz_showName);
+    FREENULL(psz_showName);
+    return returnValue;
+}
+- (void)setShowName:(NSString *)showName
+{
+    if (_vlcInputItem) {
+        input_item_SetShowName(_vlcInputItem, [showName UTF8String]);
+    }
+}
+
+- (NSString *)actors
+{
+    if (!_vlcInputItem) {
+        return nil;
+    }
+    char *psz_actors = input_item_GetActors(_vlcInputItem);
+    NSString *returnValue = toNSStr(psz_actors);
+    FREENULL(psz_actors);
+    return returnValue;
+}
+- (void)setActors:(NSString *)actors
+{
+    if (_vlcInputItem) {
+        input_item_SetActors(_vlcInputItem, [actors UTF8String]);
+    }
+}
+
+- (NSString *)discNumber
+{
+    if (!_vlcInputItem) {
+        return nil;
+    }
+    char *psz_discNumber = input_item_GetDiscNumber(_vlcInputItem);
+    NSString *returnValue = toNSStr(psz_discNumber);
+    FREENULL(psz_discNumber);
+    return returnValue;
+}
+
+- (NSString *)totalNumberOfDiscs
+{
+    if (!_vlcInputItem) {
+        return nil;
+    }
+    char *psz_totalDiscNumber = input_item_GetDiscTotal(_vlcInputItem);
+    NSString *returnValue = toNSStr(psz_totalDiscNumber);
+    FREENULL(psz_totalDiscNumber);
+    return returnValue;
+}
 
 - (NSString *)MRL
 {
@@ -99,6 +439,17 @@ static const struct input_item_parser_cbs_t parserCallbacks =
     return @"";
 }
 
+- (NSString *)decodedMRL
+{
+    if (_vlcInputItem) {
+        char *psz_url = vlc_uri_decode(input_item_GetURI(_vlcInputItem));
+        NSString *returnValue = toNSStr(psz_url);
+        FREENULL(psz_url);
+        return returnValue;
+    }
+    return nil;
+}
+
 - (vlc_tick_t)duration
 {
     if (_vlcInputItem) {
@@ -155,12 +506,62 @@ static const struct input_item_parser_cbs_t parserCallbacks =
     _p_parserID = NULL;
 }
 
+- (BOOL)preparsed
+{
+    if (_vlcInputItem) {
+        return input_item_IsPreparsed(_vlcInputItem);
+    }
+    return NO;
+}
+
+- (void)preparsingEnded:(enum input_item_preparse_status)status
+{
+    NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
+    switch (status) {
+        case ITEM_PREPARSE_SKIPPED:
+            [notificationCenter postNotificationName:VLCInputItemPreparsingSkipped object:self];
+            break;
+        case ITEM_PREPARSE_FAILED:
+            [notificationCenter postNotificationName:VLCInputItemPreparsingFailed object:self];
+            break;
+        case ITEM_PREPARSE_TIMEOUT:
+            [notificationCenter postNotificationName:VLCInputItemPreparsingTimeOut object:self];
+
+        case ITEM_PREPARSE_DONE:
+        default:
+            [notificationCenter postNotificationName:VLCInputItemPreparsingSucceeded object:self];
+            break;
+    }
+}
+
+- (int)preparseInputItem
+{
+    if (!_vlcInputItem) {
+        return VLC_ENOVAR;
+    }
+
+    return libvlc_MetadataRequest(vlc_object_instance(getIntf()),
+                                  _vlcInputItem,
+                                  META_REQUEST_OPTION_SCOPE_ANY,
+                                  &preparseCallbacks,
+                                  (__bridge void *)self,
+                                  -1, NULL);
+}
+
 - (void)subTreeAdded:(input_item_node_t *)p_node
 {
     _subTree = p_node;
     [[NSNotificationCenter defaultCenter] postNotificationName:VLCInputItemSubtreeAdded object:self];
 }
 
+- (int)writeMetadataToFile
+{
+    if (!_vlcInputItem) {
+        return VLC_ENOVAR;
+    }
+    return input_item_WriteMeta(VLC_OBJECT(getIntf()), _vlcInputItem);
+}
+
 @end
 
 @interface VLCInputNode()



More information about the vlc-commits mailing list