2023-11-28 23:08:34 +08:00
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
import 'package:dart_rss/dart_rss.dart';
|
2024-02-07 19:32:36 +08:00
|
|
|
import 'package:starcitizen_doctor/common/io/rs_http.dart';
|
2024-01-29 20:44:00 +08:00
|
|
|
import 'package:starcitizen_doctor/common/conf/url_conf.dart';
|
2023-11-28 23:08:34 +08:00
|
|
|
|
|
|
|
class RSSApi {
|
|
|
|
static Future<List<RssItem>> getRssVideo() async {
|
2024-02-07 19:32:36 +08:00
|
|
|
final r = await RSHttp.getText(URLConf.rssVideoUrl);
|
2024-02-07 00:20:06 +08:00
|
|
|
final f = RssFeed.parse(r);
|
2023-11-28 23:08:34 +08:00
|
|
|
return f.items.sublist(0, 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Future<List<RssItem>> getRssText() async {
|
2024-02-07 19:32:36 +08:00
|
|
|
final r1 = await RSHttp.getText(URLConf.rssTextUrl1);
|
2024-02-07 00:20:06 +08:00
|
|
|
final r1f = RssFeed.parse(r1);
|
2024-02-07 19:32:36 +08:00
|
|
|
final r2 = await RSHttp.getText(URLConf.rssTextUrl2);
|
2024-02-07 00:20:06 +08:00
|
|
|
final r2f = RssFeed.parse(r2);
|
2023-11-28 23:08:34 +08:00
|
|
|
final items = r1f.items..addAll(r2f.items);
|
|
|
|
items.sort((a, b) {
|
|
|
|
final aDate = HttpDate.parse(a.pubDate ?? "").millisecondsSinceEpoch;
|
|
|
|
final bDate = HttpDate.parse(b.pubDate ?? "").millisecondsSinceEpoch;
|
|
|
|
return bDate - aDate;
|
|
|
|
});
|
|
|
|
return items;
|
|
|
|
}
|
|
|
|
}
|