Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6ec727e9c5 | ||
|
|
210543ba1f | ||
|
|
0e805184d9 | ||
|
|
373169d697 |
No files matched your search
@@ -1,4 +1,4 @@
|
||||
using System.Text.Encodings.Web;
|
||||
using System.Text.Encodings.Web;
|
||||
using System.Text.Json;
|
||||
using WebImageViewer.Class.Legacy.Models;
|
||||
|
||||
@@ -1720,8 +1720,6 @@ public static class HtmlRenderer
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
|
||||
""";
|
||||
}
|
||||
|
||||
@@ -2106,7 +2104,6 @@ public static class HtmlRenderer
|
||||
playerUrl ??= $"https://video.fc2.com/a/embed/player/{safeId}/";
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
siteDisplayName = !string.IsNullOrWhiteSpace(site) ? site.ToUpperInvariant() : "動画プレイヤー";
|
||||
badgeText = "WEB VIDEO";
|
||||
@@ -2117,10 +2114,19 @@ public static class HtmlRenderer
|
||||
break;
|
||||
}
|
||||
|
||||
bool is123Av = string.Equals(normalizedSite, "123av", StringComparison.OrdinalIgnoreCase) ||
|
||||
(!string.IsNullOrWhiteSpace(originalUrl) && originalUrl.Contains("123av.", StringComparison.OrdinalIgnoreCase)) ||
|
||||
(!string.IsNullOrWhiteSpace(playerUrl) && (playerUrl.Contains("123av.", StringComparison.OrdinalIgnoreCase) || playerUrl.Contains("jav-master", StringComparison.OrdinalIgnoreCase) || playerUrl.Contains("javplayer.cc", StringComparison.OrdinalIgnoreCase) || playerUrl.Contains("sadie-shop.site", StringComparison.OrdinalIgnoreCase)));
|
||||
|
||||
var effectivePlayerUrl = (!string.IsNullOrWhiteSpace(playerUrl) && is123Av && !playerUrl.StartsWith("/api/clean-embed", StringComparison.OrdinalIgnoreCase))
|
||||
? $"/api/clean-embed?url={Uri.EscapeDataString(playerUrl.Trim())}&referer={Uri.EscapeDataString(!string.IsNullOrWhiteSpace(originalUrl) ? originalUrl.Trim() : defaultOrigUrl)}"
|
||||
: (playerUrl ?? "");
|
||||
|
||||
var safeTitle = !string.IsNullOrWhiteSpace(title) ? Encoder.Encode(title) : $"{siteDisplayName} 動画プレイヤー ({safeId})";
|
||||
var safeOriginalUrl = !string.IsNullOrWhiteSpace(originalUrl) ? Encoder.Encode(originalUrl) : defaultOrigUrl;
|
||||
var safePlayerUrl = !string.IsNullOrWhiteSpace(playerUrl) ? Encoder.Encode(playerUrl) : "";
|
||||
var safePlayerUrl = !string.IsNullOrWhiteSpace(effectivePlayerUrl) ? Encoder.Encode(effectivePlayerUrl) : "";
|
||||
var safeStreamUrl = !string.IsNullOrWhiteSpace(streamUrl) ? Encoder.Encode(streamUrl) : "";
|
||||
var sandboxAttr = is123Av ? """sandbox="allow-scripts allow-same-origin allow-forms allow-presentation" """ : "";
|
||||
|
||||
bool hasStream = !string.IsNullOrEmpty(safeStreamUrl);
|
||||
bool hasPlayer = !string.IsNullOrEmpty(safePlayerUrl);
|
||||
@@ -2413,7 +2419,7 @@ public static class HtmlRenderer
|
||||
<iframe
|
||||
id="videoIframe"
|
||||
src="{{safePlayerUrl}}"
|
||||
class="player-iframe"
|
||||
{{sandboxAttr}}class="player-iframe"
|
||||
frameborder="0"
|
||||
scrolling="no"
|
||||
referrerpolicy="no-referrer-when-downgrade"
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.Text.Encodings.Web;
|
||||
using System.Text.Encodings.Web;
|
||||
using System.Text.Json;
|
||||
using WebImageViewer.Class.Unified.Models;
|
||||
using WebImageViewer.Class.Unified.Services;
|
||||
|
||||
namespace WebImageViewer.Class.Unified.Renderers;
|
||||
|
||||
@@ -565,11 +566,17 @@ public static class UnifiedHtmlRenderer
|
||||
/// </summary>
|
||||
public static string RenderVideoViewer(UnifiedVideoItem video)
|
||||
{
|
||||
bool is123Av = UnifiedEmbedSanitizer.Is123AvDomain(video.Site, video.OriginalUrl, video.EmbedUrl);
|
||||
var effectiveEmbedUrl = (!string.IsNullOrWhiteSpace(video.EmbedUrl) && is123Av)
|
||||
? UnifiedEmbedSanitizer.ToCleanEmbedUrl(video.EmbedUrl, video.OriginalUrl)
|
||||
: (video.EmbedUrl ?? "");
|
||||
|
||||
var safeTitle = Encoder.Encode(video.Title);
|
||||
var safeOrigUrl = Encoder.Encode(video.OriginalUrl);
|
||||
var safeEmbedUrl = !string.IsNullOrWhiteSpace(video.EmbedUrl) ? Encoder.Encode(video.EmbedUrl) : "";
|
||||
var safeEmbedUrl = !string.IsNullOrWhiteSpace(effectiveEmbedUrl) ? Encoder.Encode(effectiveEmbedUrl) : "";
|
||||
var safeStreamUrl = !string.IsNullOrWhiteSpace(video.StreamUrl) ? Encoder.Encode(video.StreamUrl) : "";
|
||||
var safePoster = !string.IsNullOrWhiteSpace(video.PosterUrl) ? Encoder.Encode(video.PosterUrl) : "";
|
||||
var sandboxAttr = is123Av ? """sandbox="allow-scripts allow-same-origin allow-forms allow-presentation" """ : "";
|
||||
|
||||
bool hasStream = !string.IsNullOrEmpty(safeStreamUrl);
|
||||
bool hasEmbed = !string.IsNullOrEmpty(safeEmbedUrl);
|
||||
@@ -729,7 +736,7 @@ public static class UnifiedHtmlRenderer
|
||||
<iframe
|
||||
id="videoIframe"
|
||||
src="{{safeEmbedUrl}}"
|
||||
class="player-iframe"
|
||||
{{sandboxAttr}}class="player-iframe"
|
||||
frameborder="0"
|
||||
scrolling="no"
|
||||
referrerpolicy="no-referrer-when-downgrade"
|
||||
@@ -808,6 +815,40 @@ public static class UnifiedHtmlRenderer
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 123av ドメイン接続時の透明リンクエリア・外部リンク除去バックアップ監視
|
||||
const is123AvDomain = {{(is123Av ? "true" : "false")}};
|
||||
const videoIframe = document.getElementById('videoIframe');
|
||||
if (is123AvDomain) {
|
||||
try {
|
||||
Object.defineProperty(window, 'open', {
|
||||
value: function() { return null; },
|
||||
writable: false,
|
||||
configurable: false
|
||||
});
|
||||
} catch (e) {
|
||||
window.open = function() { return null; };
|
||||
}
|
||||
|
||||
if (videoIframe) {
|
||||
const cleanIframeOverlays = () => {
|
||||
try {
|
||||
const doc = videoIframe.contentDocument || (videoIframe.contentWindow && videoIframe.contentWindow.document);
|
||||
if (!doc) return;
|
||||
const links = doc.querySelectorAll('body > a, a[target="_blank"], a[style*="999999"], ins');
|
||||
links.forEach(el => {
|
||||
el.removeAttribute('href');
|
||||
el.removeAttribute('target');
|
||||
el.style.setProperty('pointer-events', 'none', 'important');
|
||||
el.style.setProperty('display', 'none', 'important');
|
||||
el.remove();
|
||||
});
|
||||
} catch (e) {}
|
||||
};
|
||||
videoIframe.addEventListener('load', cleanIframeOverlays);
|
||||
setInterval(cleanIframeOverlays, 250);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,4 +1,4 @@
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Text.RegularExpressions;
|
||||
using HtmlAgilityPack;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using WebImageViewer.Class.Unified.Common;
|
||||
@@ -194,72 +194,210 @@ public class VideoEmbedExtractor
|
||||
|
||||
/// <summary>
|
||||
/// MissAV の埋め込み・HLSストリームを解決します。
|
||||
/// Cloudflare保護を通過し、surrit.comのm3u8を安全な内部プロキシ経由(CORS・Referer解決)で設定することで、
|
||||
/// 外部リンク誘導ではなく純粋な動画プレイヤーのみを表示して再生できるようにします。
|
||||
/// </summary>
|
||||
private async Task<UnifiedVideoItem> ResolveMissAvAsync(string url, CancellationToken ct)
|
||||
{
|
||||
var match = Regex.Match(url, @"(?:missav\.[a-z]+/(?:ja/)?|missav/)(?<id>[^/?#]+)", RegexOptions.IgnoreCase);
|
||||
var id = match.Success ? match.Groups["id"].Value : "video";
|
||||
var videoId = ExtractMissAvId(url) ?? "fc2-ppv-4968519";
|
||||
var canonicalUrl = url.Trim();
|
||||
if (!canonicalUrl.StartsWith("http", StringComparison.OrdinalIgnoreCase) ||
|
||||
canonicalUrl.EndsWith("missav.ai", StringComparison.OrdinalIgnoreCase) ||
|
||||
canonicalUrl.EndsWith("missav.ai/", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
canonicalUrl = $"https://missav.ai/ja/{videoId}";
|
||||
}
|
||||
|
||||
var item = new UnifiedVideoItem
|
||||
{
|
||||
Site = "missav",
|
||||
VideoId = id,
|
||||
Title = $"MissAV ({id})",
|
||||
OriginalUrl = url
|
||||
VideoId = videoId,
|
||||
Title = $"MissAV ({videoId})",
|
||||
OriginalUrl = canonicalUrl
|
||||
};
|
||||
|
||||
// HTMLを取得して Dean Edwards packer スクリプトおよび m3u8 を探索
|
||||
// 1. 通常HTTPで取得を試み、Cloudflareチャレンジまたはエラー時はFlareSolverr経由で再取得
|
||||
string? html = null;
|
||||
try
|
||||
{
|
||||
var html = await _httpHelper.GetHtmlAsync(url, ct: ct);
|
||||
if (!string.IsNullOrWhiteSpace(html))
|
||||
html = await this._httpHelper.GetHtmlAsync(canonicalUrl, useFlareSolverr: false, referer: "https://missav.ai/", ct: ct);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// タイトル抽出
|
||||
var titleMatch = Regex.Match(html, @"<meta property=""og:title"" content=""([^""]+)""");
|
||||
if (titleMatch.Success) item.Title = CleanText(titleMatch.Groups[1].Value);
|
||||
this._logger.LogInformation(ex, "MissAVの通常HTTP取得に失敗しました。FlareSolverrを試行します: {Url}", canonicalUrl);
|
||||
}
|
||||
|
||||
// ポスター画像抽出
|
||||
var posterMatch = Regex.Match(html, @"<meta property=""og:image"" content=""([^""]+)""");
|
||||
if (posterMatch.Success) item.PosterUrl = posterMatch.Groups[1].Value;
|
||||
|
||||
// 1. surrit.com の直接m3u8探索
|
||||
var directM3u8 = Regex.Match(html, @"https://surrit\.com/[a-f0-9\-]+/(?:playlist|\d+p/video)\.m3u8");
|
||||
if (directM3u8.Success)
|
||||
if (string.IsNullOrWhiteSpace(html) || UnifiedEmbedSanitizer.IsCloudflareChallengeHtml(html))
|
||||
{
|
||||
item.StreamUrl = directM3u8.Value;
|
||||
this._logger.LogInformation("MissAVがCloudflare保護下のためFlareSolverr経由で再取得します: {Url}", canonicalUrl);
|
||||
try
|
||||
{
|
||||
html = await this._httpHelper.GetHtmlAsync(canonicalUrl, useFlareSolverr: true, referer: "https://missav.ai/", ct: ct);
|
||||
}
|
||||
catch (Exception flareEx)
|
||||
{
|
||||
this._logger.LogWarning(flareEx, "MissAVのFlareSolverr取得に失敗しました: {Url}", canonicalUrl);
|
||||
}
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(html))
|
||||
{
|
||||
// HTMLが取得できない場合でも、外部リンク誘導ボタンではなくインライン埋め込み用としてEmbedUrlをセット
|
||||
item.EmbedUrl = canonicalUrl;
|
||||
return item;
|
||||
}
|
||||
|
||||
// 2. Dean Edwards Packer のアンパック試行
|
||||
var packerMatch = Regex.Match(html, @"eval\(function\(p,a,c,k,e,d\)\{.+?\.split\('\|'\),\d+,\{\}\)\)");
|
||||
if (packerMatch.Success)
|
||||
try
|
||||
{
|
||||
var unpacked = UnpackDeanEdwards(packerMatch.Value);
|
||||
var m3u8Match = Regex.Match(unpacked, @"https://surrit\.com/[a-f0-9\-]+/(?:playlist|\d+p/video)\.m3u8");
|
||||
// タイトル抽出 (og:title または title タグ)
|
||||
var titleMatch = Regex.Match(html, @"<meta\s+property=[""']og:title[""']\s+content=[""']([^""']+)[""']", RegexOptions.IgnoreCase);
|
||||
if (titleMatch.Success)
|
||||
{
|
||||
item.Title = CleanText(System.Net.WebUtility.HtmlDecode(titleMatch.Groups[1].Value));
|
||||
}
|
||||
else
|
||||
{
|
||||
var docTitleMatch = Regex.Match(html, @"<title>([^<]+)</title>", RegexOptions.IgnoreCase);
|
||||
if (docTitleMatch.Success)
|
||||
{
|
||||
item.Title = CleanText(System.Net.WebUtility.HtmlDecode(docTitleMatch.Groups[1].Value));
|
||||
}
|
||||
}
|
||||
|
||||
// ポスター画像抽出 (og:image)
|
||||
var posterMatch = Regex.Match(html, @"<meta\s+property=[""']og:image[""']\s+content=[""']([^""']+)[""']", RegexOptions.IgnoreCase);
|
||||
if (posterMatch.Success)
|
||||
{
|
||||
item.PosterUrl = posterMatch.Groups[1].Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
item.PosterUrl = $"https://fourhoi.com/{videoId}/cover-n.jpg";
|
||||
}
|
||||
|
||||
string? rawStreamUrl = null;
|
||||
|
||||
// 1. Dean Edwards Packer のアンパック試行 (複数ある場合も走査)
|
||||
var packerMatches = Regex.Matches(html, @"eval\(function\(p,a,c,k,e,d\)\{.+?\.split\('\|'\),\d+,\{\}\)\)", RegexOptions.Singleline);
|
||||
foreach (Match pm in packerMatches)
|
||||
{
|
||||
var unpacked = UnpackDeanEdwards(pm.Value);
|
||||
if (!string.IsNullOrEmpty(unpacked))
|
||||
{
|
||||
unpacked = unpacked.Replace("\\", "");
|
||||
var m3u8Match = Regex.Match(unpacked, @"https://surrit\.com/[a-f0-9\-]+/(?:playlist|\d+p/video)\.m3u8", RegexOptions.IgnoreCase);
|
||||
if (m3u8Match.Success)
|
||||
{
|
||||
item.StreamUrl = m3u8Match.Value;
|
||||
return item;
|
||||
rawStreamUrl = m3u8Match.Value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 2. surrit.com の直接m3u8探索
|
||||
if (string.IsNullOrEmpty(rawStreamUrl))
|
||||
{
|
||||
var directM3u8 = Regex.Match(html, @"https://surrit\.com/[a-f0-9\-]+/(?:playlist|\d+p/video)\.m3u8", RegexOptions.IgnoreCase);
|
||||
if (directM3u8.Success)
|
||||
{
|
||||
rawStreamUrl = directM3u8.Value;
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 一般的な UUID パターンから surrit.com m3u8 を推測復元
|
||||
var uuidMatch = Regex.Match(html, @"[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}");
|
||||
if (string.IsNullOrEmpty(rawStreamUrl))
|
||||
{
|
||||
var uuidMatch = Regex.Match(html, @"[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}", RegexOptions.IgnoreCase);
|
||||
if (uuidMatch.Success)
|
||||
{
|
||||
item.StreamUrl = $"https://surrit.com/{uuidMatch.Value}/playlist.m3u8";
|
||||
return item;
|
||||
rawStreamUrl = $"https://surrit.com/{uuidMatch.Value}/playlist.m3u8";
|
||||
}
|
||||
}
|
||||
|
||||
// 4. ストリームURLが抽出された場合、内部プロキシ経由のURLに変換
|
||||
if (!string.IsNullOrWhiteSpace(rawStreamUrl))
|
||||
{
|
||||
// surrit.com は Referer: https://missav.ai/ が必須かつブラウザ直接アクセスでは CORS 制限があるため、
|
||||
// WebImageViewer のプロキシ (/api/proxy-embed-req) 経由にルーティング
|
||||
item.StreamUrl = $"/api/proxy-embed-req?url={Uri.EscapeDataString(rawStreamUrl)}&referer={Uri.EscapeDataString(canonicalUrl)}";
|
||||
}
|
||||
else
|
||||
{
|
||||
// m3u8が抽出できなかった場合でも、外部リンク誘導を回避するためEmbedUrlにセット
|
||||
item.EmbedUrl = canonicalUrl;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "MissAV の HTML からの m3u8 抽出に失敗しました: {Url}", url);
|
||||
this._logger.LogWarning(ex, "MissAV の HTML からの m3u8 抽出に失敗しました: {Url}", canonicalUrl);
|
||||
item.EmbedUrl = canonicalUrl;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 入力URLまたは識別文字列からMissAVの動画IDを抽出します。
|
||||
/// </summary>
|
||||
/// <param name="url">入力URLまたはID文字列</param>
|
||||
/// <returns>抽出された動画ID。判定できない場合は null</returns>
|
||||
private static string? ExtractMissAvId(string url)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(url))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var clean = url.Trim();
|
||||
|
||||
// 1. missav.ai/{lang}/{id} や missav/{id} 等の正規表現マッチング
|
||||
var match = Regex.Match(
|
||||
clean,
|
||||
@"(?:missav\.[a-z]+(?:/dm\d+)?/(?:(?:ja|en|cn|zh|zh-Hant|zh-Hans|ko|ms|th|de|fr|vi|es|it|ru|pt)/)?|^missav/)(?<id>[^/?#]+)",
|
||||
RegexOptions.IgnoreCase);
|
||||
|
||||
if (match.Success)
|
||||
{
|
||||
var id = match.Groups["id"].Value.Trim().TrimEnd('/');
|
||||
if (!IsMissAvReservedWord(id))
|
||||
{
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
// 2. URI パスセグメントからの抽出フォールバック
|
||||
if (Uri.TryCreate(clean, UriKind.Absolute, out var uri))
|
||||
{
|
||||
var segments = uri.AbsolutePath.Trim('/').Split('/', StringSplitOptions.RemoveEmptyEntries);
|
||||
if (segments.Length > 0)
|
||||
{
|
||||
var last = segments[^1].Trim();
|
||||
if (!IsMissAvReservedWord(last))
|
||||
{
|
||||
return last;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 指定されたパスセグメントが言語コードやプレフィックス等の予約語であるかを判定します。
|
||||
/// </summary>
|
||||
private static bool IsMissAvReservedWord(string segment)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(segment))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
var lower = segment.ToLowerInvariant();
|
||||
return lower is "ja" or "en" or "cn" or "zh" or "zh-hant" or "zh-hans" or "ko" or "ms" or "th" or "de" or "fr" or "vi" or "es" or "it" or "ru" or "pt"
|
||||
|| lower.StartsWith("dm", StringComparison.Ordinal)
|
||||
|| lower is "video" or "sample" or "search" or "genres" or "actresses" or "makers" or "directors" or "tags";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SpankBang の公式埋め込みプレイヤーを解決します。
|
||||
/// </summary>
|
||||
@@ -280,8 +418,13 @@ public class VideoEmbedExtractor
|
||||
|
||||
/// <summary>
|
||||
/// 123av の埋め込みプレイヤーを動的解決します。
|
||||
/// ページHTML内の player(JSON.parse(...)) から最新の埋め込みプレイヤーURL(jav-master等)を抽出します。
|
||||
/// ページHTML内の player(JSON.parse(...)) 等から最新の埋め込みプレイヤーURL(jav-master等)を抽出し、
|
||||
/// 定期的に出現する透明なリンクエリア(オーバーレイ広告)および外部リンク処理を除去するクリーン埋め込みURLに変換します。
|
||||
/// </summary>
|
||||
/// <param name="url">対象ページのURL</param>
|
||||
/// <param name="customPlayUrl">明示指定された再生URL(任意)</param>
|
||||
/// <param name="ct">キャンセルトークン</param>
|
||||
/// <returns>解決された動画アイテム</returns>
|
||||
private async Task<UnifiedVideoItem> Resolve123AvAsync(string url, string? customPlayUrl = null, CancellationToken ct = default)
|
||||
{
|
||||
// 0. 直接 jav-master 等の埋め込みプレイヤーURLが指定された場合の即時対応
|
||||
@@ -295,7 +438,7 @@ public class VideoEmbedExtractor
|
||||
VideoId = vId,
|
||||
Title = $"123av 動画 ({vId})",
|
||||
OriginalUrl = url,
|
||||
EmbedUrl = url
|
||||
EmbedUrl = UnifiedEmbedSanitizer.ToCleanEmbedUrl(url, "https://123av.com/")
|
||||
};
|
||||
}
|
||||
|
||||
@@ -356,7 +499,22 @@ public class VideoEmbedExtractor
|
||||
// 2. 123av 公式ページHTMLを取得して実プレイヤーURLおよびタイトル・サムネイルを動的抽出
|
||||
try
|
||||
{
|
||||
var html = await _httpHelper.GetHtmlAsync(canonicalUrl, ct: ct);
|
||||
string? html = null;
|
||||
try
|
||||
{
|
||||
html = await this._httpHelper.GetHtmlAsync(canonicalUrl, useFlareSolverr: false, ct: ct);
|
||||
if (string.IsNullOrWhiteSpace(html) ||
|
||||
html.Contains("<title>Just a moment...</title>", StringComparison.OrdinalIgnoreCase) ||
|
||||
(html.Contains("challenge-platform", StringComparison.OrdinalIgnoreCase) && !html.Contains("watch__title", StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
html = await this._httpHelper.GetHtmlAsync(canonicalUrl, useFlareSolverr: true, ct: ct);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
html = await this._httpHelper.GetHtmlAsync(canonicalUrl, useFlareSolverr: true, ct: ct);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(html))
|
||||
{
|
||||
// タイトル抽出
|
||||
@@ -368,7 +526,10 @@ public class VideoEmbedExtractor
|
||||
else
|
||||
{
|
||||
var ogTitle = Regex.Match(html, @"<meta property=""og:title"" content=""([^""]+)""");
|
||||
if (ogTitle.Success) item.Title = CleanText(ogTitle.Groups[1].Value);
|
||||
if (ogTitle.Success)
|
||||
{
|
||||
item.Title = CleanText(ogTitle.Groups[1].Value);
|
||||
}
|
||||
}
|
||||
|
||||
// ポスター画像抽出
|
||||
@@ -380,15 +541,18 @@ public class VideoEmbedExtractor
|
||||
else
|
||||
{
|
||||
var coverMatch = Regex.Match(html, @"(https?://[^""']+/cover\.jpg[^""']*)");
|
||||
if (coverMatch.Success) item.PosterUrl = coverMatch.Groups[1].Value;
|
||||
if (coverMatch.Success)
|
||||
{
|
||||
item.PosterUrl = coverMatch.Groups[1].Value;
|
||||
}
|
||||
}
|
||||
|
||||
// player(JSON.parse('...')) から jav-master 等の埋め込みURLを抽出
|
||||
// (A) player(JSON.parse('...')) から jav-master 等の埋め込みURLを抽出
|
||||
var playerJsonMatch = Regex.Match(html, @"player\(JSON\.parse\('(?<json>[^']+)'\)");
|
||||
if (playerJsonMatch.Success)
|
||||
{
|
||||
var rawJson = playerJsonMatch.Groups["json"].Value;
|
||||
rawJson = System.Text.RegularExpressions.Regex.Unescape(rawJson);
|
||||
rawJson = Regex.Unescape(rawJson);
|
||||
try
|
||||
{
|
||||
using var doc = System.Text.Json.JsonDocument.Parse(rawJson);
|
||||
@@ -410,11 +574,35 @@ public class VideoEmbedExtractor
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "123av の player JSON 解析エラー: {Json}", rawJson);
|
||||
this._logger.LogWarning(ex, "123av の player JSON 解析エラー: {Json}", rawJson);
|
||||
}
|
||||
}
|
||||
|
||||
// JSONで見つからなかった場合、iframeタグのsrcをフォールバック探索
|
||||
// (B) v-scope="Movie({id: ...})" から ajax/v/{movieId}/videos 経由で埋め込みURLを抽出
|
||||
if (string.IsNullOrWhiteSpace(item.EmbedUrl))
|
||||
{
|
||||
var movieScopeMatch = Regex.Match(html, @"v-scope=""Movie\(\{[^""]*?\bid\s*:\s*(?<movieId>\d+)", RegexOptions.IgnoreCase);
|
||||
if (movieScopeMatch.Success)
|
||||
{
|
||||
var movieId = movieScopeMatch.Groups["movieId"].Value;
|
||||
var ajaxUrl = $"https://123av.com/ja/ajax/v/{movieId}/videos";
|
||||
try
|
||||
{
|
||||
var ajaxJson = await this._httpHelper.GetHtmlAsync(ajaxUrl, useFlareSolverr: false, referer: canonicalUrl, ct: ct);
|
||||
var ajaxUrlMatch = Regex.Match(ajaxJson, @"""url""\s*:\s*""(?<uUrl>https?:[^""]+)""");
|
||||
if (ajaxUrlMatch.Success)
|
||||
{
|
||||
item.EmbedUrl = ajaxUrlMatch.Groups["uUrl"].Value.Replace(@"\/", "/");
|
||||
}
|
||||
}
|
||||
catch (Exception ajaxEx)
|
||||
{
|
||||
this._logger.LogDebug(ajaxEx, "123av ajax/v/{MovieId}/videos の取得に失敗しました", movieId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// (C) JSONで見つからなかった場合、iframeタグのsrcをフォールバック探索
|
||||
if (string.IsNullOrWhiteSpace(item.EmbedUrl))
|
||||
{
|
||||
var iframeMatch = Regex.Match(html, @"<iframe[^>]+src=""([^""]+)""");
|
||||
@@ -427,7 +615,7 @@ public class VideoEmbedExtractor
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "123av ページ({Url})の取得に失敗しました。フォールバック処理を継続します。", canonicalUrl);
|
||||
this._logger.LogWarning(ex, "123av ページ({Url})の取得に失敗しました。フォールバック処理を継続します。", canonicalUrl);
|
||||
}
|
||||
|
||||
// customPlayUrl が指定されていて HTML から埋め込みが取得できなかった場合は customPlayUrl を確実に採用
|
||||
@@ -436,6 +624,12 @@ public class VideoEmbedExtractor
|
||||
item.EmbedUrl = customPlayUrl;
|
||||
}
|
||||
|
||||
// 3. 123av接続時は、定期的に出現する透明なリンクエリア(オーバーレイ広告)および外部リンク処理を除去するクリーン埋め込みURLに変換
|
||||
if (!string.IsNullOrWhiteSpace(item.EmbedUrl))
|
||||
{
|
||||
item.EmbedUrl = UnifiedEmbedSanitizer.ToCleanEmbedUrl(item.EmbedUrl, canonicalUrl);
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,15 +1,22 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using WebImageViewer.Class.Unified.Common;
|
||||
using WebImageViewer.Class.Unified.Scrapers;
|
||||
using WebImageViewer.Class.Unified.Services;
|
||||
|
||||
namespace WebImageViewer.Class.Unified;
|
||||
|
||||
/// <summary>
|
||||
/// 新アーキテクチャ(Unified)用のDIサービス登録拡張クラス
|
||||
/// </summary>
|
||||
public static class UnifiedServiceExtensions
|
||||
{
|
||||
#region □メソッド(Public)
|
||||
|
||||
/// <summary>
|
||||
/// 新アーキテクチャ(Unified)のサービス群をDIコンテナに登録します。
|
||||
/// </summary>
|
||||
/// <param name="services">サービスコレクション</param>
|
||||
/// <returns>登録後のサービスコレクション</returns>
|
||||
public static IServiceCollection AddUnifiedServices(this IServiceCollection services)
|
||||
{
|
||||
// HTTP通信ヘルパー
|
||||
@@ -23,6 +30,9 @@ public static class UnifiedServiceExtensions
|
||||
services.AddScoped<IUnifiedScraper, UnifiedAuraHentaiScraper>();
|
||||
services.AddScoped<IUnifiedScraper, UnifiedMangalearScraper>();
|
||||
|
||||
// 123av等の透明リンクエリア・外部広告除去サニタイザー
|
||||
services.AddScoped<UnifiedEmbedSanitizer>();
|
||||
|
||||
// 動画埋め込み抽出エンジン
|
||||
services.AddScoped<VideoEmbedExtractor>();
|
||||
|
||||
@@ -31,4 +41,6 @@ public static class UnifiedServiceExtensions
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using Microsoft.AspNetCore.HttpOverrides;
|
||||
using Microsoft.AspNetCore.HttpOverrides;
|
||||
using WebImageViewer.Class.Legacy;
|
||||
using WebImageViewer.Class.Unified;
|
||||
using WebImageViewer.Class.Unified.Common;
|
||||
@@ -114,6 +114,25 @@ app.MapGet("/api/proxy-image", async (string url, string? referer, HttpContext h
|
||||
}
|
||||
});
|
||||
|
||||
// ==========================================
|
||||
// 123av等の動画プレイヤー透明リンクエリア・外部リンク除去プロキシAPI
|
||||
// ==========================================
|
||||
app.MapGet("/api/clean-embed", async (string? url, string? referer, UnifiedEmbedSanitizer embedSanitizer, CancellationToken ct) =>
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(url))
|
||||
{
|
||||
return Results.BadRequest("url is required");
|
||||
}
|
||||
|
||||
var sanitizedHtml = await embedSanitizer.GetSanitizedEmbedHtmlAsync(url, referer, ct);
|
||||
return Results.Content(sanitizedHtml, "text/html; charset=utf-8");
|
||||
});
|
||||
|
||||
app.MapMethods("/api/proxy-embed-req", new[] { "GET", "POST", "HEAD" }, async (string? url, string? referer, HttpContext httpContext, UnifiedEmbedSanitizer embedSanitizer, CancellationToken ct) =>
|
||||
{
|
||||
return await embedSanitizer.ProxyEmbedRequestAsync(httpContext, url, referer, ct);
|
||||
});
|
||||
|
||||
// ==========================================
|
||||
// 旧バージョン(Legacy)のエンドポイント登録
|
||||
// (/view, /video, /{site}/{id}, /spankbang/{id}, 旧API等を過去互換用として保持)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="HtmlAgilityPack" Version="1.13.0" />
|
||||
<PackageReference Include="System.Net.Http.WinHttpHandler" Version="10.0.14" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in new issue
Block a user