Skip to content

Commit 1699632

Browse files
committed
use readfromjsonasync, change Tv to TV and change return type from nullable to always a List
1 parent 59cb11c commit 1699632

File tree

5 files changed

+13
-11
lines changed

5 files changed

+13
-11
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
*/bin
33
.idea
44
test
5-
*.DotSettings.user
5+
*.DotSettings.user
6+
FileListSharp.sln

FileListSharp/Builders/FileListTorrent.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,10 @@ public record FileListTorrent
107107
/// </summary>
108108
public string? Description { get; init; }
109109

110-
[JsonPropertyName("tv")] public Tv? Tv { get; init; }
110+
[JsonPropertyName("tv")] public TV? TV { get; init; }
111111
}
112112

113-
public record Tv
113+
public record TV
114114
{
115115
/// <summary>
116116
/// The season of the TV show contained in this torrent (where applicable)

FileListSharp/FileListSharp.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Net;
22
using System.Net.Http.Headers;
3+
using System.Net.Http.Json;
34
using System.Text;
45
using System.Text.Json;
56
using System.Web;
@@ -37,7 +38,7 @@ public FileList(string username, string passkey)
3738
/// </example>
3839
/// <exception cref="Exception">If the API returns an error or rate limit is reached</exception>
3940
/// <returns>FileListTorrent</returns>
40-
public async Task<List<FileListTorrent>?> SearchAsync(FileListSearchParams searchParams)
41+
public async Task<List<FileListTorrent>> SearchAsync(FileListSearchParams searchParams)
4142
{
4243
var parameters = new StringBuilder(searchParams.ToString());
4344
parameters.Append("&action=search-torrents&output=json");
@@ -56,14 +57,14 @@ public FileList(string username, string passkey)
5657
/// </example>
5758
/// <exception cref="Exception">If the API returns an error or rate limit is reached</exception>
5859
/// <returns>FileListTorrent</returns>
59-
public async Task<List<FileListTorrent>?> LatestAsync(FileListLatestParams searchParams)
60+
public async Task<List<FileListTorrent>> LatestAsync(FileListLatestParams searchParams)
6061
{
6162
var parameters = new StringBuilder(searchParams.ToString());
6263
parameters.Append("&action=latest-torrents&output=json");
6364
return await _Query(parameters.ToString());
6465
}
6566

66-
private async Task<List<FileListTorrent>?> _Query(string parameters)
67+
private async Task<List<FileListTorrent>> _Query(string parameters)
6768
{
6869
var url = $"{ApiUrl}?{HttpUtility.UrlDecode(parameters)}";
6970
var response = await _client.GetAsync(url);
@@ -74,13 +75,13 @@ public FileList(string username, string passkey)
7475
throw new Exception("Rate limit reached, try again later.");
7576
}
7677

77-
var error = JsonSerializer.Deserialize<FileListError>(await response.Content.ReadAsStringAsync());
78+
var error = await response.Content.ReadFromJsonAsync<FileListError>();
7879
throw new Exception($"Failed to successfully query the API, error: {error.Error ?? "Unknown"}");
7980
}
8081

81-
var content = await response.Content.ReadAsStringAsync();
82+
var content = await response.Content.ReadFromJsonAsync<List<FileListTorrent>>();
8283

83-
return JsonSerializer.Deserialize<List<FileListTorrent>>(content);
84+
return content ?? [];
8485
}
8586
}
8687

FileListSharp/FileListSharp.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<RepositoryUrl>https://github.com/alexthemaster/FileListSharp</RepositoryUrl>
1212
<PackageTags>tracker, filelist, torrent tracker, private torrent</PackageTags>
1313
<PackageReadmeFile>README.md</PackageReadmeFile>
14-
<Version>2.0.1</Version>
14+
<Version>3.0.0</Version>
1515
</PropertyGroup>
1616

1717
<ItemGroup>

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ Console.WriteLine($"Just looked up torrent {latest.Name} with the ID of {latest.
3737
```
3838

3939
Your passkey can be obtained from [here](https://filelist.io/my.php)<br>
40-
Category IDs can be found [here](https://gist.github.com/alexthemaster/c4a64a718e5db2128a8b179ff1ca86e3)
40+
Category IDs can be found [here](https://gist.github.com/alexthemaster/c4a64a718e5db2128a8b179ff1ca86e3)

0 commit comments

Comments
 (0)