mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-13 07:55:18 +00:00
commit
ba27dc70e4
@ -1,6 +1,10 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
## [4.0.2](https://github.com/krtirtho/spotube/compare/v4.0.1...v4.0.2) (2025-03-16)
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
- invalid access token exception #2525
|
||||||
|
|
||||||
## [4.0.1](https://github.com/krtirtho/spotube/compare/v4.0.0...v4.0.1) (2025-03-15)
|
## [4.0.1](https://github.com/krtirtho/spotube/compare/v4.0.0...v4.0.1) (2025-03-15)
|
||||||
|
|
||||||
|
@ -30,7 +30,6 @@ import 'package:spotube/provider/download_manager_provider.dart';
|
|||||||
import 'package:spotube/provider/local_tracks/local_tracks_provider.dart';
|
import 'package:spotube/provider/local_tracks/local_tracks_provider.dart';
|
||||||
import 'package:spotube/provider/audio_player/audio_player.dart';
|
import 'package:spotube/provider/audio_player/audio_player.dart';
|
||||||
import 'package:spotube/provider/spotify/spotify.dart';
|
import 'package:spotube/provider/spotify/spotify.dart';
|
||||||
import 'package:spotube/provider/spotify_provider.dart';
|
|
||||||
|
|
||||||
import 'package:url_launcher/url_launcher_string.dart';
|
import 'package:url_launcher/url_launcher_string.dart';
|
||||||
|
|
||||||
@ -122,8 +121,9 @@ class TrackOptions extends HookConsumerWidget {
|
|||||||
final playlist = ref.read(audioPlayerProvider);
|
final playlist = ref.read(audioPlayerProvider);
|
||||||
final spotify = ref.read(spotifyProvider);
|
final spotify = ref.read(spotifyProvider);
|
||||||
final query = "${track.name} Radio";
|
final query = "${track.name} Radio";
|
||||||
final pages =
|
final pages = await spotify.invoke(
|
||||||
await spotify.search.get(query, types: [SearchType.playlist]).first();
|
(api) => api.search.get(query, types: [SearchType.playlist]).first(),
|
||||||
|
);
|
||||||
|
|
||||||
final radios = pages
|
final radios = pages
|
||||||
.expand((e) => e.items?.cast<PlaylistSimple>().toList() ?? [])
|
.expand((e) => e.items?.cast<PlaylistSimple>().toList() ?? [])
|
||||||
@ -165,8 +165,9 @@ class TrackOptions extends HookConsumerWidget {
|
|||||||
await playback.addTrack(track);
|
await playback.addTrack(track);
|
||||||
}
|
}
|
||||||
|
|
||||||
final tracks =
|
final tracks = await spotify.invoke(
|
||||||
await spotify.playlists.getTracksByPlaylistId(radio.id!).all();
|
(api) => api.playlists.getTracksByPlaylistId(radio.id!).all(),
|
||||||
|
);
|
||||||
|
|
||||||
await playback.addTracks(
|
await playback.addTracks(
|
||||||
tracks.toList()
|
tracks.toList()
|
||||||
|
@ -191,8 +191,7 @@ class TrackTile extends HookConsumerWidget {
|
|||||||
const SizedBox(
|
const SizedBox(
|
||||||
width: 26,
|
width: 26,
|
||||||
height: 26,
|
height: 26,
|
||||||
child:
|
child: CircularProgressIndicator(),
|
||||||
CircularProgressIndicator(size: 1.5),
|
|
||||||
),
|
),
|
||||||
(_, _, true, _, _) => Icon(
|
(_, _, true, _, _) => Icon(
|
||||||
SpotubeIcons.pause,
|
SpotubeIcons.pause,
|
||||||
|
@ -5,7 +5,7 @@ import 'package:flutter_hooks/flutter_hooks.dart';
|
|||||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
import 'package:spotube/collections/routes.dart';
|
import 'package:spotube/collections/routes.dart';
|
||||||
import 'package:spotube/collections/routes.gr.dart';
|
import 'package:spotube/collections/routes.gr.dart';
|
||||||
import 'package:spotube/provider/spotify_provider.dart';
|
import 'package:spotube/provider/spotify/spotify.dart';
|
||||||
import 'package:flutter_sharing_intent/flutter_sharing_intent.dart';
|
import 'package:flutter_sharing_intent/flutter_sharing_intent.dart';
|
||||||
import 'package:flutter_sharing_intent/model/sharing_file.dart';
|
import 'package:flutter_sharing_intent/model/sharing_file.dart';
|
||||||
import 'package:spotube/services/logger/logger.dart';
|
import 'package:spotube/services/logger/logger.dart';
|
||||||
@ -27,7 +27,9 @@ void useDeepLinking(WidgetRef ref, AppRouter router) {
|
|||||||
|
|
||||||
switch (url.pathSegments.first) {
|
switch (url.pathSegments.first) {
|
||||||
case "album":
|
case "album":
|
||||||
final album = await spotify.albums.get(url.pathSegments.last);
|
final album = await spotify.invoke((api) {
|
||||||
|
return api.albums.get(url.pathSegments.last);
|
||||||
|
});
|
||||||
router.navigate(
|
router.navigate(
|
||||||
AlbumRoute(id: album.id!, album: album),
|
AlbumRoute(id: album.id!, album: album),
|
||||||
);
|
);
|
||||||
@ -36,7 +38,9 @@ void useDeepLinking(WidgetRef ref, AppRouter router) {
|
|||||||
router.navigate(ArtistRoute(artistId: url.pathSegments.last));
|
router.navigate(ArtistRoute(artistId: url.pathSegments.last));
|
||||||
break;
|
break;
|
||||||
case "playlist":
|
case "playlist":
|
||||||
final playlist = await spotify.playlists.get(url.pathSegments.last);
|
final playlist = await spotify.invoke((api) {
|
||||||
|
return api.playlists.get(url.pathSegments.last);
|
||||||
|
});
|
||||||
router
|
router
|
||||||
.navigate(PlaylistRoute(id: playlist.id!, playlist: playlist));
|
.navigate(PlaylistRoute(id: playlist.id!, playlist: playlist));
|
||||||
break;
|
break;
|
||||||
@ -65,7 +69,9 @@ void useDeepLinking(WidgetRef ref, AppRouter router) {
|
|||||||
|
|
||||||
switch (startSegment) {
|
switch (startSegment) {
|
||||||
case "spotify:album":
|
case "spotify:album":
|
||||||
final album = await spotify.albums.get(endSegment);
|
final album = await spotify.invoke((api) {
|
||||||
|
return api.albums.get(endSegment);
|
||||||
|
});
|
||||||
await router.navigate(
|
await router.navigate(
|
||||||
AlbumRoute(id: album.id!, album: album),
|
AlbumRoute(id: album.id!, album: album),
|
||||||
);
|
);
|
||||||
@ -77,7 +83,9 @@ void useDeepLinking(WidgetRef ref, AppRouter router) {
|
|||||||
await router.navigate(TrackRoute(trackId: endSegment));
|
await router.navigate(TrackRoute(trackId: endSegment));
|
||||||
break;
|
break;
|
||||||
case "spotify:playlist":
|
case "spotify:playlist":
|
||||||
final playlist = await spotify.playlists.get(endSegment);
|
final playlist = await spotify.invoke((api) {
|
||||||
|
return api.playlists.get(endSegment);
|
||||||
|
});
|
||||||
await router.navigate(
|
await router.navigate(
|
||||||
PlaylistRoute(id: playlist.id!, playlist: playlist),
|
PlaylistRoute(id: playlist.id!, playlist: playlist),
|
||||||
);
|
);
|
||||||
|
@ -4,7 +4,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|||||||
import 'package:spotify/spotify.dart';
|
import 'package:spotify/spotify.dart';
|
||||||
import 'package:spotube/provider/authentication/authentication.dart';
|
import 'package:spotube/provider/authentication/authentication.dart';
|
||||||
import 'package:spotube/provider/audio_player/audio_player.dart';
|
import 'package:spotube/provider/audio_player/audio_player.dart';
|
||||||
import 'package:spotube/provider/spotify_provider.dart';
|
import 'package:spotube/provider/spotify/spotify.dart';
|
||||||
import 'package:spotube/provider/user_preferences/user_preferences_provider.dart';
|
import 'package:spotube/provider/user_preferences/user_preferences_provider.dart';
|
||||||
import 'package:spotube/services/audio_player/audio_player.dart';
|
import 'package:spotube/services/audio_player/audio_player.dart';
|
||||||
|
|
||||||
@ -28,8 +28,8 @@ void useEndlessPlayback(WidgetRef ref) {
|
|||||||
final track = playlist.tracks.last;
|
final track = playlist.tracks.last;
|
||||||
|
|
||||||
final query = "${track.name} Radio";
|
final query = "${track.name} Radio";
|
||||||
final pages = await spotify.search
|
final pages = await spotify.invoke((api) =>
|
||||||
.get(query, types: [SearchType.playlist]).first();
|
api.search.get(query, types: [SearchType.playlist]).first());
|
||||||
|
|
||||||
final radios = pages
|
final radios = pages
|
||||||
.expand((e) => e.items?.toList() ?? <PlaylistSimple>[])
|
.expand((e) => e.items?.toList() ?? <PlaylistSimple>[])
|
||||||
@ -50,8 +50,8 @@ void useEndlessPlayback(WidgetRef ref) {
|
|||||||
orElse: () => radios.first,
|
orElse: () => radios.first,
|
||||||
);
|
);
|
||||||
|
|
||||||
final tracks =
|
final tracks = await spotify.invoke(
|
||||||
await spotify.playlists.getTracksByPlaylistId(radio.id!).all();
|
(api) => api.playlists.getTracksByPlaylistId(radio.id!).all());
|
||||||
|
|
||||||
await playback.addTracks(
|
await playback.addTracks(
|
||||||
tracks.toList()
|
tracks.toList()
|
||||||
|
@ -8,7 +8,7 @@ import 'package:spotube/collections/routes.gr.dart';
|
|||||||
import 'package:spotube/collections/spotube_icons.dart';
|
import 'package:spotube/collections/spotube_icons.dart';
|
||||||
import 'package:spotube/components/image/universal_image.dart';
|
import 'package:spotube/components/image/universal_image.dart';
|
||||||
import 'package:spotube/models/spotify_friends.dart';
|
import 'package:spotube/models/spotify_friends.dart';
|
||||||
import 'package:spotube/provider/spotify_provider.dart';
|
import 'package:spotube/provider/spotify/spotify.dart';
|
||||||
|
|
||||||
class FriendItem extends HookConsumerWidget {
|
class FriendItem extends HookConsumerWidget {
|
||||||
final SpotifyFriendActivity friend;
|
final SpotifyFriendActivity friend;
|
||||||
@ -95,8 +95,9 @@ class FriendItem extends HookConsumerWidget {
|
|||||||
text: " ${friend.track.album.name}",
|
text: " ${friend.track.album.name}",
|
||||||
recognizer: TapGestureRecognizer()
|
recognizer: TapGestureRecognizer()
|
||||||
..onTap = () async {
|
..onTap = () async {
|
||||||
final album =
|
final album = await spotify.invoke(
|
||||||
await spotify.albums.get(friend.track.album.id);
|
(api) => api.albums.get(friend.track.album.id),
|
||||||
|
);
|
||||||
if (context.mounted) {
|
if (context.mounted) {
|
||||||
context.navigateTo(
|
context.navigateTo(
|
||||||
AlbumRoute(id: album.id!, album: album),
|
AlbumRoute(id: album.id!, album: album),
|
||||||
|
@ -19,7 +19,6 @@ import 'package:spotube/components/image/universal_image.dart';
|
|||||||
import 'package:spotube/extensions/context.dart';
|
import 'package:spotube/extensions/context.dart';
|
||||||
import 'package:spotube/extensions/image.dart';
|
import 'package:spotube/extensions/image.dart';
|
||||||
import 'package:spotube/provider/spotify/spotify.dart';
|
import 'package:spotube/provider/spotify/spotify.dart';
|
||||||
import 'package:spotube/provider/spotify_provider.dart';
|
|
||||||
|
|
||||||
class PlaylistCreateDialog extends HookConsumerWidget {
|
class PlaylistCreateDialog extends HookConsumerWidget {
|
||||||
/// Track ids to add to the playlist
|
/// Track ids to add to the playlist
|
||||||
@ -260,7 +259,7 @@ class PlaylistCreateDialog extends HookConsumerWidget {
|
|||||||
class PlaylistCreateDialogButton extends HookConsumerWidget {
|
class PlaylistCreateDialogButton extends HookConsumerWidget {
|
||||||
const PlaylistCreateDialogButton({super.key});
|
const PlaylistCreateDialogButton({super.key});
|
||||||
|
|
||||||
showPlaylistDialog(BuildContext context, SpotifyApi spotify) {
|
showPlaylistDialog(BuildContext context, SpotifyApiWrapper spotify) {
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
alignment: Alignment.center,
|
alignment: Alignment.center,
|
||||||
|
@ -22,7 +22,6 @@ import 'package:spotube/extensions/context.dart';
|
|||||||
import 'package:spotube/extensions/image.dart';
|
import 'package:spotube/extensions/image.dart';
|
||||||
import 'package:spotube/models/spotify/recommendation_seeds.dart';
|
import 'package:spotube/models/spotify/recommendation_seeds.dart';
|
||||||
import 'package:spotube/provider/spotify/spotify.dart';
|
import 'package:spotube/provider/spotify/spotify.dart';
|
||||||
import 'package:spotube/provider/spotify_provider.dart';
|
|
||||||
import 'package:spotube/provider/user_preferences/user_preferences_provider.dart';
|
import 'package:spotube/provider/user_preferences/user_preferences_provider.dart';
|
||||||
import 'package:auto_route/auto_route.dart';
|
import 'package:auto_route/auto_route.dart';
|
||||||
|
|
||||||
@ -70,7 +69,8 @@ class PlaylistGeneratorPage extends HookConsumerWidget {
|
|||||||
leftSeedCount,
|
leftSeedCount,
|
||||||
context.l10n.artists,
|
context.l10n.artists,
|
||||||
)),
|
)),
|
||||||
fetchSeeds: (textEditingValue) => spotify.search
|
fetchSeeds: (textEditingValue) => spotify.invoke(
|
||||||
|
(api) => api.search
|
||||||
.get(
|
.get(
|
||||||
textEditingValue.text,
|
textEditingValue.text,
|
||||||
types: [SearchType.artist],
|
types: [SearchType.artist],
|
||||||
@ -86,6 +86,7 @@ class PlaylistGeneratorPage extends HookConsumerWidget {
|
|||||||
)
|
)
|
||||||
.toList(),
|
.toList(),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
autocompleteOptionBuilder: (option, onSelected) => ButtonTile(
|
autocompleteOptionBuilder: (option, onSelected) => ButtonTile(
|
||||||
leading: Avatar(
|
leading: Avatar(
|
||||||
initials: "O",
|
initials: "O",
|
||||||
@ -146,7 +147,8 @@ class PlaylistGeneratorPage extends HookConsumerWidget {
|
|||||||
leftSeedCount,
|
leftSeedCount,
|
||||||
context.l10n.tracks,
|
context.l10n.tracks,
|
||||||
)),
|
)),
|
||||||
fetchSeeds: (textEditingValue) => spotify.search
|
fetchSeeds: (textEditingValue) => spotify.invoke(
|
||||||
|
(api) => api.search
|
||||||
.get(
|
.get(
|
||||||
textEditingValue.text,
|
textEditingValue.text,
|
||||||
types: [SearchType.track],
|
types: [SearchType.track],
|
||||||
@ -162,6 +164,7 @@ class PlaylistGeneratorPage extends HookConsumerWidget {
|
|||||||
)
|
)
|
||||||
.toList(),
|
.toList(),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
autocompleteOptionBuilder: (option, onSelected) => ButtonTile(
|
autocompleteOptionBuilder: (option, onSelected) => ButtonTile(
|
||||||
leading: Avatar(
|
leading: Avatar(
|
||||||
initials: option.name!.substring(0, 1),
|
initials: option.name!.substring(0, 1),
|
||||||
|
@ -15,6 +15,7 @@ import 'package:spotube/components/dialogs/prompt_dialog.dart';
|
|||||||
import 'package:spotube/extensions/context.dart';
|
import 'package:spotube/extensions/context.dart';
|
||||||
import 'package:spotube/models/database/database.dart';
|
import 'package:spotube/models/database/database.dart';
|
||||||
import 'package:spotube/provider/database/database.dart';
|
import 'package:spotube/provider/database/database.dart';
|
||||||
|
import 'package:spotube/services/logger/logger.dart';
|
||||||
import 'package:spotube/utils/platform.dart';
|
import 'package:spotube/utils/platform.dart';
|
||||||
import 'package:otp_util/otp_util.dart';
|
import 'package:otp_util/otp_util.dart';
|
||||||
// ignore: implementation_imports
|
// ignore: implementation_imports
|
||||||
@ -197,6 +198,34 @@ class AuthenticationNotifier extends AsyncNotifier<AuthenticationTableData?> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<Response> getToken({
|
||||||
|
required String totp,
|
||||||
|
required int timestamp,
|
||||||
|
String mode = "transport",
|
||||||
|
String? spDc,
|
||||||
|
}) async {
|
||||||
|
assert(mode == "transport" || mode == "init");
|
||||||
|
|
||||||
|
final accessTokenUrl = Uri.parse(
|
||||||
|
"https://open.spotify.com/get_access_token?reason=$mode&productType=web-player"
|
||||||
|
"&totp=$totp&totpVer=5&ts=$timestamp",
|
||||||
|
);
|
||||||
|
|
||||||
|
final res = await dio.getUri(
|
||||||
|
accessTokenUrl,
|
||||||
|
options: Options(
|
||||||
|
headers: {
|
||||||
|
"Cookie": spDc ?? "",
|
||||||
|
"User-Agent": ServiceUtils.randomUserAgent(
|
||||||
|
kIsDesktop ? UserAgentDevice.desktop : UserAgentDevice.mobile,
|
||||||
|
),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
Future<AuthenticationTableCompanion> credentialsFromCookie(
|
Future<AuthenticationTableCompanion> credentialsFromCookie(
|
||||||
String cookie,
|
String cookie,
|
||||||
) async {
|
) async {
|
||||||
@ -207,24 +236,34 @@ class AuthenticationNotifier extends AsyncNotifier<AuthenticationTableData?> {
|
|||||||
?.trim();
|
?.trim();
|
||||||
|
|
||||||
final totp = await generateTotp();
|
final totp = await generateTotp();
|
||||||
|
|
||||||
final timestamp = (DateTime.now().millisecondsSinceEpoch / 1000).floor();
|
final timestamp = (DateTime.now().millisecondsSinceEpoch / 1000).floor();
|
||||||
|
|
||||||
final accessTokenUrl = Uri.parse(
|
var res = await getToken(
|
||||||
"https://open.spotify.com/get_access_token?reason=transport&productType=web_player"
|
totp: totp,
|
||||||
"&totp=$totp&totpVer=5&ts=$timestamp",
|
timestamp: timestamp,
|
||||||
|
spDc: spDc,
|
||||||
|
mode: "transport",
|
||||||
);
|
);
|
||||||
|
|
||||||
final res = await dio.getUri(
|
if ((res.data["accessToken"]?.length ?? 0) != 374) {
|
||||||
accessTokenUrl,
|
res = await getToken(
|
||||||
options: Options(
|
totp: totp,
|
||||||
headers: {
|
timestamp: timestamp,
|
||||||
"Cookie": spDc ?? "",
|
spDc: spDc,
|
||||||
"User-Agent":
|
mode: "init",
|
||||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36"
|
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
final body = res.data;
|
}
|
||||||
|
|
||||||
|
final body = res.data as Map<String, dynamic>;
|
||||||
|
|
||||||
|
if (body["accessToken"] == null) {
|
||||||
|
AppLogger.reportError(
|
||||||
|
"The access token is only ${body["accessToken"]?.length} characters long instead of 374\n"
|
||||||
|
"Your authentication probably doesn't work",
|
||||||
|
StackTrace.current,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return AuthenticationTableCompanion.insert(
|
return AuthenticationTableCompanion.insert(
|
||||||
id: const Value(0),
|
id: const Value(0),
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
import 'package:spotube/provider/authentication/authentication.dart';
|
import 'package:spotube/provider/authentication/authentication.dart';
|
||||||
import 'package:spotube/provider/spotify_provider.dart';
|
import 'package:spotube/provider/spotify/spotify.dart';
|
||||||
import 'package:spotube/services/custom_spotify_endpoints/spotify_endpoints.dart';
|
import 'package:spotube/services/custom_spotify_endpoints/spotify_endpoints.dart';
|
||||||
|
|
||||||
final customSpotifyEndpointProvider = Provider<CustomSpotifyEndpoints>((ref) {
|
final customSpotifyEndpointProvider = Provider<CustomSpotifyEndpoints>((ref) {
|
||||||
|
@ -76,8 +76,6 @@ final localTracksProvider =
|
|||||||
final mime = lookupMimeType(e.path) ??
|
final mime = lookupMimeType(e.path) ??
|
||||||
(extension(e.path) == ".opus" ? "audio/opus" : null);
|
(extension(e.path) == ".opus" ? "audio/opus" : null);
|
||||||
|
|
||||||
print("${basename(e.path)}: $mime");
|
|
||||||
|
|
||||||
return e is File && supportedAudioTypes.contains(mime);
|
return e is File && supportedAudioTypes.contains(mime);
|
||||||
},
|
},
|
||||||
).cast<File>(),
|
).cast<File>(),
|
||||||
|
@ -22,11 +22,14 @@ class FavoriteAlbumState extends PaginatedState<AlbumSimple> {
|
|||||||
class FavoriteAlbumNotifier
|
class FavoriteAlbumNotifier
|
||||||
extends PaginatedAsyncNotifier<AlbumSimple, FavoriteAlbumState> {
|
extends PaginatedAsyncNotifier<AlbumSimple, FavoriteAlbumState> {
|
||||||
@override
|
@override
|
||||||
Future<List<AlbumSimple>> fetch(int offset, int limit) {
|
Future<List<AlbumSimple>> fetch(int offset, int limit) async {
|
||||||
return spotify.me
|
return await spotify
|
||||||
.savedAlbums()
|
.invoke(
|
||||||
.getPage(limit, offset)
|
(api) => api.me.savedAlbums().getPage(limit, offset),
|
||||||
.then((value) => value.items?.toList() ?? []);
|
)
|
||||||
|
.then(
|
||||||
|
(value) => value.items?.toList() ?? <AlbumSimple>[],
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -45,8 +48,10 @@ class FavoriteAlbumNotifier
|
|||||||
if (state.value == null) return;
|
if (state.value == null) return;
|
||||||
|
|
||||||
state = await AsyncValue.guard(() async {
|
state = await AsyncValue.guard(() async {
|
||||||
await spotify.me.saveAlbums(ids);
|
await spotify.invoke((api) => api.me.saveAlbums(ids));
|
||||||
final albums = await spotify.albums.list(ids);
|
final albums = await spotify.invoke(
|
||||||
|
(api) => api.albums.list(ids),
|
||||||
|
);
|
||||||
|
|
||||||
return state.value!.copyWith(
|
return state.value!.copyWith(
|
||||||
items: [
|
items: [
|
||||||
@ -65,7 +70,7 @@ class FavoriteAlbumNotifier
|
|||||||
if (state.value == null) return;
|
if (state.value == null) return;
|
||||||
|
|
||||||
state = await AsyncValue.guard(() async {
|
state = await AsyncValue.guard(() async {
|
||||||
await spotify.me.removeAlbums(ids);
|
await spotify.invoke((api) => api.me.removeAlbums(ids));
|
||||||
|
|
||||||
return state.value!.copyWith(
|
return state.value!.copyWith(
|
||||||
items: state.value!.items
|
items: state.value!.items
|
||||||
|
@ -3,8 +3,10 @@ part of '../spotify.dart';
|
|||||||
final albumsIsSavedProvider = FutureProvider.autoDispose.family<bool, String>(
|
final albumsIsSavedProvider = FutureProvider.autoDispose.family<bool, String>(
|
||||||
(ref, albumId) async {
|
(ref, albumId) async {
|
||||||
final spotify = ref.watch(spotifyProvider);
|
final spotify = ref.watch(spotifyProvider);
|
||||||
return spotify.me.containsSavedAlbums([albumId]).then(
|
return spotify.invoke(
|
||||||
|
(api) => api.me.containsSavedAlbums([albumId]).then(
|
||||||
(value) => value[albumId] ?? false,
|
(value) => value[albumId] ?? false,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
@ -32,9 +32,9 @@ class AlbumReleasesNotifier
|
|||||||
fetch(int offset, int limit) async {
|
fetch(int offset, int limit) async {
|
||||||
final market = ref.read(userPreferencesProvider).market;
|
final market = ref.read(userPreferencesProvider).market;
|
||||||
|
|
||||||
final albums = await spotify.browse
|
final albums = await spotify.invoke(
|
||||||
.newReleases(country: market)
|
(api) => api.browse.newReleases(country: market).getPage(limit, offset),
|
||||||
.getPage(limit, offset);
|
);
|
||||||
|
|
||||||
return albums.items?.map((album) => album.toAlbum()).toList() ?? [];
|
return albums.items?.map((album) => album.toAlbum()).toList() ?? [];
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,9 @@ class AlbumTracksNotifier extends AutoDisposeFamilyPaginatedAsyncNotifier<Track,
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
fetch(arg, offset, limit) async {
|
fetch(arg, offset, limit) async {
|
||||||
final tracks = await spotify.albums.tracks(arg.id!).getPage(limit, offset);
|
final tracks = await spotify.invoke(
|
||||||
|
(api) => api.albums.tracks(arg.id!).getPage(limit, offset),
|
||||||
|
);
|
||||||
final items = tracks.items?.map((e) => e.asTrack(arg)).toList() ?? [];
|
final items = tracks.items?.map((e) => e.asTrack(arg)).toList() ?? [];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -31,9 +31,9 @@ class ArtistAlbumsNotifier extends AutoDisposeFamilyPaginatedAsyncNotifier<
|
|||||||
@override
|
@override
|
||||||
fetch(arg, offset, limit) async {
|
fetch(arg, offset, limit) async {
|
||||||
final market = ref.read(userPreferencesProvider).market;
|
final market = ref.read(userPreferencesProvider).market;
|
||||||
final albums = await spotify.artists
|
final albums = await spotify.invoke(
|
||||||
.albums(arg, country: market)
|
(api) => api.artists.albums(arg, country: market).getPage(limit, offset),
|
||||||
.getPage(limit, offset);
|
);
|
||||||
|
|
||||||
final items = albums.items?.toList() ?? [];
|
final items = albums.items?.toList() ?? [];
|
||||||
|
|
||||||
|
@ -6,5 +6,5 @@ final artistProvider =
|
|||||||
|
|
||||||
final spotify = ref.watch(spotifyProvider);
|
final spotify = ref.watch(spotifyProvider);
|
||||||
|
|
||||||
return spotify.artists.get(artistId);
|
return spotify.invoke((api) => api.artists.get(artistId));
|
||||||
});
|
});
|
||||||
|
@ -33,9 +33,11 @@ class FollowedArtistsNotifier
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
fetch(offset, limit) async {
|
fetch(offset, limit) async {
|
||||||
final artists = await spotify.me.following(FollowingType.artist).getPage(
|
final artists = await spotify.invoke(
|
||||||
|
(api) => api.me.following(FollowingType.artist).getPage(
|
||||||
limit,
|
limit,
|
||||||
offset ?? '',
|
offset ?? '',
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
return (artists.items?.toList() ?? [], artists.after);
|
return (artists.items?.toList() ?? [], artists.after);
|
||||||
@ -55,7 +57,9 @@ class FollowedArtistsNotifier
|
|||||||
|
|
||||||
Future<void> _followArtists(List<String> artistIds) async {
|
Future<void> _followArtists(List<String> artistIds) async {
|
||||||
try {
|
try {
|
||||||
final creds = await spotify.getCredentials();
|
final creds = await spotify.invoke(
|
||||||
|
(api) => api.getCredentials(),
|
||||||
|
);
|
||||||
|
|
||||||
await dio.post(
|
await dio.post(
|
||||||
"https://api-partner.spotify.com/pathfinder/v1/query",
|
"https://api-partner.spotify.com/pathfinder/v1/query",
|
||||||
@ -93,7 +97,9 @@ class FollowedArtistsNotifier
|
|||||||
await _followArtists(artistIds);
|
await _followArtists(artistIds);
|
||||||
|
|
||||||
state = await AsyncValue.guard(() async {
|
state = await AsyncValue.guard(() async {
|
||||||
final artists = await spotify.artists.list(artistIds);
|
final artists = await spotify.invoke(
|
||||||
|
(api) => api.artists.list(artistIds),
|
||||||
|
);
|
||||||
|
|
||||||
return state.value!.copyWith(
|
return state.value!.copyWith(
|
||||||
items: [
|
items: [
|
||||||
@ -110,7 +116,9 @@ class FollowedArtistsNotifier
|
|||||||
|
|
||||||
Future<void> removeArtists(List<String> artistIds) async {
|
Future<void> removeArtists(List<String> artistIds) async {
|
||||||
if (state.value == null) return;
|
if (state.value == null) return;
|
||||||
await spotify.me.unfollow(FollowingType.artist, artistIds);
|
await spotify.invoke(
|
||||||
|
(api) => api.me.unfollow(FollowingType.artist, artistIds),
|
||||||
|
);
|
||||||
|
|
||||||
state = await AsyncValue.guard(() async {
|
state = await AsyncValue.guard(() async {
|
||||||
final artists = state.value!.items.where((artist) {
|
final artists = state.value!.items.where((artist) {
|
||||||
@ -136,7 +144,9 @@ final followedArtistsProvider =
|
|||||||
final allFollowedArtistsProvider = FutureProvider<List<Artist>>(
|
final allFollowedArtistsProvider = FutureProvider<List<Artist>>(
|
||||||
(ref) async {
|
(ref) async {
|
||||||
final spotify = ref.watch(spotifyProvider);
|
final spotify = ref.watch(spotifyProvider);
|
||||||
final artists = await spotify.me.following(FollowingType.artist).all();
|
final artists = await spotify.invoke(
|
||||||
|
(api) => api.me.following(FollowingType.artist).all(),
|
||||||
|
);
|
||||||
return artists.toList();
|
return artists.toList();
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
@ -3,8 +3,10 @@ part of '../spotify.dart';
|
|||||||
final artistIsFollowingProvider = FutureProvider.family(
|
final artistIsFollowingProvider = FutureProvider.family(
|
||||||
(ref, String artistId) async {
|
(ref, String artistId) async {
|
||||||
final spotify = ref.watch(spotifyProvider);
|
final spotify = ref.watch(spotifyProvider);
|
||||||
return spotify.me.checkFollowing(FollowingType.artist, [artistId]).then(
|
return spotify.invoke(
|
||||||
|
(api) => api.me.checkFollowing(FollowingType.artist, [artistId]).then(
|
||||||
(value) => value[artistId] ?? false,
|
(value) => value[artistId] ?? false,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
@ -5,7 +5,9 @@ final relatedArtistsProvider = FutureProvider.autoDispose
|
|||||||
ref.cacheFor();
|
ref.cacheFor();
|
||||||
|
|
||||||
final spotify = ref.watch(spotifyProvider);
|
final spotify = ref.watch(spotifyProvider);
|
||||||
final artists = await spotify.artists.relatedArtists(artistId);
|
final artists = await spotify.invoke(
|
||||||
|
(api) => api.artists.relatedArtists(artistId),
|
||||||
|
);
|
||||||
|
|
||||||
return artists.toList();
|
return artists.toList();
|
||||||
});
|
});
|
||||||
|
@ -7,7 +7,9 @@ final artistTopTracksProvider =
|
|||||||
|
|
||||||
final spotify = ref.watch(spotifyProvider);
|
final spotify = ref.watch(spotifyProvider);
|
||||||
final market = ref.watch(userPreferencesProvider.select((s) => s.market));
|
final market = ref.watch(userPreferencesProvider.select((s) => s.market));
|
||||||
final tracks = await spotify.artists.topTracks(artistId, market);
|
final tracks = await spotify.invoke(
|
||||||
|
(api) => api.artists.topTracks(artistId, market),
|
||||||
|
);
|
||||||
|
|
||||||
return tracks.toList();
|
return tracks.toList();
|
||||||
},
|
},
|
||||||
|
@ -5,14 +5,16 @@ final categoriesProvider = FutureProvider(
|
|||||||
final spotify = ref.watch(spotifyProvider);
|
final spotify = ref.watch(spotifyProvider);
|
||||||
final market = ref.watch(userPreferencesProvider.select((s) => s.market));
|
final market = ref.watch(userPreferencesProvider.select((s) => s.market));
|
||||||
final locale = ref.watch(userPreferencesProvider.select((s) => s.locale));
|
final locale = ref.watch(userPreferencesProvider.select((s) => s.locale));
|
||||||
final categories = await spotify.categories
|
final categories = await spotify.invoke(
|
||||||
|
(api) => api.categories
|
||||||
.list(
|
.list(
|
||||||
country: market,
|
country: market,
|
||||||
locale: Intl.canonicalizedLocale(
|
locale: Intl.canonicalizedLocale(
|
||||||
locale.toString(),
|
locale.toString(),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.all();
|
.all(),
|
||||||
|
);
|
||||||
|
|
||||||
return categories.toList()..shuffle();
|
return categories.toList()..shuffle();
|
||||||
},
|
},
|
||||||
|
@ -32,7 +32,7 @@ class CategoryPlaylistsNotifier extends AutoDisposeFamilyPaginatedAsyncNotifier<
|
|||||||
fetch(arg, offset, limit) async {
|
fetch(arg, offset, limit) async {
|
||||||
final preferences = ref.read(userPreferencesProvider);
|
final preferences = ref.read(userPreferencesProvider);
|
||||||
final playlists = await Pages<PlaylistSimple?>(
|
final playlists = await Pages<PlaylistSimple?>(
|
||||||
spotify,
|
spotify.api,
|
||||||
"v1/browse/categories/$arg/playlists?country=${preferences.market.name}&locale=${preferences.locale}",
|
"v1/browse/categories/$arg/playlists?country=${preferences.market.name}&locale=${preferences.locale}",
|
||||||
(json) => json == null ? null : PlaylistSimple.fromJson(json),
|
(json) => json == null ? null : PlaylistSimple.fromJson(json),
|
||||||
'playlists',
|
'playlists',
|
||||||
|
@ -138,7 +138,7 @@ class SyncedLyricsNotifier extends FamilyAsyncNotifier<SubtitleSimple, Track?> {
|
|||||||
|
|
||||||
SubtitleSimple? lyrics = cachedLyrics;
|
SubtitleSimple? lyrics = cachedLyrics;
|
||||||
|
|
||||||
final token = await spotify.getCredentials();
|
final token = await spotify.invoke((api) => api.getCredentials());
|
||||||
|
|
||||||
if ((lyrics == null || lyrics.lyrics.isEmpty) && auth != null) {
|
if ((lyrics == null || lyrics.lyrics.isEmpty) && auth != null) {
|
||||||
lyrics = await getSpotifyLyrics(token.accessToken);
|
lyrics = await getSpotifyLyrics(token.accessToken);
|
||||||
|
@ -30,9 +30,11 @@ class FavoritePlaylistsNotifier
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
fetch(int offset, int limit) async {
|
fetch(int offset, int limit) async {
|
||||||
final playlists = await spotify.playlists.me.getPage(
|
final playlists = await spotify.invoke(
|
||||||
|
(api) => api.playlists.me.getPage(
|
||||||
limit,
|
limit,
|
||||||
offset,
|
offset,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
return playlists.items?.toList() ?? [];
|
return playlists.items?.toList() ?? [];
|
||||||
@ -67,7 +69,9 @@ class FavoritePlaylistsNotifier
|
|||||||
|
|
||||||
Future<void> addFavorite(PlaylistSimple playlist) async {
|
Future<void> addFavorite(PlaylistSimple playlist) async {
|
||||||
await update((state) async {
|
await update((state) async {
|
||||||
await spotify.playlists.followPlaylist(playlist.id!);
|
await spotify.invoke(
|
||||||
|
(api) => api.playlists.followPlaylist(playlist.id!),
|
||||||
|
);
|
||||||
return state.copyWith(
|
return state.copyWith(
|
||||||
items: [...state.items, playlist],
|
items: [...state.items, playlist],
|
||||||
);
|
);
|
||||||
@ -78,7 +82,9 @@ class FavoritePlaylistsNotifier
|
|||||||
|
|
||||||
Future<void> removeFavorite(PlaylistSimple playlist) async {
|
Future<void> removeFavorite(PlaylistSimple playlist) async {
|
||||||
await update((state) async {
|
await update((state) async {
|
||||||
await spotify.playlists.unfollowPlaylist(playlist.id!);
|
await spotify.invoke(
|
||||||
|
(api) => api.playlists.unfollowPlaylist(playlist.id!),
|
||||||
|
);
|
||||||
return state.copyWith(
|
return state.copyWith(
|
||||||
items: state.items.where((e) => e.id != playlist.id).toList(),
|
items: state.items.where((e) => e.id != playlist.id).toList(),
|
||||||
);
|
);
|
||||||
@ -92,9 +98,11 @@ class FavoritePlaylistsNotifier
|
|||||||
|
|
||||||
final spotify = ref.read(spotifyProvider);
|
final spotify = ref.read(spotifyProvider);
|
||||||
|
|
||||||
await spotify.playlists.addTracks(
|
await spotify.invoke(
|
||||||
|
(api) => api.playlists.addTracks(
|
||||||
trackIds.map((id) => 'spotify:track:$id').toList(),
|
trackIds.map((id) => 'spotify:track:$id').toList(),
|
||||||
playlistId,
|
playlistId,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
ref.invalidate(playlistTracksProvider(playlistId));
|
ref.invalidate(playlistTracksProvider(playlistId));
|
||||||
@ -105,9 +113,11 @@ class FavoritePlaylistsNotifier
|
|||||||
|
|
||||||
final spotify = ref.read(spotifyProvider);
|
final spotify = ref.read(spotifyProvider);
|
||||||
|
|
||||||
await spotify.playlists.removeTracks(
|
await spotify.invoke(
|
||||||
|
(api) => api.playlists.removeTracks(
|
||||||
trackIds.map((id) => 'spotify:track:$id').toList(),
|
trackIds.map((id) => 'spotify:track:$id').toList(),
|
||||||
playlistId,
|
playlistId,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
ref.invalidate(playlistTracksProvider(playlistId));
|
ref.invalidate(playlistTracksProvider(playlistId));
|
||||||
@ -128,8 +138,8 @@ final isFavoritePlaylistProvider = FutureProvider.family<bool, String>(
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
final follows =
|
final follows = await spotify
|
||||||
await spotify.playlists.followedByUsers(id, [me.value!.id!]);
|
.invoke((api) => api.playlists.followedByUsers(id, [me.value!.id!]));
|
||||||
|
|
||||||
return follows[me.value!.id!] ?? false;
|
return follows[me.value!.id!] ?? false;
|
||||||
},
|
},
|
||||||
|
@ -30,9 +30,8 @@ class FeaturedPlaylistsNotifier
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
fetch(int offset, int limit) async {
|
fetch(int offset, int limit) async {
|
||||||
final playlists = await spotify.playlists.featured.getPage(
|
final playlists = await spotify.invoke(
|
||||||
limit,
|
(api) => api.playlists.featured.getPage(limit, offset),
|
||||||
offset,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return playlists.items?.toList() ?? [];
|
return playlists.items?.toList() ?? [];
|
||||||
|
@ -8,7 +8,8 @@ final generatePlaylistProvider = FutureProvider.autoDispose
|
|||||||
userPreferencesProvider.select((s) => s.market),
|
userPreferencesProvider.select((s) => s.market),
|
||||||
);
|
);
|
||||||
|
|
||||||
final recommendation = await spotify.recommendations
|
final recommendation = await spotify.invoke(
|
||||||
|
(api) => api.recommendations
|
||||||
.get(
|
.get(
|
||||||
limit: input.limit,
|
limit: input.limit,
|
||||||
seedArtists: input.seedArtists?.toList(),
|
seedArtists: input.seedArtists?.toList(),
|
||||||
@ -26,14 +27,17 @@ final generatePlaylistProvider = FutureProvider.autoDispose
|
|||||||
.catchError((e, stackTrace) {
|
.catchError((e, stackTrace) {
|
||||||
AppLogger.reportError(e, stackTrace);
|
AppLogger.reportError(e, stackTrace);
|
||||||
return Recommendations();
|
return Recommendations();
|
||||||
});
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
if (recommendation.tracks?.isEmpty ?? true) {
|
if (recommendation.tracks?.isEmpty ?? true) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
final tracks = await spotify.tracks
|
final tracks = await spotify.invoke(
|
||||||
.list(recommendation.tracks!.map((e) => e.id!).toList());
|
(api) =>
|
||||||
|
api.tracks.list(recommendation.tracks!.map((e) => e.id!).toList()),
|
||||||
|
);
|
||||||
|
|
||||||
return tracks.toList();
|
return tracks.toList();
|
||||||
},
|
},
|
||||||
|
@ -4,7 +4,9 @@ class LikedTracksNotifier extends AsyncNotifier<List<Track>> {
|
|||||||
@override
|
@override
|
||||||
FutureOr<List<Track>> build() async {
|
FutureOr<List<Track>> build() async {
|
||||||
final spotify = ref.watch(spotifyProvider);
|
final spotify = ref.watch(spotifyProvider);
|
||||||
final savedTracked = await spotify.tracks.me.saved.all();
|
final savedTracked = await spotify.invoke(
|
||||||
|
(api) => api.tracks.me.saved.all(),
|
||||||
|
);
|
||||||
|
|
||||||
return savedTracked.map((e) => e.track!).toList();
|
return savedTracked.map((e) => e.track!).toList();
|
||||||
}
|
}
|
||||||
@ -17,10 +19,14 @@ class LikedTracksNotifier extends AsyncNotifier<List<Track>> {
|
|||||||
final isLiked = tracks.map((e) => e.id).contains(track.id);
|
final isLiked = tracks.map((e) => e.id).contains(track.id);
|
||||||
|
|
||||||
if (isLiked) {
|
if (isLiked) {
|
||||||
await spotify.tracks.me.removeOne(track.id!);
|
await spotify.invoke(
|
||||||
|
(api) => api.tracks.me.removeOne(track.id!),
|
||||||
|
);
|
||||||
return tracks.where((e) => e.id != track.id).toList();
|
return tracks.where((e) => e.id != track.id).toList();
|
||||||
} else {
|
} else {
|
||||||
await spotify.tracks.me.saveOne(track.id!);
|
await spotify.invoke(
|
||||||
|
(api) => api.tracks.me.saveOne(track.id!),
|
||||||
|
);
|
||||||
return [track, ...tracks];
|
return [track, ...tracks];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -12,7 +12,9 @@ class PlaylistNotifier extends FamilyAsyncNotifier<Playlist, String> {
|
|||||||
@override
|
@override
|
||||||
FutureOr<Playlist> build(String arg) {
|
FutureOr<Playlist> build(String arg) {
|
||||||
final spotify = ref.watch(spotifyProvider);
|
final spotify = ref.watch(spotifyProvider);
|
||||||
return spotify.playlists.get(arg);
|
return spotify.invoke(
|
||||||
|
(api) => api.playlists.get(arg),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> create(PlaylistInput input, [ValueChanged? onError]) async {
|
Future<void> create(PlaylistInput input, [ValueChanged? onError]) async {
|
||||||
@ -26,18 +28,22 @@ class PlaylistNotifier extends FamilyAsyncNotifier<Playlist, String> {
|
|||||||
|
|
||||||
state = await AsyncValue.guard(() async {
|
state = await AsyncValue.guard(() async {
|
||||||
try {
|
try {
|
||||||
final playlist = await spotify.playlists.createPlaylist(
|
final playlist = await spotify.invoke(
|
||||||
|
(api) => api.playlists.createPlaylist(
|
||||||
me.value!.id!,
|
me.value!.id!,
|
||||||
input.playlistName,
|
input.playlistName,
|
||||||
collaborative: input.collaborative,
|
collaborative: input.collaborative,
|
||||||
description: input.description,
|
description: input.description,
|
||||||
public: input.public,
|
public: input.public,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (input.base64Image != null) {
|
if (input.base64Image != null) {
|
||||||
await spotify.playlists.updatePlaylistImage(
|
await spotify.invoke(
|
||||||
|
(api) => api.playlists.updatePlaylistImage(
|
||||||
playlist.id!,
|
playlist.id!,
|
||||||
input.base64Image!,
|
input.base64Image!,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,21 +64,27 @@ class PlaylistNotifier extends FamilyAsyncNotifier<Playlist, String> {
|
|||||||
|
|
||||||
await update((state) async {
|
await update((state) async {
|
||||||
try {
|
try {
|
||||||
await spotify.playlists.updatePlaylist(
|
await spotify.invoke(
|
||||||
|
(api) => api.playlists.updatePlaylist(
|
||||||
state.id!,
|
state.id!,
|
||||||
input.playlistName,
|
input.playlistName,
|
||||||
collaborative: input.collaborative,
|
collaborative: input.collaborative,
|
||||||
description: input.description,
|
description: input.description,
|
||||||
public: input.public,
|
public: input.public,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (input.base64Image != null) {
|
if (input.base64Image != null) {
|
||||||
await spotify.playlists.updatePlaylistImage(
|
await spotify.invoke(
|
||||||
|
(api) => api.playlists.updatePlaylistImage(
|
||||||
state.id!,
|
state.id!,
|
||||||
input.base64Image!,
|
input.base64Image!,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
final playlist = await spotify.playlists.get(state.id!);
|
final playlist = await spotify.invoke(
|
||||||
|
(api) => api.playlists.get(state.id!),
|
||||||
|
);
|
||||||
|
|
||||||
ref.read(favoritePlaylistsProvider.notifier).updatePlaylist(playlist);
|
ref.read(favoritePlaylistsProvider.notifier).updatePlaylist(playlist);
|
||||||
return playlist;
|
return playlist;
|
||||||
@ -105,9 +117,11 @@ class PlaylistNotifier extends FamilyAsyncNotifier<Playlist, String> {
|
|||||||
|
|
||||||
final spotify = ref.read(spotifyProvider);
|
final spotify = ref.read(spotifyProvider);
|
||||||
|
|
||||||
await spotify.playlists.addTracks(
|
await spotify.invoke(
|
||||||
|
(api) => api.playlists.addTracks(
|
||||||
trackIds.map((id) => "spotify:track:$id").toList(),
|
trackIds.map((id) => "spotify:track:$id").toList(),
|
||||||
state.value!.id!,
|
state.value!.id!,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
} catch (e, stack) {
|
} catch (e, stack) {
|
||||||
onError?.call(e);
|
onError?.call(e);
|
||||||
|
@ -30,9 +30,9 @@ class PlaylistTracksNotifier extends AutoDisposeFamilyPaginatedAsyncNotifier<
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
fetch(arg, offset, limit) async {
|
fetch(arg, offset, limit) async {
|
||||||
final tracks = await spotify.playlists
|
final tracks = await spotify.invoke(
|
||||||
.getTracksByPlaylistId(arg)
|
(api) => api.playlists.getTracksByPlaylistId(arg).getPage(limit, offset),
|
||||||
.getPage(limit, offset);
|
);
|
||||||
|
|
||||||
/// Filter out tracks with null id because some personal playlists
|
/// Filter out tracks with null id because some personal playlists
|
||||||
/// may contain local tracks that are not available in the Spotify catalog
|
/// may contain local tracks that are not available in the Spotify catalog
|
||||||
|
@ -44,13 +44,15 @@ class SearchNotifier<Y> extends AutoDisposeFamilyPaginatedAsyncNotifier<Y,
|
|||||||
nextOffset: 0,
|
nextOffset: 0,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
final results = await spotify.search
|
final results = await spotify.invoke(
|
||||||
|
(api) => api.search
|
||||||
.get(
|
.get(
|
||||||
ref.read(searchTermStateProvider),
|
ref.read(searchTermStateProvider),
|
||||||
types: [arg],
|
types: [arg],
|
||||||
market: ref.read(userPreferencesProvider).market,
|
market: ref.read(userPreferencesProvider).market,
|
||||||
)
|
)
|
||||||
.getPage(limit, offset);
|
.getPage(limit, offset),
|
||||||
|
);
|
||||||
|
|
||||||
final items = results.expand((e) => e.items ?? <Y>[]).toList().cast<Y>();
|
final items = results.expand((e) => e.items ?? <Y>[]).toList().cast<Y>();
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ import 'dart:math';
|
|||||||
|
|
||||||
import 'package:drift/drift.dart';
|
import 'package:drift/drift.dart';
|
||||||
import 'package:spotube/collections/assets.gen.dart';
|
import 'package:spotube/collections/assets.gen.dart';
|
||||||
|
import 'package:spotube/collections/env.dart';
|
||||||
import 'package:spotube/models/database/database.dart';
|
import 'package:spotube/models/database/database.dart';
|
||||||
import 'package:spotube/provider/authentication/authentication.dart';
|
import 'package:spotube/provider/authentication/authentication.dart';
|
||||||
import 'package:spotube/provider/database/database.dart';
|
import 'package:spotube/provider/database/database.dart';
|
||||||
@ -25,10 +26,10 @@ import 'package:spotube/models/lyrics.dart';
|
|||||||
import 'package:spotube/models/spotify/recommendation_seeds.dart';
|
import 'package:spotube/models/spotify/recommendation_seeds.dart';
|
||||||
import 'package:spotube/models/spotify_friends.dart';
|
import 'package:spotube/models/spotify_friends.dart';
|
||||||
import 'package:spotube/provider/custom_spotify_endpoint_provider.dart';
|
import 'package:spotube/provider/custom_spotify_endpoint_provider.dart';
|
||||||
import 'package:spotube/provider/spotify_provider.dart';
|
|
||||||
import 'package:spotube/provider/user_preferences/user_preferences_provider.dart';
|
import 'package:spotube/provider/user_preferences/user_preferences_provider.dart';
|
||||||
import 'package:spotube/services/dio/dio.dart';
|
import 'package:spotube/services/dio/dio.dart';
|
||||||
import 'package:spotube/services/wikipedia/wikipedia.dart';
|
import 'package:spotube/services/wikipedia/wikipedia.dart';
|
||||||
|
import 'package:spotube/utils/primitive_utils.dart';
|
||||||
|
|
||||||
import 'package:wikipedia_api/wikipedia_api.dart';
|
import 'package:wikipedia_api/wikipedia_api.dart';
|
||||||
|
|
||||||
@ -76,3 +77,57 @@ part 'utils/provider/paginated.dart';
|
|||||||
part 'utils/provider/cursor.dart';
|
part 'utils/provider/cursor.dart';
|
||||||
part 'utils/provider/paginated_family.dart';
|
part 'utils/provider/paginated_family.dart';
|
||||||
part 'utils/provider/cursor_family.dart';
|
part 'utils/provider/cursor_family.dart';
|
||||||
|
|
||||||
|
class SpotifyApiWrapper {
|
||||||
|
final SpotifyApi api;
|
||||||
|
|
||||||
|
final Ref ref;
|
||||||
|
SpotifyApiWrapper(
|
||||||
|
this.ref,
|
||||||
|
this.api,
|
||||||
|
);
|
||||||
|
|
||||||
|
bool _isRefreshing = false;
|
||||||
|
|
||||||
|
FutureOr<T> invoke<T>(
|
||||||
|
FutureOr<T> Function(SpotifyApi api) fn,
|
||||||
|
) async {
|
||||||
|
try {
|
||||||
|
return await fn(api);
|
||||||
|
} catch (e) {
|
||||||
|
if (((e is AuthorizationException && e.error == 'invalid_token') ||
|
||||||
|
e is ExpirationException) &&
|
||||||
|
!_isRefreshing) {
|
||||||
|
_isRefreshing = true;
|
||||||
|
await ref.read(authenticationProvider.notifier).refreshCredentials();
|
||||||
|
|
||||||
|
_isRefreshing = false;
|
||||||
|
return await fn(api);
|
||||||
|
}
|
||||||
|
rethrow;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final spotifyProvider = Provider<SpotifyApiWrapper>(
|
||||||
|
(ref) {
|
||||||
|
final authState = ref.watch(authenticationProvider);
|
||||||
|
final anonCred = PrimitiveUtils.getRandomElement(Env.spotifySecrets);
|
||||||
|
|
||||||
|
final wrapper = SpotifyApiWrapper(
|
||||||
|
ref,
|
||||||
|
authState.asData?.value == null
|
||||||
|
? SpotifyApi(
|
||||||
|
SpotifyApiCredentials(
|
||||||
|
anonCred["clientId"],
|
||||||
|
anonCred["clientSecret"],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: SpotifyApi.withAccessToken(
|
||||||
|
authState.asData!.value!.accessToken.value,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
return wrapper;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
@ -6,5 +6,5 @@ final trackProvider =
|
|||||||
|
|
||||||
final spotify = ref.watch(spotifyProvider);
|
final spotify = ref.watch(spotifyProvider);
|
||||||
|
|
||||||
return spotify.tracks.get(id);
|
return spotify.invoke((api) => api.tracks.get(id));
|
||||||
});
|
});
|
||||||
|
@ -2,5 +2,5 @@ part of '../spotify.dart';
|
|||||||
|
|
||||||
final meProvider = FutureProvider<User>((ref) async {
|
final meProvider = FutureProvider<User>((ref) async {
|
||||||
final spotify = ref.watch(spotifyProvider);
|
final spotify = ref.watch(spotifyProvider);
|
||||||
return spotify.me.get();
|
return spotify.invoke((api) => api.me.get());
|
||||||
});
|
});
|
||||||
|
@ -2,7 +2,7 @@ part of '../spotify.dart';
|
|||||||
|
|
||||||
// ignore: invalid_use_of_internal_member
|
// ignore: invalid_use_of_internal_member
|
||||||
mixin SpotifyMixin<T> on AsyncNotifierBase<T> {
|
mixin SpotifyMixin<T> on AsyncNotifierBase<T> {
|
||||||
SpotifyApi get spotify => ref.read(spotifyProvider);
|
SpotifyApiWrapper get spotify => ref.read(spotifyProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
extension on AutoDisposeAsyncNotifierProviderRef {
|
extension on AutoDisposeAsyncNotifierProviderRef {
|
||||||
|
@ -1,22 +0,0 @@
|
|||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:spotify/spotify.dart';
|
|
||||||
import 'package:spotube/collections/env.dart';
|
|
||||||
|
|
||||||
import 'package:spotube/provider/authentication/authentication.dart';
|
|
||||||
import 'package:spotube/utils/primitive_utils.dart';
|
|
||||||
|
|
||||||
final spotifyProvider = Provider<SpotifyApi>((ref) {
|
|
||||||
final authState = ref.watch(authenticationProvider);
|
|
||||||
final anonCred = PrimitiveUtils.getRandomElement(Env.spotifySecrets);
|
|
||||||
|
|
||||||
if (authState.asData?.value == null) {
|
|
||||||
return SpotifyApi(
|
|
||||||
SpotifyApiCredentials(
|
|
||||||
anonCred["clientId"],
|
|
||||||
anonCred["clientSecret"],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return SpotifyApi.withAccessToken(authState.asData!.value!.accessToken.value);
|
|
||||||
});
|
|
@ -42,10 +42,10 @@ packages:
|
|||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: app_links
|
name: app_links
|
||||||
sha256: ad1a6d598e7e39b46a34f746f9a8b011ee147e4c275d407fa457e7a62f84dd99
|
sha256: "85ed8fc1d25a76475914fff28cc994653bd900bc2c26e4b57a49e097febb54ba"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "6.3.2"
|
version: "6.4.0"
|
||||||
app_links_linux:
|
app_links_linux:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
@ -3,7 +3,7 @@ description: Open source Spotify client that doesn't require Premium nor uses El
|
|||||||
|
|
||||||
publish_to: "none"
|
publish_to: "none"
|
||||||
|
|
||||||
version: 4.0.1+40
|
version: 4.0.2+41
|
||||||
|
|
||||||
homepage: https://spotube.krtirtho.dev
|
homepage: https://spotube.krtirtho.dev
|
||||||
repository: https://github.com/KRTirtho/spotube
|
repository: https://github.com/KRTirtho/spotube
|
||||||
@ -13,7 +13,7 @@ environment:
|
|||||||
flutter: ">=3.29.0"
|
flutter: ">=3.29.0"
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
app_links: ^6.3.2
|
app_links: ^6.4.0
|
||||||
args: ^2.5.0
|
args: ^2.5.0
|
||||||
async: ^2.11.0
|
async: ^2.11.0
|
||||||
audio_service: ^0.18.13
|
audio_service: ^0.18.13
|
||||||
|
Loading…
Reference in New Issue
Block a user