Enclosure support
This commit is contained in:
parent
f9e78f3d80
commit
42a73b35e8
@ -75,6 +75,10 @@ The data values within the <code>Items</code> array are as follows:</p>
|
||||
<tr><td><a href="http://feedparser.org/docs/reference-entry-updated_parsed.html">updated_parsed</a></td></tr>
|
||||
<tr><td rowspan="2">date_iso</td><td rowspan="2">Rfc3399</td><td><a href="http://feedparser.org/docs/reference-entry-published_parsed.html">published_parsed</a></td></tr>
|
||||
<tr><td><a href="http://feedparser.org/docs/reference-entry-updated_parsed.html">updated_parsed</a></td></tr>
|
||||
<tr><td><ins>enclosure_href</ins></td><td>String</td><td><a href="http://feedparser.org/docs/reference-entry-enclosures.html#reference.entry.enclosures.href">enclosures[0].href</a></td></tr>
|
||||
<tr><td><ins>enclosure_length</ins></td><td>String</td><td><a href="http://feedparser.org/docs/reference-entry-enclosures.html#reference.entry.enclosures.length">enclosures[0].length</a></td></tr>
|
||||
<tr><td><ins>enclosure_type</ins></td><td>String</td><td><a href="http://feedparser.org/docs/reference-entry-enclosures.html#reference.entry.enclosures.type">enclosures[0].type</a></td></tr>
|
||||
<tr><td><ins>guid_isPermaLink</ins></td><td>String</td><td><a href="http://blogs.law.harvard.edu/tech/rss#ltguidgtSubelementOfLtitemgt">isPermaLink</a></td></tr>
|
||||
<tr><td>id</td><td>String</td><td><a href="http://feedparser.org/docs/reference-entry-id.html">id</a></td></tr>
|
||||
<tr><td>link</td><td>String</td><td><a href="http://feedparser.org/docs/reference-entry-links.html#reference.entry.links.href">links[rel='alternate'].href</a></td></tr>
|
||||
<tr><td>new_channel</td><td>String</td><td><a href="http://feedparser.org/docs/reference-entry-id.html">id</a></td></tr>
|
||||
|
@ -218,6 +218,9 @@ class FeedParserDict(UserDict):
|
||||
def __getitem__(self, key):
|
||||
if key == 'category':
|
||||
return UserDict.__getitem__(self, 'tags')[0]['term']
|
||||
if key == 'enclosures':
|
||||
norel = lambda link: FeedParserDict([(name,value) for (name,value) in link.items() if name!='rel'])
|
||||
return [norel(link) for link in UserDict.__getitem__(self, 'links') if link['rel']=='enclosure']
|
||||
if key == 'categories':
|
||||
return [(tag['scheme'], tag['term']) for tag in UserDict.__getitem__(self, 'tags')]
|
||||
realkey = self.keymap.get(key, key)
|
||||
@ -1303,15 +1306,15 @@ class _FeedParserMixin:
|
||||
attrsD.setdefault('type', 'application/atom+xml')
|
||||
else:
|
||||
attrsD.setdefault('type', 'text/html')
|
||||
context = self._getContext()
|
||||
attrsD = self._itsAnHrefDamnIt(attrsD)
|
||||
if attrsD.has_key('href'):
|
||||
attrsD['href'] = self.resolveURI(attrsD['href'])
|
||||
if attrsD.get('rel')=='enclosure' and not context.get('id'):
|
||||
context['id'] = attrsD.get('href')
|
||||
expectingText = self.infeed or self.inentry or self.insource
|
||||
context = self._getContext()
|
||||
context.setdefault('links', [])
|
||||
context['links'].append(FeedParserDict(attrsD))
|
||||
if attrsD['rel'] == 'enclosure':
|
||||
self._start_enclosure(attrsD)
|
||||
if attrsD.has_key('href'):
|
||||
expectingText = 0
|
||||
if (attrsD.get('rel') == 'alternate') and (self.mapContentType(attrsD.get('type')) in self.html_types):
|
||||
@ -1427,7 +1430,8 @@ class _FeedParserMixin:
|
||||
def _start_enclosure(self, attrsD):
|
||||
attrsD = self._itsAnHrefDamnIt(attrsD)
|
||||
context = self._getContext()
|
||||
context.setdefault('enclosures', []).append(FeedParserDict(attrsD))
|
||||
attrsD['rel']='enclosure'
|
||||
context.setdefault('links', []).append(FeedParserDict(attrsD))
|
||||
href = attrsD.get('href')
|
||||
if href and not context.get('id'):
|
||||
context['id'] = href
|
||||
|
@ -100,6 +100,8 @@ def links(xentry, entry):
|
||||
xlink.setAttribute('type', link.get('type'))
|
||||
if link.has_key('rel'):
|
||||
xlink.setAttribute('rel', link.get('rel',None))
|
||||
if link.has_key('length'):
|
||||
xlink.setAttribute('length', link.get('length'))
|
||||
xentry.appendChild(xlink)
|
||||
|
||||
def date(xentry, name, parsed):
|
||||
|
@ -97,6 +97,9 @@ Items = [
|
||||
['date_822', Rfc822, 'updated_parsed'],
|
||||
['date_iso', Rfc3399, 'published_parsed'],
|
||||
['date_iso', Rfc3399, 'updated_parsed'],
|
||||
['enclosure_href', String, 'links', {'rel': 'enclosure'}, 'href'],
|
||||
['enclosure_length', String, 'links', {'rel': 'enclosure'}, 'length'],
|
||||
['enclosure_type', String, 'links', {'rel': 'enclosure'}, 'type'],
|
||||
['id', String, 'id'],
|
||||
['link', String, 'links', {'rel': 'alternate'}, 'href'],
|
||||
['new_channel', String, 'id'],
|
||||
@ -190,6 +193,13 @@ def template_info(source):
|
||||
for entry in data.entries:
|
||||
output['Items'].append(tmpl_mapper(entry, Items))
|
||||
|
||||
# synthesize isPermaLink attribute
|
||||
for item in output['Items']:
|
||||
if item.get('id') == item.get('link'):
|
||||
item['guid_isPermaLink']='true'
|
||||
else:
|
||||
item['guid_isPermaLink']='false'
|
||||
|
||||
# feed level information
|
||||
output['generator'] = config.generator_uri()
|
||||
output['name'] = config.name()
|
||||
|
11
tests/data/filter/tmpl/enclosure_href.xml
Normal file
11
tests/data/filter/tmpl/enclosure_href.xml
Normal file
@ -0,0 +1,11 @@
|
||||
<!--
|
||||
Description: link relationship
|
||||
Expect: Items[0]['enclosure_href'] == 'http://example.com/music.mp3'
|
||||
-->
|
||||
|
||||
<feed xmlns="http://www.w3.org/2005/Atom">
|
||||
<entry>
|
||||
<link rel="enclosure" href="http://example.com/music.mp3"/>
|
||||
</entry>
|
||||
</feed>
|
||||
|
11
tests/data/filter/tmpl/enclosure_length.xml
Normal file
11
tests/data/filter/tmpl/enclosure_length.xml
Normal file
@ -0,0 +1,11 @@
|
||||
<!--
|
||||
Description: link relationship
|
||||
Expect: Items[0]['enclosure_length'] == '100'
|
||||
-->
|
||||
|
||||
<feed xmlns="http://www.w3.org/2005/Atom">
|
||||
<entry>
|
||||
<link rel="enclosure" length="100"/>
|
||||
</entry>
|
||||
</feed>
|
||||
|
11
tests/data/filter/tmpl/enclosure_type.xml
Normal file
11
tests/data/filter/tmpl/enclosure_type.xml
Normal file
@ -0,0 +1,11 @@
|
||||
<!--
|
||||
Description: link relationship
|
||||
Expect: Items[0]['enclosure_type'] == 'audio/mpeg'
|
||||
-->
|
||||
|
||||
<feed xmlns="http://www.w3.org/2005/Atom">
|
||||
<entry>
|
||||
<link rel="enclosure" type="audio/mpeg"/>
|
||||
</entry>
|
||||
</feed>
|
||||
|
13
tests/data/reconstitute/enclosure.xml
Normal file
13
tests/data/reconstitute/enclosure.xml
Normal file
@ -0,0 +1,13 @@
|
||||
<!--
|
||||
Description: enclosure
|
||||
Expect: links[0].rel == 'enclosure' and id == 'http://example.com/1'
|
||||
-->
|
||||
|
||||
<rss>
|
||||
<channel>
|
||||
<item>
|
||||
<enclosure href="http://example.com/1"/>
|
||||
</item>
|
||||
</channel>
|
||||
</rss>
|
||||
|
11
tests/data/reconstitute/link_length.xml
Normal file
11
tests/data/reconstitute/link_length.xml
Normal file
@ -0,0 +1,11 @@
|
||||
<!--
|
||||
Description: link relationship
|
||||
Expect: links[0].length == '4000000'
|
||||
-->
|
||||
|
||||
<feed xmlns="http://www.w3.org/2005/Atom">
|
||||
<entry>
|
||||
<link rel="enclosure" href="http://example.com/music.mp3" length="4000000"/>
|
||||
</entry>
|
||||
</feed>
|
||||
|
@ -10,7 +10,7 @@
|
||||
<TMPL_LOOP Items>
|
||||
<item>
|
||||
<title><TMPL_VAR channel_name ESCAPE="HTML"><TMPL_IF title>: <TMPL_VAR title_plain ESCAPE="HTML"></TMPL_IF></title>
|
||||
<guid><TMPL_VAR id ESCAPE="HTML"></guid>
|
||||
<guid isPermaLink="<TMPL_VAR guid_isPermaLink>"><TMPL_VAR id ESCAPE="HTML"></guid>
|
||||
<link><TMPL_VAR link ESCAPE="HTML"></link>
|
||||
<TMPL_IF content>
|
||||
<description><TMPL_VAR content ESCAPE="HTML"></description>
|
||||
@ -23,6 +23,9 @@
|
||||
<author><TMPL_VAR author_email></author>
|
||||
</TMPL_IF>
|
||||
</TMPL_IF>
|
||||
<TMPL_IF enclosure_href>
|
||||
<enclosure url="<TMPL_VAR enclosure_href ESCAPE="HTML">" length="<TMPL_VAR enclosure_length>" type="<TMPL_VAR enclosure_type>"/>
|
||||
</TMPL_IF>
|
||||
</item>
|
||||
</TMPL_LOOP>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user