Marked util classes as static (#460)

* Marked util classes as static

* Used file-scoped namespaces
This commit is contained in:
irodai-majom 2024-11-10 09:15:30 +01:00 committed by GitHub
parent 8a25815c1f
commit 9fc37d5b61
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
15 changed files with 1560 additions and 1588 deletions

View File

@ -8,10 +8,10 @@ using System.Text.Json;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace N_m3u8DL_RE.Common.Util namespace N_m3u8DL_RE.Common.Util;
public static class GlobalUtil
{ {
public class GlobalUtil
{
private static readonly JsonSerializerOptions Options = new JsonSerializerOptions private static readonly JsonSerializerOptions Options = new JsonSerializerOptions
{ {
Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping, Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
@ -76,5 +76,4 @@ namespace N_m3u8DL_RE.Common.Util
Array.Empty<string>(); Array.Empty<string>();
return searchPath.Concat(envPath).Select(p => Path.Combine(p, name + fileExt)).FirstOrDefault(File.Exists); return searchPath.Concat(envPath).Select(p => Path.Combine(p, name + fileExt)).FirstOrDefault(File.Exists);
} }
}
} }

View File

@ -3,10 +3,10 @@ using System.Net.Http.Headers;
using N_m3u8DL_RE.Common.Log; using N_m3u8DL_RE.Common.Log;
using N_m3u8DL_RE.Common.Resource; using N_m3u8DL_RE.Common.Resource;
namespace N_m3u8DL_RE.Common.Util namespace N_m3u8DL_RE.Common.Util;
public static class HTTPUtil
{ {
public class HTTPUtil
{
public static readonly HttpClientHandler HttpClientHandler = new() public static readonly HttpClientHandler HttpClientHandler = new()
{ {
AllowAutoRedirect = false, AllowAutoRedirect = false,
@ -137,5 +137,4 @@ namespace N_m3u8DL_RE.Common.Util
htmlCode = await webResponse.Content.ReadAsStringAsync(); htmlCode = await webResponse.Content.ReadAsStringAsync();
return htmlCode; return htmlCode;
} }
}
} }

View File

@ -1,13 +1,7 @@
using System; namespace N_m3u8DL_RE.Common.Util;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace N_m3u8DL_RE.Common.Util public static class HexUtil
{ {
public class HexUtil
{
public static string BytesToHex(byte[] data, string split = "") public static string BytesToHex(byte[] data, string split = "")
{ {
return BitConverter.ToString(data).Replace("-", split); return BitConverter.ToString(data).Replace("-", split);
@ -42,5 +36,4 @@ namespace N_m3u8DL_RE.Common.Util
return Convert.FromHexString(hexSpan); return Convert.FromHexString(hexSpan);
} }
}
} }

View File

@ -4,7 +4,7 @@ using Spectre.Console;
namespace N_m3u8DL_RE.Common.Util; namespace N_m3u8DL_RE.Common.Util;
public class RetryUtil public static class RetryUtil
{ {
public static async Task<T?> WebRequestRetryAsync<T>(Func<Task<T>> funcAsync, int maxRetries = 10, int retryDelayMilliseconds = 1500, int retryDelayIncrementMilliseconds = 0) public static async Task<T?> WebRequestRetryAsync<T>(Func<Task<T>> funcAsync, int maxRetries = 10, int retryDelayMilliseconds = 1500, int retryDelayIncrementMilliseconds = 0)
{ {

View File

@ -6,10 +6,10 @@ using System.IO;
using System.Net; using System.Net;
using System.Net.Http.Headers; using System.Net.Http.Headers;
namespace N_m3u8DL_RE.Util namespace N_m3u8DL_RE.Util;
internal static class DownloadUtil
{ {
internal class DownloadUtil
{
private static readonly HttpClient AppHttpClient = HTTPUtil.AppHttpClient; private static readonly HttpClient AppHttpClient = HTTPUtil.AppHttpClient;
private static async Task<DownloadResult> CopyFileAsync(string sourceFile, string path, SpeedContainer speedContainer, long? fromPosition = null, long? toPosition = null) private static async Task<DownloadResult> CopyFileAsync(string sourceFile, string path, SpeedContainer speedContainer, long? fromPosition = null, long? toPosition = null)
@ -142,5 +142,4 @@ namespace N_m3u8DL_RE.Util
throw new Exception("Download speed too slow!"); throw new Exception("Download speed too slow!");
} }
} }
}
} }

View File

@ -11,10 +11,10 @@ using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace N_m3u8DL_RE.Util namespace N_m3u8DL_RE.Util;
public static class FilterUtil
{ {
public class FilterUtil
{
public static List<StreamSpec> DoFilterKeep(IEnumerable<StreamSpec> lists, StreamFilter? filter) public static List<StreamSpec> DoFilterKeep(IEnumerable<StreamSpec> lists, StreamFilter? filter)
{ {
if (filter == null) return new List<StreamSpec>(); if (filter == null) return new List<StreamSpec>();
@ -280,5 +280,4 @@ namespace N_m3u8DL_RE.Util
} }
} }
} }
}
} }

