diff --git a/Services/DownloaderService.cs b/Services/DownloaderService.cs index 2dbec73..419fad7 100644 --- a/Services/DownloaderService.cs +++ b/Services/DownloaderService.cs @@ -92,8 +92,6 @@ public async Task CheckExecutableExists() public async Task DownloadClips(List clips) { - await CreateAllDirectoriesRequired(clips); - var root = Directory.GetCurrentDirectory(); var username = clips.First().BroadcasterName; @@ -112,7 +110,7 @@ await ParallelExtensions.ParallelForEachAsync(clips, async clip => if (!File.Exists(path)) { counter++; - await ProcessEx.RunAsync(await _hostService.GetDownloaderExecutablePath(), $"{clip.Url} -o \"{path}\""); + await ProcessEx.RunAsync(await _hostService.GetDownloaderExecutablePath(), $"{clip.Url} --restrict-filenames --windows-filenames -o \"{path}\""); await LogHelper.Log($"Downloading clip {counter}/{nonExistingClips.Count} using {await _twitchConfigurationService.GetDownloadThreads()} download threads", asyncLock); } }, await _twitchConfigurationService.GetDownloadThreads()); @@ -120,22 +118,6 @@ await ParallelExtensions.ParallelForEachAsync(clips, async clip => LogHelper.Index += 1; } - private async Task CreateAllDirectoriesRequired(List clips) - { - await LogHelper.Log("Creating directories. This might take a while."); - - foreach (var clip in clips) - { - var savePath = await _hostService.ConvertCustomPathExpressionToSavePath(clip); - var path = savePath.Replace(Path.GetFileName(savePath), ""); - path = path.TrimEnd('\\').TrimEnd('/'); - - path = Path.Combine(Directory.GetCurrentDirectory().TrimEnd('\\').TrimEnd('/'), "clips", path.TrimStart('\\').TrimStart('/')); - - await _hostService.CreateDirectoryIfNotExists(path); - } - } - private async Task GetPath(TwitchClipModel clip) { var path = await _hostService.ConvertCustomPathExpressionToSavePath(clip); diff --git a/Services/HostService.cs b/Services/HostService.cs index 28796ed..e0a7801 100644 --- a/Services/HostService.cs +++ b/Services/HostService.cs @@ -98,25 +98,6 @@ public async Task ConvertCustomPathExpressionToSavePath(TwitchClipModel await ErrorHelper.LogAndExit("Your custom path does not end with .mp4. Check https://github.com/mortenmoulder/TwitchClipper/wiki/Custom-save-expressions#requirements"); } - var replace = path - .Replace("{id", "{0") - .Replace("{broadcaster_name", "{1") - .Replace("{broadcaster_id", "{2") - .Replace("{game_id", "{3") - .Replace("{title", "{4") - .Replace("{yyyy", "{5:yyyy").Replace("{yyy", "{5:yyy").Replace("{yy", "{5:yy").Replace("{y", "{5:%y") - .Replace("{MMMM", "{5:MMMM").Replace("{MMM", "{5:MMM").Replace("{MM", "{5:MM").Replace("{M", "{5:%M") - .Replace("{dddd", "{5:dddd").Replace("{ddd", "{5:ddd").Replace("{dd", "{5:dd").Replace("{d", "{5:%d") - .Replace("{HH", "{5:HH").Replace("{H", "{5:%H").Replace("{hh", "{5:hh") - .Replace("{mm", "{5:mm").Replace("{m", "{5:%m") - .Replace("{ss", "{5:ss").Replace("{s", "{5:%s") - .Replace("{tt", "{5:tt").Replace("{t", "{5:t") - .Replace("{viewcount", "{6") - .Replace("{uploader", "{7") - ; - - path = string.Format(culture, replace, model.Id, model.BroadcasterName, model.BroadcasterId, model.GameId, model.Title, model.CreatedAt, model.ViewCount, model.CreatorName); - if (await GetOSPlatform() == OSPlatform.Windows) { illegalCharacters = new List() @@ -136,6 +117,25 @@ public async Task ConvertCustomPathExpressionToSavePath(TwitchClipModel path = path.Replace(@"\", "/"); } + var replace = path + .Replace("{id", "{0") + .Replace("{broadcaster_name", "{1") + .Replace("{broadcaster_id", "{2") + .Replace("{game_id", "{3") + .Replace("{title", "{4") + .Replace("{yyyy", "{5:yyyy").Replace("{yyy", "{5:yyy").Replace("{yy", "{5:yy").Replace("{y", "{5:%y") + .Replace("{MMMM", "{5:MMMM").Replace("{MMM", "{5:MMM").Replace("{MM", "{5:MM").Replace("{M", "{5:%M") + .Replace("{dddd", "{5:dddd").Replace("{ddd", "{5:ddd").Replace("{dd", "{5:dd").Replace("{d", "{5:%d") + .Replace("{HH", "{5:HH").Replace("{H", "{5:%H").Replace("{hh", "{5:hh") + .Replace("{mm", "{5:mm").Replace("{m", "{5:%m") + .Replace("{ss", "{5:ss").Replace("{s", "{5:%s") + .Replace("{tt", "{5:tt").Replace("{t", "{5:t") + .Replace("{viewcount", "{6") + .Replace("{uploader", "{7") + ; + + path = string.Format(culture, replace, model.Id, model.BroadcasterName, model.BroadcasterId, model.GameId, model.Title, model.CreatedAt, model.ViewCount, model.CreatorName); + foreach (var character in illegalCharacters) { path = path.Replace(character, ""); diff --git a/Services/TwitchAPIService.cs b/Services/TwitchAPIService.cs index c8bab96..31ba859 100644 --- a/Services/TwitchAPIService.cs +++ b/Services/TwitchAPIService.cs @@ -126,7 +126,7 @@ await ParallelExtensions.ParallelForEachAsync(dates, async date => LogHelper.Index += 1; - return clips; + return clips.Where(x => x is not null).ToList(); } /// diff --git a/TwitchClipper.csproj b/TwitchClipper.csproj index a70123f..b22de1c 100644 --- a/TwitchClipper.csproj +++ b/TwitchClipper.csproj @@ -11,7 +11,7 @@ mortenmoulder https://github.com/mortenmoulder/TwitchClipper https://github.com/mortenmoulder/TwitchClipper - 1.0.10 + 1.0.12