Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
3df93e47d2 | |||
6d2a027d9b | |||
222d50d80d | |||
499bca5b1c | |||
252e4619f7 | |||
463cb9870f | |||
2cee7ee958 | |||
e30e7a5c24 | |||
6509cd2511 | |||
6cdc025c40 | |||
de3ad4b21e |
@ -1,59 +1,61 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CADisableMinimumFrameDurationOnPhone</key>
|
||||
<true/>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>$(DEVELOPMENT_LANGUAGE)</string>
|
||||
<key>CFBundleDisplayName</key>
|
||||
<string>Groovy Box</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>Groovy Box</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>$(FLUTTER_BUILD_NAME)</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>$(FLUTTER_BUILD_NUMBER)</string>
|
||||
<key>LSApplicationCategoryType</key>
|
||||
<string>public.app-category.music</string>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
<true/>
|
||||
<key>NSMicrophoneUsageDescription</key>
|
||||
<string>To provide information for RhythmBox to normalize the output audio</string>
|
||||
<key>UIApplicationSupportsIndirectInputEvents</key>
|
||||
<true/>
|
||||
<key>UIBackgroundModes</key>
|
||||
<array>
|
||||
<string>audio</string>
|
||||
</array>
|
||||
<key>UILaunchStoryboardName</key>
|
||||
<string>LaunchScreen</string>
|
||||
<key>UIMainStoryboardFile</key>
|
||||
<string>Main</string>
|
||||
<key>UIStatusBarHidden</key>
|
||||
<false/>
|
||||
<key>UISupportedInterfaceOrientations</key>
|
||||
<array>
|
||||
<string>UIInterfaceOrientationPortrait</string>
|
||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||
</array>
|
||||
<key>UISupportedInterfaceOrientations~ipad</key>
|
||||
<array>
|
||||
<string>UIInterfaceOrientationPortrait</string>
|
||||
<string>UIInterfaceOrientationPortraitUpsideDown</string>
|
||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||
</array>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>ITSAppUsesNonExemptEncryption</key>
|
||||
<false/>
|
||||
<key>CADisableMinimumFrameDurationOnPhone</key>
|
||||
<true/>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>$(DEVELOPMENT_LANGUAGE)</string>
|
||||
<key>CFBundleDisplayName</key>
|
||||
<string>Groovy Box</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>Groovy Box</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>$(FLUTTER_BUILD_NAME)</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>$(FLUTTER_BUILD_NUMBER)</string>
|
||||
<key>LSApplicationCategoryType</key>
|
||||
<string>public.app-category.music</string>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
<true/>
|
||||
<key>NSMicrophoneUsageDescription</key>
|
||||
<string>To provide information for RhythmBox to normalize the output audio</string>
|
||||
<key>UIApplicationSupportsIndirectInputEvents</key>
|
||||
<true/>
|
||||
<key>UIBackgroundModes</key>
|
||||
<array>
|
||||
<string>audio</string>
|
||||
</array>
|
||||
<key>UILaunchStoryboardName</key>
|
||||
<string>LaunchScreen</string>
|
||||
<key>UIMainStoryboardFile</key>
|
||||
<string>Main</string>
|
||||
<key>UIStatusBarHidden</key>
|
||||
<false/>
|
||||
<key>UISupportedInterfaceOrientations</key>
|
||||
<array>
|
||||
<string>UIInterfaceOrientationPortrait</string>
|
||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||
</array>
|
||||
<key>UISupportedInterfaceOrientations~ipad</key>
|
||||
<array>
|
||||
<string>UIInterfaceOrientationPortrait</string>
|
||||
<string>UIInterfaceOrientationPortraitUpsideDown</string>
|
||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
|
@ -9,15 +9,23 @@ import 'package:rhythm_box/providers/database.dart';
|
||||
import 'package:rhythm_box/services/database/database.dart';
|
||||
|
||||
extension ExpirationAuthenticationTableData on AuthenticationTableData {
|
||||
bool get isExpired => DateTime.now().isAfter(expiration);
|
||||
bool get isExpired => DateTime.now().isAfter(spotifyExpiration);
|
||||
|
||||
String? getCookie(String key) => cookie.value
|
||||
String? getCookie(String key) => spotifyCookie.value
|
||||
.split('; ')
|
||||
.firstWhereOrNull((c) => c.trim().startsWith('$key='))
|
||||
?.trim()
|
||||
.split('=')
|
||||
.last
|
||||
.replaceAll(';', '');
|
||||
|
||||
String? getNeteaseCookie(String key) => neteaseCookie?.value
|
||||
.split(';')
|
||||
.firstWhereOrNull((c) => c.trim().startsWith('$key='))
|
||||
?.trim()
|
||||
.split('=')
|
||||
.last
|
||||
.replaceAll(';', '');
|
||||
}
|
||||
|
||||
class AuthenticationProvider extends GetxController {
|
||||
@ -55,18 +63,18 @@ class AuthenticationProvider extends GetxController {
|
||||
void _setRefreshTimer() {
|
||||
refreshTimer?.cancel();
|
||||
if (auth.value != null && auth.value!.isExpired) {
|
||||
refreshCredentials();
|
||||
refreshSpotifyCredentials();
|
||||
}
|
||||
refreshTimer = Timer(
|
||||
auth.value!.expiration.difference(DateTime.now()),
|
||||
() => refreshCredentials(),
|
||||
auth.value!.spotifyExpiration.difference(DateTime.now()),
|
||||
() => refreshSpotifyCredentials(),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> refreshCredentials() async {
|
||||
Future<void> refreshSpotifyCredentials() async {
|
||||
final database = Get.find<DatabaseProvider>().database;
|
||||
final refreshedCredentials =
|
||||
await credentialsFromCookie(auth.value!.cookie.value);
|
||||
await credentialsFromCookie(auth.value!.spotifyCookie.value);
|
||||
|
||||
await database
|
||||
.update(database.authenticationTable)
|
||||
@ -112,9 +120,10 @@ class AuthenticationProvider extends GetxController {
|
||||
|
||||
return AuthenticationTableCompanion.insert(
|
||||
id: const Value(0),
|
||||
cookie: DecryptedText("${res.headers["set-cookie"]?.join(";")}; $spDc"),
|
||||
accessToken: DecryptedText(body['accessToken']),
|
||||
expiration: DateTime.fromMillisecondsSinceEpoch(
|
||||
spotifyCookie:
|
||||
DecryptedText("${res.headers["set-cookie"]?.join(";")}; $spDc"),
|
||||
spotifyAccessToken: DecryptedText(body['accessToken']),
|
||||
spotifyExpiration: DateTime.fromMillisecondsSinceEpoch(
|
||||
body['accessTokenExpirationTimestampMs']),
|
||||
);
|
||||
} catch (e) {
|
||||
@ -123,6 +132,21 @@ class AuthenticationProvider extends GetxController {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> setNeteaseCredentials(String cookie) async {
|
||||
final database = Get.find<DatabaseProvider>().database;
|
||||
await database.update(database.authenticationTable).replace(
|
||||
AuthenticationTableCompanion.insert(
|
||||
id: const Value(0),
|
||||
spotifyCookie: auth.value!.spotifyCookie,
|
||||
spotifyAccessToken: auth.value!.spotifyAccessToken,
|
||||
spotifyExpiration: auth.value!.spotifyExpiration,
|
||||
neteaseCookie: Value(DecryptedText(cookie)),
|
||||
neteaseExpiration: const Value(null),
|
||||
),
|
||||
);
|
||||
await loadAuthenticationData();
|
||||
}
|
||||
|
||||
Future<void> logout() async {
|
||||
auth.value = null;
|
||||
final database = Get.find<DatabaseProvider>().database;
|
||||
@ -132,6 +156,21 @@ class AuthenticationProvider extends GetxController {
|
||||
// Additional cleanup if necessary
|
||||
}
|
||||
|
||||
Future<void> logoutNetease() async {
|
||||
final database = Get.find<DatabaseProvider>().database;
|
||||
await database.update(database.authenticationTable).replace(
|
||||
AuthenticationTableCompanion.insert(
|
||||
id: const Value(0),
|
||||
spotifyCookie: auth.value!.spotifyCookie,
|
||||
spotifyAccessToken: auth.value!.spotifyAccessToken,
|
||||
spotifyExpiration: auth.value!.spotifyExpiration,
|
||||
neteaseCookie: const Value(null),
|
||||
neteaseExpiration: const Value(null),
|
||||
),
|
||||
);
|
||||
await loadAuthenticationData();
|
||||
}
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
refreshTimer?.cancel();
|
||||
|
@ -44,7 +44,7 @@ class SpotifyProvider extends GetxController {
|
||||
log('[SpotifyApi] Using user credentials...');
|
||||
final AuthenticationProvider authenticate = Get.find();
|
||||
return SpotifyApi.withAccessToken(
|
||||
authenticate.auth.value!.accessToken.value);
|
||||
authenticate.auth.value!.spotifyAccessToken.value);
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:rhythm_box/screens/about.dart';
|
||||
import 'package:rhythm_box/screens/album/view.dart';
|
||||
import 'package:rhythm_box/screens/auth/login_netease.dart';
|
||||
import 'package:rhythm_box/screens/auth/mobile_login.dart';
|
||||
import 'package:rhythm_box/screens/explore.dart';
|
||||
import 'package:rhythm_box/screens/library/view.dart';
|
||||
@ -104,6 +105,11 @@ final router = GoRouter(routes: [
|
||||
name: 'authMobileLogin',
|
||||
builder: (context, state) => const MobileLogin(),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/auth/netease/login',
|
||||
name: 'authMobileLoginNetease',
|
||||
builder: (context, state) => const LoginNeteaseScreen(),
|
||||
),
|
||||
],
|
||||
),
|
||||
]);
|
||||
|
156
lib/screens/auth/login_netease.dart
Normal file
156
lib/screens/auth/login_netease.dart
Normal file
@ -0,0 +1,156 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:gap/gap.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:rhythm_box/providers/auth.dart';
|
||||
import 'package:rhythm_box/providers/error_notifier.dart';
|
||||
import 'package:rhythm_box/services/sourced_track/sources/netease.dart';
|
||||
import 'package:rhythm_box/widgets/sized_container.dart';
|
||||
|
||||
class LoginNeteaseScreen extends StatefulWidget {
|
||||
const LoginNeteaseScreen({super.key});
|
||||
|
||||
@override
|
||||
State<LoginNeteaseScreen> createState() => _LoginNeteaseScreenState();
|
||||
}
|
||||
|
||||
class _LoginNeteaseScreenState extends State<LoginNeteaseScreen> {
|
||||
final TextEditingController _phoneController = TextEditingController();
|
||||
final TextEditingController _phoneRegionController = TextEditingController();
|
||||
final TextEditingController _passwordController = TextEditingController();
|
||||
|
||||
late final AuthenticationProvider _auth = Get.find();
|
||||
|
||||
bool _isLogging = false;
|
||||
|
||||
Future<void> _sentCaptcha() async {
|
||||
setState(() => _isLogging = true);
|
||||
|
||||
final phone = _phoneController.text;
|
||||
var region = _phoneRegionController.text;
|
||||
if (region.isEmpty) region = '86';
|
||||
final client = NeteaseSourcedTrack.getClient();
|
||||
final resp = await client.get(
|
||||
'/captcha/sent?phone=$phone&ctcode=$region×tamp=${DateTime.now().millisecondsSinceEpoch}',
|
||||
);
|
||||
|
||||
if (resp.statusCode != 200 || resp.body?['code'] != 200) {
|
||||
Get.find<ErrorNotifier>().showError(
|
||||
resp.bodyString ?? resp.status.toString(),
|
||||
);
|
||||
}
|
||||
|
||||
setState(() => _isLogging = false);
|
||||
}
|
||||
|
||||
Future<void> _performLogin() async {
|
||||
setState(() => _isLogging = true);
|
||||
|
||||
final phone = _phoneController.text;
|
||||
final password = _passwordController.text;
|
||||
var region = _phoneRegionController.text;
|
||||
if (region.isEmpty) region = '86';
|
||||
final client = NeteaseSourcedTrack.getClient();
|
||||
final resp = await client.get(
|
||||
'/login/cellphone?phone=$phone&captcha=$password&countrycode=$region×tamp=${DateTime.now().millisecondsSinceEpoch}',
|
||||
);
|
||||
|
||||
if (resp.statusCode != 200 || resp.body?['code'] != 200) {
|
||||
Get.find<ErrorNotifier>().showError(
|
||||
resp.bodyString ?? resp.status.toString(),
|
||||
);
|
||||
setState(() => _isLogging = false);
|
||||
return;
|
||||
}
|
||||
|
||||
await _auth.setNeteaseCredentials(resp.body['cookie']);
|
||||
|
||||
setState(() => _isLogging = false);
|
||||
|
||||
GoRouter.of(context).goNamed('settings');
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_phoneController.dispose();
|
||||
_phoneRegionController.dispose();
|
||||
_passwordController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Connect with Netease Cloud Music'),
|
||||
),
|
||||
body: CenteredContainer(
|
||||
maxWidth: 320,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 64,
|
||||
child: TextField(
|
||||
controller: _phoneRegionController,
|
||||
decoration: const InputDecoration(
|
||||
border: OutlineInputBorder(),
|
||||
hintText: '86',
|
||||
isDense: true,
|
||||
),
|
||||
onTapOutside: (_) =>
|
||||
FocusManager.instance.primaryFocus?.unfocus(),
|
||||
),
|
||||
),
|
||||
const Gap(8),
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: _phoneController,
|
||||
decoration: const InputDecoration(
|
||||
border: OutlineInputBorder(),
|
||||
label: Text('Phone Number'),
|
||||
isDense: true,
|
||||
),
|
||||
onTapOutside: (_) =>
|
||||
FocusManager.instance.primaryFocus?.unfocus(),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const Gap(8),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: _passwordController,
|
||||
obscureText: true,
|
||||
decoration: const InputDecoration(
|
||||
border: OutlineInputBorder(),
|
||||
label: Text('Captcha Code'),
|
||||
isDense: true,
|
||||
),
|
||||
onTapOutside: (_) =>
|
||||
FocusManager.instance.primaryFocus?.unfocus(),
|
||||
),
|
||||
),
|
||||
const Gap(8),
|
||||
IconButton(
|
||||
onPressed: _isLogging ? null : () => _sentCaptcha(),
|
||||
icon: const Icon(Icons.sms),
|
||||
tooltip: 'Get Captcha',
|
||||
),
|
||||
],
|
||||
),
|
||||
const Gap(8),
|
||||
TextButton(
|
||||
onPressed: _isLogging ? null : () => _performLogin(),
|
||||
child: const Text('Login'),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -72,8 +72,8 @@ class _ExploreScreenState extends State<ExploreScreen> {
|
||||
}
|
||||
|
||||
if (_auth.auth.value != null) {
|
||||
final customEndpoint =
|
||||
CustomSpotifyEndpoints(_auth.auth.value?.accessToken.value ?? '');
|
||||
final customEndpoint = CustomSpotifyEndpoints(
|
||||
_auth.auth.value?.spotifyAccessToken.value ?? '');
|
||||
final forYouView = await customEndpoint.getView(
|
||||
'made-for-x-hub',
|
||||
market: market,
|
||||
|
@ -1,15 +1,19 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:rhythm_box/services/server/active_sourced_track.dart';
|
||||
import 'package:rhythm_box/services/sourced_track/sourced_track.dart';
|
||||
import 'package:rhythm_box/widgets/player/track_source_details.dart';
|
||||
|
||||
class SourceDetailsPopup extends StatelessWidget {
|
||||
const SourceDetailsPopup({super.key});
|
||||
|
||||
Future<SourcedTrack?> _pullActiveTrack() async {
|
||||
final ActiveSourcedTrackProvider activeSourcedTrack = Get.find();
|
||||
return activeSourcedTrack.state.value;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final ActiveSourcedTrackProvider activeTrack = Get.find();
|
||||
|
||||
return SizedBox(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
@ -20,8 +24,19 @@ class SourceDetailsPopup extends StatelessWidget {
|
||||
).paddingOnly(left: 24, right: 24, top: 32, bottom: 16),
|
||||
Expanded(
|
||||
child: Obx(
|
||||
() => TrackSourceDetails(
|
||||
track: activeTrack.state.value!,
|
||||
() => FutureBuilder(
|
||||
future: _pullActiveTrack(),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
return TrackSourceDetails(
|
||||
track: snapshot.data!,
|
||||
);
|
||||
}
|
||||
|
||||
return const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
},
|
||||
).paddingSymmetric(horizontal: 24),
|
||||
),
|
||||
)
|
||||
|
@ -82,34 +82,38 @@ class _PlayerScreenState extends State<PlayerScreen> {
|
||||
padding: const EdgeInsets.symmetric(vertical: 24),
|
||||
children: [
|
||||
Obx(
|
||||
() => LimitedBox(
|
||||
maxHeight: maxAlbumSize,
|
||||
maxWidth: maxAlbumSize,
|
||||
child: Hero(
|
||||
tag: const Key('current-active-track-album-art'),
|
||||
child: AspectRatio(
|
||||
aspectRatio: 1,
|
||||
child: ClipRRect(
|
||||
borderRadius:
|
||||
const BorderRadius.all(Radius.circular(16)),
|
||||
child: _albumArt != null
|
||||
? AutoCacheImage(
|
||||
_albumArt!,
|
||||
width: albumSize,
|
||||
height: albumSize,
|
||||
)
|
||||
: Container(
|
||||
color: Theme.of(context)
|
||||
.colorScheme
|
||||
.surfaceContainerHigh,
|
||||
width: 64,
|
||||
height: 64,
|
||||
child: const Center(
|
||||
child: Icon(Icons.image),
|
||||
() => Center(
|
||||
child: LimitedBox(
|
||||
maxHeight: maxAlbumSize,
|
||||
maxWidth: maxAlbumSize,
|
||||
child: Hero(
|
||||
tag: const Key('current-active-track-album-art'),
|
||||
child: AspectRatio(
|
||||
aspectRatio: 1,
|
||||
child: ClipRRect(
|
||||
borderRadius: const BorderRadius.all(
|
||||
Radius.circular(16),
|
||||
),
|
||||
child: _albumArt != null
|
||||
? AutoCacheImage(
|
||||
_albumArt!,
|
||||
width: albumSize,
|
||||
height: albumSize,
|
||||
fit: BoxFit.cover,
|
||||
)
|
||||
: Container(
|
||||
color: Theme.of(context)
|
||||
.colorScheme
|
||||
.surfaceContainerHigh,
|
||||
width: 64,
|
||||
height: 64,
|
||||
child: const Center(
|
||||
child: Icon(Icons.image),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
).marginSymmetric(horizontal: 24),
|
||||
),
|
||||
).marginSymmetric(horizontal: 24),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
@ -309,86 +313,89 @@ class _PlayerScreenState extends State<PlayerScreen> {
|
||||
],
|
||||
),
|
||||
const Gap(20),
|
||||
SizedBox(
|
||||
height: 40,
|
||||
child: ListView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
children: [
|
||||
TextButton.icon(
|
||||
icon: const Icon(Icons.queue_music),
|
||||
label: const Text(
|
||||
'Queue',
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.fade,
|
||||
),
|
||||
onPressed: () {
|
||||
showModalBottomSheet(
|
||||
useRootNavigator: true,
|
||||
isScrollControlled: true,
|
||||
context: context,
|
||||
builder: (context) =>
|
||||
const PlayerQueuePopup(),
|
||||
).then((_) {
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
}
|
||||
});
|
||||
},
|
||||
),
|
||||
if (!isLargeScreen) const Gap(4),
|
||||
if (!isLargeScreen)
|
||||
Center(
|
||||
child: SizedBox(
|
||||
height: 40,
|
||||
child: ListView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
shrinkWrap: true,
|
||||
children: [
|
||||
TextButton.icon(
|
||||
icon: const Icon(Icons.lyrics),
|
||||
icon: const Icon(Icons.queue_music),
|
||||
label: const Text(
|
||||
'Lyrics',
|
||||
'Queue',
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.fade,
|
||||
),
|
||||
onPressed: () {
|
||||
GoRouter.of(context)
|
||||
.pushNamed('playerLyrics');
|
||||
showModalBottomSheet(
|
||||
useRootNavigator: true,
|
||||
isScrollControlled: true,
|
||||
context: context,
|
||||
builder: (context) =>
|
||||
const PlayerQueuePopup(),
|
||||
).then((_) {
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
}
|
||||
});
|
||||
},
|
||||
),
|
||||
const Gap(4),
|
||||
TextButton.icon(
|
||||
icon: const Icon(Icons.merge),
|
||||
label: const Text(
|
||||
'Sources',
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.fade,
|
||||
if (!isLargeScreen) const Gap(4),
|
||||
if (!isLargeScreen)
|
||||
TextButton.icon(
|
||||
icon: const Icon(Icons.lyrics),
|
||||
label: const Text(
|
||||
'Lyrics',
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.fade,
|
||||
),
|
||||
onPressed: () {
|
||||
GoRouter.of(context)
|
||||
.pushNamed('playerLyrics');
|
||||
},
|
||||
),
|
||||
const Gap(4),
|
||||
TextButton.icon(
|
||||
icon: const Icon(Icons.merge),
|
||||
label: const Text(
|
||||
'Sources',
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.fade,
|
||||
),
|
||||
onPressed: () {
|
||||
showModalBottomSheet(
|
||||
useRootNavigator: true,
|
||||
isScrollControlled: true,
|
||||
context: context,
|
||||
builder: (context) =>
|
||||
const SiblingTracksPopup(),
|
||||
).then((_) {
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
}
|
||||
});
|
||||
},
|
||||
),
|
||||
onPressed: () {
|
||||
showModalBottomSheet(
|
||||
useRootNavigator: true,
|
||||
isScrollControlled: true,
|
||||
context: context,
|
||||
builder: (context) =>
|
||||
const SiblingTracksPopup(),
|
||||
).then((_) {
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
}
|
||||
});
|
||||
},
|
||||
),
|
||||
const Gap(4),
|
||||
TextButton.icon(
|
||||
label: const Text('Info'),
|
||||
icon: const Icon(Icons.info),
|
||||
onPressed: () {
|
||||
showModalBottomSheet(
|
||||
useRootNavigator: true,
|
||||
context: context,
|
||||
builder: (context) =>
|
||||
const SourceDetailsPopup(),
|
||||
).then((_) {
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
}
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
const Gap(4),
|
||||
TextButton.icon(
|
||||
label: const Text('Info'),
|
||||
icon: const Icon(Icons.info),
|
||||
onPressed: () {
|
||||
showModalBottomSheet(
|
||||
useRootNavigator: true,
|
||||
context: context,
|
||||
builder: (context) =>
|
||||
const SourceDetailsPopup(),
|
||||
).then((_) {
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
}
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
@ -7,6 +7,7 @@ import 'package:rhythm_box/providers/spotify.dart';
|
||||
import 'package:rhythm_box/providers/user_preferences.dart';
|
||||
import 'package:rhythm_box/screens/auth/login.dart';
|
||||
import 'package:rhythm_box/services/database/database.dart';
|
||||
import 'package:rhythm_box/services/sourced_track/sources/netease.dart';
|
||||
import 'package:rhythm_box/widgets/auto_cache_image.dart';
|
||||
import 'package:rhythm_box/widgets/sized_container.dart';
|
||||
|
||||
@ -86,6 +87,75 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
},
|
||||
);
|
||||
}),
|
||||
Obx(() {
|
||||
if (_authenticate.auth.value == null) {
|
||||
return const SizedBox();
|
||||
}
|
||||
if (_authenticate.auth.value?.neteaseCookie == null) {
|
||||
return ListTile(
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 24),
|
||||
leading: const Icon(Icons.cloud_outlined),
|
||||
title: const Text('Connect with Netease Cloud Music'),
|
||||
subtitle: const Text(
|
||||
'Make us able to play more music from Netease Cloud Music'),
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
enabled: !_isLoggingIn,
|
||||
onTap: () async {
|
||||
setState(() => _isLoggingIn = true);
|
||||
await GoRouter.of(context)
|
||||
.pushNamed('authMobileLoginNetease');
|
||||
setState(() => _isLoggingIn = false);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
return FutureBuilder(
|
||||
future: NeteaseSourcedTrack.getClient().get('/user/account'),
|
||||
builder: (context, snapshot) {
|
||||
if (!snapshot.hasData) {
|
||||
return ListTile(
|
||||
contentPadding:
|
||||
const EdgeInsets.symmetric(horizontal: 24),
|
||||
leading: const SizedBox(
|
||||
width: 20,
|
||||
height: 20,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 3,
|
||||
),
|
||||
),
|
||||
title: const Text('Loading...'),
|
||||
trailing: IconButton(
|
||||
onPressed: () {
|
||||
_authenticate.logoutNetease();
|
||||
},
|
||||
icon: const Icon(Icons.link_off),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return ListTile(
|
||||
leading:
|
||||
snapshot.data!.body['profile']['avatarUrl'] != null
|
||||
? CircleAvatar(
|
||||
backgroundImage: AutoCacheImage.provider(
|
||||
snapshot.data!.body['profile']['avatarUrl'],
|
||||
),
|
||||
)
|
||||
: const Icon(Icons.account_circle),
|
||||
title: Text(snapshot.data!.body['profile']['nickname']),
|
||||
subtitle: const Text(
|
||||
'Connected with your Netease Cloud Music account',
|
||||
),
|
||||
trailing: IconButton(
|
||||
onPressed: () {
|
||||
_authenticate.logoutNetease();
|
||||
},
|
||||
icon: const Icon(Icons.link_off),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}),
|
||||
Obx(() {
|
||||
if (_authenticate.auth.value == null) {
|
||||
return const SizedBox();
|
||||
@ -95,7 +165,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 24),
|
||||
leading: const Icon(Icons.logout),
|
||||
title: const Text('Log out'),
|
||||
subtitle: const Text('Disconnect with this Spotify account'),
|
||||
subtitle: const Text('Disconnect with every account'),
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
onTap: () async {
|
||||
_authenticate.logout();
|
||||
|
@ -55,7 +55,7 @@ class AppDatabase extends _$AppDatabase {
|
||||
AppDatabase() : super(_openConnection());
|
||||
|
||||
@override
|
||||
int get schemaVersion => 2;
|
||||
int get schemaVersion => 1;
|
||||
|
||||
@override
|
||||
MigrationStrategy get migration {
|
||||
@ -63,11 +63,7 @@ class AppDatabase extends _$AppDatabase {
|
||||
onCreate: (Migrator m) async {
|
||||
await m.createAll();
|
||||
},
|
||||
onUpgrade: (Migrator m, int from, int to) async {
|
||||
if (from < 2) {
|
||||
await m.addColumn(preferencesTable, preferencesTable.playerWakelock);
|
||||
}
|
||||
},
|
||||
onUpgrade: (Migrator m, int from, int to) async {},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -18,29 +18,54 @@ class $AuthenticationTableTable extends AuthenticationTable
|
||||
requiredDuringInsert: false,
|
||||
defaultConstraints:
|
||||
GeneratedColumn.constraintIsAlways('PRIMARY KEY AUTOINCREMENT'));
|
||||
static const VerificationMeta _cookieMeta = const VerificationMeta('cookie');
|
||||
@override
|
||||
late final GeneratedColumnWithTypeConverter<DecryptedText, String> cookie =
|
||||
GeneratedColumn<String>('cookie', aliasedName, false,
|
||||
type: DriftSqlType.string, requiredDuringInsert: true)
|
||||
.withConverter<DecryptedText>(
|
||||
$AuthenticationTableTable.$convertercookie);
|
||||
static const VerificationMeta _accessTokenMeta =
|
||||
const VerificationMeta('accessToken');
|
||||
static const VerificationMeta _spotifyCookieMeta =
|
||||
const VerificationMeta('spotifyCookie');
|
||||
@override
|
||||
late final GeneratedColumnWithTypeConverter<DecryptedText, String>
|
||||
accessToken = GeneratedColumn<String>('access_token', aliasedName, false,
|
||||
spotifyCookie = GeneratedColumn<String>(
|
||||
'spotify_cookie', aliasedName, false,
|
||||
type: DriftSqlType.string, requiredDuringInsert: true)
|
||||
.withConverter<DecryptedText>(
|
||||
$AuthenticationTableTable.$converteraccessToken);
|
||||
static const VerificationMeta _expirationMeta =
|
||||
const VerificationMeta('expiration');
|
||||
$AuthenticationTableTable.$converterspotifyCookie);
|
||||
static const VerificationMeta _spotifyAccessTokenMeta =
|
||||
const VerificationMeta('spotifyAccessToken');
|
||||
@override
|
||||
late final GeneratedColumn<DateTime> expiration = GeneratedColumn<DateTime>(
|
||||
'expiration', aliasedName, false,
|
||||
type: DriftSqlType.dateTime, requiredDuringInsert: true);
|
||||
late final GeneratedColumnWithTypeConverter<DecryptedText, String>
|
||||
spotifyAccessToken = GeneratedColumn<String>(
|
||||
'spotify_access_token', aliasedName, false,
|
||||
type: DriftSqlType.string, requiredDuringInsert: true)
|
||||
.withConverter<DecryptedText>(
|
||||
$AuthenticationTableTable.$converterspotifyAccessToken);
|
||||
static const VerificationMeta _spotifyExpirationMeta =
|
||||
const VerificationMeta('spotifyExpiration');
|
||||
@override
|
||||
List<GeneratedColumn> get $columns => [id, cookie, accessToken, expiration];
|
||||
late final GeneratedColumn<DateTime> spotifyExpiration =
|
||||
GeneratedColumn<DateTime>('spotify_expiration', aliasedName, false,
|
||||
type: DriftSqlType.dateTime, requiredDuringInsert: true);
|
||||
static const VerificationMeta _neteaseCookieMeta =
|
||||
const VerificationMeta('neteaseCookie');
|
||||
@override
|
||||
late final GeneratedColumnWithTypeConverter<DecryptedText?, String>
|
||||
neteaseCookie = GeneratedColumn<String>(
|
||||
'netease_cookie', aliasedName, true,
|
||||
type: DriftSqlType.string, requiredDuringInsert: false)
|
||||
.withConverter<DecryptedText?>(
|
||||
$AuthenticationTableTable.$converterneteaseCookien);
|
||||
static const VerificationMeta _neteaseExpirationMeta =
|
||||
const VerificationMeta('neteaseExpiration');
|
||||
@override
|
||||
late final GeneratedColumn<DateTime> neteaseExpiration =
|
||||
GeneratedColumn<DateTime>('netease_expiration', aliasedName, true,
|
||||
type: DriftSqlType.dateTime, requiredDuringInsert: false);
|
||||
@override
|
||||
List<GeneratedColumn> get $columns => [
|
||||
id,
|
||||
spotifyCookie,
|
||||
spotifyAccessToken,
|
||||
spotifyExpiration,
|
||||
neteaseCookie,
|
||||
neteaseExpiration
|
||||
];
|
||||
@override
|
||||
String get aliasedName => _alias ?? actualTableName;
|
||||
@override
|
||||
@ -55,15 +80,22 @@ class $AuthenticationTableTable extends AuthenticationTable
|
||||
if (data.containsKey('id')) {
|
||||
context.handle(_idMeta, id.isAcceptableOrUnknown(data['id']!, _idMeta));
|
||||
}
|
||||
context.handle(_cookieMeta, const VerificationResult.success());
|
||||
context.handle(_accessTokenMeta, const VerificationResult.success());
|
||||
if (data.containsKey('expiration')) {
|
||||
context.handle(_spotifyCookieMeta, const VerificationResult.success());
|
||||
context.handle(_spotifyAccessTokenMeta, const VerificationResult.success());
|
||||
if (data.containsKey('spotify_expiration')) {
|
||||
context.handle(
|
||||
_expirationMeta,
|
||||
expiration.isAcceptableOrUnknown(
|
||||
data['expiration']!, _expirationMeta));
|
||||
_spotifyExpirationMeta,
|
||||
spotifyExpiration.isAcceptableOrUnknown(
|
||||
data['spotify_expiration']!, _spotifyExpirationMeta));
|
||||
} else if (isInserting) {
|
||||
context.missing(_expirationMeta);
|
||||
context.missing(_spotifyExpirationMeta);
|
||||
}
|
||||
context.handle(_neteaseCookieMeta, const VerificationResult.success());
|
||||
if (data.containsKey('netease_expiration')) {
|
||||
context.handle(
|
||||
_neteaseExpirationMeta,
|
||||
neteaseExpiration.isAcceptableOrUnknown(
|
||||
data['netease_expiration']!, _neteaseExpirationMeta));
|
||||
}
|
||||
return context;
|
||||
}
|
||||
@ -77,14 +109,19 @@ class $AuthenticationTableTable extends AuthenticationTable
|
||||
return AuthenticationTableData(
|
||||
id: attachedDatabase.typeMapping
|
||||
.read(DriftSqlType.int, data['${effectivePrefix}id'])!,
|
||||
cookie: $AuthenticationTableTable.$convertercookie.fromSql(
|
||||
attachedDatabase.typeMapping
|
||||
.read(DriftSqlType.string, data['${effectivePrefix}cookie'])!),
|
||||
accessToken: $AuthenticationTableTable.$converteraccessToken.fromSql(
|
||||
spotifyCookie: $AuthenticationTableTable.$converterspotifyCookie.fromSql(
|
||||
attachedDatabase.typeMapping.read(
|
||||
DriftSqlType.string, data['${effectivePrefix}access_token'])!),
|
||||
expiration: attachedDatabase.typeMapping
|
||||
.read(DriftSqlType.dateTime, data['${effectivePrefix}expiration'])!,
|
||||
DriftSqlType.string, data['${effectivePrefix}spotify_cookie'])!),
|
||||
spotifyAccessToken: $AuthenticationTableTable.$converterspotifyAccessToken
|
||||
.fromSql(attachedDatabase.typeMapping.read(DriftSqlType.string,
|
||||
data['${effectivePrefix}spotify_access_token'])!),
|
||||
spotifyExpiration: attachedDatabase.typeMapping.read(
|
||||
DriftSqlType.dateTime, data['${effectivePrefix}spotify_expiration'])!,
|
||||
neteaseCookie: $AuthenticationTableTable.$converterneteaseCookien.fromSql(
|
||||
attachedDatabase.typeMapping.read(
|
||||
DriftSqlType.string, data['${effectivePrefix}netease_cookie'])),
|
||||
neteaseExpiration: attachedDatabase.typeMapping.read(
|
||||
DriftSqlType.dateTime, data['${effectivePrefix}netease_expiration']),
|
||||
);
|
||||
}
|
||||
|
||||
@ -93,45 +130,69 @@ class $AuthenticationTableTable extends AuthenticationTable
|
||||
return $AuthenticationTableTable(attachedDatabase, alias);
|
||||
}
|
||||
|
||||
static TypeConverter<DecryptedText, String> $convertercookie =
|
||||
static TypeConverter<DecryptedText, String> $converterspotifyCookie =
|
||||
EncryptedTextConverter();
|
||||
static TypeConverter<DecryptedText, String> $converteraccessToken =
|
||||
static TypeConverter<DecryptedText, String> $converterspotifyAccessToken =
|
||||
EncryptedTextConverter();
|
||||
static TypeConverter<DecryptedText, String> $converterneteaseCookie =
|
||||
EncryptedTextConverter();
|
||||
static TypeConverter<DecryptedText?, String?> $converterneteaseCookien =
|
||||
NullAwareTypeConverter.wrap($converterneteaseCookie);
|
||||
}
|
||||
|
||||
class AuthenticationTableData extends DataClass
|
||||
implements Insertable<AuthenticationTableData> {
|
||||
final int id;
|
||||
final DecryptedText cookie;
|
||||
final DecryptedText accessToken;
|
||||
final DateTime expiration;
|
||||
final DecryptedText spotifyCookie;
|
||||
final DecryptedText spotifyAccessToken;
|
||||
final DateTime spotifyExpiration;
|
||||
final DecryptedText? neteaseCookie;
|
||||
final DateTime? neteaseExpiration;
|
||||
const AuthenticationTableData(
|
||||
{required this.id,
|
||||
required this.cookie,
|
||||
required this.accessToken,
|
||||
required this.expiration});
|
||||
required this.spotifyCookie,
|
||||
required this.spotifyAccessToken,
|
||||
required this.spotifyExpiration,
|
||||
this.neteaseCookie,
|
||||
this.neteaseExpiration});
|
||||
@override
|
||||
Map<String, Expression> toColumns(bool nullToAbsent) {
|
||||
final map = <String, Expression>{};
|
||||
map['id'] = Variable<int>(id);
|
||||
{
|
||||
map['cookie'] = Variable<String>(
|
||||
$AuthenticationTableTable.$convertercookie.toSql(cookie));
|
||||
map['spotify_cookie'] = Variable<String>($AuthenticationTableTable
|
||||
.$converterspotifyCookie
|
||||
.toSql(spotifyCookie));
|
||||
}
|
||||
{
|
||||
map['access_token'] = Variable<String>(
|
||||
$AuthenticationTableTable.$converteraccessToken.toSql(accessToken));
|
||||
map['spotify_access_token'] = Variable<String>($AuthenticationTableTable
|
||||
.$converterspotifyAccessToken
|
||||
.toSql(spotifyAccessToken));
|
||||
}
|
||||
map['spotify_expiration'] = Variable<DateTime>(spotifyExpiration);
|
||||
if (!nullToAbsent || neteaseCookie != null) {
|
||||
map['netease_cookie'] = Variable<String>($AuthenticationTableTable
|
||||
.$converterneteaseCookien
|
||||
.toSql(neteaseCookie));
|
||||
}
|
||||
if (!nullToAbsent || neteaseExpiration != null) {
|
||||
map['netease_expiration'] = Variable<DateTime>(neteaseExpiration);
|
||||
}
|
||||
map['expiration'] = Variable<DateTime>(expiration);
|
||||
return map;
|
||||
}
|
||||
|
||||
AuthenticationTableCompanion toCompanion(bool nullToAbsent) {
|
||||
return AuthenticationTableCompanion(
|
||||
id: Value(id),
|
||||
cookie: Value(cookie),
|
||||
accessToken: Value(accessToken),
|
||||
expiration: Value(expiration),
|
||||
spotifyCookie: Value(spotifyCookie),
|
||||
spotifyAccessToken: Value(spotifyAccessToken),
|
||||
spotifyExpiration: Value(spotifyExpiration),
|
||||
neteaseCookie: neteaseCookie == null && nullToAbsent
|
||||
? const Value.absent()
|
||||
: Value(neteaseCookie),
|
||||
neteaseExpiration: neteaseExpiration == null && nullToAbsent
|
||||
? const Value.absent()
|
||||
: Value(neteaseExpiration),
|
||||
);
|
||||
}
|
||||
|
||||
@ -140,9 +201,14 @@ class AuthenticationTableData extends DataClass
|
||||
serializer ??= driftRuntimeOptions.defaultSerializer;
|
||||
return AuthenticationTableData(
|
||||
id: serializer.fromJson<int>(json['id']),
|
||||
cookie: serializer.fromJson<DecryptedText>(json['cookie']),
|
||||
accessToken: serializer.fromJson<DecryptedText>(json['accessToken']),
|
||||
expiration: serializer.fromJson<DateTime>(json['expiration']),
|
||||
spotifyCookie: serializer.fromJson<DecryptedText>(json['spotifyCookie']),
|
||||
spotifyAccessToken:
|
||||
serializer.fromJson<DecryptedText>(json['spotifyAccessToken']),
|
||||
spotifyExpiration:
|
||||
serializer.fromJson<DateTime>(json['spotifyExpiration']),
|
||||
neteaseCookie: serializer.fromJson<DecryptedText?>(json['neteaseCookie']),
|
||||
neteaseExpiration:
|
||||
serializer.fromJson<DateTime?>(json['neteaseExpiration']),
|
||||
);
|
||||
}
|
||||
@override
|
||||
@ -150,31 +216,51 @@ class AuthenticationTableData extends DataClass
|
||||
serializer ??= driftRuntimeOptions.defaultSerializer;
|
||||
return <String, dynamic>{
|
||||
'id': serializer.toJson<int>(id),
|
||||
'cookie': serializer.toJson<DecryptedText>(cookie),
|
||||
'accessToken': serializer.toJson<DecryptedText>(accessToken),
|
||||
'expiration': serializer.toJson<DateTime>(expiration),
|
||||
'spotifyCookie': serializer.toJson<DecryptedText>(spotifyCookie),
|
||||
'spotifyAccessToken':
|
||||
serializer.toJson<DecryptedText>(spotifyAccessToken),
|
||||
'spotifyExpiration': serializer.toJson<DateTime>(spotifyExpiration),
|
||||
'neteaseCookie': serializer.toJson<DecryptedText?>(neteaseCookie),
|
||||
'neteaseExpiration': serializer.toJson<DateTime?>(neteaseExpiration),
|
||||
};
|
||||
}
|
||||
|
||||
AuthenticationTableData copyWith(
|
||||
{int? id,
|
||||
DecryptedText? cookie,
|
||||
DecryptedText? accessToken,
|
||||
DateTime? expiration}) =>
|
||||
DecryptedText? spotifyCookie,
|
||||
DecryptedText? spotifyAccessToken,
|
||||
DateTime? spotifyExpiration,
|
||||
Value<DecryptedText?> neteaseCookie = const Value.absent(),
|
||||
Value<DateTime?> neteaseExpiration = const Value.absent()}) =>
|
||||
AuthenticationTableData(
|
||||
id: id ?? this.id,
|
||||
cookie: cookie ?? this.cookie,
|
||||
accessToken: accessToken ?? this.accessToken,
|
||||
expiration: expiration ?? this.expiration,
|
||||
spotifyCookie: spotifyCookie ?? this.spotifyCookie,
|
||||
spotifyAccessToken: spotifyAccessToken ?? this.spotifyAccessToken,
|
||||
spotifyExpiration: spotifyExpiration ?? this.spotifyExpiration,
|
||||
neteaseCookie:
|
||||
neteaseCookie.present ? neteaseCookie.value : this.neteaseCookie,
|
||||
neteaseExpiration: neteaseExpiration.present
|
||||
? neteaseExpiration.value
|
||||
: this.neteaseExpiration,
|
||||
);
|
||||
AuthenticationTableData copyWithCompanion(AuthenticationTableCompanion data) {
|
||||
return AuthenticationTableData(
|
||||
id: data.id.present ? data.id.value : this.id,
|
||||
cookie: data.cookie.present ? data.cookie.value : this.cookie,
|
||||
accessToken:
|
||||
data.accessToken.present ? data.accessToken.value : this.accessToken,
|
||||
expiration:
|
||||
data.expiration.present ? data.expiration.value : this.expiration,
|
||||
spotifyCookie: data.spotifyCookie.present
|
||||
? data.spotifyCookie.value
|
||||
: this.spotifyCookie,
|
||||
spotifyAccessToken: data.spotifyAccessToken.present
|
||||
? data.spotifyAccessToken.value
|
||||
: this.spotifyAccessToken,
|
||||
spotifyExpiration: data.spotifyExpiration.present
|
||||
? data.spotifyExpiration.value
|
||||
: this.spotifyExpiration,
|
||||
neteaseCookie: data.neteaseCookie.present
|
||||
? data.neteaseCookie.value
|
||||
: this.neteaseCookie,
|
||||
neteaseExpiration: data.neteaseExpiration.present
|
||||
? data.neteaseExpiration.value
|
||||
: this.neteaseExpiration,
|
||||
);
|
||||
}
|
||||
|
||||
@ -182,69 +268,89 @@ class AuthenticationTableData extends DataClass
|
||||
String toString() {
|
||||
return (StringBuffer('AuthenticationTableData(')
|
||||
..write('id: $id, ')
|
||||
..write('cookie: $cookie, ')
|
||||
..write('accessToken: $accessToken, ')
|
||||
..write('expiration: $expiration')
|
||||
..write('spotifyCookie: $spotifyCookie, ')
|
||||
..write('spotifyAccessToken: $spotifyAccessToken, ')
|
||||
..write('spotifyExpiration: $spotifyExpiration, ')
|
||||
..write('neteaseCookie: $neteaseCookie, ')
|
||||
..write('neteaseExpiration: $neteaseExpiration')
|
||||
..write(')'))
|
||||
.toString();
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(id, cookie, accessToken, expiration);
|
||||
int get hashCode => Object.hash(id, spotifyCookie, spotifyAccessToken,
|
||||
spotifyExpiration, neteaseCookie, neteaseExpiration);
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
(other is AuthenticationTableData &&
|
||||
other.id == this.id &&
|
||||
other.cookie == this.cookie &&
|
||||
other.accessToken == this.accessToken &&
|
||||
other.expiration == this.expiration);
|
||||
other.spotifyCookie == this.spotifyCookie &&
|
||||
other.spotifyAccessToken == this.spotifyAccessToken &&
|
||||
other.spotifyExpiration == this.spotifyExpiration &&
|
||||
other.neteaseCookie == this.neteaseCookie &&
|
||||
other.neteaseExpiration == this.neteaseExpiration);
|
||||
}
|
||||
|
||||
class AuthenticationTableCompanion
|
||||
extends UpdateCompanion<AuthenticationTableData> {
|
||||
final Value<int> id;
|
||||
final Value<DecryptedText> cookie;
|
||||
final Value<DecryptedText> accessToken;
|
||||
final Value<DateTime> expiration;
|
||||
final Value<DecryptedText> spotifyCookie;
|
||||
final Value<DecryptedText> spotifyAccessToken;
|
||||
final Value<DateTime> spotifyExpiration;
|
||||
final Value<DecryptedText?> neteaseCookie;
|
||||
final Value<DateTime?> neteaseExpiration;
|
||||
const AuthenticationTableCompanion({
|
||||
this.id = const Value.absent(),
|
||||
this.cookie = const Value.absent(),
|
||||
this.accessToken = const Value.absent(),
|
||||
this.expiration = const Value.absent(),
|
||||
this.spotifyCookie = const Value.absent(),
|
||||
this.spotifyAccessToken = const Value.absent(),
|
||||
this.spotifyExpiration = const Value.absent(),
|
||||
this.neteaseCookie = const Value.absent(),
|
||||
this.neteaseExpiration = const Value.absent(),
|
||||
});
|
||||
AuthenticationTableCompanion.insert({
|
||||
this.id = const Value.absent(),
|
||||
required DecryptedText cookie,
|
||||
required DecryptedText accessToken,
|
||||
required DateTime expiration,
|
||||
}) : cookie = Value(cookie),
|
||||
accessToken = Value(accessToken),
|
||||
expiration = Value(expiration);
|
||||
required DecryptedText spotifyCookie,
|
||||
required DecryptedText spotifyAccessToken,
|
||||
required DateTime spotifyExpiration,
|
||||
this.neteaseCookie = const Value.absent(),
|
||||
this.neteaseExpiration = const Value.absent(),
|
||||
}) : spotifyCookie = Value(spotifyCookie),
|
||||
spotifyAccessToken = Value(spotifyAccessToken),
|
||||
spotifyExpiration = Value(spotifyExpiration);
|
||||
static Insertable<AuthenticationTableData> custom({
|
||||
Expression<int>? id,
|
||||
Expression<String>? cookie,
|
||||
Expression<String>? accessToken,
|
||||
Expression<DateTime>? expiration,
|
||||
Expression<String>? spotifyCookie,
|
||||
Expression<String>? spotifyAccessToken,
|
||||
Expression<DateTime>? spotifyExpiration,
|
||||
Expression<String>? neteaseCookie,
|
||||
Expression<DateTime>? neteaseExpiration,
|
||||
}) {
|
||||
return RawValuesInsertable({
|
||||
if (id != null) 'id': id,
|
||||
if (cookie != null) 'cookie': cookie,
|
||||
if (accessToken != null) 'access_token': accessToken,
|
||||
if (expiration != null) 'expiration': expiration,
|
||||
if (spotifyCookie != null) 'spotify_cookie': spotifyCookie,
|
||||
if (spotifyAccessToken != null)
|
||||
'spotify_access_token': spotifyAccessToken,
|
||||
if (spotifyExpiration != null) 'spotify_expiration': spotifyExpiration,
|
||||
if (neteaseCookie != null) 'netease_cookie': neteaseCookie,
|
||||
if (neteaseExpiration != null) 'netease_expiration': neteaseExpiration,
|
||||
});
|
||||
}
|
||||
|
||||
AuthenticationTableCompanion copyWith(
|
||||
{Value<int>? id,
|
||||
Value<DecryptedText>? cookie,
|
||||
Value<DecryptedText>? accessToken,
|
||||
Value<DateTime>? expiration}) {
|
||||
Value<DecryptedText>? spotifyCookie,
|
||||
Value<DecryptedText>? spotifyAccessToken,
|
||||
Value<DateTime>? spotifyExpiration,
|
||||
Value<DecryptedText?>? neteaseCookie,
|
||||
Value<DateTime?>? neteaseExpiration}) {
|
||||
return AuthenticationTableCompanion(
|
||||
id: id ?? this.id,
|
||||
cookie: cookie ?? this.cookie,
|
||||
accessToken: accessToken ?? this.accessToken,
|
||||
expiration: expiration ?? this.expiration,
|
||||
spotifyCookie: spotifyCookie ?? this.spotifyCookie,
|
||||
spotifyAccessToken: spotifyAccessToken ?? this.spotifyAccessToken,
|
||||
spotifyExpiration: spotifyExpiration ?? this.spotifyExpiration,
|
||||
neteaseCookie: neteaseCookie ?? this.neteaseCookie,
|
||||
neteaseExpiration: neteaseExpiration ?? this.neteaseExpiration,
|
||||
);
|
||||
}
|
||||
|
||||
@ -254,17 +360,26 @@ class AuthenticationTableCompanion
|
||||
if (id.present) {
|
||||
map['id'] = Variable<int>(id.value);
|
||||
}
|
||||
if (cookie.present) {
|
||||
map['cookie'] = Variable<String>(
|
||||
$AuthenticationTableTable.$convertercookie.toSql(cookie.value));
|
||||
if (spotifyCookie.present) {
|
||||
map['spotify_cookie'] = Variable<String>($AuthenticationTableTable
|
||||
.$converterspotifyCookie
|
||||
.toSql(spotifyCookie.value));
|
||||
}
|
||||
if (accessToken.present) {
|
||||
map['access_token'] = Variable<String>($AuthenticationTableTable
|
||||
.$converteraccessToken
|
||||
.toSql(accessToken.value));
|
||||
if (spotifyAccessToken.present) {
|
||||
map['spotify_access_token'] = Variable<String>($AuthenticationTableTable
|
||||
.$converterspotifyAccessToken
|
||||
.toSql(spotifyAccessToken.value));
|
||||
}
|
||||
if (expiration.present) {
|
||||
map['expiration'] = Variable<DateTime>(expiration.value);
|
||||
if (spotifyExpiration.present) {
|
||||
map['spotify_expiration'] = Variable<DateTime>(spotifyExpiration.value);
|
||||
}
|
||||
if (neteaseCookie.present) {
|
||||
map['netease_cookie'] = Variable<String>($AuthenticationTableTable
|
||||
.$converterneteaseCookien
|
||||
.toSql(neteaseCookie.value));
|
||||
}
|
||||
if (neteaseExpiration.present) {
|
||||
map['netease_expiration'] = Variable<DateTime>(neteaseExpiration.value);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
@ -273,9 +388,11 @@ class AuthenticationTableCompanion
|
||||
String toString() {
|
||||
return (StringBuffer('AuthenticationTableCompanion(')
|
||||
..write('id: $id, ')
|
||||
..write('cookie: $cookie, ')
|
||||
..write('accessToken: $accessToken, ')
|
||||
..write('expiration: $expiration')
|
||||
..write('spotifyCookie: $spotifyCookie, ')
|
||||
..write('spotifyAccessToken: $spotifyAccessToken, ')
|
||||
..write('spotifyExpiration: $spotifyExpiration, ')
|
||||
..write('neteaseCookie: $neteaseCookie, ')
|
||||
..write('neteaseExpiration: $neteaseExpiration')
|
||||
..write(')'))
|
||||
.toString();
|
||||
}
|
||||
@ -3824,16 +3941,20 @@ abstract class _$AppDatabase extends GeneratedDatabase {
|
||||
typedef $$AuthenticationTableTableCreateCompanionBuilder
|
||||
= AuthenticationTableCompanion Function({
|
||||
Value<int> id,
|
||||
required DecryptedText cookie,
|
||||
required DecryptedText accessToken,
|
||||
required DateTime expiration,
|
||||
required DecryptedText spotifyCookie,
|
||||
required DecryptedText spotifyAccessToken,
|
||||
required DateTime spotifyExpiration,
|
||||
Value<DecryptedText?> neteaseCookie,
|
||||
Value<DateTime?> neteaseExpiration,
|
||||
});
|
||||
typedef $$AuthenticationTableTableUpdateCompanionBuilder
|
||||
= AuthenticationTableCompanion Function({
|
||||
Value<int> id,
|
||||
Value<DecryptedText> cookie,
|
||||
Value<DecryptedText> accessToken,
|
||||
Value<DateTime> expiration,
|
||||
Value<DecryptedText> spotifyCookie,
|
||||
Value<DecryptedText> spotifyAccessToken,
|
||||
Value<DateTime> spotifyExpiration,
|
||||
Value<DecryptedText?> neteaseCookie,
|
||||
Value<DateTime?> neteaseExpiration,
|
||||
});
|
||||
|
||||
class $$AuthenticationTableTableTableManager extends RootTableManager<
|
||||
@ -3855,27 +3976,35 @@ class $$AuthenticationTableTableTableManager extends RootTableManager<
|
||||
ComposerState(db, table)),
|
||||
updateCompanionCallback: ({
|
||||
Value<int> id = const Value.absent(),
|
||||
Value<DecryptedText> cookie = const Value.absent(),
|
||||
Value<DecryptedText> accessToken = const Value.absent(),
|
||||
Value<DateTime> expiration = const Value.absent(),
|
||||
Value<DecryptedText> spotifyCookie = const Value.absent(),
|
||||
Value<DecryptedText> spotifyAccessToken = const Value.absent(),
|
||||
Value<DateTime> spotifyExpiration = const Value.absent(),
|
||||
Value<DecryptedText?> neteaseCookie = const Value.absent(),
|
||||
Value<DateTime?> neteaseExpiration = const Value.absent(),
|
||||
}) =>
|
||||
AuthenticationTableCompanion(
|
||||
id: id,
|
||||
cookie: cookie,
|
||||
accessToken: accessToken,
|
||||
expiration: expiration,
|
||||
spotifyCookie: spotifyCookie,
|
||||
spotifyAccessToken: spotifyAccessToken,
|
||||
spotifyExpiration: spotifyExpiration,
|
||||
neteaseCookie: neteaseCookie,
|
||||
neteaseExpiration: neteaseExpiration,
|
||||
),
|
||||
createCompanionCallback: ({
|
||||
Value<int> id = const Value.absent(),
|
||||
required DecryptedText cookie,
|
||||
required DecryptedText accessToken,
|
||||
required DateTime expiration,
|
||||
required DecryptedText spotifyCookie,
|
||||
required DecryptedText spotifyAccessToken,
|
||||
required DateTime spotifyExpiration,
|
||||
Value<DecryptedText?> neteaseCookie = const Value.absent(),
|
||||
Value<DateTime?> neteaseExpiration = const Value.absent(),
|
||||
}) =>
|
||||
AuthenticationTableCompanion.insert(
|
||||
id: id,
|
||||
cookie: cookie,
|
||||
accessToken: accessToken,
|
||||
expiration: expiration,
|
||||
spotifyCookie: spotifyCookie,
|
||||
spotifyAccessToken: spotifyAccessToken,
|
||||
spotifyExpiration: spotifyExpiration,
|
||||
neteaseCookie: neteaseCookie,
|
||||
neteaseExpiration: neteaseExpiration,
|
||||
),
|
||||
));
|
||||
}
|
||||
@ -3889,21 +4018,33 @@ class $$AuthenticationTableTableFilterComposer
|
||||
ColumnFilters(column, joinBuilders: joinBuilders));
|
||||
|
||||
ColumnWithTypeConverterFilters<DecryptedText, DecryptedText, String>
|
||||
get cookie => $state.composableBuilder(
|
||||
column: $state.table.cookie,
|
||||
get spotifyCookie => $state.composableBuilder(
|
||||
column: $state.table.spotifyCookie,
|
||||
builder: (column, joinBuilders) => ColumnWithTypeConverterFilters(
|
||||
column,
|
||||
joinBuilders: joinBuilders));
|
||||
|
||||
ColumnWithTypeConverterFilters<DecryptedText, DecryptedText, String>
|
||||
get accessToken => $state.composableBuilder(
|
||||
column: $state.table.accessToken,
|
||||
get spotifyAccessToken => $state.composableBuilder(
|
||||
column: $state.table.spotifyAccessToken,
|
||||
builder: (column, joinBuilders) => ColumnWithTypeConverterFilters(
|
||||
column,
|
||||
joinBuilders: joinBuilders));
|
||||
|
||||
ColumnFilters<DateTime> get expiration => $state.composableBuilder(
|
||||
column: $state.table.expiration,
|
||||
ColumnFilters<DateTime> get spotifyExpiration => $state.composableBuilder(
|
||||
column: $state.table.spotifyExpiration,
|
||||
builder: (column, joinBuilders) =>
|
||||
ColumnFilters(column, joinBuilders: joinBuilders));
|
||||
|
||||
ColumnWithTypeConverterFilters<DecryptedText?, DecryptedText, String>
|
||||
get neteaseCookie => $state.composableBuilder(
|
||||
column: $state.table.neteaseCookie,
|
||||
builder: (column, joinBuilders) => ColumnWithTypeConverterFilters(
|
||||
column,
|
||||
joinBuilders: joinBuilders));
|
||||
|
||||
ColumnFilters<DateTime> get neteaseExpiration => $state.composableBuilder(
|
||||
column: $state.table.neteaseExpiration,
|
||||
builder: (column, joinBuilders) =>
|
||||
ColumnFilters(column, joinBuilders: joinBuilders));
|
||||
}
|
||||
@ -3916,18 +4057,28 @@ class $$AuthenticationTableTableOrderingComposer
|
||||
builder: (column, joinBuilders) =>
|
||||
ColumnOrderings(column, joinBuilders: joinBuilders));
|
||||
|
||||
ColumnOrderings<String> get cookie => $state.composableBuilder(
|
||||
column: $state.table.cookie,
|
||||
ColumnOrderings<String> get spotifyCookie => $state.composableBuilder(
|
||||
column: $state.table.spotifyCookie,
|
||||
builder: (column, joinBuilders) =>
|
||||
ColumnOrderings(column, joinBuilders: joinBuilders));
|
||||
|
||||
ColumnOrderings<String> get accessToken => $state.composableBuilder(
|
||||
column: $state.table.accessToken,
|
||||
ColumnOrderings<String> get spotifyAccessToken => $state.composableBuilder(
|
||||
column: $state.table.spotifyAccessToken,
|
||||
builder: (column, joinBuilders) =>
|
||||
ColumnOrderings(column, joinBuilders: joinBuilders));
|
||||
|
||||
ColumnOrderings<DateTime> get expiration => $state.composableBuilder(
|
||||
column: $state.table.expiration,
|
||||
ColumnOrderings<DateTime> get spotifyExpiration => $state.composableBuilder(
|
||||
column: $state.table.spotifyExpiration,
|
||||
builder: (column, joinBuilders) =>
|
||||
ColumnOrderings(column, joinBuilders: joinBuilders));
|
||||
|
||||
ColumnOrderings<String> get neteaseCookie => $state.composableBuilder(
|
||||
column: $state.table.neteaseCookie,
|
||||
builder: (column, joinBuilders) =>
|
||||
ColumnOrderings(column, joinBuilders: joinBuilders));
|
||||
|
||||
ColumnOrderings<DateTime> get neteaseExpiration => $state.composableBuilder(
|
||||
column: $state.table.neteaseExpiration,
|
||||
builder: (column, joinBuilders) =>
|
||||
ColumnOrderings(column, joinBuilders: joinBuilders));
|
||||
}
|
||||
|
@ -2,7 +2,10 @@ part of '../database.dart';
|
||||
|
||||
class AuthenticationTable extends Table {
|
||||
IntColumn get id => integer().autoIncrement()();
|
||||
TextColumn get cookie => text().map(EncryptedTextConverter())();
|
||||
TextColumn get accessToken => text().map(EncryptedTextConverter())();
|
||||
DateTimeColumn get expiration => dateTime()();
|
||||
TextColumn get spotifyCookie => text().map(EncryptedTextConverter())();
|
||||
TextColumn get spotifyAccessToken => text().map(EncryptedTextConverter())();
|
||||
DateTimeColumn get spotifyExpiration => dateTime()();
|
||||
TextColumn get neteaseCookie =>
|
||||
text().map(EncryptedTextConverter()).nullable()();
|
||||
DateTimeColumn get neteaseExpiration => dateTime().nullable()();
|
||||
}
|
||||
|
@ -14,7 +14,8 @@ enum CloseBehavior {
|
||||
enum AudioSource {
|
||||
youtube,
|
||||
piped,
|
||||
netease;
|
||||
netease,
|
||||
kugou;
|
||||
|
||||
String get label => name[0].toUpperCase() + name.substring(1);
|
||||
}
|
||||
|
@ -3,7 +3,8 @@ part of '../database.dart';
|
||||
enum SourceType {
|
||||
youtube._('YouTube'),
|
||||
youtubeMusic._('YouTube Music'),
|
||||
netease._('Netease Music');
|
||||
netease._('Netease Music'),
|
||||
kugou._('Kugou Music');
|
||||
|
||||
final String label;
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:dio/dio.dart' hide Response;
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:get/get.dart' hide Response;
|
||||
@ -6,6 +8,7 @@ import 'package:rhythm_box/providers/error_notifier.dart';
|
||||
import 'package:rhythm_box/services/audio_player/audio_player.dart';
|
||||
import 'package:rhythm_box/services/server/active_sourced_track.dart';
|
||||
import 'package:rhythm_box/services/server/sourced_track.dart';
|
||||
import 'package:rhythm_box/services/sourced_track/sources/kugou.dart';
|
||||
import 'package:rhythm_box/services/sourced_track/sources/netease.dart';
|
||||
import 'package:shelf/shelf.dart';
|
||||
|
||||
@ -34,6 +37,13 @@ class ServerPlaybackRoutesProvider {
|
||||
);
|
||||
final realUrl = resp.body['data'][0]['url'];
|
||||
url = realUrl;
|
||||
} else if (sourcedTrack is KugouSourcedTrack) {
|
||||
// Special processing for kugou to get real assets url
|
||||
final resp = await GetConnect(timeout: const Duration(seconds: 30))
|
||||
.get(sourcedTrack.url);
|
||||
final realUrl =
|
||||
KugouSourcedTrack.unescapeUrl(jsonDecode(resp.body)['url'][0]);
|
||||
url = realUrl;
|
||||
}
|
||||
|
||||
final res = await Dio().get(
|
||||
|
@ -1,7 +1,9 @@
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:rhythm_box/providers/error_notifier.dart';
|
||||
import 'package:rhythm_box/providers/user_preferences.dart';
|
||||
import 'package:rhythm_box/services/database/database.dart';
|
||||
import 'package:rhythm_box/services/sourced_track/sources/kugou.dart';
|
||||
import 'package:rhythm_box/services/sourced_track/sources/netease.dart';
|
||||
import 'package:rhythm_box/services/utils.dart';
|
||||
import 'package:spotify/spotify.dart';
|
||||
@ -103,16 +105,23 @@ abstract class SourcedTrack extends Track {
|
||||
return switch (audioSource) {
|
||||
AudioSource.netease =>
|
||||
await NeteaseSourcedTrack.fetchFromTrack(track: track),
|
||||
AudioSource.kugou =>
|
||||
await KugouSourcedTrack.fetchFromTrack(track: track),
|
||||
AudioSource.piped =>
|
||||
await PipedSourcedTrack.fetchFromTrack(track: track),
|
||||
_ => await YoutubeSourcedTrack.fetchFromTrack(track: track),
|
||||
};
|
||||
} on TrackNotFoundError catch (_) {
|
||||
} on TrackNotFoundError catch (err) {
|
||||
Get.find<ErrorNotifier>().showError(
|
||||
'${err.toString()} via ${preferences.audioSource.label}, querying in fallback sources...',
|
||||
);
|
||||
return switch (preferences.audioSource) {
|
||||
AudioSource.piped ||
|
||||
AudioSource.youtube =>
|
||||
await NeteaseSourcedTrack.fetchFromTrack(track: track),
|
||||
AudioSource.netease =>
|
||||
await KugouSourcedTrack.fetchFromTrack(track: track),
|
||||
AudioSource.kugou =>
|
||||
await YoutubeSourcedTrack.fetchFromTrack(track: track),
|
||||
};
|
||||
} on HttpClientClosedException catch (_) {
|
||||
|
229
lib/services/sourced_track/sources/kugou.dart
Normal file
229
lib/services/sourced_track/sources/kugou.dart
Normal file
@ -0,0 +1,229 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:crypto/crypto.dart';
|
||||
import 'package:get/get.dart' hide Value;
|
||||
import 'package:rhythm_box/providers/database.dart';
|
||||
import 'package:rhythm_box/services/database/database.dart';
|
||||
import 'package:spotify/spotify.dart';
|
||||
import 'package:rhythm_box/services/sourced_track/enums.dart';
|
||||
import 'package:rhythm_box/services/sourced_track/exceptions.dart';
|
||||
import 'package:rhythm_box/services/sourced_track/models/source_info.dart';
|
||||
import 'package:rhythm_box/services/sourced_track/models/source_map.dart';
|
||||
import 'package:rhythm_box/services/sourced_track/sourced_track.dart';
|
||||
|
||||
class KugouSourceInfo extends SourceInfo {
|
||||
KugouSourceInfo({
|
||||
required super.id,
|
||||
required super.title,
|
||||
required super.artist,
|
||||
required super.thumbnail,
|
||||
required super.pageUrl,
|
||||
required super.duration,
|
||||
required super.artistUrl,
|
||||
required super.album,
|
||||
});
|
||||
}
|
||||
|
||||
class KugouSourcedTrack extends SourcedTrack {
|
||||
KugouSourcedTrack({
|
||||
required super.source,
|
||||
required super.siblings,
|
||||
required super.sourceInfo,
|
||||
required super.track,
|
||||
});
|
||||
|
||||
static String unescapeUrl(String src) {
|
||||
return src.replaceAll('\\/', '/');
|
||||
}
|
||||
|
||||
static String getBaseUrl() {
|
||||
return 'http://mobilecdn.kugou.com';
|
||||
}
|
||||
|
||||
static GetConnect getClient() {
|
||||
final client = GetConnect(
|
||||
withCredentials: true,
|
||||
timeout: const Duration(seconds: 30),
|
||||
);
|
||||
client.baseUrl = getBaseUrl();
|
||||
return client;
|
||||
}
|
||||
|
||||
static Future<KugouSourcedTrack> fetchFromTrack({
|
||||
required Track track,
|
||||
}) async {
|
||||
final DatabaseProvider db = Get.find();
|
||||
final cachedSource = await (db.database.select(db.database.sourceMatchTable)
|
||||
..where((s) => s.trackId.equals(track.id!))
|
||||
..limit(1)
|
||||
..orderBy([
|
||||
(s) =>
|
||||
OrderingTerm(expression: s.createdAt, mode: OrderingMode.desc),
|
||||
]))
|
||||
.get()
|
||||
.then((s) => s.firstOrNull);
|
||||
|
||||
if (cachedSource == null || cachedSource.sourceType != SourceType.kugou) {
|
||||
final siblings = await fetchSiblings(track: track);
|
||||
if (siblings.isEmpty) {
|
||||
throw TrackNotFoundError(track);
|
||||
}
|
||||
|
||||
await db.database.into(db.database.sourceMatchTable).insert(
|
||||
SourceMatchTableCompanion.insert(
|
||||
trackId: track.id!,
|
||||
sourceId: siblings.first.info.id,
|
||||
sourceType: const Value(SourceType.kugou),
|
||||
),
|
||||
);
|
||||
|
||||
return KugouSourcedTrack(
|
||||
siblings: siblings.map((s) => s.info).skip(1).toList(),
|
||||
source: siblings.first.source as SourceMap,
|
||||
sourceInfo: siblings.first.info,
|
||||
track: track,
|
||||
);
|
||||
}
|
||||
|
||||
return KugouSourcedTrack(
|
||||
siblings: [],
|
||||
source: toSourceMap(cachedSource),
|
||||
sourceInfo: KugouSourceInfo(
|
||||
id: cachedSource.sourceId,
|
||||
artist: 'unknown',
|
||||
artistUrl: '#',
|
||||
pageUrl: '#',
|
||||
thumbnail: '#',
|
||||
title: 'unknown',
|
||||
duration: Duration.zero,
|
||||
album: 'unknown',
|
||||
),
|
||||
track: track,
|
||||
);
|
||||
}
|
||||
|
||||
static SourceMap toSourceMap(dynamic manifest) {
|
||||
const baseUrl = 'http://trackercdn.kugou.com/i/v2';
|
||||
|
||||
final hash = manifest is SourceMatchTableData
|
||||
? manifest.sourceId
|
||||
: 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';
|
||||
|
||||
return SourceMap(
|
||||
m4a: SourceQualityMap(
|
||||
high: url,
|
||||
medium: url,
|
||||
low: url,
|
||||
),
|
||||
weba: SourceQualityMap(
|
||||
high: url,
|
||||
medium: url,
|
||||
low: url,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
static Future<List<SiblingType>> fetchSiblings({
|
||||
required Track track,
|
||||
}) async {
|
||||
final query = SourcedTrack.getSearchTerm(track);
|
||||
|
||||
final client = getClient();
|
||||
final resp = await client.get(
|
||||
'/api/v3/search/song?keyword=${Uri.encodeComponent(query)}&page=1&pagesize=10',
|
||||
);
|
||||
final results = jsonDecode(resp.body)['data']['info'];
|
||||
|
||||
// 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();
|
||||
|
||||
return matchedResults.cast<SiblingType>();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<KugouSourcedTrack> copyWithSibling() async {
|
||||
if (siblings.isNotEmpty) {
|
||||
return this;
|
||||
}
|
||||
final fetchedSiblings = await fetchSiblings(track: this);
|
||||
|
||||
return KugouSourcedTrack(
|
||||
siblings: fetchedSiblings
|
||||
.where((s) => s.info.id != sourceInfo.id)
|
||||
.map((s) => s.info)
|
||||
.toList(),
|
||||
source: source,
|
||||
sourceInfo: sourceInfo,
|
||||
track: this,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<KugouSourcedTrack?> swapWithSibling(SourceInfo sibling) async {
|
||||
if (sibling.id == sourceInfo.id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// a sibling source that was fetched from the search results
|
||||
final isStepSibling = siblings.none((s) => s.id == sibling.id);
|
||||
|
||||
final newSourceInfo = isStepSibling
|
||||
? sibling
|
||||
: siblings.firstWhere((s) => s.id == sibling.id);
|
||||
final newSiblings = siblings.where((s) => s.id != sibling.id).toList()
|
||||
..insert(0, sourceInfo);
|
||||
|
||||
final info = newSourceInfo as KugouSourceInfo;
|
||||
final source = toSourceMap(newSourceInfo.id);
|
||||
|
||||
final db = Get.find<DatabaseProvider>();
|
||||
await db.database.into(db.database.sourceMatchTable).insert(
|
||||
SourceMatchTableCompanion.insert(
|
||||
trackId: id!,
|
||||
sourceId: info.id,
|
||||
sourceType: const Value(SourceType.kugou),
|
||||
// Because we're sorting by createdAt in the query
|
||||
// we have to update it to indicate priority
|
||||
createdAt: Value(DateTime.now()),
|
||||
),
|
||||
mode: InsertMode.replace,
|
||||
);
|
||||
|
||||
return KugouSourcedTrack(
|
||||
siblings: newSiblings,
|
||||
source: source,
|
||||
sourceInfo: info,
|
||||
track: this,
|
||||
);
|
||||
}
|
||||
|
||||
static KugouSourceInfo toSourceInfo(dynamic item) {
|
||||
return KugouSourceInfo(
|
||||
id: item['hash'],
|
||||
artist: item['singername'],
|
||||
artistUrl: '#',
|
||||
pageUrl: '#',
|
||||
thumbnail: unescapeUrl(item['trans_param']['union_cover'])
|
||||
.replaceFirst('/{size}', ''),
|
||||
title: item['songname'],
|
||||
duration: Duration(seconds: item['duration']),
|
||||
album: item['album_name'],
|
||||
);
|
||||
}
|
||||
|
||||
static SiblingType toSiblingType(dynamic item) {
|
||||
final SiblingType sibling = (
|
||||
info: toSourceInfo(item),
|
||||
source: toSourceMap(item),
|
||||
);
|
||||
|
||||
return sibling;
|
||||
}
|
||||
}
|
@ -1,6 +1,8 @@
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:get/get.dart' hide Value;
|
||||
import 'package:get/get_connect/http/src/request/request.dart';
|
||||
import 'package:rhythm_box/providers/auth.dart';
|
||||
import 'package:rhythm_box/providers/database.dart';
|
||||
import 'package:rhythm_box/providers/user_preferences.dart';
|
||||
import 'package:rhythm_box/services/database/database.dart';
|
||||
@ -38,9 +40,25 @@ class NeteaseSourcedTrack extends SourcedTrack {
|
||||
}
|
||||
|
||||
static GetConnect getClient() {
|
||||
final client = GetConnect();
|
||||
final client = GetConnect(
|
||||
withCredentials: true,
|
||||
timeout: const Duration(seconds: 30),
|
||||
);
|
||||
client.baseUrl = getBaseUrl();
|
||||
client.timeout = const Duration(seconds: 30);
|
||||
client.httpClient.addRequestModifier((Request request) async {
|
||||
final AuthenticationProvider auth = Get.find();
|
||||
if (auth.auth.value?.neteaseCookie != null) {
|
||||
final cookie =
|
||||
'MUSIC_U=${auth.auth.value!.getNeteaseCookie('MUSIC_U')}';
|
||||
if (request.headers['Cookie'] == null) {
|
||||
request.headers['Cookie'] = cookie;
|
||||
} else {
|
||||
request.headers['Cookie'] = request.headers['Cookie']! + cookie;
|
||||
}
|
||||
}
|
||||
|
||||
return request;
|
||||
});
|
||||
return client;
|
||||
}
|
||||
|
||||
@ -69,12 +87,18 @@ class NeteaseSourcedTrack extends SourcedTrack {
|
||||
.get()
|
||||
.then((s) => s.firstOrNull);
|
||||
|
||||
if (cachedSource == null) {
|
||||
if (cachedSource == null || cachedSource.sourceType != SourceType.netease) {
|
||||
final siblings = await fetchSiblings(track: track);
|
||||
if (siblings.isEmpty) {
|
||||
throw TrackNotFoundError(track);
|
||||
}
|
||||
|
||||
final client = getClient();
|
||||
final checkResp = await client.get(
|
||||
'/check/music?id=${siblings.first.info.id}&realIP=${await lookupRealIp()}',
|
||||
);
|
||||
if (checkResp.body['success'] != true) throw TrackNotFoundError(track);
|
||||
|
||||
await db.database.into(db.database.sourceMatchTable).insert(
|
||||
SourceMatchTableCompanion.insert(
|
||||
trackId: track.id!,
|
||||
@ -93,7 +117,14 @@ class NeteaseSourcedTrack extends SourcedTrack {
|
||||
|
||||
final client = getClient();
|
||||
final resp = await client.get('/song/detail?ids=${cachedSource.sourceId}');
|
||||
final item = resp.body['songs'][0];
|
||||
final item = (resp.body['songs'] as List<dynamic>).firstOrNull;
|
||||
|
||||
if (item == null) throw TrackNotFoundError(track);
|
||||
|
||||
final checkResp = await client.get(
|
||||
'/check/music?id=${item['id']}&realIP=${await lookupRealIp()}',
|
||||
);
|
||||
if (checkResp.body['success'] != true) throw TrackNotFoundError(track);
|
||||
|
||||
return NeteaseSourcedTrack(
|
||||
siblings: [],
|
||||
@ -136,8 +167,10 @@ class NeteaseSourcedTrack extends SourcedTrack {
|
||||
final query = SourcedTrack.getSearchTerm(track);
|
||||
|
||||
final client = getClient();
|
||||
final resp =
|
||||
await client.get('/search?keywords=${Uri.encodeComponent(query)}');
|
||||
final resp = await client.get(
|
||||
'/search?keywords=${Uri.encodeComponent(query)}&realIP=${NeteaseSourcedTrack.lookupRealIp()}',
|
||||
);
|
||||
if (resp.body?['code'] == 405) throw TrackNotFoundError(track);
|
||||
final results = resp.body['result']['songs'];
|
||||
|
||||
// We can just trust netease music for now
|
||||
@ -183,7 +216,7 @@ class NeteaseSourcedTrack extends SourcedTrack {
|
||||
|
||||
final client = getClient();
|
||||
final resp = await client.get('/song/detail?ids=${newSourceInfo.id}');
|
||||
final item = resp.body['songs'][0];
|
||||
final item = (resp.body['songs'] as List<dynamic>).first;
|
||||
|
||||
final (:info, :source) = toSiblingType(item);
|
||||
|
||||
@ -208,25 +241,29 @@ class NeteaseSourcedTrack extends SourcedTrack {
|
||||
);
|
||||
}
|
||||
|
||||
static SiblingType toSiblingType(dynamic item) {
|
||||
static NeteaseSourceInfo toSourceInfo(dynamic item) {
|
||||
final firstArtist = item['ar'] != null ? item['ar'][0] : item['artists'][0];
|
||||
|
||||
return NeteaseSourceInfo(
|
||||
id: item['id'].toString(),
|
||||
artist: item['ar'] != null
|
||||
? item['ar'].map((x) => x['name']).join(',')
|
||||
: item['artists'].map((x) => x['name']).toString(),
|
||||
artistUrl: 'https://music.163.com/#/artist?id=${firstArtist['id']}',
|
||||
pageUrl: 'https://music.163.com/#/song?id=${item['id']}',
|
||||
thumbnail: item['al']?['picUrl'] ??
|
||||
'https://p1.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg',
|
||||
title: item['name'],
|
||||
duration: item['dt'] != null
|
||||
? Duration(milliseconds: item['dt'])
|
||||
: Duration(milliseconds: item['duration']),
|
||||
album: item['al']?['name'],
|
||||
);
|
||||
}
|
||||
|
||||
static SiblingType toSiblingType(dynamic item) {
|
||||
final SiblingType sibling = (
|
||||
info: NeteaseSourceInfo(
|
||||
id: item['id'].toString(),
|
||||
artist: item['ar'] != null
|
||||
? item['ar'].map((x) => x['name']).join(',')
|
||||
: item['artists'].map((x) => x['name']).toString(),
|
||||
artistUrl: 'https://music.163.com/#/artist?id=${firstArtist['id']}',
|
||||
pageUrl: 'https://music.163.com/#/song?id=${item['id']}',
|
||||
thumbnail: item['al']?['picUrl'] ??
|
||||
'https://p1.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg',
|
||||
title: item['name'],
|
||||
duration: item['dt'] != null
|
||||
? Duration(milliseconds: item['dt'])
|
||||
: Duration.zero,
|
||||
album: item['al']?['name'],
|
||||
),
|
||||
info: toSourceInfo(item),
|
||||
source: toSourceMap(item),
|
||||
);
|
||||
|
||||
|
@ -69,6 +69,7 @@ class YoutubeSourcedTrack extends SourcedTrack {
|
||||
sourceId: siblings.first.info.id,
|
||||
sourceType: const Value(SourceType.youtube),
|
||||
),
|
||||
mode: InsertMode.insertOrReplace,
|
||||
);
|
||||
|
||||
return YoutubeSourcedTrack(
|
||||
|
@ -5,8 +5,10 @@ import 'package:rhythm_box/platform.dart';
|
||||
class AutoCacheImage extends StatelessWidget {
|
||||
final String url;
|
||||
final double? width, height;
|
||||
final BoxFit? fit;
|
||||
|
||||
const AutoCacheImage(this.url, {super.key, this.width, this.height});
|
||||
const AutoCacheImage(this.url,
|
||||
{super.key, this.width, this.height, this.fit});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -15,12 +17,14 @@ class AutoCacheImage extends StatelessWidget {
|
||||
imageUrl: url,
|
||||
width: width,
|
||||
height: height,
|
||||
fit: fit,
|
||||
);
|
||||
}
|
||||
return Image.network(
|
||||
url,
|
||||
width: width,
|
||||
height: height,
|
||||
fit: fit,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
import 'package:rhythm_box/providers/audio_player.dart';
|
||||
import 'package:rhythm_box/providers/error_notifier.dart';
|
||||
import 'package:rhythm_box/providers/user_preferences.dart';
|
||||
import 'package:rhythm_box/services/database/database.dart';
|
||||
import 'package:rhythm_box/services/duration.dart';
|
||||
@ -12,6 +13,7 @@ import 'package:rhythm_box/services/server/active_sourced_track.dart';
|
||||
import 'package:rhythm_box/services/sourced_track/models/source_info.dart';
|
||||
import 'package:rhythm_box/services/sourced_track/models/video_info.dart';
|
||||
import 'package:rhythm_box/services/sourced_track/sourced_track.dart';
|
||||
import 'package:rhythm_box/services/sourced_track/sources/kugou.dart';
|
||||
import 'package:rhythm_box/services/sourced_track/sources/netease.dart';
|
||||
import 'package:rhythm_box/services/sourced_track/sources/piped.dart';
|
||||
import 'package:rhythm_box/services/sourced_track/sources/youtube.dart';
|
||||
@ -44,6 +46,7 @@ class _SiblingTracksState extends State<SiblingTracks> {
|
||||
YoutubeSourceInfo: 'YouTube',
|
||||
PipedSourceInfo: 'Piped',
|
||||
NeteaseSourceInfo: 'Netease',
|
||||
KugouSourceInfo: 'Kugou',
|
||||
};
|
||||
|
||||
List<StreamSubscription>? _subscriptions;
|
||||
@ -89,48 +92,54 @@ class _SiblingTracksState extends State<SiblingTracks> {
|
||||
final preferences = Get.find<UserPreferencesProvider>().state.value;
|
||||
final searchTerm = _searchTermController.text.trim();
|
||||
|
||||
if (preferences.audioSource == AudioSource.youtube ||
|
||||
preferences.audioSource == AudioSource.piped) {
|
||||
final resultsYt = await youtubeClient.search.search(searchTerm.trim());
|
||||
try {
|
||||
if (preferences.audioSource == AudioSource.youtube ||
|
||||
preferences.audioSource == AudioSource.piped) {
|
||||
final resultsYt = await youtubeClient.search.search(searchTerm.trim());
|
||||
|
||||
final searchResults = await Future.wait(
|
||||
resultsYt.map(YoutubeVideoInfo.fromVideo).mapIndexed((i, video) async {
|
||||
final siblingType = await YoutubeSourcedTrack.toSiblingType(i, video);
|
||||
return siblingType.info;
|
||||
}),
|
||||
);
|
||||
final activeSourceInfo = (_activeTrack! as SourcedTrack).sourceInfo;
|
||||
_siblings = List.from(
|
||||
searchResults
|
||||
..removeWhere((element) => element.id == activeSourceInfo.id)
|
||||
..insert(
|
||||
0,
|
||||
activeSourceInfo,
|
||||
),
|
||||
growable: true,
|
||||
);
|
||||
} else if (preferences.audioSource == AudioSource.netease) {
|
||||
final client = NeteaseSourcedTrack.getClient();
|
||||
final resp = await client
|
||||
.get('/search?keywords=${Uri.encodeComponent(searchTerm)}');
|
||||
final searchResults = resp.body['result']['songs']
|
||||
.map(NeteaseSourcedTrack.toSiblingType)
|
||||
.map((x) => x.info)
|
||||
.toList();
|
||||
final searchResults = await Future.wait(
|
||||
resultsYt
|
||||
.map(YoutubeVideoInfo.fromVideo)
|
||||
.mapIndexed((i, video) async {
|
||||
final siblingType =
|
||||
await YoutubeSourcedTrack.toSiblingType(i, video);
|
||||
return siblingType.info;
|
||||
}),
|
||||
);
|
||||
final activeSourceInfo = (_activeTrack! as SourcedTrack).sourceInfo;
|
||||
_siblings = List.from(
|
||||
searchResults
|
||||
..removeWhere((element) => element.id == activeSourceInfo.id)
|
||||
..insert(
|
||||
0,
|
||||
activeSourceInfo,
|
||||
),
|
||||
growable: true,
|
||||
);
|
||||
} else if (preferences.audioSource == AudioSource.netease) {
|
||||
final client = NeteaseSourcedTrack.getClient();
|
||||
final resp = await client.get(
|
||||
'/search?keywords=${Uri.encodeComponent(searchTerm)}&realIP=${NeteaseSourcedTrack.lookupRealIp()}');
|
||||
final searchResults = resp.body['result']['songs']
|
||||
.map(NeteaseSourcedTrack.toSourceInfo)
|
||||
.toList();
|
||||
|
||||
final activeSourceInfo = (_activeTrack! as SourcedTrack).sourceInfo;
|
||||
_siblings = List.from(
|
||||
searchResults
|
||||
..removeWhere((element) => element.id == activeSourceInfo.id)
|
||||
..insert(
|
||||
0,
|
||||
activeSourceInfo,
|
||||
),
|
||||
growable: true,
|
||||
);
|
||||
final activeSourceInfo = (_activeTrack! as SourcedTrack).sourceInfo;
|
||||
_siblings = List.from(
|
||||
searchResults
|
||||
..removeWhere((element) => element.id == activeSourceInfo.id)
|
||||
..insert(
|
||||
0,
|
||||
activeSourceInfo,
|
||||
),
|
||||
growable: true,
|
||||
);
|
||||
}
|
||||
} catch (err) {
|
||||
Get.find<ErrorNotifier>().showError(err.toString());
|
||||
} finally {
|
||||
setState(() => _isSearching = false);
|
||||
}
|
||||
|
||||
setState(() => _isSearching = false);
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -1,13 +1,13 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:rhythm_box/services/duration.dart';
|
||||
import 'package:rhythm_box/services/sourced_track/sourced_track.dart';
|
||||
import 'package:rhythm_box/services/sourced_track/sources/kugou.dart';
|
||||
import 'package:rhythm_box/services/sourced_track/sources/netease.dart';
|
||||
import 'package:rhythm_box/services/sourced_track/sources/piped.dart';
|
||||
import 'package:rhythm_box/services/sourced_track/sources/youtube.dart';
|
||||
import 'package:spotify/spotify.dart';
|
||||
|
||||
class TrackSourceDetails extends StatelessWidget {
|
||||
final Track track;
|
||||
final SourcedTrack track;
|
||||
|
||||
const TrackSourceDetails({super.key, required this.track});
|
||||
|
||||
@ -15,6 +15,7 @@ class TrackSourceDetails extends StatelessWidget {
|
||||
YoutubeSourceInfo: 'YouTube',
|
||||
PipedSourceInfo: 'Piped',
|
||||
NeteaseSourceInfo: 'Netease',
|
||||
KugouSourceInfo: 'Kugou',
|
||||
};
|
||||
|
||||
@override
|
||||
@ -25,14 +26,11 @@ class TrackSourceDetails extends StatelessWidget {
|
||||
'Title': track.name!,
|
||||
'Artist': track.artists?.map((x) => x.name).join(', '),
|
||||
'Album': track.album!.name!,
|
||||
'Duration': (track is SourcedTrack
|
||||
? (track as SourcedTrack).sourceInfo.duration
|
||||
: track.duration!)
|
||||
.toHumanReadableString(),
|
||||
'Duration': track.sourceInfo.duration.toHumanReadableString(),
|
||||
if (track.album!.releaseDate != null)
|
||||
'Released': track.album!.releaseDate,
|
||||
'Popularity': track.popularity?.toString() ?? '0',
|
||||
'Provider': sourceInfoToLabelMap[track.runtimeType],
|
||||
'Provider': sourceInfoToLabelMap[track.sourceInfo.runtimeType],
|
||||
};
|
||||
|
||||
return Table(
|
||||
|
@ -28,6 +28,8 @@
|
||||
<string>MainMenu</string>
|
||||
<key>LSApplicationCategoryType</key>
|
||||
<string>public.app-category.music</string>
|
||||
<key>ITSAppUsesNonExemptEncryption</key>
|
||||
<false/>
|
||||
<key>NSPrincipalClass</key>
|
||||
<string>NSApplication</string>
|
||||
</dict>
|
||||
|
@ -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+8
|
||||
version: 1.0.0+12
|
||||
|
||||
environment:
|
||||
sdk: ^3.5.0
|
||||
|
Reference in New Issue
Block a user