mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-12 23:45:18 +00:00
fix: calling /track/:streamId endpoint causes active sourced track to be anything
This commit is contained in:
parent
2c4cc94985
commit
b74c2eab8f
1
.vscode/settings.json
vendored
1
.vscode/settings.json
vendored
@ -9,6 +9,7 @@
|
||||
"fuzzywuzzy",
|
||||
"gapless",
|
||||
"instrumentalness",
|
||||
"isrc",
|
||||
"Mpris",
|
||||
"RGBO",
|
||||
"riverpod",
|
||||
|
@ -128,7 +128,10 @@ class ServerPlaybackRoutes {
|
||||
.read(sourcedTrackProvider(SpotubeMedia(track)).notifier)
|
||||
.refreshStreamingUrl();
|
||||
|
||||
if (playlist.activeTrack?.id == sourcedTrack?.id &&
|
||||
sourcedTrack != null) {
|
||||
ref.read(activeSourcedTrackProvider.notifier).update(sourcedTrack);
|
||||
}
|
||||
|
||||
return await dio.get<Uint8List>(
|
||||
sourcedTrack!.url,
|
||||
@ -199,7 +202,10 @@ class ServerPlaybackRoutes {
|
||||
? activeSourcedTrack
|
||||
: await ref.read(sourcedTrackProvider(SpotubeMedia(track)).future);
|
||||
|
||||
if (playlist.activeTrack?.id == sourcedTrack?.id &&
|
||||
sourcedTrack != null) {
|
||||
ref.read(activeSourcedTrackProvider.notifier).update(sourcedTrack);
|
||||
}
|
||||
|
||||
final (bytes: audioBytes, response: res) =
|
||||
await streamTrack(sourcedTrack!, request.headers);
|
||||
|
@ -238,27 +238,23 @@ class YoutubeSourcedTrack extends SourcedTrack {
|
||||
|
||||
static Future<List<YoutubeVideoInfo>> fetchFromIsrc({
|
||||
required Track track,
|
||||
required Provider provider,
|
||||
required Ref ref,
|
||||
}) async {
|
||||
final isrcResults = <YoutubeVideoInfo>[];
|
||||
final isrc = track.externalIds?.isrc;
|
||||
if (isrc != null && isrc.isNotEmpty) {
|
||||
final searchedVideos = await ref
|
||||
.read(provider)
|
||||
.searchVideos(isrc.toString());
|
||||
final searchedVideos =
|
||||
await ref.read(youtubeEngineProvider).searchVideos(isrc.toString());
|
||||
if (searchedVideos.isNotEmpty) {
|
||||
isrcResults.addAll(searchedVideos
|
||||
.map<YoutubeVideoInfo>(YoutubeVideoInfo.fromVideo)
|
||||
.map((YoutubeVideoInfo videoInfo) {
|
||||
final ytWords =
|
||||
videoInfo.title
|
||||
final ytWords = videoInfo.title
|
||||
.toLowerCase()
|
||||
.replaceAll(RegExp(r'[^a-zA-Z0-9\s]+'), '')
|
||||
.split(RegExp(r'\s+'))
|
||||
.where((item) => item.isNotEmpty);
|
||||
final spWords =
|
||||
track.name!
|
||||
final spWords = track.name!
|
||||
.toLowerCase()
|
||||
.replaceAll(RegExp(r'\((.*)\)'), '')
|
||||
.replaceAll(RegExp(r'[^a-zA-Z0-9\s]+'), '')
|
||||
@ -271,8 +267,9 @@ class YoutubeSourcedTrack extends SourcedTrack {
|
||||
return videoInfo;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
).whereType<YoutubeVideoInfo>().toList());
|
||||
})
|
||||
.whereType<YoutubeVideoInfo>()
|
||||
.toList());
|
||||
}
|
||||
}
|
||||
return isrcResults;
|
||||
@ -284,24 +281,33 @@ class YoutubeSourcedTrack extends SourcedTrack {
|
||||
}) async {
|
||||
final videoResults = <YoutubeVideoInfo>[];
|
||||
|
||||
final isrcResults = await fetchFromIsrc(track: track, provider: youtubeEngineProvider, ref: ref);
|
||||
if (track is! SourcedTrack) {
|
||||
final isrcResults = await fetchFromIsrc(
|
||||
track: track,
|
||||
ref: ref,
|
||||
);
|
||||
|
||||
videoResults.addAll(isrcResults);
|
||||
|
||||
if (isrcResults.isEmpty) {
|
||||
final links = await SongLinkService.links(track.id!);
|
||||
final ytLink = links.firstWhereOrNull((link) => link.platform == "youtube");
|
||||
|
||||
if (isrcResults.isEmpty && ytLink?.url != null) {
|
||||
final ytLink = links.firstWhereOrNull(
|
||||
(link) => link.platform == "youtube",
|
||||
);
|
||||
if (ytLink?.url != null) {
|
||||
try {
|
||||
videoResults.add(
|
||||
YoutubeVideoInfo.fromVideo(
|
||||
await ref.read(youtubeEngineProvider)
|
||||
.getVideo(Uri.parse(ytLink!.url!).queryParameters["v"]!)
|
||||
));
|
||||
YoutubeVideoInfo.fromVideo(await ref
|
||||
.read(youtubeEngineProvider)
|
||||
.getVideo(Uri.parse(ytLink!.url!).queryParameters["v"]!)),
|
||||
);
|
||||
} on VideoUnplayableException catch (e, stack) {
|
||||
// Ignore this error and continue with the search
|
||||
AppLogger.reportError(e, stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final query = SourcedTrack.getSearchTerm(track);
|
||||
|
||||
@ -309,9 +315,8 @@ class YoutubeSourcedTrack extends SourcedTrack {
|
||||
await ref.read(youtubeEngineProvider).searchVideos(query);
|
||||
|
||||
if (ServiceUtils.onlyContainsEnglish(query)) {
|
||||
videoResults.addAll(
|
||||
searchResults.map(YoutubeVideoInfo.fromVideo).toList()
|
||||
);
|
||||
videoResults
|
||||
.addAll(searchResults.map(YoutubeVideoInfo.fromVideo).toList());
|
||||
} else {
|
||||
videoResults.addAll(rankResults(
|
||||
searchResults.map(YoutubeVideoInfo.fromVideo).toList(),
|
||||
|
@ -32,6 +32,7 @@ function(APPLY_STANDARD_SETTINGS TARGET)
|
||||
target_compile_options(${TARGET} PRIVATE -Wall -Werror)
|
||||
target_compile_options(${TARGET} PRIVATE "$<$<NOT:$<CONFIG:Debug>>:-O3>")
|
||||
target_compile_definitions(${TARGET} PRIVATE "$<$<NOT:$<CONFIG:Debug>>:NDEBUG>")
|
||||
target_compile_options(${TARGET} PRIVATE -Wno-error=deprecated-declarations)
|
||||
endfunction()
|
||||
|
||||
set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter")
|
||||
|
@ -2449,10 +2449,10 @@ packages:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: tray_manager
|
||||
sha256: f231031c5c0eb4ad514e18ddaab27a912ddbe50335c594bc28fb0f9972ab6a84
|
||||
sha256: c2da0f0f1ddb455e721cf68d05d1281fec75cf5df0a1d3cb67b6ca0bdfd5709d
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.3.1"
|
||||
version: "0.4.0"
|
||||
type_plus:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -120,7 +120,7 @@ dependencies:
|
||||
test: ^1.25.7
|
||||
timezone: ^0.10.0
|
||||
titlebar_buttons: ^1.0.0
|
||||
tray_manager: ^0.3.0
|
||||
tray_manager: ^0.4.0
|
||||
url_launcher: ^6.2.6
|
||||
uuid: ^4.4.0
|
||||
version: ^3.0.2
|
||||
|
Loading…
Reference in New Issue
Block a user