Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Harlan-H committed May 13, 2024
2 parents d5c084d + 993ee22 commit 7e53968
Show file tree
Hide file tree
Showing 73 changed files with 1,244 additions and 804 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- master
- develop
tags:
- "*"

Expand All @@ -28,19 +29,20 @@ jobs:
- name: Publish
run: |
dotnet publish M3u8Downloader_H/ -o M3u8Downloader_H/bin/Publish --configuration Release
dotnet publish M3u8Downloader_H.PluginManager/ -o M3u8Downloader_H/bin/Publish --configuration Release
dotnet publish M3u8Downloader_H/ -o M3u8Downloader_H/bin/PublishSingleFile -c Release --self-contained true -r win7-x64 -p:PublishSingleFile=true
dotnet publish M3u8Downloader_H.PluginManager/ -o M3u8Downloader_H/bin/PublishSingleFile -c Release --self-contained true -r win7-x64 -p:PublishSingleFile=true
- name: Download .NET 6 SDK And Copy .NET 6 SDK
run: |
Invoke-WebRequest -Uri 'https://download.visualstudio.microsoft.com/download/pr/d0849e66-227d-40f7-8f7b-c3f7dfe51f43/37f8a04ab7ff94db7f20d3c598dc4d74/windowsdesktop-runtime-6.0.29-win-x64.exe' -OutFile 'dotnet-sdk-win-x64.exe'
Copy-Item dotnet-sdk-win-x64.exe M3u8Downloader_H/bin/Publish -Recurse
- name: Upload artifacts normal
if: ${{ github.event_name == 'push' && github.ref_type == 'tag' }}
uses: actions/upload-artifact@v3
with:
name: M3u8Downloader_H
path: M3u8Downloader_H/bin/Publish

- name: Upload artifacts single file
if: ${{ github.event_name == 'push' && github.ref_type == 'tag' }}
uses: actions/upload-artifact@v3
with:
name: M3u8Downloader_H-SingleFile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Threading;
using System.Threading.Tasks;

