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
|
if (newReleases.error
|
||||||
case MetadataPluginException(
|
case MetadataPluginException(
|
||||||
errorCode: MetadataPluginErrorCode.noDefaultPlugin,
|
errorCode: MetadataPluginErrorCode.noDefaultMetadataPlugin,
|
||||||
message: _,
|
message: _,
|
||||||
)) {
|
)) {
|
||||||
return const SizedBox.shrink();
|
return const SizedBox.shrink();
|
||||||
|
|||||||
@ -48,7 +48,7 @@ class HomePageBrowseSection extends HookConsumerWidget {
|
|||||||
|
|
||||||
if (browseSections.error
|
if (browseSections.error
|
||||||
case MetadataPluginException(
|
case MetadataPluginException(
|
||||||
errorCode: MetadataPluginErrorCode.noDefaultPlugin,
|
errorCode: MetadataPluginErrorCode.noDefaultMetadataPlugin,
|
||||||
message: _,
|
message: _,
|
||||||
)) {
|
)) {
|
||||||
return const SliverFillRemaining(
|
return const SliverFillRemaining(
|
||||||
|
|||||||
@ -55,7 +55,7 @@ class UserAlbumsPage extends HookConsumerWidget {
|
|||||||
|
|
||||||
if (albumsQuery.error
|
if (albumsQuery.error
|
||||||
case MetadataPluginException(
|
case MetadataPluginException(
|
||||||
errorCode: MetadataPluginErrorCode.noDefaultPlugin,
|
errorCode: MetadataPluginErrorCode.noDefaultMetadataPlugin,
|
||||||
message: _,
|
message: _,
|
||||||
)) {
|
)) {
|
||||||
return const Center(child: NoDefaultMetadataPlugin());
|
return const Center(child: NoDefaultMetadataPlugin());
|
||||||
|
|||||||
@ -60,7 +60,7 @@ class UserArtistsPage extends HookConsumerWidget {
|
|||||||
|
|
||||||
if (artistQuery.error
|
if (artistQuery.error
|
||||||
case MetadataPluginException(
|
case MetadataPluginException(
|
||||||
errorCode: MetadataPluginErrorCode.noDefaultPlugin,
|
errorCode: MetadataPluginErrorCode.noDefaultMetadataPlugin,
|
||||||
message: _,
|
message: _,
|
||||||
)) {
|
)) {
|
||||||
return const Center(child: NoDefaultMetadataPlugin());
|
return const Center(child: NoDefaultMetadataPlugin());
|
||||||
|
|||||||
@ -83,7 +83,7 @@ class UserPlaylistsPage extends HookConsumerWidget {
|
|||||||
|
|
||||||
if (playlistsQuery.error
|
if (playlistsQuery.error
|
||||||
case MetadataPluginException(
|
case MetadataPluginException(
|
||||||
errorCode: MetadataPluginErrorCode.noDefaultPlugin,
|
errorCode: MetadataPluginErrorCode.noDefaultMetadataPlugin,
|
||||||
message: _,
|
message: _,
|
||||||
)) {
|
)) {
|
||||||
return const Center(child: NoDefaultMetadataPlugin());
|
return const Center(child: NoDefaultMetadataPlugin());
|
||||||
|
|||||||
@ -85,7 +85,7 @@ class SearchPage extends HookConsumerWidget {
|
|||||||
child: Builder(builder: (context) {
|
child: Builder(builder: (context) {
|
||||||
if (searchChipSnapshot.error
|
if (searchChipSnapshot.error
|
||||||
case MetadataPluginException(
|
case MetadataPluginException(
|
||||||
errorCode: MetadataPluginErrorCode.noDefaultPlugin,
|
errorCode: MetadataPluginErrorCode.noDefaultMetadataPlugin,
|
||||||
message: _
|
message: _
|
||||||
)) {
|
)) {
|
||||||
return const NoDefaultMetadataPlugin();
|
return const NoDefaultMetadataPlugin();
|
||||||
|
|||||||
@ -144,40 +144,8 @@ class AudioPlayerNotifier extends Notifier<AudioPlayerState> {
|
|||||||
}),
|
}),
|
||||||
audioPlayer.playlistStream.listen((playlist) async {
|
audioPlayer.playlistStream.listen((playlist) async {
|
||||||
try {
|
try {
|
||||||
// Playlist and state has to be in sync. This is only meant for
|
final tracks =
|
||||||
// the shuffle/re-ordering indices to be in sync
|
playlist.medias.map((e) => SpotubeMedia.media(e).track).toList();
|
||||||
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(", ")}",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
state = state.copyWith(
|
state = state.copyWith(
|
||||||
tracks: tracks,
|
tracks: tracks,
|
||||||
@ -434,13 +402,31 @@ class AudioPlayerNotifier extends Notifier<AudioPlayerState> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final currentIndex = state.currentIndex;
|
final oldState = state;
|
||||||
final currentTrack = state.activeTrack as SpotubeFullTrackObject;
|
await audioPlayer.stop();
|
||||||
final swappedMedia = SpotubeMedia(currentTrack);
|
|
||||||
|
|
||||||
await audioPlayer.addTrackAt(swappedMedia, currentIndex + 1);
|
await load(
|
||||||
await audioPlayer.skipToNext();
|
oldState.tracks,
|
||||||
await audioPlayer.removeTrack(currentIndex);
|
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 {
|
Future<void> jumpToTrack(SpotubeTrackObject track) async {
|
||||||
|
|||||||
@ -12,7 +12,7 @@ final metadataPluginAlbumProvider =
|
|||||||
final metadataPlugin = await ref.watch(metadataPluginProvider.future);
|
final metadataPlugin = await ref.watch(metadataPluginProvider.future);
|
||||||
|
|
||||||
if (metadataPlugin == null) {
|
if (metadataPlugin == null) {
|
||||||
throw MetadataPluginException.noDefaultPlugin();
|
throw MetadataPluginException.noDefaultMetadataPlugin();
|
||||||
}
|
}
|
||||||
|
|
||||||
return metadataPlugin.album.getAlbum(id);
|
return metadataPlugin.album.getAlbum(id);
|
||||||
|
|||||||
@ -12,7 +12,7 @@ final metadataPluginArtistProvider =
|
|||||||
final metadataPlugin = await ref.watch(metadataPluginProvider.future);
|
final metadataPlugin = await ref.watch(metadataPluginProvider.future);
|
||||||
|
|
||||||
if (metadataPlugin == null) {
|
if (metadataPlugin == null) {
|
||||||
throw MetadataPluginException.noDefaultPlugin();
|
throw MetadataPluginException.noDefaultMetadataPlugin();
|
||||||
}
|
}
|
||||||
|
|
||||||
return metadataPlugin.artist.getArtist(artistId);
|
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/models/metadata/metadata.dart';
|
||||||
import 'package:spotube/provider/metadata_plugin/metadata_plugin_provider.dart';
|
import 'package:spotube/provider/metadata_plugin/metadata_plugin_provider.dart';
|
||||||
import 'package:spotube/services/audio_player/audio_player.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';
|
import 'package:spotube/services/metadata/metadata.dart';
|
||||||
|
|
||||||
part 'quality_presets.g.dart';
|
part 'quality_presets.g.dart';
|
||||||
@ -61,7 +62,7 @@ class AudioSourceAvailableQualityPresetsNotifier
|
|||||||
audioSourceConfigSnapshot.whenData((audioSourceConfig) {
|
audioSourceConfigSnapshot.whenData((audioSourceConfig) {
|
||||||
audioSourceSnapshot.whenData((audioSource) async {
|
audioSourceSnapshot.whenData((audioSource) async {
|
||||||
if (audioSource == null || audioSourceConfig == null) {
|
if (audioSource == null || audioSourceConfig == null) {
|
||||||
throw Exception("Dude wat?");
|
throw MetadataPluginException.noDefaultAudioSourcePlugin();
|
||||||
}
|
}
|
||||||
final preferences = await SharedPreferences.getInstance();
|
final preferences = await SharedPreferences.getInstance();
|
||||||
final persistedStateStr =
|
final persistedStateStr =
|
||||||
@ -114,7 +115,7 @@ class AudioSourceAvailableQualityPresetsNotifier
|
|||||||
final audioSourceConfig = await ref.read(metadataPluginsProvider
|
final audioSourceConfig = await ref.read(metadataPluginsProvider
|
||||||
.selectAsync((data) => data.defaultAudioSourcePluginConfig));
|
.selectAsync((data) => data.defaultAudioSourcePluginConfig));
|
||||||
if (audioSourceConfig == null) {
|
if (audioSourceConfig == null) {
|
||||||
throw Exception("Dude wat?");
|
throw MetadataPluginException.noDefaultAudioSourcePlugin();
|
||||||
}
|
}
|
||||||
|
|
||||||
final preferences = await SharedPreferences.getInstance();
|
final preferences = await SharedPreferences.getInstance();
|
||||||
|
|||||||
@ -131,7 +131,7 @@ final metadataPluginIsSavedPlaylistProvider =
|
|||||||
final plugin = await ref.watch(metadataPluginProvider.future);
|
final plugin = await ref.watch(metadataPluginProvider.future);
|
||||||
|
|
||||||
if (plugin == null) {
|
if (plugin == null) {
|
||||||
throw MetadataPluginException.noDefaultPlugin();
|
throw MetadataPluginException.noDefaultMetadataPlugin();
|
||||||
}
|
}
|
||||||
|
|
||||||
final savedPlaylists =
|
final savedPlaylists =
|
||||||
|
|||||||
@ -13,7 +13,7 @@ class MetadataPluginPlaylistNotifier
|
|||||||
final metadataPlugin = await ref.read(metadataPluginProvider.future);
|
final metadataPlugin = await ref.read(metadataPluginProvider.future);
|
||||||
|
|
||||||
if (metadataPlugin == null) {
|
if (metadataPlugin == null) {
|
||||||
throw MetadataPluginException.noDefaultPlugin();
|
throw MetadataPluginException.noDefaultMetadataPlugin();
|
||||||
}
|
}
|
||||||
|
|
||||||
return metadataPlugin;
|
return metadataPlugin;
|
||||||
|
|||||||
@ -9,7 +9,7 @@ final metadataPluginSearchAllProvider =
|
|||||||
final metadataPlugin = await ref.watch(metadataPluginProvider.future);
|
final metadataPlugin = await ref.watch(metadataPluginProvider.future);
|
||||||
|
|
||||||
if (metadataPlugin == null) {
|
if (metadataPlugin == null) {
|
||||||
throw MetadataPluginException.noDefaultPlugin();
|
throw MetadataPluginException.noDefaultMetadataPlugin();
|
||||||
}
|
}
|
||||||
|
|
||||||
return metadataPlugin.search.all(query);
|
return metadataPlugin.search.all(query);
|
||||||
@ -20,7 +20,7 @@ final metadataPluginSearchChipsProvider = FutureProvider((ref) async {
|
|||||||
final metadataPlugin = await ref.watch(metadataPluginProvider.future);
|
final metadataPlugin = await ref.watch(metadataPluginProvider.future);
|
||||||
|
|
||||||
if (metadataPlugin == null) {
|
if (metadataPlugin == null) {
|
||||||
throw MetadataPluginException.noDefaultPlugin();
|
throw MetadataPluginException.noDefaultMetadataPlugin();
|
||||||
}
|
}
|
||||||
return metadataPlugin.search.chips;
|
return metadataPlugin.search.chips;
|
||||||
});
|
});
|
||||||
|
|||||||
@ -8,7 +8,7 @@ final metadataPluginTrackProvider =
|
|||||||
final metadataPlugin = await ref.watch(metadataPluginProvider.future);
|
final metadataPlugin = await ref.watch(metadataPluginProvider.future);
|
||||||
|
|
||||||
if (metadataPlugin == null) {
|
if (metadataPlugin == null) {
|
||||||
throw MetadataPluginException.noDefaultPlugin();
|
throw MetadataPluginException.noDefaultMetadataPlugin();
|
||||||
}
|
}
|
||||||
|
|
||||||
return metadataPlugin.track.getTrack(trackId);
|
return metadataPlugin.track.getTrack(trackId);
|
||||||
|
|||||||
@ -20,7 +20,7 @@ mixin MetadataPluginMixin<K>
|
|||||||
final plugin = await ref.read(metadataPluginProvider.future);
|
final plugin = await ref.read(metadataPluginProvider.future);
|
||||||
|
|
||||||
if (plugin == null) {
|
if (plugin == null) {
|
||||||
throw MetadataPluginException.noDefaultPlugin();
|
throw MetadataPluginException.noDefaultMetadataPlugin();
|
||||||
}
|
}
|
||||||
|
|
||||||
return plugin;
|
return plugin;
|
||||||
|
|||||||
@ -95,7 +95,7 @@ class TrackOptionsActions {
|
|||||||
final metadataPlugin = await ref.read(metadataPluginProvider.future);
|
final metadataPlugin = await ref.read(metadataPluginProvider.future);
|
||||||
|
|
||||||
if (metadataPlugin == null) {
|
if (metadataPlugin == null) {
|
||||||
throw MetadataPluginException.noDefaultPlugin();
|
throw MetadataPluginException.noDefaultMetadataPlugin();
|
||||||
}
|
}
|
||||||
|
|
||||||
final tracks = await metadataPlugin.track.radio(track.id);
|
final tracks = await metadataPlugin.track.radio(track.id);
|
||||||
|
|||||||
@ -9,7 +9,8 @@ enum MetadataPluginErrorCode {
|
|||||||
pluginDownloadFailed,
|
pluginDownloadFailed,
|
||||||
duplicatePlugin,
|
duplicatePlugin,
|
||||||
pluginByteCodeFileNotFound,
|
pluginByteCodeFileNotFound,
|
||||||
noDefaultPlugin,
|
noDefaultMetadataPlugin,
|
||||||
|
noDefaultAudiSourcePlugin,
|
||||||
}
|
}
|
||||||
|
|
||||||
class MetadataPluginException implements Exception {
|
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.',
|
'Plugin byte code file, plugin.out not found. Please ensure the plugin is correctly packaged.',
|
||||||
errorCode: MetadataPluginErrorCode.pluginByteCodeFileNotFound,
|
errorCode: MetadataPluginErrorCode.pluginByteCodeFileNotFound,
|
||||||
);
|
);
|
||||||
MetadataPluginException.noDefaultPlugin()
|
MetadataPluginException.noDefaultMetadataPlugin()
|
||||||
: this._(
|
: this._(
|
||||||
'No default metadata plugin is set. Please set a default plugin in the settings.',
|
'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
|
@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/provider/metadata_plugin/metadata_plugin_provider.dart';
|
||||||
import 'package:spotube/services/dio/dio.dart';
|
import 'package:spotube/services/dio/dio.dart';
|
||||||
import 'package:spotube/services/logger/logger.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/services/sourced_track/exceptions.dart';
|
||||||
import 'package:spotube/utils/service_utils.dart';
|
import 'package:spotube/utils/service_utils.dart';
|
||||||
@ -41,7 +42,7 @@ class SourcedTrack extends BasicSourcedTrack {
|
|||||||
final audioSourceConfig = await ref.read(metadataPluginsProvider
|
final audioSourceConfig = await ref.read(metadataPluginsProvider
|
||||||
.selectAsync((data) => data.defaultAudioSourcePluginConfig));
|
.selectAsync((data) => data.defaultAudioSourcePluginConfig));
|
||||||
if (audioSource == null || audioSourceConfig == null) {
|
if (audioSource == null || audioSourceConfig == null) {
|
||||||
throw Exception("Dude wat?");
|
throw MetadataPluginException.noDefaultAudioSourcePlugin();
|
||||||
}
|
}
|
||||||
|
|
||||||
final database = ref.read(databaseProvider);
|
final database = ref.read(databaseProvider);
|
||||||
@ -157,7 +158,7 @@ class SourcedTrack extends BasicSourcedTrack {
|
|||||||
final audioSource = await ref.read(audioSourcePluginProvider.future);
|
final audioSource = await ref.read(audioSourcePluginProvider.future);
|
||||||
|
|
||||||
if (audioSource == null) {
|
if (audioSource == null) {
|
||||||
throw Exception("Dude wat?");
|
throw MetadataPluginException.noDefaultAudioSourcePlugin();
|
||||||
}
|
}
|
||||||
|
|
||||||
final videoResults = <SpotubeAudioSourceMatchObject>[];
|
final videoResults = <SpotubeAudioSourceMatchObject>[];
|
||||||
@ -190,7 +191,8 @@ class SourcedTrack extends BasicSourcedTrack {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<SourcedTrack?> swapWithSibling(
|
Future<SourcedTrack?> swapWithSibling(
|
||||||
SpotubeAudioSourceMatchObject sibling) async {
|
SpotubeAudioSourceMatchObject sibling,
|
||||||
|
) async {
|
||||||
if (sibling.id == info.id) {
|
if (sibling.id == info.id) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -199,7 +201,7 @@ class SourcedTrack extends BasicSourcedTrack {
|
|||||||
final audioSourceConfig = await ref.read(metadataPluginsProvider
|
final audioSourceConfig = await ref.read(metadataPluginsProvider
|
||||||
.selectAsync((data) => data.defaultAudioSourcePluginConfig));
|
.selectAsync((data) => data.defaultAudioSourcePluginConfig));
|
||||||
if (audioSource == null || audioSourceConfig == null) {
|
if (audioSource == null || audioSourceConfig == null) {
|
||||||
throw Exception("Dude wat?");
|
throw MetadataPluginException.noDefaultAudioSourcePlugin();
|
||||||
}
|
}
|
||||||
|
|
||||||
// a sibling source that was fetched from the search results
|
// a sibling source that was fetched from the search results
|
||||||
@ -216,10 +218,19 @@ class SourcedTrack extends BasicSourcedTrack {
|
|||||||
|
|
||||||
final database = ref.read(databaseProvider);
|
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(
|
await database.into(database.sourceMatchTable).insert(
|
||||||
SourceMatchTableCompanion.insert(
|
SourceMatchTableCompanion.insert(
|
||||||
trackId: query.id,
|
trackId: query.id,
|
||||||
sourceInfo: Value(jsonEncode(siblings.first)),
|
sourceInfo: Value(jsonEncode(sibling)),
|
||||||
sourceType: audioSourceConfig.slug,
|
sourceType: audioSourceConfig.slug,
|
||||||
createdAt: Value(DateTime.now()),
|
createdAt: Value(DateTime.now()),
|
||||||
),
|
),
|
||||||
@ -245,7 +256,7 @@ class SourcedTrack extends BasicSourcedTrack {
|
|||||||
final audioSourceConfig = await ref.read(metadataPluginsProvider
|
final audioSourceConfig = await ref.read(metadataPluginsProvider
|
||||||
.selectAsync((data) => data.defaultAudioSourcePluginConfig));
|
.selectAsync((data) => data.defaultAudioSourcePluginConfig));
|
||||||
if (audioSource == null || audioSourceConfig == null) {
|
if (audioSource == null || audioSourceConfig == null) {
|
||||||
throw Exception("Dude wat?");
|
throw MetadataPluginException.noDefaultAudioSourcePlugin();
|
||||||
}
|
}
|
||||||
|
|
||||||
List<SpotubeAudioSourceStreamObject> validStreams = [];
|
List<SpotubeAudioSourceStreamObject> validStreams = [];
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user