Compare commits
23
Commits
61239f067f
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
39eb1fef31 | ||
|
|
d2f3bb4a6e | ||
|
|
80ba9afcc1 | ||
|
|
32786ca023 | ||
|
|
0e82c7a2b7 | ||
|
|
2eb067ff8f | ||
|
|
62738928fd | ||
|
|
20ff5b2eac | ||
|
|
6be0d060bf | ||
|
|
86f6e6cf16 | ||
|
|
95e16189cc | ||
|
|
9b5953fbca | ||
|
|
e4aa86589c | ||
|
|
4800d98223 | ||
|
|
0fe359cf17 | ||
|
|
4302fee3fe | ||
|
|
70b5bfa088 | ||
|
|
2a9e4c4218 | ||
|
|
3b856f6cbf | ||
|
|
f2b2edc247 | ||
|
|
c788acaeca | ||
|
|
a5d796e099 | ||
|
|
f0e6a1f1e8 |
No files matched your search
@@ -6,3 +6,4 @@
|
|||||||
/rss-generator/bin
|
/rss-generator/bin
|
||||||
/rss-generator/obj
|
/rss-generator/obj
|
||||||
/app
|
/app
|
||||||
|
/publish
|
||||||
@@ -0,0 +1,145 @@
|
|||||||
|
# プロジェクト固有規則(rss-generator)
|
||||||
|
|
||||||
|
本プロジェクト(`rss-generator`)におけるコード記述およびフィード生成処理では、以下のプロジェクト固有規則を厳格に遵守してください。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 1. ドメイン毎の出力先フォルダ分離規則(必須)
|
||||||
|
|
||||||
|
RSSフィード(XMLファイル)を出力する際は、`output` ディレクトリ直下に直接配置せず、**必ず対象サイトのドメイン名等に応じたサブディレクトリを作成し、その中にXMLファイルを出力してください**。
|
||||||
|
|
||||||
|
### 1.1 命名規則および具体例
|
||||||
|
- 対象サイトのドメイン名(FQDN)またはサービス識別子をサブディレクトリ名として使用します。
|
||||||
|
- `ryuugames.com` → `output/ryuugames.com/ryuugames.xml`
|
||||||
|
- `kimochi.info` → `output/kimochi.info/kimochiinfo.xml`
|
||||||
|
- `japaneseavi.blogspot.com` → `output/japaneseavi.blogspot.com/japaneseavi.xml`
|
||||||
|
- `jpfiles.net` → `output/jpfiles.net/jpfiles.xml`
|
||||||
|
- `pixiv.net` → `output/pixiv.net/...`
|
||||||
|
- `x.com` → `output/x.com/...`
|
||||||
|
- `e-hentai.org` → `output/e-hentai.org/...`
|
||||||
|
- `momon-ga.com` → `output/momon-ga.com/...`
|
||||||
|
- `skebetter.com` → `output/skebetter.com/...`
|
||||||
|
- `danbooru` → `output/danbooru/...`
|
||||||
|
- `youtube` → `output/youtube/...`
|
||||||
|
|
||||||
|
### 1.2 実装方法(C#)
|
||||||
|
- フィード出力メソッド `CmnUtil.ExportXMLFileAsync` を呼び出す際は、必ず `addDir` 引数に対象ドメインサブディレクトリ名を指定してください。
|
||||||
|
```csharp
|
||||||
|
// 例: ryuugames.com の場合
|
||||||
|
private const string DomainDir = "ryuugames.com";
|
||||||
|
|
||||||
|
await CmnUtil.ExportXMLFileAsync(
|
||||||
|
fileName,
|
||||||
|
feed,
|
||||||
|
client,
|
||||||
|
addDir: DomainDir,
|
||||||
|
embedBase64: false,
|
||||||
|
filter24Hours: false);
|
||||||
|
```
|
||||||
|
- 既存XMLファイルを読み込むキャッシュ処理(`LoadExistingEntries` 等)を実装する場合も、`CmnUtil.GetExportXmlPath(fileName, addDir)` を使用して該当ドメインサブフォルダ内のXMLファイルを探索・読み込んでください。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 2. GUID(一意識別子)の標準ハッシュ化規則(必須)
|
||||||
|
|
||||||
|
各記事エントリの一意識別子(RSS 2.0 の `<guid isPermaLink="false">`、`SyndicationItem.Id`)には、生のURL文字列をそのまま設定せず、**必ず `CmnUtil.CreateGuid(articleUrl)` で生成した SHA512 ハッシュ文字列(小文字16進数)を設定してください**。
|
||||||
|
|
||||||
|
### 2.1 実装方法
|
||||||
|
```csharp
|
||||||
|
var guid = CmnUtil.CreateGuid(articleUrl);
|
||||||
|
|
||||||
|
var item = new SyndicationItem(
|
||||||
|
cleanTitle,
|
||||||
|
summaryHtml,
|
||||||
|
new Uri(articleUrl),
|
||||||
|
guid, // 生URLではなく CmnUtil.CreateGuid によるハッシュ値を指定
|
||||||
|
publishDate)
|
||||||
|
{
|
||||||
|
PublishDate = publishDate,
|
||||||
|
LastUpdatedTime = lastUpdatedTime
|
||||||
|
};
|
||||||
|
```
|
||||||
|
- キャッシュ再利用時および既存フィードマージ時も、必ず `CmnUtil.CreateGuid(url)` によるハッシュIDを付与してください。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 3. 日付・時刻(pubDate / LastUpdatedTime)の日本時間(JST)統一規則(必須)
|
||||||
|
|
||||||
|
RSSフィード内の `<pubDate>` は、**必ず正確な日本時間(JST = UTC+9)として解釈・出力してください**。UTC時刻のまま `+0900` が付与されて時間がズレる(例: UTC 02:22 に `+0900` が付いて深夜2時になってしまう現象)ことを厳重に防止してください。
|
||||||
|
|
||||||
|
### 3.1 取得元形式別の変換実装
|
||||||
|
- **サイト現地日時(JST表記、タイムゾーンなし文字列)の場合**:
|
||||||
|
`DateTime.TryParse` 後、オフセット `TimeSpan.FromHours(9)` を明示して `DateTimeOffset` を構築します。
|
||||||
|
```csharp
|
||||||
|
if (DateTime.TryParse(dateStr, out var parsedLocal))
|
||||||
|
{
|
||||||
|
pubDate = new DateTimeOffset(parsedLocal, TimeSpan.FromHours(9));
|
||||||
|
}
|
||||||
|
```
|
||||||
|
- **UTC日時(`date_gmt` や `Z` 付き文字列)の場合**:
|
||||||
|
`DateTimeKind.Utc` を明示し、`ToOffset(TimeSpan.FromHours(9))` で日本時間に変換します。
|
||||||
|
```csharp
|
||||||
|
if (DateTime.TryParse(dateGmtStr, out var parsedGmt))
|
||||||
|
{
|
||||||
|
var utc = DateTime.SpecifyKind(parsedGmt, DateTimeKind.Utc);
|
||||||
|
pubDate = new DateTimeOffset(utc).ToOffset(TimeSpan.FromHours(9));
|
||||||
|
}
|
||||||
|
```
|
||||||
|
- **HTMLメタタグ(`meta property="article:published_time"` 等)の場合**:
|
||||||
|
`CmnUtil.GetPublishedTimeAsJst(doc)` または `CmnUtil.GetModifiedTimeAsJst(doc)` を使用してください。
|
||||||
|
|
||||||
|
### 3.2 本文内の日本時間表示
|
||||||
|
本文(SummaryHtml)ヘッダー部分にも、リーダー画面で直感的に確認できるよう日本時間を明記してください:
|
||||||
|
```html
|
||||||
|
<span style="font-size: 11px; color: #6c757d; font-weight: bold;">📅 2026/11/11 11:22:27 (JST)</span>
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 4. タイトル整形および Windows フォルダ名用タイトルの提供規則(必須)
|
||||||
|
|
||||||
|
ユーザーが記事タイトルをそのままWindowsの保存用フォルダ名として利用できるよう、以下の整形処理とワンクリックコピー枠を必ず提供してください。
|
||||||
|
|
||||||
|
### 4.1 タイトル整形仕様
|
||||||
|
1. **Windows 禁止文字の全角置換**:
|
||||||
|
`\ / : * ? " < > |` は必ず全角文字 `¥ / : * ? ” < > |` に置換してください。
|
||||||
|
2. **タイトル構成フォーマット**:
|
||||||
|
原則として `[サークル名・発売元・カテゴリ・品番] タイトル (バージョン情報)` の形式に整形してください。
|
||||||
|
|
||||||
|
### 4.2 本文最上部へのワンクリックコピー枠の配置
|
||||||
|
本文(SummaryHtml)の先頭に、クリックするだけで文字列全体が選択(`onclick="this.select();"`)される入力欄を必ず配置してください:
|
||||||
|
```html
|
||||||
|
<div style="margin-bottom: 16px; background-color: #f8f9fa; border: 1px solid #ced4da; border-radius: 6px; padding: 10px;">
|
||||||
|
<div style="font-size: 11px; color: #6c757d; font-weight: bold; margin-bottom: 4px;">📁 フォルダ名用タイトル(クリックで全選択)</div>
|
||||||
|
<input type="text" readonly value="{WebUtility.HtmlEncode(cleanTitle)}" onclick="this.select();" style="width: 100%; padding: 6px 10px; font-size: 13px; font-family: Consolas, monospace; background-color: #ffffff; border: 1px solid #adb5bd; border-radius: 4px; box-sizing: border-box; cursor: pointer; color: #212529;" />
|
||||||
|
</div>
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 5. ダウンロードリンクの直リンク化および直下グリッド配置規則(必須)
|
||||||
|
|
||||||
|
### 5.1 直リンク化の徹底
|
||||||
|
- 外部ストレージ・アップローダーへのリンクは、中継短縮URL(adfly等)や不要なサイト内中継ページを可能な限りバイパス・自動解決し、**目的のストレージ(Mediafire, Mega, Rapidgator, Katfile, Nitroflare, Frdl 等)のダウンロードページURLを直接出力してください**。
|
||||||
|
- ボタンではなく、RSSリーダー上で確実にクリック遷移可能な標準の `<a href="...">` タグで出力してください。
|
||||||
|
|
||||||
|
### 5.2 タイトル直下へのグリッドレイアウト配置
|
||||||
|
- ダウンロードリンクは本文の奥深くに埋もれさせず、**タイトル・フォルダ名コピー枠のすぐ直下に配置してください**。
|
||||||
|
- 1行に押し込めず、押しやすいボタングリッド(`display: flex; flex-wrap: wrap; gap: 8px;`)として並べてください。
|
||||||
|
- プロバイダー別にブランドカラーを設定してください(例: Rapidgator=青 `#1976d2`, Katfile=オレンジ `#f57c00`, Nitroflare=赤 `#d32f2f`, Frdl=緑 `#388e3c`, Mediafire=紺 `#00539b`)。
|
||||||
|
- 分割ファイルの場合は、ファイルパート番号(`Part 1`, `Part 2` 等)を自動判定してボタンに表記してください。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 6. カバー画像表示規則(必須)
|
||||||
|
|
||||||
|
- 記事内のカバー画像・サムネイル(Pixhost, TurboImageHost, ブログ内画像等)は、本文中央にセンタリング配置してください。
|
||||||
|
- サムネイル画像をクリックした際、高解像度の元画像ページ(例: Pixhost の `show` ページ等)を別タブで開けるようにアンカータグ(`<a href="元画像URL" target="_blank"><img src="サムネイルURL" /></a>`)でラップしてください。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 7. 既存XMLキャッシュとの連携および差分マージ規則(必須)
|
||||||
|
|
||||||
|
- 各フィード処理では、起動時に該当ドメインサブディレクトリ内の既存 XML を読み込む `LoadExistingEntries` を実装してください。
|
||||||
|
- 最新フォーマット識別タグ(例: `domain-format-vX`)を持つ記事は解析処理をスキップして高速に再利用してください。
|
||||||
|
- サイト側の最新一覧から押し出された過去記事も、重複排除(URLおよびGUIDによるチェック)を行った上でマージし、フィード全体として最大件数(50〜100件程度)を安定して保持してください。
|
||||||
@@ -0,0 +1,248 @@
|
|||||||
|
using AngleSharp.Html.Parser;
|
||||||
|
using rss_generator.Class.Common;
|
||||||
|
using System.ServiceModel.Syndication;
|
||||||
|
using System.Text;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
|
namespace rss_generator.Class.AnigeSokuhou;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// アニゲー速報VIP (http://www.anige-sokuhouvip.com/) のフィードを取得・再構成し、
|
||||||
|
/// 記事URLに基づいた一意なGUIDを割り当てたRSSフィードを生成するクラスです。
|
||||||
|
/// FreshRSS等での同一記事の重複登録を防止します。
|
||||||
|
/// </summary>
|
||||||
|
internal static class anige_sokuhouvip
|
||||||
|
{
|
||||||
|
#region "□定数(Private)"
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 元となるアニゲー速報VIPのRSS 1.0 (RDF) フィードURL
|
||||||
|
/// </summary>
|
||||||
|
private const string FeedUrl = "http://www.anige-sokuhouvip.com/?xml";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// アニゲー速報VIPのトップページURL
|
||||||
|
/// </summary>
|
||||||
|
private const string SiteUrl = "http://www.anige-sokuhouvip.com/";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// フィードタイトル
|
||||||
|
/// </summary>
|
||||||
|
private const string FeedTitle = "アニゲー速報";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// フィード説明文
|
||||||
|
/// </summary>
|
||||||
|
private const string FeedDescription = "アニゲー速報のRSSフィード";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 出力先XMLファイル名
|
||||||
|
/// </summary>
|
||||||
|
private const string OutputFileName = "anige_sokuhouvip.xml";
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region "□メソッド(Public)"
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// アニゲー速報VIPのフィードを取得し、URLから一意のGUIDを設定したRSS 2.0フィードを非同期で生成・出力します。
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="client">HTTPリクエストに使用するHttpClient</param>
|
||||||
|
/// <returns>非同期タスク</returns>
|
||||||
|
public static async Task CreateRSSAsync(HttpClient client)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// 1. 元フィード (RSS 1.0 / RDF) の取得
|
||||||
|
using var response = await client.GetAsync(FeedUrl);
|
||||||
|
response.EnsureSuccessStatusCode();
|
||||||
|
|
||||||
|
using var stream = await response.Content.ReadAsStreamAsync();
|
||||||
|
var xdoc = await XDocument.LoadAsync(stream, LoadOptions.None, CancellationToken.None);
|
||||||
|
|
||||||
|
var root = xdoc.Root;
|
||||||
|
if (root == null)
|
||||||
|
{
|
||||||
|
LogManager.AddLog("[警告] 【anige_sokuhouvip】 XMLルート要素が存在しません。");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 名前空間の定義
|
||||||
|
XNamespace rss = "http://purl.org/rss/1.0/";
|
||||||
|
XNamespace rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
|
||||||
|
XNamespace dc = "http://purl.org/dc/elements/1.1/";
|
||||||
|
XNamespace content = "http://purl.org/rss/1.0/modules/content/";
|
||||||
|
|
||||||
|
// <item> 要素の一覧取得(名前空間付き、またはフォールバック)
|
||||||
|
var itemElements = root.Elements(rss + "item");
|
||||||
|
if (!itemElements.Any())
|
||||||
|
{
|
||||||
|
itemElements = root.Descendants().Where(e => e.Name.LocalName == "item");
|
||||||
|
}
|
||||||
|
|
||||||
|
var items = new List<SyndicationItem>();
|
||||||
|
var seenUrls = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
||||||
|
|
||||||
|
foreach (var itemElem in itemElements)
|
||||||
|
{
|
||||||
|
var link = itemElem.Element(rss + "link")?.Value?.Trim()
|
||||||
|
?? itemElem.Attribute(rdf + "about")?.Value?.Trim()
|
||||||
|
?? itemElem.Elements().FirstOrDefault(e => e.Name.LocalName == "link")?.Value?.Trim()
|
||||||
|
?? string.Empty;
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(link))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 同一フィード内のURL重複を除外
|
||||||
|
if (!seenUrls.Add(link))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var title = itemElem.Element(rss + "title")?.Value?.Trim()
|
||||||
|
?? itemElem.Elements().FirstOrDefault(e => e.Name.LocalName == "title")?.Value?.Trim()
|
||||||
|
?? "タイトルなし";
|
||||||
|
|
||||||
|
// 公開日時の解析(ISO 8601形式: 例 2026-10-22T09:45:33+09:00)
|
||||||
|
var dateStr = itemElem.Element(dc + "date")?.Value?.Trim()
|
||||||
|
?? itemElem.Elements().FirstOrDefault(e => e.Name.LocalName == "date")?.Value?.Trim();
|
||||||
|
var itemDate = DateTimeOffset.Now;
|
||||||
|
if (!string.IsNullOrWhiteSpace(dateStr) && DateTimeOffset.TryParse(dateStr, out var parsedDate))
|
||||||
|
{
|
||||||
|
itemDate = parsedDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 記事本文・HTMLの取得(content:encoded 優先、無ければ description)
|
||||||
|
var rawBodyHtml = itemElem.Element(content + "encoded")?.Value
|
||||||
|
?? itemElem.Elements().FirstOrDefault(e => e.Name.LocalName == "encoded")?.Value
|
||||||
|
?? itemElem.Element(rss + "description")?.Value
|
||||||
|
?? itemElem.Elements().FirstOrDefault(e => e.Name.LocalName == "description")?.Value
|
||||||
|
?? string.Empty;
|
||||||
|
|
||||||
|
var formattedBody = FormatHtmlBody(rawBodyHtml, link, title);
|
||||||
|
|
||||||
|
// URLから一意のGUIDを生成(他フィードと同様にSHA512ハッシュによる一意識別子)
|
||||||
|
var guid = CmnUtil.CreateGuid(link);
|
||||||
|
var itemUri = new Uri(link);
|
||||||
|
|
||||||
|
var syndicationItem = new SyndicationItem(
|
||||||
|
title,
|
||||||
|
string.Empty,
|
||||||
|
itemUri,
|
||||||
|
guid,
|
||||||
|
itemDate
|
||||||
|
)
|
||||||
|
{
|
||||||
|
PublishDate = itemDate,
|
||||||
|
LastUpdatedTime = itemDate,
|
||||||
|
Summary = new TextSyndicationContent(formattedBody, TextSyndicationContentKind.Html)
|
||||||
|
};
|
||||||
|
|
||||||
|
// カテゴリ(dc:subject)
|
||||||
|
var subject = itemElem.Element(dc + "subject")?.Value?.Trim()
|
||||||
|
?? itemElem.Elements().FirstOrDefault(e => e.Name.LocalName == "subject")?.Value?.Trim();
|
||||||
|
if (!string.IsNullOrWhiteSpace(subject))
|
||||||
|
{
|
||||||
|
syndicationItem.Categories.Add(new SyndicationCategory(subject));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 作成者(dc:creator)
|
||||||
|
var creator = itemElem.Element(dc + "creator")?.Value?.Trim()
|
||||||
|
?? itemElem.Elements().FirstOrDefault(e => e.Name.LocalName == "creator")?.Value?.Trim();
|
||||||
|
if (!string.IsNullOrWhiteSpace(creator))
|
||||||
|
{
|
||||||
|
syndicationItem.Authors.Add(new SyndicationPerson { Name = creator });
|
||||||
|
}
|
||||||
|
|
||||||
|
items.Add(syndicationItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
var feed = new SyndicationFeed(FeedTitle, FeedDescription, new Uri(SiteUrl))
|
||||||
|
{
|
||||||
|
Items = items,
|
||||||
|
Language = "ja-JP",
|
||||||
|
LastUpdatedTime = DateTimeOffset.Now
|
||||||
|
};
|
||||||
|
|
||||||
|
// RSS 2.0 形式で出力(filter24Hours: false で全件維持、embedBase64: false で画像リンク維持)
|
||||||
|
await CmnUtil.ExportXMLFileAsync(OutputFileName, feed, client, embedBase64: false, filter24Hours: false);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
LogManager.AddLog($"[エラー] 【anige_sokuhouvip】 フィード生成失敗: {ex.Message}");
|
||||||
|
CmnUtil.PrintCallStackToEvent(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region "□メソッド(Private)"
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 記事HTMLのリンク属性や画像属性を調整し、整形したHTML文字列を生成します。
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="rawHtml">元のHTML文字列</param>
|
||||||
|
/// <param name="articleUrl">記事のURL</param>
|
||||||
|
/// <param name="articleTitle">記事のタイトル</param>
|
||||||
|
/// <returns>整形後のHTML文字列</returns>
|
||||||
|
private static string FormatHtmlBody(string rawHtml, string articleUrl, string articleTitle)
|
||||||
|
{
|
||||||
|
var sb = new StringBuilder();
|
||||||
|
sb.Append($@"<div><a href=""{articleUrl}"" target=""_blank"" rel=""noopener noreferrer"" referrerpolicy=""no-referrer"">{articleTitle}</a></div>");
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(rawHtml))
|
||||||
|
{
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var parser = new HtmlParser();
|
||||||
|
var document = parser.ParseDocument($"<div id=\"content-root\">{rawHtml}</div>");
|
||||||
|
var rootDiv = document.QuerySelector("#content-root");
|
||||||
|
|
||||||
|
if (rootDiv != null)
|
||||||
|
{
|
||||||
|
// 不要なスクリプトタグの除去
|
||||||
|
var scriptTags = rootDiv.QuerySelectorAll("script").ToList();
|
||||||
|
foreach (var script in scriptTags)
|
||||||
|
{
|
||||||
|
script.Remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
// リンクタグの属性調整
|
||||||
|
foreach (var a in rootDiv.QuerySelectorAll("a"))
|
||||||
|
{
|
||||||
|
a.SetAttribute("target", "_blank");
|
||||||
|
a.SetAttribute("rel", "noopener noreferrer");
|
||||||
|
a.SetAttribute("referrerpolicy", "no-referrer");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 画像タグの属性調整
|
||||||
|
foreach (var img in rootDiv.QuerySelectorAll("img"))
|
||||||
|
{
|
||||||
|
img.SetAttribute("referrerpolicy", "no-referrer");
|
||||||
|
var currentStyle = img.GetAttribute("style") ?? string.Empty;
|
||||||
|
if (!currentStyle.Contains("max-width", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
img.SetAttribute("style", $"{currentStyle}; max-width: 100%; height: auto;".Trim(';', ' '));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.Append(rootDiv.InnerHtml);
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// パース失敗時は元のHTMLをフォールバックとして追記
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.Append(rawHtml);
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
using AngleSharp.Dom;
|
using AngleSharp.Dom;
|
||||||
using AngleSharp.Html.Dom;
|
using AngleSharp.Html.Dom;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@@ -46,14 +46,7 @@ internal class aurahentai
|
|||||||
// 既存の aurahentai.xml から過去に出力した各記事の内容(タイトル・本文・日時)を読み込む
|
// 既存の aurahentai.xml から過去に出力した各記事の内容(タイトル・本文・日時)を読み込む
|
||||||
var existingEntries = LoadExistingEntries("aurahentai.xml");
|
var existingEntries = LoadExistingEntries("aurahentai.xml");
|
||||||
|
|
||||||
// 外部からセッションが渡されなかった場合は自前で作成
|
sessionId ??= CmnUtil.SharedFlareSolverrSessionId;
|
||||||
bool ownSession = sessionId == null;
|
|
||||||
if (ownSession)
|
|
||||||
{
|
|
||||||
sessionId = await CmnUtil.CreateFlareSolverrSession(client);
|
|
||||||
}
|
|
||||||
try
|
|
||||||
{
|
|
||||||
for (int pageId = 1; pageId <= 5; pageId++)
|
for (int pageId = 1; pageId <= 5; pageId++)
|
||||||
{
|
{
|
||||||
var pageURL = $"{baseURL}?page={pageId}";
|
var pageURL = $"{baseURL}?page={pageId}";
|
||||||
@@ -66,14 +59,6 @@ internal class aurahentai
|
|||||||
var newItems = await CreateFeedItemsFromListPageAsync(client, sessionId, document, pageId, existingEntries);
|
var newItems = await CreateFeedItemsFromListPageAsync(client, sessionId, document, pageId, existingEntries);
|
||||||
items.AddRange(newItems);
|
items.AddRange(newItems);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
if (ownSession && sessionId != null)
|
|
||||||
{
|
|
||||||
await CmnUtil.DestroyFlareSolverrSession(client, sessionId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ID 重複排除
|
// ID 重複排除
|
||||||
var uniqueItems = items
|
var uniqueItems = items
|
||||||
|
|||||||
@@ -60,13 +60,37 @@ internal class ci_en
|
|||||||
using var response = await client.SendAsync(request);
|
using var response = await client.SendAsync(request);
|
||||||
response.EnsureSuccessStatusCode();
|
response.EnsureSuccessStatusCode();
|
||||||
|
|
||||||
var jsonString = await response.Content.ReadAsStringAsync();
|
// リダイレクト先URLがメンテナンスページであるか検証
|
||||||
using var jsonDoc = JsonDocument.Parse(jsonString);
|
var responseUri = response.RequestMessage?.RequestUri?.ToString() ?? string.Empty;
|
||||||
|
if (responseUri.Contains("maintenance", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
AddLog($"[情報] 【ci_en】 Ci-enは現在システムメンテナンス中です ({responseUri})。メンテナンス完了後に自動再開されます。");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var responseString = await response.Content.ReadAsStringAsync();
|
||||||
|
var trimmedContent = responseString.TrimStart();
|
||||||
|
|
||||||
|
// レスポンスがJSONではなくHTML(メンテナンス画面やログイン画面等)の場合の安全ハンドリング
|
||||||
|
if (trimmedContent.StartsWith('<'))
|
||||||
|
{
|
||||||
|
if (trimmedContent.Contains("メンテナンス") || trimmedContent.Contains("maintenance", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
AddLog("[情報] 【ci_en】 Ci-enは現在システムメンテナンス中です。サービスの再開後に自動取得されます。");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
AddLog("[警告] 【ci_en】 APIからJSONではなくHTMLが返却されました。セッションCookieの有効期限切れ、またはリダイレクトの可能性があります。");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
using var jsonDoc = JsonDocument.Parse(responseString);
|
||||||
|
|
||||||
if (!jsonDoc.RootElement.TryGetProperty("items", out var itemsElem) ||
|
if (!jsonDoc.RootElement.TryGetProperty("items", out var itemsElem) ||
|
||||||
!itemsElem.TryGetProperty("data", out var dataElem))
|
!itemsElem.TryGetProperty("data", out var dataElem))
|
||||||
{
|
{
|
||||||
AddLog("[警告] [ci_en] items.data プロパティが存在しません。");
|
AddLog("[警告] 【ci_en】 items.data プロパティが存在しません。");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -230,7 +254,7 @@ internal class ci_en
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
AddLog($"[エラー] [ci_en]:{ex.Message}");
|
AddLog($"[エラー] 【ci_en】 {ex.Message}");
|
||||||
CmnUtil.PrintCallStackToEvent(ex);
|
CmnUtil.PrintCallStackToEvent(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using AngleSharp;
|
using AngleSharp;
|
||||||
using AngleSharp.Dom;
|
using AngleSharp.Dom;
|
||||||
using AngleSharp.Html.Parser;
|
using AngleSharp.Html.Parser;
|
||||||
using PuppeteerSharp;
|
using PuppeteerSharp;
|
||||||
@@ -427,7 +427,7 @@ public class CmnUtil
|
|||||||
|
|
||||||
int count = feed.Items?.Count() ?? 0;
|
int count = feed.Items?.Count() ?? 0;
|
||||||
string displayFileName = System.IO.Path.GetFileName(filePath);
|
string displayFileName = System.IO.Path.GetFileName(filePath);
|
||||||
LogManager.AddLog($"[情報] {displayFileName} を正常に出力しました (記事数: {count})");
|
LogManager.AddLog($"[情報] 【CmnUtil】 {displayFileName} を正常に出力しました (記事数: {count})");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -459,7 +459,7 @@ public class CmnUtil
|
|||||||
|
|
||||||
int count = feed.Items?.Count() ?? 0;
|
int count = feed.Items?.Count() ?? 0;
|
||||||
string displayFileName = System.IO.Path.GetFileName(filePath);
|
string displayFileName = System.IO.Path.GetFileName(filePath);
|
||||||
LogManager.AddLog($"[情報] {displayFileName} を正常に出力しました (記事数: {count})");
|
LogManager.AddLog($"[情報] 【CmnUtil】 {displayFileName} を正常に出力しました (記事数: {count})");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -482,7 +482,7 @@ public class CmnUtil
|
|||||||
{
|
{
|
||||||
// 404の場合などのログをここに書くことも可能
|
// 404の場合などのログをここに書くことも可能
|
||||||
//AddLog($"[HTTP Error] Status Code: {response.StatusCode} for {url}");
|
//AddLog($"[HTTP Error] Status Code: {response.StatusCode} for {url}");
|
||||||
LogManager.AddLog($"[HTTP Error] Status Code: {response.StatusCode} for {url}");
|
LogManager.AddLog($"[エラー] 【CmnUtil】 HTTP Error Status Code: {response.StatusCode} for {url}");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -492,7 +492,7 @@ public class CmnUtil
|
|||||||
catch (HttpRequestException ex)
|
catch (HttpRequestException ex)
|
||||||
{
|
{
|
||||||
// ネットワーク不通やタイムアウトなどの例外処理
|
// ネットワーク不通やタイムアウトなどの例外処理
|
||||||
LogManager.AddLog($"[Network Error] {ex.Message}");
|
LogManager.AddLog($"[エラー] 【CmnUtil】 Network Error {ex.Message}");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
@@ -600,6 +600,11 @@ public class CmnUtil
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private static readonly SemaphoreSlim FlareSolverrSemaphore = new(1, 1);
|
private static readonly SemaphoreSlim FlareSolverrSemaphore = new(1, 1);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// アプリケーション全体で共有・使い回す FlareSolverr セッションID
|
||||||
|
/// </summary>
|
||||||
|
public static string? SharedFlareSolverrSessionId { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// FlareSolverr 経由で対象 URL の HTML を取得し、AngleSharp の IDocument を生成して返します。
|
/// FlareSolverr 経由で対象 URL の HTML を取得し、AngleSharp の IDocument を生成して返します。
|
||||||
/// 排他制御および最大3回の自動リトライ(セッション無効化フォールバック・待機付き)を備えています。
|
/// 排他制御および最大3回の自動リトライ(セッション無効化フォールバック・待機付き)を備えています。
|
||||||
@@ -621,7 +626,7 @@ public class CmnUtil
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
const int maxRetries = 3;
|
const int maxRetries = 3;
|
||||||
string? currentSession = session;
|
string? currentSession = session ?? SharedFlareSolverrSessionId;
|
||||||
|
|
||||||
for (int attempt = 1; attempt <= maxRetries; attempt++)
|
for (int attempt = 1; attempt <= maxRetries; attempt++)
|
||||||
{
|
{
|
||||||
@@ -652,7 +657,7 @@ public class CmnUtil
|
|||||||
// セッション不整合による500の可能性があるため、次回はセッションなしでリトライ
|
// セッション不整合による500の可能性があるため、次回はセッションなしでリトライ
|
||||||
if (currentSession != null)
|
if (currentSession != null)
|
||||||
{
|
{
|
||||||
LogManager.AddLog($"[情報] セッション {currentSession} を解除して次回セッションなしで再試行します。");
|
LogManager.AddLog($"[情報] 【CmnUtil】 セッション {currentSession} を解除して次回セッションなしで再試行します。");
|
||||||
currentSession = null;
|
currentSession = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -674,7 +679,7 @@ public class CmnUtil
|
|||||||
if (!string.Equals(flareResponse.Status, "ok", StringComparison.OrdinalIgnoreCase))
|
if (!string.Equals(flareResponse.Status, "ok", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
string errorMsg = $"FlareSolverr エラー (Status: {flareResponse.Status}, Message: {flareResponse.Message}): {pageURL}";
|
string errorMsg = $"FlareSolverr エラー (Status: {flareResponse.Status}, Message: {flareResponse.Message}): {pageURL}";
|
||||||
LogManager.AddLog($"[警告] {errorMsg}");
|
LogManager.AddLog($"[警告] 【CmnUtil】 {errorMsg}");
|
||||||
|
|
||||||
if (attempt < maxRetries)
|
if (attempt < maxRetries)
|
||||||
{
|
{
|
||||||
@@ -699,7 +704,7 @@ public class CmnUtil
|
|||||||
}
|
}
|
||||||
catch (Exception ex) when (attempt < maxRetries && ex is not OperationCanceledException)
|
catch (Exception ex) when (attempt < maxRetries && ex is not OperationCanceledException)
|
||||||
{
|
{
|
||||||
LogManager.AddLog($"[警告] FlareSolverr リクエスト再試行 (試行 {attempt}/{maxRetries}, URL: {pageURL}): {ex.Message}");
|
LogManager.AddLog($"[警告] 【CmnUtil】 FlareSolverr リクエスト再試行 (試行 {attempt}/{maxRetries}, URL: {pageURL}): {ex.Message}");
|
||||||
currentSession = null;
|
currentSession = null;
|
||||||
await Task.Delay(attempt * 2500);
|
await Task.Delay(attempt * 2500);
|
||||||
}
|
}
|
||||||
@@ -734,7 +739,7 @@ public class CmnUtil
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
const int maxRetries = 3;
|
const int maxRetries = 3;
|
||||||
string? currentSession = session;
|
string? currentSession = session ?? SharedFlareSolverrSessionId;
|
||||||
|
|
||||||
for (int attempt = 1; attempt <= maxRetries; attempt++)
|
for (int attempt = 1; attempt <= maxRetries; attempt++)
|
||||||
{
|
{
|
||||||
@@ -764,7 +769,7 @@ public class CmnUtil
|
|||||||
|
|
||||||
if (currentSession != null)
|
if (currentSession != null)
|
||||||
{
|
{
|
||||||
LogManager.AddLog($"[情報] セッション {currentSession} を解除して次回セッションなしで再試行します。");
|
LogManager.AddLog($"[情報] 【CmnUtil】 セッション {currentSession} を解除して次回セッションなしで再試行します。");
|
||||||
currentSession = null;
|
currentSession = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -786,7 +791,7 @@ public class CmnUtil
|
|||||||
if (!string.Equals(flareResponse.Status, "ok", StringComparison.OrdinalIgnoreCase))
|
if (!string.Equals(flareResponse.Status, "ok", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
string errorMsg = $"FlareSolverr エラー (Status: {flareResponse.Status}, Message: {flareResponse.Message}): {url}";
|
string errorMsg = $"FlareSolverr エラー (Status: {flareResponse.Status}, Message: {flareResponse.Message}): {url}";
|
||||||
LogManager.AddLog($"[警告] {errorMsg}");
|
LogManager.AddLog($"[警告] 【CmnUtil】 {errorMsg}");
|
||||||
|
|
||||||
if (attempt < maxRetries)
|
if (attempt < maxRetries)
|
||||||
{
|
{
|
||||||
@@ -811,7 +816,7 @@ public class CmnUtil
|
|||||||
}
|
}
|
||||||
catch (Exception ex) when (attempt < maxRetries && ex is not OperationCanceledException)
|
catch (Exception ex) when (attempt < maxRetries && ex is not OperationCanceledException)
|
||||||
{
|
{
|
||||||
LogManager.AddLog($"[警告] FlareSolverr リクエスト再試行 (試行 {attempt}/{maxRetries}, URL: {url}): {ex.Message}");
|
LogManager.AddLog($"[警告] 【CmnUtil】 FlareSolverr リクエスト再試行 (試行 {attempt}/{maxRetries}, URL: {url}): {ex.Message}");
|
||||||
currentSession = null;
|
currentSession = null;
|
||||||
await Task.Delay(attempt * 2500);
|
await Task.Delay(attempt * 2500);
|
||||||
}
|
}
|
||||||
@@ -849,7 +854,7 @@ public class CmnUtil
|
|||||||
Cmd = "request.get",
|
Cmd = "request.get",
|
||||||
Url = url,
|
Url = url,
|
||||||
MaxTimeout = maxTimeout,
|
MaxTimeout = maxTimeout,
|
||||||
Session = session
|
Session = session ?? SharedFlareSolverrSessionId
|
||||||
};
|
};
|
||||||
|
|
||||||
using var request = new HttpRequestMessage(HttpMethod.Post, flareSolverrEndpoint)
|
using var request = new HttpRequestMessage(HttpMethod.Post, flareSolverrEndpoint)
|
||||||
@@ -874,7 +879,7 @@ public class CmnUtil
|
|||||||
if (!string.Equals(flareResponse.Status, "ok", StringComparison.OrdinalIgnoreCase))
|
if (!string.Equals(flareResponse.Status, "ok", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
string errorMsg = $"FlareSolverr エラー (Status: {flareResponse.Status}, Message: {flareResponse.Message}): {url}";
|
string errorMsg = $"FlareSolverr エラー (Status: {flareResponse.Status}, Message: {flareResponse.Message}): {url}";
|
||||||
LogManager.AddLog($"[エラー] {errorMsg}");
|
LogManager.AddLog($"[エラー] 【CmnUtil】 {errorMsg}");
|
||||||
throw new InvalidOperationException(errorMsg);
|
throw new InvalidOperationException(errorMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -906,7 +911,7 @@ public class CmnUtil
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
LogManager.AddLog($"[エラー] FlareSolverr フィード {url} の取得に失敗: {ex.Message}");
|
LogManager.AddLog($"[エラー] 【CmnUtil】 FlareSolverr フィード {url} の取得に失敗: {ex.Message}");
|
||||||
PrintCallStackToEvent(ex);
|
PrintCallStackToEvent(ex);
|
||||||
return Enumerable.Empty<SyndicationItem>();
|
return Enumerable.Empty<SyndicationItem>();
|
||||||
}
|
}
|
||||||
@@ -1118,7 +1123,7 @@ public class CmnUtil
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
LogManager.AddLog($"[エラー] {url} の取得に失敗: {ex.Message}");
|
LogManager.AddLog($"[エラー] 【CmnUtil】 {url} の取得に失敗: {ex.Message}");
|
||||||
return Enumerable.Empty<SyndicationItem>();
|
return Enumerable.Empty<SyndicationItem>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1371,7 +1376,7 @@ public class CmnUtil
|
|||||||
if (process.ExitCode != 0)
|
if (process.ExitCode != 0)
|
||||||
{
|
{
|
||||||
// エラー時は StandardError と StandardOutput の両方をログに出力する
|
// エラー時は StandardError と StandardOutput の両方をログに出力する
|
||||||
LogManager.AddLog($"[エラー] コマンド実行失敗 (ExitCode: {process.ExitCode}, Cmd: {command} {arguments})\n" +
|
LogManager.AddLog($"[エラー] 【CmnUtil】 コマンド実行失敗 (ExitCode: {process.ExitCode}, Cmd: {command} {arguments})\n" +
|
||||||
$"STDERR: {(string.IsNullOrEmpty(error) ? "(なし)" : error)}\n" +
|
$"STDERR: {(string.IsNullOrEmpty(error) ? "(なし)" : error)}\n" +
|
||||||
$"STDOUT: {(string.IsNullOrEmpty(output) ? "(なし)" : output)}");
|
$"STDOUT: {(string.IsNullOrEmpty(output) ? "(なし)" : output)}");
|
||||||
}
|
}
|
||||||
@@ -1385,7 +1390,7 @@ public class CmnUtil
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LogManager.AddLog($"[エラー] プロセスの起動に失敗しました: {command}");
|
LogManager.AddLog($"[エラー] 【CmnUtil】 プロセスの起動に失敗しました: {command}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
@@ -91,11 +91,11 @@ public class ExternalConfigWatcher : IDisposable
|
|||||||
_watcher.Created += OnFileEvent;
|
_watcher.Created += OnFileEvent;
|
||||||
_watcher.Renamed += (s, e) => OnFileEvent(s, new FileSystemEventArgs(WatcherChangeTypes.Changed, watchDir, e.Name));
|
_watcher.Renamed += (s, e) => OnFileEvent(s, new FileSystemEventArgs(WatcherChangeTypes.Changed, watchDir, e.Name));
|
||||||
|
|
||||||
LogManager.AddLog($"[情報] FileSystemWatcher による設定ファイル監視を開始しました: {watchDir}");
|
LogManager.AddLog($"[情報] 【ExternalConfigWatcher】 FileSystemWatcher による設定ファイル監視を開始しました: {watchDir}");
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
LogManager.AddLog($"[警告] FileSystemWatcher の初期化に失敗(ポーリングのみで監視を継続します): {ex.Message}");
|
LogManager.AddLog($"[警告] 【ExternalConfigWatcher】 FileSystemWatcher の初期化に失敗(ポーリングのみで監視を継続します): {ex.Message}");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. バックグラウンドポーリングタスク(Dockerバインドマウント環境でも確実に検知するため2.5秒間隔で更新日時を走査)
|
// 2. バックグラウンドポーリングタスク(Dockerバインドマウント環境でも確実に検知するため2.5秒間隔で更新日時を走査)
|
||||||
@@ -216,7 +216,7 @@ public class ExternalConfigWatcher : IDisposable
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
LogManager.AddLog($"[エラー] 外部設定ファイル監視ループ例外: {ex.Message}");
|
LogManager.AddLog($"[エラー] 【ExternalConfigWatcher】 外部設定ファイル監視ループ例外: {ex.Message}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -231,7 +231,7 @@ public class ExternalConfigWatcher : IDisposable
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
LogManager.AddLog($"[情報] 外部設定ファイルの変更を検知しました: {fileName} -> 【{handler.DisplayName}】のRSS生成を開始します");
|
LogManager.AddLog($"[情報] 【ExternalConfigWatcher】 外部設定ファイルの変更を検知しました: {fileName} -> 【{handler.DisplayName}】のRSS生成を開始します");
|
||||||
|
|
||||||
// 定期実行または他トリガーとの排他ロックを取得
|
// 定期実行または他トリガーとの排他ロックを取得
|
||||||
await _executionLock.WaitAsync();
|
await _executionLock.WaitAsync();
|
||||||
@@ -247,7 +247,7 @@ public class ExternalConfigWatcher : IDisposable
|
|||||||
await handler.Action(client);
|
await handler.Action(client);
|
||||||
|
|
||||||
sw.Stop();
|
sw.Stop();
|
||||||
LogManager.AddLog($"[情報] 【{handler.DisplayName}】 外部設定変更に伴うRSS生成完了 ({sw.Elapsed.TotalSeconds:0.##}秒)");
|
LogManager.AddLog($"[情報] 【ExternalConfigWatcher】 【{handler.DisplayName}】 外部設定変更に伴うRSS生成完了 ({sw.Elapsed.TotalSeconds:0.##}秒)");
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -112,13 +112,13 @@ public static class ExternalFeedConfigManager
|
|||||||
{
|
{
|
||||||
if (defaultTargets != null && defaultTargets.Any())
|
if (defaultTargets != null && defaultTargets.Any())
|
||||||
{
|
{
|
||||||
LogManager.AddLog($"[情報] 設定ファイルが存在しないため、デフォルト設定を書き出します: {filePath}");
|
LogManager.AddLog($"[情報] 【ExternalFeedConfigManager】 設定ファイルが存在しないため、デフォルト設定を書き出します: {filePath}");
|
||||||
await SaveTargetsAsync(fileName, defaultTargets);
|
await SaveTargetsAsync(fileName, defaultTargets);
|
||||||
var defaults = defaultTargets.ToList();
|
var defaults = defaultTargets.ToList();
|
||||||
return onlyEnabled ? defaults.Where(t => t.Enabled).ToList() : defaults;
|
return onlyEnabled ? defaults.Where(t => t.Enabled).ToList() : defaults;
|
||||||
}
|
}
|
||||||
|
|
||||||
LogManager.AddLog($"[警告] 設定ファイルが見つかりません: {filePath}");
|
LogManager.AddLog($"[警告] 【ExternalFeedConfigManager】 設定ファイルが見つかりません: {filePath}");
|
||||||
return new List<T>();
|
return new List<T>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,22 +127,22 @@ public static class ExternalFeedConfigManager
|
|||||||
|
|
||||||
if (items == null)
|
if (items == null)
|
||||||
{
|
{
|
||||||
LogManager.AddLog($"[警告] 設定ファイルの内容が空または不正です: {filePath}");
|
LogManager.AddLog($"[警告] 【ExternalFeedConfigManager】 設定ファイルの内容が空または不正です: {filePath}");
|
||||||
return new List<T>();
|
return new List<T>();
|
||||||
}
|
}
|
||||||
|
|
||||||
LogManager.AddLog($"[情報] 外部設定ファイル読み込み完了: {fileName} ({items.Count}件)");
|
LogManager.AddLog($"[情報] 【ExternalFeedConfigManager】 外部設定ファイル読み込み完了: {fileName} ({items.Count}件)");
|
||||||
return onlyEnabled ? items.Where(t => t.Enabled).ToList() : items;
|
return onlyEnabled ? items.Where(t => t.Enabled).ToList() : items;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
LogManager.AddLog($"[エラー] 外部設定ファイル読み込み失敗 ({filePath}): {ex.Message}");
|
LogManager.AddLog($"[エラー] 【ExternalFeedConfigManager】 外部設定ファイル読み込み失敗 ({filePath}): {ex.Message}");
|
||||||
CmnUtil.PrintCallStackToEvent(ex);
|
CmnUtil.PrintCallStackToEvent(ex);
|
||||||
|
|
||||||
// 読み込みに失敗した場合、デフォルトが指定されていればフォールバック
|
// 読み込みに失敗した場合、デフォルトが指定されていればフォールバック
|
||||||
if (defaultTargets != null && defaultTargets.Any())
|
if (defaultTargets != null && defaultTargets.Any())
|
||||||
{
|
{
|
||||||
LogManager.AddLog($"[情報] デフォルト設定をフォールバックとして使用します: {fileName}");
|
LogManager.AddLog($"[情報] 【ExternalFeedConfigManager】 デフォルト設定をフォールバックとして使用します: {fileName}");
|
||||||
var defaults = defaultTargets.ToList();
|
var defaults = defaultTargets.ToList();
|
||||||
return onlyEnabled ? defaults.Where(t => t.Enabled).ToList() : defaults;
|
return onlyEnabled ? defaults.Where(t => t.Enabled).ToList() : defaults;
|
||||||
}
|
}
|
||||||
@@ -168,6 +168,6 @@ public static class ExternalFeedConfigManager
|
|||||||
string filePath = Path.Combine(dir, fileName);
|
string filePath = Path.Combine(dir, fileName);
|
||||||
using var stream = File.Create(filePath);
|
using var stream = File.Create(filePath);
|
||||||
await JsonSerializer.SerializeAsync(stream, targets, JsonOptions);
|
await JsonSerializer.SerializeAsync(stream, targets, JsonOptions);
|
||||||
LogManager.AddLog($"[情報] 設定ファイルを保存しました: {filePath}");
|
LogManager.AddLog($"[情報] 【ExternalFeedConfigManager】 設定ファイルを保存しました: {filePath}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@@ -8,6 +8,7 @@ using rss_generator.Class.HentaiPaw;
|
|||||||
using rss_generator.Class.HitomiLa;
|
using rss_generator.Class.HitomiLa;
|
||||||
using rss_generator.Class.MissAV;
|
using rss_generator.Class.MissAV;
|
||||||
using rss_generator.Class.MissAV123;
|
using rss_generator.Class.MissAV123;
|
||||||
|
using rss_generator.Class.Skebetter;
|
||||||
using rss_generator.Class.SpankBang;
|
using rss_generator.Class.SpankBang;
|
||||||
using rss_generator.Class.YahooBaseball;
|
using rss_generator.Class.YahooBaseball;
|
||||||
|
|
||||||
@@ -26,7 +27,7 @@ internal static class FlareSolverrFeedManager
|
|||||||
/// <param name="client">HttpClient インスタンス</param>
|
/// <param name="client">HttpClient インスタンス</param>
|
||||||
public static async Task CreateAllRSSAsync(HttpClient client)
|
public static async Task CreateAllRSSAsync(HttpClient client)
|
||||||
{
|
{
|
||||||
LogManager.AddLog("[情報] FlareSolverr フィード生成(単一セッション順次実行)を開始します");
|
LogManager.AddLog("[情報] 【FlareSolverrFeedManager】 FlareSolverr フィード生成(単一セッション順次実行)を開始します");
|
||||||
var sw = Stopwatch.StartNew();
|
var sw = Stopwatch.StartNew();
|
||||||
string? sessionId = null;
|
string? sessionId = null;
|
||||||
|
|
||||||
@@ -37,7 +38,8 @@ internal static class FlareSolverrFeedManager
|
|||||||
|
|
||||||
// 1. 全タスク共通の単一 FlareSolverr セッションを作成(Chromium 1インスタンスのみ起動)
|
// 1. 全タスク共通の単一 FlareSolverr セッションを作成(Chromium 1インスタンスのみ起動)
|
||||||
sessionId = await CmnUtil.CreateFlareSolverrSession(client);
|
sessionId = await CmnUtil.CreateFlareSolverrSession(client);
|
||||||
LogManager.AddLog($"[情報] 共通 FlareSolverr セッションを作成しました (Session: {sessionId ?? "none"})");
|
CmnUtil.SharedFlareSolverrSessionId = sessionId;
|
||||||
|
LogManager.AddLog($"[情報] 【FlareSolverrFeedManager】 共通 FlareSolverr セッションを作成しました (Session: {sessionId ?? "none"})");
|
||||||
|
|
||||||
// 2. メモリ節約のため、1つのセッションを使い回して直列(同期)で順番に実行
|
// 2. メモリ節約のため、1つのセッションを使い回して直列(同期)で順番に実行
|
||||||
// 個別のエラーで全体が止まらないよう各タスクを保護
|
// 個別のエラーで全体が止まらないよう各タスクを保護
|
||||||
@@ -49,7 +51,7 @@ internal static class FlareSolverrFeedManager
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
LogManager.AddLog($"[エラー] [FlareSolverrFeedManager] npb_6 実行失敗: {ex.Message}");
|
LogManager.AddLog($"[エラー] 【FlareSolverrFeedManager】 npb_6 実行失敗: {ex.Message}");
|
||||||
}
|
}
|
||||||
|
|
||||||
// aurahentai
|
// aurahentai
|
||||||
@@ -59,7 +61,7 @@ internal static class FlareSolverrFeedManager
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
LogManager.AddLog($"[エラー] [FlareSolverrFeedManager] aurahentai 実行失敗: {ex.Message}");
|
LogManager.AddLog($"[エラー] 【FlareSolverrFeedManager】 aurahentai 実行失敗: {ex.Message}");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Danbooru rank
|
// Danbooru rank
|
||||||
@@ -69,7 +71,7 @@ internal static class FlareSolverrFeedManager
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
LogManager.AddLog($"[エラー] [FlareSolverrFeedManager] Danbooru.rank 実行失敗: {ex.Message}");
|
LogManager.AddLog($"[エラー] 【FlareSolverrFeedManager】 Danbooru.rank 実行失敗: {ex.Message}");
|
||||||
}
|
}
|
||||||
|
|
||||||
// missav
|
// missav
|
||||||
@@ -79,7 +81,7 @@ internal static class FlareSolverrFeedManager
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
LogManager.AddLog($"[エラー] [FlareSolverrFeedManager] missav 実行失敗: {ex.Message}");
|
LogManager.AddLog($"[エラー] 【FlareSolverrFeedManager】 missav 実行失敗: {ex.Message}");
|
||||||
}
|
}
|
||||||
|
|
||||||
// missav123
|
// missav123
|
||||||
@@ -89,7 +91,7 @@ internal static class FlareSolverrFeedManager
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
LogManager.AddLog($"[エラー] [FlareSolverrFeedManager] missav123 実行失敗: {ex.Message}");
|
LogManager.AddLog($"[エラー] 【FlareSolverrFeedManager】 missav123 実行失敗: {ex.Message}");
|
||||||
}
|
}
|
||||||
|
|
||||||
// hitomi.la
|
// hitomi.la
|
||||||
@@ -99,7 +101,7 @@ internal static class FlareSolverrFeedManager
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
LogManager.AddLog($"[エラー] [FlareSolverrFeedManager] hitomi.la 実行失敗: {ex.Message}");
|
LogManager.AddLog($"[エラー] 【FlareSolverrFeedManager】 hitomi.la 実行失敗: {ex.Message}");
|
||||||
}
|
}
|
||||||
|
|
||||||
// spankbang
|
// spankbang
|
||||||
@@ -109,7 +111,7 @@ internal static class FlareSolverrFeedManager
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
LogManager.AddLog($"[エラー] [FlareSolverrFeedManager] spankbang 実行失敗: {ex.Message}");
|
LogManager.AddLog($"[エラー] 【FlareSolverrFeedManager】 spankbang 実行失敗: {ex.Message}");
|
||||||
}
|
}
|
||||||
|
|
||||||
// hentaipaw (エロモフ)
|
// hentaipaw (エロモフ)
|
||||||
@@ -119,30 +121,41 @@ internal static class FlareSolverrFeedManager
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
LogManager.AddLog($"[エラー] [FlareSolverrFeedManager] hentaipaw 実行失敗: {ex.Message}");
|
LogManager.AddLog($"[エラー] 【FlareSolverrFeedManager】 hentaipaw 実行失敗: {ex.Message}");
|
||||||
|
}
|
||||||
|
|
||||||
|
// skebetter
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await skebetter.CreateRSSAsync(client, sessionId);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
LogManager.AddLog($"[エラー] 【FlareSolverrFeedManager】 skebetter 実行失敗: {ex.Message}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
LogManager.AddLog($"[エラー] [FlareSolverrFeedManager] 共通セッション処理中に例外発生: {ex.Message}");
|
LogManager.AddLog($"[エラー] 【FlareSolverrFeedManager】 共通セッション処理中に例外発生: {ex.Message}");
|
||||||
CmnUtil.PrintCallStackToEvent(ex);
|
CmnUtil.PrintCallStackToEvent(ex);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
// 3. すべて取得完了後にセッション(Chromiumインスタンス)を確実に破棄してメモリ・CPUを完全解放
|
// 3. すべて取得完了後にセッション(Chromiumインスタンス)を確実に破棄してメモリ・CPUを完全解放
|
||||||
|
CmnUtil.SharedFlareSolverrSessionId = null;
|
||||||
// 個別の sessionId 破棄に加え、万が一の残留セッションも一括破棄
|
// 個別の sessionId 破棄に加え、万が一の残留セッションも一括破棄
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await CmnUtil.DestroyAllFlareSolverrSessions(client);
|
await CmnUtil.DestroyAllFlareSolverrSessions(client);
|
||||||
LogManager.AddLog($"[情報] [FlareSolverrFeedManager] FlareSolverr セッションクリーンアップ完了");
|
LogManager.AddLog($"[情報] 【FlareSolverrFeedManager】 FlareSolverr セッションクリーンアップ完了");
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
LogManager.AddLog($"[警告] [FlareSolverrFeedManager] セッションクリーンアップ中にエラー: {ex.Message}");
|
LogManager.AddLog($"[警告] 【FlareSolverrFeedManager】 セッションクリーンアップ中にエラー: {ex.Message}");
|
||||||
}
|
}
|
||||||
|
|
||||||
sw.Stop();
|
sw.Stop();
|
||||||
LogManager.AddLog($"[情報] FlareSolverr フィード生成完了 実行時間:{sw.Elapsed.TotalSeconds:0.##}秒");
|
LogManager.AddLog($"[情報] 【FlareSolverrFeedManager】 FlareSolverr フィード生成完了 実行時間:{sw.Elapsed.TotalSeconds:0.##}秒");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
using AngleSharp.Dom;
|
using AngleSharp.Dom;
|
||||||
using AngleSharp.Html.Dom;
|
using AngleSharp.Html.Dom;
|
||||||
using AngleSharp.Html.Parser;
|
using AngleSharp.Html.Parser;
|
||||||
using System;
|
using System;
|
||||||
@@ -24,14 +24,7 @@ internal class rank
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// 外部からセッションが渡されなかった場合は自前で作成
|
sessionId ??= CmnUtil.SharedFlareSolverrSessionId;
|
||||||
bool ownSession = sessionId == null;
|
|
||||||
if (ownSession)
|
|
||||||
{
|
|
||||||
sessionId = await CmnUtil.CreateFlareSolverrSession(client);
|
|
||||||
}
|
|
||||||
try
|
|
||||||
{
|
|
||||||
// FlareSolverr 経由で Atom フィードアイテムを取得
|
// FlareSolverr 経由で Atom フィードアイテムを取得
|
||||||
var items = await CmnUtil.GetFeedItemsFlareSolverr(client, pageMaster, session: sessionId);
|
var items = await CmnUtil.GetFeedItemsFlareSolverr(client, pageMaster, session: sessionId);
|
||||||
var simplifiedItems = new List<SyndicationItem>();
|
var simplifiedItems = new List<SyndicationItem>();
|
||||||
@@ -62,17 +55,9 @@ internal class rank
|
|||||||
|
|
||||||
await CmnUtil.ExportXMLFileAsync("rank.xml", mergedFeed, client, "danbooru");
|
await CmnUtil.ExportXMLFileAsync("rank.xml", mergedFeed, client, "danbooru");
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
if (ownSession && sessionId != null)
|
|
||||||
{
|
|
||||||
await CmnUtil.DestroyFlareSolverrSession(client, sessionId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
LogManager.AddLog($"[エラー] danbooru:{ex.Message}");
|
LogManager.AddLog($"[エラー] 【Danbooru】 {ex.Message}");
|
||||||
CmnUtil.PrintCallStackToEvent(ex);
|
CmnUtil.PrintCallStackToEvent(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
@@ -35,7 +35,7 @@ internal class e_hentai_ai
|
|||||||
);
|
);
|
||||||
|
|
||||||
// XML ファイルとして出力
|
// XML ファイルとして出力
|
||||||
await CmnUtil.ExportXMLFileAsync("e_hentai_ai.xml", feed, client);
|
await CmnUtil.ExportXMLFileAsync("e_hentai_ai.xml", feed, client, addDir: "e-hentai.org");
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using AngleSharp.Dom;
|
using AngleSharp.Dom;
|
||||||
using AngleSharp.Html.Dom;
|
using AngleSharp.Html.Dom;
|
||||||
using AngleSharp.Html.Parser;
|
using AngleSharp.Html.Parser;
|
||||||
using System;
|
using System;
|
||||||
@@ -65,7 +65,7 @@ internal static class e_hentai_common
|
|||||||
using var response = await client.SendAsync(request);
|
using var response = await client.SendAsync(request);
|
||||||
if (!response.IsSuccessStatusCode)
|
if (!response.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
LogManager.AddLog($"[警告] E-Hentai 一覧取得失敗 (URL={currentUrl}, Status={response.StatusCode})");
|
LogManager.AddLog($"[警告] 【EHentai】 E-Hentai 一覧取得失敗 (URL={currentUrl}, Status={response.StatusCode})");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -247,7 +247,7 @@ internal static class e_hentai_common
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
LogManager.AddLog($"[警告] ギャラリー詳細取得エラー ({gallery.Url}): {ex.Message}");
|
LogManager.AddLog($"[警告] 【EHentai】 ギャラリー詳細取得エラー ({gallery.Url}): {ex.Message}");
|
||||||
}
|
}
|
||||||
|
|
||||||
return new List<string>();
|
return new List<string>();
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
@@ -35,7 +35,7 @@ internal class e_hentai_non_ai
|
|||||||
);
|
);
|
||||||
|
|
||||||
// XML ファイルとして出力
|
// XML ファイルとして出力
|
||||||
await CmnUtil.ExportXMLFileAsync("e_hentai_non_ai.xml", feed, client);
|
await CmnUtil.ExportXMLFileAsync("e_hentai_non_ai.xml", feed, client, addDir: "e-hentai.org");
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using AngleSharp.Dom;
|
using AngleSharp.Dom;
|
||||||
using rss_generator.Class.Common;
|
using rss_generator.Class.Common;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@@ -351,6 +351,8 @@ internal static class MovieEroterestFeedManager
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 新着アイテムと既存アイテムをマージし、重複を排除して公開日時順にソートします。
|
/// 新着アイテムと既存アイテムをマージし、重複を排除して公開日時順にソートします。
|
||||||
|
/// 既存アイテムが存在する場合は前回のPublishDateおよびSummaryHtmlを最優先で維持し、
|
||||||
|
/// FreshRSSで更新されていない記事が未読化するのを防ぎます。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private static List<SyndicationItem> MergeFeedItems(
|
private static List<SyndicationItem> MergeFeedItems(
|
||||||
IEnumerable<SyndicationItem> newItems,
|
IEnumerable<SyndicationItem> newItems,
|
||||||
@@ -369,12 +371,27 @@ internal static class MovieEroterestFeedManager
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. 新着アイテムで上書き・追加(最新の詳細情報を優先)
|
// 2. 新着アイテムを追加(既存アイテムが存在する場合は公開日時および本文HTMLを固定)
|
||||||
foreach (var item in newItems)
|
foreach (var item in newItems)
|
||||||
{
|
{
|
||||||
var key = GetItemKey(item);
|
var key = GetItemKey(item);
|
||||||
if (!string.IsNullOrWhiteSpace(key))
|
if (!string.IsNullOrWhiteSpace(key))
|
||||||
{
|
{
|
||||||
|
if (merged.TryGetValue(key, out var existing))
|
||||||
|
{
|
||||||
|
if (existing.PublishDate != DateTimeOffset.MinValue)
|
||||||
|
{
|
||||||
|
item.PublishDate = existing.PublishDate;
|
||||||
|
}
|
||||||
|
if (existing.LastUpdatedTime != DateTimeOffset.MinValue)
|
||||||
|
{
|
||||||
|
item.LastUpdatedTime = existing.LastUpdatedTime;
|
||||||
|
}
|
||||||
|
if (existing.Summary != null && !string.IsNullOrWhiteSpace(existing.Summary.Text))
|
||||||
|
{
|
||||||
|
item.Summary = new TextSyndicationContent(existing.Summary.Text, TextSyndicationContentKind.Html);
|
||||||
|
}
|
||||||
|
}
|
||||||
merged[key] = item;
|
merged[key] = item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using AngleSharp.Dom;
|
using AngleSharp.Dom;
|
||||||
using rss_generator.Class.Common;
|
using rss_generator.Class.Common;
|
||||||
using rss_generator.Class.Eroterest.Core;
|
using rss_generator.Class.Eroterest.Core;
|
||||||
using System;
|
using System;
|
||||||
@@ -322,12 +322,11 @@ internal static class MovieEroterestVideoParser
|
|||||||
sb.Append("</div>");
|
sb.Append("</div>");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4. メタ情報リスト
|
// 4. メタ情報リスト(相対時間文字列や閲覧クリック数などの変動要素はハッシュ安定のため除外)
|
||||||
sb.Append("<ul style=\"font-size: 0.9em; color: #475569; list-style-type: none; padding-left: 0; margin: 8px 0; line-height: 1.6;\">");
|
sb.Append("<ul style=\"font-size: 0.9em; color: #475569; list-style-type: none; padding-left: 0; margin: 8px 0; line-height: 1.6;\">");
|
||||||
if (info.ArticlePublishDate.HasValue)
|
if (info.ArticlePublishDate.HasValue)
|
||||||
{
|
{
|
||||||
var relSuffix = !string.IsNullOrWhiteSpace(info.RelativeTimeText) ? $" ({WebUtility.HtmlEncode(info.RelativeTimeText)})" : "";
|
sb.Append($"<li>📅 <strong>記事公開日:</strong> {info.ArticlePublishDate.Value:yyyy/MM/dd HH:mm}</li>");
|
||||||
sb.Append($"<li>📅 <strong>記事公開日:</strong> {info.ArticlePublishDate.Value:yyyy/MM/dd HH:mm}{relSuffix}</li>");
|
|
||||||
}
|
}
|
||||||
if (info.VideoPublishDate.HasValue)
|
if (info.VideoPublishDate.HasValue)
|
||||||
{
|
{
|
||||||
@@ -341,10 +340,6 @@ internal static class MovieEroterestVideoParser
|
|||||||
{
|
{
|
||||||
sb.Append($"<li>⏱ <strong>再生時間:</strong> {WebUtility.HtmlEncode(info.Duration)}</li>");
|
sb.Append($"<li>⏱ <strong>再生時間:</strong> {WebUtility.HtmlEncode(info.Duration)}</li>");
|
||||||
}
|
}
|
||||||
if (!string.IsNullOrWhiteSpace(info.ClickCount))
|
|
||||||
{
|
|
||||||
sb.Append($"<li>👁 <strong>人気度:</strong> {WebUtility.HtmlEncode(info.ClickCount)}</li>");
|
|
||||||
}
|
|
||||||
if (info.Actresses.Count > 0)
|
if (info.Actresses.Count > 0)
|
||||||
{
|
{
|
||||||
var actressLinks = string.Join(" / ", info.Actresses.Select(a => $"<a href=\"https://movie.eroterest.net/?word={Uri.EscapeDataString(a)}\" target=\"_blank\" rel=\"noopener noreferrer\">{WebUtility.HtmlEncode(a)}</a>"));
|
var actressLinks = string.Join(" / ", info.Actresses.Select(a => $"<a href=\"https://movie.eroterest.net/?word={Uri.EscapeDataString(a)}\" target=\"_blank\" rel=\"noopener noreferrer\">{WebUtility.HtmlEncode(a)}</a>"));
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using AngleSharp.Dom;
|
using AngleSharp.Dom;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
@@ -53,19 +53,11 @@ internal static class hentaipaw
|
|||||||
// 既存の hentaipaw.xml から各記事(タイトル・本文・日時・カテゴリ)を読み込んでキャッシュ化
|
// 既存の hentaipaw.xml から各記事(タイトル・本文・日時・カテゴリ)を読み込んでキャッシュ化
|
||||||
var existingEntries = LoadExistingEntries("hentaipaw.xml");
|
var existingEntries = LoadExistingEntries("hentaipaw.xml");
|
||||||
|
|
||||||
// 外部からセッションが渡されなかった場合は自前で作成
|
sessionId ??= CmnUtil.SharedFlareSolverrSessionId;
|
||||||
bool ownSession = sessionId == null;
|
|
||||||
if (ownSession)
|
|
||||||
{
|
|
||||||
sessionId = await CmnUtil.CreateFlareSolverrSession(client);
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var document = await CmnUtil.GetDocumentFlareSolverr(client, TargetUrl, session: sessionId);
|
var document = await CmnUtil.GetDocumentFlareSolverr(client, TargetUrl, session: sessionId);
|
||||||
if (document == null)
|
if (document == null)
|
||||||
{
|
{
|
||||||
LogManager.AddLog("[警告] [hentaipaw] トップページの取得に失敗しました。");
|
LogManager.AddLog("[警告] 【hentaipaw】 トップページの取得に失敗しました。");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -409,17 +401,9 @@ internal static class hentaipaw
|
|||||||
feed.Items = items;
|
feed.Items = items;
|
||||||
await CmnUtil.ExportXMLFileAsync("hentaipaw.xml", feed, client, filter24Hours: false);
|
await CmnUtil.ExportXMLFileAsync("hentaipaw.xml", feed, client, filter24Hours: false);
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
if (ownSession && sessionId != null)
|
|
||||||
{
|
|
||||||
await CmnUtil.DestroyFlareSolverrSession(client, sessionId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
LogManager.AddLog($"[エラー] hentaipaw: {ex.Message}");
|
LogManager.AddLog($"[エラー] 【hentaipaw】 {ex.Message}");
|
||||||
CmnUtil.PrintCallStackToEvent(ex);
|
CmnUtil.PrintCallStackToEvent(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using AngleSharp.Dom;
|
using AngleSharp.Dom;
|
||||||
using AngleSharp.Html.Dom;
|
using AngleSharp.Html.Dom;
|
||||||
using AngleSharp.Html.Parser;
|
using AngleSharp.Html.Parser;
|
||||||
using System;
|
using System;
|
||||||
@@ -61,15 +61,69 @@ internal class index_japanese
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 重複除外(IDベース)
|
// 既存フィードを読み込み、過去の公開日時・更新日時・本文HTMLを引き継ぐ
|
||||||
var uniqueItems = items
|
var existingEntries = LoadExistingEntries("hitomi-japanese.xml");
|
||||||
.GroupBy(x => x.Id)
|
|
||||||
.Select(g => g.First())
|
// 既存エントリの引き継ぎとマージ
|
||||||
|
var mergedDict = new Dictionary<string, SyndicationItem>(StringComparer.OrdinalIgnoreCase);
|
||||||
|
|
||||||
|
// まず既存フィードの全アイテムを登録
|
||||||
|
foreach (var kvp in existingEntries)
|
||||||
|
{
|
||||||
|
var entry = kvp.Value;
|
||||||
|
if (!mergedDict.ContainsKey(entry.Guid))
|
||||||
|
{
|
||||||
|
var synItem = new SyndicationItem(
|
||||||
|
entry.Title,
|
||||||
|
(string?)null,
|
||||||
|
!string.IsNullOrEmpty(entry.Link) ? new Uri(entry.Link) : null,
|
||||||
|
entry.Guid,
|
||||||
|
entry.PublishDate != DateTimeOffset.MinValue ? entry.PublishDate : entry.LastUpdatedTime
|
||||||
|
)
|
||||||
|
{
|
||||||
|
PublishDate = entry.PublishDate != DateTimeOffset.MinValue ? entry.PublishDate : entry.LastUpdatedTime,
|
||||||
|
LastUpdatedTime = entry.LastUpdatedTime != DateTimeOffset.MinValue ? entry.LastUpdatedTime : entry.PublishDate,
|
||||||
|
Summary = new TextSyndicationContent(entry.SummaryHtml, TextSyndicationContentKind.Html)
|
||||||
|
};
|
||||||
|
foreach (var author in entry.Authors)
|
||||||
|
{
|
||||||
|
synItem.Authors.Add(new SyndicationPerson { Name = author });
|
||||||
|
}
|
||||||
|
foreach (var category in entry.Categories)
|
||||||
|
{
|
||||||
|
synItem.Categories.Add(new SyndicationCategory(category));
|
||||||
|
}
|
||||||
|
mergedDict[entry.Guid] = synItem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 今回取得したアイテムを反映(既存がある場合は前回の公開日時・本文HTMLを最優先で維持)
|
||||||
|
foreach (var newItem in items)
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrEmpty(newItem.Id))
|
||||||
|
{
|
||||||
|
if (existingEntries.TryGetValue(newItem.Id, out var existing))
|
||||||
|
{
|
||||||
|
newItem.PublishDate = existing.PublishDate != DateTimeOffset.MinValue ? existing.PublishDate : newItem.PublishDate;
|
||||||
|
newItem.LastUpdatedTime = existing.LastUpdatedTime != DateTimeOffset.MinValue ? existing.LastUpdatedTime : newItem.LastUpdatedTime;
|
||||||
|
if (!string.IsNullOrWhiteSpace(existing.SummaryHtml))
|
||||||
|
{
|
||||||
|
newItem.Summary = new TextSyndicationContent(existing.SummaryHtml, TextSyndicationContentKind.Html);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mergedDict[newItem.Id] = newItem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 重複除外とソート(新しい順)
|
||||||
|
var finalItems = mergedDict.Values
|
||||||
|
.OrderByDescending(x => x.PublishDate != DateTimeOffset.MinValue ? x.PublishDate : x.LastUpdatedTime)
|
||||||
|
.Take(100)
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
feed.Items = uniqueItems;
|
feed.Items = finalItems;
|
||||||
|
|
||||||
await CmnUtil.ExportXMLFileAsync("hitomi-japanese.xml", feed, client);
|
await CmnUtil.ExportXMLFileAsync("hitomi-japanese.xml", feed, client, filter24Hours: false);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -229,4 +283,50 @@ internal class index_japanese
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 既存の hitomi-japanese.xml を読み込み、GUIDおよびURLをキーとするキャッシュ辞書を返します。
|
||||||
|
/// </summary>
|
||||||
|
private static Dictionary<string, (string Guid, string Link, string Title, string SummaryHtml, DateTimeOffset PublishDate, DateTimeOffset LastUpdatedTime, List<string> Authors, List<string> Categories)> LoadExistingEntries(string fileName)
|
||||||
|
{
|
||||||
|
var dict = new Dictionary<string, (string Guid, string Link, string Title, string SummaryHtml, DateTimeOffset PublishDate, DateTimeOffset LastUpdatedTime, List<string> Authors, List<string> Categories)>(StringComparer.OrdinalIgnoreCase);
|
||||||
|
var filePath = CmnUtil.GetExportXmlPath(fileName);
|
||||||
|
if (!System.IO.File.Exists(filePath)) return dict;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var reader = System.Xml.XmlReader.Create(filePath);
|
||||||
|
var feed = SyndicationFeed.Load(reader);
|
||||||
|
if (feed?.Items != null)
|
||||||
|
{
|
||||||
|
foreach (var item in feed.Items)
|
||||||
|
{
|
||||||
|
string guid = item.Id ?? string.Empty;
|
||||||
|
string link = item.Links.FirstOrDefault()?.Uri?.ToString() ?? string.Empty;
|
||||||
|
string title = item.Title?.Text ?? string.Empty;
|
||||||
|
string summary = item.Summary?.Text ?? string.Empty;
|
||||||
|
DateTimeOffset pubDate = item.PublishDate;
|
||||||
|
DateTimeOffset lastUpdated = item.LastUpdatedTime;
|
||||||
|
var authors = item.Authors.Select(a => a.Name).Where(n => !string.IsNullOrEmpty(n)).ToList();
|
||||||
|
var categories = item.Categories.Select(c => c.Name).Where(n => !string.IsNullOrEmpty(n)).ToList();
|
||||||
|
|
||||||
|
var entry = (guid, link, title, summary, pubDate, lastUpdated, authors, categories);
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(guid) && !dict.ContainsKey(guid))
|
||||||
|
{
|
||||||
|
dict[guid] = entry;
|
||||||
|
}
|
||||||
|
if (!string.IsNullOrEmpty(link) && !dict.ContainsKey(link))
|
||||||
|
{
|
||||||
|
dict[link] = entry;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
LogManager.AddLog($"[警告] 【hitomi-japanese】 既存フィード読み込み失敗 ({fileName}): {ex.Message}");
|
||||||
|
}
|
||||||
|
return dict;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,547 @@
|
|||||||
|
using AngleSharp.Dom;
|
||||||
|
using AngleSharp.Html.Dom;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.ServiceModel.Syndication;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Xml;
|
||||||
|
using rss_generator.Class.Common;
|
||||||
|
|
||||||
|
namespace rss_generator.Class.JapaneseAvi;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// japaneseavi.blogspot.com から記事情報を収集し、RSS フィード (japaneseavi.xml) を生成するクラスです。
|
||||||
|
/// </summary>
|
||||||
|
internal class japaneseavi
|
||||||
|
{
|
||||||
|
#region □定数(Private)
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// プロジェクト固有規則に基づく出力先ドメインディレクトリ名です。
|
||||||
|
/// </summary>
|
||||||
|
private const string DomainDir = "japaneseavi.blogspot.com";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// キャッシュ判定用の最新フォーマット識別子です。
|
||||||
|
/// </summary>
|
||||||
|
private const string CacheFormatTag = "avi-format-v1";
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region □クラス(Private)
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 既存の RSS フィードから読み込んだ記事情報を保持する内部クラスです。
|
||||||
|
/// </summary>
|
||||||
|
private sealed class ExistingFeedEntry
|
||||||
|
{
|
||||||
|
/// <summary>記事のタイトルを取得または設定します。</summary>
|
||||||
|
public string Title { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>記事の本文 HTML (Summary) を取得または設定します。</summary>
|
||||||
|
public string SummaryHtml { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>記事の初回公開日時を取得または設定します。</summary>
|
||||||
|
public DateTimeOffset PublishDate { get; set; }
|
||||||
|
|
||||||
|
/// <summary>記事の最終更新日時を取得または設定します。</summary>
|
||||||
|
public DateTimeOffset LastUpdatedTime { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// ダウンロードリンクの情報を保持する内部クラスです。
|
||||||
|
/// </summary>
|
||||||
|
private sealed class DownloadItem
|
||||||
|
{
|
||||||
|
/// <summary>プロバイダー名を取得または設定します。</summary>
|
||||||
|
public string ProviderName { get; set; } = "Mediafire";
|
||||||
|
|
||||||
|
/// <summary>ダウンロード先 URL を取得または設定します。</summary>
|
||||||
|
public string DownloadUrl { get; set; } = string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 解析された記事詳細情報を保持する内部クラスです。
|
||||||
|
/// </summary>
|
||||||
|
private sealed class ArticleDetailInfo
|
||||||
|
{
|
||||||
|
/// <summary>品番(例: SOE-798, MXGS-422 等)を取得または設定します。</summary>
|
||||||
|
public string ProductId { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>整形されたタイトル文字列を取得または設定します。</summary>
|
||||||
|
public string CleanTitle { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>メディア形式(例: DVD, WMV 等)を取得または設定します。</summary>
|
||||||
|
public string MediaFormat { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>メインカバー画像の URL を取得または設定します。</summary>
|
||||||
|
public string ImageUrl { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>ダウンロードリンク一覧を取得または設定します。</summary>
|
||||||
|
public List<DownloadItem> Downloads { get; set; } = new();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region □メソッド(Public)
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// japaneseavi.blogspot.com から記事情報を収集し、RSS フィード (japaneseavi.xml) を生成・出力します。
|
||||||
|
/// プロジェクト固有規則に基づき、ドメイン別ディレクトリ output/japaneseavi.blogspot.com/ に出力します。
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="client">HTTP 通信用 HttpClient</param>
|
||||||
|
/// <returns>非同期タスク</returns>
|
||||||
|
public static async Task CreateRSSAsync(HttpClient client)
|
||||||
|
{
|
||||||
|
var feedUrl = "https://japaneseavi.blogspot.com/feeds/posts/default?alt=json&max-results=50";
|
||||||
|
var fileName = "japaneseavi.xml";
|
||||||
|
|
||||||
|
var feed = new SyndicationFeed("Japanese Porn Movie XXX Mediafire", "japaneseavi.blogspot.com RSS Feed", new Uri("https://japaneseavi.blogspot.com/"));
|
||||||
|
var items = new List<SyndicationItem>();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// 既存フィードの読み込み(ドメイン別サブディレクトリ)
|
||||||
|
var existingEntries = LoadExistingEntries(fileName);
|
||||||
|
|
||||||
|
// Blogger JSON フィードを取得
|
||||||
|
string jsonString = await client.GetStringAsync(feedUrl);
|
||||||
|
using var jsonDoc = JsonDocument.Parse(jsonString);
|
||||||
|
|
||||||
|
if (!jsonDoc.RootElement.TryGetProperty("feed", out var feedElem) ||
|
||||||
|
!feedElem.TryGetProperty("entry", out var entriesElem) ||
|
||||||
|
entriesElem.ValueKind != JsonValueKind.Array)
|
||||||
|
{
|
||||||
|
LogManager.AddLog("[情報] 【japaneseavi】 エントリが見つかりませんでした。");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var entry in entriesElem.EnumerateArray())
|
||||||
|
{
|
||||||
|
// タイトル取得
|
||||||
|
string rawTitle = string.Empty;
|
||||||
|
if (entry.TryGetProperty("title", out var titleElem) &&
|
||||||
|
titleElem.TryGetProperty("$t", out var titleTextElem))
|
||||||
|
{
|
||||||
|
rawTitle = titleTextElem.GetString() ?? string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 記事リンクの取得
|
||||||
|
string articleUrl = string.Empty;
|
||||||
|
if (entry.TryGetProperty("link", out var linkArrayElem) && linkArrayElem.ValueKind == JsonValueKind.Array)
|
||||||
|
{
|
||||||
|
foreach (var linkElem in linkArrayElem.EnumerateArray())
|
||||||
|
{
|
||||||
|
if (linkElem.TryGetProperty("rel", out var relElem) && relElem.GetString() == "alternate" &&
|
||||||
|
linkElem.TryGetProperty("href", out var hrefElem))
|
||||||
|
{
|
||||||
|
articleUrl = hrefElem.GetString() ?? string.Empty;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(articleUrl))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var itemUri = new Uri(articleUrl);
|
||||||
|
var guid = CmnUtil.CreateGuid(articleUrl);
|
||||||
|
|
||||||
|
// 公開日時・更新日時の取得
|
||||||
|
DateTimeOffset publishDate = DateTimeOffset.Now;
|
||||||
|
DateTimeOffset updatedDate = DateTimeOffset.Now;
|
||||||
|
if (entry.TryGetProperty("published", out var pubElem) && pubElem.TryGetProperty("$t", out var pubTextElem))
|
||||||
|
{
|
||||||
|
if (DateTimeOffset.TryParse(pubTextElem.GetString(), out var dt))
|
||||||
|
{
|
||||||
|
publishDate = dt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (entry.TryGetProperty("updated", out var updElem) && updElem.TryGetProperty("$t", out var updTextElem))
|
||||||
|
{
|
||||||
|
if (DateTimeOffset.TryParse(updTextElem.GetString(), out var dt))
|
||||||
|
{
|
||||||
|
updatedDate = dt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 本文 HTML (content) の取得
|
||||||
|
string rawContent = string.Empty;
|
||||||
|
if (entry.TryGetProperty("content", out var contentElem) &&
|
||||||
|
contentElem.TryGetProperty("$t", out var contentTextElem))
|
||||||
|
{
|
||||||
|
rawContent = contentTextElem.GetString() ?? string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
existingEntries.TryGetValue(articleUrl, out var prevEntry);
|
||||||
|
if (prevEntry == null && !string.IsNullOrEmpty(guid))
|
||||||
|
{
|
||||||
|
existingEntries.TryGetValue(guid, out prevEntry);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 最新フォーマット識別子 avi-format-v1 が含まれているキャッシュのみ再利用
|
||||||
|
bool isLatestFormat = prevEntry != null &&
|
||||||
|
prevEntry.SummaryHtml.Contains("avi-dl-section") &&
|
||||||
|
prevEntry.SummaryHtml.Contains(CacheFormatTag);
|
||||||
|
|
||||||
|
SyndicationItem item;
|
||||||
|
if (isLatestFormat && prevEntry != null)
|
||||||
|
{
|
||||||
|
// 【キャッシュヒット(未更新記事)】
|
||||||
|
item = new SyndicationItem(
|
||||||
|
prevEntry.Title,
|
||||||
|
(string?)null,
|
||||||
|
itemUri,
|
||||||
|
guid,
|
||||||
|
prevEntry.LastUpdatedTime
|
||||||
|
)
|
||||||
|
{
|
||||||
|
PublishDate = prevEntry.PublishDate,
|
||||||
|
LastUpdatedTime = prevEntry.LastUpdatedTime,
|
||||||
|
Summary = new TextSyndicationContent(prevEntry.SummaryHtml, TextSyndicationContentKind.Html)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// 【新規記事またはフォーマット更新記事】
|
||||||
|
var detailInfo = ParseArticleContent(rawTitle, rawContent);
|
||||||
|
|
||||||
|
// フォルダ名用タイトルの構築: [品番] タイトル [メディア形式]
|
||||||
|
string folderTitle = BuildFolderTitle(detailInfo, rawTitle);
|
||||||
|
|
||||||
|
// 本文 HTML の構築(フォルダ名コピー枠、タイトル表示、直下ダウンロードグリッド、高画質カバー画像)
|
||||||
|
string summaryHtml = BuildSummaryHtml(detailInfo, folderTitle, itemUri);
|
||||||
|
|
||||||
|
item = new SyndicationItem(
|
||||||
|
folderTitle,
|
||||||
|
(string?)null,
|
||||||
|
itemUri,
|
||||||
|
guid,
|
||||||
|
updatedDate
|
||||||
|
)
|
||||||
|
{
|
||||||
|
PublishDate = publishDate,
|
||||||
|
LastUpdatedTime = updatedDate,
|
||||||
|
Summary = new TextSyndicationContent(summaryHtml, TextSyndicationContentKind.Html)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
items.Add(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
feed.Items = items;
|
||||||
|
|
||||||
|
// プロジェクト固有規則に従い、ドメイン名サブディレクトリ (output/japaneseavi.blogspot.com/japaneseavi.xml) に出力
|
||||||
|
await CmnUtil.ExportXMLFileAsync(
|
||||||
|
fileName,
|
||||||
|
feed,
|
||||||
|
client,
|
||||||
|
addDir: DomainDir,
|
||||||
|
embedBase64: false,
|
||||||
|
filter24Hours: false);
|
||||||
|
|
||||||
|
LogManager.AddLog($"[情報] 【japaneseavi】 出力完了 - 記事数: {items.Count}");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
LogManager.AddLog($"[エラー] 【japaneseavi】 {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region □メソッド(Private)
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// タイトルおよび本文 HTML から各種情報(品番、クリーンタイトル、メディア形式、画像、ダウンロードリンク)を抽出・解析します。
|
||||||
|
/// </summary>
|
||||||
|
private static ArticleDetailInfo ParseArticleContent(string rawTitle, string rawContent)
|
||||||
|
{
|
||||||
|
var info = new ArticleDetailInfo();
|
||||||
|
|
||||||
|
// 1. 品番(Product ID)の抽出(例: SOE-798, MXGS-422, ONSD-643, XV-1077, WDI-028, ONED-448 等)
|
||||||
|
var pidMatch = Regex.Match(rawTitle, @"\b([A-Z0-9]{2,5}-\d{3,4})\b", RegexOptions.IgnoreCase);
|
||||||
|
if (pidMatch.Success)
|
||||||
|
{
|
||||||
|
info.ProductId = pidMatch.Groups[1].Value.ToUpperInvariant();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. メディア形式(DVD, WMV 等)の抽出
|
||||||
|
var formatMatch = Regex.Match(rawTitle, @"\[(DVD|WMV|MP4|AVI|HD|FHD)\]|\b(DVD|WMV|MP4|AVI)\b", RegexOptions.IgnoreCase);
|
||||||
|
if (formatMatch.Success)
|
||||||
|
{
|
||||||
|
string fmt = !string.IsNullOrWhiteSpace(formatMatch.Groups[1].Value)
|
||||||
|
? formatMatch.Groups[1].Value
|
||||||
|
: formatMatch.Groups[2].Value;
|
||||||
|
info.MediaFormat = fmt.ToUpperInvariant();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. タイトル文字列のクリーンアップ([CEN], [DVD], 品番などを整理)
|
||||||
|
string clean = rawTitle;
|
||||||
|
clean = Regex.Replace(clean, @"\[?CEN\]?", "", RegexOptions.IgnoreCase);
|
||||||
|
clean = Regex.Replace(clean, @"\[(DVD|WMV|MP4|AVI|HD|FHD)\]", "", RegexOptions.IgnoreCase);
|
||||||
|
if (!string.IsNullOrWhiteSpace(info.ProductId))
|
||||||
|
{
|
||||||
|
clean = Regex.Replace(clean, @"[\[\(\{]?" + Regex.Escape(info.ProductId) + @"[\]\)\}]?", "", RegexOptions.IgnoreCase);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 前後の記号や空白を整形
|
||||||
|
clean = clean.Trim(' ', '-', '–', '—', ':', '・', '[', ']', '(', ')');
|
||||||
|
clean = Regex.Replace(clean, @"\s{2,}", " ").Trim();
|
||||||
|
info.CleanTitle = clean;
|
||||||
|
|
||||||
|
// 4. 高解像度メイン画像の抽出
|
||||||
|
var imgMatch = Regex.Match(rawContent, @"<a[^>]+href=""([^""]+\.(?:jpg|jpeg|png|webp))""[^>]*>[\s\S]*?<img", RegexOptions.IgnoreCase);
|
||||||
|
if (imgMatch.Success)
|
||||||
|
{
|
||||||
|
info.ImageUrl = imgMatch.Groups[1].Value;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var directImg = Regex.Match(rawContent, @"<img[^>]+src=""([^""]+)""", RegexOptions.IgnoreCase);
|
||||||
|
if (directImg.Success)
|
||||||
|
{
|
||||||
|
info.ImageUrl = directImg.Groups[1].Value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 5. ダウンロードリンクの抽出
|
||||||
|
var aMatches = Regex.Matches(rawContent, @"<a\s+[^>]*href=""([^""]+)""[^>]*>([\s\S]*?)</a>", RegexOptions.IgnoreCase);
|
||||||
|
foreach (Match a in aMatches)
|
||||||
|
{
|
||||||
|
string href = a.Groups[1].Value;
|
||||||
|
string text = Regex.Replace(a.Groups[2].Value, @"<[^>]+>", "").Trim();
|
||||||
|
|
||||||
|
// 画像リンクそのものは除外
|
||||||
|
if (href.EndsWith(".jpg", StringComparison.OrdinalIgnoreCase) ||
|
||||||
|
href.EndsWith(".png", StringComparison.OrdinalIgnoreCase) ||
|
||||||
|
href.EndsWith(".webp", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (href.Contains("adf.ly", StringComparison.OrdinalIgnoreCase) ||
|
||||||
|
href.Contains("mediafire.com", StringComparison.OrdinalIgnoreCase) ||
|
||||||
|
text.Contains("download", StringComparison.OrdinalIgnoreCase) ||
|
||||||
|
text.Contains("mediafire", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
string provider = "Mediafire";
|
||||||
|
if (text.Contains("Mediafire", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
provider = "Mediafire";
|
||||||
|
}
|
||||||
|
|
||||||
|
info.Downloads.Add(new DownloadItem
|
||||||
|
{
|
||||||
|
ProviderName = provider,
|
||||||
|
DownloadUrl = href
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 解析情報から Windows のフォルダ名としてコピー可能なタイトル文字列を生成します。
|
||||||
|
/// </summary>
|
||||||
|
private static string BuildFolderTitle(ArticleDetailInfo info, string fallbackRawTitle)
|
||||||
|
{
|
||||||
|
var sb = new StringBuilder();
|
||||||
|
|
||||||
|
// 1. 品番を先頭に配置
|
||||||
|
if (!string.IsNullOrWhiteSpace(info.ProductId))
|
||||||
|
{
|
||||||
|
sb.Append($"[{info.ProductId}] ");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. クリーンタイトル
|
||||||
|
if (!string.IsNullOrWhiteSpace(info.CleanTitle))
|
||||||
|
{
|
||||||
|
sb.Append(info.CleanTitle);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sb.Append(fallbackRawTitle);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. メディア形式(末尾に付加)
|
||||||
|
if (!string.IsNullOrWhiteSpace(info.MediaFormat) &&
|
||||||
|
!sb.ToString().Contains(info.MediaFormat, StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
sb.Append($" [{info.MediaFormat}]");
|
||||||
|
}
|
||||||
|
|
||||||
|
return SanitizeWindowsPath(sb.ToString().Trim());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 整形された本文 HTML を生成します。
|
||||||
|
/// フォルダ名コピー枠、タイトル表示、直下ダウンロードグリッド、高画質カバー画像を配置します。
|
||||||
|
/// </summary>
|
||||||
|
private static string BuildSummaryHtml(ArticleDetailInfo info, string folderTitle, Uri articleUri)
|
||||||
|
{
|
||||||
|
var sb = new StringBuilder();
|
||||||
|
|
||||||
|
// 1. バッジ
|
||||||
|
sb.Append("<div style=\"margin-bottom: 12px;\">");
|
||||||
|
sb.Append("<span style=\"display: inline-block; background-color: #c2185b; color: #ffffff; padding: 4px 10px; border-radius: 4px; font-weight: bold; font-size: 13px;\">🎬 JAV (Japanese Adult Video)</span>");
|
||||||
|
if (!string.IsNullOrWhiteSpace(info.ProductId))
|
||||||
|
{
|
||||||
|
sb.Append($"<span style=\"display: inline-block; background-color: #374151; color: #ffffff; padding: 4px 8px; border-radius: 4px; font-size: 13px; font-weight: bold; margin-left: 8px;\">🏷️ {WebUtility.HtmlEncode(info.ProductId)}</span>");
|
||||||
|
}
|
||||||
|
if (!string.IsNullOrWhiteSpace(info.MediaFormat))
|
||||||
|
{
|
||||||
|
sb.Append($"<span style=\"display: inline-block; background-color: #1976d2; color: #ffffff; padding: 4px 8px; border-radius: 4px; font-size: 13px; font-weight: bold; margin-left: 8px;\">💿 {WebUtility.HtmlEncode(info.MediaFormat)}</span>");
|
||||||
|
}
|
||||||
|
sb.Append("</div>");
|
||||||
|
|
||||||
|
// 2. フォルダ名用タイトルコピー枠(ワンクリック全選択コピー可能)
|
||||||
|
sb.Append($"<div class=\"avi-folder-title {CacheFormatTag}\" style=\"background-color: #f3f4f6; border-left: 4px solid #374151; padding: 10px 14px; margin-bottom: 12px; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif; border-radius: 0 4px 4px 0;\">");
|
||||||
|
sb.Append("<div style=\"font-size: 11px; font-weight: bold; color: #4b5563; margin-bottom: 4px;\">📁 フォルダ名用タイトル (コピー用):</div>");
|
||||||
|
sb.Append($"<div style=\"font-size: 15px; font-weight: bold; color: #111827; user-select: all; -webkit-user-select: all;\">{WebUtility.HtmlEncode(folderTitle)}</div>");
|
||||||
|
sb.Append("</div>");
|
||||||
|
|
||||||
|
// 3. タイトル・詳細情報ブロック
|
||||||
|
sb.Append("<div class=\"avi-info-block\" style=\"background-color: #f8fafc; border-left: 4px solid #0284c7; padding: 8px 12px; margin-bottom: 12px; font-size: 14px; border-radius: 0 4px 4px 0;\">");
|
||||||
|
if (!string.IsNullOrWhiteSpace(info.ProductId))
|
||||||
|
{
|
||||||
|
sb.Append($"<div style=\"margin-bottom: 4px;\"><strong style=\"color: #0369a1;\">品番 (Product ID):</strong> <span>{WebUtility.HtmlEncode(info.ProductId)}</span></div>");
|
||||||
|
}
|
||||||
|
if (!string.IsNullOrWhiteSpace(info.CleanTitle))
|
||||||
|
{
|
||||||
|
sb.Append($"<div><strong style=\"color: #0369a1;\">作品名 (Title):</strong> <span>{WebUtility.HtmlEncode(info.CleanTitle)}</span></div>");
|
||||||
|
}
|
||||||
|
sb.Append("</div>");
|
||||||
|
|
||||||
|
// 4. ダウンロードセクション (avi-dl-section) - タイトル直下に整然としたグリッドレイアウトで配置
|
||||||
|
if (info.Downloads.Any())
|
||||||
|
{
|
||||||
|
sb.Append("<div class=\"avi-dl-section\" style=\"background-color: #f7f9fa; border: 1px solid #cfd8dc; border-radius: 6px; padding: 14px; margin-top: 10px; margin-bottom: 14px; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;\">");
|
||||||
|
sb.Append("<h4 style=\"margin: 0 0 10px 0; font-size: 16px; border-bottom: 2px solid #e53935; padding-bottom: 6px; color: #c62828;\">");
|
||||||
|
sb.Append("📥 ダウンロード (DOWNLOAD)");
|
||||||
|
sb.Append("</h4>");
|
||||||
|
|
||||||
|
sb.Append("<div style=\"display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; margin-bottom: 6px;\">");
|
||||||
|
|
||||||
|
foreach (var dl in info.Downloads)
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrWhiteSpace(dl.DownloadUrl))
|
||||||
|
{
|
||||||
|
sb.Append($"<a href=\"{dl.DownloadUrl}\" target=\"_blank\" rel=\"noopener noreferrer\" referrerpolicy=\"no-referrer\" style=\"display: flex; align-items: center; justify-content: center; gap: 6px; text-align: center; background-color: #1976d2; color: #ffffff; padding: 10px 14px; border-radius: 4px; text-decoration: none; font-weight: bold; font-size: 13px; box-shadow: 0 1px 3px rgba(0,0,0,0.12);\">");
|
||||||
|
sb.Append($"<span>⬇️</span> <span>{WebUtility.HtmlEncode(dl.ProviderName)} Download</span>");
|
||||||
|
sb.Append("</a>");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.Append("</div>");
|
||||||
|
sb.Append("</div>");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 5. メインカバー画像(高画質表示)
|
||||||
|
if (!string.IsNullOrWhiteSpace(info.ImageUrl))
|
||||||
|
{
|
||||||
|
sb.Append("<div style=\"margin-bottom: 14px; text-align: center;\">");
|
||||||
|
sb.Append($"<img src=\"{info.ImageUrl}\" referrerpolicy=\"no-referrer\" alt=\"{WebUtility.HtmlEncode(folderTitle)}\" style=\"max-width: 100%; height: auto; border-radius: 4px; box-shadow: 0 2px 4px rgba(0,0,0,0.15);\" />");
|
||||||
|
sb.Append("</div>");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 6. 記事ページへのリンク
|
||||||
|
sb.Append("<div style=\"margin-top: 16px; padding-top: 10px; border-top: 1px solid #e0e0e0; font-size: 13px;\">");
|
||||||
|
sb.Append($"<a href=\"{articleUri}\" target=\"_blank\" rel=\"noopener noreferrer\" referrerpolicy=\"no-referrer\" style=\"color: #1976d2; text-decoration: none;\">🔗 japaneseavi.blogspot.com 記事ページを開く</a>");
|
||||||
|
sb.Append("</div>");
|
||||||
|
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Windows のフォルダ名に使用できない記号文字を全角文字に置換します。
|
||||||
|
/// </summary>
|
||||||
|
private static string SanitizeWindowsPath(string name)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(name))
|
||||||
|
{
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
return name
|
||||||
|
.Replace('\\', '¥')
|
||||||
|
.Replace('/', '/')
|
||||||
|
.Replace(':', ':')
|
||||||
|
.Replace('*', '*')
|
||||||
|
.Replace('?', '?')
|
||||||
|
.Replace('"', '”')
|
||||||
|
.Replace('<', '<')
|
||||||
|
.Replace('>', '>')
|
||||||
|
.Replace('|', '|')
|
||||||
|
.Trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 既存の XML ファイルから各記事のタイトル・本文 HTML・公開日時・更新日時を読み込みます。
|
||||||
|
/// プロジェクト固有規則に基づき、ドメイン別サブディレクトリ(output/japaneseavi.blogspot.com/)内のファイルを読み込みます。
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="fileName">XML ファイル名</param>
|
||||||
|
/// <returns>URL または GUID をキーとする既存エントリの辞書</returns>
|
||||||
|
private static Dictionary<string, ExistingFeedEntry> LoadExistingEntries(string fileName)
|
||||||
|
{
|
||||||
|
var existingEntries = new Dictionary<string, ExistingFeedEntry>(StringComparer.OrdinalIgnoreCase);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string xmlPath = CmnUtil.GetExportXmlPath(fileName, addDir: DomainDir);
|
||||||
|
if (!File.Exists(xmlPath))
|
||||||
|
{
|
||||||
|
return existingEntries;
|
||||||
|
}
|
||||||
|
|
||||||
|
using var reader = XmlReader.Create(xmlPath);
|
||||||
|
var existingFeed = SyndicationFeed.Load(reader);
|
||||||
|
if (existingFeed?.Items != null)
|
||||||
|
{
|
||||||
|
foreach (var item in existingFeed.Items)
|
||||||
|
{
|
||||||
|
var linkUrl = item.Links.FirstOrDefault()?.Uri?.AbsoluteUri;
|
||||||
|
var guid = item.Id;
|
||||||
|
|
||||||
|
var entry = new ExistingFeedEntry
|
||||||
|
{
|
||||||
|
Title = item.Title?.Text?.Trim() ?? string.Empty,
|
||||||
|
SummaryHtml = item.Summary?.Text?.Trim() ?? string.Empty,
|
||||||
|
PublishDate = item.PublishDate != DateTimeOffset.MinValue
|
||||||
|
? item.PublishDate
|
||||||
|
: (item.LastUpdatedTime != DateTimeOffset.MinValue ? item.LastUpdatedTime : DateTimeOffset.Now),
|
||||||
|
LastUpdatedTime = item.LastUpdatedTime != DateTimeOffset.MinValue
|
||||||
|
? item.LastUpdatedTime
|
||||||
|
: (item.PublishDate != DateTimeOffset.MinValue ? item.PublishDate : DateTimeOffset.Now)
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(linkUrl) && !existingEntries.ContainsKey(linkUrl))
|
||||||
|
{
|
||||||
|
existingEntries[linkUrl] = entry;
|
||||||
|
}
|
||||||
|
if (!string.IsNullOrWhiteSpace(guid) && !existingEntries.ContainsKey(guid))
|
||||||
|
{
|
||||||
|
existingEntries[guid] = entry;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
LogManager.AddLog($"[情報] japaneseavi 既存エントリ読み込みスキップ: {ex.Message}");
|
||||||
|
}
|
||||||
|
|
||||||
|
return existingEntries;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
using AngleSharp.Dom;
|
using AngleSharp.Dom;
|
||||||
using AngleSharp.Html.Dom;
|
using AngleSharp.Html.Dom;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@@ -120,7 +120,7 @@ internal class javtwi
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
LogManager.AddLog($"[エラー] javtwi:{ex.Message}");
|
LogManager.AddLog($"[エラー] 【javtwi】 {ex.Message}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,651 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.ServiceModel.Syndication;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Xml;
|
||||||
|
using rss_generator.Class.Common;
|
||||||
|
|
||||||
|
namespace rss_generator.Class.Jpfiles;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// jpfiles.net から最新記事を収集し、RSS フィード (jpfiles.xml) を生成・出力するクラスです。
|
||||||
|
/// </summary>
|
||||||
|
internal class jpfiles
|
||||||
|
{
|
||||||
|
#region □定数(Private)
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// プロジェクト固有規則に基づく出力先ドメインディレクトリ名です。
|
||||||
|
/// </summary>
|
||||||
|
private const string DomainDir = "jpfiles.net";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// キャッシュ判定用の最新フォーマット識別子です。
|
||||||
|
/// </summary>
|
||||||
|
private const string CacheFormatTag = "jpfiles-format-v2";
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region □クラス(Private)
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 既存の RSS フィードから読み込んだ記事情報を保持する内部クラスです。
|
||||||
|
/// </summary>
|
||||||
|
private sealed class ExistingFeedEntry
|
||||||
|
{
|
||||||
|
/// <summary>記事のタイトルを取得または設定します。</summary>
|
||||||
|
public string Title { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>記事の本文 HTML (Summary) を取得または設定します。</summary>
|
||||||
|
public string SummaryHtml { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>記事の初回公開日時を取得または設定します。</summary>
|
||||||
|
public DateTimeOffset PublishDate { get; set; }
|
||||||
|
|
||||||
|
/// <summary>記事の最終更新日時を取得または設定します。</summary>
|
||||||
|
public DateTimeOffset LastUpdatedTime { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 各種アップローダーのダウンロードリンク情報を保持する内部クラスです。
|
||||||
|
/// </summary>
|
||||||
|
private sealed class DownloadItem
|
||||||
|
{
|
||||||
|
/// <summary>プロバイダー名(Rapidgator, Katfile, Nitroflare 等)を取得または設定します。</summary>
|
||||||
|
public string ProviderName { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>ダウンロード用 URL を取得または設定します。</summary>
|
||||||
|
public string Url { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>パート名またはファイル名表示(例: Part 1, Part 2, Full)を取得または設定します。</summary>
|
||||||
|
public string PartLabel { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>ボタンスタイルの背景色カラーコードを取得または設定します。</summary>
|
||||||
|
public string BgColor { get; set; } = "#1976d2";
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 解析された記事詳細情報を保持する内部クラスです。
|
||||||
|
/// </summary>
|
||||||
|
private sealed class ArticleInfo
|
||||||
|
{
|
||||||
|
/// <summary>記事 ID を取得または設定します。</summary>
|
||||||
|
public long Id { get; set; }
|
||||||
|
|
||||||
|
/// <summary>記事の URL を取得または設定します。</summary>
|
||||||
|
public string Url { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>元記事の生のタイトルを取得または設定します。</summary>
|
||||||
|
public string RawTitle { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>Windows フォルダ名用に整形されたタイトルを取得または設定します。</summary>
|
||||||
|
public string CleanTitle { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>カテゴリ・品番タグ(例: [BDRIP], [DVDRIP], [Onlyfans] 等)を取得または設定します。</summary>
|
||||||
|
public string CategoryTag { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>記事の公開日時を取得または設定します。</summary>
|
||||||
|
public DateTimeOffset PublishDate { get; set; }
|
||||||
|
|
||||||
|
/// <summary>カバー画像の URL を取得または設定します。</summary>
|
||||||
|
public string CoverImageUrl { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>カバー画像の原寸リンク URL を取得または設定します。</summary>
|
||||||
|
public string CoverOriginalUrl { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>ダウンロードリンク一覧を取得または設定します。</summary>
|
||||||
|
public List<DownloadItem> Downloads { get; set; } = new();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region □メソッド(Public)
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// jpfiles.net から記事情報を収集し、RSS フィード (jpfiles.xml) を生成・出力します。
|
||||||
|
/// プロジェクト固有規則に基づき、ドメイン別ディレクトリ output/jpfiles.net/ に出力します。
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="client">HTTP 通信用 HttpClient</param>
|
||||||
|
/// <returns>非同期タスク</returns>
|
||||||
|
public static async Task CreateRSSAsync(HttpClient client)
|
||||||
|
{
|
||||||
|
var feedUrl = "https://jpfiles.net/wp-json/wp/v2/posts?per_page=50";
|
||||||
|
var fileName = "jpfiles.xml";
|
||||||
|
|
||||||
|
var feed = new SyndicationFeed(
|
||||||
|
"jpfiles.net 最新ダウンロード",
|
||||||
|
"jpfiles.net の最新記事およびダイレクトダウンロードリンク一覧",
|
||||||
|
new Uri("https://jpfiles.net/"));
|
||||||
|
|
||||||
|
var items = new List<SyndicationItem>();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// 既存フィードの読み込み(ドメイン別サブディレクトリ output/jpfiles.net/jpfiles.xml)
|
||||||
|
var existingEntries = LoadExistingEntries(fileName);
|
||||||
|
|
||||||
|
// WordPress REST API から JSON データを取得
|
||||||
|
using var request = new HttpRequestMessage(HttpMethod.Get, feedUrl);
|
||||||
|
request.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36");
|
||||||
|
|
||||||
|
var response = await client.SendAsync(request);
|
||||||
|
response.EnsureSuccessStatusCode();
|
||||||
|
|
||||||
|
var jsonString = await response.Content.ReadAsStringAsync();
|
||||||
|
using var jsonDoc = JsonDocument.Parse(jsonString);
|
||||||
|
|
||||||
|
if (jsonDoc.RootElement.ValueKind != JsonValueKind.Array)
|
||||||
|
{
|
||||||
|
LogManager.AddLog("[情報] 【jpfiles】 記事データが配列形式ではありませんでした。");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var postElem in jsonDoc.RootElement.EnumerateArray())
|
||||||
|
{
|
||||||
|
var id = postElem.TryGetProperty("id", out var idElem) ? idElem.GetInt64() : 0;
|
||||||
|
var articleUrl = postElem.TryGetProperty("link", out var linkElem) ? linkElem.GetString() ?? string.Empty : string.Empty;
|
||||||
|
|
||||||
|
var rawTitle = string.Empty;
|
||||||
|
if (postElem.TryGetProperty("title", out var titleElem) &&
|
||||||
|
titleElem.TryGetProperty("rendered", out var titleTextElem))
|
||||||
|
{
|
||||||
|
rawTitle = titleTextElem.GetString() ?? string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
var contentHtml = string.Empty;
|
||||||
|
if (postElem.TryGetProperty("content", out var contentElem) &&
|
||||||
|
contentElem.TryGetProperty("rendered", out var contentTextElem))
|
||||||
|
{
|
||||||
|
contentHtml = contentTextElem.GetString() ?? string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 公開日時 (date または date_gmt) を日本時間 (JST = UTC+9) として厳密に解釈
|
||||||
|
var pubDate = DateTimeOffset.Now;
|
||||||
|
if (postElem.TryGetProperty("date", out var dateElem) &&
|
||||||
|
DateTime.TryParse(dateElem.GetString(), out var parsedLocal))
|
||||||
|
{
|
||||||
|
// date はサイト現地時刻(日本時間相当の文字列)のため JST (+09:00) として解釈
|
||||||
|
pubDate = new DateTimeOffset(parsedLocal, TimeSpan.FromHours(9));
|
||||||
|
}
|
||||||
|
else if (postElem.TryGetProperty("date_gmt", out var dateGmtElem) &&
|
||||||
|
DateTime.TryParse(dateGmtElem.GetString(), out var parsedGmt))
|
||||||
|
{
|
||||||
|
// date_gmt は GMT/UTC のため UTC として設定後に JST (+09:00) へ変換
|
||||||
|
var utcDate = DateTime.SpecifyKind(parsedGmt, DateTimeKind.Utc);
|
||||||
|
pubDate = new DateTimeOffset(utcDate).ToOffset(TimeSpan.FromHours(9));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(articleUrl) || string.IsNullOrWhiteSpace(rawTitle))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// プロジェクト共通仕様に基づく一意な GUID (SHA512ハッシュ) の生成
|
||||||
|
var guid = CmnUtil.CreateGuid(articleUrl);
|
||||||
|
|
||||||
|
// 既存キャッシュの確認
|
||||||
|
if (existingEntries.TryGetValue(articleUrl, out var cached) &&
|
||||||
|
!string.IsNullOrWhiteSpace(cached.SummaryHtml) &&
|
||||||
|
cached.SummaryHtml.Contains(CacheFormatTag))
|
||||||
|
{
|
||||||
|
var item = new SyndicationItem(
|
||||||
|
cached.Title,
|
||||||
|
cached.SummaryHtml,
|
||||||
|
new Uri(articleUrl),
|
||||||
|
guid,
|
||||||
|
cached.LastUpdatedTime)
|
||||||
|
{
|
||||||
|
PublishDate = cached.PublishDate
|
||||||
|
};
|
||||||
|
items.Add(item);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 記事の解析
|
||||||
|
var article = ParseArticle(id, rawTitle, contentHtml, articleUrl, pubDate);
|
||||||
|
|
||||||
|
// 本文 HTML の生成
|
||||||
|
var summaryHtml = GenerateSummaryHtml(article);
|
||||||
|
|
||||||
|
var newItem = new SyndicationItem(
|
||||||
|
article.CleanTitle,
|
||||||
|
summaryHtml,
|
||||||
|
new Uri(article.Url),
|
||||||
|
guid,
|
||||||
|
article.PublishDate)
|
||||||
|
{
|
||||||
|
PublishDate = article.PublishDate
|
||||||
|
};
|
||||||
|
|
||||||
|
items.Add(newItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 既存フィードのうち API に含まれなかった未重複記事をマージ(最大100件まで保持)
|
||||||
|
foreach (var kvp in existingEntries)
|
||||||
|
{
|
||||||
|
var oldGuid = CmnUtil.CreateGuid(kvp.Key);
|
||||||
|
if (items.Any(i => i.Id == oldGuid || i.Links.Any(l => l.Uri.ToString().Equals(kvp.Key, StringComparison.OrdinalIgnoreCase))))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var oldItem = new SyndicationItem(
|
||||||
|
kvp.Value.Title,
|
||||||
|
kvp.Value.SummaryHtml,
|
||||||
|
new Uri(kvp.Key),
|
||||||
|
oldGuid,
|
||||||
|
kvp.Value.LastUpdatedTime)
|
||||||
|
{
|
||||||
|
PublishDate = kvp.Value.PublishDate
|
||||||
|
};
|
||||||
|
items.Add(oldItem);
|
||||||
|
|
||||||
|
if (items.Count >= 100)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
feed.Items = items;
|
||||||
|
|
||||||
|
// ドメイン別ディレクトリ output/jpfiles.net/jpfiles.xml に出力
|
||||||
|
await CmnUtil.ExportXMLFileAsync(
|
||||||
|
fileName,
|
||||||
|
feed,
|
||||||
|
client,
|
||||||
|
addDir: DomainDir,
|
||||||
|
embedBase64: false,
|
||||||
|
filter24Hours: false);
|
||||||
|
|
||||||
|
LogManager.AddLog($"[情報] 【jpfiles】 出力完了: {items.Count} 件 (フォルダ: {DomainDir})");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
LogManager.AddLog($"[エラー] 【jpfiles】 RSS生成処理中にエラーが発生しました: {ex.Message}");
|
||||||
|
CmnUtil.PrintCallStackToEvent(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region □メソッド(Private)
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 既存の RSS フィードファイルから記事情報を読み込み、URL をキーとする辞書として取得します。
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="fileName">読み込む XML ファイル名</param>
|
||||||
|
/// <returns>既存記事辞書</returns>
|
||||||
|
private static Dictionary<string, ExistingFeedEntry> LoadExistingEntries(string fileName)
|
||||||
|
{
|
||||||
|
var result = new Dictionary<string, ExistingFeedEntry>(StringComparer.OrdinalIgnoreCase);
|
||||||
|
var filePath = CmnUtil.GetExportXmlPath(fileName, DomainDir);
|
||||||
|
|
||||||
|
if (!File.Exists(filePath))
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var reader = XmlReader.Create(filePath);
|
||||||
|
var feed = SyndicationFeed.Load(reader);
|
||||||
|
|
||||||
|
if (feed?.Items == null)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var item in feed.Items)
|
||||||
|
{
|
||||||
|
var link = item.Links.FirstOrDefault()?.Uri?.ToString() ?? item.Id;
|
||||||
|
if (string.IsNullOrWhiteSpace(link) || result.ContainsKey(link))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var title = item.Title?.Text ?? string.Empty;
|
||||||
|
var summary = item.Summary?.Text ?? string.Empty;
|
||||||
|
|
||||||
|
result[link] = new ExistingFeedEntry
|
||||||
|
{
|
||||||
|
Title = title,
|
||||||
|
SummaryHtml = summary,
|
||||||
|
PublishDate = item.PublishDate,
|
||||||
|
LastUpdatedTime = item.LastUpdatedTime
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
LogManager.AddLog($"[警告] 【jpfiles】 既存フィード読み込み中にエラーが発生しました: {ex.Message}");
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 生のタイトルおよび本文 HTML から記事詳細情報(タイトル整形、画像、ダウンロードリンク)を解析します。
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">記事 ID</param>
|
||||||
|
/// <param name="rawTitle">生のタイトル文字列</param>
|
||||||
|
/// <param name="contentHtml">本文 HTML</param>
|
||||||
|
/// <param name="articleUrl">記事の URL</param>
|
||||||
|
/// <param name="pubDate">公開日時</param>
|
||||||
|
/// <returns>解析された記事詳細情報</returns>
|
||||||
|
private static ArticleInfo ParseArticle(long id, string rawTitle, string contentHtml, string articleUrl, DateTimeOffset pubDate)
|
||||||
|
{
|
||||||
|
var decodedTitle = WebUtility.HtmlDecode(rawTitle).Trim();
|
||||||
|
|
||||||
|
// カテゴリタグの抽出(例: [BDRIP], [DVDRIP], [Onlyfans], [Minisuka] 等)
|
||||||
|
var categoryTag = string.Empty;
|
||||||
|
var tagMatch = Regex.Match(decodedTitle, @"^\s*(\[[^\]]+\])");
|
||||||
|
if (tagMatch.Success)
|
||||||
|
{
|
||||||
|
categoryTag = tagMatch.Groups[1].Value.Trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Windows フォルダ名禁止文字の全角置換
|
||||||
|
var cleanTitle = SanitizeForWindows(decodedTitle);
|
||||||
|
|
||||||
|
var article = new ArticleInfo
|
||||||
|
{
|
||||||
|
Id = id,
|
||||||
|
Url = articleUrl,
|
||||||
|
RawTitle = decodedTitle,
|
||||||
|
CleanTitle = cleanTitle,
|
||||||
|
CategoryTag = categoryTag,
|
||||||
|
PublishDate = pubDate
|
||||||
|
};
|
||||||
|
|
||||||
|
// 画像の抽出(Pixhost または TurboImageHost 等)
|
||||||
|
ExtractImages(contentHtml, article);
|
||||||
|
|
||||||
|
// ダウンロードリンクの抽出(Rapidgator, Katfile, Nitroflare, Frdl 等)
|
||||||
|
article.Downloads = ExtractDownloads(contentHtml);
|
||||||
|
|
||||||
|
return article;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 本文 HTML からサムネイル画像および原寸表示用 URL を抽出して記事情報に設定します。
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="contentHtml">本文 HTML</param>
|
||||||
|
/// <param name="article">記事詳細情報オブジェクト</param>
|
||||||
|
private static void ExtractImages(string contentHtml, ArticleInfo article)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(contentHtml))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1. サムネイル画像 <img src="..."> の抽出
|
||||||
|
var imgMatches = Regex.Matches(contentHtml, @"<img[^>]+src=[""']([^""']+)[""']", RegexOptions.IgnoreCase);
|
||||||
|
foreach (Match match in imgMatches)
|
||||||
|
{
|
||||||
|
var src = match.Groups[1].Value.Trim();
|
||||||
|
if (string.IsNullOrWhiteSpace(src))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pixhost サムネイル等の画像を採用
|
||||||
|
if (src.Contains("pixhost.cc") || src.Contains("turboimagehost.com") || src.Contains(".jpg") || src.Contains(".png") || src.Contains(".webp"))
|
||||||
|
{
|
||||||
|
article.CoverImageUrl = src;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 原寸表示リンク <a href="https://pixhost.cc/show/..."> の抽出
|
||||||
|
var aMatches = Regex.Matches(contentHtml, @"<a[^>]+href=[""']([^""']+)[""']", RegexOptions.IgnoreCase);
|
||||||
|
foreach (Match match in aMatches)
|
||||||
|
{
|
||||||
|
var href = match.Groups[1].Value.Trim();
|
||||||
|
if (href.Contains("pixhost.cc/show/") || href.Contains("turboimagehost.com/p/"))
|
||||||
|
{
|
||||||
|
article.CoverOriginalUrl = href;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 原寸リンクが見つからず画像のみある場合は画像URLを代用
|
||||||
|
if (string.IsNullOrWhiteSpace(article.CoverOriginalUrl) && !string.IsNullOrWhiteSpace(article.CoverImageUrl))
|
||||||
|
{
|
||||||
|
article.CoverOriginalUrl = article.CoverImageUrl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 本文 HTML から主要アップローダーのダウンロードリンクを抽出してリストとして取得します。
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="contentHtml">本文 HTML</param>
|
||||||
|
/// <returns>ダウンロードリンク一覧</returns>
|
||||||
|
private static List<DownloadItem> ExtractDownloads(string contentHtml)
|
||||||
|
{
|
||||||
|
var downloads = new List<DownloadItem>();
|
||||||
|
if (string.IsNullOrWhiteSpace(contentHtml))
|
||||||
|
{
|
||||||
|
return downloads;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 本文内のすべての <a href="..."> タグを探索
|
||||||
|
var matches = Regex.Matches(contentHtml, @"<a[^>]+href=[""']([^""']+)[""'][^>]*>(.*?)</a>", RegexOptions.IgnoreCase | RegexOptions.Singleline);
|
||||||
|
var seenUrls = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
||||||
|
|
||||||
|
foreach (Match match in matches)
|
||||||
|
{
|
||||||
|
var url = match.Groups[1].Value.Trim();
|
||||||
|
if (string.IsNullOrWhiteSpace(url) || seenUrls.Contains(url))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Uri.TryCreate(url, UriKind.Absolute, out var uri))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var host = uri.Host.ToLowerInvariant();
|
||||||
|
|
||||||
|
// アップローダー判定とメタデータ付与
|
||||||
|
string providerName;
|
||||||
|
string bgColor;
|
||||||
|
|
||||||
|
if (host.Contains("rapidgator.net"))
|
||||||
|
{
|
||||||
|
providerName = "Rapidgator";
|
||||||
|
bgColor = "#1976d2"; // ブルー
|
||||||
|
}
|
||||||
|
else if (host.Contains("katfile."))
|
||||||
|
{
|
||||||
|
providerName = "Katfile";
|
||||||
|
bgColor = "#f57c00"; // オレンジ
|
||||||
|
}
|
||||||
|
else if (host.Contains("nitroflare.com"))
|
||||||
|
{
|
||||||
|
providerName = "Nitroflare";
|
||||||
|
bgColor = "#d32f2f"; // レッド
|
||||||
|
}
|
||||||
|
else if (host.Contains("frdl.io"))
|
||||||
|
{
|
||||||
|
providerName = "Frdl";
|
||||||
|
bgColor = "#388e3c"; // グリーン
|
||||||
|
}
|
||||||
|
else if (host.Contains("uploady.io"))
|
||||||
|
{
|
||||||
|
providerName = "Uploady";
|
||||||
|
bgColor = "#7b1fa2"; // パープル
|
||||||
|
}
|
||||||
|
else if (host.Contains("mexashare.com") || host.Contains("rosefile.net") || host.Contains("alfafile.net") || host.Contains("ddownload.com"))
|
||||||
|
{
|
||||||
|
providerName = host;
|
||||||
|
bgColor = "#455a64"; // ダークスレート
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Pixhost や jpfiles 内部リンクなどは除外
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
seenUrls.Add(url);
|
||||||
|
|
||||||
|
// パート情報またはファイル名ラベルの判定(URL 末尾から判定)
|
||||||
|
var partLabel = DeterminePartLabel(url);
|
||||||
|
|
||||||
|
downloads.Add(new DownloadItem
|
||||||
|
{
|
||||||
|
ProviderName = providerName,
|
||||||
|
Url = url,
|
||||||
|
PartLabel = partLabel,
|
||||||
|
BgColor = bgColor
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return downloads;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// URL からパート情報(Part 1, Part 2 等)またはファイル名ラベルを判定します。
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="url">ダウンロード URL</param>
|
||||||
|
/// <returns>パート表示ラベル</returns>
|
||||||
|
private static string DeterminePartLabel(string url)
|
||||||
|
{
|
||||||
|
var fileName = Path.GetFileName(new Uri(url).AbsolutePath);
|
||||||
|
|
||||||
|
// .part1.rar, .part2.rar などのパート表記を検出
|
||||||
|
var partMatch = Regex.Match(fileName, @"\.part(\d+)\.", RegexOptions.IgnoreCase);
|
||||||
|
if (partMatch.Success)
|
||||||
|
{
|
||||||
|
return $"Part {partMatch.Groups[1].Value}";
|
||||||
|
}
|
||||||
|
|
||||||
|
// part1, part2 等
|
||||||
|
var altPartMatch = Regex.Match(fileName, @"part(\d+)", RegexOptions.IgnoreCase);
|
||||||
|
if (altPartMatch.Success)
|
||||||
|
{
|
||||||
|
return $"Part {altPartMatch.Groups[1].Value}";
|
||||||
|
}
|
||||||
|
|
||||||
|
// 単一ファイルの場合、拡張子を含めて簡潔に表示
|
||||||
|
if (!string.IsNullOrWhiteSpace(fileName))
|
||||||
|
{
|
||||||
|
return fileName.Length > 20 ? fileName.Substring(fileName.Length - 20) : fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
return "ダウンロード";
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Windows のフォルダ名に使用できない禁止文字(\ / : * ? " < > |)を全角文字に置換します。
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="text">対象文字列</param>
|
||||||
|
/// <returns>置換後の安全な文字列</returns>
|
||||||
|
private static string SanitizeForWindows(string text)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(text))
|
||||||
|
{
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
var sb = new StringBuilder(text);
|
||||||
|
sb.Replace('\\', '¥');
|
||||||
|
sb.Replace('/', '/');
|
||||||
|
sb.Replace(':', ':');
|
||||||
|
sb.Replace('*', '*');
|
||||||
|
sb.Replace('?', '?');
|
||||||
|
sb.Replace('"', '”');
|
||||||
|
sb.Replace('<', '<');
|
||||||
|
sb.Replace('>', '>');
|
||||||
|
sb.Replace('|', '|');
|
||||||
|
|
||||||
|
// 改行コードを除去
|
||||||
|
sb.Replace("\r", " ").Replace("\n", " ");
|
||||||
|
|
||||||
|
return Regex.Replace(sb.ToString(), @"\s+", " ").Trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 記事詳細情報から、整形された視認性の高い本文 HTML を生成します。
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="article">記事詳細情報オブジェクト</param>
|
||||||
|
/// <returns>生成された本文 HTML</returns>
|
||||||
|
private static string GenerateSummaryHtml(ArticleInfo article)
|
||||||
|
{
|
||||||
|
var sb = new StringBuilder();
|
||||||
|
|
||||||
|
// コンテナ開始(スタイル定義)
|
||||||
|
sb.AppendLine($"<div style=\"font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif; line-height: 1.6; color: #212529; max-width: 800px; margin: 0 auto;\">");
|
||||||
|
|
||||||
|
// 1. バッジ・タグ表示および公開日時(日本時間)
|
||||||
|
sb.AppendLine(" <div style=\"margin-bottom: 12px;\">");
|
||||||
|
sb.AppendLine(" <span style=\"display: inline-block; background-color: #1a237e; color: #ffffff; padding: 3px 8px; font-size: 11px; font-weight: bold; border-radius: 4px; margin-right: 6px;\">JPFILES.NET</span>");
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(article.CategoryTag))
|
||||||
|
{
|
||||||
|
sb.AppendLine($" <span style=\"display: inline-block; background-color: #37474f; color: #ffffff; padding: 3px 8px; font-size: 11px; font-weight: bold; border-radius: 4px; margin-right: 6px;\">{WebUtility.HtmlEncode(article.CategoryTag)}</span>");
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.AppendLine($" <span style=\"display: inline-block; font-size: 11px; color: #6c757d; font-weight: bold; margin-left: 4px;\">📅 {article.PublishDate:yyyy/MM/dd HH:mm:ss} (JST)</span>");
|
||||||
|
sb.AppendLine(" </div>");
|
||||||
|
|
||||||
|
// 2. コピー用フォルダ名枠(クリックで全選択できるワンクリックコピー仕様)
|
||||||
|
sb.AppendLine(" <div style=\"margin-bottom: 16px; background-color: #f8f9fa; border: 1px solid #ced4da; border-radius: 6px; padding: 10px;\">");
|
||||||
|
sb.AppendLine(" <div style=\"font-size: 11px; color: #6c757d; font-weight: bold; margin-bottom: 4px;\">📁 フォルダ名用タイトル(クリックで全選択)</div>");
|
||||||
|
sb.AppendLine($" <input type=\"text\" readonly value=\"{WebUtility.HtmlEncode(article.CleanTitle)}\" onclick=\"this.select();\" style=\"width: 100%; padding: 6px 10px; font-size: 13px; font-family: Consolas, monospace; background-color: #ffffff; border: 1px solid #adb5bd; border-radius: 4px; box-sizing: border-box; cursor: pointer; color: #212529;\" />");
|
||||||
|
sb.AppendLine(" </div>");
|
||||||
|
|
||||||
|
// 3. タイトル表示
|
||||||
|
sb.AppendLine($" <h2 style=\"font-size: 17px; font-weight: bold; margin: 0 0 16px 0; color: #0d47a1; line-height: 1.4;\">{WebUtility.HtmlEncode(article.CleanTitle)}</h2>");
|
||||||
|
|
||||||
|
// 4. ダウンロードリンク群(タイトル直下にグリッド配置)
|
||||||
|
if (article.Downloads.Count > 0)
|
||||||
|
{
|
||||||
|
sb.AppendLine(" <div style=\"margin-bottom: 20px; background-color: #e8eaf6; border: 1px solid #c5cae9; border-radius: 8px; padding: 14px;\">");
|
||||||
|
sb.AppendLine(" <div style=\"font-size: 13px; font-weight: bold; color: #1a237e; margin-bottom: 10px;\">⚡ ダイレクト・ダウンロードリンク(直リンク)</div>");
|
||||||
|
sb.AppendLine(" <div style=\"display: flex; flex-wrap: wrap; gap: 8px;\">");
|
||||||
|
|
||||||
|
foreach (var dl in article.Downloads)
|
||||||
|
{
|
||||||
|
var label = $"{dl.ProviderName} {dl.PartLabel}";
|
||||||
|
sb.AppendLine($" <a href=\"{WebUtility.HtmlEncode(dl.Url)}\" target=\"_blank\" rel=\"noopener noreferrer\" style=\"display: inline-block; background-color: {dl.BgColor}; color: #ffffff; padding: 8px 14px; font-size: 12px; font-weight: bold; text-decoration: none; border-radius: 6px; box-shadow: 0 1px 3px rgba(0,0,0,0.15); transition: opacity 0.2s;\">⬇ {WebUtility.HtmlEncode(label)}</a>");
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.AppendLine(" </div>");
|
||||||
|
sb.AppendLine(" </div>");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 5. カバー画像表示(サムネイル表示 & クリックで原寸表示)
|
||||||
|
if (!string.IsNullOrWhiteSpace(article.CoverImageUrl))
|
||||||
|
{
|
||||||
|
var openUrl = !string.IsNullOrWhiteSpace(article.CoverOriginalUrl) ? article.CoverOriginalUrl : article.CoverImageUrl;
|
||||||
|
sb.AppendLine(" <div style=\"text-align: center; margin: 20px 0;\">");
|
||||||
|
sb.AppendLine($" <a href=\"{WebUtility.HtmlEncode(openUrl)}\" target=\"_blank\" rel=\"noopener noreferrer\">");
|
||||||
|
sb.AppendLine($" <img src=\"{WebUtility.HtmlEncode(article.CoverImageUrl)}\" alt=\"{WebUtility.HtmlEncode(article.CleanTitle)}\" style=\"max-width: 100%; height: auto; border-radius: 6px; box-shadow: 0 2px 8px rgba(0,0,0,0.15); border: 1px solid #e0e0e0;\" />");
|
||||||
|
sb.AppendLine(" </a>");
|
||||||
|
sb.AppendLine(" <div style=\"font-size: 11px; color: #757575; margin-top: 6px;\">※画像クリックで高解像度表示</div>");
|
||||||
|
sb.AppendLine(" </div>");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 6. 元記事リンクおよびフォーマット識別タグ
|
||||||
|
sb.AppendLine(" <div style=\"margin-top: 20px; padding-top: 10px; border-top: 1px dashed #cccccc; font-size: 12px;\">");
|
||||||
|
sb.AppendLine($" <a href=\"{WebUtility.HtmlEncode(article.Url)}\" target=\"_blank\" rel=\"noopener noreferrer\" style=\"color: #1565c0; text-decoration: underline;\">🌐 jpfiles.net の元記事を見る</a>");
|
||||||
|
sb.AppendLine(" </div>");
|
||||||
|
|
||||||
|
// キャッシュ識別用タグ
|
||||||
|
sb.AppendLine($" <!-- {CacheFormatTag} -->");
|
||||||
|
|
||||||
|
sb.AppendLine("</div>");
|
||||||
|
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
@@ -1,26 +1,145 @@
|
|||||||
using AngleSharp.Dom;
|
using AngleSharp.Dom;
|
||||||
using AngleSharp.Html.Dom;
|
using AngleSharp.Html.Dom;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
|
using System.Net.Http;
|
||||||
using System.ServiceModel.Syndication;
|
using System.ServiceModel.Syndication;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Xml;
|
||||||
using rss_generator.Class.Common;
|
using rss_generator.Class.Common;
|
||||||
|
|
||||||
namespace rss_generator.Class.KimochiInfo;
|
namespace rss_generator.Class.KimochiInfo;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// kimochi.info の Windows 向け日本語作品一覧から RSS フィード (kimochiinfo.xml) を生成するクラスです。
|
||||||
|
/// </summary>
|
||||||
internal class kimochiinfo
|
internal class kimochiinfo
|
||||||
{
|
{
|
||||||
|
#region □定数(Private)
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// プロジェクト固有規則に基づく出力先ドメインディレクトリ名です。
|
||||||
|
/// </summary>
|
||||||
|
private const string DomainDir = "kimochi.info";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// キャッシュ判定用の最新フォーマット識別子です。
|
||||||
|
/// </summary>
|
||||||
|
private const string CacheFormatTag = "kimochi-format-v1";
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region □クラス(Private)
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 既存の RSS フィードから読み込んだ記事情報を保持する内部クラスです。
|
||||||
|
/// </summary>
|
||||||
|
private sealed class ExistingFeedEntry
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 記事のタイトル(サークル名・バージョン表記を含む)を取得または設定します。
|
||||||
|
/// </summary>
|
||||||
|
public string Title { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 記事の本文 HTML (Summary) を取得または設定します。
|
||||||
|
/// </summary>
|
||||||
|
public string SummaryHtml { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 記事の初回公開日時を取得または設定します。
|
||||||
|
/// </summary>
|
||||||
|
public DateTimeOffset PublishDate { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 記事の最終更新日時を取得または設定します。
|
||||||
|
/// </summary>
|
||||||
|
public DateTimeOffset LastUpdatedTime { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// ダウンロードリンクの情報を保持するクラスです。
|
||||||
|
/// </summary>
|
||||||
|
private sealed class DownloadItem
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// プロバイダー名(Google Drive, MediaFire, Workupload等)を取得または設定します。
|
||||||
|
/// </summary>
|
||||||
|
public string ProviderName { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// kimochi.info のオリジナルダウンロードURLを取得または設定します。
|
||||||
|
/// </summary>
|
||||||
|
public string RawUrl { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 解決された直接の外部ストレージURL(Google Drive, MediaFire等)を取得または設定します。
|
||||||
|
/// </summary>
|
||||||
|
public string DirectStorageUrl { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 最終的なリンク先URLを取得します。直リンクが解決されている場合は直リンク、それ以外は元URLを返します。
|
||||||
|
/// </summary>
|
||||||
|
public string FinalUrl => !string.IsNullOrWhiteSpace(this.DirectStorageUrl) ? this.DirectStorageUrl : this.RawUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 解析された記事詳細情報を保持する内部クラスです。
|
||||||
|
/// </summary>
|
||||||
|
private sealed class ArticleDetailInfo
|
||||||
|
{
|
||||||
|
/// <summary>サークル名・開発元を取得または設定します。</summary>
|
||||||
|
public string CircleName { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>日本語タイトルを取得または設定します。</summary>
|
||||||
|
public string JapaneseTitle { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>バージョン情報を取得または設定します。</summary>
|
||||||
|
public string VersionText { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>DLsite 等の公式ストア URL を取得または設定します。</summary>
|
||||||
|
public string OfficialStoreUrl { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>メイン画像(カバー画像)の URL を取得または設定します。</summary>
|
||||||
|
public string MainImageUrl { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>ダウンロードリンク一覧を取得または設定します。</summary>
|
||||||
|
public List<DownloadItem> Downloads { get; set; } = new();
|
||||||
|
|
||||||
|
/// <summary>本文解説の HTML を取得または設定します。</summary>
|
||||||
|
public string BodyHtml { get; set; } = string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region □メソッド(Public)
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// kimochi.info から記事情報を収集し、RSS フィード (kimochiinfo.xml) を生成・出力します。
|
||||||
|
/// 既存のフィードが存在する場合は同一バージョンの記事情報をそのまま引き継ぎ、
|
||||||
|
/// FreshRSS 等で「更新された記事を未読とする」が有効な場合でも不要な未読化が発生しないようにします。
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="client">HTTP 通信用 HttpClient</param>
|
||||||
|
/// <returns>非同期タスク</returns>
|
||||||
public static async Task CreateRSSAsync(HttpClient client)
|
public static async Task CreateRSSAsync(HttpClient client)
|
||||||
{
|
{
|
||||||
var baseURL = "https://kimochi.info/browse/";
|
var baseURL = "https://kimochi.info/browse/";
|
||||||
var query = "?platform=windows";
|
var query = "?platform=windows";
|
||||||
|
var fileName = "kimochiinfo.xml";
|
||||||
|
|
||||||
var feed = new SyndicationFeed("kimochi.info", "", new Uri($"{baseURL}{query}"));
|
var feed = new SyndicationFeed("kimochi.info", "", new Uri($"{baseURL}{query}"));
|
||||||
var items = new List<SyndicationItem>();
|
var items = new List<SyndicationItem>();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// 複数ページをまとめる場合に先に取得する
|
// プロジェクト固有規則に従い、ドメイン別サブディレクトリ(output/kimochi.info/)から既存キャッシュを読込
|
||||||
|
var existingEntries = LoadExistingEntries(fileName);
|
||||||
|
|
||||||
|
// 複数ページ(1〜5ページ)を取得
|
||||||
var docList = new List<IDocument>();
|
var docList = new List<IDocument>();
|
||||||
for (int pageId = 1; pageId <= 5; pageId++)
|
for (int pageId = 1; pageId <= 5; pageId++)
|
||||||
{
|
{
|
||||||
@@ -55,13 +174,14 @@ internal class kimochiinfo
|
|||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
var itemUri = !string.IsNullOrEmpty(linkHref) ? new Uri(linkHref) : null;
|
var itemUri = !string.IsNullOrEmpty(linkHref) ? new Uri(linkHref) : null;
|
||||||
var imageUri = !string.IsNullOrEmpty(imageSrc) ? new Uri(imageSrc) : null;
|
|
||||||
if (itemUri == null)
|
if (itemUri == null)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// バージョン表記の取得
|
||||||
var divVerElems = linkElement.QuerySelectorAll("div>div.tracking-wider");
|
var divVerElems = linkElement.QuerySelectorAll("div>div.tracking-wider");
|
||||||
var versionText = "v1.0.0";
|
var versionText = "v1.0.0";
|
||||||
foreach (var divVerElem in divVerElems)
|
foreach (var divVerElem in divVerElems)
|
||||||
@@ -71,68 +191,617 @@ internal class kimochiinfo
|
|||||||
}
|
}
|
||||||
|
|
||||||
var h3Elem = linkElement.QuerySelector("h3");
|
var h3Elem = linkElement.QuerySelector("h3");
|
||||||
var title = $"{h3Elem!.TextContent.Replace("\t", "").Replace("\r", "").Replace("\n", "").Trim()} {versionText}";
|
var rawTitle = h3Elem?.TextContent?.Replace("\t", "")?.Replace("\r", "")?.Replace("\n", "")?.Trim() ?? string.Empty;
|
||||||
|
|
||||||
|
// 日本語版 (JP) の判定
|
||||||
var divContents = linkElement.QuerySelectorAll("h3+div>div");
|
var divContents = linkElement.QuerySelectorAll("h3+div>div");
|
||||||
var isJP = false;
|
var isJP = false;
|
||||||
if (divContents!.Length > 2)
|
if (divContents.Length > 2)
|
||||||
{
|
{
|
||||||
var span = divContents[1];
|
var span = divContents[1];
|
||||||
if (span.TextContent.Contains("JP"))
|
if (span.TextContent.Contains("JP", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
isJP = true;
|
isJP = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isJP == false)
|
if (!isJP)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var guid = CmnUtil.CreateGuid(linkHref);
|
||||||
|
existingEntries.TryGetValue(linkHref, out var prevEntry);
|
||||||
|
if (prevEntry == null && !string.IsNullOrEmpty(guid))
|
||||||
|
{
|
||||||
|
existingEntries.TryGetValue(guid, out prevEntry);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 最新フォーマット識別子 kimochi-format-v1 が含まれているキャッシュのみ再利用
|
||||||
|
bool isLatestFormat = prevEntry != null &&
|
||||||
|
prevEntry.SummaryHtml.Contains("kimochi-dl-section") &&
|
||||||
|
prevEntry.SummaryHtml.Contains(CacheFormatTag);
|
||||||
|
|
||||||
|
SyndicationItem item;
|
||||||
|
if (isLatestFormat && prevEntry != null)
|
||||||
|
{
|
||||||
|
// 【キャッシュヒット(未更新記事)】
|
||||||
|
// 前回の本文HTMLおよび日時(PublishDate / LastUpdatedTime)をそのまま維持
|
||||||
|
item = new SyndicationItem(
|
||||||
|
prevEntry.Title,
|
||||||
|
(string?)null,
|
||||||
|
itemUri,
|
||||||
|
guid,
|
||||||
|
prevEntry.LastUpdatedTime
|
||||||
|
)
|
||||||
|
{
|
||||||
|
PublishDate = prevEntry.PublishDate,
|
||||||
|
LastUpdatedTime = prevEntry.LastUpdatedTime,
|
||||||
|
Summary = new TextSyndicationContent(prevEntry.SummaryHtml, TextSyndicationContentKind.Html)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// 【新規記事またはフォーマット更新記事】
|
||||||
var docContents = await CmnUtil.GetDocument(client, linkHref);
|
var docContents = await CmnUtil.GetDocument(client, linkHref);
|
||||||
var divDetail = docContents.QuerySelector("main>div>div")!;
|
if (docContents == null)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var detailInfo = await ParseArticleDetailAsync(client, docContents, rawTitle, versionText, imageSrc ?? string.Empty);
|
||||||
|
if (detailInfo == null)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// フォルダ名用タイトルの構築: [サークル名] タイトル (バージョン)
|
||||||
|
string folderTitle = BuildFolderTitle(detailInfo.CircleName, detailInfo.JapaneseTitle, detailInfo.VersionText);
|
||||||
|
|
||||||
|
// 本文 HTML の構築(フォルダ名コピー枠、タイトル表示、直リンク化済みダウンロードセクション、公式ストアボタン、カバー画像、解説)
|
||||||
|
string summaryHtml = BuildSummaryHtml(detailInfo, folderTitle, itemUri);
|
||||||
|
|
||||||
var metaPubDate = CmnUtil.GetPublishedTimeAsJst(docContents);
|
var metaPubDate = CmnUtil.GetPublishedTimeAsJst(docContents);
|
||||||
var metaModDate = CmnUtil.GetModifiedTimeAsJst(docContents);
|
var metaModDate = CmnUtil.GetModifiedTimeAsJst(docContents);
|
||||||
|
|
||||||
var body = new StringBuilder();
|
DateTimeOffset publishDate;
|
||||||
|
DateTimeOffset lastUpdatedTime;
|
||||||
|
|
||||||
body.Append($@"<div>バージョン:{versionText}</div>");
|
if (prevEntry != null)
|
||||||
body.Append($@"<div><a href=""{itemUri}"" target=""_blank"" rel=""noopener noreferrer"" referrerpolicy=""no-referrer"">{title}</a></div>");
|
|
||||||
body.Append($@"<div><img src=""{imageUri}"" referrerpolicy=""no-referrer"" alt=""{title}"" style=""max-width: 100%; height: auto;"" /></div>");
|
|
||||||
|
|
||||||
foreach (var a in divDetail.QuerySelectorAll("a"))
|
|
||||||
{
|
{
|
||||||
a.SetAttribute("target", "_blank");
|
publishDate = prevEntry.PublishDate != DateTimeOffset.MinValue
|
||||||
a.SetAttribute("rel", "noopener noreferrer");
|
? prevEntry.PublishDate
|
||||||
a.SetAttribute("referrerpolicy", "no-referrer");
|
: (metaPubDate.HasValue ? new DateTimeOffset(metaPubDate.Value) : DateTimeOffset.Now);
|
||||||
}
|
|
||||||
foreach (var img in divDetail.QuerySelectorAll("img"))
|
|
||||||
{
|
|
||||||
img.SetAttribute("referrerpolicy", "no-referrer");
|
|
||||||
}
|
|
||||||
body.Append(CmnUtil.GetHtmlWithoutJavaScript(divDetail));
|
|
||||||
|
|
||||||
var item = new SyndicationItem(
|
lastUpdatedTime = metaModDate.HasValue
|
||||||
title,
|
? new DateTimeOffset(metaModDate.Value)
|
||||||
string.Empty,
|
: DateTimeOffset.Now;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
publishDate = metaPubDate.HasValue
|
||||||
|
? new DateTimeOffset(metaPubDate.Value)
|
||||||
|
: (metaModDate.HasValue ? new DateTimeOffset(metaModDate.Value) : DateTimeOffset.Now);
|
||||||
|
|
||||||
|
lastUpdatedTime = metaModDate.HasValue
|
||||||
|
? new DateTimeOffset(metaModDate.Value)
|
||||||
|
: publishDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
item = new SyndicationItem(
|
||||||
|
folderTitle,
|
||||||
|
(string?)null,
|
||||||
itemUri,
|
itemUri,
|
||||||
CmnUtil.CreateGuid(linkHref),
|
guid,
|
||||||
metaModDate ?? (metaPubDate ?? DateTime.Now) // 取得できた公開日時があればそれをセット
|
lastUpdatedTime
|
||||||
);
|
)
|
||||||
// item.Content = SyndicationContent.CreateHtmlContent(body.ToString());
|
{
|
||||||
// ※ RSS 2.0の場合は Content よりも Summary(<description>タグ)が使われることが多いため、
|
PublishDate = publishDate,
|
||||||
// 両方に設定しておくか、Summary側にHTMLを設定すると大半のリーダーで確実です。
|
LastUpdatedTime = lastUpdatedTime,
|
||||||
item.Summary = new TextSyndicationContent(body.ToString(), TextSyndicationContentKind.Html);
|
Summary = new TextSyndicationContent(summaryHtml, TextSyndicationContentKind.Html)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
items.Add(item);
|
items.Add(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
feed.Items = items;
|
feed.Items = items;
|
||||||
|
|
||||||
// kimochiinfo は画像リンクを Base64 変換せず、通常の画像リンクとして出力する
|
// プロジェクト固有規則に従い、ドメイン名サブディレクトリ (output/kimochi.info/kimochiinfo.xml) に出力
|
||||||
await CmnUtil.ExportXMLFileAsync("kimochiinfo.xml", feed, client, embedBase64: false);
|
await CmnUtil.ExportXMLFileAsync(
|
||||||
|
fileName,
|
||||||
|
feed,
|
||||||
|
client,
|
||||||
|
addDir: DomainDir,
|
||||||
|
embedBase64: false,
|
||||||
|
filter24Hours: false);
|
||||||
|
|
||||||
|
LogManager.AddLog($"[情報] 【kimochiinfo】 出力完了 - 記事数: {items.Count}");
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
LogManager.AddLog($"[エラー] kimochiinfo:{ex.Message}");
|
LogManager.AddLog($"[エラー] 【kimochiinfo】 {ex.Message}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region □メソッド(Private)
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 記事詳細ページから各種情報(サークル名、タイトル、DLsiteリンク、ダウンロードリンク一覧、本文解説)を抽出・解析します。
|
||||||
|
/// 各ダウンロードリンクの直接外部ストレージURL(Google Drive, MediaFire等)も非同期解決します。
|
||||||
|
/// </summary>
|
||||||
|
private static async Task<ArticleDetailInfo?> ParseArticleDetailAsync(
|
||||||
|
HttpClient client,
|
||||||
|
IDocument doc,
|
||||||
|
string rawTitle,
|
||||||
|
string versionText,
|
||||||
|
string fallbackImageSrc)
|
||||||
|
{
|
||||||
|
var mainElem = doc.QuerySelector("main");
|
||||||
|
if (mainElem == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var info = new ArticleDetailInfo
|
||||||
|
{
|
||||||
|
VersionText = versionText
|
||||||
|
};
|
||||||
|
|
||||||
|
// 1. サークル名・開発元の抽出 (a[href*="/developer/"] または a[href*="/publisher/"])
|
||||||
|
var devLink = doc.QuerySelector("a[href*='/developer/'], a[href*='/publisher/']");
|
||||||
|
if (devLink != null)
|
||||||
|
{
|
||||||
|
string devText = devLink.TextContent
|
||||||
|
.Replace("Developer", "", StringComparison.OrdinalIgnoreCase)
|
||||||
|
.Replace("Publisher", "", StringComparison.OrdinalIgnoreCase)
|
||||||
|
.Replace("code", "", StringComparison.OrdinalIgnoreCase)
|
||||||
|
.Trim();
|
||||||
|
info.CircleName = SanitizeWindowsPath(devText);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. タイトルの抽出(H1 または一覧の rawTitle)
|
||||||
|
var h1Elem = doc.QuerySelector("h1");
|
||||||
|
string titleCandidate = h1Elem?.TextContent?.Trim() ?? rawTitle;
|
||||||
|
string cleanTitle = RemoveProductIds(titleCandidate);
|
||||||
|
info.JapaneseTitle = SanitizeWindowsPath(cleanTitle);
|
||||||
|
|
||||||
|
// 3. DLsite リンクの抽出
|
||||||
|
var dlsiteLink = doc.QuerySelector("a[href*='dlsite.com']");
|
||||||
|
if (dlsiteLink != null)
|
||||||
|
{
|
||||||
|
info.OfficialStoreUrl = dlsiteLink.GetAttribute("href") ?? string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. メインカバー画像の抽出
|
||||||
|
var mainImg = doc.QuerySelector("main img");
|
||||||
|
string imgSrc = (mainImg as IHtmlImageElement)?.Source ?? mainImg?.GetAttribute("src") ?? fallbackImageSrc;
|
||||||
|
info.MainImageUrl = imgSrc ?? string.Empty;
|
||||||
|
|
||||||
|
// 5. ダウンロードリンクの抽出と直リンク解決
|
||||||
|
var dlElements = doc.QuerySelectorAll("a[href*='/download/']");
|
||||||
|
var addedUrls = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
||||||
|
|
||||||
|
foreach (var dlElem in dlElements)
|
||||||
|
{
|
||||||
|
string href = dlElem.GetAttribute("href") ?? string.Empty;
|
||||||
|
if (string.IsNullOrWhiteSpace(href) || !href.Contains("/download/") || href.Contains("/file/?dl="))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// プロバイダー名の抽出(Google Drive, MediaFire, Workupload 等)
|
||||||
|
string rawText = dlElem.TextContent ?? string.Empty;
|
||||||
|
string providerName = CleanProviderName(rawText);
|
||||||
|
|
||||||
|
if (addedUrls.Add(href))
|
||||||
|
{
|
||||||
|
var dlItem = new DownloadItem
|
||||||
|
{
|
||||||
|
ProviderName = providerName,
|
||||||
|
RawUrl = href
|
||||||
|
};
|
||||||
|
|
||||||
|
// 直接外部ストレージURLの自動解決(待機カウントダウンを経由しない直リンク化)
|
||||||
|
string directUrl = await ResolveDirectDownloadUrlAsync(client, href);
|
||||||
|
if (!string.IsNullOrWhiteSpace(directUrl))
|
||||||
|
{
|
||||||
|
dlItem.DirectStorageUrl = directUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
info.Downloads.Add(dlItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 6. 本文解説(広告・トラッキング要素を除去)
|
||||||
|
var divDetail = doc.QuerySelector("main>div>div") ?? mainElem;
|
||||||
|
var cloneDetail = divDetail.Clone() as IElement;
|
||||||
|
if (cloneDetail != null)
|
||||||
|
{
|
||||||
|
RemoveUnwantedElements(cloneDetail);
|
||||||
|
|
||||||
|
foreach (var a in cloneDetail.QuerySelectorAll("a"))
|
||||||
|
{
|
||||||
|
a.SetAttribute("target", "_blank");
|
||||||
|
a.SetAttribute("rel", "noopener noreferrer");
|
||||||
|
a.SetAttribute("referrerpolicy", "no-referrer");
|
||||||
|
}
|
||||||
|
foreach (var img in cloneDetail.QuerySelectorAll("img"))
|
||||||
|
{
|
||||||
|
img.SetAttribute("referrerpolicy", "no-referrer");
|
||||||
|
}
|
||||||
|
|
||||||
|
info.BodyHtml = CmnUtil.GetHtmlWithoutJavaScript(cloneDetail);
|
||||||
|
}
|
||||||
|
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// kimochi.info のダウンロードURLから末尾のハッシュを抽出し、
|
||||||
|
/// https://kimochi.info/download/file/?dl=[hash] へリクエストを行って
|
||||||
|
/// x-download-url または Location ヘッダーから直接外部ストレージURL(Google Drive, MediaFire等)を解決します。
|
||||||
|
/// </summary>
|
||||||
|
private static async Task<string> ResolveDirectDownloadUrlAsync(HttpClient client, string downloadUrl)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(downloadUrl))
|
||||||
|
{
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
var match = Regex.Match(downloadUrl, @"/download/([^/?#]+)", RegexOptions.IgnoreCase);
|
||||||
|
if (!match.Success)
|
||||||
|
{
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
string hash = match.Groups[1].Value.Trim();
|
||||||
|
string fileUrl = $"https://kimochi.info/download/file/?dl={Uri.EscapeDataString(hash)}";
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var request = new HttpRequestMessage(HttpMethod.Get, fileUrl);
|
||||||
|
request.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36");
|
||||||
|
|
||||||
|
// レスポンスヘッダーのみ読み取り、大容量ファイルのダウンロード通信を防止
|
||||||
|
using var response = await client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead);
|
||||||
|
|
||||||
|
// 1. x-download-url ヘッダーの確認(最も確実)
|
||||||
|
if (response.Headers.TryGetValues("x-download-url", out var downloadUrls))
|
||||||
|
{
|
||||||
|
string direct = downloadUrls.FirstOrDefault() ?? string.Empty;
|
||||||
|
if (!string.IsNullOrWhiteSpace(direct))
|
||||||
|
{
|
||||||
|
return direct;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. Location ヘッダー(301/302リダイレクト時)の確認
|
||||||
|
if (response.Headers.Location != null)
|
||||||
|
{
|
||||||
|
string loc = response.Headers.Location.AbsoluteUri;
|
||||||
|
if (!loc.Contains("kimochi.info", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
return loc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. リダイレクト自動追従時の最終リクエストURIの確認
|
||||||
|
if (response.RequestMessage?.RequestUri != null)
|
||||||
|
{
|
||||||
|
string finalUri = response.RequestMessage.RequestUri.AbsoluteUri;
|
||||||
|
if (!finalUri.Contains("kimochi.info", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
return finalUri;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
LogManager.AddLog($"[情報] 【kimochiinfo】 直リンク解決スキップ ({hash}): {ex.Message}");
|
||||||
|
}
|
||||||
|
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// アンカーテキストからアイコン名や余分な文字を除去し、クリーンなプロバイダー名を取得します。
|
||||||
|
/// </summary>
|
||||||
|
private static string CleanProviderName(string rawText)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(rawText))
|
||||||
|
{
|
||||||
|
return "Download";
|
||||||
|
}
|
||||||
|
|
||||||
|
string cleaned = rawText
|
||||||
|
.Replace("add_to_drive", "", StringComparison.OrdinalIgnoreCase)
|
||||||
|
.Replace("whatshot", "", StringComparison.OrdinalIgnoreCase)
|
||||||
|
.Replace("cloud_download", "", StringComparison.OrdinalIgnoreCase)
|
||||||
|
.Replace("arrow_forward", "", StringComparison.OrdinalIgnoreCase)
|
||||||
|
.Replace("Download", "", StringComparison.OrdinalIgnoreCase)
|
||||||
|
.Replace("Game", "", StringComparison.OrdinalIgnoreCase)
|
||||||
|
.Trim();
|
||||||
|
|
||||||
|
cleaned = Regex.Replace(cleaned, @"\s+", " ").Trim();
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(cleaned))
|
||||||
|
{
|
||||||
|
return "Download";
|
||||||
|
}
|
||||||
|
|
||||||
|
return cleaned;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// サークル名・タイトル・バージョン情報から Windows フォルダ名としてコピー可能なタイトルを構築します。
|
||||||
|
/// </summary>
|
||||||
|
private static string BuildFolderTitle(string circleName, string title, string version)
|
||||||
|
{
|
||||||
|
string verSuffix = !string.IsNullOrWhiteSpace(version) && !title.Contains(version, StringComparison.OrdinalIgnoreCase)
|
||||||
|
? $" {version}"
|
||||||
|
: string.Empty;
|
||||||
|
|
||||||
|
string result;
|
||||||
|
if (!string.IsNullOrWhiteSpace(circleName))
|
||||||
|
{
|
||||||
|
result = $"[{circleName}] {title}{verSuffix}".Trim();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result = $"{title}{verSuffix}".Trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
return SanitizeWindowsPath(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 整形された本文 HTML を生成します。
|
||||||
|
/// フォルダ名コピー枠、タイトル表示、整然としたグリッド型ダウンロードリンク、公式ストアリンク、カバー画像、解説文を配置します。
|
||||||
|
/// </summary>
|
||||||
|
private static string BuildSummaryHtml(ArticleDetailInfo info, string folderTitle, Uri articleUri)
|
||||||
|
{
|
||||||
|
var sb = new StringBuilder();
|
||||||
|
|
||||||
|
// 1. バッジ
|
||||||
|
sb.Append("<div style=\"margin-bottom: 12px;\">");
|
||||||
|
sb.Append("<span style=\"display: inline-block; background-color: #2e7d32; color: #ffffff; padding: 4px 10px; border-radius: 4px; font-weight: bold; font-size: 13px;\">🇯🇵 日本語版 (RAW / 原作)</span>");
|
||||||
|
if (!string.IsNullOrWhiteSpace(info.VersionText))
|
||||||
|
{
|
||||||
|
sb.Append($"<span style=\"display: inline-block; background-color: #424242; color: #ffffff; padding: 4px 8px; border-radius: 4px; font-size: 13px; margin-left: 8px;\">🏷️ {WebUtility.HtmlEncode(info.VersionText)}</span>");
|
||||||
|
}
|
||||||
|
sb.Append("</div>");
|
||||||
|
|
||||||
|
// 2. フォルダ名用タイトルコピー枠
|
||||||
|
sb.Append($"<div class=\"kimochi-folder-title {CacheFormatTag}\" style=\"background-color: #f3f4f6; border-left: 4px solid #374151; padding: 10px 14px; margin-bottom: 12px; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif; border-radius: 0 4px 4px 0;\">");
|
||||||
|
sb.Append("<div style=\"font-size: 11px; font-weight: bold; color: #4b5563; margin-bottom: 4px;\">📁 フォルダ名用タイトル (コピー用):</div>");
|
||||||
|
sb.Append($"<div style=\"font-size: 15px; font-weight: bold; color: #111827; user-select: all; -webkit-user-select: all;\">{WebUtility.HtmlEncode(folderTitle)}</div>");
|
||||||
|
sb.Append("</div>");
|
||||||
|
|
||||||
|
// 3. 日本語タイトルの明記
|
||||||
|
if (!string.IsNullOrWhiteSpace(info.JapaneseTitle))
|
||||||
|
{
|
||||||
|
sb.Append("<div class=\"kimochi-jp-title\" style=\"background-color: #f1f8e9; border-left: 4px solid #43a047; padding: 8px 12px; margin-bottom: 12px; font-size: 14px; border-radius: 0 4px 4px 0;\">");
|
||||||
|
sb.Append("<strong style=\"color: #2e7d32;\">日本語タイトル (Japanese Title):</strong> ");
|
||||||
|
sb.Append($"<span>{WebUtility.HtmlEncode(info.JapaneseTitle)}</span>");
|
||||||
|
sb.Append("</div>");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. ダウンロードセクション (kimochi-dl-section) - 日本語タイトルの直下に配置
|
||||||
|
if (info.Downloads.Any())
|
||||||
|
{
|
||||||
|
sb.Append("<div class=\"kimochi-dl-section\" style=\"background-color: #f7f9fa; border: 1px solid #cfd8dc; border-radius: 6px; padding: 14px; margin-top: 10px; margin-bottom: 14px; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;\">");
|
||||||
|
sb.Append("<h4 style=\"margin: 0 0 10px 0; font-size: 16px; border-bottom: 2px solid #e53935; padding-bottom: 6px; color: #c62828;\">");
|
||||||
|
sb.Append("📥 ダウンロード (DIRECT DOWNLOAD)");
|
||||||
|
sb.Append("</h4>");
|
||||||
|
|
||||||
|
// 整然としたレスポンシブグリッドレイアウトでボタンを配置(横1行詰め込みを解消)
|
||||||
|
sb.Append("<div style=\"display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 8px; margin-bottom: 10px;\">");
|
||||||
|
|
||||||
|
foreach (var dl in info.Downloads)
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrWhiteSpace(dl.FinalUrl))
|
||||||
|
{
|
||||||
|
string bgColor = GetProviderButtonColor(dl.ProviderName);
|
||||||
|
string icon = GetProviderIcon(dl.ProviderName);
|
||||||
|
|
||||||
|
sb.Append($"<a href=\"{dl.FinalUrl}\" target=\"_blank\" rel=\"noopener noreferrer\" referrerpolicy=\"no-referrer\" style=\"display: flex; align-items: center; justify-content: center; gap: 6px; text-align: center; background-color: {bgColor}; color: #ffffff; padding: 9px 14px; border-radius: 4px; text-decoration: none; font-weight: bold; font-size: 13px; box-shadow: 0 1px 3px rgba(0,0,0,0.12);\">");
|
||||||
|
sb.Append($"<span>{icon}</span> <span>{WebUtility.HtmlEncode(dl.ProviderName)}</span>");
|
||||||
|
sb.Append("</a>");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.Append("</div>");
|
||||||
|
sb.Append("</div>");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 5. 公式ストア(DLsite等)リンク
|
||||||
|
if (!string.IsNullOrWhiteSpace(info.OfficialStoreUrl))
|
||||||
|
{
|
||||||
|
sb.Append("<div style=\"margin-bottom: 14px;\">");
|
||||||
|
sb.Append($"<a href=\"{info.OfficialStoreUrl}\" target=\"_blank\" rel=\"noopener noreferrer\" referrerpolicy=\"no-referrer\" style=\"display: inline-flex; align-items: center; gap: 6px; background-color: #f59e0b; color: #ffffff; padding: 8px 16px; border-radius: 4px; text-decoration: none; font-weight: bold; font-size: 13px; box-shadow: 0 1px 3px rgba(0,0,0,0.12);\">");
|
||||||
|
sb.Append("🛒 <span>DLsite で購入して公式を支援 (Official Store)</span>");
|
||||||
|
sb.Append("</a>");
|
||||||
|
sb.Append("</div>");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 6. メインカバー画像
|
||||||
|
if (!string.IsNullOrWhiteSpace(info.MainImageUrl))
|
||||||
|
{
|
||||||
|
sb.Append("<div style=\"margin-bottom: 14px;\">");
|
||||||
|
sb.Append($"<img src=\"{info.MainImageUrl}\" referrerpolicy=\"no-referrer\" alt=\"{WebUtility.HtmlEncode(info.JapaneseTitle)}\" style=\"max-width: 100%; height: auto; border-radius: 4px; box-shadow: 0 2px 4px rgba(0,0,0,0.1);\" />");
|
||||||
|
sb.Append("</div>");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 7. 本文解説
|
||||||
|
if (!string.IsNullOrWhiteSpace(info.BodyHtml))
|
||||||
|
{
|
||||||
|
sb.Append("<div style=\"margin-top: 14px; line-height: 1.6; color: #212121;\">");
|
||||||
|
sb.Append(info.BodyHtml);
|
||||||
|
sb.Append("</div>");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 8. 記事ページへのリンク
|
||||||
|
sb.Append("<div style=\"margin-top: 16px; padding-top: 10px; border-top: 1px solid #e0e0e0; font-size: 13px;\">");
|
||||||
|
sb.Append($"<a href=\"{articleUri}\" target=\"_blank\" rel=\"noopener noreferrer\" referrerpolicy=\"no-referrer\" style=\"color: #1976d2; text-decoration: none;\">🔗 kimochi.info 記事ページを開く</a>");
|
||||||
|
sb.Append("</div>");
|
||||||
|
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// プロバイダー名に応じたボタン背景色を取得します。
|
||||||
|
/// </summary>
|
||||||
|
private static string GetProviderButtonColor(string providerName)
|
||||||
|
{
|
||||||
|
if (providerName.Contains("Drive", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
return "#0f9d58"; // Google Drive (緑)
|
||||||
|
}
|
||||||
|
if (providerName.Contains("MediaFire", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
return "#1976d2"; // MediaFire (青)
|
||||||
|
}
|
||||||
|
if (providerName.Contains("Workupload", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
return "#ea580c"; // Workupload (オレンジ)
|
||||||
|
}
|
||||||
|
if (providerName.Contains("Mega", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
return "#d32f2f"; // Mega (赤)
|
||||||
|
}
|
||||||
|
if (providerName.Contains("PixelDrain", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
return "#7b1fa2"; // PixelDrain (紫)
|
||||||
|
}
|
||||||
|
return "#1976d2";
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// プロバイダー名に応じたアイコン絵文字を取得します。
|
||||||
|
/// </summary>
|
||||||
|
private static string GetProviderIcon(string providerName)
|
||||||
|
{
|
||||||
|
if (providerName.Contains("Drive", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
return "💾";
|
||||||
|
}
|
||||||
|
if (providerName.Contains("Workupload", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
return "☁️";
|
||||||
|
}
|
||||||
|
return "⬇️";
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Windows のフォルダ名に使用できない記号文字を全角文字に置換します。
|
||||||
|
/// </summary>
|
||||||
|
private static string SanitizeWindowsPath(string name)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(name))
|
||||||
|
{
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
return name
|
||||||
|
.Replace('\\', '¥')
|
||||||
|
.Replace('/', '/')
|
||||||
|
.Replace(':', ':')
|
||||||
|
.Replace('*', '*')
|
||||||
|
.Replace('?', '?')
|
||||||
|
.Replace('"', '”')
|
||||||
|
.Replace('<', '<')
|
||||||
|
.Replace('>', '>')
|
||||||
|
.Replace('|', '|')
|
||||||
|
.Trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// タイトル文字列から製品ID([RJ01735580], (RJ01735580) 等)を除去します。
|
||||||
|
/// </summary>
|
||||||
|
private static string RemoveProductIds(string text)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(text))
|
||||||
|
{
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
string cleaned = Regex.Replace(text, @"[\[\(\{\【]\s*(?:RJ|VJ|BJ)\d{6,8}\s*[\]\)\}\】]", "", RegexOptions.IgnoreCase);
|
||||||
|
cleaned = Regex.Replace(cleaned, @"\b(?:RJ|VJ|BJ)\d{6,8}\b", "", RegexOptions.IgnoreCase);
|
||||||
|
cleaned = Regex.Replace(cleaned, @"\s{2,}", " ");
|
||||||
|
return cleaned.Trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 既存の XML ファイルから各記事のタイトル・本文 HTML・公開日時・更新日時を読み込みます。
|
||||||
|
/// プロジェクト固有規則に基づき、ドメイン別サブディレクトリ(output/kimochi.info/)内のファイルを読み込みます。
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="fileName">XML ファイル名</param>
|
||||||
|
/// <returns>URL または GUID をキーとする既存エントリの辞書</returns>
|
||||||
|
private static Dictionary<string, ExistingFeedEntry> LoadExistingEntries(string fileName)
|
||||||
|
{
|
||||||
|
var existingEntries = new Dictionary<string, ExistingFeedEntry>(StringComparer.OrdinalIgnoreCase);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string xmlPath = CmnUtil.GetExportXmlPath(fileName, addDir: DomainDir);
|
||||||
|
if (!File.Exists(xmlPath))
|
||||||
|
{
|
||||||
|
return existingEntries;
|
||||||
|
}
|
||||||
|
|
||||||
|
using var reader = XmlReader.Create(xmlPath);
|
||||||
|
var existingFeed = SyndicationFeed.Load(reader);
|
||||||
|
if (existingFeed?.Items != null)
|
||||||
|
{
|
||||||
|
foreach (var item in existingFeed.Items)
|
||||||
|
{
|
||||||
|
var linkUrl = item.Links.FirstOrDefault()?.Uri?.AbsoluteUri;
|
||||||
|
var guid = item.Id;
|
||||||
|
|
||||||
|
var entry = new ExistingFeedEntry
|
||||||
|
{
|
||||||
|
Title = item.Title?.Text?.Trim() ?? string.Empty,
|
||||||
|
SummaryHtml = item.Summary?.Text?.Trim() ?? string.Empty,
|
||||||
|
PublishDate = item.PublishDate != DateTimeOffset.MinValue
|
||||||
|
? item.PublishDate
|
||||||
|
: (item.LastUpdatedTime != DateTimeOffset.MinValue ? item.LastUpdatedTime : DateTimeOffset.Now),
|
||||||
|
LastUpdatedTime = item.LastUpdatedTime != DateTimeOffset.MinValue
|
||||||
|
? item.LastUpdatedTime
|
||||||
|
: (item.PublishDate != DateTimeOffset.MinValue ? item.PublishDate : DateTimeOffset.Now)
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(linkUrl) && !existingEntries.ContainsKey(linkUrl))
|
||||||
|
{
|
||||||
|
existingEntries[linkUrl] = entry;
|
||||||
|
}
|
||||||
|
if (!string.IsNullOrWhiteSpace(guid) && !existingEntries.ContainsKey(guid))
|
||||||
|
{
|
||||||
|
existingEntries[guid] = entry;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
LogManager.AddLog($"[情報] kimochiinfo 既存エントリ読み込みスキップ: {ex.Message}");
|
||||||
|
}
|
||||||
|
|
||||||
|
return existingEntries;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 詳細ページ内の不要な広告枠やトラッキング要素を除去します。
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="element">対象の HTML 要素</param>
|
||||||
|
private static void RemoveUnwantedElements(IElement element)
|
||||||
|
{
|
||||||
|
var unwantedNodes = element.QuerySelectorAll("div[data-cl-spot], div[data-km], ins.adsbygoogle, script, style");
|
||||||
|
foreach (var node in unwantedNodes)
|
||||||
|
{
|
||||||
|
node.Remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
using AngleSharp.Dom;
|
using AngleSharp.Dom;
|
||||||
using AngleSharp.Html.Dom;
|
using AngleSharp.Html.Dom;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@@ -185,7 +185,7 @@ internal class mangalear
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
AddLog($"[エラー] [mangalear]: {ex.Message}");
|
AddLog($"[エラー] 【mangalear】 {ex.Message}");
|
||||||
CmnUtil.PrintCallStackToEvent(ex);
|
CmnUtil.PrintCallStackToEvent(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,39 +1,64 @@
|
|||||||
using AngleSharp.Dom;
|
using AngleSharp.Dom;
|
||||||
using AngleSharp.Html.Dom;
|
using AngleSharp.Html.Dom;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.ServiceModel.Syndication;
|
using System.ServiceModel.Syndication;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Xml;
|
||||||
using rss_generator.Class.Common;
|
using rss_generator.Class.Common;
|
||||||
|
|
||||||
namespace rss_generator.Class.MissAV;
|
namespace rss_generator.Class.MissAV;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// missav.ai の新着動画を取得し、WebImageViewer (https://udukipc-web.armonica-vps.work/) で動画を視聴できるリンクを含むRSSを生成します。
|
/// missav.ai の新着動画を取得し、WebImageViewer (https://udukipc-web.armonica-vps.work/) で動画を視聴できるリンクを含むRSSを生成します。
|
||||||
|
/// 既存のフィードが存在する場合は同一記事の情報を引き継ぎ、FreshRSS 等で「更新された記事を未読とする」が有効な場合でも不要な未読化が発生しないようにします。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal static class missav
|
internal static class missav
|
||||||
{
|
{
|
||||||
|
#region □クラス(Private)
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 既存の RSS フィードから読み込んだ記事情報を保持する内部クラスです。
|
||||||
|
/// </summary>
|
||||||
|
private sealed class ExistingFeedEntry
|
||||||
|
{
|
||||||
|
public string Title { get; set; } = string.Empty;
|
||||||
|
public string SummaryHtml { get; set; } = string.Empty;
|
||||||
|
public DateTimeOffset PublishDate { get; set; }
|
||||||
|
public DateTimeOffset LastUpdatedTime { get; set; }
|
||||||
|
public List<string> Categories { get; set; } = new();
|
||||||
|
public List<string> Authors { get; set; } = new();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region □メソッド(Public)
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// missav.ai の新着動画から RSS フィード (missav.xml) を生成・出力します。
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="client">HttpClient</param>
|
||||||
|
/// <param name="sessionId">FlareSolverr セッションID</param>
|
||||||
|
/// <returns>非同期タスク</returns>
|
||||||
public static async Task CreateRSSAsync(HttpClient client, string? sessionId = null)
|
public static async Task CreateRSSAsync(HttpClient client, string? sessionId = null)
|
||||||
{
|
{
|
||||||
var pageMaster = "https://missav.ai";
|
var pageMaster = "https://missav.ai";
|
||||||
|
var fileName = "missav.xml";
|
||||||
var feed = new SyndicationFeed("missav.ai", "missav Recent Videos", new Uri($"{pageMaster}/ja/new"));
|
var feed = new SyndicationFeed("missav.ai", "missav Recent Videos", new Uri($"{pageMaster}/ja/new"));
|
||||||
var items = new List<SyndicationItem>();
|
var items = new List<SyndicationItem>();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// 外部からセッションが渡されなかった場合は自前で作成
|
sessionId ??= CmnUtil.SharedFlareSolverrSessionId;
|
||||||
bool ownSession = sessionId == null;
|
|
||||||
if (ownSession)
|
// 既存フィードの読み込み(未更新記事の不要な未読化防止およびFlareSolverrアクセス削減)
|
||||||
{
|
var existingEntries = LoadExistingEntries(fileName);
|
||||||
sessionId = await CmnUtil.CreateFlareSolverrSession(client);
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var docList = new List<IDocument>();
|
var docList = new List<IDocument>();
|
||||||
for (int pageId = 1; pageId <= 2; pageId++)
|
for (int pageId = 1; pageId <= 2; pageId++)
|
||||||
{
|
{
|
||||||
@@ -80,9 +105,44 @@ internal static class missav
|
|||||||
|
|
||||||
var itemUri = new Uri(linkHref);
|
var itemUri = new Uri(linkHref);
|
||||||
var imageUri = !string.IsNullOrEmpty(imageSrc) ? new Uri(imageSrc) : null;
|
var imageUri = !string.IsNullOrEmpty(imageSrc) ? new Uri(imageSrc) : null;
|
||||||
|
var guid = CmnUtil.CreateGuid(linkHref);
|
||||||
|
|
||||||
// 詳細ページから動画ストリーム情報およびメタ情報を取得
|
existingEntries.TryGetValue(linkHref, out var prevEntry);
|
||||||
string? streamUrl = null;
|
if (prevEntry == null && !string.IsNullOrEmpty(guid))
|
||||||
|
{
|
||||||
|
existingEntries.TryGetValue(guid, out prevEntry);
|
||||||
|
}
|
||||||
|
|
||||||
|
SyndicationItem item;
|
||||||
|
if (prevEntry != null && !string.IsNullOrEmpty(prevEntry.SummaryHtml))
|
||||||
|
{
|
||||||
|
// 【未更新記事】
|
||||||
|
// 前回の本文HTMLおよび日時をそのまま維持して未読化を完全防止
|
||||||
|
item = new SyndicationItem(
|
||||||
|
title,
|
||||||
|
(string?)null,
|
||||||
|
itemUri,
|
||||||
|
guid,
|
||||||
|
prevEntry.LastUpdatedTime
|
||||||
|
)
|
||||||
|
{
|
||||||
|
PublishDate = prevEntry.PublishDate,
|
||||||
|
LastUpdatedTime = prevEntry.LastUpdatedTime,
|
||||||
|
Summary = new TextSyndicationContent(prevEntry.SummaryHtml, TextSyndicationContentKind.Html)
|
||||||
|
};
|
||||||
|
|
||||||
|
foreach (var cat in prevEntry.Categories)
|
||||||
|
{
|
||||||
|
item.Categories.Add(new SyndicationCategory(cat));
|
||||||
|
}
|
||||||
|
foreach (var auth in prevEntry.Authors)
|
||||||
|
{
|
||||||
|
item.Authors.Add(new SyndicationPerson { Name = auth });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// 【新規記事】
|
||||||
string? descText = null;
|
string? descText = null;
|
||||||
string? maker = null;
|
string? maker = null;
|
||||||
var actresses = new List<string>();
|
var actresses = new List<string>();
|
||||||
@@ -94,33 +154,6 @@ internal static class missav
|
|||||||
var docDetail = await CmnUtil.GetDocumentFlareSolverr(client, linkHref, session: sessionId);
|
var docDetail = await CmnUtil.GetDocumentFlareSolverr(client, linkHref, session: sessionId);
|
||||||
if (docDetail != null)
|
if (docDetail != null)
|
||||||
{
|
{
|
||||||
var sourceText = docDetail.Source.Text;
|
|
||||||
|
|
||||||
// 1. surrit.com の m3u8 URL を正規表現で抽出
|
|
||||||
var surritMatch = Regex.Match(sourceText, @"https?:\\?/\\?/[^""'\s\\]*surrit\.com/[^""'\s\\]+?\.m3u8", RegexOptions.IgnoreCase);
|
|
||||||
if (surritMatch.Success)
|
|
||||||
{
|
|
||||||
streamUrl = surritMatch.Value.Replace(@"\/", "/");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// 2. UUID から surrit.com の playlist.m3u8 を構築
|
|
||||||
var uuidMatch = Regex.Match(sourceText, @"[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}", RegexOptions.IgnoreCase);
|
|
||||||
if (uuidMatch.Success)
|
|
||||||
{
|
|
||||||
streamUrl = $"https://surrit.com/{uuidMatch.Value}/playlist.m3u8";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// 3. 汎用 .m3u8 のフォールバック抽出
|
|
||||||
var m3u8Match = Regex.Match(sourceText, @"https?:\\?/\\?/[^""'\s\\]+?\.m3u8", RegexOptions.IgnoreCase);
|
|
||||||
if (m3u8Match.Success)
|
|
||||||
{
|
|
||||||
streamUrl = m3u8Match.Value.Replace(@"\/", "/");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 詳細テキスト(説明文)
|
// 詳細テキスト(説明文)
|
||||||
descText = docDetail.QuerySelector("meta[name='description']")?.GetAttribute("content")
|
descText = docDetail.QuerySelector("meta[name='description']")?.GetAttribute("content")
|
||||||
?? docDetail.QuerySelector("meta[property='og:description']")?.GetAttribute("content")
|
?? docDetail.QuerySelector("meta[property='og:description']")?.GetAttribute("content")
|
||||||
@@ -171,10 +204,9 @@ internal static class missav
|
|||||||
// WebImageViewer統一リンクの生成 (https://udukipc-web.armonica-vps.work/?url=[ページURL])
|
// WebImageViewer統一リンクの生成 (https://udukipc-web.armonica-vps.work/?url=[ページURL])
|
||||||
string viewerUrl = $"https://udukipc-web.armonica-vps.work/?url={Uri.EscapeDataString(linkHref)}";
|
string viewerUrl = $"https://udukipc-web.armonica-vps.work/?url={Uri.EscapeDataString(linkHref)}";
|
||||||
|
|
||||||
// 本文 HTML(Summary)の生成(123avと同様の構成)
|
|
||||||
var body = new StringBuilder();
|
var body = new StringBuilder();
|
||||||
|
|
||||||
// 1. WebImageViewer への再生リンク & 外部リンク(記事への直接埋め込みは行わない)
|
// 1. WebImageViewer への再生リンク & 外部リンク
|
||||||
body.Append($@"<div style=""margin-bottom: 12px; padding: 10px 14px; background: rgba(236, 72, 153, 0.08); border-radius: 8px; border-left: 4px solid #ec4899;"">");
|
body.Append($@"<div style=""margin-bottom: 12px; padding: 10px 14px; background: rgba(236, 72, 153, 0.08); border-radius: 8px; border-left: 4px solid #ec4899;"">");
|
||||||
body.Append($@"<p style=""margin: 0 0 6px 0;""><a href=""{viewerUrl}"" target=""_blank"" rel=""noopener noreferrer"" style=""font-weight: bold; font-size: 1.1em; color: #db2777; text-decoration: none;"">▶ WebImageViewerで動画を再生する</a></p>");
|
body.Append($@"<p style=""margin: 0 0 6px 0;""><a href=""{viewerUrl}"" target=""_blank"" rel=""noopener noreferrer"" style=""font-weight: bold; font-size: 1.1em; color: #db2777; text-decoration: none;"">▶ WebImageViewerで動画を再生する</a></p>");
|
||||||
body.Append($@"<p style=""margin: 0; font-size: 0.9em; color: #64748b;""><a href=""{itemUri}"" target=""_blank"" rel=""noopener noreferrer"" referrerpolicy=""no-referrer"">missav公式ページで開く</a></p>");
|
body.Append($@"<p style=""margin: 0; font-size: 0.9em; color: #64748b;""><a href=""{itemUri}"" target=""_blank"" rel=""noopener noreferrer"" referrerpolicy=""no-referrer"">missav公式ページで開く</a></p>");
|
||||||
@@ -208,13 +240,19 @@ internal static class missav
|
|||||||
body.Append($@"<div><strong>タグ:</strong> {WebUtility.HtmlEncode(string.Join(", ", tags))}</div>");
|
body.Append($@"<div><strong>タグ:</strong> {WebUtility.HtmlEncode(string.Join(", ", tags))}</div>");
|
||||||
}
|
}
|
||||||
|
|
||||||
var item = new SyndicationItem(
|
var now = DateTimeOffset.Now;
|
||||||
|
item = new SyndicationItem(
|
||||||
title,
|
title,
|
||||||
string.Empty,
|
(string?)null,
|
||||||
itemUri,
|
itemUri,
|
||||||
CmnUtil.CreateGuid(linkHref),
|
guid,
|
||||||
DateTime.Now
|
now
|
||||||
);
|
)
|
||||||
|
{
|
||||||
|
PublishDate = now,
|
||||||
|
LastUpdatedTime = now,
|
||||||
|
Summary = new TextSyndicationContent(body.ToString(), TextSyndicationContentKind.Html)
|
||||||
|
};
|
||||||
|
|
||||||
// カテゴリ登録(ジャンル、タグ、女優)
|
// カテゴリ登録(ジャンル、タグ、女優)
|
||||||
foreach (var g in genres)
|
foreach (var g in genres)
|
||||||
@@ -239,27 +277,83 @@ internal static class missav
|
|||||||
{
|
{
|
||||||
item.Authors.Add(new SyndicationPerson { Name = actresses[0] });
|
item.Authors.Add(new SyndicationPerson { Name = actresses[0] });
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
item.Summary = new TextSyndicationContent(body.ToString(), TextSyndicationContentKind.Html);
|
|
||||||
items.Add(item);
|
items.Add(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
feed.Items = items;
|
feed.Items = items;
|
||||||
await CmnUtil.ExportXMLFileAsync("missav.xml", feed, client);
|
await CmnUtil.ExportXMLFileAsync(fileName, feed, client, filter24Hours: false);
|
||||||
}
|
}
|
||||||
finally
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
if (ownSession && sessionId != null)
|
LogManager.AddLog($"[エラー] 【missav】 {ex.Message}");
|
||||||
|
CmnUtil.PrintCallStackToEvent(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region □メソッド(Private)
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 既存の XML ファイルから各記事のタイトル・本文 HTML・公開日時・更新日時を読み込みます。
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="fileName">XML ファイル名</param>
|
||||||
|
/// <returns>URL または GUID をキーとする既存エントリの辞書</returns>
|
||||||
|
private static Dictionary<string, ExistingFeedEntry> LoadExistingEntries(string fileName)
|
||||||
{
|
{
|
||||||
await CmnUtil.DestroyFlareSolverrSession(client, sessionId);
|
var existingEntries = new Dictionary<string, ExistingFeedEntry>(StringComparer.OrdinalIgnoreCase);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string xmlPath = CmnUtil.GetExportXmlPath(fileName);
|
||||||
|
if (!File.Exists(xmlPath))
|
||||||
|
{
|
||||||
|
return existingEntries;
|
||||||
|
}
|
||||||
|
|
||||||
|
using var reader = XmlReader.Create(xmlPath);
|
||||||
|
var existingFeed = SyndicationFeed.Load(reader);
|
||||||
|
if (existingFeed?.Items != null)
|
||||||
|
{
|
||||||
|
foreach (var item in existingFeed.Items)
|
||||||
|
{
|
||||||
|
var linkUrl = item.Links.FirstOrDefault()?.Uri?.AbsoluteUri;
|
||||||
|
var guid = item.Id;
|
||||||
|
|
||||||
|
var entry = new ExistingFeedEntry
|
||||||
|
{
|
||||||
|
Title = item.Title?.Text?.Trim() ?? string.Empty,
|
||||||
|
SummaryHtml = item.Summary?.Text?.Trim() ?? string.Empty,
|
||||||
|
PublishDate = item.PublishDate != DateTimeOffset.MinValue
|
||||||
|
? item.PublishDate
|
||||||
|
: (item.LastUpdatedTime != DateTimeOffset.MinValue ? item.LastUpdatedTime : DateTimeOffset.Now),
|
||||||
|
LastUpdatedTime = item.LastUpdatedTime != DateTimeOffset.MinValue
|
||||||
|
? item.LastUpdatedTime
|
||||||
|
: (item.PublishDate != DateTimeOffset.MinValue ? item.PublishDate : DateTimeOffset.Now),
|
||||||
|
Categories = item.Categories.Select(c => c.Name).ToList(),
|
||||||
|
Authors = item.Authors.Select(a => a.Name).ToList()
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(linkUrl) && !existingEntries.ContainsKey(linkUrl))
|
||||||
|
{
|
||||||
|
existingEntries[linkUrl] = entry;
|
||||||
|
}
|
||||||
|
if (!string.IsNullOrWhiteSpace(guid) && !existingEntries.ContainsKey(guid))
|
||||||
|
{
|
||||||
|
existingEntries[guid] = entry;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
LogManager.AddLog($"[エラー] missav:{ex.Message}");
|
LogManager.AddLog($"[情報] missav 既存エントリ読み込みスキップ: {ex.Message}");
|
||||||
CmnUtil.PrintCallStackToEvent(ex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return existingEntries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
@@ -1,40 +1,64 @@
|
|||||||
using AngleSharp.Dom;
|
using AngleSharp.Dom;
|
||||||
using AngleSharp.Html.Dom;
|
using AngleSharp.Html.Dom;
|
||||||
using AngleSharp.Html.Parser;
|
using AngleSharp.Html.Parser;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.ServiceModel.Syndication;
|
using System.ServiceModel.Syndication;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Xml;
|
||||||
using rss_generator.Class.Common;
|
using rss_generator.Class.Common;
|
||||||
|
|
||||||
namespace rss_generator.Class.MissAV123;
|
namespace rss_generator.Class.MissAV123;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 123av.com の新着動画を取得し、WebImageViewer (https://udukipc-web.armonica-vps.work/) で動画を視聴できるリンクを含むRSSを生成します。
|
||||||
|
/// 既存のフィードが存在する場合は同一記事の情報を引き継ぎ、FreshRSS 等で「更新された記事を未読とする」が有効な場合でも不要な未読化が発生しないようにします。
|
||||||
|
/// </summary>
|
||||||
internal class missav123
|
internal class missav123
|
||||||
{
|
{
|
||||||
|
#region □クラス(Private)
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 123av.com の新着動画を取得し、WebImageViewer (https://udukipc-web.armonica-vps.work/) で動画を視聴できるリンクを含むRSSを生成します。
|
/// 既存の RSS フィードから読み込んだ記事情報を保持する内部クラスです。
|
||||||
|
/// </summary>
|
||||||
|
private sealed class ExistingFeedEntry
|
||||||
|
{
|
||||||
|
public string Title { get; set; } = string.Empty;
|
||||||
|
public string SummaryHtml { get; set; } = string.Empty;
|
||||||
|
public DateTimeOffset PublishDate { get; set; }
|
||||||
|
public DateTimeOffset LastUpdatedTime { get; set; }
|
||||||
|
public List<string> Categories { get; set; } = new();
|
||||||
|
public List<string> Authors { get; set; } = new();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region □メソッド(Public)
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 123av.com の新着動画を取得し、RSS フィード (123av.xml) を生成・出力します。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="client">HttpClient インスタンス</param>
|
/// <param name="client">HttpClient インスタンス</param>
|
||||||
|
/// <param name="sessionId">FlareSolverr セッションID</param>
|
||||||
public static async Task CreateRSSAsync(HttpClient client, string? sessionId = null)
|
public static async Task CreateRSSAsync(HttpClient client, string? sessionId = null)
|
||||||
{
|
{
|
||||||
var pageMaster = "https://123av.com";
|
var pageMaster = "https://123av.com";
|
||||||
|
var fileName = "123av.xml";
|
||||||
|
|
||||||
var feed = new SyndicationFeed("123av.com", "123av Recent Videos", new Uri($"{pageMaster}/ja/recent"));
|
var feed = new SyndicationFeed("123av.com", "123av Recent Videos", new Uri($"{pageMaster}/ja/recent"));
|
||||||
var items = new List<SyndicationItem>();
|
var items = new List<SyndicationItem>();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// 外部からセッションが渡されなかった場合は自前で作成
|
sessionId ??= CmnUtil.SharedFlareSolverrSessionId;
|
||||||
bool ownSession = sessionId == null;
|
|
||||||
if (ownSession)
|
// 既存フィードの読み込み(相対時間の再計算による未読化防止および高速化)
|
||||||
{
|
var existingEntries = LoadExistingEntries(fileName);
|
||||||
sessionId = await CmnUtil.CreateFlareSolverrSession(client);
|
|
||||||
}
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var docList = new List<IDocument>();
|
var docList = new List<IDocument>();
|
||||||
for (int pageId = 1; pageId <= 2; pageId++)
|
for (int pageId = 1; pageId <= 2; pageId++)
|
||||||
{
|
{
|
||||||
@@ -68,7 +92,7 @@ internal class missav123
|
|||||||
? relHref
|
? relHref
|
||||||
: $"{pageMaster.TrimEnd('/')}/{relHref.TrimStart('/')}";
|
: $"{pageMaster.TrimEnd('/')}/{relHref.TrimStart('/')}";
|
||||||
|
|
||||||
var imageSrc = imgElement?.GetAttribute("src");
|
var imageSrc = imgElement?.GetAttribute("data-src") ?? imgElement?.GetAttribute("src");
|
||||||
if (!linkList.Contains(linkHref))
|
if (!linkList.Contains(linkHref))
|
||||||
{
|
{
|
||||||
linkList.Add(linkHref);
|
linkList.Add(linkHref);
|
||||||
@@ -78,67 +102,98 @@ internal class missav123
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
var cardMetaTimeText = div.QuerySelector(".card__meta span")?.TextContent?.Trim();
|
|
||||||
|
|
||||||
var itemUri = new Uri(linkHref);
|
var itemUri = new Uri(linkHref);
|
||||||
var imageUri = !string.IsNullOrEmpty(imageSrc) ? new Uri(imageSrc) : null;
|
var imageUri = !string.IsNullOrEmpty(imageSrc) ? new Uri(imageSrc) : null;
|
||||||
|
var guid = CmnUtil.CreateGuid(linkHref);
|
||||||
|
|
||||||
|
existingEntries.TryGetValue(linkHref, out var prevEntry);
|
||||||
|
if (prevEntry == null && !string.IsNullOrEmpty(guid))
|
||||||
|
{
|
||||||
|
existingEntries.TryGetValue(guid, out prevEntry);
|
||||||
|
}
|
||||||
|
|
||||||
|
SyndicationItem item;
|
||||||
|
if (prevEntry != null && !string.IsNullOrEmpty(prevEntry.SummaryHtml))
|
||||||
|
{
|
||||||
|
// 【未更新記事】
|
||||||
|
// 前回の本文HTMLおよび日時(PublishDate / LastUpdatedTime)をそのまま維持
|
||||||
|
item = new SyndicationItem(
|
||||||
|
title,
|
||||||
|
(string?)null,
|
||||||
|
itemUri,
|
||||||
|
guid,
|
||||||
|
prevEntry.LastUpdatedTime
|
||||||
|
)
|
||||||
|
{
|
||||||
|
PublishDate = prevEntry.PublishDate,
|
||||||
|
LastUpdatedTime = prevEntry.LastUpdatedTime,
|
||||||
|
Summary = new TextSyndicationContent(prevEntry.SummaryHtml, TextSyndicationContentKind.Html)
|
||||||
|
};
|
||||||
|
|
||||||
|
foreach (var cat in prevEntry.Categories)
|
||||||
|
{
|
||||||
|
item.Categories.Add(new SyndicationCategory(cat));
|
||||||
|
}
|
||||||
|
foreach (var auth in prevEntry.Authors)
|
||||||
|
{
|
||||||
|
item.Authors.Add(new SyndicationPerson { Name = auth });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// 【新規記事】
|
||||||
|
// カード上の時間表記
|
||||||
|
var cardMetaTimeText = div.QuerySelector(".card__meta")?.TextContent?.Trim();
|
||||||
|
|
||||||
// 詳細ページから動画プレイヤーURLおよび詳細情報を取得
|
|
||||||
string? playerUrl = null;
|
|
||||||
string? descText = null;
|
string? descText = null;
|
||||||
var genres = new List<string>();
|
|
||||||
var tags = new List<string>();
|
|
||||||
var actresses = new List<string>();
|
|
||||||
string? maker = null;
|
|
||||||
string? series = null;
|
|
||||||
string? releaseDateText = null;
|
string? releaseDateText = null;
|
||||||
string? detailMetaTimeText = null;
|
string? detailMetaTimeText = null;
|
||||||
|
string? maker = null;
|
||||||
|
string? series = null;
|
||||||
|
var actresses = new List<string>();
|
||||||
|
var genres = new List<string>();
|
||||||
|
var tags = new List<string>();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var docDetail = await CmnUtil.GetDocumentFlareSolverr(client, linkHref, session: sessionId);
|
var docDetail = await CmnUtil.GetDocumentFlareSolverr(client, linkHref, session: sessionId);
|
||||||
if (docDetail != null)
|
if (docDetail != null)
|
||||||
{
|
{
|
||||||
// 1. iframe.player__frame の src から取得
|
// 詳細テキスト(説明文)
|
||||||
playerUrl = docDetail.QuerySelector("iframe.player__frame")?.GetAttribute("src")
|
descText = docDetail.QuerySelector("meta[name='description']")?.GetAttribute("content")
|
||||||
?? docDetail.QuerySelector(".player iframe")?.GetAttribute("src");
|
?? docDetail.QuerySelector("meta[property='og:description']")?.GetAttribute("content")
|
||||||
|
?? docDetail.QuerySelector(".detail__description")?.TextContent?.Trim();
|
||||||
|
|
||||||
// 2. HTML内の javplayer.cc URL から正規表現で取得(フォールバック)
|
// 発売日および更新日時
|
||||||
if (string.IsNullOrEmpty(playerUrl))
|
var metaDivs = docDetail.QuerySelectorAll(".detail__meta, .card__meta, .video-info span, .detail__info div");
|
||||||
|
foreach (var m in metaDivs)
|
||||||
{
|
{
|
||||||
var match = Regex.Match(docDetail.Source.Text, @"https?:\\?/\\?/javplayer\.cc[^\s""'\\]+");
|
var txt = m.TextContent?.Trim();
|
||||||
if (match.Success)
|
if (string.IsNullOrEmpty(txt)) continue;
|
||||||
|
|
||||||
|
if (txt.Contains("発売日") || txt.Contains("リリース") || txt.Contains("Release"))
|
||||||
{
|
{
|
||||||
playerUrl = match.Value.Replace(@"\/", "/");
|
var mMatch = Regex.Match(txt, @"\d{4}[-/年]\d{1,2}[-/月]\d{1,2}");
|
||||||
|
if (mMatch.Success)
|
||||||
|
{
|
||||||
|
releaseDateText = mMatch.Value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (txt.Contains("前") || txt.Contains("ago"))
|
||||||
|
{
|
||||||
|
detailMetaTimeText = txt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. 詳細ページ上部の相対更新日時(例: "1分 56秒前", "31m 26s ago")
|
// メーカー / レーベル
|
||||||
detailMetaTimeText = docDetail.QuerySelector(".watch__meta--stats .watch__metaitem")?.TextContent?.Trim();
|
maker = docDetail.QuerySelector("a[href*='/makers/'], a[href*='/maker/'], a[href*='/labels/'], a[href*='/label/']")?.TextContent?.Trim();
|
||||||
if (!string.IsNullOrEmpty(detailMetaTimeText))
|
|
||||||
{
|
|
||||||
detailMetaTimeText = Regex.Replace(detailMetaTimeText, @"\s+", " ").Trim();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 4. 詳細説明文
|
// シリーズ
|
||||||
descText = docDetail.QuerySelector(".watch__desc-text")?.TextContent?.Trim();
|
series = docDetail.QuerySelector("a[href*='/series/'], a[href*='/serie/']")?.TextContent?.Trim();
|
||||||
|
|
||||||
// 5. 詳細情報ブロック (<dl class="watch__info">) 内の各項目を抽出
|
// 出演者
|
||||||
var infoRows = docDetail.QuerySelectorAll(".watch__info-row");
|
var actressElements = docDetail.QuerySelectorAll("a[href*='/actresses/'], a[href*='/actress/']");
|
||||||
foreach (var row in infoRows)
|
foreach (var a in actressElements)
|
||||||
{
|
|
||||||
var dtText = row.QuerySelector("dt")?.TextContent?.Trim() ?? string.Empty;
|
|
||||||
var ddElement = row.QuerySelector("dd");
|
|
||||||
if (string.IsNullOrEmpty(dtText) || ddElement == null) continue;
|
|
||||||
|
|
||||||
if (dtText.Contains("発売日") || dtText.Contains("公開日") || dtText.Contains("配信日") || dtText.Equals("Release date", StringComparison.OrdinalIgnoreCase))
|
|
||||||
{
|
|
||||||
releaseDateText = ddElement.TextContent?.Trim();
|
|
||||||
}
|
|
||||||
else if (dtText.Contains("出演者") || dtText.Contains("女優") || dtText.Equals("Cast", StringComparison.OrdinalIgnoreCase))
|
|
||||||
{
|
|
||||||
var actressLinks = ddElement.QuerySelectorAll("a");
|
|
||||||
foreach (var a in actressLinks)
|
|
||||||
{
|
{
|
||||||
var aName = a.TextContent?.Trim();
|
var aName = a.TextContent?.Trim();
|
||||||
if (!string.IsNullOrEmpty(aName) && !actresses.Contains(aName))
|
if (!string.IsNullOrEmpty(aName) && !actresses.Contains(aName))
|
||||||
@@ -146,62 +201,9 @@ internal class missav123
|
|||||||
actresses.Add(aName);
|
actresses.Add(aName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (actresses.Count == 0 && !string.IsNullOrWhiteSpace(ddElement.TextContent))
|
|
||||||
{
|
|
||||||
var textVal = ddElement.TextContent.Trim();
|
|
||||||
if (!actresses.Contains(textVal))
|
|
||||||
{
|
|
||||||
actresses.Add(textVal);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (dtText.Contains("メーカー") || dtText.Equals("Maker", StringComparison.OrdinalIgnoreCase))
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(maker))
|
|
||||||
{
|
|
||||||
maker = ddElement.TextContent?.Trim();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (dtText.Contains("シリーズ") || dtText.Equals("Series", StringComparison.OrdinalIgnoreCase))
|
|
||||||
{
|
|
||||||
series = ddElement.TextContent?.Trim();
|
|
||||||
}
|
|
||||||
else if (dtText.Contains("ジャンル") || dtText.Equals("Genres", StringComparison.OrdinalIgnoreCase))
|
|
||||||
{
|
|
||||||
var gLinks = ddElement.QuerySelectorAll("a");
|
|
||||||
foreach (var g in gLinks)
|
|
||||||
{
|
|
||||||
var gName = g.TextContent?.Trim();
|
|
||||||
if (!string.IsNullOrEmpty(gName) && !genres.Contains(gName))
|
|
||||||
{
|
|
||||||
genres.Add(gName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (dtText.Contains("タグ") || dtText.Equals("Tags", StringComparison.OrdinalIgnoreCase))
|
|
||||||
{
|
|
||||||
var tLinks = ddElement.QuerySelectorAll("a");
|
|
||||||
foreach (var t in tLinks)
|
|
||||||
{
|
|
||||||
var tName = t.TextContent?.Trim();
|
|
||||||
if (!string.IsNullOrEmpty(tName) && !tags.Contains(tName))
|
|
||||||
{
|
|
||||||
tags.Add(tName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// フォールバック: メーカー
|
// ジャンル
|
||||||
if (string.IsNullOrEmpty(maker))
|
var genreElements = docDetail.QuerySelectorAll("a[href*='/genres/'], a[href*='/genre/']");
|
||||||
{
|
|
||||||
maker = docDetail.QuerySelector("a[href*='/makers/']")?.TextContent?.Trim();
|
|
||||||
}
|
|
||||||
|
|
||||||
// フォールバック: ジャンル
|
|
||||||
if (genres.Count == 0)
|
|
||||||
{
|
|
||||||
var genreElements = docDetail.QuerySelectorAll("a[href*='/genres/']");
|
|
||||||
foreach (var g in genreElements)
|
foreach (var g in genreElements)
|
||||||
{
|
{
|
||||||
var gName = g.TextContent?.Trim();
|
var gName = g.TextContent?.Trim();
|
||||||
@@ -210,12 +212,9 @@ internal class missav123
|
|||||||
genres.Add(gName);
|
genres.Add(gName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// フォールバック: タグ
|
// タグ
|
||||||
if (tags.Count == 0)
|
var tagElements = docDetail.QuerySelectorAll("a[href*='/tags/'], a[href*='/tag/']");
|
||||||
{
|
|
||||||
var tagElements = docDetail.QuerySelectorAll("a[href*='/tags/']");
|
|
||||||
foreach (var t in tagElements)
|
foreach (var t in tagElements)
|
||||||
{
|
{
|
||||||
var tName = t.TextContent?.Trim();
|
var tName = t.TextContent?.Trim();
|
||||||
@@ -226,7 +225,6 @@ internal class missav123
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
LogManager.AddLog($"[警告] 123av 詳細ページ取得失敗 ({linkHref}): {ex.Message}");
|
LogManager.AddLog($"[警告] 123av 詳細ページ取得失敗 ({linkHref}): {ex.Message}");
|
||||||
@@ -235,7 +233,7 @@ internal class missav123
|
|||||||
// WebImageViewer統一リンクの生成 (https://udukipc-web.armonica-vps.work/?url=[ページURL])
|
// WebImageViewer統一リンクの生成 (https://udukipc-web.armonica-vps.work/?url=[ページURL])
|
||||||
string viewerUrl = $"https://udukipc-web.armonica-vps.work/?url={Uri.EscapeDataString(linkHref)}";
|
string viewerUrl = $"https://udukipc-web.armonica-vps.work/?url={Uri.EscapeDataString(linkHref)}";
|
||||||
|
|
||||||
// 更新日時(サイト上の追加・更新日時)の算出
|
// 更新日時の算出
|
||||||
DateTimeOffset? updatedDate = null;
|
DateTimeOffset? updatedDate = null;
|
||||||
var timeTextToParse = !string.IsNullOrWhiteSpace(detailMetaTimeText) ? detailMetaTimeText : cardMetaTimeText;
|
var timeTextToParse = !string.IsNullOrWhiteSpace(detailMetaTimeText) ? detailMetaTimeText : cardMetaTimeText;
|
||||||
if (!string.IsNullOrWhiteSpace(timeTextToParse))
|
if (!string.IsNullOrWhiteSpace(timeTextToParse))
|
||||||
@@ -257,23 +255,19 @@ internal class missav123
|
|||||||
// 本文 HTML(Summary)の生成
|
// 本文 HTML(Summary)の生成
|
||||||
var body = new StringBuilder();
|
var body = new StringBuilder();
|
||||||
|
|
||||||
// 1. WebImageViewer への再生リンク & 外部リンク(記事への直接埋め込みは行わない)
|
// 1. WebImageViewer への再生リンク & 外部リンク
|
||||||
body.Append($@"<div style=""margin-bottom: 12px; padding: 10px 14px; background: rgba(99, 102, 241, 0.08); border-radius: 8px; border-left: 4px solid #6366f1;"">");
|
body.Append($@"<div style=""margin-bottom: 12px; padding: 10px 14px; background: rgba(99, 102, 241, 0.08); border-radius: 8px; border-left: 4px solid #6366f1;"">");
|
||||||
body.Append($@"<p style=""margin: 0 0 6px 0;""><a href=""{viewerUrl}"" target=""_blank"" rel=""noopener noreferrer"" style=""font-weight: bold; font-size: 1.1em; color: #4f46e5; text-decoration: none;"">▶ WebImageViewerで動画を再生する</a></p>");
|
body.Append($@"<p style=""margin: 0 0 6px 0;""><a href=""{viewerUrl}"" target=""_blank"" rel=""noopener noreferrer"" style=""font-weight: bold; font-size: 1.1em; color: #4f46e5; text-decoration: none;"">▶ WebImageViewerで動画を再生する</a></p>");
|
||||||
body.Append($@"<p style=""margin: 0; font-size: 0.9em; color: #64748b;""><a href=""{itemUri}"" target=""_blank"" rel=""noopener noreferrer"" referrerpolicy=""no-referrer"">123av公式ページで開く</a>");
|
body.Append($@"<p style=""margin: 0; font-size: 0.9em; color: #64748b;""><a href=""{itemUri}"" target=""_blank"" rel=""noopener noreferrer"" referrerpolicy=""no-referrer"">123av公式ページで開く</a></p>");
|
||||||
if (!string.IsNullOrEmpty(playerUrl))
|
body.Append($@"</div>");
|
||||||
{
|
|
||||||
body.Append($@" | <a href=""{playerUrl}"" target=""_blank"" rel=""noopener noreferrer"" referrerpolicy=""no-referrer"">直接動画プレイヤーを開く</a>");
|
|
||||||
}
|
|
||||||
body.Append($@"</p></div>");
|
|
||||||
|
|
||||||
// 3. サムネイル画像
|
// 2. サムネイル画像
|
||||||
if (imageUri != null)
|
if (imageUri != null)
|
||||||
{
|
{
|
||||||
body.Append($@"<div><img src=""{imageUri}"" referrerpolicy=""no-referrer"" alt=""{WebUtility.HtmlEncode(title)}"" style=""max-width: 100%; height: auto; margin-top: 8px;"" /></div>");
|
body.Append($@"<div><img src=""{imageUri}"" referrerpolicy=""no-referrer"" alt=""{WebUtility.HtmlEncode(title)}"" style=""max-width: 100%; height: auto; margin-top: 8px;"" /></div>");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4. メタ情報(詳細、発売日、更新日時、メーカー、シリーズ、出演者、ジャンル、タグ)
|
// 3. メタ情報(詳細、発売日、更新日時、メーカー、シリーズ、出演者、ジャンル、タグ)
|
||||||
if (!string.IsNullOrWhiteSpace(descText))
|
if (!string.IsNullOrWhiteSpace(descText))
|
||||||
{
|
{
|
||||||
body.Append($@"<div style=""margin-top: 8px;""><strong>詳細:</strong> {WebUtility.HtmlEncode(descText)}</div>");
|
body.Append($@"<div style=""margin-top: 8px;""><strong>詳細:</strong> {WebUtility.HtmlEncode(descText)}</div>");
|
||||||
@@ -307,16 +301,17 @@ internal class missav123
|
|||||||
body.Append($@"<div><strong>タグ:</strong> {WebUtility.HtmlEncode(string.Join(", ", tags))}</div>");
|
body.Append($@"<div><strong>タグ:</strong> {WebUtility.HtmlEncode(string.Join(", ", tags))}</div>");
|
||||||
}
|
}
|
||||||
|
|
||||||
var item = new SyndicationItem(
|
item = new SyndicationItem(
|
||||||
title,
|
title,
|
||||||
string.Empty,
|
(string?)null,
|
||||||
itemUri,
|
itemUri,
|
||||||
CmnUtil.CreateGuid(linkHref),
|
guid,
|
||||||
lastUpdatedDate
|
lastUpdatedDate
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
PublishDate = publishDate,
|
PublishDate = publishDate,
|
||||||
LastUpdatedTime = lastUpdatedDate
|
LastUpdatedTime = lastUpdatedDate,
|
||||||
|
Summary = new TextSyndicationContent(body.ToString(), TextSyndicationContentKind.Html)
|
||||||
};
|
};
|
||||||
|
|
||||||
// カテゴリ登録(ジャンル、タグ、出演者)
|
// カテゴリ登録(ジャンル、タグ、出演者)
|
||||||
@@ -341,27 +336,18 @@ internal class missav123
|
|||||||
{
|
{
|
||||||
item.Authors.Add(new SyndicationPerson { Name = a });
|
item.Authors.Add(new SyndicationPerson { Name = a });
|
||||||
}
|
}
|
||||||
|
}
|
||||||
item.Summary = new TextSyndicationContent(body.ToString(), TextSyndicationContentKind.Html);
|
|
||||||
|
|
||||||
items.Add(item);
|
items.Add(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
feed.Items = items;
|
feed.Items = items;
|
||||||
|
|
||||||
await CmnUtil.ExportXMLFileAsync("123av.xml", feed, client);
|
await CmnUtil.ExportXMLFileAsync(fileName, feed, client, filter24Hours: false);
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
if (ownSession && sessionId != null)
|
|
||||||
{
|
|
||||||
await CmnUtil.DestroyFlareSolverrSession(client, sessionId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
LogManager.AddLog($"[エラー] 123av:{ex.Message}");
|
LogManager.AddLog($"[エラー] 【missav123】 {ex.Message}");
|
||||||
CmnUtil.PrintCallStackToEvent(ex);
|
CmnUtil.PrintCallStackToEvent(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -381,7 +367,7 @@ internal class missav123
|
|||||||
var span = TimeSpan.Zero;
|
var span = TimeSpan.Zero;
|
||||||
bool matched = false;
|
bool matched = false;
|
||||||
|
|
||||||
// 年 (日本語: "1年前", 英語: "1y ago", "1 year ago")
|
// 年
|
||||||
var yearMatch = Regex.Match(text, @"(\d+)\s*(?:年|y(?:ears?)?)(?:\s*前|\s*ago)?", RegexOptions.IgnoreCase);
|
var yearMatch = Regex.Match(text, @"(\d+)\s*(?:年|y(?:ears?)?)(?:\s*前|\s*ago)?", RegexOptions.IgnoreCase);
|
||||||
if (yearMatch.Success && int.TryParse(yearMatch.Groups[1].Value, out int years))
|
if (yearMatch.Success && int.TryParse(yearMatch.Groups[1].Value, out int years))
|
||||||
{
|
{
|
||||||
@@ -389,7 +375,7 @@ internal class missav123
|
|||||||
matched = true;
|
matched = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 月 (日本語: "1か月前", "1ヶ月前", "1月前", 英語: "1mo ago", "1 month ago")
|
// 月
|
||||||
var monthMatch = Regex.Match(text, @"(\d+)\s*(?:(?:か|ヶ|ケ)?月|mo(?:nths?)?)(?:\s*前|\s*ago)?", RegexOptions.IgnoreCase);
|
var monthMatch = Regex.Match(text, @"(\d+)\s*(?:(?:か|ヶ|ケ)?月|mo(?:nths?)?)(?:\s*前|\s*ago)?", RegexOptions.IgnoreCase);
|
||||||
if (monthMatch.Success && int.TryParse(monthMatch.Groups[1].Value, out int months))
|
if (monthMatch.Success && int.TryParse(monthMatch.Groups[1].Value, out int months))
|
||||||
{
|
{
|
||||||
@@ -397,7 +383,7 @@ internal class missav123
|
|||||||
matched = true;
|
matched = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 週 (日本語: "1週間前", "1週前", 英語: "1w ago", "1 week ago")
|
// 週
|
||||||
var weekMatch = Regex.Match(text, @"(\d+)\s*(?:(?:週|週間)|w(?:eeks?)?)(?:\s*前|\s*ago)?", RegexOptions.IgnoreCase);
|
var weekMatch = Regex.Match(text, @"(\d+)\s*(?:(?:週|週間)|w(?:eeks?)?)(?:\s*前|\s*ago)?", RegexOptions.IgnoreCase);
|
||||||
if (weekMatch.Success && int.TryParse(weekMatch.Groups[1].Value, out int weeks))
|
if (weekMatch.Success && int.TryParse(weekMatch.Groups[1].Value, out int weeks))
|
||||||
{
|
{
|
||||||
@@ -405,7 +391,7 @@ internal class missav123
|
|||||||
matched = true;
|
matched = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 日 (日本語: "1日前", "1日 2時間前", 英語: "1d ago", "1 day ago")
|
// 日
|
||||||
var dayMatch = Regex.Match(text, @"(\d+)\s*(?:日|d(?:ays?)?)(?:\s*前|\s*ago)?", RegexOptions.IgnoreCase);
|
var dayMatch = Regex.Match(text, @"(\d+)\s*(?:日|d(?:ays?)?)(?:\s*前|\s*ago)?", RegexOptions.IgnoreCase);
|
||||||
if (dayMatch.Success && int.TryParse(dayMatch.Groups[1].Value, out int days))
|
if (dayMatch.Success && int.TryParse(dayMatch.Groups[1].Value, out int days))
|
||||||
{
|
{
|
||||||
@@ -413,7 +399,7 @@ internal class missav123
|
|||||||
matched = true;
|
matched = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 時間 (日本語: "1時間前", "1時間 30分前", 英語: "1h ago", "1 hour ago")
|
// 時間
|
||||||
var hourMatch = Regex.Match(text, @"(\d+)\s*(?:時間|h(?:ours?)?)(?:\s*前|\s*ago)?", RegexOptions.IgnoreCase);
|
var hourMatch = Regex.Match(text, @"(\d+)\s*(?:時間|h(?:ours?)?)(?:\s*前|\s*ago)?", RegexOptions.IgnoreCase);
|
||||||
if (hourMatch.Success && int.TryParse(hourMatch.Groups[1].Value, out int hours))
|
if (hourMatch.Success && int.TryParse(hourMatch.Groups[1].Value, out int hours))
|
||||||
{
|
{
|
||||||
@@ -421,7 +407,7 @@ internal class missav123
|
|||||||
matched = true;
|
matched = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 分 (日本語: "30分前", "30分 20秒前", 英語: "30m ago", "30 mins ago")
|
// 分
|
||||||
var minMatch = Regex.Match(text, @"(\d+)\s*(?:分|m(?:in(?:ute)?s?)?)(?:\s*前|\s*ago)?", RegexOptions.IgnoreCase);
|
var minMatch = Regex.Match(text, @"(\d+)\s*(?:分|m(?:in(?:ute)?s?)?)(?:\s*前|\s*ago)?", RegexOptions.IgnoreCase);
|
||||||
if (minMatch.Success && int.TryParse(minMatch.Groups[1].Value, out int mins))
|
if (minMatch.Success && int.TryParse(minMatch.Groups[1].Value, out int mins))
|
||||||
{
|
{
|
||||||
@@ -429,7 +415,7 @@ internal class missav123
|
|||||||
matched = true;
|
matched = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 秒 (日本語: "39秒前", 英語: "39s ago", "39 secs ago")
|
// 秒
|
||||||
var secMatch = Regex.Match(text, @"(\d+)\s*(?:秒|s(?:ec(?:ond)?s?)?)(?:\s*前|\s*ago)?", RegexOptions.IgnoreCase);
|
var secMatch = Regex.Match(text, @"(\d+)\s*(?:秒|s(?:ec(?:ond)?s?)?)(?:\s*前|\s*ago)?", RegexOptions.IgnoreCase);
|
||||||
if (secMatch.Success && int.TryParse(secMatch.Groups[1].Value, out int secs))
|
if (secMatch.Success && int.TryParse(secMatch.Groups[1].Value, out int secs))
|
||||||
{
|
{
|
||||||
@@ -450,4 +436,68 @@ internal class missav123
|
|||||||
|
|
||||||
return now;
|
return now;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region □メソッド(Private)
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 既存の XML ファイルから各記事のタイトル・本文 HTML・公開日時・更新日時を読み込みます。
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="fileName">XML ファイル名</param>
|
||||||
|
/// <returns>URL または GUID をキーとする既存エントリの辞書</returns>
|
||||||
|
private static Dictionary<string, ExistingFeedEntry> LoadExistingEntries(string fileName)
|
||||||
|
{
|
||||||
|
var existingEntries = new Dictionary<string, ExistingFeedEntry>(StringComparer.OrdinalIgnoreCase);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string xmlPath = CmnUtil.GetExportXmlPath(fileName);
|
||||||
|
if (!File.Exists(xmlPath))
|
||||||
|
{
|
||||||
|
return existingEntries;
|
||||||
|
}
|
||||||
|
|
||||||
|
using var reader = XmlReader.Create(xmlPath);
|
||||||
|
var existingFeed = SyndicationFeed.Load(reader);
|
||||||
|
if (existingFeed?.Items != null)
|
||||||
|
{
|
||||||
|
foreach (var item in existingFeed.Items)
|
||||||
|
{
|
||||||
|
var linkUrl = item.Links.FirstOrDefault()?.Uri?.AbsoluteUri;
|
||||||
|
var guid = item.Id;
|
||||||
|
|
||||||
|
var entry = new ExistingFeedEntry
|
||||||
|
{
|
||||||
|
Title = item.Title?.Text?.Trim() ?? string.Empty,
|
||||||
|
SummaryHtml = item.Summary?.Text?.Trim() ?? string.Empty,
|
||||||
|
PublishDate = item.PublishDate != DateTimeOffset.MinValue
|
||||||
|
? item.PublishDate
|
||||||
|
: (item.LastUpdatedTime != DateTimeOffset.MinValue ? item.LastUpdatedTime : DateTimeOffset.Now),
|
||||||
|
LastUpdatedTime = item.LastUpdatedTime != DateTimeOffset.MinValue
|
||||||
|
? item.LastUpdatedTime
|
||||||
|
: (item.PublishDate != DateTimeOffset.MinValue ? item.PublishDate : DateTimeOffset.Now),
|
||||||
|
Categories = item.Categories.Select(c => c.Name).ToList(),
|
||||||
|
Authors = item.Authors.Select(a => a.Name).ToList()
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(linkUrl) && !existingEntries.ContainsKey(linkUrl))
|
||||||
|
{
|
||||||
|
existingEntries[linkUrl] = entry;
|
||||||
|
}
|
||||||
|
if (!string.IsNullOrWhiteSpace(guid) && !existingEntries.ContainsKey(guid))
|
||||||
|
{
|
||||||
|
existingEntries[guid] = entry;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
LogManager.AddLog($"[情報] missav123 既存エントリ読み込みスキップ: {ex.Message}");
|
||||||
|
}
|
||||||
|
|
||||||
|
return existingEntries;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
using AngleSharp.Html.Parser;
|
using AngleSharp.Html.Parser;
|
||||||
using System.ServiceModel.Syndication;
|
using System.ServiceModel.Syndication;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
@@ -31,9 +31,11 @@ internal class momonga_fanzine
|
|||||||
// 簡潔なRSSに非同期で整形
|
// 簡潔なRSSに非同期で整形
|
||||||
var itemTasks = validItems.OrderByDescending(x => x.PublishDate).Select(async originalItem =>
|
var itemTasks = validItems.OrderByDescending(x => x.PublishDate).Select(async originalItem =>
|
||||||
{
|
{
|
||||||
List<SyndicationCategory> getAddCategory()
|
// 本文内のメタデータからカテゴリおよび著者(サークル・作者)を抽出
|
||||||
|
(List<SyndicationCategory> categories, List<string> authors) parseMetadata()
|
||||||
{
|
{
|
||||||
List<SyndicationCategory> result = new List<SyndicationCategory>();
|
var resultCategories = new List<SyndicationCategory>();
|
||||||
|
var resultAuthors = new List<string>();
|
||||||
|
|
||||||
string orgText = originalItem.Summary.Text;
|
string orgText = originalItem.Summary.Text;
|
||||||
var parser = new HtmlParser();
|
var parser = new HtmlParser();
|
||||||
@@ -50,14 +52,15 @@ internal class momonga_fanzine
|
|||||||
targetText = targetText.Substring(0, tagIndex);
|
targetText = targetText.Substring(0, tagIndex);
|
||||||
}
|
}
|
||||||
// ----------------------------------------------------
|
// ----------------------------------------------------
|
||||||
// 正規表現で各項目の値を抽出する
|
// 正規表現で各項目のラベルと値を抽出する
|
||||||
// ----------------------------------------------------
|
// ----------------------------------------------------
|
||||||
string pattern = @"【[^】]+】([^【]*)";
|
string pattern = @"【(?<key>[^】]+)】(?<val>[^【]*)";
|
||||||
var matches = Regex.Matches(targetText, pattern);
|
var matches = Regex.Matches(targetText, pattern);
|
||||||
|
|
||||||
foreach (Match match in matches)
|
foreach (Match match in matches)
|
||||||
{
|
{
|
||||||
string valuesStr = match.Groups[1].Value;
|
string key = match.Groups["key"].Value.Trim();
|
||||||
|
string valuesStr = match.Groups["val"].Value;
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(valuesStr))
|
if (string.IsNullOrWhiteSpace(valuesStr))
|
||||||
{
|
{
|
||||||
@@ -68,16 +71,27 @@ internal class momonga_fanzine
|
|||||||
|
|
||||||
foreach (var val in splitValues)
|
foreach (var val in splitValues)
|
||||||
{
|
{
|
||||||
string categoryName = val.Trim();
|
string cleanName = val.Trim();
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(categoryName))
|
if (!string.IsNullOrEmpty(cleanName))
|
||||||
{
|
{
|
||||||
result.Add(new SyndicationCategory(categoryName));
|
resultCategories.Add(new SyndicationCategory(cleanName));
|
||||||
|
|
||||||
|
// サークルまたは作者(アーティスト)の場合は著者一覧にも追加
|
||||||
|
if (key == "サークル" || key == "作者" ||
|
||||||
|
key.Equals("circle", StringComparison.OrdinalIgnoreCase) ||
|
||||||
|
key.Equals("artist", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
if (!resultAuthors.Contains(cleanName, StringComparer.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
resultAuthors.Add(cleanName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
}
|
||||||
|
}
|
||||||
|
return (resultCategories, resultAuthors);
|
||||||
}
|
}
|
||||||
|
|
||||||
var newItem = new SyndicationItem()
|
var newItem = new SyndicationItem()
|
||||||
@@ -93,8 +107,11 @@ internal class momonga_fanzine
|
|||||||
{
|
{
|
||||||
newItem.Links.Add(new SyndicationLink(link));
|
newItem.Links.Add(new SyndicationLink(link));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var (addCategories, addAuthors) = parseMetadata();
|
||||||
|
|
||||||
// カテゴリに本文内の作者などの情報を追加する
|
// カテゴリに本文内の作者などの情報を追加する
|
||||||
foreach (var category in getAddCategory())
|
foreach (var category in addCategories)
|
||||||
{
|
{
|
||||||
newItem.Categories.Add(category);
|
newItem.Categories.Add(category);
|
||||||
}
|
}
|
||||||
@@ -104,10 +121,22 @@ internal class momonga_fanzine
|
|||||||
category.Scheme = null;
|
category.Scheme = null;
|
||||||
newItem.Categories.Add(category);
|
newItem.Categories.Add(category);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 著者の設定:アーティストやサークルの値をすべて追加してFreshRSSで検索可能にする
|
||||||
|
if (addAuthors.Count > 0)
|
||||||
|
{
|
||||||
|
foreach (var authorName in addAuthors)
|
||||||
|
{
|
||||||
|
newItem.Authors.Add(new SyndicationPerson { Name = authorName });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
foreach (var author in originalItem.Authors)
|
foreach (var author in originalItem.Authors)
|
||||||
{
|
{
|
||||||
newItem.Authors.Add(author);
|
newItem.Authors.Add(author);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ID
|
// ID
|
||||||
newItem.Id = CmnUtil.CreateGuid($"{link}");
|
newItem.Id = CmnUtil.CreateGuid($"{link}");
|
||||||
@@ -165,11 +194,11 @@ internal class momonga_fanzine
|
|||||||
simplifiedItems
|
simplifiedItems
|
||||||
);
|
);
|
||||||
|
|
||||||
await CmnUtil.ExportXMLFileAsync("momonga-fanzine.xml", mergedFeed, client);
|
await CmnUtil.ExportXMLFileAsync("momonga-fanzine.xml", mergedFeed, client, addDir: "momon-ga.com");
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
LogManager.AddLog($"[エラー] momonga-fanzine:{ex.Message}");
|
LogManager.AddLog($"[エラー] 【Momonga】 fanzine: {ex.Message}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -184,5 +213,5 @@ internal class momonga_fanzine
|
|||||||
.Replace('/', '_') // '/' を '_' に置換
|
.Replace('/', '_') // '/' を '_' に置換
|
||||||
.TrimEnd('='); // 末尾のパディング '=' を削除
|
.TrimEnd('='); // 末尾のパディング '=' を削除
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
using AngleSharp.Html.Parser;
|
using AngleSharp.Html.Parser;
|
||||||
using System.ServiceModel.Syndication;
|
using System.ServiceModel.Syndication;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
@@ -31,9 +31,11 @@ internal class momonga_magazine
|
|||||||
// 簡潔なRSSに非同期で整形
|
// 簡潔なRSSに非同期で整形
|
||||||
var itemTasks = validItems.OrderByDescending(x => x.PublishDate).Select(async originalItem =>
|
var itemTasks = validItems.OrderByDescending(x => x.PublishDate).Select(async originalItem =>
|
||||||
{
|
{
|
||||||
List<SyndicationCategory> getAddCategory()
|
// 本文内のメタデータからカテゴリおよび著者(サークル・作者)を抽出
|
||||||
|
(List<SyndicationCategory> categories, List<string> authors) parseMetadata()
|
||||||
{
|
{
|
||||||
List<SyndicationCategory> result = new List<SyndicationCategory>();
|
var resultCategories = new List<SyndicationCategory>();
|
||||||
|
var resultAuthors = new List<string>();
|
||||||
|
|
||||||
string orgText = originalItem.Summary.Text;
|
string orgText = originalItem.Summary.Text;
|
||||||
var parser = new HtmlParser();
|
var parser = new HtmlParser();
|
||||||
@@ -50,14 +52,15 @@ internal class momonga_magazine
|
|||||||
targetText = targetText.Substring(0, tagIndex);
|
targetText = targetText.Substring(0, tagIndex);
|
||||||
}
|
}
|
||||||
// ----------------------------------------------------
|
// ----------------------------------------------------
|
||||||
// 正規表現で各項目の値を抽出する
|
// 正規表現で各項目のラベルと値を抽出する
|
||||||
// ----------------------------------------------------
|
// ----------------------------------------------------
|
||||||
string pattern = @"【[^】]+】([^【]*)";
|
string pattern = @"【(?<key>[^】]+)】(?<val>[^【]*)";
|
||||||
var matches = Regex.Matches(targetText, pattern);
|
var matches = Regex.Matches(targetText, pattern);
|
||||||
|
|
||||||
foreach (Match match in matches)
|
foreach (Match match in matches)
|
||||||
{
|
{
|
||||||
string valuesStr = match.Groups[1].Value;
|
string key = match.Groups["key"].Value.Trim();
|
||||||
|
string valuesStr = match.Groups["val"].Value;
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(valuesStr))
|
if (string.IsNullOrWhiteSpace(valuesStr))
|
||||||
{
|
{
|
||||||
@@ -68,16 +71,27 @@ internal class momonga_magazine
|
|||||||
|
|
||||||
foreach (var val in splitValues)
|
foreach (var val in splitValues)
|
||||||
{
|
{
|
||||||
string categoryName = val.Trim();
|
string cleanName = val.Trim();
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(categoryName))
|
if (!string.IsNullOrEmpty(cleanName))
|
||||||
{
|
{
|
||||||
result.Add(new SyndicationCategory(categoryName));
|
resultCategories.Add(new SyndicationCategory(cleanName));
|
||||||
|
|
||||||
|
// サークルまたは作者(アーティスト)の場合は著者一覧にも追加
|
||||||
|
if (key == "サークル" || key == "作者" ||
|
||||||
|
key.Equals("circle", StringComparison.OrdinalIgnoreCase) ||
|
||||||
|
key.Equals("artist", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
if (!resultAuthors.Contains(cleanName, StringComparer.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
resultAuthors.Add(cleanName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
}
|
||||||
|
}
|
||||||
|
return (resultCategories, resultAuthors);
|
||||||
}
|
}
|
||||||
|
|
||||||
var newItem = new SyndicationItem()
|
var newItem = new SyndicationItem()
|
||||||
@@ -93,8 +107,11 @@ internal class momonga_magazine
|
|||||||
{
|
{
|
||||||
newItem.Links.Add(new SyndicationLink(link));
|
newItem.Links.Add(new SyndicationLink(link));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var (addCategories, addAuthors) = parseMetadata();
|
||||||
|
|
||||||
// カテゴリに本文内の作者などの情報を追加する
|
// カテゴリに本文内の作者などの情報を追加する
|
||||||
foreach (var category in getAddCategory())
|
foreach (var category in addCategories)
|
||||||
{
|
{
|
||||||
newItem.Categories.Add(category);
|
newItem.Categories.Add(category);
|
||||||
}
|
}
|
||||||
@@ -104,10 +121,22 @@ internal class momonga_magazine
|
|||||||
category.Scheme = null;
|
category.Scheme = null;
|
||||||
newItem.Categories.Add(category);
|
newItem.Categories.Add(category);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 著者の設定:アーティストやサークルの値をすべて追加してFreshRSSで検索可能にする
|
||||||
|
if (addAuthors.Count > 0)
|
||||||
|
{
|
||||||
|
foreach (var authorName in addAuthors)
|
||||||
|
{
|
||||||
|
newItem.Authors.Add(new SyndicationPerson { Name = authorName });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
foreach (var author in originalItem.Authors)
|
foreach (var author in originalItem.Authors)
|
||||||
{
|
{
|
||||||
newItem.Authors.Add(author);
|
newItem.Authors.Add(author);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ID
|
// ID
|
||||||
newItem.Id = CmnUtil.CreateGuid($"{link}");
|
newItem.Id = CmnUtil.CreateGuid($"{link}");
|
||||||
@@ -165,11 +194,11 @@ internal class momonga_magazine
|
|||||||
simplifiedItems
|
simplifiedItems
|
||||||
);
|
);
|
||||||
|
|
||||||
await CmnUtil.ExportXMLFileAsync("momonga-magazine.xml", mergedFeed, client);
|
await CmnUtil.ExportXMLFileAsync("momonga-magazine.xml", mergedFeed, client, addDir: "momon-ga.com");
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
LogManager.AddLog($"[エラー] momonga-magazine:{ex.Message}");
|
LogManager.AddLog($"[エラー] 【Momonga】 magazine: {ex.Message}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -184,5 +213,5 @@ internal class momonga_magazine
|
|||||||
.Replace('/', '_') // '/' を '_' に置換
|
.Replace('/', '_') // '/' を '_' に置換
|
||||||
.TrimEnd('='); // 末尾のパディング '=' を削除
|
.TrimEnd('='); // 末尾のパディング '=' を削除
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -564,7 +564,7 @@ internal static class pixiv_common
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Pixiv は自前画像URLまたはプロキシ画像URLを出力するため、Base64への再変換は行わない
|
// Pixiv は自前画像URLまたはプロキシ画像URLを出力するため、Base64への再変換は行わない
|
||||||
await CmnUtil.ExportXMLFileAsync(fileName, feed, client, embedBase64: false);
|
await CmnUtil.ExportXMLFileAsync(fileName, feed, client, addDir: "pixiv.net", embedBase64: false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -584,7 +584,7 @@ internal static class pixiv_common
|
|||||||
items
|
items
|
||||||
);
|
);
|
||||||
|
|
||||||
CmnUtil.ExportXMLFile(fileName, feed);
|
CmnUtil.ExportXMLFile(fileName, feed, addDir: "pixiv.net");
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Pixiv API レスポンス用データモデル
|
#region Pixiv API レスポンス用データモデル
|
||||||
|
|||||||
File diff suppressed because it is too large.
Load diff
@@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
@@ -30,27 +30,27 @@ internal static class skebetter
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Skebetter の全フィード(漫画急上昇・イラスト急上昇)を順次生成します。
|
/// Skebetter の全フィード(漫画急上昇・イラスト急上昇)を順次生成します。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static async Task CreateRSSAsync(HttpClient client)
|
public static async Task CreateRSSAsync(HttpClient client, string? sessionId = null)
|
||||||
{
|
{
|
||||||
// 1. 急上昇(漫画・総合)の生成
|
// 1. 急上昇(漫画・総合)の生成
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await CreateMangaHotRssAsync(client);
|
await CreateMangaHotRssAsync(client, sessionId);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
LogManager.AddLog($"[エラー] [skebetter] 漫画急上昇 RSS 生成失敗: {ex.Message}");
|
LogManager.AddLog($"[エラー] 【skebetter】 漫画急上昇 RSS 生成失敗: {ex.Message}");
|
||||||
CmnUtil.PrintCallStackToEvent(ex);
|
CmnUtil.PrintCallStackToEvent(ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. イラスト急上昇の生成
|
// 2. イラスト急上昇の生成
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await CreateIllustHotRssAsync(client);
|
await CreateIllustHotRssAsync(client, sessionId);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
LogManager.AddLog($"[エラー] [skebetter] イラスト急上昇 RSS 生成失敗: {ex.Message}");
|
LogManager.AddLog($"[エラー] 【skebetter】 イラスト急上昇 RSS 生成失敗: {ex.Message}");
|
||||||
CmnUtil.PrintCallStackToEvent(ex);
|
CmnUtil.PrintCallStackToEvent(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -59,13 +59,13 @@ internal static class skebetter
|
|||||||
/// 急上昇(漫画・総合)の RSS フィード (skebetter.xml) を生成します。
|
/// 急上昇(漫画・総合)の RSS フィード (skebetter.xml) を生成します。
|
||||||
/// 複数ページつながっている漫画は同一記事内で全ページをつなげて出力します。
|
/// 複数ページつながっている漫画は同一記事内で全ページをつなげて出力します。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static async Task CreateMangaHotRssAsync(HttpClient client)
|
public static async Task CreateMangaHotRssAsync(HttpClient client, string? sessionId = null)
|
||||||
{
|
{
|
||||||
LogManager.AddLog("[情報] [skebetter] 漫画急上昇の取得を開始します");
|
LogManager.AddLog("[情報] 【skebetter】 漫画急上昇の取得を開始します");
|
||||||
var posts = await FetchPostsAsync(client, MangaApiUrl, MangaPageUrl, isIllust: false);
|
var posts = await FetchPostsAsync(client, MangaApiUrl, MangaPageUrl, isIllust: false, sessionId);
|
||||||
if (posts == null || posts.Count == 0)
|
if (posts == null || posts.Count == 0)
|
||||||
{
|
{
|
||||||
LogManager.AddLog("[警告] [skebetter] 漫画急上昇の投稿が取得できませんでした");
|
LogManager.AddLog("[警告] 【skebetter】 漫画急上昇の投稿が取得できませんでした");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,23 +75,23 @@ internal static class skebetter
|
|||||||
new Uri(MangaPageUrl)
|
new Uri(MangaPageUrl)
|
||||||
);
|
);
|
||||||
|
|
||||||
var items = await ConvertToSyndicationItemsAsync(client, posts, isIllust: false);
|
var items = await ConvertToSyndicationItemsAsync(client, posts, isIllust: false, sessionId);
|
||||||
feed.Items = items;
|
feed.Items = items;
|
||||||
|
|
||||||
// 急上昇フィードのため、過去の人気作品・連載が除外されないよう filter24Hours: false で出力
|
// 急上昇フィードのため、過去の人気作品・連載が除外されないよう filter24Hours: false で出力
|
||||||
await CmnUtil.ExportXMLFileAsync("skebetter.xml", feed, client, embedBase64: false, filter24Hours: false);
|
await CmnUtil.ExportXMLFileAsync("skebetter.xml", feed, client, addDir: "skebetter.com", embedBase64: false, filter24Hours: false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// イラスト急上昇の RSS フィード (skebetter_illust.xml) を生成します。
|
/// イラスト急上昇の RSS フィード (skebetter_illust.xml) を生成します。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static async Task CreateIllustHotRssAsync(HttpClient client)
|
public static async Task CreateIllustHotRssAsync(HttpClient client, string? sessionId = null)
|
||||||
{
|
{
|
||||||
LogManager.AddLog("[情報] [skebetter] イラスト急上昇の取得を開始します");
|
LogManager.AddLog("[情報] 【skebetter】 イラスト急上昇の取得を開始します");
|
||||||
var posts = await FetchPostsAsync(client, IllustApiUrl, IllustPageUrl, isIllust: true);
|
var posts = await FetchPostsAsync(client, IllustApiUrl, IllustPageUrl, isIllust: true, sessionId);
|
||||||
if (posts == null || posts.Count == 0)
|
if (posts == null || posts.Count == 0)
|
||||||
{
|
{
|
||||||
LogManager.AddLog("[警告] [skebetter] イラスト急上昇の投稿が取得できませんでした");
|
LogManager.AddLog("[警告] 【skebetter】 イラスト急上昇の投稿が取得できませんでした");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,11 +101,11 @@ internal static class skebetter
|
|||||||
new Uri(IllustPageUrl)
|
new Uri(IllustPageUrl)
|
||||||
);
|
);
|
||||||
|
|
||||||
var items = await ConvertToSyndicationItemsAsync(client, posts, isIllust: true);
|
var items = await ConvertToSyndicationItemsAsync(client, posts, isIllust: true, sessionId);
|
||||||
feed.Items = items;
|
feed.Items = items;
|
||||||
|
|
||||||
// 急上昇フィードのため、過去の人気作品が除外されないよう filter24Hours: false で出力
|
// 急上昇フィードのため、過去の人気作品が除外されないよう filter24Hours: false で出力
|
||||||
await CmnUtil.ExportXMLFileAsync("skebetter_illust.xml", feed, client, embedBase64: false, filter24Hours: false);
|
await CmnUtil.ExportXMLFileAsync("skebetter_illust.xml", feed, client, addDir: "skebetter.com", embedBase64: false, filter24Hours: false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -132,12 +132,12 @@ internal static class skebetter
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 投稿リストを常に FlareSolverr 経由で取得します(API または Web ページの __NEXT_DATA__)。
|
/// 投稿リストを常に FlareSolverr 経由で取得します(API または Web ページの __NEXT_DATA__)。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private static async Task<List<SkebetterPost>> FetchPostsAsync(HttpClient client, string apiUrl, string pageUrl, bool isIllust)
|
private static async Task<List<SkebetterPost>> FetchPostsAsync(HttpClient client, string apiUrl, string pageUrl, bool isIllust, string? sessionId = null)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
LogManager.AddLog($"[情報] [skebetter] 常に FlareSolverr 経由で API 取得を実行します: {apiUrl}");
|
LogManager.AddLog($"[情報] 【skebetter】 常に FlareSolverr 経由で API 取得を実行します: {apiUrl}");
|
||||||
var flareJson = await CmnUtil.GetStringFlareSolverr(client, apiUrl);
|
var flareJson = await CmnUtil.GetStringFlareSolverr(client, apiUrl, session: sessionId ?? CmnUtil.SharedFlareSolverrSessionId);
|
||||||
if (!string.IsNullOrEmpty(flareJson))
|
if (!string.IsNullOrEmpty(flareJson))
|
||||||
{
|
{
|
||||||
var apiResult = JsonSerializer.Deserialize<SkebetterApiResponse>(flareJson, JsonOptions);
|
var apiResult = JsonSerializer.Deserialize<SkebetterApiResponse>(flareJson, JsonOptions);
|
||||||
@@ -146,28 +146,28 @@ internal static class skebetter
|
|||||||
var list = CombinePosts(apiResult);
|
var list = CombinePosts(apiResult);
|
||||||
if (list.Count > 0)
|
if (list.Count > 0)
|
||||||
{
|
{
|
||||||
LogManager.AddLog($"[情報] [skebetter] FlareSolverr 経由で {list.Count} 件の投稿を取得しました");
|
LogManager.AddLog($"[情報] 【skebetter】 FlareSolverr 経由で {list.Count} 件の投稿を取得しました");
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 万が一 API の取得が空だった場合、Web ページを FlareSolverr で取得して __NEXT_DATA__ をパース
|
// 万が一 API の取得が空だった場合、Web ページを FlareSolverr で取得して __NEXT_DATA__ をパース
|
||||||
LogManager.AddLog($"[情報] [skebetter] FlareSolverr 経由で Web ページからの抽出を試みます: {pageUrl}");
|
LogManager.AddLog($"[情報] 【skebetter】 FlareSolverr 経由で Web ページからの抽出を試みます: {pageUrl}");
|
||||||
var flareHtml = await CmnUtil.GetStringFlareSolverr(client, pageUrl);
|
var flareHtml = await CmnUtil.GetStringFlareSolverr(client, pageUrl, session: sessionId ?? CmnUtil.SharedFlareSolverrSessionId);
|
||||||
if (!string.IsNullOrEmpty(flareHtml))
|
if (!string.IsNullOrEmpty(flareHtml))
|
||||||
{
|
{
|
||||||
var list = ExtractPostsFromNextData(flareHtml);
|
var list = ExtractPostsFromNextData(flareHtml);
|
||||||
if (list != null && list.Count > 0)
|
if (list != null && list.Count > 0)
|
||||||
{
|
{
|
||||||
LogManager.AddLog($"[情報] [skebetter] FlareSolverr 経由で Web ページから {list.Count} 件の投稿を抽出しました");
|
LogManager.AddLog($"[情報] 【skebetter】 FlareSolverr 経由で Web ページから {list.Count} 件の投稿を抽出しました");
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
LogManager.AddLog($"[エラー] [skebetter] FlareSolverr 取得例外: {ex.Message}");
|
LogManager.AddLog($"[エラー] 【skebetter】 FlareSolverr 取得例外: {ex.Message}");
|
||||||
}
|
}
|
||||||
|
|
||||||
return new List<SkebetterPost>();
|
return new List<SkebetterPost>();
|
||||||
@@ -246,12 +246,12 @@ internal static class skebetter
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// シリーズ作品の全ツイート・全ページ情報を常に FlareSolverr 経由で API から取得します。
|
/// シリーズ作品の全ツイート・全ページ情報を常に FlareSolverr 経由で API から取得します。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private static async Task<List<SkebetterPost>?> FetchSeriesTweetsAsync(HttpClient client, long seriesId)
|
private static async Task<List<SkebetterPost>?> FetchSeriesTweetsAsync(HttpClient client, long seriesId, string? sessionId = null)
|
||||||
{
|
{
|
||||||
string url = $"{SeriesDetailApiUrl}{seriesId}";
|
string url = $"{SeriesDetailApiUrl}{seriesId}";
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var flareJson = await CmnUtil.GetStringFlareSolverr(client, url);
|
var flareJson = await CmnUtil.GetStringFlareSolverr(client, url, session: sessionId ?? CmnUtil.SharedFlareSolverrSessionId);
|
||||||
if (!string.IsNullOrEmpty(flareJson))
|
if (!string.IsNullOrEmpty(flareJson))
|
||||||
{
|
{
|
||||||
var result = JsonSerializer.Deserialize<MangaSeriesDetailResponse>(flareJson, JsonOptions);
|
var result = JsonSerializer.Deserialize<MangaSeriesDetailResponse>(flareJson, JsonOptions);
|
||||||
@@ -264,7 +264,7 @@ internal static class skebetter
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
LogManager.AddLog($"[警告] [skebetter] シリーズ詳細 FlareSolverr 取得失敗 (series_id: {seriesId}): {ex.Message}");
|
LogManager.AddLog($"[警告] 【skebetter】 シリーズ詳細 FlareSolverr 取得失敗 (series_id: {seriesId}): {ex.Message}");
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@@ -273,14 +273,14 @@ internal static class skebetter
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 通常作品のリプライツリー情報を常に FlareSolverr 経由で API から取得します。
|
/// 通常作品のリプライツリー情報を常に FlareSolverr 経由で API から取得します。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private static async Task<List<SkebetterPost>?> FetchUserTweetDetailAsync(HttpClient client, string? userId, string? tweetId)
|
private static async Task<List<SkebetterPost>?> FetchUserTweetDetailAsync(HttpClient client, string? userId, string? tweetId, string? sessionId = null)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(userId) || string.IsNullOrEmpty(tweetId)) return null;
|
if (string.IsNullOrEmpty(userId) || string.IsNullOrEmpty(tweetId)) return null;
|
||||||
|
|
||||||
string url = $"{UserTweetDetailApiUrl}?user_id={userId}&tweet_uri={tweetId}&ssr=1";
|
string url = $"{UserTweetDetailApiUrl}?user_id={userId}&tweet_uri={tweetId}&ssr=1";
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var flareJson = await CmnUtil.GetStringFlareSolverr(client, url);
|
var flareJson = await CmnUtil.GetStringFlareSolverr(client, url, session: sessionId ?? CmnUtil.SharedFlareSolverrSessionId);
|
||||||
if (!string.IsNullOrEmpty(flareJson))
|
if (!string.IsNullOrEmpty(flareJson))
|
||||||
{
|
{
|
||||||
var result = JsonSerializer.Deserialize<UserTweetDetailResponse>(flareJson, JsonOptions);
|
var result = JsonSerializer.Deserialize<UserTweetDetailResponse>(flareJson, JsonOptions);
|
||||||
@@ -292,7 +292,7 @@ internal static class skebetter
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
LogManager.AddLog($"[警告] [skebetter] 個別詳細 FlareSolverr 取得失敗 (tweet: {tweetId}): {ex.Message}");
|
LogManager.AddLog($"[警告] 【skebetter】 個別詳細 FlareSolverr 取得失敗 (tweet: {tweetId}): {ex.Message}");
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@@ -312,7 +312,7 @@ internal static class skebetter
|
|||||||
/// Skebetter 投稿一覧を SyndicationItem のリストに変換します。
|
/// Skebetter 投稿一覧を SyndicationItem のリストに変換します。
|
||||||
/// 複数ページつながっている漫画は全ページをつなげて1つの記事にします。
|
/// 複数ページつながっている漫画は全ページをつなげて1つの記事にします。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private static async Task<List<SyndicationItem>> ConvertToSyndicationItemsAsync(HttpClient client, List<SkebetterPost> posts, bool isIllust)
|
private static async Task<List<SyndicationItem>> ConvertToSyndicationItemsAsync(HttpClient client, List<SkebetterPost> posts, bool isIllust, string? sessionId = null)
|
||||||
{
|
{
|
||||||
var items = new List<SyndicationItem>();
|
var items = new List<SyndicationItem>();
|
||||||
int index = 0;
|
int index = 0;
|
||||||
@@ -451,6 +451,16 @@ internal static class skebetter
|
|||||||
{
|
{
|
||||||
body.Append($" | <a href=\"https://x.com/{authorScreenName}\" target=\"_blank\" rel=\"noopener noreferrer\">@{authorScreenName}</a>");
|
body.Append($" | <a href=\"https://x.com/{authorScreenName}\" target=\"_blank\" rel=\"noopener noreferrer\">@{authorScreenName}</a>");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ポスト自体のリンク (x.com)
|
||||||
|
string? tweetIdStr = !string.IsNullOrEmpty(post.TweetUri) ? post.TweetUri : post.Id;
|
||||||
|
if (!string.IsNullOrEmpty(tweetIdStr))
|
||||||
|
{
|
||||||
|
string postUrl = !string.IsNullOrEmpty(authorScreenName)
|
||||||
|
? $"https://x.com/{authorScreenName}/status/{tweetIdStr}"
|
||||||
|
: $"https://x.com/i/web/status/{tweetIdStr}";
|
||||||
|
body.Append($" | <a href=\"{postUrl}\" target=\"_blank\" rel=\"noopener noreferrer\">ポストを開く</a>");
|
||||||
|
}
|
||||||
body.Append("</p>");
|
body.Append("</p>");
|
||||||
|
|
||||||
// 6. SyndicationItem の生成
|
// 6. SyndicationItem の生成
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
using AngleSharp.Dom;
|
using AngleSharp.Dom;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.ServiceModel.Syndication;
|
using System.ServiceModel.Syndication;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Xml;
|
||||||
using rss_generator.Class.Common;
|
using rss_generator.Class.Common;
|
||||||
|
|
||||||
namespace rss_generator.Class.SpankBang;
|
namespace rss_generator.Class.SpankBang;
|
||||||
@@ -14,11 +16,35 @@ namespace rss_generator.Class.SpankBang;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// SpankBang (https://spankbang.com/new_videos/) の最新動画を取得し、
|
/// SpankBang (https://spankbang.com/new_videos/) の最新動画を取得し、
|
||||||
/// WebImageViewer (https://udukipc-web.armonica-vps.work/) での再生リンクを含むRSSフィード (spankbang.xml) を生成します。
|
/// WebImageViewer (https://udukipc-web.armonica-vps.work/) での再生リンクを含むRSSフィード (spankbang.xml) を生成します。
|
||||||
|
/// 既存のフィードが存在する場合は同一動画の情報を引き継ぎ、再生数の変動等で FreshRSS の「更新された記事を未読とする」が反応しないようにします。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal static class spankbang
|
internal static class spankbang
|
||||||
{
|
{
|
||||||
|
#region □定数(Private)
|
||||||
|
|
||||||
private const string BaseUrl = "https://spankbang.com";
|
private const string BaseUrl = "https://spankbang.com";
|
||||||
private const string TargetUrl = "https://spankbang.com/new_videos/";
|
private const string TargetUrl = "https://spankbang.com/new_videos/";
|
||||||
|
private const string FileName = "spankbang.xml";
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region □クラス(Private)
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 既存の RSS フィードから読み込んだ記事情報を保持する内部クラスです。
|
||||||
|
/// </summary>
|
||||||
|
private sealed class ExistingFeedEntry
|
||||||
|
{
|
||||||
|
public string Title { get; set; } = string.Empty;
|
||||||
|
public string SummaryHtml { get; set; } = string.Empty;
|
||||||
|
public DateTimeOffset PublishDate { get; set; }
|
||||||
|
public DateTimeOffset LastUpdatedTime { get; set; }
|
||||||
|
public List<string> Categories { get; set; } = new();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region □メソッド(Public)
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// SpankBang の最新動画RSSを生成します。
|
/// SpankBang の最新動画RSSを生成します。
|
||||||
@@ -36,19 +62,15 @@ internal static class spankbang
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// 外部からセッションが渡されなかった場合は自前で作成
|
sessionId ??= CmnUtil.SharedFlareSolverrSessionId;
|
||||||
bool ownSession = sessionId == null;
|
|
||||||
if (ownSession)
|
// 既存フィードの読み込み(再生数変動による未読化防止および高速化)
|
||||||
{
|
var existingEntries = LoadExistingEntries(FileName);
|
||||||
sessionId = await CmnUtil.CreateFlareSolverrSession(client);
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var document = await CmnUtil.GetDocumentFlareSolverr(client, TargetUrl, session: sessionId);
|
var document = await CmnUtil.GetDocumentFlareSolverr(client, TargetUrl, session: sessionId);
|
||||||
if (document == null)
|
if (document == null)
|
||||||
{
|
{
|
||||||
LogManager.AddLog("[警告] [spankbang] ドキュメントの取得に失敗しました。");
|
LogManager.AddLog("[警告] 【spankbang】 ドキュメントの取得に失敗しました。");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,6 +99,42 @@ internal static class spankbang
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var guid = CmnUtil.CreateGuid(fullUrl);
|
||||||
|
var itemUri = new Uri(fullUrl);
|
||||||
|
|
||||||
|
existingEntries.TryGetValue(fullUrl, out var prevEntry);
|
||||||
|
if (prevEntry == null && !string.IsNullOrEmpty(guid))
|
||||||
|
{
|
||||||
|
existingEntries.TryGetValue(guid, out prevEntry);
|
||||||
|
}
|
||||||
|
|
||||||
|
SyndicationItem item;
|
||||||
|
if (prevEntry != null && !string.IsNullOrEmpty(prevEntry.SummaryHtml))
|
||||||
|
{
|
||||||
|
// 【未更新記事】
|
||||||
|
// 前回の本文HTMLおよび日時(PublishDate / LastUpdatedTime)を完全維持
|
||||||
|
// これにより再生数 views の増加による本文ハッシュ変化を防止し、FreshRSSの未読化を完全抑止
|
||||||
|
item = new SyndicationItem(
|
||||||
|
prevEntry.Title,
|
||||||
|
(string?)null,
|
||||||
|
itemUri,
|
||||||
|
guid,
|
||||||
|
prevEntry.LastUpdatedTime
|
||||||
|
)
|
||||||
|
{
|
||||||
|
PublishDate = prevEntry.PublishDate,
|
||||||
|
LastUpdatedTime = prevEntry.LastUpdatedTime,
|
||||||
|
Summary = new TextSyndicationContent(prevEntry.SummaryHtml, TextSyndicationContentKind.Html)
|
||||||
|
};
|
||||||
|
|
||||||
|
foreach (var cat in prevEntry.Categories)
|
||||||
|
{
|
||||||
|
item.Categories.Add(new SyndicationCategory(cat));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// 【新規記事】
|
||||||
// タイトルを取得
|
// タイトルを取得
|
||||||
var title = videoDiv.QuerySelector("p a[title]")?.GetAttribute("title")?.Trim()
|
var title = videoDiv.QuerySelector("p a[title]")?.GetAttribute("title")?.Trim()
|
||||||
?? videoDiv.QuerySelector("p a")?.TextContent?.Trim()
|
?? videoDiv.QuerySelector("p a")?.TextContent?.Trim()
|
||||||
@@ -105,7 +163,6 @@ internal static class spankbang
|
|||||||
var tag = videoDiv.QuerySelector("span[data-badge='tag'] ~ a[data-testid='title'], a[href^='/s/']")?.TextContent?.Trim();
|
var tag = videoDiv.QuerySelector("span[data-badge='tag'] ~ a[data-testid='title'], a[href^='/s/']")?.TextContent?.Trim();
|
||||||
var views = videoDiv.QuerySelector("span[data-testid='views']")?.TextContent?.Trim();
|
var views = videoDiv.QuerySelector("span[data-testid='views']")?.TextContent?.Trim();
|
||||||
|
|
||||||
var itemUri = new Uri(fullUrl);
|
|
||||||
var imageUri = !string.IsNullOrEmpty(imageSrc) ? new Uri(imageSrc) : null;
|
var imageUri = !string.IsNullOrEmpty(imageSrc) ? new Uri(imageSrc) : null;
|
||||||
var previewVideoUri = !string.IsNullOrEmpty(previewVideoSrc) ? new Uri(previewVideoSrc) : null;
|
var previewVideoUri = !string.IsNullOrEmpty(previewVideoSrc) ? new Uri(previewVideoSrc) : null;
|
||||||
|
|
||||||
@@ -136,7 +193,6 @@ internal static class spankbang
|
|||||||
}
|
}
|
||||||
else if (imageUri != null)
|
else if (imageUri != null)
|
||||||
{
|
{
|
||||||
// プレビュー動画がない場合はサムネイル画像を表示
|
|
||||||
body.Append($@"<div style=""margin-bottom: 10px;"">");
|
body.Append($@"<div style=""margin-bottom: 10px;"">");
|
||||||
body.Append($@"<a href=""{itemUri}"" target=""_blank"" rel=""noopener noreferrer"" referrerpolicy=""no-referrer"">");
|
body.Append($@"<a href=""{itemUri}"" target=""_blank"" rel=""noopener noreferrer"" referrerpolicy=""no-referrer"">");
|
||||||
body.Append($@"<img src=""{imageUri}"" referrerpolicy=""no-referrer"" alt=""{WebUtility.HtmlEncode(title)}"" style=""max-width: 100%; height: auto; border-radius: 6px;"">");
|
body.Append($@"<img src=""{imageUri}"" referrerpolicy=""no-referrer"" alt=""{WebUtility.HtmlEncode(title)}"" style=""max-width: 100%; height: auto; border-radius: 6px;"">");
|
||||||
@@ -191,20 +247,20 @@ internal static class spankbang
|
|||||||
// 下部リンク
|
// 下部リンク
|
||||||
body.Append($@"<p style=""margin-top: 10px;""><a href=""{viewerUrl}"" target=""_blank"" rel=""noopener noreferrer"" style=""font-weight: bold; color: #e11d48;"">▶ WebImageViewerで動画を再生する</a> | <a href=""{itemUri}"" target=""_blank"" rel=""noopener noreferrer"" referrerpolicy=""no-referrer"">SpankBang公式で視聴する</a></p>");
|
body.Append($@"<p style=""margin-top: 10px;""><a href=""{viewerUrl}"" target=""_blank"" rel=""noopener noreferrer"" style=""font-weight: bold; color: #e11d48;"">▶ WebImageViewerで動画を再生する</a> | <a href=""{itemUri}"" target=""_blank"" rel=""noopener noreferrer"" referrerpolicy=""no-referrer"">SpankBang公式で視聴する</a></p>");
|
||||||
|
|
||||||
// 取得できた場合はその日時、取得できなかった場合は新着順維持のためフォールバック日時
|
|
||||||
var itemPubDate = publishedDateOffset ?? new DateTimeOffset(DateTime.Now.AddSeconds(-itemIndex));
|
var itemPubDate = publishedDateOffset ?? new DateTimeOffset(DateTime.Now.AddSeconds(-itemIndex));
|
||||||
itemIndex++;
|
itemIndex++;
|
||||||
|
|
||||||
var item = new SyndicationItem(
|
item = new SyndicationItem(
|
||||||
title,
|
title,
|
||||||
string.Empty,
|
(string?)null,
|
||||||
itemUri,
|
itemUri,
|
||||||
CmnUtil.CreateGuid(fullUrl),
|
guid,
|
||||||
itemPubDate
|
itemPubDate
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
PublishDate = itemPubDate,
|
PublishDate = itemPubDate,
|
||||||
LastUpdatedTime = itemPubDate
|
LastUpdatedTime = itemPubDate,
|
||||||
|
Summary = new TextSyndicationContent(body.ToString(), TextSyndicationContentKind.Html)
|
||||||
};
|
};
|
||||||
|
|
||||||
// カテゴリ
|
// カテゴリ
|
||||||
@@ -216,26 +272,81 @@ internal static class spankbang
|
|||||||
{
|
{
|
||||||
item.Categories.Add(new SyndicationCategory(resolution));
|
item.Categories.Add(new SyndicationCategory(resolution));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
item.Summary = new TextSyndicationContent(body.ToString(), TextSyndicationContentKind.Html);
|
|
||||||
items.Add(item);
|
items.Add(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
feed.Items = items;
|
feed.Items = items;
|
||||||
await CmnUtil.ExportXMLFileAsync("spankbang.xml", feed, client);
|
await CmnUtil.ExportXMLFileAsync(FileName, feed, client, filter24Hours: false);
|
||||||
}
|
}
|
||||||
finally
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
if (ownSession && sessionId != null)
|
LogManager.AddLog($"[エラー] 【spankbang】 {ex.Message}");
|
||||||
|
CmnUtil.PrintCallStackToEvent(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region □メソッド(Private)
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 既存の XML ファイルから各記事のタイトル・本文 HTML・公開日時・更新日時を読み込みます。
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="fileName">XML ファイル名</param>
|
||||||
|
/// <returns>URL または GUID をキーとする既存エントリの辞書</returns>
|
||||||
|
private static Dictionary<string, ExistingFeedEntry> LoadExistingEntries(string fileName)
|
||||||
{
|
{
|
||||||
await CmnUtil.DestroyFlareSolverrSession(client, sessionId);
|
var existingEntries = new Dictionary<string, ExistingFeedEntry>(StringComparer.OrdinalIgnoreCase);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string xmlPath = CmnUtil.GetExportXmlPath(fileName);
|
||||||
|
if (!File.Exists(xmlPath))
|
||||||
|
{
|
||||||
|
return existingEntries;
|
||||||
|
}
|
||||||
|
|
||||||
|
using var reader = XmlReader.Create(xmlPath);
|
||||||
|
var existingFeed = SyndicationFeed.Load(reader);
|
||||||
|
if (existingFeed?.Items != null)
|
||||||
|
{
|
||||||
|
foreach (var item in existingFeed.Items)
|
||||||
|
{
|
||||||
|
var linkUrl = item.Links.FirstOrDefault()?.Uri?.AbsoluteUri;
|
||||||
|
var guid = item.Id;
|
||||||
|
|
||||||
|
var entry = new ExistingFeedEntry
|
||||||
|
{
|
||||||
|
Title = item.Title?.Text?.Trim() ?? string.Empty,
|
||||||
|
SummaryHtml = item.Summary?.Text?.Trim() ?? string.Empty,
|
||||||
|
PublishDate = item.PublishDate != DateTimeOffset.MinValue
|
||||||
|
? item.PublishDate
|
||||||
|
: (item.LastUpdatedTime != DateTimeOffset.MinValue ? item.LastUpdatedTime : DateTimeOffset.Now),
|
||||||
|
LastUpdatedTime = item.LastUpdatedTime != DateTimeOffset.MinValue
|
||||||
|
? item.LastUpdatedTime
|
||||||
|
: (item.PublishDate != DateTimeOffset.MinValue ? item.PublishDate : DateTimeOffset.Now),
|
||||||
|
Categories = item.Categories.Select(c => c.Name).ToList()
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(linkUrl) && !existingEntries.ContainsKey(linkUrl))
|
||||||
|
{
|
||||||
|
existingEntries[linkUrl] = entry;
|
||||||
|
}
|
||||||
|
if (!string.IsNullOrWhiteSpace(guid) && !existingEntries.ContainsKey(guid))
|
||||||
|
{
|
||||||
|
existingEntries[guid] = entry;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
LogManager.AddLog($"[エラー] spankbang: {ex.Message}");
|
LogManager.AddLog($"[情報] spankbang 既存エントリ読み込みスキップ: {ex.Message}");
|
||||||
CmnUtil.PrintCallStackToEvent(ex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return existingEntries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
+131
-17
@@ -1,13 +1,35 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
using System.ServiceModel.Syndication;
|
using System.ServiceModel.Syndication;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Xml.Linq;
|
||||||
using rss_generator.Class.Common;
|
using rss_generator.Class.Common;
|
||||||
|
|
||||||
namespace rss_generator.Class.X;
|
namespace rss_generator.Class.X;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// x.com (Twitter) のリストから RSS フィードを生成・統合するクラスです。
|
||||||
|
/// </summary>
|
||||||
internal class x_list
|
internal class x_list
|
||||||
{
|
{
|
||||||
|
#region □定数(Private)
|
||||||
|
|
||||||
private const string BASE_URL = "https://rsshub.armonica-vps.work/twitter/list";
|
private const string BASE_URL = "https://rsshub.armonica-vps.work/twitter/list";
|
||||||
private const string QUERY1 = "showEmojiForRetweetAndReply=1?filterout_title=%5E%28🔁%7CRT%29";
|
private const string QUERY1 = "showEmojiForRetweetAndReply=1?filterout_title=%5E%28🔁%7CRT%29";
|
||||||
private const string QUERY2 = "showEmojiForRetweetAndReply=1?filter_title=%5E%28🔁%7CRT%29";
|
private const string QUERY2 = "showEmojiForRetweetAndReply=1?filter_title=%5E%28🔁%7CRT%29";
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region □メソッド(Public)
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 各対象リストの RSS を順次生成します。
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="client">HTTP 通信用 HttpClient</param>
|
||||||
|
/// <returns>非同期タスク</returns>
|
||||||
public static async Task CreateRSSAsync(HttpClient client)
|
public static async Task CreateRSSAsync(HttpClient client)
|
||||||
{
|
{
|
||||||
// メモリ消費を最小化するため、各リストを1つずつ順次処理
|
// メモリ消費を最小化するため、各リストを1つずつ順次処理
|
||||||
@@ -31,17 +53,32 @@ internal class x_list
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
LogManager.AddLog($"[エラー] Xリスト生成失敗 ({fileName}): {ex.Message}");
|
LogManager.AddLog($"[エラー] 【x_list】 Xリスト生成失敗 ({fileName}): {ex.Message}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 単一リストの通常ツイートとRTツイートの RSS を生成します。
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="client">HttpClient</param>
|
||||||
|
/// <param name="listId">リストID</param>
|
||||||
|
/// <param name="fileName">出力ファイル名(プレフィックス)</param>
|
||||||
|
/// <returns>非同期タスク</returns>
|
||||||
public static async Task CreateSub1(HttpClient client, string listId, string fileName)
|
public static async Task CreateSub1(HttpClient client, string listId, string fileName)
|
||||||
{
|
{
|
||||||
await CreateSub2(client, listId, QUERY1, $"{fileName}");
|
await CreateSub2(client, listId, QUERY1, $"{fileName}");
|
||||||
await CreateSub2(client, listId, QUERY2, $"{fileName}RT");
|
await CreateSub2(client, listId, QUERY2, $"{fileName}RT");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 指定されたクエリ条件で RSS を取得・整形して出力します。
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="client">HttpClient</param>
|
||||||
|
/// <param name="listId">リストID</param>
|
||||||
|
/// <param name="query">クエリ文字列</param>
|
||||||
|
/// <param name="fileName">出力ファイル名</param>
|
||||||
|
/// <returns>非同期タスク</returns>
|
||||||
public static async Task CreateSub2(HttpClient client, string listId, string query, string fileName)
|
public static async Task CreateSub2(HttpClient client, string listId, string query, string fileName)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -52,37 +89,112 @@ internal class x_list
|
|||||||
// 簡潔なRSSに整形
|
// 簡潔なRSSに整形
|
||||||
var simplifiedItems = allItems.OrderByDescending(x => x.PublishDate).Select(originalItem =>
|
var simplifiedItems = allItems.OrderByDescending(x => x.PublishDate).Select(originalItem =>
|
||||||
{
|
{
|
||||||
var newItem = new SyndicationItem()
|
// リンクの取得
|
||||||
{
|
var link = originalItem.Links.FirstOrDefault()?.Uri;
|
||||||
// タイトルは TextSyndicationContent でラップする必要があります
|
|
||||||
Title = new TextSyndicationContent(originalItem.Title?.Text ?? "No Title")
|
|
||||||
, Id = CmnUtil.CreateGuid(originalItem.Id)
|
|
||||||
, PublishDate = originalItem.PublishDate
|
|
||||||
, LastUpdatedTime = originalItem.LastUpdatedTime
|
|
||||||
|
|
||||||
// 元のコンテンツをそのまま引き継ぐ
|
// 著者の取得 (originalItem.Authors または dc:creator から取得)
|
||||||
// Content = originalItem.Content,
|
string? authorName = originalItem.Authors.FirstOrDefault()?.Name;
|
||||||
, Summary = originalItem.Summary
|
if (string.IsNullOrWhiteSpace(authorName))
|
||||||
|
{
|
||||||
|
// ElementExtensions から dc:creator を取得
|
||||||
|
foreach (var ext in originalItem.ElementExtensions)
|
||||||
|
{
|
||||||
|
if (string.Equals(ext.OuterName, "creator", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
authorName = ext.GetObject<XElement>()?.Value?.Trim();
|
||||||
|
if (!string.IsNullOrEmpty(authorName))
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var reader = ext.GetReader();
|
||||||
|
authorName = reader.ReadElementContentAsString()?.Trim();
|
||||||
|
if (!string.IsNullOrEmpty(authorName))
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// リンクURLからスクリーン名を抽出(例: https://x.com/PeroVRC/status/... -> @PeroVRC)
|
||||||
|
string? screenName = null;
|
||||||
|
if (link != null)
|
||||||
|
{
|
||||||
|
var match = Regex.Match(link.AbsoluteUri, @"(?:x|twitter)\.com/([^/]+)/status/", RegexOptions.IgnoreCase);
|
||||||
|
if (match.Success)
|
||||||
|
{
|
||||||
|
screenName = match.Groups[1].Value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(authorName) && !string.IsNullOrWhiteSpace(screenName))
|
||||||
|
{
|
||||||
|
authorName = screenName;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 本文(Summary)にも著者情報を上部に付与して各種リーダーで確実に可視化
|
||||||
|
var rawSummary = originalItem.Summary?.Text ?? string.Empty;
|
||||||
|
string authorHeader = "";
|
||||||
|
if (!string.IsNullOrWhiteSpace(authorName))
|
||||||
|
{
|
||||||
|
string authorDisplay = !string.IsNullOrWhiteSpace(screenName) && !string.Equals(authorName, screenName, StringComparison.OrdinalIgnoreCase)
|
||||||
|
? $"{WebUtility.HtmlEncode(authorName)} (@{screenName})"
|
||||||
|
: WebUtility.HtmlEncode(authorName);
|
||||||
|
|
||||||
|
string authorUrl = !string.IsNullOrWhiteSpace(screenName)
|
||||||
|
? $"https://x.com/{screenName}"
|
||||||
|
: (link?.AbsoluteUri ?? "#");
|
||||||
|
|
||||||
|
authorHeader = $"<p style=\"font-size: 0.95em; color: #475569; margin-bottom: 8px;\"><strong>👤 投稿者:</strong> <a href=\"{authorUrl}\" target=\"_blank\" rel=\"noopener noreferrer\">{authorDisplay}</a></p>\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
var newItem = new SyndicationItem
|
||||||
|
{
|
||||||
|
Title = new TextSyndicationContent(originalItem.Title?.Text ?? "No Title"),
|
||||||
|
Id = CmnUtil.CreateGuid(originalItem.Id),
|
||||||
|
PublishDate = originalItem.PublishDate,
|
||||||
|
LastUpdatedTime = originalItem.LastUpdatedTime,
|
||||||
|
Summary = new TextSyndicationContent(authorHeader + rawSummary, TextSyndicationContentKind.Html)
|
||||||
};
|
};
|
||||||
|
|
||||||
// リンクを引き継ぐ
|
// リンクを引き継ぐ
|
||||||
var link = originalItem.Links.FirstOrDefault()?.Uri;
|
|
||||||
if (link != null)
|
if (link != null)
|
||||||
{
|
{
|
||||||
newItem.Links.Add(new SyndicationLink(link));
|
newItem.Links.Add(new SyndicationLink(link));
|
||||||
}
|
}
|
||||||
// 【追加】元のRSSが持っていたカテゴリ(タグ)をそのまま引き継ぐ
|
|
||||||
|
// 元のRSSが持っていたカテゴリ(タグ)をそのまま引き継ぐ
|
||||||
foreach (var category in originalItem.Categories)
|
foreach (var category in originalItem.Categories)
|
||||||
{
|
{
|
||||||
category.Scheme = null;
|
category.Scheme = null;
|
||||||
newItem.Categories.Add(category);
|
newItem.Categories.Add(category);
|
||||||
}
|
}
|
||||||
foreach (var author in originalItem.Authors)
|
|
||||||
|
// 著者の設定 (Atom用 Authors および RSS 2.0 Dublin Core用 dc:creator)
|
||||||
|
if (!string.IsNullOrWhiteSpace(authorName))
|
||||||
{
|
{
|
||||||
newItem.Authors.Add(author);
|
newItem.Authors.Add(new SyndicationPerson { Name = authorName });
|
||||||
|
newItem.ElementExtensions.Add(new XElement(
|
||||||
|
XName.Get("creator", "http://purl.org/dc/elements/1.1/"),
|
||||||
|
authorName
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
return newItem;
|
return newItem;
|
||||||
});
|
});
|
||||||
|
|
||||||
// 新しい統合フィードを作成
|
// 新しい統合フィードを作成
|
||||||
var mergedFeed = new SyndicationFeed(
|
var mergedFeed = new SyndicationFeed(
|
||||||
fileName,
|
fileName,
|
||||||
@@ -92,11 +204,13 @@ internal class x_list
|
|||||||
);
|
);
|
||||||
|
|
||||||
// X (Twitter) は画像リンクを Base64 変換せず、通常の画像リンクとして出力する
|
// X (Twitter) は画像リンクを Base64 変換せず、通常の画像リンクとして出力する
|
||||||
await CmnUtil.ExportXMLFileAsync($"{fileName}.xml", mergedFeed, client, embedBase64: false);
|
await CmnUtil.ExportXMLFileAsync($"{fileName}.xml", mergedFeed, client, addDir: "x.com", embedBase64: false);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
LogManager.AddLog($"[エラー] fileName:{ex.Message}");
|
LogManager.AddLog($"[エラー] 【x_list】 {fileName}: {ex.Message}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
@@ -1,41 +1,69 @@
|
|||||||
using AngleSharp.Dom;
|
using AngleSharp.Dom;
|
||||||
using PuppeteerSharp;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net.Http;
|
||||||
using System.ServiceModel.Syndication;
|
using System.ServiceModel.Syndication;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Xml;
|
||||||
using rss_generator.Class.Common;
|
using rss_generator.Class.Common;
|
||||||
|
|
||||||
namespace rss_generator.Class.YahooBaseball;
|
namespace rss_generator.Class.YahooBaseball;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 広島東洋カープ(スポーツナビ)のニュースタイムラインからRSSフィードを生成するクラス
|
||||||
|
/// </summary>
|
||||||
internal class npb_6
|
internal class npb_6
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 広島東洋カープの最新情報を取得し、npb_6.xml として出力します。
|
||||||
|
/// 既存フィードを読み込み、過去の公開日時および本文HTMLを維持することで、FreshRSSにおける不要な未読化を防ぎます。
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="client">HttpClient インスタンス</param>
|
||||||
|
/// <param name="sessionId">FlareSolverr セッションID(任意)</param>
|
||||||
public static async Task CreateRSSAsync(HttpClient client, string? sessionId = null)
|
public static async Task CreateRSSAsync(HttpClient client, string? sessionId = null)
|
||||||
{
|
{
|
||||||
var feed = new SyndicationFeed("広島東洋カープ - プロ野球 - スポーツナビ", "", new Uri("https://baseball.yahoo.co.jp/npb/teams/6/top"));
|
var feed = new SyndicationFeed("広島東洋カープ - プロ野球 - スポーツナビ", "広島東洋カープの最新ニュース・タイムライン", new Uri("https://baseball.yahoo.co.jp/npb/teams/6/top"));
|
||||||
var items = new List<SyndicationItem>();
|
var items = new List<SyndicationItem>();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var pageURL = $"https://baseball.yahoo.co.jp/npb/teams/6/top";
|
var pageURL = "https://baseball.yahoo.co.jp/npb/teams/6/top";
|
||||||
IDocument document;
|
sessionId ??= CmnUtil.SharedFlareSolverrSessionId;
|
||||||
bool ownSession = sessionId == null;
|
var document = await CmnUtil.GetDocumentFlareSolverr(client, pageURL, session: sessionId);
|
||||||
if (ownSession)
|
|
||||||
|
// 既存フィードを読み込み、過去の公開日時・更新日時・本文HTMLを引き継ぐ
|
||||||
|
var existingEntries = LoadExistingEntries("npb_6.xml");
|
||||||
|
var mergedDict = new Dictionary<string, SyndicationItem>(StringComparer.OrdinalIgnoreCase);
|
||||||
|
|
||||||
|
// 既存フィードの全アイテムを登録
|
||||||
|
foreach (var kvp in existingEntries)
|
||||||
{
|
{
|
||||||
sessionId = await CmnUtil.CreateFlareSolverrSession(client);
|
var entry = kvp.Value;
|
||||||
|
if (!mergedDict.ContainsKey(entry.Guid))
|
||||||
|
{
|
||||||
|
var synItem = new SyndicationItem(
|
||||||
|
entry.Title,
|
||||||
|
(string?)null,
|
||||||
|
!string.IsNullOrEmpty(entry.Link) ? new Uri(entry.Link) : null,
|
||||||
|
entry.Guid,
|
||||||
|
entry.PublishDate != DateTimeOffset.MinValue ? entry.PublishDate : entry.LastUpdatedTime
|
||||||
|
)
|
||||||
|
{
|
||||||
|
PublishDate = entry.PublishDate != DateTimeOffset.MinValue ? entry.PublishDate : entry.LastUpdatedTime,
|
||||||
|
LastUpdatedTime = entry.LastUpdatedTime != DateTimeOffset.MinValue ? entry.LastUpdatedTime : entry.PublishDate,
|
||||||
|
Summary = new TextSyndicationContent(entry.SummaryHtml, TextSyndicationContentKind.Html)
|
||||||
|
};
|
||||||
|
foreach (var author in entry.Authors)
|
||||||
|
{
|
||||||
|
synItem.Authors.Add(new SyndicationPerson { Name = author });
|
||||||
}
|
}
|
||||||
try
|
mergedDict[entry.Guid] = synItem;
|
||||||
{
|
|
||||||
document = await CmnUtil.GetDocumentFlareSolverr(client, pageURL, session: sessionId);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
if (ownSession && sessionId != null)
|
|
||||||
{
|
|
||||||
await CmnUtil.DestroyFlareSolverrSession(client, sessionId);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var linkList = new List<string>();
|
|
||||||
if (document != null)
|
if (document != null)
|
||||||
{
|
{
|
||||||
var elements = document.QuerySelectorAll("li.sn-timeLine__item");
|
var elements = document.QuerySelectorAll("li.sn-timeLine__item");
|
||||||
@@ -57,36 +85,121 @@ internal class npb_6
|
|||||||
|
|
||||||
var itemUri = !string.IsNullOrEmpty(linkHref) ? new Uri(linkHref) : null;
|
var itemUri = !string.IsNullOrEmpty(linkHref) ? new Uri(linkHref) : null;
|
||||||
var imageUri = !string.IsNullOrEmpty(imageSrc) ? new Uri(imageSrc) : null;
|
var imageUri = !string.IsNullOrEmpty(imageSrc) ? new Uri(imageSrc) : null;
|
||||||
|
string guid = CmnUtil.CreateGuid(linkHref);
|
||||||
|
|
||||||
var body = new StringBuilder();
|
var body = new StringBuilder();
|
||||||
body.Append($@"<div><a href=""{itemUri}"" target=""_blank"" rel=""noopener noreferrer"" referrerpolicy=""no-referrer"">{title}</a></div>");
|
body.Append($@"<div><a href=""{itemUri}"" target=""_blank"" rel=""noopener noreferrer"" referrerpolicy=""no-referrer"">{title}</a></div>");
|
||||||
body.Append($@"<div><img src=""{imageUri}"" referrerpolicy=""no-referrer"" alt=""{title}"" style=""max-width: 100%; height: auto;"" /></div>");
|
if (imageUri != null)
|
||||||
|
|
||||||
var updateTime = DateTime.Now;
|
|
||||||
if (DateTime.TryParse(elemTime?.TextContent?.Trim(), out DateTime itemTime))
|
|
||||||
{
|
{
|
||||||
updateTime = itemTime;
|
body.Append($@"<div><img src=""{imageUri}"" referrerpolicy=""no-referrer"" alt=""{title}"" style=""max-width: 100%; height: auto;"" /></div>");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 既存エントリが存在する場合は前回の公開日時・本文HTMLを最優先で維持
|
||||||
|
DateTimeOffset itemDate;
|
||||||
|
string summaryHtml = body.ToString();
|
||||||
|
|
||||||
|
if (existingEntries.TryGetValue(guid, out var existing))
|
||||||
|
{
|
||||||
|
itemDate = existing.PublishDate != DateTimeOffset.MinValue ? existing.PublishDate : existing.LastUpdatedTime;
|
||||||
|
if (!string.IsNullOrWhiteSpace(existing.SummaryHtml))
|
||||||
|
{
|
||||||
|
summaryHtml = existing.SummaryHtml;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (DateTime.TryParse(elemTime?.TextContent?.Trim(), out DateTime parsedTime))
|
||||||
|
{
|
||||||
|
itemDate = new DateTimeOffset(parsedTime);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
itemDate = DateTimeOffset.Now;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var item = new SyndicationItem(
|
var item = new SyndicationItem(
|
||||||
title,
|
title,
|
||||||
string.Empty,
|
(string?)null,
|
||||||
itemUri,
|
itemUri,
|
||||||
CmnUtil.CreateGuid(linkHref),
|
guid,
|
||||||
updateTime
|
itemDate
|
||||||
);
|
)
|
||||||
item.Authors.Add(new SyndicationPerson() { Name = elemCredit?.TextContent?.Trim() ?? "" });
|
{
|
||||||
item.Summary = new TextSyndicationContent(body.ToString(), TextSyndicationContentKind.Html);
|
PublishDate = itemDate,
|
||||||
|
LastUpdatedTime = itemDate,
|
||||||
|
Summary = new TextSyndicationContent(summaryHtml, TextSyndicationContentKind.Html)
|
||||||
|
};
|
||||||
|
|
||||||
items.Add(item);
|
var credit = elemCredit?.TextContent?.Trim();
|
||||||
|
if (!string.IsNullOrEmpty(credit))
|
||||||
|
{
|
||||||
|
item.Authors.Add(new SyndicationPerson { Name = credit });
|
||||||
|
}
|
||||||
|
|
||||||
|
mergedDict[guid] = item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
feed.Items = items;
|
|
||||||
|
|
||||||
await CmnUtil.ExportXMLFileAsync("npb_6.xml", feed, client);
|
// 重複除外とソート(新しい順)
|
||||||
|
var finalItems = mergedDict.Values
|
||||||
|
.OrderByDescending(x => x.PublishDate != DateTimeOffset.MinValue ? x.PublishDate : x.LastUpdatedTime)
|
||||||
|
.Take(100)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
feed.Items = finalItems;
|
||||||
|
|
||||||
|
await CmnUtil.ExportXMLFileAsync("npb_6.xml", feed, client, filter24Hours: false);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
LogManager.AddLog($"[エラー] npb_6:{ex.Message}");
|
LogManager.AddLog($"[エラー] 【npb_6】 {ex.Message}");
|
||||||
|
CmnUtil.PrintCallStackToEvent(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 既存の npb_6.xml を読み込み、GUIDおよびURLをキーとするキャッシュ辞書を返します。
|
||||||
|
/// </summary>
|
||||||
|
private static Dictionary<string, (string Guid, string Link, string Title, string SummaryHtml, DateTimeOffset PublishDate, DateTimeOffset LastUpdatedTime, List<string> Authors)> LoadExistingEntries(string fileName)
|
||||||
|
{
|
||||||
|
var dict = new Dictionary<string, (string Guid, string Link, string Title, string SummaryHtml, DateTimeOffset PublishDate, DateTimeOffset LastUpdatedTime, List<string> Authors)>(StringComparer.OrdinalIgnoreCase);
|
||||||
|
var filePath = CmnUtil.GetExportXmlPath(fileName);
|
||||||
|
if (!File.Exists(filePath)) return dict;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var reader = XmlReader.Create(filePath);
|
||||||
|
var feed = SyndicationFeed.Load(reader);
|
||||||
|
if (feed?.Items != null)
|
||||||
|
{
|
||||||
|
foreach (var item in feed.Items)
|
||||||
|
{
|
||||||
|
string guid = item.Id ?? string.Empty;
|
||||||
|
string link = item.Links.FirstOrDefault()?.Uri?.ToString() ?? string.Empty;
|
||||||
|
string title = item.Title?.Text ?? string.Empty;
|
||||||
|
string summary = item.Summary?.Text ?? string.Empty;
|
||||||
|
DateTimeOffset pubDate = item.PublishDate;
|
||||||
|
DateTimeOffset lastUpdated = item.LastUpdatedTime;
|
||||||
|
var authors = item.Authors.Select(a => a.Name).Where(n => !string.IsNullOrEmpty(n)).ToList();
|
||||||
|
|
||||||
|
var entry = (guid, link, title, summary, pubDate, lastUpdated, authors);
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(guid) && !dict.ContainsKey(guid))
|
||||||
|
{
|
||||||
|
dict[guid] = entry;
|
||||||
|
}
|
||||||
|
if (!string.IsNullOrEmpty(link) && !dict.ContainsKey(link))
|
||||||
|
{
|
||||||
|
dict[link] = entry;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
LogManager.AddLog($"[警告] 【npb_6】 既存フィード読み込み失敗 ({fileName}): {ex.Message}");
|
||||||
|
}
|
||||||
|
return dict;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
@@ -22,7 +22,7 @@ public static class YouTubeFeedManager
|
|||||||
/// <param name="client">HttpClient インスタンス</param>
|
/// <param name="client">HttpClient インスタンス</param>
|
||||||
public static async Task CreateRSSAsync(HttpClient client)
|
public static async Task CreateRSSAsync(HttpClient client)
|
||||||
{
|
{
|
||||||
LogManager.AddLog("[情報] YouTubeフィード生成を開始します");
|
LogManager.AddLog("[情報] 【YouTube】 YouTubeフィード生成を開始します");
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -45,7 +45,7 @@ public static class YouTubeFeedManager
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
LogManager.AddLog($"[エラー] チャンネル処理失敗 ({channel.Name ?? channel.IdOrHandle}): {ex.Message}");
|
LogManager.AddLog($"[エラー] 【YouTube】 チャンネル処理失敗 ({channel.Name ?? channel.IdOrHandle}): {ex.Message}");
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
@@ -82,15 +82,15 @@ public static class YouTubeFeedManager
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
LogManager.AddLog($"[エラー] カテゴリ出力失敗 ({category}): {ex.Message}");
|
LogManager.AddLog($"[エラー] 【YouTube】 カテゴリ出力失敗 ({category}): {ex.Message}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LogManager.AddLog("[情報] YouTubeフィード生成が完了しました");
|
LogManager.AddLog("[情報] 【YouTube】 YouTubeフィード生成が完了しました");
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
LogManager.AddLog($"[エラー] YouTubeFeedManager.CreateRSSAsync: {ex.Message}");
|
LogManager.AddLog($"[エラー] 【YouTube】 YouTubeFeedManager.CreateRSSAsync: {ex.Message}");
|
||||||
CmnUtil.PrintCallStackToEvent(ex);
|
CmnUtil.PrintCallStackToEvent(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -141,7 +141,7 @@ public static class YouTubeFeedManager
|
|||||||
int totalCount = liveItems.Count + videoItems.Count + shortsItems.Count;
|
int totalCount = liveItems.Count + videoItems.Count + shortsItems.Count;
|
||||||
if (totalCount == 0)
|
if (totalCount == 0)
|
||||||
{
|
{
|
||||||
LogManager.AddLog($"[警告] 取得アイテム0件 【{channelDisplayName}】 ({channel.IdOrHandle})");
|
LogManager.AddLog($"[警告] 【YouTube】 取得アイテム0件 【{channelDisplayName}】 ({channel.IdOrHandle})");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 統合フィード用に蓄積
|
// 統合フィード用に蓄積
|
||||||
@@ -152,7 +152,7 @@ public static class YouTubeFeedManager
|
|||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
// チャンネルごとのエラーを出力して処理を続行
|
// チャンネルごとのエラーを出力して処理を続行
|
||||||
LogManager.AddLog($"[エラー] チャンネル処理失敗 【{channelDisplayName}】 ({channel.IdOrHandle}): {ex.Message}");
|
LogManager.AddLog($"[エラー] 【YouTube】 チャンネル処理失敗 【{channelDisplayName}】 ({channel.IdOrHandle}): {ex.Message}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -176,7 +176,7 @@ public static class YouTubeFeedManager
|
|||||||
using var response = await client.SendAsync(request);
|
using var response = await client.SendAsync(request);
|
||||||
if (!response.IsSuccessStatusCode)
|
if (!response.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
LogManager.AddLog($"[警告] タブ取得HTTPエラー 【{channelDisplayName}】({feedType}) [{(int)response.StatusCode} {response.StatusCode}]: {url}");
|
LogManager.AddLog($"[警告] 【YouTube】 タブ取得HTTPエラー 【{channelDisplayName}】({feedType}) [{(int)response.StatusCode} {response.StatusCode}]: {url}");
|
||||||
return new List<YouTubeVideoItem>();
|
return new List<YouTubeVideoItem>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,7 +188,7 @@ public static class YouTubeFeedManager
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
LogManager.AddLog($"[エラー] タブ取得失敗 【{channelDisplayName}】({feedType}): {ex.Message}");
|
LogManager.AddLog($"[エラー] 【YouTube】 タブ取得失敗 【{channelDisplayName}】({feedType}): {ex.Message}");
|
||||||
return new List<YouTubeVideoItem>();
|
return new List<YouTubeVideoItem>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -342,30 +342,91 @@ public static class YouTubeFeedManager
|
|||||||
_ => "フィード"
|
_ => "フィード"
|
||||||
};
|
};
|
||||||
|
|
||||||
// 公開日時の新しい順にソートし、重複を除外
|
// 既存フィードを読み込み、過去の公開日時・本文HTML・タイトルを引き継げるようにする
|
||||||
var distinctItems = items
|
var existingDict = LoadExistingFeedItems(fileName, YouTubeConfig.OutputSubDir);
|
||||||
|
|
||||||
|
// 重複を除外
|
||||||
|
var distinctRawItems = items
|
||||||
.GroupBy(i => i.VideoId)
|
.GroupBy(i => i.VideoId)
|
||||||
.Select(g => g.First())
|
.Select(g => g.First())
|
||||||
.OrderByDescending(i => i.PublishedDate)
|
.ToList();
|
||||||
|
|
||||||
|
var syndicationItems = new List<SyndicationItem>();
|
||||||
|
foreach (var video in distinctRawItems)
|
||||||
|
{
|
||||||
|
string guid = CmnUtil.CreateGuid(video.Url);
|
||||||
|
existingDict.TryGetValue(guid, out var existingItem);
|
||||||
|
if (existingItem == null && !string.IsNullOrWhiteSpace(video.Url))
|
||||||
|
{
|
||||||
|
existingDict.TryGetValue(video.Url, out existingItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
var synItem = CreateSyndicationItem(video, existingItem, feedType);
|
||||||
|
syndicationItems.Add(synItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 公開日時の新しい順にソートし、最大件数に制限
|
||||||
|
var finalItems = syndicationItems
|
||||||
|
.OrderByDescending(i => i.PublishDate)
|
||||||
.Take(YouTubeConfig.MaxItemsPerFeed * 3)
|
.Take(YouTubeConfig.MaxItemsPerFeed * 3)
|
||||||
.Select(CreateSyndicationItem)
|
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
var feed = new SyndicationFeed(
|
var feed = new SyndicationFeed(
|
||||||
$"{feedTitle} ({typeLabel})",
|
$"{feedTitle} ({typeLabel})",
|
||||||
$"登録チャンネル全件の {typeLabel} 統合RSSフィード",
|
$"登録チャンネル全件の {typeLabel} 統合RSSフィード",
|
||||||
new Uri("https://www.youtube.com"),
|
new Uri("https://www.youtube.com"),
|
||||||
distinctItems
|
finalItems
|
||||||
);
|
);
|
||||||
|
|
||||||
// YouTube は画像リンクを Base64 変換せず、通常の画像リンクとして出力する
|
// YouTube は画像リンクを Base64 変換せず、通常の画像リンクとして出力する(filter24Hours: false で全件維持)
|
||||||
await CmnUtil.ExportXMLFileAsync(fileName, feed, client, YouTubeConfig.OutputSubDir, embedBase64: false);
|
await CmnUtil.ExportXMLFileAsync(fileName, feed, client, YouTubeConfig.OutputSubDir, embedBase64: false, filter24Hours: false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 既存のXMLファイルから SyndicationItem を読み込み、GUIDおよびURLをキーとする辞書を返します。
|
||||||
|
/// </summary>
|
||||||
|
private static Dictionary<string, SyndicationItem> LoadExistingFeedItems(string fileName, string subDir)
|
||||||
|
{
|
||||||
|
var dict = new Dictionary<string, SyndicationItem>(StringComparer.OrdinalIgnoreCase);
|
||||||
|
var filePath = CmnUtil.GetExportXmlPath(fileName, subDir);
|
||||||
|
if (!System.IO.File.Exists(filePath)) return dict;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var reader = System.Xml.XmlReader.Create(filePath);
|
||||||
|
var feed = SyndicationFeed.Load(reader);
|
||||||
|
if (feed?.Items != null)
|
||||||
|
{
|
||||||
|
foreach (var item in feed.Items)
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrWhiteSpace(item.Id) && !dict.ContainsKey(item.Id))
|
||||||
|
{
|
||||||
|
dict[item.Id] = item;
|
||||||
|
}
|
||||||
|
var link = item.Links.FirstOrDefault()?.Uri?.ToString();
|
||||||
|
if (!string.IsNullOrWhiteSpace(link) && !dict.ContainsKey(link))
|
||||||
|
{
|
||||||
|
dict[link] = item;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
LogManager.AddLog($"[警告] 【YouTube】 既存フィード読み込み失敗 ({fileName}): {ex.Message}");
|
||||||
|
}
|
||||||
|
return dict;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// YouTubeVideoItemからSyndicationItemを生成します。
|
/// YouTubeVideoItemからSyndicationItemを生成します。
|
||||||
|
/// 既存アイテムが存在する場合は、前回のPublishDateおよびSummaryHtmlを最優先で維持し、
|
||||||
|
/// 再生回数の増加や「○時間前」の更新によるFreshRSSの未読化を防ぎます。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private static SyndicationItem CreateSyndicationItem(YouTubeVideoItem video)
|
private static SyndicationItem CreateSyndicationItem(
|
||||||
|
YouTubeVideoItem video,
|
||||||
|
SyndicationItem? existingItem = null,
|
||||||
|
YouTubeFeedType feedType = YouTubeFeedType.Video)
|
||||||
{
|
{
|
||||||
// フィードタイトルの先頭にチャンネル・ユーザー名を付与(例: 【白上フブキ】 動画タイトル)
|
// フィードタイトルの先頭にチャンネル・ユーザー名を付与(例: 【白上フブキ】 動画タイトル)
|
||||||
string channelName = !string.IsNullOrWhiteSpace(video.ChannelTitle) ? video.ChannelTitle.Trim() : "";
|
string channelName = !string.IsNullOrWhiteSpace(video.ChannelTitle) ? video.ChannelTitle.Trim() : "";
|
||||||
@@ -379,12 +440,21 @@ public static class YouTubeFeedManager
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 既存アイテムが存在する場合、ライブ配信以外は前回の公開日時を完全に維持
|
||||||
|
var pubDate = (existingItem != null && existingItem.PublishDate != DateTimeOffset.MinValue && feedType != YouTubeFeedType.Live)
|
||||||
|
? existingItem.PublishDate
|
||||||
|
: video.PublishedDate;
|
||||||
|
|
||||||
|
var lastUpdate = (existingItem != null && existingItem.LastUpdatedTime != DateTimeOffset.MinValue && feedType != YouTubeFeedType.Live)
|
||||||
|
? existingItem.LastUpdatedTime
|
||||||
|
: pubDate;
|
||||||
|
|
||||||
var item = new SyndicationItem
|
var item = new SyndicationItem
|
||||||
{
|
{
|
||||||
Title = new TextSyndicationContent(displayTitle),
|
Title = new TextSyndicationContent(displayTitle),
|
||||||
Id = CmnUtil.CreateGuid(video.Url),
|
Id = CmnUtil.CreateGuid(video.Url),
|
||||||
PublishDate = video.PublishedDate,
|
PublishDate = pubDate,
|
||||||
LastUpdatedTime = video.PublishedDate
|
LastUpdatedTime = lastUpdate
|
||||||
};
|
};
|
||||||
|
|
||||||
item.Links.Add(new SyndicationLink(new Uri(video.Url)));
|
item.Links.Add(new SyndicationLink(new Uri(video.Url)));
|
||||||
@@ -396,7 +466,15 @@ public static class YouTubeFeedManager
|
|||||||
|
|
||||||
item.Categories.Add(new SyndicationCategory(video.FeedType.ToString()));
|
item.Categories.Add(new SyndicationCategory(video.FeedType.ToString()));
|
||||||
|
|
||||||
// HTML形式のSummaryを生成
|
// 既存エントリがあり、かつライブ配信でない場合は、前回のSummary(本文HTML)をそのまま引き継ぐ
|
||||||
|
// (再生回数や相対日時の変化による本文ハッシュ変動を100%防止)
|
||||||
|
if (existingItem?.Summary != null && !string.IsNullOrWhiteSpace(existingItem.Summary.Text) && feedType != YouTubeFeedType.Live)
|
||||||
|
{
|
||||||
|
item.Summary = new TextSyndicationContent(existingItem.Summary.Text, TextSyndicationContentKind.Html);
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 新規アイテムまたはライブ配信の場合の本文HTML生成
|
||||||
var body = new StringBuilder();
|
var body = new StringBuilder();
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(video.ThumbnailUrl))
|
if (!string.IsNullOrWhiteSpace(video.ThumbnailUrl))
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
@@ -97,7 +97,7 @@ public static class YouTubeParser
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
LogManager.AddLog($"[エラー] YouTubeParser.ParseTabContent: {ex.Message}");
|
LogManager.AddLog($"[エラー] 【YouTube】 YouTubeParser.ParseTabContent: {ex.Message}");
|
||||||
}
|
}
|
||||||
|
|
||||||
return items;
|
return items;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using AngleSharp.Html.Dom;
|
using AngleSharp.Html.Dom;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ServiceModel.Syndication;
|
using System.ServiceModel.Syndication;
|
||||||
@@ -57,8 +57,8 @@ internal class Youtube
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
AddLog($"[エラー] Youtube:{ex.Message}");
|
AddLog($"[エラー] 【YouTube】 {ex.Message}");
|
||||||
AddLog($"StackTrace\n{ex.StackTrace}");
|
AddLog($"[エラー] 【YouTube】 StackTrace\n{ex.StackTrace}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,7 +78,7 @@ internal class Youtube
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
AddLog($"[エラー] {url} の取得に失敗: {ex.Message}");
|
AddLog($"[エラー] 【YouTube】 {url} の取得に失敗: {ex.Message}");
|
||||||
return Enumerable.Empty<SyndicationItem>();
|
return Enumerable.Empty<SyndicationItem>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+91
-51
@@ -1,4 +1,5 @@
|
|||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using rss_generator.Class.AnigeSokuhou;
|
||||||
using rss_generator.Class.AuraHentai;
|
using rss_generator.Class.AuraHentai;
|
||||||
using rss_generator.Class.CiEn;
|
using rss_generator.Class.CiEn;
|
||||||
using rss_generator.Class.Common;
|
using rss_generator.Class.Common;
|
||||||
@@ -7,13 +8,16 @@ using rss_generator.Class.EHentai;
|
|||||||
using rss_generator.Class.Eroterest;
|
using rss_generator.Class.Eroterest;
|
||||||
using rss_generator.Class.HentaiPaw;
|
using rss_generator.Class.HentaiPaw;
|
||||||
using rss_generator.Class.HitomiLa;
|
using rss_generator.Class.HitomiLa;
|
||||||
|
using rss_generator.Class.JapaneseAvi;
|
||||||
using rss_generator.Class.Javtwi;
|
using rss_generator.Class.Javtwi;
|
||||||
|
using rss_generator.Class.Jpfiles;
|
||||||
using rss_generator.Class.KimochiInfo;
|
using rss_generator.Class.KimochiInfo;
|
||||||
using rss_generator.Class.Mangalear;
|
using rss_generator.Class.Mangalear;
|
||||||
using rss_generator.Class.MissAV;
|
using rss_generator.Class.MissAV;
|
||||||
using rss_generator.Class.MissAV123;
|
using rss_generator.Class.MissAV123;
|
||||||
using rss_generator.Class.Momonga;
|
using rss_generator.Class.Momonga;
|
||||||
using rss_generator.Class.Pixiv;
|
using rss_generator.Class.Pixiv;
|
||||||
|
using rss_generator.Class.Ryuugames;
|
||||||
using rss_generator.Class.Skebetter;
|
using rss_generator.Class.Skebetter;
|
||||||
using rss_generator.Class.SpankBang;
|
using rss_generator.Class.SpankBang;
|
||||||
using rss_generator.Class.X;
|
using rss_generator.Class.X;
|
||||||
@@ -21,7 +25,6 @@ using rss_generator.Class.YahooBaseball;
|
|||||||
using rss_generator.Class.YouTube;
|
using rss_generator.Class.YouTube;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
|
||||||
|
|
||||||
// 1. 同期スレッド等の未処理例外
|
// 1. 同期スレッド等の未処理例外
|
||||||
AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
|
AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
|
||||||
{
|
{
|
||||||
@@ -58,11 +61,11 @@ using var configWatcher = new ExternalConfigWatcher(httpClientFactory, execution
|
|||||||
configWatcher.RegisterHandler(YouTubeConfig.ConfigFileName, "YouTube", client => YouTubeFeedManager.CreateRSSAsync(client));
|
configWatcher.RegisterHandler(YouTubeConfig.ConfigFileName, "YouTube", client => YouTubeFeedManager.CreateRSSAsync(client));
|
||||||
configWatcher.Start();
|
configWatcher.Start();
|
||||||
|
|
||||||
LogManager.AddLog($"[情報] rss-generatorの起動");
|
LogManager.AddLog($"[情報] 【Program】 rss-generatorの起動");
|
||||||
var isFirst = true;
|
var isFirst = true;
|
||||||
|
|
||||||
// 生成完了後の待機時間(固定で5分)
|
// 生成完了後の待機時間(固定で30分)
|
||||||
TimeSpan waitInterval = TimeSpan.FromMinutes(5);
|
TimeSpan waitInterval = TimeSpan.FromMinutes(30);
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
@@ -75,9 +78,9 @@ while (true)
|
|||||||
#if DEBUG
|
#if DEBUG
|
||||||
#else
|
#else
|
||||||
var nextRunTime = DateTime.Now.Add(waitInterval);
|
var nextRunTime = DateTime.Now.Add(waitInterval);
|
||||||
LogManager.AddLog($"[情報] 次回実行予定: {nextRunTime:HH:mm:ss} (固定で5分待機)");
|
LogManager.AddLog($"[情報] 【Program】 次回実行予定: {nextRunTime:HH:mm:ss} (固定で30分待機)");
|
||||||
|
|
||||||
// 生成完了後、固定で5分待機(非同期スリープ)
|
// 生成完了後、固定で30分待機(非同期スリープ)
|
||||||
await Task.Delay(waitInterval);
|
await Task.Delay(waitInterval);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -87,89 +90,126 @@ while (true)
|
|||||||
// 指定時刻になったら処理を実行
|
// 指定時刻になったら処理を実行
|
||||||
Stopwatch totalSw = Stopwatch.StartNew();
|
Stopwatch totalSw = Stopwatch.StartNew();
|
||||||
Stopwatch sw = Stopwatch.StartNew();
|
Stopwatch sw = Stopwatch.StartNew();
|
||||||
LogManager.AddLog("[情報] 全フィードの取得処理を開始します");
|
LogManager.AddLog("[情報] 【Program】 全フィードの取得処理を開始します");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using var client = httpClientFactory.CreateClient("webClient");
|
// =====================================================================
|
||||||
client.DefaultRequestHeaders.UserAgent.Clear();
|
// 1. FlareSolverr を利用しない RSS 群(非同期で同時に取得処理を実行)
|
||||||
// ここでブラウザのUser-Agentを偽装(最新のChromeを偽装)
|
// =====================================================================
|
||||||
client.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36");
|
var nonFlareActions = new List<(string Name, Func<HttpClient, Task> Action)>();
|
||||||
// サイトによってはAcceptヘッダーがないと弾く場合もあるため、念のため追加
|
|
||||||
client.DefaultRequestHeaders.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
|
|
||||||
|
|
||||||
// メモリ消費を最小化(512MB制限内)するため、各フィードを並行ではなく順次実行し、タスクごとにGCを実行
|
|
||||||
var feedActions = new List<(string Name, Func<Task> Action)>();
|
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
feedActions.Add(("YouTube", () => YouTubeFeedManager.CreateRSSAsync(client)));
|
nonFlareActions.Add(("YouTube", client => YouTubeFeedManager.CreateRSSAsync(client)));
|
||||||
|
nonFlareActions.Add(("ryuugames", client => ryuugames.CreateRSSAsync(client)));
|
||||||
|
nonFlareActions.Add(("japaneseavi", client => japaneseavi.CreateRSSAsync(client)));
|
||||||
|
nonFlareActions.Add(("jpfiles", client => jpfiles.CreateRSSAsync(client)));
|
||||||
#else
|
#else
|
||||||
feedActions.Add(("movie.eroterest.net", () => MovieEroterestFeedManager.CreateAllRSSAsync(client)));
|
// ※ movie.eroterest.net は取得処理停止のため除外
|
||||||
feedActions.Add(("YouTube", () => YouTubeFeedManager.CreateRSSAsync(client)));
|
nonFlareActions.Add(("ryuugames", client => ryuugames.CreateRSSAsync(client)));
|
||||||
feedActions.Add(("X (Twitter)", () => x_list.CreateRSSAsync(client)));
|
nonFlareActions.Add(("YouTube", client => YouTubeFeedManager.CreateRSSAsync(client)));
|
||||||
feedActions.Add(("kimochiinfo", () => kimochiinfo.CreateRSSAsync(client)));
|
nonFlareActions.Add(("X (Twitter)", client => x_list.CreateRSSAsync(client)));
|
||||||
feedActions.Add(("ci_en", () => ci_en.CreateRSSAsync(client)));
|
nonFlareActions.Add(("kimochiinfo", client => kimochiinfo.CreateRSSAsync(client)));
|
||||||
feedActions.Add(("javtwi", () => javtwi.CreateRSSAsync(client)));
|
nonFlareActions.Add(("japaneseavi", client => japaneseavi.CreateRSSAsync(client)));
|
||||||
feedActions.Add(("mangalear", () => mangalear.CreateRSSAsync(client)));
|
nonFlareActions.Add(("jpfiles", client => jpfiles.CreateRSSAsync(client)));
|
||||||
feedActions.Add(("e_hentai_ai", () => e_hentai_ai.CreateRSSAsync(client)));
|
nonFlareActions.Add(("ci_en", client => ci_en.CreateRSSAsync(client)));
|
||||||
feedActions.Add(("e_hentai_non_ai", () => e_hentai_non_ai.CreateRSSAsync(client)));
|
nonFlareActions.Add(("javtwi", client => javtwi.CreateRSSAsync(client)));
|
||||||
feedActions.Add(("pixiv_non_r18_non_ai", () => pixiv_non_r18_non_ai.CreateRSSAsync(client)));
|
nonFlareActions.Add(("mangalear", client => mangalear.CreateRSSAsync(client)));
|
||||||
feedActions.Add(("pixiv_non_r18_ai", () => pixiv_non_r18_ai.CreateRSSAsync(client)));
|
nonFlareActions.Add(("e_hentai_ai", client => e_hentai_ai.CreateRSSAsync(client)));
|
||||||
feedActions.Add(("pixiv_r18_non_ai", () => pixiv_r18_non_ai.CreateRSSAsync(client)));
|
nonFlareActions.Add(("e_hentai_non_ai", client => e_hentai_non_ai.CreateRSSAsync(client)));
|
||||||
feedActions.Add(("pixiv_r18_ai", () => pixiv_r18_ai.CreateRSSAsync(client)));
|
nonFlareActions.Add(("pixiv_non_r18_non_ai", client => pixiv_non_r18_non_ai.CreateRSSAsync(client)));
|
||||||
feedActions.Add(("momonga_fanzine", () => momonga_fanzine.CreateRSSAsync(client)));
|
nonFlareActions.Add(("pixiv_non_r18_ai", client => pixiv_non_r18_ai.CreateRSSAsync(client)));
|
||||||
feedActions.Add(("momonga_magazine", () => momonga_magazine.CreateRSSAsync(client)));
|
nonFlareActions.Add(("pixiv_r18_non_ai", client => pixiv_r18_non_ai.CreateRSSAsync(client)));
|
||||||
feedActions.Add(("skebetter", () => skebetter.CreateRSSAsync(client)));
|
nonFlareActions.Add(("pixiv_r18_ai", client => pixiv_r18_ai.CreateRSSAsync(client)));
|
||||||
|
nonFlareActions.Add(("momonga_fanzine", client => momonga_fanzine.CreateRSSAsync(client)));
|
||||||
// FlareSolverr 利用タスク群(単一セッションで順次実行し、完了後に破棄してメモリ最小化)
|
nonFlareActions.Add(("momonga_magazine", client => momonga_magazine.CreateRSSAsync(client)));
|
||||||
feedActions.Add(("FlareSolverr", () => FlareSolverrFeedManager.CreateAllRSSAsync(client)));
|
nonFlareActions.Add(("anige_sokuhouvip", client => anige_sokuhouvip.CreateRSSAsync(client)));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
foreach (var (name, action) in feedActions)
|
LogManager.AddLog($"[情報] 【Program】 非FlareSolverrフィード ({nonFlareActions.Count} 件) の非同期同時取得を開始します");
|
||||||
|
var nonFlareSw = Stopwatch.StartNew();
|
||||||
|
|
||||||
|
var nonFlareTasks = nonFlareActions.Select(async item =>
|
||||||
{
|
{
|
||||||
|
// 各タスクに独立した HttpClient インスタンスを割り当てて競合・Cookie漏れを防止
|
||||||
|
using var taskClient = httpClientFactory.CreateClient("webClient");
|
||||||
|
taskClient.DefaultRequestHeaders.UserAgent.Clear();
|
||||||
|
taskClient.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36");
|
||||||
|
taskClient.DefaultRequestHeaders.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
|
||||||
|
|
||||||
|
var taskSw = Stopwatch.StartNew();
|
||||||
|
LogManager.AddLog($"[情報] 【{item.Name}】 取得開始");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var taskSw = Stopwatch.StartNew();
|
await item.Action(taskClient);
|
||||||
LogManager.AddLog($"[情報] 【{name}】 取得開始");
|
|
||||||
await action();
|
|
||||||
taskSw.Stop();
|
taskSw.Stop();
|
||||||
LogManager.AddLog($"[情報] 【{name}】 完了 ({taskSw.Elapsed.TotalSeconds:0.##}秒)");
|
LogManager.AddLog($"[情報] 【{item.Name}】 完了 ({taskSw.Elapsed.TotalSeconds:0.##}秒)");
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
LogManager.AddLog($"[エラー] 【{name}】 実行時エラー: {ex.Message}");
|
LogManager.AddLog($"[エラー] 【{item.Name}】 実行時エラー: {ex.Message}");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 非FlareSolverrフィードをすべて同時に実行し、完了を待機
|
||||||
|
await Task.WhenAll(nonFlareTasks);
|
||||||
|
nonFlareSw.Stop();
|
||||||
|
LogManager.AddLog($"[情報] 【Program】 非FlareSolverrフィードの取得がすべて完了しました ({nonFlareSw.Elapsed.TotalSeconds:0.##}秒)");
|
||||||
|
|
||||||
|
// メモリ積極回収
|
||||||
|
GC.Collect(2, GCCollectionMode.Aggressive, true, true);
|
||||||
|
GC.WaitForPendingFinalizers();
|
||||||
|
GC.Collect(2, GCCollectionMode.Aggressive, true, true);
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
#else
|
||||||
|
// =====================================================================
|
||||||
|
// 2. FlareSolverr を利用する RSS 群
|
||||||
|
// (非FlareSolverr完了後に実行。全体セッションを共有し単一Chromiumインスタンスで順次実行)
|
||||||
|
// =====================================================================
|
||||||
|
LogManager.AddLog("[情報] 【Program】 FlareSolverr 利用フィードの取得を開始します");
|
||||||
|
using var flareClient = httpClientFactory.CreateClient("webClient");
|
||||||
|
flareClient.DefaultRequestHeaders.UserAgent.Clear();
|
||||||
|
flareClient.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36");
|
||||||
|
flareClient.DefaultRequestHeaders.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await FlareSolverrFeedManager.CreateAllRSSAsync(flareClient);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
LogManager.AddLog($"[エラー] 【Program】 FlareSolverrタスク全体エラー: {ex.Message}");
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
// 各タスク完了後にメモリを積極回収してOSに返却
|
|
||||||
GC.Collect(2, GCCollectionMode.Aggressive, true, true);
|
GC.Collect(2, GCCollectionMode.Aggressive, true, true);
|
||||||
GC.WaitForPendingFinalizers();
|
GC.WaitForPendingFinalizers();
|
||||||
GC.Collect(2, GCCollectionMode.Aggressive, true, true);
|
GC.Collect(2, GCCollectionMode.Aggressive, true, true);
|
||||||
}
|
}
|
||||||
}
|
#endif
|
||||||
|
|
||||||
sw.Stop();
|
sw.Stop();
|
||||||
LogManager.AddLog($"[情報] RSS生成完了 実行時間:{sw.Elapsed.TotalSeconds:0.##}秒");
|
LogManager.AddLog($"[情報] 【Program】 RSS生成完了 実行時間:{sw.Elapsed.TotalSeconds:0.##}秒");
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
sw.Stop();
|
sw.Stop();
|
||||||
totalSw.Stop();
|
totalSw.Stop();
|
||||||
LogManager.AddLog($"[情報] 全処理完了 トータル実行時間:{totalSw.Elapsed.TotalSeconds:0.##}秒");
|
LogManager.AddLog($"[情報] 【Program】 全処理完了 トータル実行時間:{totalSw.Elapsed.TotalSeconds:0.##}秒");
|
||||||
LogManager.AddLog($"[情報] デバッグ完了");
|
LogManager.AddLog($"[情報] 【Program】 デバッグ完了");
|
||||||
|
|
||||||
await LogManager.FlushAndCloseAsync();
|
await LogManager.FlushAndCloseAsync();
|
||||||
break;
|
break;
|
||||||
#else
|
#else
|
||||||
sw.Stop();
|
sw.Stop();
|
||||||
totalSw.Stop();
|
totalSw.Stop();
|
||||||
LogManager.AddLog($"[情報] 全処理完了 トータル実行時間:{totalSw.Elapsed.TotalSeconds:0.##}秒");
|
LogManager.AddLog($"[情報] 【Program】 全処理完了 トータル実行時間:{totalSw.Elapsed.TotalSeconds:0.##}秒");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
// 途中でエラーが起きてもプログラム全体がクラッシュして止まらないように保護
|
// 途中でエラーが起きてもプログラム全体がクラッシュして止まらないように保護
|
||||||
LogManager.AddLog($"[エラー] main:{ex.Message}");
|
LogManager.AddLog($"[エラー] 【Program】 main:{ex.Message}");
|
||||||
LogManager.AddLog($"{ex.StackTrace}");
|
LogManager.AddLog($"{ex.StackTrace}");
|
||||||
//await LogManager.FlushAndCloseAsync();
|
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in new issue
Block a user