1
0
mirror of https://github.com/stonega/tsacdop synced 2025-01-10 14:23:08 +01:00
tsacdop-podcast-app-android/lib/webfeed/domain/atom_feed.dart
stonegate 1021f2eea4 modified: lib/class/audiostate.dart
new file:   lib/class/fireside_data.dart
	modified:   lib/episodes/episodedetail.dart
	modified:   lib/home/appbar/addpodcast.dart
	modified:   lib/home/audioplayer.dart
	modified:   lib/local_storage/key_value_storage.dart
	modified:   lib/local_storage/sqflite_localpodcast.dart
	modified:   lib/podcasts/podcastdetail.dart
	modified:   lib/webfeed/domain/atom_feed.dart
	modified:   lib/webfeed/domain/atom_item.dart
	modified:   lib/webfeed/domain/atom_person.dart
	modified:   lib/webfeed/domain/atom_source.dart
	modified:   lib/webfeed/domain/media/community.dart
	modified:   lib/webfeed/domain/media/embed.dart
	modified:   lib/webfeed/domain/media/group.dart
	modified:   lib/webfeed/domain/media/media.dart
	modified:   lib/webfeed/domain/media/scene.dart
	modified:   pubspec.lock
	modified:   pubspec.yaml
2020-02-26 17:54:59 +08:00

78 lines
2.4 KiB
Dart

import 'package:tsacdop/webfeed/domain/atom_category.dart';
import 'package:tsacdop/webfeed/domain/atom_generator.dart';
import 'package:tsacdop/webfeed/domain/atom_item.dart';
import 'package:tsacdop/webfeed/domain/atom_link.dart';
import 'package:tsacdop/webfeed/domain/atom_person.dart';
import 'package:tsacdop/webfeed/util/helpers.dart';
import 'package:xml/xml.dart';
class AtomFeed {
final String id;
final String title;
final String updated;
final List<AtomItem> items;
final List<AtomLink> links;
final List<AtomPerson> authors;
final List<AtomPerson> contributors;
final List<AtomCategory> categories;
final AtomGenerator generator;
final String icon;
final String logo;
final String rights;
final String subtitle;
AtomFeed({
this.id,
this.title,
this.updated,
this.items,
this.links,
this.authors,
this.contributors,
this.categories,
this.generator,
this.icon,
this.logo,
this.rights,
this.subtitle,
});
factory AtomFeed.parse(String xmlString) {
var document = parse(xmlString);
XmlElement feedElement;
try {
feedElement = document.findElements("feed").first;
} on StateError {
throw new ArgumentError("feed not found");
}
return AtomFeed(
id: findElementOrNull(feedElement, "id")?.text,
title: findElementOrNull(feedElement, "title")?.text,
updated: findElementOrNull(feedElement, "updated")?.text,
items: feedElement.findElements("entry").map((element) {
return AtomItem.parse(element);
}).toList(),
links: feedElement.findElements("link").map((element) {
return AtomLink.parse(element);
}).toList(),
authors: feedElement.findElements("author").map((element) {
return AtomPerson.parse(element);
}).toList(),
contributors: feedElement.findElements("contributor").map((element) {
return AtomPerson.parse(element);
}).toList(),
categories: feedElement.findElements("category").map((element) {
return AtomCategory.parse(element);
}).toList(),
generator:
AtomGenerator.parse(findElementOrNull(feedElement, "generator")),
icon: findElementOrNull(feedElement, "icon")?.text,
logo: findElementOrNull(feedElement, "logo")?.text,
rights: findElementOrNull(feedElement, "rights")?.text,
subtitle: findElementOrNull(feedElement, "subtitle")?.text,
);
}
}