This repository has been archived by the owner on Aug 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 39
Updated package to support media:content tag #71
Open
bubudrc
wants to merge
2
commits into
Ranchero-Software:main
Choose a base branch
from
bubudrc:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// RSParsedMediaContent.h | ||
// RSParser | ||
// | ||
// | ||
// Created by Marcelo Perretta on 07/04/2022. | ||
// | ||
|
||
@import Foundation; | ||
#import "RSParsedMediaDescription.h" | ||
#import "RSParsedMediaCredit.h" | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface RSParsedMediaContent : NSObject | ||
|
||
@property (nonatomic) NSString *url; | ||
@property (nonatomic, nullable) NSString *mimeType; | ||
@property (nonatomic, nullable) RSParsedMediaDescription *mediaDescription; | ||
@property (nonatomic, nullable) RSParsedMediaCredit *mediaCredit; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// RSParsedMediaContent.m | ||
// RSParser | ||
// | ||
// | ||
// Created by Marcelo Perretta on 07/04/2022. | ||
// | ||
|
||
#import "RSParsedMediaContent.h" | ||
|
||
@implementation RSParsedMediaContent | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// RSParsedMediaCredit.h | ||
// RSParser | ||
// | ||
// | ||
// Created by Marcelo Perretta on 07/04/2022. | ||
// | ||
|
||
@import Foundation; | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface RSParsedMediaCredit : NSObject | ||
|
||
@property (nonatomic, nullable) NSString *mediaCreditRole; | ||
@property (nonatomic, nullable) NSString *mediaCreditScheme; | ||
@property (nonatomic, nullable) NSString *mediaCreditDescription; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// RSParsedMediaCredit.m | ||
// RSParser | ||
// | ||
// | ||
// Created by Marcelo Perretta on 07/04/2022. | ||
// | ||
|
||
#import "RSParsedMediaCredit.h" | ||
|
||
@implementation RSParsedMediaCredit | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// RSParsedMediaDescription.h | ||
// RSParser | ||
// | ||
// | ||
// Created by Marcelo Perretta on 07/04/2022. | ||
// | ||
|
||
@import Foundation; | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface RSParsedMediaDescription : NSObject | ||
|
||
@property (nonatomic, nullable) NSString *mimeType; | ||
@property (nonatomic, nullable) NSString *mediaDescription; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// RSParsedMediaDescription.m | ||
// RSParser | ||
// | ||
// | ||
// Created by Marcelo Perretta on 07/04/2022. | ||
// | ||
|
||
#import "RSParsedMediaDescription.h" | ||
|
||
@implementation RSParsedMediaDescription | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
#import "NSString+RSParser.h" | ||
#import "RSDateParser.h" | ||
#import "ParserData.h" | ||
#import "RSParsedMediaContent.h" | ||
#import "RSParsedEnclosure.h" | ||
#import "RSParsedAuthor.h" | ||
|
||
|
@@ -31,6 +32,7 @@ @interface RSRSSParser () <RSSAXParserDelegate> | |
@property (nonatomic) NSMutableArray *articles; | ||
@property (nonatomic) BOOL parsingArticle; | ||
@property (nonatomic) BOOL parsingAuthor; | ||
@property (nonatomic) BOOL parsingMedia; | ||
@property (nonatomic, readonly) RSParsedArticle *currentArticle; | ||
@property (nonatomic) BOOL parsingChannelImage; | ||
@property (nonatomic, readonly) NSDate *currentDate; | ||
|
@@ -95,6 +97,8 @@ - (RSParsedFeed *)parseFeed { | |
static NSString *kDCDateKey = @"dc:date"; | ||
static NSString *kDCCreatorKey = @"dc:creator"; | ||
static NSString *kRDFAboutKey = @"rdf:about"; | ||
static NSString *kMediaCreditRole = @"role"; | ||
static NSString *kMediaCreditScheme = @"scheme"; | ||
|
||
static const char *kItem = "item"; | ||
static const NSInteger kItemLength = 5; | ||
|
@@ -168,6 +172,12 @@ - (RSParsedFeed *)parseFeed { | |
static const char *kEnclosure = "enclosure"; | ||
static const NSInteger kEnclosureLength = 10; | ||
|
||
static const char *kMediaContent = "media"; | ||
static const NSInteger kMediaContentLength = 10; | ||
|
||
static const char *kMediaCredit = "credit"; | ||
static const NSInteger kMediaCreditLengt = 10; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
static const char *kLanguage = "language"; | ||
static const NSInteger kLanguageLength = 9; | ||
|
||
|
@@ -254,6 +264,45 @@ - (void)addGuid { | |
} | ||
} | ||
|
||
- (void)addMediaContent { | ||
NSDictionary *attributes = self.currentAttributes; | ||
NSString *url = attributes[kURLKey]; | ||
if (!url || url.length < 1) { | ||
return; | ||
} | ||
|
||
RSParsedMediaContent *mediaContent = [[RSParsedMediaContent alloc] init]; | ||
mediaContent.url = url; | ||
mediaContent.mimeType = attributes[kTypeKey]; | ||
|
||
self.currentArticle.mediaContent = mediaContent; | ||
} | ||
|
||
- (void)addMediaDescription { | ||
|
||
NSString *s = [self currentString]; | ||
if (!RSParserStringIsEmpty(s)) { | ||
RSParsedMediaDescription *mediaDescription = [[RSParsedMediaDescription alloc] init]; | ||
mediaDescription.mediaDescription = s; | ||
mediaDescription.mimeType = self.currentAttributes[kTypeKey]; | ||
self.currentArticle.mediaContent.mediaDescription = mediaDescription; | ||
} | ||
} | ||
|
||
- (void)addMediaCredit { | ||
|
||
NSDictionary *attributes = self.currentAttributes; | ||
NSString *s = [self currentString]; | ||
if (!RSParserStringIsEmpty(s)) { | ||
RSParsedMediaCredit *mediaCredit = [[RSParsedMediaCredit alloc] init]; | ||
mediaCredit.mediaCreditDescription = s; | ||
mediaCredit.mediaCreditRole = attributes[kMediaCreditRole]; | ||
mediaCredit.mediaCreditScheme = attributes[kMediaCreditScheme]; | ||
|
||
self.currentArticle.mediaContent.mediaCredit = mediaCredit; | ||
} | ||
} | ||
|
||
- (void)addEnclosure { | ||
|
||
NSDictionary *attributes = self.currentAttributes; | ||
|
@@ -340,6 +389,18 @@ - (void)addArticleElement:(const xmlChar *)localName prefix:(const xmlChar *)pre | |
return; | ||
} | ||
|
||
|
||
if (RSSAXEqualTags(prefix, kMediaContent, kMediaContentLength)) { | ||
if (RSSAXEqualTags(localName, kDescription, kDescription)) { | ||
[self addMediaDescription]; | ||
} | ||
else if (RSSAXEqualTags(localName, kMediaCredit, kMediaContentLength)) { | ||
[self addMediaCredit]; | ||
} | ||
|
||
return; | ||
} | ||
|
||
if (prefix != NULL) { | ||
return; | ||
} | ||
|
@@ -394,12 +455,17 @@ - (void)saxParser:(RSSAXParser *)SAXParser XMLStartElement:(const xmlChar *)loca | |
} | ||
|
||
NSDictionary *xmlAttributes = nil; | ||
if ((self.isRDF && RSSAXEqualTags(localName, kItem, kItemLength)) || RSSAXEqualTags(localName, kGuid, kGuidLength) || RSSAXEqualTags(localName, kEnclosure, kEnclosureLength)) { | ||
xmlAttributes = [self.parser attributesDictionary:attributes numberOfAttributes:numberOfAttributes]; | ||
} | ||
if (self.currentAttributes != xmlAttributes) { | ||
self.currentAttributes = xmlAttributes; | ||
} | ||
if ((self.isRDF && | ||
RSSAXEqualTags(localName, kItem, kItemLength)) || | ||
RSSAXEqualTags(localName, kGuid, kGuidLength) || | ||
RSSAXEqualTags(localName, kEnclosure, kEnclosureLength) || | ||
RSSAXEqualTags(prefix, kMediaContent, kMediaContentLength)) { | ||
xmlAttributes = [self.parser attributesDictionary:attributes numberOfAttributes:numberOfAttributes]; | ||
} | ||
|
||
if (self.currentAttributes != xmlAttributes) { | ||
self.currentAttributes = xmlAttributes; | ||
} | ||
|
||
if (!prefix && RSSAXEqualTags(localName, kItem, kItemLength)) { | ||
|
||
|
@@ -420,6 +486,12 @@ - (void)saxParser:(RSSAXParser *)SAXParser XMLStartElement:(const xmlChar *)loca | |
self.parsingAuthor = true; | ||
} | ||
} | ||
else if (prefix && RSSAXEqualTags(prefix, kMediaContent, kMediaContentLength)) { | ||
if (self.parsingArticle && prefix && RSSAXEqualTags(localName, kContent, kContent)) { | ||
[self addMediaContent]; | ||
self.parsingMedia = true; | ||
} | ||
} | ||
|
||
if (!self.parsingChannelImage) { | ||
[self.parser beginStoringCharacters]; | ||
|
@@ -449,6 +521,13 @@ - (void)saxParser:(RSSAXParser *)SAXParser XMLEndElement:(const xmlChar *)localN | |
self.parsingArticle = NO; | ||
} | ||
|
||
else if (self.parsingMedia) { | ||
[self addArticleElement:localName prefix:prefix]; | ||
if (RSSAXEqualTags(localName, kContent, kContentLength) && RSSAXEqualTags(prefix, kMediaContent, kMediaContentLength)) { | ||
self.parsingMedia = NO; | ||
} | ||
} | ||
|
||
else if (self.parsingArticle) { | ||
[self addArticleElement:localName prefix:prefix]; | ||
if (RSSAXEqualTags(localName, kAuthor, kAuthorLength)) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
10
should be6
— m-e-d-i-a plus a null character is 6 characters.