1
0
Fork 0
mirror of https://github.com/fiso64/slsk-batchdl.git synced 2024-12-22 06:22:41 +00:00

fix invalid filename chars

This commit is contained in:
fiso64 2024-10-03 23:11:55 +02:00
parent 962510ad7c
commit 6a2e68e562
5 changed files with 34 additions and 4 deletions

View file

@ -28,6 +28,8 @@ static class Download
string origPath = filePath;
filePath += ".incomplete";
Printing.WriteLine($"Downloading: {track} to '{filePath}'", debugOnly: true);
var transferOptions = new TransferOptions(
stateChanged: (state) =>
{

View file

@ -33,7 +33,7 @@ public class FileManager
if (tle.defaultFolderName != null)
{
parent = Path.Join(parent, tle.defaultFolderName.ReplaceInvalidChars(Config.I.invalidReplaceStr, removeSlash: false));
parent = Path.Join(parent, tle.defaultFolderName);
}
if (tle.source.Type == TrackType.Album && !string.IsNullOrEmpty(remoteCommonDir))
@ -44,7 +44,7 @@ public class FileManager
parent = Path.Join(parent, dirname, Path.GetDirectoryName(relpath) ?? "");
}
return Path.Join(parent, name);
return Path.Join(parent, name).CleanPath(Config.I.invalidReplaceStr);
}
public void SetRemoteCommonDir(string? remoteCommonDir)

View file

@ -493,7 +493,7 @@ static partial class Program
PrintAlbum(tracks);
}
var semaphore = new SemaphoreSlim(999); // Needs to be uncapped due to a bug that causes album downloads to fail after some time
var semaphore = new SemaphoreSlim(Config.I.concurrentProcesses == -2 ? 1 : 999); // Needs to be uncapped due to a bug that causes album downloads to fail after some time
using var cts = new CancellationTokenSource();
try

View file

@ -272,6 +272,34 @@ public static class Utils
return str;
}
public static string CleanPath(this string fullPath, string replaceWith)
{
fullPath = Utils.NormalizedPath(fullPath);
string[] pathParts = fullPath.Split('/');
foreach (char badChar in Path.GetInvalidPathChars())
{
if (badChar != ':')
{
pathParts[0] = pathParts[0].Replace(badChar.ToString(), replaceWith);
}
}
var chars = Path.GetInvalidFileNameChars();
for (int i = 1; i < pathParts.Length; i++)
{
foreach (char badChar in chars)
{
pathParts[i] = pathParts[i].Replace(badChar.ToString(), replaceWith);
}
}
return string.Join('/', pathParts);
}
public static string ReplaceSpecialChars(this string str, string replaceStr)
{
if (str.Length == 0)

View file

@ -27,7 +27,7 @@
<PackageReference Include="SpotifyAPI.Web" Version="7.1.1" />
<PackageReference Include="SpotifyAPI.Web.Auth" Version="7.1.1" />
<PackageReference Include="TagLibSharp" Version="2.3.0" />
<PackageReference Include="YoutubeExplode" Version="6.4.2" />
<PackageReference Include="YoutubeExplode" Version="6.4.3" />
</ItemGroup>
<ItemGroup>