Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CLI][videodownload] Add options -k and -K to keep cache folder #983

Closed
wants to merge 64 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
c603097
#tsmerge Update README.md
superbonaci Oct 28, 2023
baf2271
#tsmerge Update Program.cs
superbonaci Oct 28, 2023
9fc7c74
#tsmerge Add MergeTS.cs
superbonaci Oct 28, 2023
fefe961
#tsmerge Add TsMergeArgs.cs
superbonaci Oct 28, 2023
0a00e81
#tsmerge Add TsMerger.cs
superbonaci Oct 28, 2023
550c265
#tsmerge Add TsMergeOptions.cs
superbonaci Oct 28, 2023
0946fcc
Update Program.cs
superbonaci Oct 28, 2023
638d5b1
#tsmerge Update README.md
superbonaci Oct 28, 2023
36cc340
Program.cs Remove newline at the end
superbonaci Oct 28, 2023
8fb6a4d
Delete TwitchDownloaderCLI/Program.cs
superbonaci Oct 28, 2023
68d686b
Try to upload again Program.cs
superbonaci Oct 28, 2023
b1d48b1
Merge pull request #1 from lay295/master
superbonaci Nov 5, 2023
a69c641
Merge pull request #2 from lay295/master
superbonaci Nov 9, 2023
37a2e14
Merge pull request #3 from lay295/master
superbonaci Nov 12, 2023
32e6b0d
Delete TwitchDownloaderCLI/README.md
superbonaci Nov 12, 2023
a192207
Add files via upload
superbonaci Nov 12, 2023
7a41051
Delete TwitchDownloaderCLI/Program.cs
superbonaci Nov 12, 2023
b71b6b8
Add files via upload
superbonaci Nov 12, 2023
b9bfa63
Delete TwitchDownloaderCore/TsMerger.cs
superbonaci Nov 12, 2023
84172c6
Add files via upload
superbonaci Nov 12, 2023
286f71c
Delete TwitchDownloaderCLI/Modes/Arguments/TsMergeArgs.cs
superbonaci Nov 12, 2023
e155335
Add files via upload
superbonaci Nov 12, 2023
8288281
Delete TwitchDownloaderCLI/Modes/Arguments/TsMergeArgs.cs
superbonaci Nov 12, 2023
f8fbf31
Add files via upload
superbonaci Nov 12, 2023
ee02787
Delete TwitchDownloaderCore/TsMerger.cs
superbonaci Nov 12, 2023
393e3c0
Add files via upload
superbonaci Nov 12, 2023
00a7d4d
Delete TwitchDownloaderCLI/Modes/Arguments/TsMergeArgs.cs
superbonaci Nov 12, 2023
81ecdbe
Add files via upload
superbonaci Nov 12, 2023
abe5b40
Delete TwitchDownloaderCore/TsMergeArgs.cs
superbonaci Nov 12, 2023
4c72064
Add files via upload
superbonaci Nov 12, 2023
60b3491
Delete TwitchDownloaderCLI/README.md
superbonaci Nov 12, 2023
263dff8
Add files via upload
superbonaci Nov 12, 2023
b1d95af
Merge pull request #4 from lay295/master
superbonaci Nov 16, 2023
b3f7bea
Merge pull request #5 from lay295/master
superbonaci Nov 18, 2023
92dcb03
Merge pull request #6 from lay295/master
superbonaci Nov 21, 2023
47022d7
Merge pull request #7 from lay295/master
superbonaci Nov 23, 2023
4d9f801
Merge pull request #8 from lay295/master
superbonaci Nov 28, 2023
10fd997
Merge pull request #9 from lay295/master
superbonaci Nov 29, 2023
2dc7026
Merge pull request #10 from lay295/master
superbonaci Nov 30, 2023
b7fe2a7
Merge pull request #11 from lay295/master
superbonaci Dec 1, 2023
4aa7309
Merge pull request #12 from lay295/master
superbonaci Dec 2, 2023
2e1a47d
Merge pull request #13 from lay295/master
superbonaci Dec 9, 2023
3dbebb9
Merge pull request #14 from lay295/master
superbonaci Dec 14, 2023
ba343bd
Merge pull request #15 from lay295/master
superbonaci Dec 15, 2023
a6ef5ee
Merge pull request #16 from lay295/master
superbonaci Dec 19, 2023
14b0728
Merge pull request #17 from lay295/master
superbonaci Dec 31, 2023
5f40948
Merge pull request #18 from lay295/master
superbonaci Jan 22, 2024
a3134c9
Cleanup code and fix Readme entry
ScrubN Jan 23, 2024
592f28f
Merge pull request #19 from lay295/master
superbonaci Jan 23, 2024
a4b4b5c
Merge pull request #20 from lay295/master
superbonaci Jan 30, 2024
5a7fb47
Merge pull request #21 from lay295/master
superbonaci Feb 2, 2024
4d607b3
Merge pull request #22 from lay295/master
superbonaci Feb 5, 2024
a11aa5b
Merge pull request #23 from lay295/master
superbonaci Feb 7, 2024
719e3e4
Merge pull request #24 from lay295/master
superbonaci Feb 13, 2024
98a3771
Cleanup
ScrubN Feb 25, 2024
9ca212e
Merge pull request #25 from lay295/master
superbonaci Feb 26, 2024
f66a0fe
Update VideoDownloadArgs.cs
superbonaci Mar 7, 2024
218cba1
Update VideoDownloadOptions.cs
superbonaci Mar 7, 2024
65a43fc
Update DownloadVideo.cs
superbonaci Mar 7, 2024
74aa5ef
Update VideoDownloader.cs
superbonaci Mar 7, 2024
b10852b
Update VideoDownloader.cs
superbonaci Mar 7, 2024
6264319
Update README.md
superbonaci Mar 7, 2024
ce29cf6
Update VideoDownloadArgs.cs
superbonaci Mar 7, 2024
7ae56f0
Update VideoDownloader.cs
superbonaci Mar 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion TwitchDownloaderCLI/Modes/Arguments/VideoDownloadArgs.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using CommandLine;
using CommandLine;

