From 222d50d80d76c195dac32aa020086f945880b0c8 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Fri, 6 Sep 2024 18:10:12 +0800 Subject: [PATCH] :bug: Bug fixes of querying backend --- ios/Runner/Info.plist | 112 +++++++++--------- lib/screens/player/view.dart | 58 ++++----- .../sourced_track/sources/netease.dart | 43 ++++--- .../sourced_track/sources/youtube.dart | 1 + lib/widgets/auto_cache_image.dart | 6 +- lib/widgets/player/sibling_tracks.dart | 7 +- macos/Runner/Info.plist | 2 + 7 files changed, 124 insertions(+), 105 deletions(-) diff --git a/ios/Runner/Info.plist b/ios/Runner/Info.plist index d94da39..9697597 100644 --- a/ios/Runner/Info.plist +++ b/ios/Runner/Info.plist @@ -1,59 +1,61 @@ - - CADisableMinimumFrameDurationOnPhone - - CFBundleDevelopmentRegion - $(DEVELOPMENT_LANGUAGE) - CFBundleDisplayName - Groovy Box - CFBundleExecutable - $(EXECUTABLE_NAME) - CFBundleIdentifier - $(PRODUCT_BUNDLE_IDENTIFIER) - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - Groovy Box - CFBundlePackageType - APPL - CFBundleShortVersionString - $(FLUTTER_BUILD_NAME) - CFBundleSignature - ???? - CFBundleVersion - $(FLUTTER_BUILD_NUMBER) - LSApplicationCategoryType - public.app-category.music - LSRequiresIPhoneOS - - NSMicrophoneUsageDescription - To provide information for RhythmBox to normalize the output audio - UIApplicationSupportsIndirectInputEvents - - UIBackgroundModes - - audio - - UILaunchStoryboardName - LaunchScreen - UIMainStoryboardFile - Main - UIStatusBarHidden - - UISupportedInterfaceOrientations - - UIInterfaceOrientationPortrait - UIInterfaceOrientationLandscapeLeft - UIInterfaceOrientationLandscapeRight - - UISupportedInterfaceOrientations~ipad - - UIInterfaceOrientationPortrait - UIInterfaceOrientationPortraitUpsideDown - UIInterfaceOrientationLandscapeLeft - UIInterfaceOrientationLandscapeRight - - + + ITSAppUsesNonExemptEncryption + + CADisableMinimumFrameDurationOnPhone + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleDisplayName + Groovy Box + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + Groovy Box + CFBundlePackageType + APPL + CFBundleShortVersionString + $(FLUTTER_BUILD_NAME) + CFBundleSignature + ???? + CFBundleVersion + $(FLUTTER_BUILD_NUMBER) + LSApplicationCategoryType + public.app-category.music + LSRequiresIPhoneOS + + NSMicrophoneUsageDescription + To provide information for RhythmBox to normalize the output audio + UIApplicationSupportsIndirectInputEvents + + UIBackgroundModes + + audio + + UILaunchStoryboardName + LaunchScreen + UIMainStoryboardFile + Main + UIStatusBarHidden + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + diff --git a/lib/screens/player/view.dart b/lib/screens/player/view.dart index 99c4e5f..3aa8366 100644 --- a/lib/screens/player/view.dart +++ b/lib/screens/player/view.dart @@ -82,34 +82,38 @@ class _PlayerScreenState extends State { 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), + ), ), ), ), diff --git a/lib/services/sourced_track/sources/netease.dart b/lib/services/sourced_track/sources/netease.dart index 5ca71f6..c8f7934 100755 --- a/lib/services/sourced_track/sources/netease.dart +++ b/lib/services/sourced_track/sources/netease.dart @@ -167,8 +167,11 @@ 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); + print(resp.body); final results = resp.body['result']['songs']; // We can just trust netease music for now @@ -239,25 +242,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(milliseconds: item['duration']), - album: item['al']?['name'], - ), + info: toSourceInfo(item), source: toSourceMap(item), ); diff --git a/lib/services/sourced_track/sources/youtube.dart b/lib/services/sourced_track/sources/youtube.dart index 6f994f2..a3c35dc 100755 --- a/lib/services/sourced_track/sources/youtube.dart +++ b/lib/services/sourced_track/sources/youtube.dart @@ -69,6 +69,7 @@ class YoutubeSourcedTrack extends SourcedTrack { sourceId: siblings.first.info.id, sourceType: const Value(SourceType.youtube), ), + mode: InsertMode.insertOrReplace, ); return YoutubeSourcedTrack( diff --git a/lib/widgets/auto_cache_image.dart b/lib/widgets/auto_cache_image.dart index e637fd2..8a84ea7 100644 --- a/lib/widgets/auto_cache_image.dart +++ b/lib/widgets/auto_cache_image.dart @@ -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, ); } diff --git a/lib/widgets/player/sibling_tracks.dart b/lib/widgets/player/sibling_tracks.dart index 50c7f16..5ed9ebc 100644 --- a/lib/widgets/player/sibling_tracks.dart +++ b/lib/widgets/player/sibling_tracks.dart @@ -116,11 +116,10 @@ class _SiblingTracksState extends State { ); } else if (preferences.audioSource == AudioSource.netease) { final client = NeteaseSourcedTrack.getClient(); - final resp = await client - .get('/search?keywords=${Uri.encodeComponent(searchTerm)}'); + final resp = await client.get( + '/search?keywords=${Uri.encodeComponent(searchTerm)}&realIP=${NeteaseSourcedTrack.lookupRealIp()}'); final searchResults = resp.body['result']['songs'] - .map(NeteaseSourcedTrack.toSiblingType) - .map((x) => x.info) + .map(NeteaseSourcedTrack.toSourceInfo) .toList(); final activeSourceInfo = (_activeTrack! as SourcedTrack).sourceInfo; diff --git a/macos/Runner/Info.plist b/macos/Runner/Info.plist index 80fa126..e97afb8 100644 --- a/macos/Runner/Info.plist +++ b/macos/Runner/Info.plist @@ -28,6 +28,8 @@ MainMenu LSApplicationCategoryType public.app-category.music + ITSAppUsesNonExemptEncryption + NSPrincipalClass NSApplication