Skip to content

Commit

Permalink
程序逻辑优化
Browse files Browse the repository at this point in the history
  • Loading branch information
91270 committed Apr 10, 2022
1 parent bc72ca4 commit 74e576d
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 95 deletions.
33 changes: 18 additions & 15 deletions Emby.MeiamSub.Shooter/ShooterProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public ShooterProvider(ILogger logger, IJsonSerializer jsonSerializer,IHttpClien
_logger = logger;
_jsonSerializer = jsonSerializer;
_httpClient = httpClient;
_logger.Info($"{Name} Init");
}
#endregion

Expand All @@ -60,7 +61,7 @@ public ShooterProvider(ILogger logger, IJsonSerializer jsonSerializer,IHttpClien
/// <returns></returns>
public async Task<IEnumerable<RemoteSubtitleInfo>> Search(SubtitleSearchRequest request, CancellationToken cancellationToken)
{
_logger.Debug($"MeiamSub.Shooter Search | Request -> { _jsonSerializer.SerializeToString(request) }");
_logger.Info($"{Name} Search | SubtitleSearchRequest -> { _jsonSerializer.SerializeToString(request) }");

var subtitles = await SearchSubtitlesAsync(request);

Expand All @@ -86,7 +87,7 @@ private async Task<IEnumerable<RemoteSubtitleInfo>> SearchSubtitlesAsync(Subtitl
HttpRequestOptions options = new HttpRequestOptions
{
Url = $"http://www.shooter.cn/api/subapi.php",
UserAgent = "Emby.MeiamSub.Shooter",
UserAgent = $"{Name}",
TimeoutMs = 30000,
AcceptHeader = "*/*",
};
Expand All @@ -99,19 +100,19 @@ private async Task<IEnumerable<RemoteSubtitleInfo>> SearchSubtitlesAsync(Subtitl
{ "lang",request.Language == "chi" ? "chn" : "eng"}
});

_logger.Debug($"MeiamSub.Shooter Search | Request -> { _jsonSerializer.SerializeToString(options) }");
_logger.Info($"{Name} Search | Request -> { _jsonSerializer.SerializeToString(options) }");

var response = await _httpClient.Post(options);

_logger.Debug($"MeiamSub.Shooter Search | Response -> { _jsonSerializer.SerializeToString(response) }");
_logger.Info($"{Name} Search | Response -> { _jsonSerializer.SerializeToString(response) }");

if (response.StatusCode == HttpStatusCode.OK && response.ContentType.Contains("application/json"))
{
var subtitleResponse = _jsonSerializer.DeserializeFromStream<List<SubtitleResponseRoot>>(response.Content);

if (subtitleResponse != null)
{
_logger.Debug($"MeiamSub.Shooter Search | Response -> { _jsonSerializer.SerializeToString(subtitleResponse) }");
_logger.Info($"{Name} Search | Response -> { _jsonSerializer.SerializeToString(subtitleResponse) }");

var remoteSubtitleInfos = new List<RemoteSubtitleInfo>();

Expand All @@ -131,20 +132,20 @@ private async Task<IEnumerable<RemoteSubtitleInfo>> SearchSubtitlesAsync(Subtitl
})),
Name = $"[MEIAMSUB] { Path.GetFileName(request.MediaPath) } | {request.TwoLetterISOLanguageName} | 射手",
Author = "Meiam ",
ProviderName = "MeiamSub.Shooter",
ProviderName = $"{Name}",
Format = subFile.Ext,
Comment = $"Format : { ExtractFormat(subFile.Ext)}"
});
}
}

_logger.Debug($"MeiamSub.Shooter Search | Summary -> Get { remoteSubtitleInfos.Count } Subtitles");
_logger.Info($"{Name} Search | Summary -> Get { remoteSubtitleInfos.Count } Subtitles");

return remoteSubtitleInfos;
}
}

