Skip to content

Commit fa090aa

Browse files
committed
try support nyaa torrentflags
1 parent 8f1449c commit fa090aa

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

OKP.Core/Interface/Nyaa/NyaaAdapter.cs

+51
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ internal class NyaaAdapter : AdapterBase
1818
private readonly string pingUrl = "upload";
1919
private readonly string postUrl = "upload";
2020
private string category;
21+
private NyaaTorrentFlags torrentFlags;
2122
private const string site = "nyaa";
2223
public NyaaAdapter(TorrentContent torrent, Template template)
2324
{
@@ -41,6 +42,7 @@ public NyaaAdapter(TorrentContent torrent, Template template)
4142
httpClientHandler.UseProxy = true;
4243
}
4344
category = CategoryHelper.SelectCategory(torrent.Tags, site);
45+
torrentFlags = SetFlags(torrent.TorrentFlags, torrent.Tags);
4446
if (!Valid())
4547
{
4648
IOHelper.ReadLine();
@@ -84,6 +86,28 @@ public override async Task<HttpResult> PostAsync()
8486
{ new StringContent(torrent.About??""), "information" },
8587
{ new StringContent(template.Content??""), "description" },
8688
};
89+
90+
if (torrentFlags != NyaaTorrentFlags.None)
91+
{
92+
var yes = new StringContent("y");
93+
if (torrentFlags.HasFlag(NyaaTorrentFlags.Anonymous))
94+
{
95+
form.Add(yes, "is_anonymous" );
96+
}
97+
if (torrentFlags.HasFlag(NyaaTorrentFlags.Complete))
98+
{
99+
form.Add(yes, "is_complete");
100+
}
101+
if (torrentFlags.HasFlag(NyaaTorrentFlags.Hidden))
102+
{
103+
form.Add(yes, "is_hidden");
104+
}
105+
if (torrentFlags.HasFlag(NyaaTorrentFlags.Remake))
106+
{
107+
form.Add(yes, "is_remake");
108+
}
109+
}
110+
87111
Log.Verbose("{Site} formdata content: {@MultipartFormDataContent}", site, form);
88112
var result = await httpClient.PostAsyncWithRetry(postUrl, form);
89113
var raw = await result.Content.ReadAsStringAsync();
@@ -141,5 +165,32 @@ private bool Valid()
141165
}
142166
return true;
143167
}
168+
169+
private NyaaTorrentFlags SetFlags(List<NyaaTorrentFlags>? flags, List<ContentTypes>? tags)
170+
{
171+
var flag = NyaaTorrentFlags.None;
172+
if (flags is not null)
173+
{
174+
foreach (var v in flags)
175+
{
176+
if (v == NyaaTorrentFlags.None)
177+
{
178+
flag = NyaaTorrentFlags.None;
179+
break;
180+
}
181+
flag |= v;
182+
}
183+
}
184+
185+
if (tags is not null)
186+
{
187+
if (tags.Contains(ContentTypes.Batch) || tags.Contains(ContentTypes.Collection))
188+
{
189+
flag |= NyaaTorrentFlags.Complete;
190+
}
191+
}
192+
193+
return flag;
194+
}
144195
}
145196
}

OKP.Core/Interface/TorrentContent.cs

+11
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public TorrentData(string filename)
5050
public bool IsFinished { get; set; }
5151
public string? CookiePath { get; set; }
5252
public List<ContentTypes>? Tags { get; set; }
53+
public List<NyaaTorrentFlags>? TorrentFlags { get; set; }
5354
public class Template
5455
{
5556
public string? Site { get; set; }
@@ -254,6 +255,16 @@ public void DisplayFileTree()
254255
}
255256
Log.Information("文件列表:{NewLine}{FileList}", Environment.NewLine, fileList);
256257
}
258+
259+
[Flags]
260+
public enum NyaaTorrentFlags
261+
{
262+
None = 0b_0,
263+
Anonymous = 0b_1,
264+
Hidden = 0b_10,
265+
Remake = 0b_100,
266+
Complete = 0b_1000,
267+
}
257268
}
258269

259270
public class UserProperties

0 commit comments

Comments
 (0)