From 62738928fdc8531d43305907ed9fd545f273bc2d Mon Sep 17 00:00:00 2001 From: uduki Date: Wed, 11 Nov 2026 13:50:32 +0900 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0:=20=E5=80=8B=E5=88=A5?= =?UTF-8?q?=E3=83=95=E3=82=A3=E3=83=BC=E3=83=89=E3=81=AE=E8=A8=80=E8=AA=9E?= =?UTF-8?q?=E3=82=BF=E3=82=B0=E9=99=A4=E5=A4=96=E3=80=81=E8=A3=BD=E5=93=81?= =?UTF-8?q?ID(RJ=E7=AD=89)=E9=99=A4=E5=A4=96=E3=81=A8=E3=83=90=E3=83=BC?= =?UTF-8?q?=E3=82=B8=E3=83=A7=E3=83=B3=E4=BF=9D=E6=8C=81=E3=80=81=E6=9C=AC?= =?UTF-8?q?=E6=96=87=E7=9B=B4=E4=B8=8B=E3=81=B8=E3=81=AE=E3=83=95=E3=82=A9?= =?UTF-8?q?=E3=83=AB=E3=83=80=E5=90=8D=E7=94=A8=E3=82=BF=E3=82=A4=E3=83=88?= =?UTF-8?q?=E3=83=AB=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rss-generator/Class/Ryuugames/ryuugames.cs | 329 ++++++++++++++------- 1 file changed, 224 insertions(+), 105 deletions(-) diff --git a/rss-generator/Class/Ryuugames/ryuugames.cs b/rss-generator/Class/Ryuugames/ryuugames.cs index cdd948b..957c123 100644 --- a/rss-generator/Class/Ryuugames/ryuugames.cs +++ b/rss-generator/Class/Ryuugames/ryuugames.cs @@ -255,35 +255,54 @@ internal class ryuugames existingEntries.TryGetValue(guid, out prevEntry); } - SyndicationItem item; LanguageType langType; - // 最新フォーマット(ダウンロードセクション、英語タイトル、および日本語タイトル表示 v4)が含まれているキャッシュのみ再利用 + // 最新フォーマット(ダウンロードセクション、英語タイトル、およびフォルダ名タイトル表示 v5)が含まれているキャッシュのみ再利用 bool isLatestFormat = prevEntry != null && prevEntry.SummaryHtml.Contains("ryuu-dl-section") && - prevEntry.SummaryHtml.Contains("ryuu-eng-title") && - prevEntry.SummaryHtml.Contains("ryuu-jp-title-v4"); + prevEntry.SummaryHtml.Contains("ryuu-format-v5"); if (prevEntry != null && !string.IsNullOrEmpty(prevEntry.SummaryHtml) && isLatestFormat) { // 【キャッシュヒット(未更新記事)】 langType = prevEntry.Language; - item = new SyndicationItem( - prevEntry.Title, - (string?)null, - new Uri(link), - guid, - prevEntry.LastUpdatedTime - ) - { - PublishDate = prevEntry.PublishDate, - LastUpdatedTime = prevEntry.LastUpdatedTime, - Summary = new TextSyndicationContent(prevEntry.SummaryHtml, TextSyndicationContentKind.Html) - }; - // カテゴリの追加 - string langTag = langType == LanguageType.Japanese ? "日本語" : (langType == LanguageType.MachineTranslated ? "MTL翻訳" : "海外向け翻訳"); - item.Categories.Add(new SyndicationCategory(langTag)); + // 全件用アイテム(言語プレフィックス【】付き) + string titleAll = prevEntry.Title; + + // 個別フィード用タイトル(言語プレフィックス【】を除去したフォルダ名形式) + string titleSpecific = Regex.Replace(titleAll, @"^【[^】]+】\s*", "").Trim(); + + var itemAll = CreateSyndicationItem( + titleAll, + link, + guid, + prevEntry.PublishDate, + prevEntry.LastUpdatedTime, + prevEntry.SummaryHtml, + langType, + new List()); + + var itemSpecific = CreateSyndicationItem( + titleSpecific, + link, + guid, + prevEntry.PublishDate, + prevEntry.LastUpdatedTime, + prevEntry.SummaryHtml, + langType, + new List()); + + allItems.Add(itemAll); + + if (langType == LanguageType.Japanese) + { + jpItems.Add(itemSpecific); + } + else + { + transItems.Add(itemSpecific); + } } else { @@ -296,49 +315,50 @@ internal class ryuugames langType = articleInfo.Language; - // 整形タイトルを作成 - string formattedTitle = BuildFormattedTitle(articleInfo); + // フォルダ名用ベースタイトル([発売元]タイトル バージョン情報、製品ID除外、Windows禁止文字全角化) + string baseFolderTitle = BuildBaseFolderTitle(articleInfo); - // 整形本文 HTML を作成 - string summaryHtml = BuildSummaryHtml(articleInfo, link); + // 全件フィード用タイトル(【日本語】等の言語プレフィックス付き) + string formattedTitleWithLang = BuildFormattedTitle(articleInfo, includeLangPrefix: true); + + // 整形本文 HTML を作成(本文直下にフォルダ名用タイトルを表示) + string summaryHtml = BuildSummaryHtml(articleInfo, link, baseFolderTitle); var pubDate = articleInfo.PublishDate != DateTimeOffset.MinValue ? articleInfo.PublishDate : DateTimeOffset.Now; var modDate = articleInfo.LastUpdatedTime != DateTimeOffset.MinValue ? articleInfo.LastUpdatedTime : pubDate; - item = new SyndicationItem( - formattedTitle, - (string?)null, - new Uri(link), + // 全件用アイテム + var itemAll = CreateSyndicationItem( + formattedTitleWithLang, + link, guid, - modDate - ) - { - PublishDate = pubDate, - LastUpdatedTime = modDate, - Summary = new TextSyndicationContent(summaryHtml, TextSyndicationContentKind.Html) - }; + pubDate, + modDate, + summaryHtml, + langType, + articleInfo.Categories); - // カテゴリ設定 - string langTag = langType == LanguageType.Japanese ? "日本語" : (langType == LanguageType.MachineTranslated ? "MTL翻訳" : "海外向け翻訳"); - item.Categories.Add(new SyndicationCategory(langTag)); - foreach (var cat in articleInfo.Categories) + // 個別フィード用アイテム(言語プレフィックス【】なし) + var itemSpecific = CreateSyndicationItem( + baseFolderTitle, + link, + guid, + pubDate, + modDate, + summaryHtml, + langType, + articleInfo.Categories); + + allItems.Add(itemAll); + + if (langType == LanguageType.Japanese) { - if (!string.IsNullOrWhiteSpace(cat) && !item.Categories.Any(c => c.Name.Equals(cat, StringComparison.OrdinalIgnoreCase))) - { - item.Categories.Add(new SyndicationCategory(cat)); - } + jpItems.Add(itemSpecific); + } + else + { + transItems.Add(itemSpecific); } - } - - allItems.Add(item); - - if (langType == LanguageType.Japanese) - { - jpItems.Add(item); - } - else - { - transItems.Add(item); } } catch (Exception ex) @@ -734,14 +754,120 @@ internal class ryuugames } /// - /// RSSフィード用のタイトルを生成します。 - /// 原題(日本語タイトル)がある場合は日本語タイトルを最優先とし、 - /// [サークル・開発元]タイトル の形式で整形します。 + /// SyndicationItem を生成し、言語タグおよび指定カテゴリを設定します。 + /// + /// 記事タイトル + /// 記事URL + /// GUID + /// 公開日時 + /// 更新日時 + /// 本文HTML + /// 言語種別 + /// カテゴリリスト + /// 構築された SyndicationItem インスタンス + private static SyndicationItem CreateSyndicationItem( + string title, + string link, + string guid, + DateTimeOffset pubDate, + DateTimeOffset modDate, + string summaryHtml, + LanguageType langType, + List categories) + { + var item = new SyndicationItem( + title, + (string?)null, + new Uri(link), + guid, + modDate + ) + { + PublishDate = pubDate, + LastUpdatedTime = modDate, + Summary = new TextSyndicationContent(summaryHtml, TextSyndicationContentKind.Html) + }; + + // カテゴリの追加 + string langTag = langType == LanguageType.Japanese ? "日本語" : (langType == LanguageType.MachineTranslated ? "MTL翻訳" : "海外向け翻訳"); + item.Categories.Add(new SyndicationCategory(langTag)); + + if (categories != null) + { + foreach (var cat in categories) + { + if (!string.IsNullOrWhiteSpace(cat) && !item.Categories.Any(c => c.Name.Equals(cat, StringComparison.OrdinalIgnoreCase))) + { + item.Categories.Add(new SyndicationCategory(cat)); + } + } + } + + return item; + } + + /// + /// [発売元]タイトル バージョン情報 の形式で、Windowsフォルダ名として安全なタイトル文字列を生成します。 + /// 製品ID(RJ番号等)は完全に除外されます。 /// /// 記事詳細情報 - /// 言語タグおよびサークル名付きの整形タイトル - private static string BuildFormattedTitle(GameArticleInfo info) + /// フォルダ名用の整形タイトル + private static string BuildBaseFolderTitle(GameArticleInfo info) { + // サークル・開発元プレフィックスの作成 + string developerPrefix = string.Empty; + if (!string.IsNullOrWhiteSpace(info.Developer)) + { + developerPrefix = $"[{info.Developer}] "; + } + + // メインタイトルの選定(原題・日本語タイトルが存在する場合はそれを最優先) + string mainTitle; + if (!string.IsNullOrWhiteSpace(info.OriginalTitle)) + { + mainTitle = RemoveProductIds(info.OriginalTitle); + + // 元記事タイトルからバージョン表記のみを抽出して付加 + string versionSuffix = ExtractVersionSuffixes(info.OriginalArticleTitle); + if (!string.IsNullOrWhiteSpace(versionSuffix) && !mainTitle.Contains(versionSuffix, StringComparison.OrdinalIgnoreCase)) + { + mainTitle = $"{mainTitle} {versionSuffix}".Trim(); + } + } + else + { + string rawMain = !string.IsNullOrWhiteSpace(info.OriginalArticleTitle) ? info.OriginalArticleTitle : info.GameTitle; + mainTitle = RemoveProductIds(rawMain); + } + + // タイトル本体の先頭にすでにサークル名が含まれている場合は二重付加を回避 + if (!string.IsNullOrWhiteSpace(developerPrefix) && mainTitle.StartsWith(developerPrefix.Trim(), StringComparison.OrdinalIgnoreCase)) + { + developerPrefix = string.Empty; + } + + string rawTitle = $"{developerPrefix}{mainTitle}".Trim(); + + // Windowsのフォルダ名・ファイル名に使用できない禁止文字を全角へサニタイズ + return SanitizeWindowsFileName(rawTitle); + } + + /// + /// RSSフィード用のタイトルを生成します。 + /// 指定に応じて言語プレフィックス【】を付加します。 + /// + /// 記事詳細情報 + /// 言語プレフィックス【日本語】等を含めるかどうか + /// 言語タグ付きまたはフォルダ名形式の整形タイトル + private static string BuildFormattedTitle(GameArticleInfo info, bool includeLangPrefix = true) + { + string baseFolderTitle = BuildBaseFolderTitle(info); + + if (!includeLangPrefix) + { + return baseFolderTitle; + } + string langPrefix; switch (info.Language) { @@ -757,41 +883,28 @@ internal class ryuugames break; } - // サークル・開発元プレフィックスの作成 - string developerPrefix = string.Empty; - if (!string.IsNullOrWhiteSpace(info.Developer)) + return $"{langPrefix} {baseFolderTitle}".Trim(); + } + + /// + /// 文字列から DLsite や各種配信プラットフォームの製品ID((RJ01512929), [RJxxxxxx], (VJxxxxxx), (d_xxxxxx) 等)を除去します。 + /// + /// 対象文字列 + /// 製品IDが除去された文字列 + private static string RemoveProductIds(string text) + { + if (string.IsNullOrWhiteSpace(text)) { - developerPrefix = $"[{info.Developer}] "; + return string.Empty; } - // メインタイトルの選定(原題・日本語タイトルが存在する場合はそれを最優先) - string mainTitle; - if (!string.IsNullOrWhiteSpace(info.OriginalTitle)) - { - mainTitle = info.OriginalTitle; + // (RJ123456), [RJ123456], (VJ123456), (d_123456) などの製品IDパターンを除去 + string cleaned = Regex.Replace(text, @"\s*[\(\[]([rR][jJ]|[vV][jJ]|d_)\d+[\)\]]", "", RegexOptions.IgnoreCase); - // 元記事タイトルからバージョン表記やRJ番号などの識別サフィックスを抽出して付加 - string suffix = ExtractSuffixes(info.OriginalArticleTitle); - if (!string.IsNullOrWhiteSpace(suffix) && !mainTitle.Contains(suffix, StringComparison.OrdinalIgnoreCase)) - { - mainTitle = $"{mainTitle} {suffix}".Trim(); - } - } - else - { - mainTitle = !string.IsNullOrWhiteSpace(info.OriginalArticleTitle) ? info.OriginalArticleTitle : info.GameTitle; - } + // 末尾の -RJxxxxxx などのハイフン区切りパターンも除去 + cleaned = Regex.Replace(cleaned, @"\s*-[rR][jJ]\d+\b", "", RegexOptions.IgnoreCase); - // タイトル本体の先頭にすでにサークル名が含まれている場合は二重付加を回避 - if (!string.IsNullOrWhiteSpace(developerPrefix) && mainTitle.StartsWith(developerPrefix.Trim(), StringComparison.OrdinalIgnoreCase)) - { - developerPrefix = string.Empty; - } - - string rawTitle = $"{langPrefix} {developerPrefix}{mainTitle}".Trim(); - - // Windowsのフォルダ名・ファイル名に使用できない禁止文字を全角へサニタイズ - return SanitizeWindowsFileName(rawTitle); + return cleaned.Trim(); } /// @@ -821,21 +934,24 @@ internal class ryuugames } /// - /// 元記事タイトルから末尾に付加されているバージョン表記やRJ番号等の識別サフィックスを抽出します。 + /// 元記事タイトルから製品IDを除外し、純粋なバージョン表記((V1.03), (v2.0)等)やステータス((Final), Uncensored等)のみを安全に抽出します。 /// /// 元記事タイトル - /// 抽出されたサフィックス文字列(存在しない場合は空文字) - private static string ExtractSuffixes(string originalArticleTitle) + /// 抽出されたバージョンサフィックス文字列(存在しない場合は空文字) + private static string ExtractVersionSuffixes(string originalArticleTitle) { if (string.IsNullOrWhiteSpace(originalArticleTitle)) { return string.Empty; } - // 末尾の (V1.03), (RJ249958), [RJxxxxxx], (v2.0), (Final), (Completed), (Uncensored), Uncensored などの塊を安全に抽出 + // 製品IDを除去した文字列からバージョン情報を抽出 + string cleaned = RemoveProductIds(originalArticleTitle); + + // 末尾の (V1.03), [V1.02], (v2.0), (Final), (Completed), (Uncensored), Uncensored などの塊を安全に抽出 var match = Regex.Match( - originalArticleTitle, - @"(?:\s*(?:\([vV]?\d[^)]*\)|\[[vV]?\d[^\]]*\]|\([rR][jJ]\d+\)|\[[rR][jJ]\d+\]|\(Final\)|\(Completed\)|\(Uncensored\)|Uncensored))+$", + cleaned, + @"(?:\s*(?:\([vV]?\d[^)]*\)|\[[vV]?\d[^\]]*\]|\(Final\)|\(Completed\)|\(Uncensored\)|Uncensored))+$", RegexOptions.IgnoreCase); if (match.Success) @@ -848,12 +964,13 @@ internal class ryuugames /// /// RSSリーダー(FreshRSS等)で美しく視認性の高い本文 HTML を構築します。 - /// 本文先頭に日本語タイトルおよび英語タイトルを明記します。 + /// 本文直下にコピー用の「[発売元]タイトル バージョン情報」フォルダ名用タイトルを表示します。 /// /// 記事詳細情報 /// 記事URL + /// フォルダ名用タイトル /// 整形済み HTML 文字列 - private static string BuildSummaryHtml(GameArticleInfo info, string articleUrl) + private static string BuildSummaryHtml(GameArticleInfo info, string articleUrl, string folderTitle) { var sb = new StringBuilder(); @@ -878,24 +995,26 @@ internal class ryuugames } sb.Append(""); - // 1.4. 日本語タイトル (Japanese Title) の明記(本文先頭) + // 1.3. フォルダ名用タイトル (Folder Name) の明記(本文直下・テキストコピー用) + sb.Append("
"); + sb.Append("
📁 フォルダ名用タイトル (コピー用):
"); + sb.Append($"
{WebUtility.HtmlEncode(folderTitle)}
"); + sb.Append("
"); + + // 1.4. 日本語タイトル (Japanese Title) の明記 string jpTitle = !string.IsNullOrWhiteSpace(info.OriginalTitle) - ? info.OriginalTitle - : (info.Language == LanguageType.Japanese ? info.GameTitle : string.Empty); + ? RemoveProductIds(info.OriginalTitle) + : (info.Language == LanguageType.Japanese ? RemoveProductIds(info.GameTitle) : string.Empty); if (!string.IsNullOrWhiteSpace(jpTitle)) { - sb.Append("
"); + sb.Append("
"); sb.Append("日本語タイトル (Japanese Title): "); sb.Append($"{WebUtility.HtmlEncode(jpTitle)}"); sb.Append("
"); } - else - { - sb.Append(""); - } - // 1.5. 英語タイトル (English Title) の明記(本文先頭) + // 1.5. 英語タイトル (English Title) の明記 if (!string.IsNullOrWhiteSpace(info.OriginalArticleTitle)) { sb.Append("
");