Skip to content

Commit

Permalink
fix: sanitize song title for file name (#644)
Browse files Browse the repository at this point in the history
  • Loading branch information
KRTirtho committed Aug 25, 2023
1 parent 08b627e commit 1a7ea0c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/provider/download_manager_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import 'package:spotube/provider/user_preferences_provider.dart';
import 'package:spotube/provider/youtube_provider.dart';
import 'package:spotube/services/download_manager/download_manager.dart';
import 'package:spotube/services/youtube/youtube.dart';
import 'package:spotube/utils/primitive_utils.dart';
import 'package:spotube/utils/type_conversion_utils.dart';

class DownloadManagerProvider extends ChangeNotifier {
Expand Down Expand Up @@ -130,7 +131,7 @@ class DownloadManagerProvider extends ChangeNotifier {
String getTrackFileUrl(Track track) {
final name =
"${track.name} - ${TypeConversionUtils.artists_X_String(track.artists ?? <Artist>[])}.m4a";
return join(downloadDirectory, name);
return join(downloadDirectory, PrimitiveUtils.toSafeFileName(name));
}

bool isActive(Track track) {
Expand Down
4 changes: 4 additions & 0 deletions lib/utils/primitive_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,8 @@ abstract class PrimitiveUtils {
}),
);
}

static String toSafeFileName(String str) {
return str.replaceAll(RegExp(r'[^\w\s\.\-_]'), "_");
}
}
4 changes: 2 additions & 2 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1090,10 +1090,10 @@ packages:
dependency: "direct main"
description:
name: media_kit_libs_android_audio
sha256: "767a93c44da73b7103a1fcbe2346f7211b7c44fa727f359410e690a156f630c5"
sha256: f16e67d4c5a85cb603290da253456bc8ea3d85d932c778e3afd11195db2dc26d
url: "https://pub.dev"
source: hosted
version: "1.3.1"
version: "1.3.2"
media_kit_libs_ios_audio:
dependency: "direct main"
description:
Expand Down

0 comments on commit 1a7ea0c

Please sign in to comment.