feedparser 2.0.1 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Manifest.txt +2 -0
- data/README.md +11 -1
- data/lib/feedparser.rb +1 -0
- data/lib/feedparser/attachment.rb +17 -0
- data/lib/feedparser/builder/atom.rb +15 -1
- data/lib/feedparser/builder/rss.rb +11 -0
- data/lib/feedparser/item.rb +18 -2
- data/lib/feedparser/version.rb +2 -2
- data/test/test_atom_live.rb +4 -0
- data/test/test_attachments_live.rb +32 -0
- data/test/test_rss_live.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a1bacd6aeb6281e16cbcd51fd6732f999d9788cd
|
4
|
+
data.tar.gz: c48df4d0c5cf710d63ec4ebabfc2e28a11b06d27
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37d3ede519e5f9e3ef3d6a5c768181408ce049e19629af277440888fd96a35890a87c7ddffe11376de4b0acb4818820f7486f8ed7411ce91a24a11229af1acb9
|
7
|
+
data.tar.gz: 6f448cc771f30d523b23337225b8bf26b0cf613be26236e7c68093e0ca8e5538f8e053ba0c84b8c58a2fbe95d3c9287fe3e90341f8ec4c4bedd8de203cb56a6a
|
data/Manifest.txt
CHANGED
@@ -3,6 +3,7 @@ Manifest.txt
|
|
3
3
|
README.md
|
4
4
|
Rakefile
|
5
5
|
lib/feedparser.rb
|
6
|
+
lib/feedparser/attachment.rb
|
6
7
|
lib/feedparser/author.rb
|
7
8
|
lib/feedparser/builder/atom.rb
|
8
9
|
lib/feedparser/builder/json.rb
|
@@ -16,6 +17,7 @@ lib/feedparser/tag.rb
|
|
16
17
|
lib/feedparser/version.rb
|
17
18
|
test/helper.rb
|
18
19
|
test/test_atom_live.rb
|
20
|
+
test/test_attachments_live.rb
|
19
21
|
test/test_dates.rb
|
20
22
|
test/test_microformats.rb
|
21
23
|
test/test_rss_live.rb
|
data/README.md
CHANGED
@@ -11,6 +11,8 @@ feedparser gem - web feed parser and normalizer (Atom, RSS, JSON Feed, HTML h-en
|
|
11
11
|
|
12
12
|
## What's News?
|
13
13
|
|
14
|
+
**October/2017**: Added support for attachments / media enclosures in RSS and Atom.
|
15
|
+
|
14
16
|
**June/2017**: Added support for reading feeds in HTML with Microformats incl.
|
15
17
|
[`h-entry`](http://microformats.org/wiki/h-entry),
|
16
18
|
[`h-feed`](http://microformats.org/wiki/h-feed) and others.
|
@@ -32,7 +34,7 @@ See the [Awesome Feeds](https://github.com/feedparser/awesome-feeds) page ».
|
|
32
34
|
|
33
35
|
### Structs
|
34
36
|
|
35
|
-
Feed • Item • Author • Tag • Generator
|
37
|
+
Feed • Item • Author • Tag • Attachment • Generator
|
36
38
|
|
37
39
|
|
38
40
|
![](feed-models.png)
|
@@ -158,12 +160,20 @@ end
|
|
158
160
|
|
159
161
|
(Source: [`lib/feedparser/tag.rb`](https://github.com/feedparser/feedparser/blob/master/lib/feedparser/tag.rb))
|
160
162
|
|
163
|
+
### `Attachment` Struct
|
164
|
+
|
165
|
+
_Also known as Media Enclosure_
|
166
|
+
|
167
|
+
(Source: [`lib/feedparser/attachment.rb`](https://github.com/feedparser/feedparser/blob/master/lib/feedparser/attachment.rb))
|
168
|
+
|
169
|
+
|
161
170
|
### `Generator` Struct
|
162
171
|
|
163
172
|
(Source: [`lib/feedparser/generator.rb`](https://github.com/feedparser/feedparser/blob/master/lib/feedparser/generator.rb))
|
164
173
|
|
165
174
|
|
166
175
|
|
176
|
+
|
167
177
|
### Read Feed Example
|
168
178
|
|
169
179
|
``` ruby
|
data/lib/feedparser.rb
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module FeedParser
|
4
|
+
|
5
|
+
class Attachment ## also known as Enclosure
|
6
|
+
|
7
|
+
attr_accessor :url
|
8
|
+
## note: uri is an alias for url
|
9
|
+
alias :uri :url ## add atom alias for uri - why? why not?
|
10
|
+
alias :uri= :url=
|
11
|
+
|
12
|
+
attr_accessor :length
|
13
|
+
attr_accessor :type
|
14
|
+
|
15
|
+
end # class Attachment
|
16
|
+
|
17
|
+
end # module FeedParser
|
@@ -176,7 +176,7 @@ class AtomFeedBuilder
|
|
176
176
|
item.updated = item.updated_local.utc
|
177
177
|
end
|
178
178
|
|
179
|
-
if atom_item.published && atom_item.published.content
|
179
|
+
if atom_item.published && atom_item.published.content
|
180
180
|
item.published_local = handle_date( atom_item.published, 'item.published' )
|
181
181
|
item.published = item.published_local.utc
|
182
182
|
end
|
@@ -203,6 +203,20 @@ class AtomFeedBuilder
|
|
203
203
|
item.tags << build_tag( atom_cat )
|
204
204
|
end
|
205
205
|
|
206
|
+
|
207
|
+
## check for attachments / media enclosures
|
208
|
+
### todo/fix: allow more than one attachment/enclosure
|
209
|
+
if atom_item.links
|
210
|
+
enclosure = atom_item.links.detect{ |x| x.rel == 'enclosure' }
|
211
|
+
if enclosure
|
212
|
+
attachment = Attachment.new
|
213
|
+
attachment.url = enclosure.href
|
214
|
+
attachment.length = enclosure.length
|
215
|
+
attachment.type = enclosure.type
|
216
|
+
item.attachments << attachment
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
206
220
|
item
|
207
221
|
end # method build_item
|
208
222
|
|
@@ -182,6 +182,17 @@ class RssFeedBuilder
|
|
182
182
|
end
|
183
183
|
|
184
184
|
|
185
|
+
## check for enclosure
|
186
|
+
## todo/check: rss can only include at most one enclosure?
|
187
|
+
|
188
|
+
if rss_item.enclosure
|
189
|
+
attachment = Attachment.new
|
190
|
+
attachment.url = rss_item.enclosure.url
|
191
|
+
attachment.length = rss_item.enclosure.length
|
192
|
+
attachment.type = rss_item.enclosure.type
|
193
|
+
item.attachments << attachment
|
194
|
+
end
|
195
|
+
|
185
196
|
item
|
186
197
|
end # method build_feed_item_from_rss
|
187
198
|
|
data/lib/feedparser/item.rb
CHANGED
@@ -81,10 +81,26 @@ class Item
|
|
81
81
|
|
82
82
|
alias :categories :tags # for now allow categories alias for tags - remove (why? why not?)
|
83
83
|
|
84
|
+
|
85
|
+
# add attachments/media enclosures (url, length and type)
|
86
|
+
# note: lets support more than one (it's an array)
|
87
|
+
attr_accessor :attachments
|
88
|
+
|
89
|
+
def attachment() @attachments[0]; end
|
90
|
+
def attachments?() @attachments && @attachments.size > 0; end
|
91
|
+
alias :attachment? :attachments?
|
92
|
+
|
93
|
+
alias :enclosures :attachments
|
94
|
+
alias :enclosure :attachment
|
95
|
+
alias :enclosures? :attachments?
|
96
|
+
alias :enclosure? :attachments?
|
97
|
+
|
98
|
+
|
84
99
|
def initialize
|
85
100
|
## note: make authors, tags empty arrays on startup (e.g. not nil)
|
86
|
-
@authors
|
87
|
-
@tags
|
101
|
+
@authors = []
|
102
|
+
@tags = []
|
103
|
+
@attachments = []
|
88
104
|
end
|
89
105
|
|
90
106
|
end # class Item
|
data/lib/feedparser/version.rb
CHANGED
data/test/test_atom_live.rb
CHANGED
@@ -25,12 +25,16 @@ class TestAtomLive < MiniTest::Test
|
|
25
25
|
end
|
26
26
|
|
27
27
|
|
28
|
+
=begin
|
29
|
+
### returns ssl error e.g.
|
30
|
+
## OpenSSL::SSL::SSLError: SSL_connect SYSCALL returned=5 errno=0 state=SSLv2/v3 read server
|
28
31
|
def test_googlegroup
|
29
32
|
feed = fetch_and_parse_feed( 'https://groups.google.com/forum/feed/beerdb/topics/atom.xml?num=15' )
|
30
33
|
|
31
34
|
assert_equal 'atom', feed.format
|
32
35
|
assert_equal 'https://groups.google.com/d/forum/beerdb', feed.url
|
33
36
|
end
|
37
|
+
=end
|
34
38
|
|
35
39
|
|
36
40
|
def test_headius
|
@@ -0,0 +1,32 @@
|
|
1
|
+
###
|
2
|
+
# to run use
|
3
|
+
# ruby -I ./lib -I ./test test/test_attachments_live.rb
|
4
|
+
# or better
|
5
|
+
# rake test
|
6
|
+
|
7
|
+
require 'helper'
|
8
|
+
|
9
|
+
class TestAttachmentsLive < MiniTest::Test
|
10
|
+
|
11
|
+
def test_atom
|
12
|
+
feed = fetch_and_parse_feed( 'http://www.lse.ac.uk/assets/richmedia/webFeeds/publicLecturesAndEvents_AtomAllMediaTypesLatest100.xml' )
|
13
|
+
|
14
|
+
assert_equal 'audio/mpeg', feed.items.first.attachment.type
|
15
|
+
assert_equal 'audio/mpeg', feed.items.first.enclosure.type
|
16
|
+
|
17
|
+
assert_equal true, feed.items.first.attachment?
|
18
|
+
assert_equal true, feed.items.first.enclosure?
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
def test_rss
|
23
|
+
feed = fetch_and_parse_feed( 'http://www.radiofreesatan.com/category/featured/feed/' )
|
24
|
+
|
25
|
+
assert_equal 'audio/mpeg', feed.items.first.attachment.type
|
26
|
+
assert_equal 'audio/mpeg', feed.items.first.enclosure.type
|
27
|
+
|
28
|
+
assert_equal true, feed.items.first.attachment?
|
29
|
+
assert_equal true, feed.items.first.enclosure?
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
data/test/test_rss_live.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: feedparser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gerald Bauer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-10-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: logutils
|
@@ -81,6 +81,7 @@ files:
|
|
81
81
|
- README.md
|
82
82
|
- Rakefile
|
83
83
|
- lib/feedparser.rb
|
84
|
+
- lib/feedparser/attachment.rb
|
84
85
|
- lib/feedparser/author.rb
|
85
86
|
- lib/feedparser/builder/atom.rb
|
86
87
|
- lib/feedparser/builder/json.rb
|
@@ -94,6 +95,7 @@ files:
|
|
94
95
|
- lib/feedparser/version.rb
|
95
96
|
- test/helper.rb
|
96
97
|
- test/test_atom_live.rb
|
98
|
+
- test/test_attachments_live.rb
|
97
99
|
- test/test_dates.rb
|
98
100
|
- test/test_microformats.rb
|
99
101
|
- test/test_rss_live.rb
|
@@ -119,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
119
121
|
version: '0'
|
120
122
|
requirements: []
|
121
123
|
rubyforge_project:
|
122
|
-
rubygems_version: 2.
|
124
|
+
rubygems_version: 2.5.2
|
123
125
|
signing_key:
|
124
126
|
specification_version: 4
|
125
127
|
summary: feedparser - web feed parser and normalizer (RSS, Atom, JSON Feed, HTML h-entry,
|