Skip to content

Commit b91a2d7

Browse files
committed
remove newtonsoft, change FileListTorrent into a record and make it match the returned object 1:1
1 parent 40ae362 commit b91a2d7

File tree

3 files changed

+56
-47
lines changed

3 files changed

+56
-47
lines changed
Lines changed: 46 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,120 +1,125 @@
1-
using Newtonsoft.Json;
1+
using System.Text.Json.Serialization;
2+
// ReSharper disable ClassNeverInstantiated.Global
23

34
namespace FileListSharp.Builders;
45

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)
6+
public record FileListTorrent
257
{
268
/// <summary>
279
/// The ID of the torrent
2810
/// </summary>
29-
public readonly int Id = id;
11+
[JsonPropertyName("id")]
12+
public required int Id { get; init; }
3013

3114
/// <summary>
3215
/// The full name of the torrent
3316
/// </summary>
34-
public readonly string Name = name;
17+
[JsonPropertyName("name")]
18+
public required string Name { get; init; }
3519

3620
/// <summary>
3721
/// The IMDb ID of the torrent's content
3822
/// </summary>
39-
public readonly string? Imdb = imdb;
23+
[JsonPropertyName("imdb")]
24+
public string? Imdb { get; init; }
4025

4126
/// <summary>
4227
/// Whether this torrent is freeleech
4328
/// </summary>
44-
public readonly bool Freeleech = freeleech;
29+
[JsonPropertyName("freeleech")]
30+
public required int FreeLeech { get; init; }
4531

4632
/// <summary>
4733
/// Whether this torrent counts as a double upload
4834
/// </summary>
49-
public readonly bool Doubleup = doubleup;
35+
[JsonPropertyName("doubleup")]
36+
public required int DoubleUp { get; init; }
5037

5138
/// <summary>
5239
/// The upload date of the torrent
5340
/// </summary>
54-
public readonly string UploadDate = uploadDate;
41+
[JsonPropertyName("upload_date")]
42+
public required string UploadDate { get; init; }
5543

5644
/// <summary>
5745
/// URL used for downloading this torrent
5846
/// </summary>
59-
public readonly string DownloadLink = downloadLink;
47+
[JsonPropertyName("download_link")]
48+
public required string DownloadLink { get; init; }
6049

6150
/// <summary>
6251
/// The size of the torrent in bytes
6352
/// </summary>
64-
public readonly long Size = size;
53+
[JsonPropertyName("size")]
54+
public long Size { get; init; }
6555

6656
/// <summary>
6757
/// Whether this torrent was uploaded by the internal FileList team
6858
/// </summary>
69-
public readonly bool Internal = internalnum is 1;
59+
[JsonPropertyName("internal")]
60+
public int Internal { get; init; }
7061

7162
/// <summary>
7263
/// Whether this torrent is moderated
7364
/// </summary>
74-
public readonly bool Moderated = moderated is 1;
65+
[JsonPropertyName("moderated")]
66+
public int Moderated { get; init; }
7567

7668
/// <summary>
7769
/// The category this torrent is in
7870
/// </summary>
79-
public readonly string Category = category;
71+
[JsonPropertyName("category")]
72+
public required string Category { get; init; }
8073

8174
/// <summary>
8275
/// The number of people seeding this torrent
8376
/// </summary>
84-
public readonly int Seeders = seeders;
77+
[JsonPropertyName("seeders")]
78+
public int Seeders { get; init; }
8579

8680
/// <summary>
8781
/// The number of people leeching (downloading) this torrent
8882
/// </summary>
89-
public readonly int Leechers = leechers;
83+
[JsonPropertyName("leechers")]
84+
public int Leechers { get; init; }
9085

9186
/// <summary>
9287
/// The number of times this torrent was snatched (downloaded)
9388
/// </summary>
94-
public readonly int TimesCompleted = timesCompleted;
89+
[JsonPropertyName("times_completed")]
90+
public int TimesCompleted { get; init; }
9591

9692
/// <summary>
9793
/// The number of comments left on this torrent
9894
/// </summary>
99-
public readonly int Comments = comments;
95+
[JsonPropertyName("comments")]
96+
public int Comments { get; init; }
10097

10198
/// <summary>
10299
/// The number of files this torrent contains
103100
/// </summary>
104-
public readonly int Files = files;
101+
[JsonPropertyName("files")]
102+
public int Files { get; init; }
105103

106104
/// <summary>
107105
/// A small description of the torrent
108106
/// </summary>
109-
public readonly string Description = description;
107+
public string? Description { get; init; }
110108

109+
[JsonPropertyName("tv")] public Tv? Tv { get; init; }
110+
}
111+
112+
public record Tv
113+
{
111114
/// <summary>
112115
/// The season of the TV show contained in this torrent (where applicable)
113-
/// </summary>
114-
public readonly int? TvSeason = tv["season"];
116+
/// </summary>
117+
[JsonPropertyName("season")]
118+
public int? Season { get; init; }
115119

116120
/// <summary>
117121
/// The episode of the TV show contained in this torrent (where applicable)
118122
/// </summary>
119-
public readonly int? TvEpisode = tv["episode"];
123+
[JsonPropertyName("episode")]
124+
public int? Episode { get; init; }
120125
}

FileListSharp/FileListSharp.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
using System.Net;
22
using System.Net.Http.Headers;
33
using System.Text;
4+
using System.Text.Json;
45
using System.Web;
5-
using Newtonsoft.Json;
6-
using FileListSharp.Builders;
6+
using FileListSharp.Builders;
77

88
namespace FileListSharp;
99

@@ -70,14 +70,17 @@ public FileList(string username, string passkey)
7070
if (!response.IsSuccessStatusCode)
7171
{
7272
if (response.StatusCode == HttpStatusCode.TooManyRequests)
73+
{
7374
throw new Exception("Rate limit reached, try again later.");
74-
var error = JsonConvert.DeserializeObject<FileListError>(await response.Content.ReadAsStringAsync());
75+
}
76+
77+
var error = JsonSerializer.Deserialize<FileListError>(await response.Content.ReadAsStringAsync());
7578
throw new Exception($"Failed to successfully query the API, error: {error.Error ?? "Unknown"}");
7679
}
7780

7881
var content = await response.Content.ReadAsStringAsync();
7982

80-
return JsonConvert.DeserializeObject<List<FileListTorrent>>(content);
83+
return JsonSerializer.Deserialize<List<FileListTorrent>>(content);
8184
}
8285
}
8386

FileListSharp/FileListSharp.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77
<Title>FileListSharp</Title>
88
<Authors>Alex Kovacs</Authors>
99
<Description>A FileList API Wrapper for .NET</Description>
10-
<PackageLicenseUrl>https://github.com/alexthemaster/FileListSharp/blob/master/LICENSE</PackageLicenseUrl>
10+
<PackageLicenseExpression>MIT</PackageLicenseExpression>
1111
<RepositoryUrl>https://github.com/alexthemaster/FileListSharp</RepositoryUrl>
1212
<PackageTags>tracker, filelist, torrent tracker, private torrent</PackageTags>
13+
<PackageReadmeFile>README.md</PackageReadmeFile>
1314
</PropertyGroup>
1415

1516
<ItemGroup>
16-
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
17+
<None Include="../README.md" Pack="true" PackagePath="\"/>
1718
</ItemGroup>
1819

1920
</Project>

0 commit comments

Comments
 (0)