Skip to content

Commit 169f6d0

Browse files
committed
Remove illegal chars before applying custom save expression
1 parent 537fece commit 169f6d0

File tree

4 files changed

+22
-40
lines changed

4 files changed

+22
-40
lines changed

Services/DownloaderService.cs

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,6 @@ public async Task CheckExecutableExists()
9292

9393
public async Task DownloadClips(List<TwitchClipModel> clips)
9494
{
95-
await CreateAllDirectoriesRequired(clips);
96-
9795
var root = Directory.GetCurrentDirectory();
9896
var username = clips.First().BroadcasterName;
9997

@@ -112,30 +110,14 @@ await ParallelExtensions.ParallelForEachAsync(clips, async clip =>
112110
if (!File.Exists(path))
113111
{
114112
counter++;
115-
await ProcessEx.RunAsync(await _hostService.GetDownloaderExecutablePath(), $"{clip.Url} -o \"{path}\"");
113+
await ProcessEx.RunAsync(await _hostService.GetDownloaderExecutablePath(), $"{clip.Url} --restrict-filenames --windows-filenames -o \"{path}\"");
116114
await LogHelper.Log($"Downloading clip {counter}/{nonExistingClips.Count} using {await _twitchConfigurationService.GetDownloadThreads()} download threads", asyncLock);
117115
}
118116
}, await _twitchConfigurationService.GetDownloadThreads());
119117

120118
LogHelper.Index += 1;
121119
}
122120

123-
private async Task CreateAllDirectoriesRequired(List<TwitchClipModel> clips)
124-
{
125-
await LogHelper.Log("Creating directories. This might take a while.");
126-
127-
foreach (var clip in clips)
128-
{
129-
var savePath = await _hostService.ConvertCustomPathExpressionToSavePath(clip);
130-
var path = savePath.Replace(Path.GetFileName(savePath), "");
131-
path = path.TrimEnd('\\').TrimEnd('/');
132-
133-
path = Path.Combine(Directory.GetCurrentDirectory().TrimEnd('\\').TrimEnd('/'), "clips", path.TrimStart('\\').TrimStart('/'));
134-
135-
await _hostService.CreateDirectoryIfNotExists(path);
136-
}
137-
}
138-
139121
private async Task<string> GetPath(TwitchClipModel clip)
140122
{
141123
var path = await _hostService.ConvertCustomPathExpressionToSavePath(clip);

Services/HostService.cs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -98,25 +98,6 @@ public async Task<string> ConvertCustomPathExpressionToSavePath(TwitchClipModel
9898
await ErrorHelper.LogAndExit("Your custom path does not end with .mp4. Check https://github.com/mortenmoulder/TwitchClipper/wiki/Custom-save-expressions#requirements");
9999
}
100100

101-
var replace = path
102-
.Replace("{id", "{0")
103-
.Replace("{broadcaster_name", "{1")
104-
.Replace("{broadcaster_id", "{2")
105-
.Replace("{game_id", "{3")
106-
.Replace("{title", "{4")
107-
.Replace("{yyyy", "{5:yyyy").Replace("{yyy", "{5:yyy").Replace("{yy", "{5:yy").Replace("{y", "{5:%y")
108-
.Replace("{MMMM", "{5:MMMM").Replace("{MMM", "{5:MMM").Replace("{MM", "{5:MM").Replace("{M", "{5:%M")
109-
.Replace("{dddd", "{5:dddd").Replace("{ddd", "{5:ddd").Replace("{dd", "{5:dd").Replace("{d", "{5:%d")
110-
.Replace("{HH", "{5:HH").Replace("{H", "{5:%H").Replace("{hh", "{5:hh")
111-
.Replace("{mm", "{5:mm").Replace("{m", "{5:%m")
112-
.Replace("{ss", "{5:ss").Replace("{s", "{5:%s")
113-
.Replace("{tt", "{5:tt").Replace("{t", "{5:t")
114-
.Replace("{viewcount", "{6")
115-
.Replace("{uploader", "{7")
116-
;
117-
118-
path = string.Format(culture, replace, model.Id, model.BroadcasterName, model.BroadcasterId, model.GameId, model.Title, model.CreatedAt, model.ViewCount, model.CreatorName);
119-
120101
if (await GetOSPlatform() == OSPlatform.Windows)
121102
{
122103
illegalCharacters = new List<string>()
@@ -136,6 +117,25 @@ public async Task<string> ConvertCustomPathExpressionToSavePath(TwitchClipModel
136117
path = path.Replace(@"\", "/");
137118
}
138119

120+
var replace = path
121+
.Replace("{id", "{0")
122+
.Replace("{broadcaster_name", "{1")
123+
.Replace("{broadcaster_id", "{2")
124+
.Replace("{game_id", "{3")
125+
.Replace("{title", "{4")
126+
.Replace("{yyyy", "{5:yyyy").Replace("{yyy", "{5:yyy").Replace("{yy", "{5:yy").Replace("{y", "{5:%y")
127+
.Replace("{MMMM", "{5:MMMM").Replace("{MMM", "{5:MMM").Replace("{MM", "{5:MM").Replace("{M", "{5:%M")
128+
.Replace("{dddd", "{5:dddd").Replace("{ddd", "{5:ddd").Replace("{dd", "{5:dd").Replace("{d", "{5:%d")
129+
.Replace("{HH", "{5:HH").Replace("{H", "{5:%H").Replace("{hh", "{5:hh")
130+
.Replace("{mm", "{5:mm").Replace("{m", "{5:%m")
131+
.Replace("{ss", "{5:ss").Replace("{s", "{5:%s")
132+
.Replace("{tt", "{5:tt").Replace("{t", "{5:t")
133+
.Replace("{viewcount", "{6")
134+
.Replace("{uploader", "{7")
135+
;
136+
137+
path = string.Format(culture, replace, model.Id, model.BroadcasterName, model.BroadcasterId, model.GameId, model.Title, model.CreatedAt, model.ViewCount, model.CreatorName);
138+
139139
foreach (var character in illegalCharacters)
140140
{
141141
path = path.Replace(character, "");

Services/TwitchAPIService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ await ParallelExtensions.ParallelForEachAsync(dates, async date =>
126126

127127
LogHelper.Index += 1;
128128

129-
return clips;
129+
return clips.Where(x => x is not null).ToList();
130130
}
131131

132132
/// <summary>

TwitchClipper.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<Authors>mortenmoulder</Authors>
1212
<PackageProjectUrl>https://github.com/mortenmoulder/TwitchClipper</PackageProjectUrl>
1313
<RepositoryUrl>https://github.com/mortenmoulder/TwitchClipper</RepositoryUrl>
14-
<Version>1.0.10</Version>
14+
<Version>1.0.12</Version>
1515
</PropertyGroup>
1616

1717
<ItemGroup>

0 commit comments

Comments
 (0)