1.0-dev8 (Video panel and videos list added)
This commit is contained in:
@@ -1,8 +0,0 @@
|
||||
namespace VDownload.Core.Enums
|
||||
{
|
||||
public enum DefaultLocationType
|
||||
{
|
||||
Last,
|
||||
Selected
|
||||
}
|
||||
}
|
||||
9
VDownload.Core/Enums/VideoStatus.cs
Normal file
9
VDownload.Core/Enums/VideoStatus.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace VDownload.Core.Enums
|
||||
{
|
||||
public enum VideoStatus
|
||||
{
|
||||
Idle,
|
||||
Waiting,
|
||||
InProgress
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,11 @@ namespace VDownload.Core.Services
|
||||
{ "default_filename", "[<date_pub:yyyy.MM.dd>] <title>" },
|
||||
{ "default_video_extension", (int)VideoFileExtension.MP4 },
|
||||
{ "default_audio_extension", (int)AudioFileExtension.MP3 },
|
||||
{ "default_location_type", (int)DefaultLocationType.Last },
|
||||
{ "custom_media_location", false },
|
||||
{ "custom_temp_location", false },
|
||||
{ "max_active_video_task", 5 },
|
||||
{ "replace_output_file_if_exists", false },
|
||||
{ "remove_task_when_successfully_ended", false }
|
||||
};
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -48,8 +48,8 @@ namespace VDownload.Core.Services
|
||||
// Init transcoder
|
||||
MediaTranscoder mediaTranscoder = new MediaTranscoder
|
||||
{
|
||||
HardwareAccelerationEnabled = (bool)Config.GetValue("media_processor_use_hardware_acceleration"),
|
||||
VideoProcessingAlgorithm = (bool)Config.GetValue("media_processor_use_mrfcrf444_algorithm") ? MediaVideoProcessingAlgorithm.MrfCrf444 : MediaVideoProcessingAlgorithm.Default,
|
||||
HardwareAccelerationEnabled = (bool)Config.GetValue("media_transcoding_use_hardware_acceleration"),
|
||||
VideoProcessingAlgorithm = (bool)Config.GetValue("media_transcoding_use_mrfcrf444_algorithm") ? MediaVideoProcessingAlgorithm.MrfCrf444 : MediaVideoProcessingAlgorithm.Default,
|
||||
TrimStartTime = TrimStart,
|
||||
TrimStopTime = TrimEnd,
|
||||
};
|
||||
|
||||
@@ -153,47 +153,57 @@ namespace VDownload.Core.Services.Sources.Twitch
|
||||
// DOWNLOAD AND TRANSCODE VOD
|
||||
public async Task<StorageFile> DownloadAndTranscodeAsync(StorageFolder downloadingFolder, Stream audioVideoStream, MediaFileExtension extension, MediaType mediaType, TimeSpan trimStart, TimeSpan trimEnd, CancellationToken cancellationToken = default)
|
||||
{
|
||||
// Set cancellation token
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
// Invoke DownloadingStarted event
|
||||
DownloadingStarted?.Invoke(this, EventArgs.Empty);
|
||||
if (!cancellationToken.IsCancellationRequested) DownloadingStarted?.Invoke(this, EventArgs.Empty);
|
||||
|
||||
// Get video chunks
|
||||
List<(Uri ChunkUrl, TimeSpan ChunkDuration)> chunksList = await ExtractChunksFromM3U8Async(audioVideoStream.Url);
|
||||
List<(Uri ChunkUrl, TimeSpan ChunkDuration)> chunksList = null;
|
||||
if (!cancellationToken.IsCancellationRequested) chunksList = await ExtractChunksFromM3U8Async(audioVideoStream.Url);
|
||||
|
||||
// Passive trim
|
||||
if ((bool)Config.GetValue("twitch_vod_passive_trim")) (trimStart, trimEnd) = PassiveVideoTrim(chunksList, trimStart, trimEnd, Duration);
|
||||
|
||||
// Download
|
||||
StorageFile rawFile = await downloadingFolder.CreateFileAsync("raw.ts");
|
||||
float chunksDownloaded = 0;
|
||||
|
||||
Task<byte[]> downloadTask;
|
||||
Task writeTask;
|
||||
|
||||
downloadTask = DownloadChunkAsync(chunksList[0].ChunkUrl);
|
||||
await downloadTask;
|
||||
for (int i = 1; i < chunksList.Count; i++)
|
||||
StorageFile rawFile = null;
|
||||
if (!cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
writeTask = WriteChunkToFileAsync(rawFile, downloadTask.Result);
|
||||
downloadTask = DownloadChunkAsync(chunksList[i].ChunkUrl);
|
||||
await Task.WhenAll(writeTask, downloadTask);
|
||||
DownloadingProgressChanged(this, new ProgressChangedEventArgs((int)Math.Round(++chunksDownloaded * 100 / chunksList.Count), null));
|
||||
}
|
||||
await WriteChunkToFileAsync(rawFile, downloadTask.Result);
|
||||
DownloadingProgressChanged(this, new ProgressChangedEventArgs((int)Math.Round(++chunksDownloaded * 100 / chunksList.Count), null));
|
||||
rawFile = await downloadingFolder.CreateFileAsync("raw.ts");
|
||||
float chunksDownloaded = 0;
|
||||
|
||||
Task<byte[]> downloadTask;
|
||||
Task writeTask;
|
||||
|
||||
downloadTask = DownloadChunkAsync(chunksList[0].ChunkUrl);
|
||||
await downloadTask;
|
||||
for (int i = 1; i < chunksList.Count && !cancellationToken.IsCancellationRequested; i++)
|
||||
{
|
||||
writeTask = WriteChunkToFileAsync(rawFile, downloadTask.Result);
|
||||
downloadTask = DownloadChunkAsync(chunksList[i].ChunkUrl);
|
||||
await Task.WhenAll(writeTask, downloadTask);
|
||||
DownloadingProgressChanged(this, new ProgressChangedEventArgs((int)Math.Round(++chunksDownloaded * 100 / chunksList.Count), null));
|
||||
}
|
||||
if (!cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
await WriteChunkToFileAsync(rawFile, downloadTask.Result);
|
||||
DownloadingProgressChanged(this, new ProgressChangedEventArgs((int)Math.Round(++chunksDownloaded * 100 / chunksList.Count), null));
|
||||
|
||||
DownloadingCompleted?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
DownloadingCompleted?.Invoke(this, EventArgs.Empty);
|
||||
|
||||
// Processing
|
||||
StorageFile outputFile = await downloadingFolder.CreateFileAsync($"transcoded.{extension.ToString().ToLower()}");
|
||||
StorageFile outputFile = null;
|
||||
if (!cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
outputFile = await downloadingFolder.CreateFileAsync($"transcoded.{extension.ToString().ToLower()}");
|
||||
|
||||
MediaProcessor mediaProcessor = new MediaProcessor(outputFile, trimStart, trimEnd);
|
||||
mediaProcessor.ProcessingStarted += ProcessingStarted;
|
||||
mediaProcessor.ProcessingProgressChanged += ProcessingProgressChanged;
|
||||
mediaProcessor.ProcessingCompleted += ProcessingCompleted;
|
||||
await mediaProcessor.Run(rawFile, extension, mediaType, cancellationToken);
|
||||
MediaProcessor mediaProcessor = new MediaProcessor(outputFile, trimStart, trimEnd);
|
||||
mediaProcessor.ProcessingStarted += ProcessingStarted;
|
||||
mediaProcessor.ProcessingProgressChanged += ProcessingProgressChanged;
|
||||
mediaProcessor.ProcessingCompleted += ProcessingCompleted;
|
||||
await mediaProcessor.Run(rawFile, extension, mediaType, cancellationToken);
|
||||
}
|
||||
|
||||
// Return output file
|
||||
return outputFile;
|
||||
@@ -298,7 +308,7 @@ namespace VDownload.Core.Services.Sources.Twitch
|
||||
});
|
||||
}
|
||||
|
||||
// PARSE DURATION TO SECONDS
|
||||
// PARSE DURATION
|
||||
private static TimeSpan ParseDuration(string duration)
|
||||
{
|
||||
char[] separators = { 'h', 'm', 's' };
|
||||
@@ -319,15 +329,10 @@ namespace VDownload.Core.Services.Sources.Twitch
|
||||
#region EVENT HANDLERS
|
||||
|
||||
public event EventHandler DownloadingStarted;
|
||||
|
||||
public event EventHandler<ProgressChangedEventArgs> DownloadingProgressChanged;
|
||||
|
||||
public event EventHandler DownloadingCompleted;
|
||||
|
||||
public event EventHandler ProcessingStarted;
|
||||
|
||||
public event EventHandler<ProgressChangedEventArgs> ProcessingProgressChanged;
|
||||
|
||||
public event EventHandler ProcessingCompleted;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -121,13 +121,13 @@
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Enums\AudioFileExtension.cs" />
|
||||
<Compile Include="Enums\DefaultLocationType.cs" />
|
||||
<Compile Include="Enums\MediaFileExtension.cs" />
|
||||
<Compile Include="Enums\MediaType.cs" />
|
||||
<Compile Include="Enums\PlaylistSource.cs" />
|
||||
<Compile Include="Enums\StreamType.cs" />
|
||||
<Compile Include="Enums\VideoFileExtension.cs" />
|
||||
<Compile Include="Enums\VideoSource.cs" />
|
||||
<Compile Include="Enums\VideoStatus.cs" />
|
||||
<Compile Include="EventArgsObjects\VideoAddEventArgs.cs" />
|
||||
<Compile Include="EventArgsObjects\VideoSearchEventArgs.cs" />
|
||||
<Compile Include="EventArgsObjects\PlaylistSearchEventArgs.cs" />
|
||||
|
||||
Reference in New Issue
Block a user