-
Notifications
You must be signed in to change notification settings - Fork 65
feat: add media and enclosure helper APIs #54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
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 hidden or 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 hidden or 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,84 @@ | ||
| require "test_helper" | ||
|
|
||
| class MediaAndEnclosureHelpersTest < Test::Unit::TestCase | ||
| def setup | ||
| @feed = SimpleRSS.parse <<~XML | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"> | ||
| <channel> | ||
| <title>Podcast Feed</title> | ||
| <item> | ||
| <title>Episode 1</title> | ||
| <enclosure url="https://example.com/audio-1.mp3" type="audio/mpeg" length="12345" /> | ||
| <media:content url="https://example.com/image-1.jpg" type="image/jpeg" /> | ||
| <media:description>Episode image</media:description> | ||
| <media:thumbnail url="https://example.com/thumb-1.jpg" /> | ||
| <itunes:duration>00:42:00</itunes:duration> | ||
| <itunes:image href="https://example.com/itunes-1.jpg" /> | ||
| </item> | ||
| <item> | ||
| <title>Episode 2</title> | ||
| <media:thumbnail url="https://example.com/thumb-2.jpg" /> | ||
| </item> | ||
| <item> | ||
| <title>Episode 3</title> | ||
| <enclosure url="https://example.com/audio-3.mp3" type="audio/mpeg" length="999" /> | ||
| </item> | ||
| <item> | ||
| <title>Episode 4</title> | ||
| <enclosure url="" type="audio/mpeg" length="111" /> | ||
| <media:thumbnail url="" /> | ||
| <itunes:image href="" /> | ||
| </item> | ||
| </channel> | ||
| </rss> | ||
| XML | ||
| end | ||
|
|
||
| def test_enclosures_extracts_podcast_enclosures | ||
| enclosures = @feed.enclosures | ||
|
|
||
| assert_equal 2, enclosures.size | ||
| assert_equal "https://example.com/audio-1.mp3", enclosures.first[:url] | ||
| assert_equal "audio/mpeg", enclosures.first[:type] | ||
| assert_equal "12345", enclosures.first[:length] | ||
| assert_equal "Episode 1", enclosures.first[:item][:title] | ||
| end | ||
|
|
||
| def test_images_collects_unique_media_urls | ||
| images = @feed.images | ||
|
|
||
| assert_equal [ | ||
| "https://example.com/thumb-1.jpg", | ||
| "https://example.com/image-1.jpg", | ||
| "https://example.com/itunes-1.jpg", | ||
| "https://example.com/thumb-2.jpg" | ||
| ], images | ||
| end | ||
|
|
||
| def test_item_media_helpers | ||
| first_item = @feed.items.first | ||
| second_item = @feed.items[1] | ||
| third_item = @feed.items[2] | ||
| fourth_item = @feed.items.last | ||
|
|
||
| assert_equal true, first_item.has_media? | ||
| assert_equal "https://example.com/image-1.jpg", first_item.media_url | ||
|
|
||
| assert_equal true, second_item.has_media? | ||
| assert_equal "https://example.com/thumb-2.jpg", second_item.media_url | ||
|
|
||
| assert_equal true, third_item.has_media? | ||
| assert_equal "https://example.com/audio-3.mp3", third_item.media_url | ||
|
|
||
| assert_equal false, fourth_item.has_media? | ||
| assert_nil fourth_item.media_url | ||
| end | ||
|
|
||
| def test_media_description_and_itunes_duration_are_parsed | ||
| first_item = @feed.items.first | ||
|
|
||
| assert_equal "Episode image", first_item[:media_description] | ||
| assert_equal "00:42:00", first_item[:itunes_duration] | ||
| end | ||
| end |
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.
Uh oh!
There was an error while loading. Please reload this page.