Skip to content

Commit 037a25c

Browse files
committed
first version... question mark?
1 parent 02a7296 commit 037a25c

File tree

8 files changed

+517
-0
lines changed

8 files changed

+517
-0
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*/obj
2+
*/bin
3+
.idea
4+
test
5+
*.DotSettings.user

CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @alexthemaster
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
using System.Dynamic;
2+
using System.Text.RegularExpressions;
3+
4+
namespace FileListSharp.Builders;
5+
6+
public partial class FileListLatestParams
7+
{
8+
private int? _limit;
9+
private string? _imdb;
10+
private int[]? _category;
11+
12+
public override string ToString()
13+
{
14+
var final = "";
15+
16+
if (_limit is not null) final += $"&limit={_limit}";
17+
if (_imdb is not null) final += $"&imdb={_imdb}";
18+
if (_category is not null) final += $"&category={string.Join(",", _category)}";
19+
20+
return final;
21+
}
22+
23+
/// <summary>
24+
/// Maximum number of torrents displayed in the request. Can be 1-100.
25+
/// </summary>
26+
/// <param name="limit">Integer ranging from 1-100</param>
27+
/// <returns>FileListLatestParams</returns>
28+
/// <exception cref="ArgumentException">Invalid limit provided</exception>
29+
public FileListLatestParams Limit(int limit)
30+
{
31+
if (limit is < 1 or > 100)
32+
throw new ArgumentException($"Invalid limit provided in {GetType().Name}. Valid limits are 1-100");
33+
_limit = limit;
34+
return this;
35+
}
36+
37+
/// <summary>
38+
/// Defines an IMDb ID for filtering recent torrents
39+
/// </summary>
40+
/// <param name="imdb"></param>
41+
/// <returns>FileListLatestParams</returns>
42+
/// <exception cref="ArgumentException">In case incorrect IMDb ID is provided</exception>
43+
public FileListLatestParams Imdb(string imdb)
44+
{
45+
if (!ImdbRegex().IsMatch(imdb))
46+
{
47+
throw new ArgumentException(
48+
"When using the IMDb search type you can only use IMDb IDs (as tt0000000 or 0000000)");
49+
}
50+
51+
_imdb = imdb;
52+
return this;
53+
}
54+
55+
/// <summary>
56+
/// Defines an array of categories for filtering recent torrents, for information on that IDs are which access <see href="https://gist.github.com/alexthemaster/c4a64a718e5db2128a8b179ff1ca86e3">this</see>
57+
/// </summary>
58+
/// <param name="categories">An array of catogories</param>
59+
/// <returns>FileListLatestParams</returns>
60+
/// <exception cref="ArgumentException">If incorrect category ID is provided</exception>
61+
public FileListLatestParams Categories(int[] categories)
62+
{
63+
if (categories.All(v => v is < 1 or > 27))
64+
{
65+
throw new ArgumentException("Invalid category number provided. Valid categories are 1-27");
66+
}
67+
68+
_category = categories;
69+
return this;
70+
}
71+
72+
[GeneratedRegex(@"(tt[0-9]*)")]
73+
private static partial Regex ImdbRegex();
74+
}
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
using System.Diagnostics.CodeAnalysis;
2+
using System.Dynamic;
3+
using System.Text.RegularExpressions;
4+
using Newtonsoft.Json;
5+
6+
namespace FileListSharp.Builders;
7+
8+
[SuppressMessage("ReSharper", "ClassNeverInstantiated.Global")]
9+
public partial class FileListSearchParams
10+
{
11+
private string _type = "name";
12+
private string? _query;
13+
private int[]? _category = [];
14+
private int? _moderated;
15+
private int? _internal;
16+
private int? _freeleech;
17+
private int? _doubleup;
18+
private int? _season;
19+
private int? _episode;
20+
21+
public override string ToString()
22+
{
23+
if (_query is null) throw new ArgumentNullException("Query", $"The query for {GetType().Name} cannot be null.");
24+
var final = $"type={_type}&query={_query}";
25+
26+
if (_category is not null) final += $"&category={string.Join(',', _category)}";
27+
if (_moderated is not null) final += $"&moderated={_moderated}";
28+
if (_internal is not null) final += $"&internal={_internal}";
29+
if (_freeleech is not null) final += $"&freeleech={_freeleech}";
30+
if (_doubleup is not null) final += $"&doubleup={_doubleup}";
31+
if (_season is not null) final += $"&season={_season}";
32+
if (_episode is not null) final += $"&episode={_episode}";
33+
34+
return final;
35+
}
36+
37+
/// <summary>
38+
/// Whether to search torrents based on its name or its tagged IMDb ID <br/> Defaults to <c>name</c>
39+
/// </summary>
40+
/// <param name="type">name or imdb</param>
41+
/// <returns>FileListSearchParams</returns>
42+
/// <exception cref="ArgumentException">If type is neither name nor imdb</exception>
43+
public FileListSearchParams Type(string type)
44+
{
45+
type = type.ToLower();
46+
if (type is "name" or "imdb")
47+
{
48+
_type = type;
49+
}
50+
else
51+
{
52+
throw new ArgumentException("The type can only be name or imdb.");
53+
}
54+
55+
return this;
56+
}
57+
58+
/// <summary>
59+
/// The query for the search (name of the torrent or an IMDb ID)
60+
/// </summary>
61+
/// <param name="query"></param>
62+
/// <returns>FileListSearchParams</returns>
63+
/// <exception cref="ArgumentException">If search type is IMDb but no valid IMDb ID is provided</exception>
64+
public FileListSearchParams Query(string query)
65+
{
66+
{
67+
if (_type is "imdb")
68+
{
69+
if (ImdbRegex().IsMatch(query))
70+
{
71+
_query = query;
72+
}
73+
else
74+
{
75+
throw new ArgumentException(
76+
"When using the IMDb search type you can only use IMDb ids (as tt0000000 or 0000000)");
77+
}
78+
}
79+
else
80+
{
81+
_query = query;
82+
}
83+
}
84+
85+
return this;
86+
}
87+
88+
/// <summary>
89+
/// Defines an array of categories for filtering the searched torrents, for information on that IDs are which access <see href="https://gist.github.com/alexthemaster/c4a64a718e5db2128a8b179ff1ca86e3">this</see>
90+
/// </summary>
91+
/// <param name="categories">An array of catogories</param>
92+
/// <returns>FileListSearchParams</returns>
93+
/// <exception cref="ArgumentException">If incorrect category ID is provided</exception>
94+
public FileListSearchParams Categories(int[] categories)
95+
{
96+
if (categories.All(v => v is < 1 or > 27))
97+
{
98+
throw new ArgumentException("Invalid category number provided. Valid categories are 1-27");
99+
}
100+
101+
_category = categories;
102+
return this;
103+
}
104+
105+
/// <summary>
106+
/// Whether the searched torrent should be moderated
107+
/// </summary>
108+
/// <param name="moderated">True or False</param>
109+
/// <returns>FileListSearchParams</returns>
110+
public FileListSearchParams Moderated(bool moderated)
111+
{
112+
_moderated = moderated ? 1 : 0;
113+
return this;
114+
}
115+
116+
/// <summary>
117+
/// Whether the searched torrent should be one uploaded by the internal team
118+
/// </summary>
119+
/// <param name="internalbool">True or False</param>
120+
/// <returns>FileListSearchParams</returns>
121+
public FileListSearchParams Internal(bool internalbool)
122+
{
123+
_internal = internalbool ? 1 : 0;
124+
return this;
125+
}
126+
127+
/// <summary>
128+
/// Whether the searched torrent should be freeleech
129+
/// </summary>
130+
/// <param name="freeleech">True or False</param>
131+
/// <returns>FileListSearchParams</returns>
132+
public FileListSearchParams FreeLeech(bool freeleech)
133+
{
134+
_freeleech = freeleech ? 1 : 0;
135+
return this;
136+
}
137+
138+
/// <summary>
139+
/// Whether the searched torrent should have the double upload property or not
140+
/// </summary>
141+
/// <param name="doubleup">True or False</param>
142+
/// <returns>FileListSearchParams</returns>
143+
public FileListSearchParams DoubleUp(bool doubleup)
144+
{
145+
_doubleup = doubleup ? 1 : 0;
146+
return this;
147+
}
148+
149+
/// <summary>
150+
/// If searching for a specific TV show season, provide it here
151+
/// </summary>
152+
/// <param name="season"></param>
153+
/// <returns>FileListSearchParams</returns>
154+
public FileListSearchParams Season(int season)
155+
{
156+
_season = season;
157+
return this;
158+
}
159+
160+
/// <summary>
161+
/// If searching for a specific TV show episode, provide it here
162+
/// </summary>
163+
/// <param name="episode"></param>
164+
/// <returns></returns>
165+
public FileListSearchParams Episode(int episode)
166+
{
167+
_episode = episode;
168+
return this;
169+
}
170+
171+
[GeneratedRegex(@"(tt[0-9]*)")]
172+
private static partial Regex ImdbRegex();
173+
}
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
using Newtonsoft.Json;
2+
3+
namespace FileListSharp.Builders;
4+
5+
public class FileListTorrent(
6+
int id,
7+
string name,
8+
string? imdb,
9+
bool freeleech,
10+
bool doubleup,
11+
[JsonProperty("upload_date")] string uploadDate,
12+
[JsonProperty("download_link")] string downloadLink,
13+
long size,
14+
[JsonProperty("internal")] int internalnum,
15+
int moderated,
16+
string category,
17+
int seeders,
18+
int leechers,
19+
[JsonProperty("times_completed")] int timesCompleted,
20+
int comments,
21+
int files,
22+
string description,
23+
[JsonProperty("tv")]
24+
Dictionary<string,int?> tv)
25+
{
26+
/// <summary>
27+
/// The ID of the torrent
28+
/// </summary>
29+
public readonly int Id = id;
30+
31+
/// <summary>
32+
/// The full name of the torrent
33+
/// </summary>
34+
public readonly string Name = name;
35+
36+
/// <summary>
37+
/// The IMDb ID of the torrent's content
38+
/// </summary>
39+
public readonly string? Imdb = imdb;
40+
41+
/// <summary>
42+
/// Whether this torrent is freeleech
43+
/// </summary>
44+
public readonly bool Freeleech = freeleech;
45+
46+
/// <summary>
47+
/// Whether this torrent counts as a double upload
48+
/// </summary>
49+
public readonly bool Doubleup = doubleup;
50+
51+
/// <summary>
52+
/// The upload date of the torrent
53+
/// </summary>
54+
public readonly string UploadDate = uploadDate;
55+
56+
/// <summary>
57+
/// URL used for downloading this torrent
58+
/// </summary>
59+
public readonly string DownloadLink = downloadLink;
60+
61+
/// <summary>
62+
/// The size of the torrent in bytes
63+
/// </summary>
64+
public readonly long Size = size;
65+
66+
/// <summary>
67+
/// Whether this torrent was uploaded by the internal FileList team
68+
/// </summary>
69+
public readonly bool Internal = internalnum is 1;
70+
71+
/// <summary>
72+
/// Whether this torrent is moderated
73+
/// </summary>
74+
public readonly bool Moderated = moderated is 1;
75+
76+
/// <summary>
77+
/// The category this torrent is in
78+
/// </summary>
79+
public readonly string Category = category;
80+
81+
/// <summary>
82+
/// The number of people seeding this torrent
83+
/// </summary>
84+
public readonly int Seeders = seeders;
85+
86+
/// <summary>
87+
/// The number of people leeching (downloading) this torrent
88+
/// </summary>
89+
public readonly int Leechers = leechers;
90+
91+
/// <summary>
92+
/// The number of times this torrent was snatched (downloaded)
93+
/// </summary>
94+
public readonly int TimesCompleted = timesCompleted;
95+
96+
/// <summary>
97+
/// The number of comments left on this torrent
98+
/// </summary>
99+
public readonly int Comments = comments;
100+
101+
/// <summary>
102+
/// The number of files this torrent contains
103+
/// </summary>
104+
public readonly int Files = files;
105+
106+
/// <summary>
107+
/// A small description of the torrent
108+
/// </summary>
109+
public readonly string Description = description;
110+
111+
/// <summary>
112+
/// The season of the TV show contained in this torrent (where applicable)
113+
/// </summary>
114+
public readonly int? TvSeason = tv["season"];
115+
116+
/// <summary>
117+
/// The episode of the TV show contained in this torrent (where applicable)
118+
/// </summary>
119+
public readonly int? TvEpisode = tv["episode"];
120+
}

0 commit comments

Comments
 (0)