namespace M3u8Downloader_H.Core.Utils.Extensions
namespace M3u8Downloader_H.Combiners.Extensions
{
internal static class M3uFileInfoExtension
{
Expand Down
23 changes: 23 additions & 0 deletions M3u8Downloader_H.Combiners/M3u8Downloader_H.Combiners.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)'=='Release'">
<DebugSymbols>False</DebugSymbols>
<DebugType>None</DebugType>

</PropertyGroup>
<ItemGroup>
<PackageReference Include="CliWrap" Version="3.6.6" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\M3u8Downloader_H.Common\M3u8Downloader_H.Common.csproj" />
<ProjectReference Include="..\SettingsManager\M3u8Downloader_H.Settings.csproj" />
</ItemGroup>

</Project>
103 changes: 103 additions & 0 deletions M3u8Downloader_H.Combiners/M3uCombinerClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
using CliWrap.Builders;
using M3u8Downloader_H.Combiners.Extensions;
using M3u8Downloader_H.Combiners.Interfaces;
using M3u8Downloader_H.Combiners.M3uCombiners;
using M3u8Downloader_H.Common.Interfaces;
using M3u8Downloader_H.Common.M3u8Infos;
using M3u8Downloader_H.Core.VideoConverter;
using M3u8Downloader_H.Settings.Models;

namespace M3u8Downloader_H.Combiners
{
public class M3uCombinerClient
{
private readonly FFmpeg _ffmpeg;
private readonly M3UFileInfo _m3UFileInfo;

public ILog? Log { get; set; }
public IDownloadParams DownloadParams { get; set; } = default!;
public ISettings Settings { get; set; } = default!;

public M3uCombinerClient(M3UFileInfo M3UFileInfo)
{
#if DEBUG
_ffmpeg = new(@"F:\源代码\库\ffmpeg-4.3.1-2020-11-19-full_build-shared\bin\ffmpeg.exe");
#else
_ffmpeg = new("./ffmpeg.exe");
#endif
_m3UFileInfo = M3UFileInfo;
}

public async Task Converter(bool isFile, CancellationToken cancellationToken = default)
{
Log?.Info("开始合并视频流");
if (Settings.SelectedFormat == "mp4")
{
if (_m3UFileInfo.MediaFiles.Any(m => m.Duration > 0))
await ConvertWithM3u8File(cancellationToken);
else
await ConvertWithFile(isFile, cancellationToken);
}
else
{
await VideoMerge(isFile, cancellationToken);
}
Log?.Info("合并完成");
}

//通过xml,目录,json等方式可能无法判断流的时长,所以采用原先的转码方案
protected async ValueTask ConvertWithFile(bool isFile, CancellationToken cancellationToken)
{
await VideoMerge(isFile, cancellationToken);
await ConverterToMp4(DownloadParams.VideoFullName, false, cancellationToken);
File.Delete(DownloadParams.VideoFullName);
}

protected async ValueTask ConvertWithM3u8File(CancellationToken cancellationToken)
{
string m3u8FilePath = Path.Combine(DownloadParams.VideoFullPath, "generated.m3u8");
if (Settings.ForcedMerger)
_m3UFileInfo.MediaFiles = _m3UFileInfo.MediaFiles.Where(m => File.Exists(Path.Combine(DownloadParams.VideoFullPath, m.Title))).ToList();
await _m3UFileInfo.WriteToAsync(m3u8FilePath, cancellationToken);
await ConverterToMp4(m3u8FilePath, true, cancellationToken);
File.Delete(m3u8FilePath);
}

protected async ValueTask VideoMerge(bool isFile, CancellationToken cancellationToken = default)
{
using M3uCombiner m3UCombiner = isFile && _m3UFileInfo.Key is not null
? new CryptM3uCombiner(_m3UFileInfo, DownloadParams.VideoFullPath)
: new M3uCombiner(DownloadParams.VideoFullPath);

m3UCombiner.Progress = DownloadParams.VodProgress;
m3UCombiner.Initialization(DownloadParams.VideoFullName);
await m3UCombiner.MegerVideoHeader(_m3UFileInfo.Map, cancellationToken);
await m3UCombiner.Start(_m3UFileInfo, Settings.ForcedMerger, cancellationToken);
}

protected async ValueTask ConverterToMp4(string m3u8FilePath, bool allowed_extensions, CancellationToken cancellationToken = default)
{
var arguments = new ArgumentsBuilder();

if (allowed_extensions)
arguments.Add("-allowed_extensions").Add("ALL");

arguments.Add("-i").Add(m3u8FilePath);

arguments.Add("-f").Add(Settings.SelectedFormat);

arguments
.Add("-c:a").Add("copy")
.Add("-c:v").Add("copy");

var tmpOutputFile = Path.ChangeExtension(DownloadParams.VideoFullName, Settings.SelectedFormat);
DownloadParams.ChangeVideoNameDelegate(tmpOutputFile);
arguments
.Add("-nostdin")
.Add("-y").Add(tmpOutputFile);

await _ffmpeg.ExecuteAsync(arguments.Build(), DownloadParams.VodProgress, cancellationToken);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using M3u8Downloader_H.Common.Extensions;
using M3u8Downloader_H.Common.M3u8Infos;

namespace M3u8Downloader_H.Core.M3uCombiners
namespace M3u8Downloader_H.Combiners.M3uCombiners
{
internal class CryptM3uCombiner : M3uCombiner
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Threading.Tasks;
using M3u8Downloader_H.Common.M3u8Infos;

namespace M3u8Downloader_H.Core.M3uCombiners
namespace M3u8Downloader_H.Combiners.M3uCombiners
{
internal interface IM3uCombiner : IDisposable
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Threading.Tasks;
using M3u8Downloader_H.Common.M3u8Infos;

namespace M3u8Downloader_H.Core.M3uCombiners
namespace M3u8Downloader_H.Combiners.M3uCombiners
{
internal class M3uCombiner : IM3uCombiner
{
Expand Down
19 changes: 19 additions & 0 deletions M3u8Downloader_H.Common/Extensions/CancellationTokenExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace M3u8Downloader_H.Downloader.Utils.Extensions
{
internal static class CancellationTokenExtension
{
public static CancellationTokenSource CancelTimeOut(this CancellationToken cancellationToken,int timeout)
{
CancellationTokenSource cancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
cancellationTokenSource.CancelAfter(timeout);
return cancellationTokenSource;
}
}
}
18 changes: 18 additions & 0 deletions M3u8Downloader_H.Common/Interfaces/IDownloadParams.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using M3u8Downloader_H.Common.M3u8Infos;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace M3u8Downloader_H.Combiners.Interfaces
{
public interface IDownloadParams
{
string VideoFullPath { get; set; }
string VideoFullName { get; set; }
IProgress<double> VodProgress { get; set; }
IProgress<double> LiveProgress { get; set; }
Action<string> ChangeVideoNameDelegate { get; set; }
}
}
17 changes: 17 additions & 0 deletions M3u8Downloader_H.Common/Interfaces/ILog.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace M3u8Downloader_H.Common.Interfaces
{
public interface ILog
{
void Info(string format, params object[] args);

void Warn(string format, params object[] args);

void Error(Exception exception);
}
}
2 changes: 1 addition & 1 deletion M3u8Downloader_H.Common/M3u8Downloader_H.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Version>1.0.1.0</Version>
<Authors>Harlan</Authors>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)'=='Release'">
Expand Down
8 changes: 5 additions & 3 deletions M3u8Downloader_H.Common/M3u8Infos/M3UFileInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public partial class M3UFileInfo
//当原始的m3u8中的数据 不满足需求的时候 可以通过自定义的数据 进行操作
public object? UserData { get; set; }

public bool IsFile => MediaFiles.Any(m => m.Uri.IsFile);

public M3UFileInfo(M3UFileInfo m3UFileInfo)
{
Version = m3UFileInfo.Version;
Expand All @@ -43,10 +45,10 @@ public M3UFileInfo(M3UFileInfo m3UFileInfo)



public M3UFileInfo()
public M3UFileInfo()
{
}

}
}

public partial class M3UFileInfo
Expand Down
Loading

0 comments on commit 7e53968

Please sign in to comment.