🐛 Bug fixes of querying backend
This commit is contained in:
		| @@ -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), | ||||
|                             ), | ||||
|                           ), | ||||
|                         ), | ||||
|                       ), | ||||
|   | ||||
| @@ -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), | ||||
|     ); | ||||
|  | ||||
|   | ||||
| @@ -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, | ||||
|     ); | ||||
|   } | ||||
|  | ||||
|   | ||||
| @@ -116,11 +116,10 @@ class _SiblingTracksState extends State<SiblingTracks> { | ||||
|         ); | ||||
|       } 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; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user