-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for liveItem parsing within the podcast extension (Resolves
#39) (#45) Co-authored-by: maxdreherwalsworth <[email protected]>
- Loading branch information
1 parent
9216498
commit fa0aba6
Showing
13 changed files
with
503 additions
and
6 deletions.
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
35 changes: 35 additions & 0 deletions
35
lib/domain/podcast_index/rss_podcast_index_alternate_enclosure.dart
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,35 @@ | ||
import 'package:dart_rss/util/helpers.dart'; | ||
import 'package:xml/xml.dart'; | ||
|
||
// TODO: Complete the definition for the "alternativeEnclosure" tag ( | ||
/// The `alternativeEnclosure` XML element. | ||
/// | ||
/// https://github.com/Podcastindex-org/podcast-namespace/blob/main/docs/1.0.md#alternate-enclosure | ||
class RssPodcastIndexAlternateEnclosure { | ||
static RssPodcastIndexAlternateEnclosure? parse(XmlElement? element) { | ||
if (element == null) { | ||
return null; | ||
} | ||
|
||
return RssPodcastIndexAlternateEnclosure( | ||
type: element.getAttribute("type"), | ||
length: parseInt(element.getAttribute("length")), | ||
isDefault: parseBool(element.getAttribute("default")), | ||
); | ||
} | ||
|
||
const RssPodcastIndexAlternateEnclosure({ | ||
required this.type, | ||
required this.length, | ||
required this.isDefault, | ||
}); | ||
|
||
final String? type; | ||
final int? length; | ||
final bool? isDefault; | ||
|
||
@override | ||
String toString() { | ||
return 'RssPodcastIndexAlternateEnclosure{type: $type, length: $length, isDefault: $isDefault}'; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
lib/domain/podcast_index/rss_podcast_index_content_link.dart
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,23 @@ | ||
import 'package:xml/xml.dart'; | ||
|
||
class RssPodcastIndexContentLink { | ||
static RssPodcastIndexContentLink parse(XmlElement element) { | ||
return RssPodcastIndexContentLink( | ||
value: element.innerText, | ||
href: element.getAttribute("href"), | ||
); | ||
} | ||
|
||
const RssPodcastIndexContentLink({ | ||
this.href, | ||
this.value, | ||
}); | ||
|
||
final String? href; | ||
final String? value; | ||
|
||
@override | ||
String toString() { | ||
return 'RssPodcastIndexContentLink{href: $href, value: $value}'; | ||
} | ||
} |
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,28 @@ | ||
import 'package:dart_rss/util/helpers.dart'; | ||
import 'package:xml/xml.dart'; | ||
|
||
class RssPodcastIndexGuid { | ||
static RssPodcastIndexGuid? parse(XmlElement? element) { | ||
if (element == null) { | ||
return null; | ||
} | ||
|
||
return RssPodcastIndexGuid( | ||
isPermalink: parseBool(element.getAttribute("isPermaLink")), | ||
value: element.innerText, | ||
); | ||
} | ||
|
||
const RssPodcastIndexGuid({ | ||
this.isPermalink, | ||
this.value, | ||
}); | ||
|
||
final bool? isPermalink; | ||
final String? value; | ||
|
||
@override | ||
String toString() { | ||
return 'RssPodcastIndexGuid{isPermalink: $isPermalink, value: $value}'; | ||
} | ||
} |
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,87 @@ | ||
import 'package:dart_rss/domain/podcast_index/rss_podcast_index_alternate_enclosure.dart'; | ||
import 'package:dart_rss/domain/podcast_index/rss_podcast_index_content_link.dart'; | ||
import 'package:dart_rss/domain/podcast_index/rss_podcast_index_guid.dart'; | ||
import 'package:dart_rss/domain/podcast_index/rss_podcast_index_person.dart'; | ||
import 'package:dart_rss/domain/podcast_index/rss_podcast_live_item_images.dart'; | ||
import 'package:dart_rss/domain/rss_enclosure.dart'; | ||
import 'package:dart_rss/domain/rss_itunes_image.dart'; | ||
import 'package:dart_rss/util/helpers.dart'; | ||
import 'package:xml/xml.dart'; | ||
|
||
/// The `liveItem` XML element. | ||
/// | ||
/// https://github.com/Podcastindex-org/podcast-namespace/blob/main/docs/1.0.md#live-item | ||
class RssPodcastIndexLiveItem { | ||
static RssPodcastIndexLiveItem? parse(XmlElement? element) { | ||
if (element == null) { | ||
return null; | ||
} | ||
|
||
return RssPodcastIndexLiveItem( | ||
//elements | ||
title: findElementOrNull(element, "title")?.innerText, | ||
description: findElementOrNull(element, "description")?.innerText, | ||
link: findElementOrNull(element, "link")?.innerText, | ||
author: findElementOrNull(element, "author")?.innerText, | ||
|
||
// attributes | ||
status: element.getAttribute("status"), | ||
start: element.getAttribute("start"), | ||
end: element.getAttribute("end"), | ||
|
||
// classes | ||
guid: RssPodcastIndexGuid.parse(findElementOrNull(element, "guid")), | ||
|
||
images: RssPodcastIndexLiveItemImages.parse(findElementOrNull(element, "podcast:images")), | ||
|
||
itunesImage: RssItunesImage.parse(findElementOrNull(element, "itunes:image")), | ||
alternateEnclosure: | ||
RssPodcastIndexAlternateEnclosure.parse(findElementOrNull(element, "podcast:alternateEnclosure")), | ||
|
||
persons: element.findElements('podcast:person').map((e) => RssPodcastIndexPerson.parse(e)).toList(), | ||
enclosure: RssEnclosure.parse(findElementOrNull(element, "enclosure")), | ||
|
||
contentLinks: | ||
element.findElements('podcast:contentLink').map((e) => RssPodcastIndexContentLink.parse(e)).toList(), | ||
); | ||
} | ||
|
||
const RssPodcastIndexLiveItem({ | ||
this.title, | ||
this.description, | ||
this.link, | ||
this.author, | ||
this.status, | ||
this.start, | ||
this.end, | ||
this.guid, | ||
this.images, | ||
this.itunesImage, | ||
this.alternateEnclosure, | ||
this.persons, | ||
this.enclosure, | ||
this.contentLinks, | ||
}); | ||
|
||
final String? title; | ||
final String? description; | ||
final String? link; | ||
final String? author; | ||
|
||
final String? status; | ||
final String? start; | ||
final String? end; | ||
|
||
final RssPodcastIndexGuid? guid; | ||
final RssPodcastIndexLiveItemImages? images; | ||
final RssItunesImage? itunesImage; | ||
final RssPodcastIndexAlternateEnclosure? alternateEnclosure; | ||
final List<RssPodcastIndexPerson>? persons; | ||
final RssEnclosure? enclosure; | ||
final List<RssPodcastIndexContentLink>? contentLinks; | ||
|
||
@override | ||
String toString() { | ||
return 'RssPodcastIndexLiveItem{title: $title, description: $description, link: $link, author: $author, status: $status, start: $start, end: $end, guid: $guid, images: $images, alternateEnclosure: $alternateEnclosure, persons: $persons, enclosure: $enclosure, contentLinks: $contentLinks}'; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
lib/domain/podcast_index/rss_podcast_live_item_images.dart
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,25 @@ | ||
import 'package:xml/xml.dart'; | ||
|
||
class RssPodcastIndexLiveItemImages { | ||
static RssPodcastIndexLiveItemImages? parse(XmlElement? element) { | ||
if (element == null) { | ||
return null; | ||
} | ||
|
||
final imagesElement = element.getAttribute("srcset"); | ||
if (imagesElement == null) { | ||
return const RssPodcastIndexLiveItemImages(urls: null); | ||
} | ||
final urls = imagesElement.split(",").map((e) => RegExp(r"^[^s]+").firstMatch(e).toString()).toList(); | ||
return RssPodcastIndexLiveItemImages(urls: urls); | ||
} | ||
|
||
const RssPodcastIndexLiveItemImages({required this.urls}); | ||
|
||
final List<String>? urls; | ||
|
||
@override | ||
String toString() { | ||
return 'RssPodcastLiveItemImages{urls: $urls}'; | ||
} | ||
} |
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.