mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-13 07:55:18 +00:00
fix: local playback not working for tracks with special # (hashtag) characters
This commit is contained in:
parent
dddaa5a964
commit
2a0853026a
@ -42,6 +42,17 @@ extension SpotubeImageExtensions on List<SpotubeImageObject>? {
|
|||||||
: placeholderUrlMap[placeholder]!;
|
: placeholderUrlMap[placeholder]!;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Uri asUri({
|
||||||
|
int index = 1,
|
||||||
|
required ImagePlaceholder placeholder,
|
||||||
|
}) {
|
||||||
|
final url = asUrlString(placeholder: placeholder, index: index);
|
||||||
|
if (url.startsWith("http")) {
|
||||||
|
return Uri.parse(url);
|
||||||
|
}
|
||||||
|
return Uri.file(url);
|
||||||
|
}
|
||||||
|
|
||||||
String smallest(ImagePlaceholder placeholder) {
|
String smallest(ImagePlaceholder placeholder) {
|
||||||
final sortedImage = this?.sorted((a, b) {
|
final sortedImage = this?.sorted((a, b) {
|
||||||
final widthComparison = (a.width ?? 0).compareTo(b.width ?? 0);
|
final widthComparison = (a.width ?? 0).compareTo(b.width ?? 0);
|
||||||
|
@ -2,6 +2,7 @@ import 'package:freezed_annotation/freezed_annotation.dart';
|
|||||||
import 'package:spotube/models/database/database.dart';
|
import 'package:spotube/models/database/database.dart';
|
||||||
import 'package:spotube/models/metadata/metadata.dart';
|
import 'package:spotube/models/metadata/metadata.dart';
|
||||||
import 'package:spotube/services/audio_player/audio_player.dart';
|
import 'package:spotube/services/audio_player/audio_player.dart';
|
||||||
|
import 'package:spotube/services/logger/logger.dart';
|
||||||
import 'package:spotube/services/sourced_track/enums.dart';
|
import 'package:spotube/services/sourced_track/enums.dart';
|
||||||
|
|
||||||
part 'track_sources.freezed.dart';
|
part 'track_sources.freezed.dart';
|
||||||
@ -38,10 +39,30 @@ class TrackSourceQuery with _$TrackSourceQuery {
|
|||||||
|
|
||||||
/// Parses [SpotubeMedia]'s [uri] property to create a [TrackSourceQuery].
|
/// Parses [SpotubeMedia]'s [uri] property to create a [TrackSourceQuery].
|
||||||
factory TrackSourceQuery.parseUri(String url) {
|
factory TrackSourceQuery.parseUri(String url) {
|
||||||
final uri = Uri.parse(url);
|
final isLocal = !url.startsWith("http");
|
||||||
final isLocal = uri.queryParameters.isEmpty;
|
|
||||||
|
if (isLocal) {
|
||||||
|
try {
|
||||||
return TrackSourceQuery(
|
return TrackSourceQuery(
|
||||||
id: isLocal ? uri.path : uri.pathSegments.last,
|
id: url,
|
||||||
|
title: '',
|
||||||
|
artists: [],
|
||||||
|
album: '',
|
||||||
|
durationMs: 0,
|
||||||
|
isrc: '',
|
||||||
|
explicit: false,
|
||||||
|
);
|
||||||
|
} catch (e, stackTrace) {
|
||||||
|
AppLogger.log.e(
|
||||||
|
"Failed to parse local track URI: $url\n$e",
|
||||||
|
stackTrace: stackTrace,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final uri = Uri.parse(url);
|
||||||
|
return TrackSourceQuery(
|
||||||
|
id: uri.pathSegments.last,
|
||||||
title: uri.queryParameters['title'] ?? '',
|
title: uri.queryParameters['title'] ?? '',
|
||||||
artists: uri.queryParameters['artists']?.split(',') ?? [],
|
artists: uri.queryParameters['artists']?.split(',') ?? [],
|
||||||
album: uri.queryParameters['album'] ?? '',
|
album: uri.queryParameters['album'] ?? '',
|
||||||
|
@ -32,23 +32,6 @@ class LocalFolderItem extends HookConsumerWidget {
|
|||||||
final isDownloadFolder = folder == downloadFolder;
|
final isDownloadFolder = folder == downloadFolder;
|
||||||
final isCacheFolder = folder == cacheFolder.data;
|
final isCacheFolder = folder == cacheFolder.data;
|
||||||
|
|
||||||
final Uri(:pathSegments) = Uri.parse(
|
|
||||||
folder
|
|
||||||
.replaceFirst(RegExp(r'^/Volumes/[^/]+/Users/'), "")
|
|
||||||
.replaceFirst(r'C:\Users\', "")
|
|
||||||
.replaceFirst(r'/home/', ""),
|
|
||||||
);
|
|
||||||
|
|
||||||
// if length > 5, we ... all the middle segments after 2 and the last 2
|
|
||||||
final segments = pathSegments.length > 5
|
|
||||||
? [
|
|
||||||
...pathSegments.take(2),
|
|
||||||
"...",
|
|
||||||
...pathSegments.skip(pathSegments.length - 3).toList()
|
|
||||||
..removeLast(),
|
|
||||||
]
|
|
||||||
: pathSegments.take(max(pathSegments.length - 1, 0)).toList();
|
|
||||||
|
|
||||||
final trackSnapshot = ref.watch(
|
final trackSnapshot = ref.watch(
|
||||||
localTracksProvider.select(
|
localTracksProvider.select(
|
||||||
(s) => s.whenData((tracks) => tracks[folder]?.take(4).toList()),
|
(s) => s.whenData((tracks) => tracks[folder]?.take(4).toList()),
|
||||||
@ -110,9 +93,6 @@ class LocalFolderItem extends HookConsumerWidget {
|
|||||||
),
|
),
|
||||||
const Gap(8),
|
const Gap(8),
|
||||||
Stack(
|
Stack(
|
||||||
children: [
|
|
||||||
Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
children: [
|
||||||
Center(
|
Center(
|
||||||
child: Text(
|
child: Text(
|
||||||
@ -127,25 +107,6 @@ class LocalFolderItem extends HookConsumerWidget {
|
|||||||
overflow: TextOverflow.ellipsis,
|
overflow: TextOverflow.ellipsis,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Wrap(
|
|
||||||
spacing: 2,
|
|
||||||
runSpacing: 2,
|
|
||||||
children: [
|
|
||||||
for (final MapEntry(key: index, value: segment)
|
|
||||||
in segments.asMap().entries)
|
|
||||||
Text.rich(
|
|
||||||
TextSpan(
|
|
||||||
children: [
|
|
||||||
if (index != 0) const TextSpan(text: "/ "),
|
|
||||||
TextSpan(text: segment),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
maxLines: 2,
|
|
||||||
).xSmall().muted(),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
if (!isDownloadFolder && !isCacheFolder)
|
if (!isDownloadFolder && !isCacheFolder)
|
||||||
Align(
|
Align(
|
||||||
alignment: Alignment.topRight,
|
alignment: Alignment.topRight,
|
||||||
|
@ -25,7 +25,6 @@ import 'package:spotube/provider/metadata_plugin/core/auth.dart';
|
|||||||
import 'package:spotube/provider/server/active_track_sources.dart';
|
import 'package:spotube/provider/server/active_track_sources.dart';
|
||||||
import 'package:spotube/provider/volume_provider.dart';
|
import 'package:spotube/provider/volume_provider.dart';
|
||||||
import 'package:spotube/services/sourced_track/sources/youtube.dart';
|
import 'package:spotube/services/sourced_track/sources/youtube.dart';
|
||||||
import 'package:spotube/utils/platform.dart';
|
|
||||||
|
|
||||||
import 'package:url_launcher/url_launcher_string.dart';
|
import 'package:url_launcher/url_launcher_string.dart';
|
||||||
|
|
||||||
@ -100,8 +99,6 @@ class PlayerView extends HookConsumerWidget {
|
|||||||
backgroundColor: Colors.transparent,
|
backgroundColor: Colors.transparent,
|
||||||
headers: [
|
headers: [
|
||||||
SafeArea(
|
SafeArea(
|
||||||
minimum:
|
|
||||||
kIsMobile ? const EdgeInsets.only(top: 80) : EdgeInsets.zero,
|
|
||||||
bottom: false,
|
bottom: false,
|
||||||
child: TitleBar(
|
child: TitleBar(
|
||||||
surfaceOpacity: 0,
|
surfaceOpacity: 0,
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
import 'package:shadcn_flutter/shadcn_flutter.dart' hide Consumer;
|
import 'package:shadcn_flutter/shadcn_flutter.dart';
|
||||||
import 'package:sliding_up_panel/sliding_up_panel.dart';
|
import 'package:sliding_up_panel/sliding_up_panel.dart';
|
||||||
import 'package:spotube/collections/intents.dart';
|
import 'package:spotube/collections/intents.dart';
|
||||||
import 'package:spotube/collections/spotube_icons.dart';
|
import 'package:spotube/collections/spotube_icons.dart';
|
||||||
|
@ -4,6 +4,7 @@ import 'package:file_selector/file_selector.dart';
|
|||||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
import 'package:shadcn_flutter/shadcn_flutter.dart';
|
import 'package:shadcn_flutter/shadcn_flutter.dart';
|
||||||
|
import 'package:shadcn_flutter/shadcn_flutter_extension.dart';
|
||||||
|
|
||||||
import 'package:spotube/collections/spotube_icons.dart';
|
import 'package:spotube/collections/spotube_icons.dart';
|
||||||
import 'package:spotube/modules/library/local_folder/local_folder_item.dart';
|
import 'package:spotube/modules/library/local_folder/local_folder_item.dart';
|
||||||
@ -85,10 +86,10 @@ class UserLocalLibraryPage extends HookConsumerWidget {
|
|||||||
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
|
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
|
||||||
maxCrossAxisExtent: 200,
|
maxCrossAxisExtent: 200,
|
||||||
mainAxisExtent: constrains.isXs
|
mainAxisExtent: constrains.isXs
|
||||||
? 210
|
? 230 * context.theme.scaling
|
||||||
: constrains.mdAndDown
|
: constrains.mdAndDown
|
||||||
? 280
|
? 280 * context.theme.scaling
|
||||||
: 250,
|
: 250 * context.theme.scaling,
|
||||||
crossAxisSpacing: 10,
|
crossAxisSpacing: 10,
|
||||||
mainAxisSpacing: 10,
|
mainAxisSpacing: 10,
|
||||||
),
|
),
|
||||||
|
@ -163,6 +163,15 @@ class AudioPlayerNotifier extends Notifier<AudioPlayerState> {
|
|||||||
.nonNulls
|
.nonNulls
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
|
if (tracks.length != state.tracks.length) {
|
||||||
|
AppLogger.log.w("Mismatch in tracks after reordering/shuffling.");
|
||||||
|
final missingTracks =
|
||||||
|
state.tracks.where((track) => !tracks.contains(track)).toList();
|
||||||
|
AppLogger.log.w(
|
||||||
|
"Missing tracks: ${missingTracks.map((e) => e.id).join(", ")}",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
state = state.copyWith(
|
state = state.copyWith(
|
||||||
tracks: tracks,
|
tracks: tracks,
|
||||||
currentIndex: playlist.index,
|
currentIndex: playlist.index,
|
||||||
|
@ -83,7 +83,9 @@ Future<void> _sendActiveTrack(SpotubeTrackObject? track) async {
|
|||||||
final image = track.album.images.firstOrNull;
|
final image = track.album.images.firstOrNull;
|
||||||
final cachedImage = image == null
|
final cachedImage = image == null
|
||||||
? null
|
? null
|
||||||
: await DefaultCacheManager().getSingleFile(image.url);
|
: image.url.startsWith("http")
|
||||||
|
? (await DefaultCacheManager().getSingleFile(image.url)).path
|
||||||
|
: image.url;
|
||||||
final data = {
|
final data = {
|
||||||
...jsonTrack,
|
...jsonTrack,
|
||||||
"album": {
|
"album": {
|
||||||
@ -92,7 +94,7 @@ Future<void> _sendActiveTrack(SpotubeTrackObject? track) async {
|
|||||||
if (cachedImage != null && image != null)
|
if (cachedImage != null && image != null)
|
||||||
{
|
{
|
||||||
...image.toJson(),
|
...image.toJson(),
|
||||||
"path": cachedImage.path,
|
"path": cachedImage,
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -53,11 +53,9 @@ class AudioServices with WidgetsBindingObserver {
|
|||||||
title: track.name,
|
title: track.name,
|
||||||
artist: track.artists.asString(),
|
artist: track.artists.asString(),
|
||||||
duration: Duration(milliseconds: track.durationMs),
|
duration: Duration(milliseconds: track.durationMs),
|
||||||
artUri: Uri.parse(
|
artUri: (track.album.images).asUri(
|
||||||
(track.album.images).asUrlString(
|
|
||||||
placeholder: ImagePlaceholder.albumArt,
|
placeholder: ImagePlaceholder.albumArt,
|
||||||
),
|
),
|
||||||
),
|
|
||||||
playable: true,
|
playable: true,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user