mirror of
https://github.com/stonega/tsacdop
synced 2025-02-08 07:38:47 +01:00
Support podcast index new namespce funding.
This commit is contained in:
parent
98b6f2f829
commit
6eab636f98
@ -1,4 +1,5 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
import 'dart:convert';
|
||||||
import 'dart:developer' as developer;
|
import 'dart:developer' as developer;
|
||||||
|
|
||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
@ -27,7 +28,7 @@ class DBHelper {
|
|||||||
var documentsDirectory = await getDatabasesPath();
|
var documentsDirectory = await getDatabasesPath();
|
||||||
var path = join(documentsDirectory, "podcasts.db");
|
var path = join(documentsDirectory, "podcasts.db");
|
||||||
var theDb = await openDatabase(path,
|
var theDb = await openDatabase(path,
|
||||||
version: 4, onCreate: _onCreate, onUpgrade: _onUpgrade);
|
version: 5, onCreate: _onCreate, onUpgrade: _onUpgrade);
|
||||||
return theDb;
|
return theDb;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,7 +40,7 @@ class DBHelper {
|
|||||||
background_image TEXT DEFAULT '', hosts TEXT DEFAULT '',update_count INTEGER DEFAULT 0,
|
background_image TEXT DEFAULT '', hosts TEXT DEFAULT '',update_count INTEGER DEFAULT 0,
|
||||||
episode_count INTEGER DEFAULT 0, skip_seconds INTEGER DEFAULT 0,
|
episode_count INTEGER DEFAULT 0, skip_seconds INTEGER DEFAULT 0,
|
||||||
auto_download INTEGER DEFAULT 0, skip_seconds_end INTEGER DEFAULT 0,
|
auto_download INTEGER DEFAULT 0, skip_seconds_end INTEGER DEFAULT 0,
|
||||||
never_update INTEGER DEFAULT 0)""");
|
never_update INTEGER DEFAULT 0, funding TEXT DEFAULT '[]')""");
|
||||||
await db
|
await db
|
||||||
.execute("""CREATE TABLE Episodes(id INTEGER PRIMARY KEY,title TEXT,
|
.execute("""CREATE TABLE Episodes(id INTEGER PRIMARY KEY,title TEXT,
|
||||||
enclosure_url TEXT UNIQUE, enclosure_length INTEGER, pubDate TEXT,
|
enclosure_url TEXT UNIQUE, enclosure_length INTEGER, pubDate TEXT,
|
||||||
@ -56,27 +57,41 @@ class DBHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _onUpgrade(Database db, int oldVersion, int newVersion) async {
|
void _onUpgrade(Database db, int oldVersion, int newVersion) async {
|
||||||
if (oldVersion == 1) {
|
switch (oldVersion) {
|
||||||
await db.execute(
|
case (1):
|
||||||
"ALTER TABLE PodcastLocal ADD skip_seconds INTEGER DEFAULT 0 ");
|
await db.execute(
|
||||||
await db.execute(
|
"ALTER TABLE PodcastLocal ADD skip_seconds INTEGER DEFAULT 0 ");
|
||||||
"ALTER TABLE PodcastLocal ADD auto_download INTEGER DEFAULT 0");
|
await db.execute(
|
||||||
await db.execute(
|
"ALTER TABLE PodcastLocal ADD auto_download INTEGER DEFAULT 0");
|
||||||
"ALTER TABLE PodcastLocal ADD skip_seconds_end INTEGER DEFAULT 0 ");
|
await db.execute(
|
||||||
await db.execute(
|
"ALTER TABLE PodcastLocal ADD skip_seconds_end INTEGER DEFAULT 0 ");
|
||||||
"ALTER TABLE PodcastLocal ADD never_update INTEGER DEFAULT 0 ");
|
await db.execute(
|
||||||
} else if (oldVersion == 2) {
|
"ALTER TABLE PodcastLocal ADD never_update INTEGER DEFAULT 0 ");
|
||||||
await db.execute(
|
await db
|
||||||
"ALTER TABLE PodcastLocal ADD auto_download INTEGER DEFAULT 0");
|
.execute("ALTER TABLE PodcastLocal ADD funding TEXT DEFAULT '[]' ");
|
||||||
await db.execute(
|
break;
|
||||||
"ALTER TABLE PodcastLocal ADD skip_seconds_end INTEGER DEFAULT 0 ");
|
case (2):
|
||||||
await db.execute(
|
await db.execute(
|
||||||
"ALTER TABLE PodcastLocal ADD never_update INTEGER DEFAULT 0 ");
|
"ALTER TABLE PodcastLocal ADD auto_download INTEGER DEFAULT 0");
|
||||||
} else if (oldVersion == 3) {
|
await db.execute(
|
||||||
await db.execute(
|
"ALTER TABLE PodcastLocal ADD skip_seconds_end INTEGER DEFAULT 0 ");
|
||||||
"ALTER TABLE PodcastLocal ADD skip_seconds_end INTEGER DEFAULT 0");
|
await db.execute(
|
||||||
await db.execute(
|
"ALTER TABLE PodcastLocal ADD never_update INTEGER DEFAULT 0 ");
|
||||||
"ALTER TABLE PodcastLocal ADD never_update INTEGER DEFAULT 0 ");
|
await db
|
||||||
|
.execute("ALTER TABLE PodcastLocal ADD funding TEXT DEFAULT '[]' ");
|
||||||
|
break;
|
||||||
|
case (3):
|
||||||
|
await db.execute(
|
||||||
|
"ALTER TABLE PodcastLocal ADD skip_seconds_end INTEGER DEFAULT 0 ");
|
||||||
|
await db.execute(
|
||||||
|
"ALTER TABLE PodcastLocal ADD never_update INTEGER DEFAULT 0 ");
|
||||||
|
await db
|
||||||
|
.execute("ALTER TABLE PodcastLocal ADD funding TEXT DEFAULT '[]' ");
|
||||||
|
break;
|
||||||
|
case (4):
|
||||||
|
await db
|
||||||
|
.execute("ALTER TABLE PodcastLocal ADD funding TEXT DEFAULT '[]' ");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,12 +105,12 @@ class DBHelper {
|
|||||||
if (updateOnly) {
|
if (updateOnly) {
|
||||||
list = await dbClient.rawQuery(
|
list = await dbClient.rawQuery(
|
||||||
"""SELECT id, title, imageUrl, rssUrl, primaryColor, author, imagePath , provider,
|
"""SELECT id, title, imageUrl, rssUrl, primaryColor, author, imagePath , provider,
|
||||||
link ,update_count, episode_count FROM PodcastLocal WHERE id = ? AND
|
link ,update_count, episode_count, funding FROM PodcastLocal WHERE id = ? AND
|
||||||
never_update = 0""", [s]);
|
never_update = 0""", [s]);
|
||||||
} else {
|
} else {
|
||||||
list = await dbClient.rawQuery(
|
list = await dbClient.rawQuery(
|
||||||
"""SELECT id, title, imageUrl, rssUrl, primaryColor, author, imagePath , provider,
|
"""SELECT id, title, imageUrl, rssUrl, primaryColor, author, imagePath , provider,
|
||||||
link ,update_count, episode_count FROM PodcastLocal WHERE id = ?""",
|
link ,update_count, episode_count, funding FROM PodcastLocal WHERE id = ?""",
|
||||||
[s]);
|
[s]);
|
||||||
}
|
}
|
||||||
if (list.length > 0) {
|
if (list.length > 0) {
|
||||||
@ -109,6 +124,7 @@ class DBHelper {
|
|||||||
list.first['imagePath'],
|
list.first['imagePath'],
|
||||||
list.first['provider'],
|
list.first['provider'],
|
||||||
list.first['link'],
|
list.first['link'],
|
||||||
|
List<String>.from(jsonDecode(list.first['funding'])),
|
||||||
updateCount: list.first['update_count'],
|
updateCount: list.first['update_count'],
|
||||||
episodeCount: list.first['episode_count']));
|
episodeCount: list.first['episode_count']));
|
||||||
}
|
}
|
||||||
@ -124,27 +140,29 @@ class DBHelper {
|
|||||||
if (updateOnly) {
|
if (updateOnly) {
|
||||||
list = await dbClient.rawQuery(
|
list = await dbClient.rawQuery(
|
||||||
"""SELECT id, title, imageUrl, rssUrl, primaryColor, author, imagePath,
|
"""SELECT id, title, imageUrl, rssUrl, primaryColor, author, imagePath,
|
||||||
provider, link FROM PodcastLocal WHERE never_update = 0 ORDER BY
|
provider, link, funding FROM PodcastLocal WHERE never_update = 0 ORDER BY
|
||||||
add_date DESC""");
|
add_date DESC""");
|
||||||
} else {
|
} else {
|
||||||
list = await dbClient.rawQuery(
|
list = await dbClient.rawQuery(
|
||||||
"""SELECT id, title, imageUrl, rssUrl, primaryColor, author, imagePath,
|
"""SELECT id, title, imageUrl, rssUrl, primaryColor, author, imagePath,
|
||||||
provider, link FROM PodcastLocal ORDER BY add_date DESC""");
|
provider, link, funding FROM PodcastLocal ORDER BY add_date DESC""");
|
||||||
}
|
}
|
||||||
|
|
||||||
var podcastLocal = <PodcastLocal>[];
|
var podcastLocal = <PodcastLocal>[];
|
||||||
|
|
||||||
for (var i in list) {
|
for (var i in list) {
|
||||||
podcastLocal.add(PodcastLocal(
|
podcastLocal.add(PodcastLocal(
|
||||||
i['title'],
|
i['title'],
|
||||||
i['imageUrl'],
|
i['imageUrl'],
|
||||||
i['rssUrl'],
|
i['rssUrl'],
|
||||||
i['primaryColor'],
|
i['primaryColor'],
|
||||||
i['author'],
|
i['author'],
|
||||||
i['id'],
|
i['id'],
|
||||||
i['imagePath'],
|
i['imagePath'],
|
||||||
list.first['provider'],
|
i['provider'],
|
||||||
list.first['link']));
|
i['link'],
|
||||||
|
List<String>.from(jsonDecode(list.first['funding'])),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
return podcastLocal;
|
return podcastLocal;
|
||||||
}
|
}
|
||||||
@ -153,7 +171,7 @@ class DBHelper {
|
|||||||
var dbClient = await database;
|
var dbClient = await database;
|
||||||
List<Map> list = await dbClient.rawQuery(
|
List<Map> list = await dbClient.rawQuery(
|
||||||
"""SELECT P.id, P.title, P.imageUrl, P.rssUrl, P.primaryColor, P.author, P.imagePath,
|
"""SELECT P.id, P.title, P.imageUrl, P.rssUrl, P.primaryColor, P.author, P.imagePath,
|
||||||
P.provider, P.link ,P.update_count, P.episode_count FROM PodcastLocal P INNER JOIN
|
P.provider, P.link ,P.update_count, P.episode_count, P.funding FROM PodcastLocal P INNER JOIN
|
||||||
Episodes E ON P.id = E.feed_id WHERE E.enclosure_url = ?""", [url]);
|
Episodes E ON P.id = E.feed_id WHERE E.enclosure_url = ?""", [url]);
|
||||||
if (list.isNotEmpty) {
|
if (list.isNotEmpty) {
|
||||||
return PodcastLocal(
|
return PodcastLocal(
|
||||||
@ -166,6 +184,7 @@ class DBHelper {
|
|||||||
list.first['imagePath'],
|
list.first['imagePath'],
|
||||||
list.first['provider'],
|
list.first['provider'],
|
||||||
list.first['link'],
|
list.first['link'],
|
||||||
|
List<String>.from(jsonDecode(list.first['funding'])),
|
||||||
updateCount: list.first['update_count'],
|
updateCount: list.first['update_count'],
|
||||||
episodeCount: list.first['episode_count']);
|
episodeCount: list.first['episode_count']);
|
||||||
}
|
}
|
||||||
@ -271,7 +290,8 @@ class DBHelper {
|
|||||||
await dbClient.transaction((txn) async {
|
await dbClient.transaction((txn) async {
|
||||||
await txn.rawInsert(
|
await txn.rawInsert(
|
||||||
"""INSERT OR IGNORE INTO PodcastLocal (id, title, imageUrl, rssUrl,
|
"""INSERT OR IGNORE INTO PodcastLocal (id, title, imageUrl, rssUrl,
|
||||||
primaryColor, author, description, add_date, imagePath, provider, link) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)""",
|
primaryColor, author, description, add_date, imagePath, provider, link, funding)
|
||||||
|
VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)""",
|
||||||
[
|
[
|
||||||
podcastLocal.id,
|
podcastLocal.id,
|
||||||
podcastLocal.title,
|
podcastLocal.title,
|
||||||
@ -283,7 +303,8 @@ class DBHelper {
|
|||||||
_milliseconds,
|
_milliseconds,
|
||||||
podcastLocal.imagePath,
|
podcastLocal.imagePath,
|
||||||
podcastLocal.provider,
|
podcastLocal.provider,
|
||||||
podcastLocal.link
|
podcastLocal.link,
|
||||||
|
jsonEncode(podcastLocal.funding)
|
||||||
]);
|
]);
|
||||||
await txn.rawInsert(
|
await txn.rawInsert(
|
||||||
"""REPLACE INTO SubscribeHistory(id, title, rss_url, add_date) VALUES (?, ?, ?, ?)""",
|
"""REPLACE INTO SubscribeHistory(id, title, rss_url, add_date) VALUES (?, ?, ?, ?)""",
|
||||||
|
@ -248,7 +248,7 @@ class _PodcastDetailState extends State<PodcastDetail> {
|
|||||||
SizedBox(height: 4),
|
SizedBox(height: 4),
|
||||||
Text(
|
Text(
|
||||||
title,
|
title,
|
||||||
style: TextStyle(fontWeight: FontWeight.bold),
|
style: context.textTheme.subtitle2,
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
maxLines: 2,
|
maxLines: 2,
|
||||||
overflow: TextOverflow.fade,
|
overflow: TextOverflow.fade,
|
||||||
@ -296,6 +296,19 @@ class _PodcastDetailState extends State<PodcastDetail> {
|
|||||||
child: Icon(LineIcons.rss_square_solid, size: 30),
|
child: Icon(LineIcons.rss_square_solid, size: 30),
|
||||||
backgroundColor: Colors.blue[600],
|
backgroundColor: Colors.blue[600],
|
||||||
onTap: () => widget.podcastLocal.rssUrl.launchUrl),
|
onTap: () => widget.podcastLocal.rssUrl.launchUrl),
|
||||||
|
if (widget.podcastLocal.funding.isNotEmpty)
|
||||||
|
for (var funding in widget.podcastLocal.funding)
|
||||||
|
_podcastLink(
|
||||||
|
title: 'Donate',
|
||||||
|
child: Icon(
|
||||||
|
funding.contains(
|
||||||
|
'paypal',
|
||||||
|
)
|
||||||
|
? LineIcons.paypal
|
||||||
|
: LineIcons.donate_solid,
|
||||||
|
size: 30),
|
||||||
|
backgroundColor: Colors.red[600],
|
||||||
|
onTap: () => funding.launchUrl),
|
||||||
if (snapshot.hasData)
|
if (snapshot.hasData)
|
||||||
...snapshot.data.item2
|
...snapshot.data.item2
|
||||||
.map<Widget>((host) {
|
.map<Widget>((host) {
|
||||||
@ -339,8 +352,7 @@ class _PodcastDetailState extends State<PodcastDetail> {
|
|||||||
SizedBox(height: 4),
|
SizedBox(height: 4),
|
||||||
Text(
|
Text(
|
||||||
host.name,
|
host.name,
|
||||||
style: TextStyle(
|
style: context.textTheme.subtitle2,
|
||||||
fontWeight: FontWeight.bold),
|
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
maxLines: 2,
|
maxLines: 2,
|
||||||
overflow: TextOverflow.fade,
|
overflow: TextOverflow.fade,
|
||||||
@ -913,7 +925,7 @@ class _PodcastDetailState extends State<PodcastDetail> {
|
|||||||
Container(
|
Container(
|
||||||
alignment: Alignment.bottomRight,
|
alignment: Alignment.bottomRight,
|
||||||
padding: EdgeInsets.only(
|
padding: EdgeInsets.only(
|
||||||
top: 10, right: 10, bottom: 10),
|
right: 20, bottom: 10),
|
||||||
child: Container(
|
child: Container(
|
||||||
height: 100,
|
height: 100,
|
||||||
width: 100,
|
width: 100,
|
||||||
|
@ -663,8 +663,11 @@ Future<void> subIsolateEntryPoint(SendPort sendPort) async {
|
|||||||
var author = p.itunes.author ?? p.author ?? '';
|
var author = p.itunes.author ?? p.author ?? '';
|
||||||
var provider = p.generator ?? '';
|
var provider = p.generator ?? '';
|
||||||
var link = p.link ?? '';
|
var link = p.link ?? '';
|
||||||
|
var funding = p.podcastFunding.isNotEmpty
|
||||||
|
? [for (var f in p.podcastFunding) f.url]
|
||||||
|
: <String>[];
|
||||||
var podcastLocal = PodcastLocal(p.title, imageUrl, realUrl,
|
var podcastLocal = PodcastLocal(p.title, imageUrl, realUrl,
|
||||||
primaryColor, author, uuid, imagePath, provider, link,
|
primaryColor, author, uuid, imagePath, provider, link, funding,
|
||||||
description: p.description);
|
description: p.description);
|
||||||
|
|
||||||
await dbHelper.savePodcastLocal(podcastLocal);
|
await dbHelper.savePodcastLocal(podcastLocal);
|
||||||
|
@ -22,16 +22,27 @@ class PodcastLocal extends Equatable {
|
|||||||
final int updateCount;
|
final int updateCount;
|
||||||
final int episodeCount;
|
final int episodeCount;
|
||||||
|
|
||||||
|
final List<String> funding;
|
||||||
|
|
||||||
//set setUpdateCount(i) => updateCount = i;
|
//set setUpdateCount(i) => updateCount = i;
|
||||||
|
|
||||||
//set setEpisodeCount(i) => episodeCount = i;
|
//set setEpisodeCount(i) => episodeCount = i;
|
||||||
|
|
||||||
PodcastLocal(this.title, this.imageUrl, this.rssUrl, this.primaryColor,
|
PodcastLocal(
|
||||||
this.author, this.id, this.imagePath, this.provider, this.link,
|
this.title,
|
||||||
{this.description = '', int updateCount, int episodeCount})
|
this.imageUrl,
|
||||||
: assert(rssUrl != null),
|
this.rssUrl,
|
||||||
episodeCount = episodeCount ?? 0,
|
this.primaryColor,
|
||||||
updateCount = updateCount ?? 0;
|
this.author,
|
||||||
|
this.id,
|
||||||
|
this.imagePath,
|
||||||
|
this.provider,
|
||||||
|
this.link,
|
||||||
|
this.funding, {
|
||||||
|
this.description = '',
|
||||||
|
this.updateCount = 0,
|
||||||
|
this.episodeCount = 0,
|
||||||
|
}) : assert(rssUrl != null);
|
||||||
|
|
||||||
ImageProvider get avatarImage {
|
ImageProvider get avatarImage {
|
||||||
return File(imagePath).existsSync()
|
return File(imagePath).existsSync()
|
||||||
@ -46,11 +57,12 @@ class PodcastLocal extends Equatable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
PodcastLocal copyWith({int updateCount, int episodeCount}) {
|
PodcastLocal copyWith({int updateCount, int episodeCount}) {
|
||||||
return PodcastLocal(title, imageUrl, rssUrl, primaryColor, author, id,
|
return PodcastLocal(title, imageUrl, rssUrl, primaryColor, author, id,
|
||||||
imagePath, provider, link,
|
imagePath, provider, link, funding,
|
||||||
description: description,
|
description: description,
|
||||||
updateCount: updateCount ?? 0,
|
updateCount: updateCount ?? 0,
|
||||||
episodeCount: episodeCount ?? 0);
|
episodeCount: episodeCount ?? 0,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user