Skip to content

Commit

Permalink
调整部分代码结构
Browse files Browse the repository at this point in the history
  • Loading branch information
nilaoda committed Nov 10, 2024
1 parent 7d8e7c6 commit b9d3b57
Show file tree
Hide file tree
Showing 88 changed files with 8,087 additions and 8,469 deletions.
53 changes: 26 additions & 27 deletions src/N_m3u8DL-RE.Common/Entity/EncryptInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,38 @@
using System.Text;
using System.Threading.Tasks;

namespace N_m3u8DL_RE.Common.Entity
namespace N_m3u8DL_RE.Common.Entity;

public class EncryptInfo
{
public class EncryptInfo
{
/// <summary>
/// 加密方式,默认无加密
/// </summary>
public EncryptMethod Method { get; set; } = EncryptMethod.NONE;
/// <summary>
/// 加密方式,默认无加密
/// </summary>
public EncryptMethod Method { get; set; } = EncryptMethod.NONE;

public byte[]? Key { get; set; }
public byte[]? IV { get; set; }
public byte[]? Key { get; set; }
public byte[]? IV { get; set; }

public EncryptInfo() { }
public EncryptInfo() { }

/// <summary>
/// 创建EncryptInfo并尝试自动解析Method
/// </summary>
/// <param name="method"></param>
public EncryptInfo(string method)
/// <summary>
/// 创建EncryptInfo并尝试自动解析Method
/// </summary>
/// <param name="method"></param>
public EncryptInfo(string method)
{
Method = ParseMethod(method);
}

public static EncryptMethod ParseMethod(string? method)
{
if (method != null && System.Enum.TryParse(method.Replace("-", "_"), out EncryptMethod m))
{
Method = ParseMethod(method);
return m;
}

public static EncryptMethod ParseMethod(string? method)
else
{
if (method != null && System.Enum.TryParse(method.Replace("-", "_"), out EncryptMethod m))
{
return m;
}
else
{
return EncryptMethod.UNKNOWN;
}
return EncryptMethod.UNKNOWN;
}
}
}
}
37 changes: 15 additions & 22 deletions src/N_m3u8DL-RE.Common/Entity/MSSData.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace N_m3u8DL_RE.Common.Entity;

namespace N_m3u8DL_RE.Common.Entity
public class MSSData
{
public class MSSData
{
public string FourCC { get; set; } = "";
public string CodecPrivateData { get; set; } = "";
public string Type { get; set; } = "";
public int Timesacle { get; set; }
public int SamplingRate { get; set; }
public int Channels { get; set; }
public int BitsPerSample { get; set; }
public int NalUnitLengthField { get; set; }
public long Duration { get; set; }
public string FourCC { get; set; } = "";
public string CodecPrivateData { get; set; } = "";
public string Type { get; set; } = "";
public int Timesacle { get; set; }
public int SamplingRate { get; set; }
public int Channels { get; set; }
public int BitsPerSample { get; set; }
public int NalUnitLengthField { get; set; }
public long Duration { get; set; }

public bool IsProtection { get; set; } = false;
public string ProtectionSystemID { get; set; } = "";
public string ProtectionData { get; set; } = "";
}
}
public bool IsProtection { get; set; } = false;
public string ProtectionSystemID { get; set; } = "";
public string ProtectionData { get; set; } = "";
}
17 changes: 5 additions & 12 deletions src/N_m3u8DL-RE.Common/Entity/MediaPart.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace N_m3u8DL_RE.Common.Entity;

namespace N_m3u8DL_RE.Common.Entity
// 主要处理 EXT-X-DISCONTINUITY
public class MediaPart
{
//主要处理 EXT-X-DISCONTINUITY
public class MediaPart
{
public List<MediaSegment> MediaSegments { get; set; } = new List<MediaSegment>();
}
}
public List<MediaSegment> MediaSegments { get; set; } = new List<MediaSegment>();
}
61 changes: 27 additions & 34 deletions src/N_m3u8DL-RE.Common/Entity/MediaSegment.cs
Original file line number Diff line number Diff line change
@@ -1,43 +1,36 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace N_m3u8DL_RE.Common.Entity;