View File

@ -1,14 +1,7 @@
using System; namespace N_m3u8DL_RE.Util;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace N_m3u8DL_RE.Util internal static class ImageHeaderUtil
{ {
internal class ImageHeaderUtil
{
public static bool IsImageHeader(byte[] bArr) public static bool IsImageHeader(byte[] bArr)
{ {
var size = bArr.Length; var size = bArr.Length;
@ -85,5 +78,4 @@ namespace N_m3u8DL_RE.Util
await File.WriteAllBytesAsync(sourcePath, sourceData); await File.WriteAllBytesAsync(sourcePath, sourceData);
} }
}
} }

View File

@ -6,10 +6,10 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace N_m3u8DL_RE.Util namespace N_m3u8DL_RE.Util;
class Language
{ {
class Language
{
public string Code; public string Code;
public string ExtendCode; public string ExtendCode;
public string Description; public string Description;
@ -22,11 +22,10 @@ namespace N_m3u8DL_RE.Util
Description = desc; Description = desc;
DescriptionAudio = descA; DescriptionAudio = descA;
} }
} }
internal class LanguageCodeUtil internal static class LanguageCodeUtil
{ {
private LanguageCodeUtil() { }
private readonly static List<Language> ALL_LANGS = @" private readonly static List<Language> ALL_LANGS = @"
af;afr;Afrikaans;Afrikaans af;afr;Afrikaans;Afrikaans
@ -388,11 +387,11 @@ CC;chi;中文(繁體);中文
CZ;chi;; CZ;chi;;
MA;msa;Melayu;Melayu MA;msa;Melayu;Melayu
" "
.Trim().Replace("\r", "").Split('\n').Where(x => !string.IsNullOrWhiteSpace(x)).Select(x => .Trim().Replace("\r", "").Split('\n').Where(x => !string.IsNullOrWhiteSpace(x)).Select(x =>
{ {
var arr = x.Trim().Split(';'); var arr = x.Trim().Split(';');
return new Language(arr[0].Trim(), arr[1].Trim(), arr[2].Trim(), arr[3].Trim()); return new Language(arr[0].Trim(), arr[1].Trim(), arr[2].Trim(), arr[3].Trim());
}).ToList(); }).ToList();
private static Dictionary<string, string> CODE_MAP = @" private static Dictionary<string, string> CODE_MAP = @"
iv;IVL iv;IVL
@ -500,7 +499,7 @@ nn;nno
bs;bos bs;bos
sr;srp sr;srp
" "
.Trim().Replace("\r", "").Split('\n').Where(x => !string.IsNullOrWhiteSpace(x)).Select(x => x.Trim()).ToDictionary(x => x.Split(';').First().Trim(), x => x.Split(';').Last().Trim()); .Trim().Replace("\r", "").Split('\n').Where(x => !string.IsNullOrWhiteSpace(x)).Select(x => x.Trim()).ToDictionary(x => x.Split(';').First().Trim(), x => x.Split(';').Last().Trim());
private static string ConvertTwoToThree(string input) private static string ConvertTwoToThree(string input)
@ -543,5 +542,4 @@ sr;srp
//无描述则把LangCode当作描述 //无描述则把LangCode当作描述
if (string.IsNullOrEmpty(outputFile.Description)) outputFile.Description = originalLangCode; if (string.IsNullOrEmpty(outputFile.Description)) outputFile.Description = originalLangCode;
} }
}
} }

View File

@ -9,10 +9,10 @@ using System.Net.Http;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace N_m3u8DL_RE.Util namespace N_m3u8DL_RE.Util;
internal static class LargeSingleFileSplitUtil
{ {
internal class LargeSingleFileSplitUtil
{
class Clip class Clip
{ {
public required int index; public required int index;
@ -118,5 +118,4 @@ namespace N_m3u8DL_RE.Util
} }
return clips; return clips;
} }
}
} }

