Files
rss-generator/rss-generator/Class/Javtwi/javtwi.cs
T
armonica c788acaeca feat(momonga): フィード著者にアーティスト(作者)およびサークルの値を追加しFreshRSSでの個別検索に対応
- momonga_fanzine.cs, momonga_magazine.cs において本文メタデータから「サークル」「作者」を抽出し、著者の箇所(Authors)にそれぞれ追加
- 複数作者や複数サークルがある場合はカンマ区切りで個別登録し、重複を排除
- FreshRSS上でサークル名・アーティスト名のそれぞれで絞り込み検索が可能になるよう改善
- リファクタリングおよびログ出力プレフィックスの統一
2026-10-28 11:32:45 +09:00

127 lines
5.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using AngleSharp.Dom;
using AngleSharp.Html.Dom;
using System;
using System.Collections.Generic;
using System.ServiceModel.Syndication;
using System.Text;
using System.Text.RegularExpressions;
using rss_generator.Class.Common;
namespace rss_generator.Class.Javtwi;
internal class javtwi
{
public static async Task CreateRSSAsync(HttpClient client)
{
var baseURL = "https://javtwi.com/new.html";
var feed = new SyndicationFeed("javtwi", "", new Uri(baseURL));
var items = new List<SyndicationItem>();
try
{
var document = await CmnUtil.GetDocument(client, baseURL);
var linkList = new List<string>();
if (document == null)
{
return;
}
var elements = document.QuerySelectorAll("div.center_contents a.center_contents");
foreach (var linkElement in elements)
{
var imgElement = linkElement.QuerySelector("a img");
var linkHref = linkElement?.GetAttribute("href") ?? string.Empty;
var imageSrc = (imgElement as IHtmlImageElement)!.Source;
if (linkHref != string.Empty && !linkList.Contains(linkHref))
{
if (linkHref.Last() == '?')
{
linkHref = linkHref.TrimEnd('?');
}
// 重複行は追加しない
if (linkList.Contains(linkHref))
{
continue;
}
linkList.Add(linkHref);
}
else
{
continue;
}
var itemUri = !string.IsNullOrEmpty(linkHref) ? new Uri(linkHref) : null;
var imageUri = !string.IsNullOrEmpty(imageSrc) ? new Uri(imageSrc) : null;
if (itemUri == null)
{
continue;
}
if (itemUri.AbsolutePath.Contains("404."))
{
continue;
}
var title = CmnUtil.GetLastPathPart(linkHref);
// Twitter Snowflake ID から正確な投稿日時(JST)を逆算
DateTime publishedDate = DateTime.Now;
var match = Regex.Match(linkHref, @"/(\d{17,20})/");
if (!match.Success && !string.IsNullOrEmpty(imageSrc))
{
match = Regex.Match(imageSrc, @"/(\d{17,20})/");
}
if (match.Success && long.TryParse(match.Groups[1].Value, out long snowflakeId))
{
try
{
// Twitter Snowflake ID (エポック: 1288834974657 ms = 2010-11-04 01:42:54.657 UTC)
long unixMs = (snowflakeId >> 22) + 1288834974657L;
var offset = DateTimeOffset.FromUnixTimeMilliseconds(unixMs).ToOffset(TimeSpan.FromHours(9));
publishedDate = offset.DateTime;
}
catch
{
publishedDate = DateTime.Now;
}
}
var body = new StringBuilder();
body.Append($@"<div><a href=""{itemUri}"" target=""_blank"" rel=""noopener noreferrer"" referrerpolicy=""no-referrer"">{title}</a></div>");
body.Append($@"<video controls poster=""{imageUri}"" preload=""metadata"" referrerpolicy=""no-referrer"" style=""max-width: 100%; height: auto;"">");
body.Append($@"<source src=""{itemUri}"" type=""video/mp4"">");
body.Append($@"<p><a href=""{itemUri}"" target=""_blank"" rel=""noopener noreferrer"" referrerpolicy=""no-referrer"">動画を開く (.mp4)</a></p>");
body.Append($@"</video>");
var item = new SyndicationItem(
title,
string.Empty,
itemUri,
CmnUtil.CreateGuid(linkHref),
publishedDate
)
{
PublishDate = publishedDate,
LastUpdatedTime = publishedDate
};
// item.Content = SyndicationContent.CreateHtmlContent(body.ToString());
// ※ RSS 2.0の場合は Content よりも Summary(<description>タグ)が使われることが多いため、
// 両方に設定しておくか、Summary側にHTMLを設定すると大半のリーダーで確実です。
item.Summary = new TextSyndicationContent(body.ToString(), TextSyndicationContentKind.Html);
items.Add(item);
}
feed.Items = items;
await CmnUtil.ExportXMLFileAsync("javtwi.xml", feed, client);
}
catch (Exception ex)
{
LogManager.AddLog($"[エラー] 【javtwi】 {ex.Message}");
}
}
}