♿ Better netease music check
This commit is contained in:
		| @@ -109,8 +109,9 @@ abstract class SourcedTrack extends Track { | ||||
|         _ => await YoutubeSourcedTrack.fetchFromTrack(track: track), | ||||
|       }; | ||||
|     } on TrackNotFoundError catch (err) { | ||||
|       Get.find<ErrorNotifier>() | ||||
|           .showError('${err.toString()} via ${preferences.audioSource.label}'); | ||||
|       Get.find<ErrorNotifier>().showError( | ||||
|         '${err.toString()} via ${preferences.audioSource.label}, querying in fallback sources...', | ||||
|       ); | ||||
|       return switch (preferences.audioSource) { | ||||
|         AudioSource.piped || | ||||
|         AudioSource.youtube => | ||||
|   | ||||
| @@ -93,6 +93,12 @@ class NeteaseSourcedTrack extends SourcedTrack { | ||||
|         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!, | ||||
| @@ -111,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: [], | ||||
| @@ -201,7 +214,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); | ||||
|  | ||||
|   | ||||
| @@ -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'; | ||||
| @@ -89,13 +90,17 @@ class _SiblingTracksState extends State<SiblingTracks> { | ||||
|     final preferences = Get.find<UserPreferencesProvider>().state.value; | ||||
|     final searchTerm = _searchTermController.text.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); | ||||
|           resultsYt | ||||
|               .map(YoutubeVideoInfo.fromVideo) | ||||
|               .mapIndexed((i, video) async { | ||||
|             final siblingType = | ||||
|                 await YoutubeSourcedTrack.toSiblingType(i, video); | ||||
|             return siblingType.info; | ||||
|           }), | ||||
|         ); | ||||
| @@ -129,9 +134,12 @@ class _SiblingTracksState extends State<SiblingTracks> { | ||||
|           growable: true, | ||||
|         ); | ||||
|       } | ||||
|  | ||||
|     } catch (err) { | ||||
|       Get.find<ErrorNotifier>().showError(err.toString()); | ||||
|     } finally { | ||||
|       setState(() => _isSearching = false); | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   @override | ||||
|   void initState() { | ||||
|   | ||||
| @@ -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+10 | ||||
| version: 1.0.0+11 | ||||
|  | ||||
| environment: | ||||
|   sdk: ^3.5.0 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user