sfeed

Simple RSS and Atom feed parser
git clone https://git.sinitax.com/codemadness/sfeed
Log | Files | Refs | README | LICENSE | Upstream | sfeed.txt

commit 13a00fb97bdf5ce92124db8f6f46b16f1ca95f8c
parent b9723075c7a1a5beae432a963a20767d7e3d49b6
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Sun,  2 Aug 2015 19:47:16 +0200

sfeed: add support for media:description and media:title (used by youtube et al)

Diffstat:
Msfeed.c | 39++++++++++++++++++++++++---------------
1 file changed, 24 insertions(+), 15 deletions(-)

diff --git a/sfeed.c b/sfeed.c @@ -34,8 +34,8 @@ enum TagId { RSSTagLink, RSSTagDescription, RSSTagContentencoded, RSSTagGuid, RSSTagAuthor, RSSTagDccreator, /* Atom */ - AtomTagPublished, AtomTagUpdated, AtomTagTitle, - AtomTagSummary, AtomTagContent, + AtomTagPublished, AtomTagUpdated, AtomTagTitle, AtomTagMediaTitle, + AtomTagMediaDescription, AtomTagSummary, AtomTagContent, AtomTagId, AtomTagLink, AtomTagAuthor }; @@ -123,20 +123,22 @@ gettag(enum FeedType feedtype, const char *name, size_t namelen) }; /* Atom, alphabetical order */ static FeedTag atomtag[] = { - { STRP("author"), AtomTagAuthor }, - { STRP("content"), AtomTagContent }, - { STRP("id"), AtomTagId }, - { STRP("link"), AtomTagLink }, - { STRP("published"), AtomTagPublished }, - { STRP("summary"), AtomTagSummary }, - { STRP("title"), AtomTagTitle }, - { STRP("updated"), AtomTagUpdated }, + { STRP("author"), AtomTagAuthor }, + { STRP("content"), AtomTagContent }, + { STRP("id"), AtomTagId }, + { STRP("link"), AtomTagLink }, + { STRP("media:description"), AtomTagMediaDescription }, + { STRP("media:title"), AtomTagMediaTitle }, + { STRP("published"), AtomTagPublished }, + { STRP("summary"), AtomTagSummary }, + { STRP("title"), AtomTagTitle }, + { STRP("updated"), AtomTagUpdated }, { NULL, 0, -1 } }; int i, n; /* optimization: these are always non-matching */ - if (namelen < 2 || namelen > 15) + if (namelen < 2 || namelen > 17) return TagUnknown; switch (feedtype) { @@ -582,7 +584,7 @@ xml_handler_start_element(XMLParser *p, const char *name, size_t namelen) } /* tag already set: return */ - if (ctx.tag[0] != '\0') + if (ctx.tagid) return; /* in item */ @@ -602,9 +604,14 @@ xml_handler_start_element(XMLParser *p, const char *name, size_t namelen) ctx.field = &ctx.item.timestamp; break; case RSSTagTitle: - case AtomTagTitle: ctx.field = &ctx.item.title; break; + case AtomTagMediaTitle: + case AtomTagTitle: + /* prefer title over media:title if set */ + if (ctx.tagid != AtomTagMediaTitle || !ctx.item.content.len) + ctx.field = &ctx.item.title; + break; case RSSTagLink: case AtomTagLink: ctx.field = &ctx.item.link; @@ -617,10 +624,12 @@ xml_handler_start_element(XMLParser *p, const char *name, size_t namelen) ctx.field = &ctx.item.content; } break; + case AtomTagMediaDescription: case AtomTagSummary: case AtomTagContent: - /* prefer content over summary if set */ - if (ctx.tagid != AtomTagSummary || !ctx.item.content.len) { + /* prefer content over summary and media:description if set */ + if ((ctx.tagid != AtomTagMediaDescription && + ctx.tagid != AtomTagSummary) || !ctx.item.content.len) { ctx.iscontenttag = 1; ctx.field = &ctx.item.content; }