Compare commits

..

1 Commits

Author SHA1 Message Date
Richard Hajek
e41baf4822
Merge 42e954428b into b248f90403 2025-09-02 20:14:55 +06:00
7 changed files with 29 additions and 71 deletions

View File

@ -60,8 +60,8 @@ class TrackDetailsDialog extends HookConsumerWidget {
context.l10n.channel: Text(sourceInfo.artists), context.l10n.channel: Text(sourceInfo.artists),
if (sourcedTrack.asData?.value.url != null) if (sourcedTrack.asData?.value.url != null)
context.l10n.streamUrl: Hyperlink( context.l10n.streamUrl: Hyperlink(
sourcedTrack.asData!.value.url ?? "", sourcedTrack.asData!.value.url,
sourcedTrack.asData!.value.url ?? "", sourcedTrack.asData!.value.url,
maxLines: 2, maxLines: 2,
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
), ),

View File

@ -130,7 +130,7 @@ class DownloadManagerProvider extends ChangeNotifier {
download.status.value == DownloadStatus.queued, download.status.value == DownloadStatus.queued,
) )
.map((e) => e.request.url) .map((e) => e.request.url)
.contains(sourcedTrack.getUrlOfCodec(downloadCodec)!); .contains(sourcedTrack.getUrlOfCodec(downloadCodec));
} }
/// For singular downloads /// For singular downloads
@ -152,9 +152,7 @@ class DownloadManagerProvider extends ChangeNotifier {
if (sourcedTrack.codec == downloadCodec) { if (sourcedTrack.codec == downloadCodec) {
final downloadTask = await dl.addDownload( final downloadTask = await dl.addDownload(
sourcedTrack.getUrlOfCodec(downloadCodec)!, sourcedTrack.getUrlOfCodec(downloadCodec), savePath);
savePath,
);
if (downloadTask != null) { if (downloadTask != null) {
$history.add(sourcedTrack); $history.add(sourcedTrack);
} }
@ -171,7 +169,7 @@ class DownloadManagerProvider extends ChangeNotifier {
return d; return d;
}); });
final downloadTask = await dl.addDownload( final downloadTask = await dl.addDownload(
sourcedTrack.getUrlOfCodec(downloadCodec)!, sourcedTrack.getUrlOfCodec(downloadCodec),
savePath, savePath,
); );
if (downloadTask != null) { if (downloadTask != null) {
@ -204,18 +202,18 @@ class DownloadManagerProvider extends ChangeNotifier {
Future<void> removeFromQueue(SpotubeFullTrackObject track) async { Future<void> removeFromQueue(SpotubeFullTrackObject track) async {
final sourcedTrack = await mapToSourcedTrack(track); final sourcedTrack = await mapToSourcedTrack(track);
await dl.removeDownload(sourcedTrack.getUrlOfCodec(downloadCodec)!); await dl.removeDownload(sourcedTrack.getUrlOfCodec(downloadCodec));
$history.remove(sourcedTrack); $history.remove(sourcedTrack);
} }
Future<void> pause(SpotubeFullTrackObject track) async { Future<void> pause(SpotubeFullTrackObject track) async {
final sourcedTrack = await mapToSourcedTrack(track); final sourcedTrack = await mapToSourcedTrack(track);
return dl.pauseDownload(sourcedTrack.getUrlOfCodec(downloadCodec)!); return dl.pauseDownload(sourcedTrack.getUrlOfCodec(downloadCodec));
} }
Future<void> resume(SpotubeFullTrackObject track) async { Future<void> resume(SpotubeFullTrackObject track) async {
final sourcedTrack = await mapToSourcedTrack(track); final sourcedTrack = await mapToSourcedTrack(track);
return dl.resumeDownload(sourcedTrack.getUrlOfCodec(downloadCodec)!); return dl.resumeDownload(sourcedTrack.getUrlOfCodec(downloadCodec));
} }
Future<void> retry(SpotubeFullTrackObject track) { Future<void> retry(SpotubeFullTrackObject track) {
@ -224,7 +222,7 @@ class DownloadManagerProvider extends ChangeNotifier {
void cancel(SpotubeFullTrackObject track) async { void cancel(SpotubeFullTrackObject track) async {
final sourcedTrack = await mapToSourcedTrack(track); final sourcedTrack = await mapToSourcedTrack(track);
return dl.cancelDownload(sourcedTrack.getUrlOfCodec(downloadCodec)!); return dl.cancelDownload(sourcedTrack.getUrlOfCodec(downloadCodec));
} }
void cancelAll() { void cancelAll() {
@ -258,7 +256,7 @@ class DownloadManagerProvider extends ChangeNotifier {
if (sourcedTrack == null) { if (sourcedTrack == null) {
return null; return null;
} }
return dl.getDownload(sourcedTrack.getUrlOfCodec(downloadCodec)!)?.status; return dl.getDownload(sourcedTrack.getUrlOfCodec(downloadCodec))?.status;
} }
ValueNotifier<double>? getProgressNotifier(SpotubeFullTrackObject track) { ValueNotifier<double>? getProgressNotifier(SpotubeFullTrackObject track) {
@ -268,7 +266,7 @@ class DownloadManagerProvider extends ChangeNotifier {
if (sourcedTrack == null) { if (sourcedTrack == null) {
return null; return null;
} }
return dl.getDownload(sourcedTrack.getUrlOfCodec(downloadCodec)!)?.progress; return dl.getDownload(sourcedTrack.getUrlOfCodec(downloadCodec))?.progress;
} }
} }

View File

@ -61,20 +61,13 @@ class ServerPlaybackRoutes {
); );
final trackPartialCacheFile = File("${trackCacheFile.path}.part"); final trackPartialCacheFile = File("${trackCacheFile.path}.part");
String? url = track.url;
url ??= await ref
.read(trackSourcesProvider(track.query).notifier)
.swapWithNextSibling()
.then((track) => track.url!);
var options = Options( var options = Options(
headers: { headers: {
...headers, ...headers,
"user-agent": _randomUserAgent, "user-agent": _randomUserAgent,
"Cache-Control": "max-age=3600", "Cache-Control": "max-age=3600",
"Connection": "keep-alive", "Connection": "keep-alive",
"host": Uri.parse(url!).host, "host": Uri.parse(track.url).host,
}, },
responseType: ResponseType.bytes, responseType: ResponseType.bytes,
validateStatus: (status) => status! < 400, validateStatus: (status) => status! < 400,
@ -82,7 +75,7 @@ class ServerPlaybackRoutes {
final headersRes = await Future<dio_lib.Response?>.value( final headersRes = await Future<dio_lib.Response?>.value(
dio.head( dio.head(
url, track.url,
options: options, options: options,
), ),
).catchError((_) async => null); ).catchError((_) async => null);
@ -102,7 +95,7 @@ class ServerPlaybackRoutes {
"accept-ranges": ["bytes"], "accept-ranges": ["bytes"],
"content-range": ["bytes 0-$cachedFileLength/$cachedFileLength"], "content-range": ["bytes 0-$cachedFileLength/$cachedFileLength"],
}), }),
requestOptions: RequestOptions(path: url), requestOptions: RequestOptions(path: track.url),
), ),
bytes: bytes, bytes: bytes,
); );
@ -125,7 +118,7 @@ class ServerPlaybackRoutes {
final res = await dio final res = await dio
.get<Uint8List>( .get<Uint8List>(
url, track.url,
options: options.copyWith(headers: { options: options.copyWith(headers: {
...?options.headers, ...?options.headers,
"user-agent": _randomUserAgent, "user-agent": _randomUserAgent,
@ -143,7 +136,7 @@ class ServerPlaybackRoutes {
// } // }
return await dio.get<Uint8List>( return await dio.get<Uint8List>(
sourcedTrack.url!, sourcedTrack.url,
options: options.copyWith(headers: { options: options.copyWith(headers: {
...?options.headers, ...?options.headers,
"user-agent": _randomUserAgent, "user-agent": _randomUserAgent,

View File

@ -34,12 +34,6 @@ class TrackSourcesNotifier
return await prev.swapWithSibling(sibling) ?? prev; return await prev.swapWithSibling(sibling) ?? prev;
}); });
} }
Future<SourcedTrack> swapWithNextSibling() async {
return await update((prev) async {
return await prev.swapWithSibling(prev.siblings.first) as SourcedTrack;
});
}
} }
final trackSourcesProvider = AsyncNotifierProviderFamily<TrackSourcesNotifier, final trackSourcesProvider = AsyncNotifierProviderFamily<TrackSourcesNotifier,

View File

@ -141,7 +141,7 @@ abstract class SourcedTrack extends BasicSourcedTrack {
} }
Future<SourcedTrack> refreshStream(); Future<SourcedTrack> refreshStream();
String? get url { String get url {
final preferences = ref.read(userPreferencesProvider); final preferences = ref.read(userPreferencesProvider);
final codec = preferences.audioSource == AudioSource.jiosaavn final codec = preferences.audioSource == AudioSource.jiosaavn
@ -157,7 +157,7 @@ abstract class SourcedTrack extends BasicSourcedTrack {
/// ///
/// If no sources match the codec, it will return the first or last source /// If no sources match the codec, it will return the first or last source
/// based on the user's audio quality preference. /// based on the user's audio quality preference.
String? getUrlOfCodec(SourceCodecs codec) { String getUrlOfCodec(SourceCodecs codec) {
final preferences = ref.read(userPreferencesProvider); final preferences = ref.read(userPreferencesProvider);
final exactMatch = sources.firstWhereOrNull( final exactMatch = sources.firstWhereOrNull(
@ -191,8 +191,8 @@ abstract class SourcedTrack extends BasicSourcedTrack {
}); });
return preferences.audioQuality != SourceQualities.low return preferences.audioQuality != SourceQualities.low
? fallbackSource.firstOrNull?.url ? fallbackSource.first.url
: fallbackSource.lastOrNull?.url; : fallbackSource.last.url;
} }
SourceCodecs get codec { SourceCodecs get codec {

View File

@ -204,8 +204,6 @@ class YoutubeSourcedTrack extends SourcedTrack {
AppLogger.log AppLogger.log
.d("${track.title} ISRC $isrc Total ${searchedVideos.length}"); .d("${track.title} ISRC $isrc Total ${searchedVideos.length}");
final stringBuffer = StringBuffer();
final filteredMatches = searchedVideos final filteredMatches = searchedVideos
.map<YoutubeVideoInfo>(YoutubeVideoInfo.fromVideo) .map<YoutubeVideoInfo>(YoutubeVideoInfo.fromVideo)
.map((YoutubeVideoInfo videoInfo) { .map((YoutubeVideoInfo videoInfo) {
@ -226,10 +224,6 @@ class YoutubeSourcedTrack extends SourcedTrack {
.abs() .abs()
.inMilliseconds <= .inMilliseconds <=
3000) { 3000) {
stringBuffer.writeln(
"ISRC MATCH: ${videoInfo.id} ${videoInfo.title} by ${videoInfo.channelName} ${videoInfo.duration}",
);
return videoInfo; return videoInfo;
} }
return null; return null;
@ -237,7 +231,11 @@ class YoutubeSourcedTrack extends SourcedTrack {
.nonNulls .nonNulls
.toList(); .toList();
AppLogger.log.d(stringBuffer.toString()); for (final match in filteredMatches) {
AppLogger.log.d(
"ISRC MATCH: ${match.id} ${match.title} by ${match.channelName} ${match.duration}",
);
}
isrcResults.addAll(filteredMatches); isrcResults.addAll(filteredMatches);
} }
@ -264,16 +262,9 @@ class YoutubeSourcedTrack extends SourcedTrack {
final links = await SongLinkService.links(query.id); final links = await SongLinkService.links(query.id);
final stringBuffer = links.fold( for (final link in links) {
StringBuffer(), AppLogger.log.d("SongLink ${query.id} ${link.platform} ${link.url}");
(previousValue, element) { }
previousValue.writeln(
"SongLink ${query.id} ${element.platform} ${element.url}");
return previousValue;
},
);
AppLogger.log.d(stringBuffer.toString());
final ytLink = links.firstWhereOrNull( final ytLink = links.firstWhereOrNull(
(link) => link.platform == "youtube", (link) => link.platform == "youtube",

View File

@ -1,7 +1,6 @@
import 'dart:isolate'; import 'dart:isolate';
import 'package:dio/dio.dart'; import 'package:dio/dio.dart';
import 'package:flutter/foundation.dart';
import 'package:spotube/services/dio/dio.dart'; import 'package:spotube/services/dio/dio.dart';
import 'package:spotube/services/logger/logger.dart'; import 'package:spotube/services/logger/logger.dart';
import 'package:spotube/services/youtube_engine/youtube_engine.dart'; import 'package:spotube/services/youtube_engine/youtube_engine.dart';
@ -61,7 +60,6 @@ class IsolatedYoutubeExplode {
static void _isolateEntry(SendPort mainSendPort) { static void _isolateEntry(SendPort mainSendPort) {
final receivePort = ReceivePort(); final receivePort = ReceivePort();
final youtubeExplode = YoutubeExplode(); final youtubeExplode = YoutubeExplode();
final stopWatch = kDebugMode ? Stopwatch() : null;
/// Send the main port to the main isolate /// Send the main port to the main isolate
mainSendPort.send(receivePort.sendPort); mainSendPort.send(receivePort.sendPort);
@ -71,19 +69,6 @@ class IsolatedYoutubeExplode {
final String methodName = message[1]; final String methodName = message[1];
final List<dynamic> arguments = message[2]; final List<dynamic> arguments = message[2];
if (stopWatch != null) {
if (stopWatch.isRunning) {
stopWatch.stop();
final symbol = stopWatch.elapsedMilliseconds < 1000 ? "⚠️" : "⏱️";
debugPrint(
"$symbol YoutubeExplode operation gap ${stopWatch.elapsedMilliseconds} ms",
);
stopWatch.reset();
} else {
stopWatch.start();
}
}
// Run the requested method on YoutubeExplode // Run the requested method on YoutubeExplode
var result = switch (methodName) { var result = switch (methodName) {
"search" => youtubeExplode.search "search" => youtubeExplode.search
@ -171,7 +156,6 @@ class YouTubeExplodeEngine implements YouTubeEngine {
); );
final accessibleStreams = <AudioOnlyStreamInfo>[]; final accessibleStreams = <AudioOnlyStreamInfo>[];
final stringBuffer = StringBuffer();
for (final stream in streamManifest.audioOnly) { for (final stream in streamManifest.audioOnly) {
// Call dio head request to check if the stream is accessible // Call dio head request to check if the stream is accessible
@ -185,7 +169,7 @@ class YouTubeExplodeEngine implements YouTubeEngine {
), ),
); );
stringBuffer.writeln( AppLogger.log.d(
"Stream $videoId Status ${response.statusCode} Codec ${stream.audioCodec} " "Stream $videoId Status ${response.statusCode} Codec ${stream.audioCodec} "
"Bitrate ${stream.bitrate} Container ${stream.container}", "Bitrate ${stream.bitrate} Container ${stream.container}",
); );
@ -215,8 +199,6 @@ class YouTubeExplodeEngine implements YouTubeEngine {
} }
} }
AppLogger.log.d(stringBuffer.toString());
return StreamManifest(accessibleStreams); return StreamManifest(accessibleStreams);
} }