View File

@ -5,10 +5,10 @@ using N_m3u8DL_RE.Config;
using System.Diagnostics; using System.Diagnostics;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
namespace N_m3u8DL_RE.Util namespace N_m3u8DL_RE.Util;
internal static class MP4DecryptUtil
{ {
internal class MP4DecryptUtil
{
private static string ZeroKid = "00000000000000000000000000000000"; private static string ZeroKid = "00000000000000000000000000000000";
public static async Task<bool> DecryptAsync(bool shakaPackager, string bin, string[]? keys, string source, string dest, string? kid, string init = "", bool isMultiDRM=false) public static async Task<bool> DecryptAsync(bool shakaPackager, string bin, string[]? keys, string source, string dest, string? kid, string init = "", bool isMultiDRM=false)
{ {
@ -184,5 +184,4 @@ namespace N_m3u8DL_RE.Util
p.WaitForExit(); p.WaitForExit();
return ShakaKeyIDRegex.Match(errorOutput).Groups[1].Value; return ShakaKeyIDRegex.Match(errorOutput).Groups[1].Value;
} }
}
} }

View File

@ -8,10 +8,10 @@ using System.Text.RegularExpressions;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Xml.Linq; using System.Xml.Linq;
namespace N_m3u8DL_RE.Util namespace N_m3u8DL_RE.Util;
internal static partial class MediainfoUtil
{ {
internal partial class MediainfoUtil
{
[GeneratedRegex(" Stream #.*")] [GeneratedRegex(" Stream #.*")]
private static partial Regex TextRegex(); private static partial Regex TextRegex();
[GeneratedRegex("#0:\\d(\\[0x\\w+?\\])")] [GeneratedRegex("#0:\\d(\\[0x\\w+?\\])")]
@ -95,5 +95,4 @@ namespace N_m3u8DL_RE.Util
return result; return result;
} }
}
} }

View File

@ -5,10 +5,10 @@ using System.Diagnostics;
using System.Text; using System.Text;
using N_m3u8DL_RE.Enum; using N_m3u8DL_RE.Enum;
namespace N_m3u8DL_RE.Util namespace N_m3u8DL_RE.Util;
internal static class MergeUtil
{ {
internal class MergeUtil
{
/// <summary> /// <summary>
/// 输入一堆已存在的文件,合并到新文件 /// 输入一堆已存在的文件,合并到新文件
/// </summary> /// </summary>
@ -290,5 +290,4 @@ namespace N_m3u8DL_RE.Util
return code == 0; return code == 0;
} }
}
} }

View File

@ -6,10 +6,10 @@ using System.IO.Compression;
using System.Text; using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
namespace N_m3u8DL_RE.Util namespace N_m3u8DL_RE.Util;
internal class OtherUtil
{ {
internal class OtherUtil
{
public static Dictionary<string, string> SplitHeaderArrayToDic(string[]? headers) public static Dictionary<string, string> SplitHeaderArrayToDic(string[]? headers)
{ {
Dictionary<string, string> dic = new(); Dictionary<string, string> dic = new();
@ -176,5 +176,4 @@ namespace N_m3u8DL_RE.Util
_ => throw new ArgumentException($"unknown format: {muxFormat}") _ => throw new ArgumentException($"unknown format: {muxFormat}")
}; };
} }
}
} }

View File

@ -10,10 +10,10 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace N_m3u8DL_RE.Util namespace N_m3u8DL_RE.Util;
internal static class PipeUtil
{ {
internal class PipeUtil
{
public static Stream CreatePipe(string pipeName) public static Stream CreatePipe(string pipeName)
{ {
if (OperatingSystem.IsWindows()) if (OperatingSystem.IsWindows())
@ -109,5 +109,4 @@ namespace N_m3u8DL_RE.Util
return p.ExitCode == 0; return p.ExitCode == 0;
} }
}
} }

View File

@ -7,10 +7,10 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace N_m3u8DL_RE.Util namespace N_m3u8DL_RE.Util;
internal static class SubtitleUtil
{ {
internal class SubtitleUtil
{
/// <summary> /// <summary>
/// 写出图形字幕PNG文件 /// 写出图形字幕PNG文件
/// </summary> /// </summary>
@ -36,5 +36,4 @@ namespace N_m3u8DL_RE.Util
} }
else return false; else return false;
} }
}
} }