🐛 Fix & optimize kugou audio source
🐛 Fix fallback source switch causing error
This commit is contained in:
@ -81,6 +81,16 @@ abstract class SourcedTrack extends Track {
|
||||
};
|
||||
}
|
||||
|
||||
static Type getTrackBySourceInfo(SourceInfo info) {
|
||||
final sourceInfoTrackMap = {
|
||||
YoutubeSourceInfo: YoutubeSourcedTrack,
|
||||
PipedSourceInfo: PipedSourcedTrack,
|
||||
NeteaseSourceInfo: NeteaseSourcedTrack,
|
||||
KugouSourceInfo: KugouSourcedTrack,
|
||||
};
|
||||
return sourceInfoTrackMap[info.runtimeType]!;
|
||||
}
|
||||
|
||||
static String getSearchTerm(Track track) {
|
||||
final artists = (track.artists ?? [])
|
||||
.map((ar) => ar.name)
|
||||
|
@ -109,7 +109,9 @@ class KugouSourcedTrack extends SourcedTrack {
|
||||
|
||||
final hash = manifest is SourceMatchTableData
|
||||
? manifest.sourceId
|
||||
: manifest?['hash'];
|
||||
: manifest is KugouSourceInfo
|
||||
? manifest.id
|
||||
: manifest?['hash'];
|
||||
final key = md5.convert(utf8.encode('${hash}kgcloudv2')).toString();
|
||||
final url =
|
||||
'$baseUrl/song/url?key=$key&hash=$hash&appid=1005&pid=2&cmd=25&behavior=play';
|
||||
@ -142,7 +144,8 @@ class KugouSourcedTrack extends SourcedTrack {
|
||||
// We can just trust kugou music for now
|
||||
// If we need to check is the result correct, refer to this code
|
||||
// https://github.com/KRTirtho/spotube/blob/9b024120601c0d381edeab4460cb22f87149d0f8/lib/services/sourced_track/sources/jiosaavn.dart#L129
|
||||
final matchedResults = results.map(toSiblingType).toList();
|
||||
final matchedResults =
|
||||
results.where((x) => x['pay_type'] == 0).map(toSiblingType).toList();
|
||||
|
||||
return matchedResults.cast<SiblingType>();
|
||||
}
|
||||
@ -166,7 +169,12 @@ class KugouSourcedTrack extends SourcedTrack {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<KugouSourcedTrack?> swapWithSibling(SourceInfo sibling) async {
|
||||
Future<SourcedTrack?> swapWithSibling(SourceInfo sibling) async {
|
||||
if (sibling is! KugouSourceInfo) {
|
||||
return (SourcedTrack.getTrackBySourceInfo(sibling) as SourcedTrack)
|
||||
.swapWithSibling(sibling);
|
||||
}
|
||||
|
||||
if (sibling.id == sourceInfo.id) {
|
||||
return null;
|
||||
}
|
||||
@ -181,7 +189,7 @@ class KugouSourcedTrack extends SourcedTrack {
|
||||
..insert(0, sourceInfo);
|
||||
|
||||
final info = newSourceInfo as KugouSourceInfo;
|
||||
final source = toSourceMap(newSourceInfo.id);
|
||||
final source = toSourceMap(newSourceInfo);
|
||||
|
||||
final db = Get.find<DatabaseProvider>();
|
||||
await db.database.into(db.database.sourceMatchTable).insert(
|
||||
|
@ -200,7 +200,12 @@ class NeteaseSourcedTrack extends SourcedTrack {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<NeteaseSourcedTrack?> swapWithSibling(SourceInfo sibling) async {
|
||||
Future<SourcedTrack?> swapWithSibling(SourceInfo sibling) async {
|
||||
if (sibling is! NeteaseSourceInfo) {
|
||||
return (SourcedTrack.getTrackBySourceInfo(sibling) as SourcedTrack)
|
||||
.swapWithSibling(sibling);
|
||||
}
|
||||
|
||||
if (sibling.id == sourceInfo.id) {
|
||||
return null;
|
||||
}
|
||||
|
@ -255,6 +255,11 @@ class PipedSourcedTrack extends SourcedTrack {
|
||||
|
||||
@override
|
||||
Future<SourcedTrack?> swapWithSibling(SourceInfo sibling) async {
|
||||
if (sibling is! PipedSourceInfo) {
|
||||
return (SourcedTrack.getTrackBySourceInfo(sibling) as SourcedTrack)
|
||||
.swapWithSibling(sibling);
|
||||
}
|
||||
|
||||
if (sibling.id == sourceInfo.id) {
|
||||
return null;
|
||||
}
|
||||
|
@ -269,7 +269,12 @@ class YoutubeSourcedTrack extends SourcedTrack {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<YoutubeSourcedTrack?> swapWithSibling(SourceInfo sibling) async {
|
||||
Future<SourcedTrack?> swapWithSibling(SourceInfo sibling) async {
|
||||
if (sibling is! YoutubeSourceInfo) {
|
||||
return (SourcedTrack.getTrackBySourceInfo(sibling) as SourcedTrack)
|
||||
.swapWithSibling(sibling);
|
||||
}
|
||||
|
||||
if (sibling.id == sourceInfo.id) {
|
||||
return null;
|
||||
}
|
||||
|
Reference in New Issue
Block a user