_logger.Debug($"MeiamSub.Shooter Search | Summary -> Get 0 Subtitles");
_logger.Info($"{Name} Search | Summary -> Get 0 Subtitles");

return Array.Empty<RemoteSubtitleInfo>();
}
Expand All @@ -159,10 +160,7 @@ private async Task<IEnumerable<RemoteSubtitleInfo>> SearchSubtitlesAsync(Subtitl
/// <returns></returns>
public async Task<SubtitleResponse> GetSubtitles(string id, CancellationToken cancellationToken)
{
await Task.Run(() =>
{
_logger.Debug($"MeiamSub.Shooter DownloadSub | Request -> {id}");
});
_logger.Info($"{Name} DownloadSub | Request -> {id}");

return await DownloadSubAsync(id);
}
Expand All @@ -176,20 +174,25 @@ private async Task<SubtitleResponse> DownloadSubAsync(string info)
{
var downloadSub = _jsonSerializer.DeserializeFromString<DownloadSubInfo>(Base64Decode(info));

if (downloadSub == null)
{
return new SubtitleResponse();
}

downloadSub.Url = downloadSub.Url.Replace("https://www.shooter.cn", "http://www.shooter.cn");

_logger.Debug($"MeiamSub.Shooter DownloadSub | Url -> { downloadSub.Url } | Format -> { downloadSub.Format } | Language -> { downloadSub.Language } ");
_logger.Info($"{Name} DownloadSub | Url -> { downloadSub.Url } | Format -> { downloadSub.Format } | Language -> { downloadSub.Language } ");

var response = await _httpClient.GetResponse(new HttpRequestOptions
{
Url = downloadSub.Url,
UserAgent = "Emby.MeiamSub.Shooter",
UserAgent = $"{Name}",
TimeoutMs = 30000,
AcceptHeader = "*/*",
});


_logger.Debug($"MeiamSub.Shooter DownloadSub | Response -> { response.StatusCode }");
_logger.Info($"{Name} DownloadSub | Response -> { response.StatusCode }");

if (response.StatusCode == HttpStatusCode.OK)
{
Expand Down
4 changes: 0 additions & 4 deletions Emby.MeiamSub.Thunder/Model/SubtitleResponseRoot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ public class SublistItem
///
/// </summary>
public int svote { get; set; }
/// <summary>
///
/// </summary>
public int roffset { get; set; }
}

public class SubtitleResponseRoot
Expand Down
34 changes: 19 additions & 15 deletions Emby.MeiamSub.Thunder/ThunderProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public ThunderProvider(ILogger logger, IJsonSerializer jsonSerializer,IHttpClien
_logger = logger;
_jsonSerializer = jsonSerializer;
_httpClient = httpClient;
_logger.Info($"{Name} Init");
}
#endregion

Expand All @@ -60,7 +61,7 @@ public ThunderProvider(ILogger logger, IJsonSerializer jsonSerializer,IHttpClien
/// <returns></returns>
public async Task<IEnumerable<RemoteSubtitleInfo>> Search(SubtitleSearchRequest request, CancellationToken cancellationToken)
{
_logger.Debug($"MeiamSub.Thunder Search | Request -> { _jsonSerializer.SerializeToString(request) }");
_logger.Info($"{Name} Search | SubtitleSearchRequest -> { _jsonSerializer.SerializeToString(request) }");

var subtitles = await SearchSubtitlesAsync(request);

Expand All @@ -83,27 +84,28 @@ private async Task<IEnumerable<RemoteSubtitleInfo>> SearchSubtitlesAsync(Subtitl

var response = await _httpClient.GetResponse(new HttpRequestOptions
{
Url = $"http://sub.xmp.sandai.net:8000/subxl/{cid}.json",
UserAgent = "Emby.MeiamSub.Thunder",
//Url = $"http://sub.xmp.sandai.net:8000/subxl/{cid}.json",
Url = $"http://subtitle.kankan.xunlei.com:8000/subxl/{cid}.json",
UserAgent = $"{Name}",
TimeoutMs = 30000,
AcceptHeader = "*/*",
});

_logger.Debug($"MeiamSub.Thunder Search | Response -> { _jsonSerializer.SerializeToString(response) }");
_logger.Info($"{Name} Search | Response -> { _jsonSerializer.SerializeToString(response) }");

if (response.StatusCode == HttpStatusCode.OK)
{
var subtitleResponse = _jsonSerializer.DeserializeFromStream<SubtitleResponseRoot>(response.Content);

if (subtitleResponse != null)
{
_logger.Debug($"MeiamSub.Thunder Search | Response -> { _jsonSerializer.SerializeToString(subtitleResponse) }");
_logger.Info($"{Name} Search | Response -> { _jsonSerializer.SerializeToString(subtitleResponse) }");

var subtitles = subtitleResponse.sublist.Where(m => !string.IsNullOrEmpty(m.sname));

if (subtitles.Count() > 0)
{
_logger.Debug($"MeiamSub.Thunder Search | Summary -> Get { subtitles.Count() } Subtitles");
_logger.Info($"{Name} Search | Summary -> Get { subtitles.Count() } Subtitles");

return subtitles.Select(m => new RemoteSubtitleInfo()
{
Expand All @@ -118,15 +120,15 @@ private async Task<IEnumerable<RemoteSubtitleInfo>> SearchSubtitlesAsync(Subtitl
Name = $"[MEIAMSUB] { Path.GetFileName(request.MediaPath) } | {request.TwoLetterISOLanguageName} | 迅雷",
Author = "Meiam ",
CommunityRating = Convert.ToSingle(m.rate),
ProviderName = "MeiamSub.Thunder",
ProviderName = $"{Name}",
Format = ExtractFormat(m.sname),
Comment = $"Format : { ExtractFormat(m.sname)} - Rate : { m.rate }"
}).OrderByDescending(m => m.CommunityRating);
}
}
}

_logger.Debug($"MeiamSub.Thunder Search | Summary -> Get 0 Subtitles");
_logger.Info($"{Name} Search | Summary -> Get 0 Subtitles");

return Array.Empty<RemoteSubtitleInfo>();
}
Expand All @@ -141,10 +143,7 @@ private async Task<IEnumerable<RemoteSubtitleInfo>> SearchSubtitlesAsync(Subtitl
/// <returns></returns>
public async Task<SubtitleResponse> GetSubtitles(string id, CancellationToken cancellationToken)
{
await Task.Run(() =>
{
_logger.Debug($"MeiamSub.Thunder DownloadSub | Request -> {id}");
});
_logger.Info($"{Name} DownloadSub | Request -> {id}");

return await DownloadSubAsync(id);
}
Expand All @@ -158,17 +157,22 @@ private async Task<SubtitleResponse> DownloadSubAsync(string info)
{
var downloadSub = _jsonSerializer.DeserializeFromString<DownloadSubInfo>(Base64Decode(info));

_logger.Debug($"MeiamSub.Thunder DownloadSub | Url -> { downloadSub.Url } | Format -> { downloadSub.Format } | Language -> { downloadSub.Language } ");
if (downloadSub == null)
{
return new SubtitleResponse();
}

_logger.Info($"{Name} DownloadSub | Url -> { downloadSub.Url } | Format -> { downloadSub.Format } | Language -> { downloadSub.Language } ");

var response = await _httpClient.GetResponse(new HttpRequestOptions
{
Url = downloadSub.Url,
UserAgent = "Emby.MeiamSub.Thunder",
UserAgent = $"{Name}",
TimeoutMs = 30000,
AcceptHeader = "*/*",
});

_logger.Debug($"MeiamSub.Thunder DownloadSub | Response -> { response.StatusCode }");
_logger.Info($"{Name} DownloadSub | Response -> { response.StatusCode }");

if (response.StatusCode == HttpStatusCode.OK)
{
Expand Down
Loading

0 comments on commit 74e576d

Please sign in to comment.