Skip to content
This repository was archived by the owner on Jul 25, 2023. It is now read-only.

Commit efd6c1c

Browse files
committed
Strip unsafe characters from filenames
1 parent b2f2e42 commit efd6c1c

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

bin/yt_splitter.dart

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ void main(List<String> arguments) async {
2424

2525
print('YT video: $videoId...');
2626

27-
final path = join( // TODO Maybe fallback to /tmp
27+
final path = join(
28+
// TODO Maybe fallback to /tmp
2829
Platform.isWindows ? Platform.environment['TMP'] : cacheHome.path,
2930
'yt-splitter',
3031
videoId,
@@ -81,7 +82,7 @@ void main(List<String> arguments) async {
8182

8283
final data = json.decode(File(jsonFilePath).readAsStringSync());
8384

84-
final album = data['title'].replaceAll('/', '|');
85+
final album = stripUnsafeCharacters(data['title']);
8586

8687
final artist = data['artist'] ?? data['uploader'] ?? '';
8788

@@ -116,7 +117,7 @@ void main(List<String> arguments) async {
116117

117118
alreadySeenTitles.add(chapterTitle);
118119

119-
chapterTitle = chapterTitle.replaceAll('/', '|');
120+
chapterTitle = stripUnsafeCharacters(chapterTitle);
120121

121122
tracknumber++;
122123

@@ -186,3 +187,7 @@ String renderDuration(int x) {
186187
}
187188
return str;
188189
}
190+
191+
String stripUnsafeCharacters(String text) {
192+
return text.trim().replaceAll(RegExp(r'\|\/\\\?":\*<>'), '_');
193+
}

0 commit comments

Comments
 (0)