♿ Better netease music check
This commit is contained in:
parent
252e4619f7
commit
499bca5b1c
@ -109,8 +109,9 @@ abstract class SourcedTrack extends Track {
|
|||||||
_ => await YoutubeSourcedTrack.fetchFromTrack(track: track),
|
_ => await YoutubeSourcedTrack.fetchFromTrack(track: track),
|
||||||
};
|
};
|
||||||
} on TrackNotFoundError catch (err) {
|
} on TrackNotFoundError catch (err) {
|
||||||
Get.find<ErrorNotifier>()
|
Get.find<ErrorNotifier>().showError(
|
||||||
.showError('${err.toString()} via ${preferences.audioSource.label}');
|
'${err.toString()} via ${preferences.audioSource.label}, querying in fallback sources...',
|
||||||
|
);
|
||||||
return switch (preferences.audioSource) {
|
return switch (preferences.audioSource) {
|
||||||
AudioSource.piped ||
|
AudioSource.piped ||
|
||||||
AudioSource.youtube =>
|
AudioSource.youtube =>
|
||||||
|
@ -93,6 +93,12 @@ class NeteaseSourcedTrack extends SourcedTrack {
|
|||||||
throw TrackNotFoundError(track);
|
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(
|
await db.database.into(db.database.sourceMatchTable).insert(
|
||||||
SourceMatchTableCompanion.insert(
|
SourceMatchTableCompanion.insert(
|
||||||
trackId: track.id!,
|
trackId: track.id!,
|
||||||
@ -111,7 +117,14 @@ class NeteaseSourcedTrack extends SourcedTrack {
|
|||||||
|
|
||||||
final client = getClient();
|
final client = getClient();
|
||||||
final resp = await client.get('/song/detail?ids=${cachedSource.sourceId}');
|
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(
|
return NeteaseSourcedTrack(
|
||||||
siblings: [],
|
siblings: [],
|
||||||
@ -201,7 +214,7 @@ class NeteaseSourcedTrack extends SourcedTrack {
|
|||||||
|
|
||||||
final client = getClient();
|
final client = getClient();
|
||||||
final resp = await client.get('/song/detail?ids=${newSourceInfo.id}');
|
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);
|
final (:info, :source) = toSiblingType(item);
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:google_fonts/google_fonts.dart';
|
import 'package:google_fonts/google_fonts.dart';
|
||||||
import 'package:rhythm_box/providers/audio_player.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/providers/user_preferences.dart';
|
||||||
import 'package:rhythm_box/services/database/database.dart';
|
import 'package:rhythm_box/services/database/database.dart';
|
||||||
import 'package:rhythm_box/services/duration.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 preferences = Get.find<UserPreferencesProvider>().state.value;
|
||||||
final searchTerm = _searchTermController.text.trim();
|
final searchTerm = _searchTermController.text.trim();
|
||||||
|
|
||||||
|
try {
|
||||||
if (preferences.audioSource == AudioSource.youtube ||
|
if (preferences.audioSource == AudioSource.youtube ||
|
||||||
preferences.audioSource == AudioSource.piped) {
|
preferences.audioSource == AudioSource.piped) {
|
||||||
final resultsYt = await youtubeClient.search.search(searchTerm.trim());
|
final resultsYt = await youtubeClient.search.search(searchTerm.trim());
|
||||||
|
|
||||||
final searchResults = await Future.wait(
|
final searchResults = await Future.wait(
|
||||||
resultsYt.map(YoutubeVideoInfo.fromVideo).mapIndexed((i, video) async {
|
resultsYt
|
||||||
final siblingType = await YoutubeSourcedTrack.toSiblingType(i, video);
|
.map(YoutubeVideoInfo.fromVideo)
|
||||||
|
.mapIndexed((i, video) async {
|
||||||
|
final siblingType =
|
||||||
|
await YoutubeSourcedTrack.toSiblingType(i, video);
|
||||||
return siblingType.info;
|
return siblingType.info;
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
@ -129,9 +134,12 @@ class _SiblingTracksState extends State<SiblingTracks> {
|
|||||||
growable: true,
|
growable: true,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
} catch (err) {
|
||||||
|
Get.find<ErrorNotifier>().showError(err.toString());
|
||||||
|
} finally {
|
||||||
setState(() => _isSearching = false);
|
setState(() => _isSearching = false);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
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
|
# 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
|
# 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.
|
# 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:
|
environment:
|
||||||
sdk: ^3.5.0
|
sdk: ^3.5.0
|
||||||
|
Loading…
Reference in New Issue
Block a user