AIを分けるように
This commit is contained in:
1 parent
e07668dc12
commit
6509f3e241
7 files changed
+301
-70
No files matched your search
@@ -184,6 +184,119 @@ internal static class pixiv_common
|
||||
return resultList;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 指定された条件(AI / 非AI、R18 / 全年齢等)に合致する作品が最低 minCount 件集まるまで、
|
||||
/// ページを順次進めて取得します。
|
||||
/// </summary>
|
||||
/// <param name="client">HttpClient インスタンス</param>
|
||||
/// <param name="mode">"all" または "r18"</param>
|
||||
/// <param name="predicate">抽出条件(例: x => x.XRestrict == 0 && !x.IsAiGenerated)</param>
|
||||
/// <param name="minCount">最低取得件数(デフォルト: 30件)</param>
|
||||
/// <param name="maxPagesLimit">最大検索ページ数(安全上限: デフォルト20ページ)</param>
|
||||
/// <returns>条件を満たす PixivIllustItem リスト</returns>
|
||||
public static async Task<List<PixivIllustItem>> FetchIllustsUntilCountAsync(
|
||||
HttpClient client,
|
||||
string mode,
|
||||
Func<PixivIllustItem, bool> predicate,
|
||||
int minCount = 30,
|
||||
int maxPagesLimit = 20)
|
||||
{
|
||||
var matchedIllusts = new List<PixivIllustItem>();
|
||||
var seenIds = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
||||
var effectiveCookie = GetEffectiveCookie();
|
||||
|
||||
if (string.IsNullOrWhiteSpace(effectiveCookie))
|
||||
{
|
||||
AddLog($"[警告] [pixiv_common] Cookie (PHPSESSID) が設定されていません。環境変数 PIXIV_COOKIE または pixiv_common.Cookie を設定してください。");
|
||||
}
|
||||
|
||||
var options = new JsonSerializerOptions
|
||||
{
|
||||
PropertyNameCaseInsensitive = true,
|
||||
NumberHandling = JsonNumberHandling.AllowReadingFromString
|
||||
};
|
||||
options.Converters.Add(new FlexibleStringConverter());
|
||||
|
||||
for (int page = 1; page <= maxPagesLimit; page++)
|
||||
{
|
||||
try
|
||||
{
|
||||
var requestUrl = $"{BASE_API_URL}?p={page}&mode={mode}&lang=ja";
|
||||
using var request = new HttpRequestMessage(HttpMethod.Get, requestUrl);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(effectiveCookie))
|
||||
{
|
||||
request.Headers.Add("Cookie", effectiveCookie);
|
||||
}
|
||||
request.Headers.Add("User-Agent", UserAgent);
|
||||
request.Headers.Referrer = new Uri(REFERER_URL);
|
||||
request.Headers.Add("Accept", "application/json");
|
||||
|
||||
using var response = await client.SendAsync(request);
|
||||
var jsonString = await response.Content.ReadAsStringAsync();
|
||||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
AddLog($"[警告] [pixiv_common] APIリクエスト失敗 (URL={requestUrl}, Status={(int)response.StatusCode} {response.ReasonPhrase}, Body={jsonString})");
|
||||
break;
|
||||
}
|
||||
|
||||
var apiResponse = JsonSerializer.Deserialize<PixivFollowLatestResponse>(jsonString, options);
|
||||
if (apiResponse == null)
|
||||
{
|
||||
AddLog($"[警告] [pixiv_common] レスポンスのJSONパースに失敗しました (page={page}, mode={mode})");
|
||||
break;
|
||||
}
|
||||
|
||||
if (apiResponse.Error)
|
||||
{
|
||||
AddLog($"[エラー] [pixiv_common] Pixiv APIエラー: {apiResponse.Message} (page={page}, mode={mode})");
|
||||
break;
|
||||
}
|
||||
|
||||
var illustList = apiResponse.Body?.Thumbnails?.Illust;
|
||||
if (illustList == null || illustList.Count == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
foreach (var illust in illustList)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(illust.Id)) continue;
|
||||
if (!seenIds.Add(illust.Id)) continue;
|
||||
|
||||
if (predicate(illust))
|
||||
{
|
||||
matchedIllusts.Add(illust);
|
||||
}
|
||||
}
|
||||
|
||||
// 目標件数に達したら終了
|
||||
if (matchedIllusts.Count >= minCount)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
// 最終ページなら終了
|
||||
if (apiResponse.Body?.Page?.IsLastPage == true)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
// 連続アクセス防止の待機(500ms)
|
||||
await Task.Delay(500);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AddLog($"[エラー] [pixiv_common] フォロー新着巡回取得中に例外が発生しました (page={page}, mode={mode}): {ex.Message}");
|
||||
CmnUtil.PrintCallStackToEvent(ex);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return matchedIllusts;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Pixiv の作品アイテムリストを SyndicationItem のリストに変換します。
|
||||
/// </summary>
|
||||
@@ -443,6 +556,12 @@ internal static class pixiv_common
|
||||
/// </summary>
|
||||
[JsonPropertyName("aiType")]
|
||||
public int AiType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// AI生成作品かどうか(aiType == 2 またはタグにAI生成が含まれるか)
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public bool IsAiGenerated => AiType == 2 || (Tags != null && Tags.Any(t => t.Equals("AI生成", StringComparison.OrdinalIgnoreCase) || t.Equals("AI", StringComparison.OrdinalIgnoreCase) || t.Equals("NovelAI", StringComparison.OrdinalIgnoreCase)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using static rss_generator.Class.LogManager;
|
||||
|
||||
namespace rss_generator.Class.RSS.Pixiv;
|
||||
|
||||
/// <summary>
|
||||
/// Pixiv のフォロー中ユーザーの最新全年齢(非R-18)作品フィード (pixiv_non_r18.xml) を生成するクラス
|
||||
/// </summary>
|
||||
internal class pixiv_non_r18
|
||||
{
|
||||
private const string FEED_TITLE = "Pixiv (Follow General)";
|
||||
private const string FEED_DESCRIPTION = "Pixiv のフォロー中ユーザーによる最新全年齢作品フィード";
|
||||
private const string FEED_LINK = "https://www.pixiv.net/bookmark_new_illust.php";
|
||||
private const string XML_FILE_NAME = "pixiv_non_r18.xml";
|
||||
|
||||
/// <summary>
|
||||
/// Pixiv のフォロー新着から全年齢作品を取得し、pixiv_non_r18.xml を生成します。
|
||||
/// </summary>
|
||||
/// <param name="client">HttpClient インスタンス</param>
|
||||
public static async Task CreateRSSAsync(HttpClient client)
|
||||
{
|
||||
try
|
||||
{
|
||||
// mode="all" でフォロー新着作品を取得
|
||||
var illusts = await pixiv_common.FetchFollowLatestIllustsAsync(client, mode: "all", maxPages: pixiv_common.MaxPagesPerRun);
|
||||
|
||||
// 全年齢作品のみ (xRestrict == 0) を抽出
|
||||
var generalIllusts = illusts.Where(x => x.XRestrict == 0).ToList();
|
||||
|
||||
// SyndicationItem のリストに変換
|
||||
var items = pixiv_common.ConvertToSyndicationItems(generalIllusts);
|
||||
|
||||
// フィード作成と XML 出力
|
||||
pixiv_common.CreateAndExportFeed(
|
||||
FEED_TITLE,
|
||||
FEED_DESCRIPTION,
|
||||
FEED_LINK,
|
||||
XML_FILE_NAME,
|
||||
items
|
||||
);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AddLog($"[エラー] [pixiv_non_r18]: {ex.Message}");
|
||||
CmnUtil.PrintCallStackToEvent(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using static rss_generator.Class.LogManager;
|
||||
|
||||
namespace rss_generator.Class.RSS.Pixiv;
|
||||
|
||||
/// <summary>
|
||||
/// Pixiv のフォロー中ユーザーの最新全年齢・AI生成作品フィード (pixiv_non_r18_ai.xml) を生成するクラス
|
||||
/// </summary>
|
||||
internal class pixiv_non_r18_ai
|
||||
{
|
||||
private const string FEED_TITLE = "Pixiv (Follow General - AI)";
|
||||
private const string FEED_DESCRIPTION = "Pixiv のフォロー中ユーザーによる最新全年齢・AI生成作品フィード";
|
||||
private const string FEED_LINK = "https://www.pixiv.net/bookmark_new_illust.php";
|
||||
private const string XML_FILE_NAME = "pixiv_non_r18_ai.xml";
|
||||
|
||||
/// <summary>
|
||||
/// Pixiv のフォロー新着から全年齢・AI生成作品を最低30件取得し、pixiv_non_r18_ai.xml を生成します。
|
||||
/// </summary>
|
||||
/// <param name="client">HttpClient インスタンス</param>
|
||||
public static async Task CreateRSSAsync(HttpClient client)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 全年齢 (xRestrict == 0) かつAI生成作品 (IsAiGenerated) を最低30件集まるまで取得
|
||||
var illusts = await pixiv_common.FetchIllustsUntilCountAsync(
|
||||
client,
|
||||
mode: "all",
|
||||
predicate: x => x.XRestrict == 0 && x.IsAiGenerated,
|
||||
minCount: 30
|
||||
);
|
||||
|
||||
// SyndicationItem のリストに変換
|
||||
var items = pixiv_common.ConvertToSyndicationItems(illusts);
|
||||
|
||||
// フィード作成と XML 出力
|
||||
pixiv_common.CreateAndExportFeed(
|
||||
FEED_TITLE,
|
||||
FEED_DESCRIPTION,
|
||||
FEED_LINK,
|
||||
XML_FILE_NAME,
|
||||
items
|
||||
);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AddLog($"[エラー] [pixiv_non_r18_ai]: {ex.Message}");
|
||||
CmnUtil.PrintCallStackToEvent(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using static rss_generator.Class.LogManager;
|
||||
|
||||
namespace rss_generator.Class.RSS.Pixiv;
|
||||
|
||||
/// <summary>
|
||||
/// Pixiv のフォロー中ユーザーの最新全年齢・非AI作品フィード (pixiv_non_r18_non_ai.xml) を生成するクラス
|
||||
/// </summary>
|
||||
internal class pixiv_non_r18_non_ai
|
||||
{
|
||||
private const string FEED_TITLE = "Pixiv (Follow General - Non-AI)";
|
||||
private const string FEED_DESCRIPTION = "Pixiv のフォロー中ユーザーによる最新全年齢・非AI作品フィード";
|
||||
private const string FEED_LINK = "https://www.pixiv.net/bookmark_new_illust.php";
|
||||
private const string XML_FILE_NAME = "pixiv_non_r18_non_ai.xml";
|
||||
|
||||
/// <summary>
|
||||
/// Pixiv のフォロー新着から全年齢・非AI作品を最低30件取得し、pixiv_non_r18_non_ai.xml を生成します。
|
||||
/// </summary>
|
||||
/// <param name="client">HttpClient インスタンス</param>
|
||||
public static async Task CreateRSSAsync(HttpClient client)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 全年齢 (xRestrict == 0) かつ非AI作品 (!IsAiGenerated) を最低30件集まるまで取得
|
||||
var illusts = await pixiv_common.FetchIllustsUntilCountAsync(
|
||||
client,
|
||||
mode: "all",
|
||||
predicate: x => x.XRestrict == 0 && !x.IsAiGenerated,
|
||||
minCount: 30
|
||||
);
|
||||
|
||||
// SyndicationItem のリストに変換
|
||||
var items = pixiv_common.ConvertToSyndicationItems(illusts);
|
||||
|
||||
// フィード作成と XML 出力
|
||||
pixiv_common.CreateAndExportFeed(
|
||||
FEED_TITLE,
|
||||
FEED_DESCRIPTION,
|
||||
FEED_LINK,
|
||||
XML_FILE_NAME,
|
||||
items
|
||||
);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AddLog($"[エラー] [pixiv_non_r18_non_ai]: {ex.Message}");
|
||||
CmnUtil.PrintCallStackToEvent(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
+15
-14
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using static rss_generator.Class.LogManager;
|
||||
@@ -8,31 +7,33 @@ using static rss_generator.Class.LogManager;
|
||||
namespace rss_generator.Class.RSS.Pixiv;
|
||||
|
||||
/// <summary>
|
||||
/// Pixiv のフォロー中ユーザーの最新 R-18 作品フィード (pixiv_r18.xml) を生成するクラス
|
||||
/// Pixiv のフォロー中ユーザーの最新 R-18・AI生成作品フィード (pixiv_r18_ai.xml) を生成するクラス
|
||||
/// </summary>
|
||||
internal class pixiv_r18
|
||||
internal class pixiv_r18_ai
|
||||
{
|
||||
private const string FEED_TITLE = "Pixiv (Follow R-18)";
|
||||
private const string FEED_DESCRIPTION = "Pixiv のフォロー中ユーザーによる最新 R-18 作品フィード";
|
||||
private const string FEED_TITLE = "Pixiv (Follow R-18 - AI)";
|
||||
private const string FEED_DESCRIPTION = "Pixiv のフォロー中ユーザーによる最新 R-18・AI生成作品フィード";
|
||||
private const string FEED_LINK = "https://www.pixiv.net/bookmark_new_illust_r18.php";
|
||||
private const string XML_FILE_NAME = "pixiv_r18.xml";
|
||||
private const string XML_FILE_NAME = "pixiv_r18_ai.xml";
|
||||
|
||||
/// <summary>
|
||||
/// Pixiv のフォロー新着から R-18 作品を取得し、pixiv_r18.xml を生成します。
|
||||
/// Pixiv のフォロー新着から R-18・AI生成作品を最低30件取得し、pixiv_r18_ai.xml を生成します。
|
||||
/// </summary>
|
||||
/// <param name="client">HttpClient インスタンス</param>
|
||||
public static async Task CreateRSSAsync(HttpClient client)
|
||||
{
|
||||
try
|
||||
{
|
||||
// mode="r18" でフォロー新着作品を取得
|
||||
var illusts = await pixiv_common.FetchFollowLatestIllustsAsync(client, mode: "r18", maxPages: pixiv_common.MaxPagesPerRun);
|
||||
|
||||
// 安全のため R-18 以上の作品 (xRestrict >= 1) のみ抽出
|
||||
var r18Illusts = illusts.Where(x => x.XRestrict >= 1).ToList();
|
||||
// R-18 (xRestrict >= 1) かつAI生成作品 (IsAiGenerated) を最低30件集まるまで取得
|
||||
var illusts = await pixiv_common.FetchIllustsUntilCountAsync(
|
||||
client,
|
||||
mode: "r18",
|
||||
predicate: x => x.XRestrict >= 1 && x.IsAiGenerated,
|
||||
minCount: 30
|
||||
);
|
||||
|
||||
// SyndicationItem のリストに変換
|
||||
var items = pixiv_common.ConvertToSyndicationItems(r18Illusts);
|
||||
var items = pixiv_common.ConvertToSyndicationItems(illusts);
|
||||
|
||||
// フィード作成と XML 出力
|
||||
pixiv_common.CreateAndExportFeed(
|
||||
@@ -45,7 +46,7 @@ internal class pixiv_r18
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AddLog($"[エラー] [pixiv_r18]: {ex.Message}");
|
||||
AddLog($"[エラー] [pixiv_r18_ai]: {ex.Message}");
|
||||
CmnUtil.PrintCallStackToEvent(ex);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using static rss_generator.Class.LogManager;
|
||||
|
||||
namespace rss_generator.Class.RSS.Pixiv;
|
||||
|
||||
/// <summary>
|
||||
/// Pixiv のフォロー中ユーザーの最新 R-18・非AI作品フィード (pixiv_r18_non_ai.xml) を生成するクラス
|
||||
/// </summary>
|
||||
internal class pixiv_r18_non_ai
|
||||
{
|
||||
private const string FEED_TITLE = "Pixiv (Follow R-18 - Non-AI)";
|
||||
private const string FEED_DESCRIPTION = "Pixiv のフォロー中ユーザーによる最新 R-18・非AI作品フィード";
|
||||
private const string FEED_LINK = "https://www.pixiv.net/bookmark_new_illust_r18.php";
|
||||
private const string XML_FILE_NAME = "pixiv_r18_non_ai.xml";
|
||||
|
||||
/// <summary>
|
||||
/// Pixiv のフォロー新着から R-18・非AI作品を最低30件取得し、pixiv_r18_non_ai.xml を生成します。
|
||||
/// </summary>
|
||||
/// <param name="client">HttpClient インスタンス</param>
|
||||
public static async Task CreateRSSAsync(HttpClient client)
|
||||
{
|
||||
try
|
||||
{
|
||||
// R-18 (xRestrict >= 1) かつ非AI作品 (!IsAiGenerated) を最低30件集まるまで取得
|
||||
var illusts = await pixiv_common.FetchIllustsUntilCountAsync(
|
||||
client,
|
||||
mode: "r18",
|
||||
predicate: x => x.XRestrict >= 1 && !x.IsAiGenerated,
|
||||
minCount: 30
|
||||
);
|
||||
|
||||
// SyndicationItem のリストに変換
|
||||
var items = pixiv_common.ConvertToSyndicationItems(illusts);
|
||||
|
||||
// フィード作成と XML 出力
|
||||
pixiv_common.CreateAndExportFeed(
|
||||
FEED_TITLE,
|
||||
FEED_DESCRIPTION,
|
||||
FEED_LINK,
|
||||
XML_FILE_NAME,
|
||||
items
|
||||
);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AddLog($"[エラー] [pixiv_r18_non_ai]: {ex.Message}");
|
||||
CmnUtil.PrintCallStackToEvent(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user