namespace TwitchDownloaderCLI.Modes.Arguments
{
Expand All @@ -14,6 +14,12 @@ public class VideoDownloadArgs : ITwitchDownloaderArgs
[Option('q', "quality", HelpText = "The quality the program will attempt to download.")]
public string Quality { get; set; }

[Option('K', "keepcache", Required = false, HelpText = "Keep entire cache folder. Overrides \"-k\".")]
public bool KeepCache { get; set; }

[Option('k', "keepcachenoparts", Required = false, HelpText = "Keep cache folder except .ts parts.")]
public bool KeepCacheNoParts { get; set; }

[Option('b', "beginning", HelpText = "Time in seconds to crop beginning.")]
public int CropBeginningTime { get; set; }

Expand Down
6 changes: 4 additions & 2 deletions TwitchDownloaderCLI/Modes/DownloadVideo.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.IO;
using System.Threading;
using TwitchDownloaderCLI.Modes.Arguments;
Expand Down Expand Up @@ -70,6 +70,8 @@ private static VideoDownloadOptions GetDownloadOptions(VideoDownloadArgs inputOp
".m4a" => "Audio",
_ => throw new ArgumentException("Only MP4 and M4A audio files are supported.")
},
KeepCache = inputOptions.KeepCache,
KeepCacheNoParts = inputOptions.KeepCacheNoParts,
CropBeginning = inputOptions.CropBeginningTime > 0.0,
CropBeginningTime = inputOptions.CropBeginningTime,
CropEnding = inputOptions.CropEndingTime > 0.0,
Expand All @@ -81,4 +83,4 @@ private static VideoDownloadOptions GetDownloadOptions(VideoDownloadArgs inputOp
return downloadOptions;
}
}
}
}
8 changes: 7 additions & 1 deletion TwitchDownloaderCLI/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ File the program will output to. File extension will be used to determine downlo
**-q / --quality**
The quality the program will attempt to download, for example "1080p60", if not found will download highest quality stream.

**-K / --keepcache**
Keep entire cache folder. Overrides "-k".

**-k / --keepcachenoparts**
Keep cache folder except .ts parts.

**-b / --beginning**
Time in seconds to crop beginning. For example if I had a 10 second stream but only wanted the last 7 seconds of it I would use `-b 3` to skip the first 3 seconds.

Expand Down Expand Up @@ -435,4 +441,4 @@ For Linux users, ensure both `fontconfig` and `libfontconfig1` are installed. `a
Some distros, like Linux Alpine, lack fonts for some languages (Arabic, Persian, Thai, etc.) If this is the case for you, install additional fonts families such as [Noto](https://fonts.google.com/noto/specimen/Noto+Sans) or check your distro's wiki page on fonts as it may have an install command for this specific scenario, such as the [Linux Alpine](https://wiki.alpinelinux.org/wiki/Fonts) font page.

The list file for `tsmerge` may contain relative or absolute paths, with one path per line.
Alternatively, the list file may also be an M3U8 playlist file.
Alternatively, the list file may also be an M3U8 playlist file.
4 changes: 3 additions & 1 deletion TwitchDownloaderCore/Options/VideoDownloadOptions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.IO;

namespace TwitchDownloaderCore.Options
Expand All @@ -8,6 +8,8 @@ public class VideoDownloadOptions
public int Id { get; set; }
public string Quality { get; set; }
public string Filename { get; set; }
public bool KeepCache { get; set; }
public bool KeepCacheNoParts { get; set; }
public bool CropBeginning { get; set; }
public double CropBeginningTime { get; set; }
public bool CropEnding { get; set; }
Expand Down
13 changes: 9 additions & 4 deletions TwitchDownloaderCore/VideoDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public VideoDownloader(VideoDownloadOptions videoDownloadOptions, IProgress<Prog
string.IsNullOrWhiteSpace(downloadOptions.TempFolder) ? Path.GetTempPath() : downloadOptions.TempFolder,
"TwitchDownloader");
_progress = progress;

_shouldClearCache = !(downloadOptions.KeepCacheNoParts || downloadOptions.KeepCache);
}

public async Task DownloadAsync(CancellationToken cancellationToken)
Expand Down Expand Up @@ -669,11 +671,14 @@ private async Task CombineVideoParts(string downloadFolder, IEnumerable<M3U8.Str
await fs.CopyToAsync(outputStream, cancellationToken).ConfigureAwait(false);
}

try
if (!downloadOptions.KeepCache && downloadOptions.KeepCacheNoParts)
{
File.Delete(partFile);
try
{
File.Delete(partFile);
}
catch { /* If we can't delete, oh well. It could get cleanup up later anyways */ }
}
catch { /* If we can't delete, oh well. It should get cleanup up later anyways */ }
}

doneCount++;
Expand Down Expand Up @@ -709,4 +714,4 @@ private static void Cleanup(string downloadFolder)
catch (IOException) { } // Directory is probably being used by another process
}
}
}
}
Loading