mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-12-05 23:19:42 +00:00
chore: fix alternative sources not persisting
This commit is contained in:
parent
7ad2066684
commit
4838656dcc
Binary file not shown.
@ -28,7 +28,7 @@ class HomeNewReleasesSection extends HookConsumerWidget {
|
||||
|
||||
if (newReleases.error
|
||||
case MetadataPluginException(
|
||||
errorCode: MetadataPluginErrorCode.noDefaultPlugin,
|
||||
errorCode: MetadataPluginErrorCode.noDefaultMetadataPlugin,
|
||||
message: _,
|
||||
)) {
|
||||
return const SizedBox.shrink();
|
||||
|
||||
@ -48,7 +48,7 @@ class HomePageBrowseSection extends HookConsumerWidget {
|
||||
|
||||
if (browseSections.error
|
||||
case MetadataPluginException(
|
||||
errorCode: MetadataPluginErrorCode.noDefaultPlugin,
|
||||
errorCode: MetadataPluginErrorCode.noDefaultMetadataPlugin,
|
||||
message: _,
|
||||
)) {
|
||||
return const SliverFillRemaining(
|
||||
|
||||
@ -55,7 +55,7 @@ class UserAlbumsPage extends HookConsumerWidget {
|
||||
|
||||
if (albumsQuery.error
|
||||
case MetadataPluginException(
|
||||
errorCode: MetadataPluginErrorCode.noDefaultPlugin,
|
||||
errorCode: MetadataPluginErrorCode.noDefaultMetadataPlugin,
|
||||
message: _,
|
||||
)) {
|
||||
return const Center(child: NoDefaultMetadataPlugin());
|
||||
|
||||
@ -60,7 +60,7 @@ class UserArtistsPage extends HookConsumerWidget {
|
||||
|
||||
if (artistQuery.error
|
||||
case MetadataPluginException(
|
||||
errorCode: MetadataPluginErrorCode.noDefaultPlugin,
|
||||
errorCode: MetadataPluginErrorCode.noDefaultMetadataPlugin,
|
||||
message: _,
|
||||
)) {
|
||||
return const Center(child: NoDefaultMetadataPlugin());
|
||||
|
||||
@ -83,7 +83,7 @@ class UserPlaylistsPage extends HookConsumerWidget {
|
||||
|
||||
if (playlistsQuery.error
|
||||
case MetadataPluginException(
|
||||
errorCode: MetadataPluginErrorCode.noDefaultPlugin,
|
||||
errorCode: MetadataPluginErrorCode.noDefaultMetadataPlugin,
|
||||
message: _,
|
||||
)) {
|
||||
return const Center(child: NoDefaultMetadataPlugin());
|
||||
|
||||
@ -85,7 +85,7 @@ class SearchPage extends HookConsumerWidget {
|
||||
child: Builder(builder: (context) {
|
||||
if (searchChipSnapshot.error
|
||||
case MetadataPluginException(
|
||||
errorCode: MetadataPluginErrorCode.noDefaultPlugin,
|
||||
errorCode: MetadataPluginErrorCode.noDefaultMetadataPlugin,
|
||||
message: _
|
||||
)) {
|
||||
return const NoDefaultMetadataPlugin();
|
||||
|
||||
@ -144,40 +144,8 @@ class AudioPlayerNotifier extends Notifier<AudioPlayerState> {
|
||||
}),
|
||||
audioPlayer.playlistStream.listen((playlist) async {
|
||||
try {
|
||||
// Playlist and state has to be in sync. This is only meant for
|
||||
// the shuffle/re-ordering indices to be in sync
|
||||
if (playlist.medias.length != state.tracks.length) {
|
||||
AppLogger.log.w(
|
||||
"Playlist length does not match state tracks length. Ignoring... "
|
||||
"Playlist length: ${playlist.medias.length}, "
|
||||
"State tracks length: ${state.tracks.length}",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
final trackGroupedById = groupBy(
|
||||
state.tracks,
|
||||
(query) => query.id,
|
||||
);
|
||||
|
||||
final tracks = <SpotubeTrackObject>[];
|
||||
|
||||
for (final media in playlist.medias) {
|
||||
final track = trackGroupedById[SpotubeMedia.media(media).track.id]
|
||||
?.firstOrNull;
|
||||
if (track != null) {
|
||||
tracks.add(track);
|
||||
}
|
||||
}
|
||||
|
||||
if (tracks.length != state.tracks.length) {
|
||||
AppLogger.log.w("Mismatch in tracks after reordering/shuffling.");
|
||||
final missingTracks =
|
||||
state.tracks.where((track) => !tracks.contains(track)).toList();
|
||||
AppLogger.log.w(
|
||||
"Missing tracks: ${missingTracks.map((e) => e.id).join(", ")}",
|
||||
);
|
||||
}
|
||||
final tracks =
|
||||
playlist.medias.map((e) => SpotubeMedia.media(e).track).toList();
|
||||
|
||||
state = state.copyWith(
|
||||
tracks: tracks,
|
||||
@ -434,13 +402,31 @@ class AudioPlayerNotifier extends Notifier<AudioPlayerState> {
|
||||
return;
|
||||
}
|
||||
|
||||
final currentIndex = state.currentIndex;
|
||||
final currentTrack = state.activeTrack as SpotubeFullTrackObject;
|
||||
final swappedMedia = SpotubeMedia(currentTrack);
|
||||
final oldState = state;
|
||||
await audioPlayer.stop();
|
||||
|
||||
await audioPlayer.addTrackAt(swappedMedia, currentIndex + 1);
|
||||
await audioPlayer.skipToNext();
|
||||
await audioPlayer.removeTrack(currentIndex);
|
||||
await load(
|
||||
oldState.tracks,
|
||||
initialIndex: oldState.currentIndex,
|
||||
autoPlay: true,
|
||||
);
|
||||
state = state.copyWith(
|
||||
collections: oldState.collections,
|
||||
loopMode: oldState.loopMode,
|
||||
playing: oldState.playing,
|
||||
shuffled: false,
|
||||
);
|
||||
await audioPlayer.setLoopMode(oldState.loopMode);
|
||||
await _updatePlayerState(
|
||||
AudioPlayerStateTableCompanion(
|
||||
tracks: Value(state.tracks),
|
||||
currentIndex: Value(state.currentIndex),
|
||||
collections: Value(state.collections),
|
||||
loopMode: Value(state.loopMode),
|
||||
playing: Value(state.playing),
|
||||
shuffled: Value(state.shuffled),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> jumpToTrack(SpotubeTrackObject track) async {
|
||||
|
||||
@ -12,7 +12,7 @@ final metadataPluginAlbumProvider =
|
||||
final metadataPlugin = await ref.watch(metadataPluginProvider.future);
|
||||
|
||||
if (metadataPlugin == null) {
|
||||
throw MetadataPluginException.noDefaultPlugin();
|
||||
throw MetadataPluginException.noDefaultMetadataPlugin();
|
||||
}
|
||||
|
||||
return metadataPlugin.album.getAlbum(id);
|
||||
|
||||
@ -12,7 +12,7 @@ final metadataPluginArtistProvider =
|
||||
final metadataPlugin = await ref.watch(metadataPluginProvider.future);
|
||||
|
||||
if (metadataPlugin == null) {
|
||||
throw MetadataPluginException.noDefaultPlugin();
|
||||
throw MetadataPluginException.noDefaultMetadataPlugin();
|
||||
}
|
||||
|
||||
return metadataPlugin.artist.getArtist(artistId);
|
||||
|
||||
@ -6,6 +6,7 @@ import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:spotube/models/metadata/metadata.dart';
|
||||
import 'package:spotube/provider/metadata_plugin/metadata_plugin_provider.dart';
|
||||
import 'package:spotube/services/audio_player/audio_player.dart';
|
||||
import 'package:spotube/services/metadata/errors/exceptions.dart';
|
||||
import 'package:spotube/services/metadata/metadata.dart';
|
||||
|
||||
part 'quality_presets.g.dart';
|
||||
@ -61,7 +62,7 @@ class AudioSourceAvailableQualityPresetsNotifier
|
||||
audioSourceConfigSnapshot.whenData((audioSourceConfig) {
|
||||
audioSourceSnapshot.whenData((audioSource) async {
|
||||
if (audioSource == null || audioSourceConfig == null) {
|
||||
throw Exception("Dude wat?");
|
||||
throw MetadataPluginException.noDefaultAudioSourcePlugin();
|
||||
}
|
||||
final preferences = await SharedPreferences.getInstance();
|
||||
final persistedStateStr =
|
||||
@ -114,7 +115,7 @@ class AudioSourceAvailableQualityPresetsNotifier
|
||||
final audioSourceConfig = await ref.read(metadataPluginsProvider
|
||||
.selectAsync((data) => data.defaultAudioSourcePluginConfig));
|
||||
if (audioSourceConfig == null) {
|
||||
throw Exception("Dude wat?");
|
||||
throw MetadataPluginException.noDefaultAudioSourcePlugin();
|
||||
}
|
||||
|
||||
final preferences = await SharedPreferences.getInstance();
|
||||
|
||||
@ -131,7 +131,7 @@ final metadataPluginIsSavedPlaylistProvider =
|
||||
final plugin = await ref.watch(metadataPluginProvider.future);
|
||||
|
||||
if (plugin == null) {
|
||||
throw MetadataPluginException.noDefaultPlugin();
|
||||
throw MetadataPluginException.noDefaultMetadataPlugin();
|
||||
}
|
||||
|
||||
final savedPlaylists =
|
||||
|
||||
@ -13,7 +13,7 @@ class MetadataPluginPlaylistNotifier
|
||||
final metadataPlugin = await ref.read(metadataPluginProvider.future);
|
||||
|
||||
if (metadataPlugin == null) {
|
||||
throw MetadataPluginException.noDefaultPlugin();
|
||||
throw MetadataPluginException.noDefaultMetadataPlugin();
|
||||
}
|
||||
|
||||
return metadataPlugin;
|
||||
|
||||
@ -9,7 +9,7 @@ final metadataPluginSearchAllProvider =
|
||||
final metadataPlugin = await ref.watch(metadataPluginProvider.future);
|
||||
|
||||
if (metadataPlugin == null) {
|
||||
throw MetadataPluginException.noDefaultPlugin();
|
||||
throw MetadataPluginException.noDefaultMetadataPlugin();
|
||||
}
|
||||
|
||||
return metadataPlugin.search.all(query);
|
||||
@ -20,7 +20,7 @@ final metadataPluginSearchChipsProvider = FutureProvider((ref) async {
|
||||
final metadataPlugin = await ref.watch(metadataPluginProvider.future);
|
||||
|
||||
if (metadataPlugin == null) {
|
||||
throw MetadataPluginException.noDefaultPlugin();
|
||||
throw MetadataPluginException.noDefaultMetadataPlugin();
|
||||
}
|
||||
return metadataPlugin.search.chips;
|
||||
});
|
||||
|
||||
@ -8,7 +8,7 @@ final metadataPluginTrackProvider =
|
||||
final metadataPlugin = await ref.watch(metadataPluginProvider.future);
|
||||
|
||||
if (metadataPlugin == null) {
|
||||
throw MetadataPluginException.noDefaultPlugin();
|
||||
throw MetadataPluginException.noDefaultMetadataPlugin();
|
||||
}
|
||||
|
||||
return metadataPlugin.track.getTrack(trackId);
|
||||
|
||||
@ -20,7 +20,7 @@ mixin MetadataPluginMixin<K>
|
||||
final plugin = await ref.read(metadataPluginProvider.future);
|
||||
|
||||
if (plugin == null) {
|
||||
throw MetadataPluginException.noDefaultPlugin();
|
||||
throw MetadataPluginException.noDefaultMetadataPlugin();
|
||||
}
|
||||
|
||||
return plugin;
|
||||
|
||||
@ -95,7 +95,7 @@ class TrackOptionsActions {
|
||||
final metadataPlugin = await ref.read(metadataPluginProvider.future);
|
||||
|
||||
if (metadataPlugin == null) {
|
||||
throw MetadataPluginException.noDefaultPlugin();
|
||||
throw MetadataPluginException.noDefaultMetadataPlugin();
|
||||
}
|
||||
|
||||
final tracks = await metadataPlugin.track.radio(track.id);
|
||||
|
||||
@ -9,7 +9,8 @@ enum MetadataPluginErrorCode {
|
||||
pluginDownloadFailed,
|
||||
duplicatePlugin,
|
||||
pluginByteCodeFileNotFound,
|
||||
noDefaultPlugin,
|
||||
noDefaultMetadataPlugin,
|
||||
noDefaultAudiSourcePlugin,
|
||||
}
|
||||
|
||||
class MetadataPluginException implements Exception {
|
||||
@ -68,10 +69,15 @@ class MetadataPluginException implements Exception {
|
||||
'Plugin byte code file, plugin.out not found. Please ensure the plugin is correctly packaged.',
|
||||
errorCode: MetadataPluginErrorCode.pluginByteCodeFileNotFound,
|
||||
);
|
||||
MetadataPluginException.noDefaultPlugin()
|
||||
MetadataPluginException.noDefaultMetadataPlugin()
|
||||
: this._(
|
||||
'No default metadata plugin is set. Please set a default plugin in the settings.',
|
||||
errorCode: MetadataPluginErrorCode.noDefaultPlugin,
|
||||
errorCode: MetadataPluginErrorCode.noDefaultMetadataPlugin,
|
||||
);
|
||||
MetadataPluginException.noDefaultAudioSourcePlugin()
|
||||
: this._(
|
||||
'No default audio source plugin is set. Please set a default plugin in the settings.',
|
||||
errorCode: MetadataPluginErrorCode.noDefaultAudiSourcePlugin,
|
||||
);
|
||||
|
||||
@override
|
||||
|
||||
@ -12,6 +12,7 @@ import 'package:spotube/provider/metadata_plugin/audio_source/quality_presets.da
|
||||
import 'package:spotube/provider/metadata_plugin/metadata_plugin_provider.dart';
|
||||
import 'package:spotube/services/dio/dio.dart';
|
||||
import 'package:spotube/services/logger/logger.dart';
|
||||
import 'package:spotube/services/metadata/errors/exceptions.dart';
|
||||
|
||||
import 'package:spotube/services/sourced_track/exceptions.dart';
|
||||
import 'package:spotube/utils/service_utils.dart';
|
||||
@ -41,7 +42,7 @@ class SourcedTrack extends BasicSourcedTrack {
|
||||
final audioSourceConfig = await ref.read(metadataPluginsProvider
|
||||
.selectAsync((data) => data.defaultAudioSourcePluginConfig));
|
||||
if (audioSource == null || audioSourceConfig == null) {
|
||||
throw Exception("Dude wat?");
|
||||
throw MetadataPluginException.noDefaultAudioSourcePlugin();
|
||||
}
|
||||
|
||||
final database = ref.read(databaseProvider);
|
||||
@ -157,7 +158,7 @@ class SourcedTrack extends BasicSourcedTrack {
|
||||
final audioSource = await ref.read(audioSourcePluginProvider.future);
|
||||
|
||||
if (audioSource == null) {
|
||||
throw Exception("Dude wat?");
|
||||
throw MetadataPluginException.noDefaultAudioSourcePlugin();
|
||||
}
|
||||
|
||||
final videoResults = <SpotubeAudioSourceMatchObject>[];
|
||||
@ -190,7 +191,8 @@ class SourcedTrack extends BasicSourcedTrack {
|
||||
}
|
||||
|
||||
Future<SourcedTrack?> swapWithSibling(
|
||||
SpotubeAudioSourceMatchObject sibling) async {
|
||||
SpotubeAudioSourceMatchObject sibling,
|
||||
) async {
|
||||
if (sibling.id == info.id) {
|
||||
return null;
|
||||
}
|
||||
@ -199,7 +201,7 @@ class SourcedTrack extends BasicSourcedTrack {
|
||||
final audioSourceConfig = await ref.read(metadataPluginsProvider
|
||||
.selectAsync((data) => data.defaultAudioSourcePluginConfig));
|
||||
if (audioSource == null || audioSourceConfig == null) {
|
||||
throw Exception("Dude wat?");
|
||||
throw MetadataPluginException.noDefaultAudioSourcePlugin();
|
||||
}
|
||||
|
||||
// a sibling source that was fetched from the search results
|
||||
@ -216,10 +218,19 @@ class SourcedTrack extends BasicSourcedTrack {
|
||||
|
||||
final database = ref.read(databaseProvider);
|
||||
|
||||
// Delete the old Entry
|
||||
await (database.sourceMatchTable.delete()
|
||||
..where(
|
||||
(table) =>
|
||||
table.trackId.equals(query.id) &
|
||||
table.sourceType.equals(audioSourceConfig.slug),
|
||||
))
|
||||
.go();
|
||||
|
||||
await database.into(database.sourceMatchTable).insert(
|
||||
SourceMatchTableCompanion.insert(
|
||||
trackId: query.id,
|
||||
sourceInfo: Value(jsonEncode(siblings.first)),
|
||||
sourceInfo: Value(jsonEncode(sibling)),
|
||||
sourceType: audioSourceConfig.slug,
|
||||
createdAt: Value(DateTime.now()),
|
||||
),
|
||||
@ -245,7 +256,7 @@ class SourcedTrack extends BasicSourcedTrack {
|
||||
final audioSourceConfig = await ref.read(metadataPluginsProvider
|
||||
.selectAsync((data) => data.defaultAudioSourcePluginConfig));
|
||||
if (audioSource == null || audioSourceConfig == null) {
|
||||
throw Exception("Dude wat?");
|
||||
throw MetadataPluginException.noDefaultAudioSourcePlugin();
|
||||
}
|
||||
|
||||
List<SpotubeAudioSourceStreamObject> validStreams = [];
|
||||
|
||||
Loading…
Reference in New Issue
Block a user