From 1913a7e9090645200f62d7bd376e96ebcd53d4f5 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Wed, 11 Sep 2024 20:18:03 +0800 Subject: [PATCH] :bug: Bug fixes on cross source track fetching --- lib/services/sourced_track/sourced_track.dart | 15 +++++++++++++++ lib/services/sourced_track/sources/kugou.dart | 7 ++++++- lib/services/sourced_track/sources/netease.dart | 8 +++++++- lib/services/sourced_track/sources/piped.dart | 8 ++++++++ lib/services/sourced_track/sources/youtube.dart | 7 ++++++- pubspec.yaml | 2 +- 6 files changed, 43 insertions(+), 4 deletions(-) diff --git a/lib/services/sourced_track/sourced_track.dart b/lib/services/sourced_track/sourced_track.dart index eb2db77..212faab 100755 --- a/lib/services/sourced_track/sourced_track.dart +++ b/lib/services/sourced_track/sourced_track.dart @@ -82,6 +82,21 @@ abstract class SourcedTrack extends Track { }; } + static Future reRoutineFetchFromTrack( + Track track, SourceMatchTableData cachedSource) { + final preferences = Get.find().state.value; + final ytOrPiped = preferences.audioSource == AudioSource.piped + ? PipedSourcedTrack.fetchFromTrack + : YoutubeSourcedTrack.fetchFromTrack; + final sourceInfoTrackMap = { + SourceType.youtube: ytOrPiped, + SourceType.youtubeMusic: ytOrPiped, + SourceType.netease: NeteaseSourcedTrack.fetchFromTrack, + SourceType.kugou: KugouSourcedTrack.fetchFromTrack, + }; + return sourceInfoTrackMap[cachedSource.sourceType]!(track: track); + } + Future reRoutineSwapSiblings(SourceInfo info) { final sourceInfoTrackMap = { YoutubeSourceInfo: YoutubeSourcedTrack.fetchFromTrack, diff --git a/lib/services/sourced_track/sources/kugou.dart b/lib/services/sourced_track/sources/kugou.dart index 7b03986..963d335 100644 --- a/lib/services/sourced_track/sources/kugou.dart +++ b/lib/services/sourced_track/sources/kugou.dart @@ -51,7 +51,7 @@ class KugouSourcedTrack extends SourcedTrack { return client; } - static Future fetchFromTrack({ + static Future fetchFromTrack({ required Track track, }) async { final DatabaseProvider db = Get.find(); @@ -86,6 +86,11 @@ class KugouSourcedTrack extends SourcedTrack { sourceInfo: siblings.first.info, track: track, ); + } else if (cachedSource.sourceType != SourceType.kugou) { + final out = + await SourcedTrack.reRoutineFetchFromTrack(track, cachedSource); + if (out == null) throw TrackNotFoundError(track); + return out; } return KugouSourcedTrack( diff --git a/lib/services/sourced_track/sources/netease.dart b/lib/services/sourced_track/sources/netease.dart index 93b9cff..9a50e68 100755 --- a/lib/services/sourced_track/sources/netease.dart +++ b/lib/services/sourced_track/sources/netease.dart @@ -73,7 +73,7 @@ class NeteaseSourcedTrack extends SourcedTrack { return _lookedUpRealIp!; } - static Future fetchFromTrack({ + static Future fetchFromTrack({ required Track track, }) async { final DatabaseProvider db = Get.find(); @@ -114,10 +114,16 @@ class NeteaseSourcedTrack extends SourcedTrack { sourceInfo: siblings.first.info, track: track, ); + } else if (cachedSource.sourceType != SourceType.netease) { + final out = + await SourcedTrack.reRoutineFetchFromTrack(track, cachedSource); + if (out == null) throw TrackNotFoundError(track); + return out; } final client = getClient(); final resp = await client.get('/song/detail?ids=${cachedSource.sourceId}'); + if (resp.body?['songs'] == null) throw TrackNotFoundError(track); final item = (resp.body['songs'] as List).firstOrNull; if (item == null) throw TrackNotFoundError(track); diff --git a/lib/services/sourced_track/sources/piped.dart b/lib/services/sourced_track/sources/piped.dart index a4a8cfc..662c6e5 100755 --- a/lib/services/sourced_track/sources/piped.dart +++ b/lib/services/sourced_track/sources/piped.dart @@ -57,6 +57,14 @@ class PipedSourcedTrack extends SourcedTrack { final preferences = Get.find().state.value; + if (cachedSource?.sourceType != SourceType.youtube && + cachedSource?.sourceType != SourceType.youtubeMusic) { + final out = + await SourcedTrack.reRoutineFetchFromTrack(track, cachedSource!); + if (out == null) throw TrackNotFoundError(track); + return out; + } + if (cachedSource == null) { final siblings = await fetchSiblings(track: track); if (siblings.isEmpty) { diff --git a/lib/services/sourced_track/sources/youtube.dart b/lib/services/sourced_track/sources/youtube.dart index 85b5360..2a6fa65 100755 --- a/lib/services/sourced_track/sources/youtube.dart +++ b/lib/services/sourced_track/sources/youtube.dart @@ -43,7 +43,7 @@ class YoutubeSourcedTrack extends SourcedTrack { required super.track, }); - static Future fetchFromTrack({ + static Future fetchFromTrack({ required Track track, }) async { final DatabaseProvider db = Get.find(); @@ -78,6 +78,11 @@ class YoutubeSourcedTrack extends SourcedTrack { sourceInfo: siblings.first.info, track: track, ); + } else if (cachedSource.sourceType != SourceType.youtube) { + final out = + await SourcedTrack.reRoutineFetchFromTrack(track, cachedSource); + if (out == null) throw TrackNotFoundError(track); + return out; } final item = await youtubeClient.videos.get(cachedSource.sourceId); diff --git a/pubspec.yaml b/pubspec.yaml index 1860eb1..6b15e1c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,7 +16,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. -version: 1.0.0+17 +version: 1.0.0+18 environment: sdk: ^3.5.0