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:
parent
962510ad7c
commit
6a2e68e562
5 changed files with 34 additions and 4 deletions
|
@ -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) =>
|
||||
{
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in a new issue