mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-12-06 07:29:42 +00:00
Compare commits
5 Commits
b97c9c98ab
...
cb84494ed1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cb84494ed1 | ||
|
|
3e34bc4be6 | ||
|
|
ff252d6b14 | ||
|
|
195cad8f39 | ||
|
|
19f525fa3c |
@ -137,16 +137,16 @@
|
||||
"pre_download_play_description": "Anzi che effettuare lo stream dell'audio, scarica invece i byte e li riproduce (raccomandato per gli utenti con banda più alta)",
|
||||
"skip_non_music": "Salta i segmenti non di musica (SponsorBlock)",
|
||||
"blacklist_description": "Tracce e artisti in blacklist",
|
||||
"wait_for_download_to_finish": "Prego attendere che lo scaricamento corrente finisca",
|
||||
"wait_for_download_to_finish": "Prego attendere che il download corrente finisca",
|
||||
"desktop": "Desktop",
|
||||
"close_behavior": "Comportamento Chiusura",
|
||||
"close": "Chiudi",
|
||||
"minimize_to_tray": "Minimizza in tray",
|
||||
"show_tray_icon": "Mostra icona in tray di sistema",
|
||||
"about": "A proposito di",
|
||||
"about": "Informazioni su",
|
||||
"u_love_spotube": "Sappiamo che ami Spotube",
|
||||
"check_for_updates": "Controlla aggiornamenti",
|
||||
"about_spotube": "A proposito di Spotube",
|
||||
"about_spotube": "Informazioni su Spotube",
|
||||
"blacklist": "Blacklist",
|
||||
"please_sponsor": "Per favore sponsorizza/dona",
|
||||
"spotube_description": "Spotube, un client spotify gratis per tutti, multipiattaforma e leggero",
|
||||
@ -187,7 +187,7 @@
|
||||
"generate_playlist": "Genera Playlist",
|
||||
"track_exists": "La traccia {track} esiste già",
|
||||
"replace_downloaded_tracks": "Sostituisci tutte le tracce scaricate",
|
||||
"skip_download_tracks": "Salta lo scaricamento di tutte le tracce scaricate",
|
||||
"skip_download_tracks": "Salta il download di tutte le tracce scaricate",
|
||||
"do_you_want_to_replace": "Vuoi sovrascrivere la traccia esistente??",
|
||||
"replace": "Sovrascrivi",
|
||||
"skip": "Salta",
|
||||
@ -256,7 +256,7 @@
|
||||
"querying_info": "Richiesta informazioni...",
|
||||
"piped_api_down": "Le Piped API non funzionano",
|
||||
"piped_down_error_instructions": "L'istanza di Piped {pipedInstance} è correntemente offline\n\nCambia istanza o cambia 'Tipo API' alle API ufficiali YouTube\n\nAssicurati di riavviare l'app dopo il cambio",
|
||||
"you_are_offline": "Sei correntemente offline",
|
||||
"you_are_offline": "Al momento sei offline",
|
||||
"connection_restored": "Connessione ad internet ripristinata",
|
||||
"use_system_title_bar": "Usa la barra del titolo di sistema",
|
||||
"crunching_results": "Elaborazione risultati...",
|
||||
@ -267,15 +267,15 @@
|
||||
"change_cover": "Cambia copertina",
|
||||
"add_cover": "Aggiungi copertina",
|
||||
"restore_defaults": "Ripristina default",
|
||||
"download_music_codec": "Codec musicale scaricamento",
|
||||
"streaming_music_codec": "Codec musicale streaming",
|
||||
"login_with_lastfm": "Accesso a Last.fm",
|
||||
"connect": "Connetti",
|
||||
"disconnect_lastfm": "Disconnetti Last.fm",
|
||||
"download_music_codec": "Codec download musica",
|
||||
"streaming_music_codec": "Codec streaming musica",
|
||||
"login_with_lastfm": "Accedi con Last.fm",
|
||||
"connect": "Connettiti",
|
||||
"disconnect_lastfm": "Disconnettiti da Last.fm",
|
||||
"disconnect": "Disconnetti",
|
||||
"username": "Nome utente",
|
||||
"password": "Password",
|
||||
"login": "Accesso",
|
||||
"login": "Accedi",
|
||||
"login_with_your_lastfm": "Accedi con il tuo account Last.fm",
|
||||
"scrobble_to_lastfm": "Invia a Last.fm",
|
||||
"audio_source": "Fonte audio",
|
||||
@ -299,7 +299,7 @@
|
||||
"song_link": "Link della Canzone",
|
||||
"skip_this_nonsense": "Salta questa sciocchezza",
|
||||
"freedom_of_music": "“Libertà della Musica”",
|
||||
"freedom_of_music_palm": "“Libertà della Musica nel palmo della tua mano”",
|
||||
"freedom_of_music_palm": "“Libertà della Musica nelle tue mani”",
|
||||
"get_started": "Cominciamo",
|
||||
"youtube_source_description": "Consigliato e funziona meglio.",
|
||||
"piped_source_description": "Ti senti libero? Come YouTube ma molto più gratuito.",
|
||||
|
||||
@ -12,6 +12,7 @@ final serverRouterProvider = Provider((ref) {
|
||||
|
||||
router.get("/ping", (Request request) => Response.ok("pong"));
|
||||
|
||||
router.head("/stream/<trackId>", playbackRoutes.headStreamTrackId);
|
||||
router.get("/stream/<trackId>", playbackRoutes.getStreamTrackId);
|
||||
|
||||
router.get("/playback/toggle-playback", playbackRoutes.togglePlayback);
|
||||
|
||||
@ -46,21 +46,95 @@ class ServerPlaybackRoutes {
|
||||
|
||||
ServerPlaybackRoutes(this.ref) : dio = Dio();
|
||||
|
||||
Future<String> _getTrackCacheFilePath(SourcedTrack track) async {
|
||||
return join(
|
||||
await UserPreferencesNotifier.getMusicCacheDir(),
|
||||
ServiceUtils.sanitizeFilename(
|
||||
'${track.query.title} - ${track.query.artists.join(",")} (${track.info.id}).${track.codec.name}',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<SourcedTrack?> _getSourcedTrack(
|
||||
Request request, String trackId) async {
|
||||
final track =
|
||||
playlist.tracks.firstWhere((element) => element.id == trackId);
|
||||
|
||||
final activeSourcedTrack =
|
||||
await ref.read(activeTrackSourcesProvider.future);
|
||||
final sourcedTrack = activeSourcedTrack?.track.id == track.id
|
||||
? activeSourcedTrack?.source
|
||||
: await ref.read(
|
||||
trackSourcesProvider(
|
||||
//! Use [Request.requestedUri] as it contains full https url.
|
||||
//! [Request.url] will exclude and starts relatively. (streams/<trackId>... basically)
|
||||
TrackSourceQuery.parseUri(request.requestedUri.toString()),
|
||||
).future,
|
||||
);
|
||||
|
||||
return sourcedTrack;
|
||||
}
|
||||
|
||||
Future<dio_lib.Response> streamTrackInformation(
|
||||
Request request,
|
||||
SourcedTrack track,
|
||||
) async {
|
||||
AppLogger.log.i(
|
||||
"HEAD request for track: ${track.query.title}\n"
|
||||
"Headers: ${request.headers}",
|
||||
);
|
||||
|
||||
final trackCacheFile = File(await _getTrackCacheFilePath(track));
|
||||
|
||||
if (await trackCacheFile.exists() && userPreferences.cacheMusic) {
|
||||
final fileLength = await trackCacheFile.length();
|
||||
|
||||
return dio_lib.Response(
|
||||
statusCode: 200,
|
||||
headers: Headers.fromMap({
|
||||
"content-type": ["audio/${track.codec.name}"],
|
||||
"content-length": ["$fileLength"],
|
||||
"accept-ranges": ["bytes"],
|
||||
"content-range": ["bytes 0-$fileLength/$fileLength"],
|
||||
}),
|
||||
requestOptions: RequestOptions(path: request.requestedUri.toString()),
|
||||
);
|
||||
}
|
||||
|
||||
String url = track.url ??
|
||||
await ref
|
||||
.read(trackSourcesProvider(track.query).notifier)
|
||||
.swapWithNextSibling()
|
||||
.then((track) => track.url!);
|
||||
|
||||
final options = Options(
|
||||
headers: {
|
||||
"user-agent": _randomUserAgent,
|
||||
"Cache-Control": "max-age=3600",
|
||||
"Connection": "keep-alive",
|
||||
"host": Uri.parse(url).host,
|
||||
},
|
||||
validateStatus: (status) => status! < 400,
|
||||
);
|
||||
|
||||
final res = await dio.head(url, options: options);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
Future<({dio_lib.Response<Uint8List> response, Uint8List? bytes})>
|
||||
streamTrack(
|
||||
Request request,
|
||||
SourcedTrack track,
|
||||
Map<String, dynamic> headers,
|
||||
) async {
|
||||
final trackCacheFile = File(
|
||||
join(
|
||||
await UserPreferencesNotifier.getMusicCacheDir(),
|
||||
ServiceUtils.sanitizeFilename(
|
||||
'${track.query.title} - ${track.query.artists.join(",")} (${track.info.id}).${track.codec.name}',
|
||||
),
|
||||
),
|
||||
AppLogger.log.i(
|
||||
"GET request for track: ${track.query.title}\n"
|
||||
"Headers: ${request.headers}",
|
||||
);
|
||||
|
||||
final trackCacheFile = File(await _getTrackCacheFilePath(track));
|
||||
|
||||
if (await trackCacheFile.exists() && userPreferences.cacheMusic) {
|
||||
final bytes = await trackCacheFile.readAsBytes();
|
||||
final cachedFileLength = bytes.length;
|
||||
@ -132,16 +206,20 @@ class ServerPlaybackRoutes {
|
||||
);
|
||||
}
|
||||
|
||||
if (headers["range"] == "bytes=0-") {
|
||||
if (headers["range"] == "bytes=0-" && track.codec == SourceCodecs.flac) {
|
||||
final bufferSize =
|
||||
userPreferences.audioQuality == SourceQualities.uncompressed
|
||||
? 6 * 1024 * 1024
|
||||
: 4 * 1024 * 1024;
|
||||
final endRange = min(bufferSize,
|
||||
int.parse(contentLengthRes?.headers.value("content-length") ?? "0"));
|
||||
? 6 * 1024 * 1024 // 6MB for lossless
|
||||
: 4 * 1024 * 1024; // 4MB for lossy
|
||||
|
||||
final endRange = min(
|
||||
bufferSize,
|
||||
int.parse(contentLengthRes?.headers.value("content-length") ?? "0"),
|
||||
);
|
||||
|
||||
options = options.copyWith(
|
||||
headers: {
|
||||
...options.headers ?? {},
|
||||
...?options.headers,
|
||||
"range": "bytes=0-$endRange",
|
||||
},
|
||||
);
|
||||
@ -149,6 +227,12 @@ class ServerPlaybackRoutes {
|
||||
|
||||
final res = await dio.get<Uint8List>(url, options: options);
|
||||
|
||||
AppLogger.log.i(
|
||||
"Response for track: ${track.query.title}\n"
|
||||
"Status Code: ${res.statusCode}\n"
|
||||
"Headers: ${res.headers.map}",
|
||||
);
|
||||
|
||||
final bytes = res.data;
|
||||
|
||||
if (bytes == null || !userPreferences.cacheMusic) {
|
||||
@ -208,27 +292,42 @@ class ServerPlaybackRoutes {
|
||||
return (bytes: bytes, response: res);
|
||||
}
|
||||
|
||||
/// @head('/stream/<trackId>')
|
||||
Future<Response> headStreamTrackId(Request request, String trackId) async {
|
||||
try {
|
||||
final sourcedTrack = await _getSourcedTrack(request, trackId);
|
||||
|
||||
if (sourcedTrack == null) {
|
||||
return Response.notFound("Track not found in the current queue");
|
||||
}
|
||||
|
||||
final res = await streamTrackInformation(
|
||||
request,
|
||||
sourcedTrack,
|
||||
);
|
||||
|
||||
return Response(
|
||||
res.statusCode!,
|
||||
headers: res.headers.map,
|
||||
);
|
||||
} catch (e, stack) {
|
||||
AppLogger.reportError(e, stack);
|
||||
return Response.internalServerError();
|
||||
}
|
||||
}
|
||||
|
||||
/// @get('/stream/<trackId>')
|
||||
Future<Response> getStreamTrackId(Request request, String trackId) async {
|
||||
try {
|
||||
final track =
|
||||
playlist.tracks.firstWhere((element) => element.id == trackId);
|
||||
final sourcedTrack = await _getSourcedTrack(request, trackId);
|
||||
|
||||
final activeSourcedTrack =
|
||||
await ref.read(activeTrackSourcesProvider.future);
|
||||
final sourcedTrack = activeSourcedTrack?.track.id == track.id
|
||||
? activeSourcedTrack?.source
|
||||
: await ref.read(
|
||||
trackSourcesProvider(
|
||||
//! Use [Request.requestedUri] as it contains full https url.
|
||||
//! [Request.url] will exclude and starts relatively. (streams/<trackId>... basically)
|
||||
TrackSourceQuery.parseUri(request.requestedUri.toString()),
|
||||
).future,
|
||||
);
|
||||
if (sourcedTrack == null) {
|
||||
return Response.notFound("Track not found in the current queue");
|
||||
}
|
||||
|
||||
final (bytes: audioBytes, response: res) = await streamTrack(
|
||||
request,
|
||||
sourcedTrack!,
|
||||
sourcedTrack,
|
||||
request.headers,
|
||||
);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user