mirror of
https://github.com/stonega/tsacdop
synced 2024-12-15 09:57:19 +01:00
a6fc34e7bb
modified: android/app/build.gradle modified: android/app/src/main/AndroidManifest.xml new file: android/app/src/main/res/drawable/launch_background_night.xml new file: android/app/src/main/res/drawable/normal_background.xml new file: android/app/src/main/res/values-night/styles.xml modified: android/app/src/main/res/values/styles.xml new file: assets/fireside.jpg new file: assets/logo.png modified: lib/class/audiostate.dart modified: lib/class/fireside_data.dart modified: lib/class/podcastlocal.dart modified: lib/class/settingstate.dart modified: lib/episodes/episodedetail.dart modified: lib/episodes/episodedownload.dart modified: lib/home/appbar/about.dart modified: lib/home/appbar/addpodcast.dart modified: lib/home/appbar/importompl.dart modified: lib/home/appbar/popupmenu.dart modified: lib/home/audiopanel.dart modified: lib/home/audioplayer.dart modified: lib/home/homescroll.dart modified: lib/home/hometab.dart new file: lib/home/paly_history.dart modified: lib/local_storage/key_value_storage.dart modified: lib/local_storage/sqflite_localpodcast.dart modified: lib/main.dart modified: lib/podcasts/podcastdetail.dart modified: lib/podcasts/podcastgroup.dart modified: lib/podcasts/podcastlist.dart modified: lib/podcasts/podcastmanage.dart new file: lib/settings/settting.dart new file: lib/settings/theme.dart new file: lib/util/colorize.dart modified: lib/util/episodegrid.dart modified: pubspec.lock modified: pubspec.yaml
78 lines
2.1 KiB
Dart
78 lines
2.1 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:dio/dio.dart';
|
|
import 'package:html/parser.dart';
|
|
import 'package:tsacdop/local_storage/sqflite_localpodcast.dart';
|
|
|
|
class FiresideData {
|
|
final String id;
|
|
final String link;
|
|
|
|
String _background;
|
|
String get background => _background;
|
|
List<PodcastHost> _hosts;
|
|
List<PodcastHost> get hosts => _hosts;
|
|
FiresideData(this.id, this.link);
|
|
|
|
DBHelper dbHelper = DBHelper();
|
|
|
|
Future fatchData() async {
|
|
Response response = await Dio().get(link);
|
|
if (response.statusCode == 200) {
|
|
var doc = parse(response.data);
|
|
RegExp reg = RegExp(r'https(.+)jpg');
|
|
String backgroundImage = reg.stringMatch(doc.body
|
|
.getElementsByClassName('hero-background')
|
|
.first
|
|
.attributes
|
|
.toString());
|
|
var ul = doc.body.getElementsByClassName('episode-hosts').first.children;
|
|
List<PodcastHost> hosts = [];
|
|
ul.forEach((element) {
|
|
PodcastHost host;
|
|
String name = element.text.trim();
|
|
String image =
|
|
element.children.first.children.first.attributes.toString();
|
|
print(reg.stringMatch(image));
|
|
|
|
host = PodcastHost(
|
|
name,
|
|
reg.stringMatch(image) ??
|
|
'http://xuanmei.us/assets/default/avatar_small-170afdc2be97fc6148b283083942d82c101d4c1061f6b28f87c8958b52664af9.jpg');
|
|
|
|
hosts.add(host);
|
|
});
|
|
List<String> data = [
|
|
id,
|
|
backgroundImage,
|
|
json.encode({'hosts': hosts.map((host) => host.toJson()).toList()})
|
|
];
|
|
await dbHelper.saveFiresideData(data);
|
|
}
|
|
}
|
|
|
|
Future getData() async {
|
|
List<String> data = await dbHelper.getFiresideData(id);
|
|
_background = data[0];
|
|
_hosts = json
|
|
.decode(data[1])['hosts']
|
|
.cast<Map<String, Object>>()
|
|
.map<PodcastHost>(PodcastHost.fromJson)
|
|
.toList();
|
|
}
|
|
}
|
|
|
|
class PodcastHost {
|
|
final String image;
|
|
final String name;
|
|
PodcastHost(this.name, this.image);
|
|
|
|
Map<String, Object> toJson() {
|
|
return {'name': name, 'image': image};
|
|
}
|
|
|
|
static PodcastHost fromJson(Map<String, Object> json) {
|
|
return PodcastHost(json['name'] as String, json['image'] as String);
|
|
}
|
|
}
|