namespace N_m3u8DL_RE.Common.Entity
public class MediaSegment
{
public class MediaSegment
{
public long Index { get; set; }
public double Duration { get; set; }
public string? Title { get; set; }
public DateTime? DateTime { get; set; }
public long Index { get; set; }
public double Duration { get; set; }
public string? Title { get; set; }
public DateTime? DateTime { get; set; }

public long? StartRange { get; set; }
public long? StopRange { get => (StartRange != null && ExpectLength != null) ? StartRange + ExpectLength - 1 : null; }
public long? ExpectLength { get; set; }
public long? StartRange { get; set; }
public long? StopRange => (StartRange != null && ExpectLength != null) ? StartRange + ExpectLength - 1 : null;
public long? ExpectLength { get; set; }

public EncryptInfo EncryptInfo { get; set; } = new EncryptInfo();
public EncryptInfo EncryptInfo { get; set; } = new EncryptInfo();

public string Url { get; set; }
public string Url { get; set; }

Check warning on line 16 in src/N_m3u8DL-RE.Common/Entity/MediaSegment.cs

View workflow job for this annotation

GitHub Actions / build-linux-x64

Non-nullable property 'Url' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 16 in src/N_m3u8DL-RE.Common/Entity/MediaSegment.cs

View workflow job for this annotation

GitHub Actions / build-linux-arm64

Non-nullable property 'Url' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 16 in src/N_m3u8DL-RE.Common/Entity/MediaSegment.cs

View workflow job for this annotation

GitHub Actions / build-win-x64-arm64

Non-nullable property 'Url' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 16 in src/N_m3u8DL-RE.Common/Entity/MediaSegment.cs

View workflow job for this annotation

GitHub Actions / build-mac-x64-arm64

Non-nullable property 'Url' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

public string? NameFromVar { get; set; } //MPD分段文件名
public string? NameFromVar { get; set; } // MPD分段文件名

public override bool Equals(object? obj)
{
return obj is MediaSegment segment &&
Index == segment.Index &&
Duration == segment.Duration &&
Title == segment.Title &&
StartRange == segment.StartRange &&
StopRange == segment.StopRange &&
ExpectLength == segment.ExpectLength &&
Url == segment.Url;
}
public override bool Equals(object? obj)
{
return obj is MediaSegment segment &&
Index == segment.Index &&
Math.Abs(Duration - segment.Duration) < 0.001 &&
Title == segment.Title &&
StartRange == segment.StartRange &&
StopRange == segment.StopRange &&
ExpectLength == segment.ExpectLength &&
Url == segment.Url;
}

public override int GetHashCode()
{
return HashCode.Combine(Index, Duration, Title, StartRange, StopRange, ExpectLength, Url);
}
public override int GetHashCode()
{
return HashCode.Combine(Index, Duration, Title, StartRange, StopRange, ExpectLength, Url);
}
}
}
42 changes: 17 additions & 25 deletions src/N_m3u8DL-RE.Common/Entity/Playlist.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,19 @@
using N_m3u8DL_RE.Common.Enum;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace N_m3u8DL_RE.Common.Entity;

namespace N_m3u8DL_RE.Common.Entity
public class Playlist
{
public class Playlist
{
//对应Url信息
public string Url { get; set; }
//是否直播
public bool IsLive { get; set; } = false;
//直播刷新间隔毫秒(默认15秒)
public double RefreshIntervalMs { get; set; } = 15000;
//所有分片时长总和
public double TotalDuration { get => MediaParts.Sum(x => x.MediaSegments.Sum(m => m.Duration)); }
//所有分片中最长时长
public double? TargetDuration { get; set; }
//INIT信息
public MediaSegment? MediaInit { get; set; }
//分片信息
public List<MediaPart> MediaParts { get; set; } = new List<MediaPart>();
}
}
// 对应Url信息
public string Url { get; set; }

Check warning on line 6 in src/N_m3u8DL-RE.Common/Entity/Playlist.cs

View workflow job for this annotation

GitHub Actions / build-linux-x64

Non-nullable property 'Url' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 6 in src/N_m3u8DL-RE.Common/Entity/Playlist.cs

View workflow job for this annotation

GitHub Actions / build-linux-arm64

Non-nullable property 'Url' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 6 in src/N_m3u8DL-RE.Common/Entity/Playlist.cs

View workflow job for this annotation

GitHub Actions / build-win-x64-arm64

Non-nullable property 'Url' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 6 in src/N_m3u8DL-RE.Common/Entity/Playlist.cs

View workflow job for this annotation

GitHub Actions / build-mac-x64-arm64

Non-nullable property 'Url' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
// 是否直播
public bool IsLive { get; set; } = false;
// 直播刷新间隔毫秒(默认15秒)
public double RefreshIntervalMs { get; set; } = 15000;
// 所有分片时长总和
public double TotalDuration { get => MediaParts.Sum(x => x.MediaSegments.Sum(m => m.Duration)); }
// 所有分片中最长时长
public double? TargetDuration { get; set; }
// INIT信息
public MediaSegment? MediaInit { get; set; }
// 分片信息
public List<MediaPart> MediaParts { get; set; } = new List<MediaPart>();
}
Loading

0 comments on commit b9d3b57

Please sign in to comment.