Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/libs/Trakt.NET/Enums/TraktSmartListItemType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace TraktNET
{
/// <summary>Determines the item type to narrow a smart list holding both media types.</summary>
[TraktEnum(HasPathSupport = true)]
public enum TraktSmartListItemType
{
/// <summary>An invalid smart list item type.</summary>
Unspecified,

/// <summary>All items (movies and shows).</summary>
All,

/// <summary>Movies only.</summary>
Movies,

/// <summary>Shows only.</summary>
Shows
}
}

11 changes: 10 additions & 1 deletion src/libs/Trakt.NET/Internal/Modules/TraktSmartListsModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,19 @@ private Task<TraktResponse<TraktSmartList>> GetSmartListImplAsync(string listIdO
}

private Task<TraktPagedResponse<TraktListItem>> GetSmartListItemsImplAsync(
string listIdOrSlug, TraktFilter? filter = null, string? watchnow = null,
string listIdOrSlug, TraktSmartListItemType? type = null, TraktSortBy? sortBy = null, TraktSortHow? sortHow = null,
TraktFilter? filter = null, string? watchnow = null, string? watchnowCountry = null,
TraktExtendedInfo? extendedInfo = null, uint? page = null, uint? limit = null, CancellationToken cancellationToken = default)
{
var request = new SmartListItemsGetRequest
{
ListId = listIdOrSlug,
Type = type,
SortBy = sortBy,
SortHow = sortHow,
Filter = filter,
Watchnow = watchnow,
WatchnowCountry = watchnowCountry,
ExtendedInfo = extendedInfo,
Page = page,
Limit = limit
Expand All @@ -36,8 +41,12 @@ private Task<TraktPagedResponse<TraktListItem>> GetSmartListItemsImplAsync(
=> new SmartListItemsGetRequest
{
ListId = listIdOrSlug,
Type = type,
SortBy = sortBy,
SortHow = sortHow,
Filter = filter,
Watchnow = watchnow,
WatchnowCountry = watchnowCountry,
ExtendedInfo = extendedInfo,
Page = page,
Limit = limit
Expand Down
35 changes: 35 additions & 0 deletions src/libs/Trakt.NET/Internal/Parameters/TraktFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ public sealed partial class TraktFilter
private const string IgnoreWatchlistedName = "ignore_watchlisted";
private const string StartDateName = "start_date";
private const string EndDateName = "end_date";
private const string ParentalNudityName = "parental_nudity";
private const string ParentalViolenceName = "parental_violence";
private const string ParentalProfanityName = "parental_profanity";
private const string ParentalAlcoholName = "parental_alcohol";
private const string ParentalFrighteningName = "parental_frightening";
private const string ParentalIncludeUnratedName = "parental_include_unrated";

public override string ToString()
{
Expand Down Expand Up @@ -162,9 +168,38 @@ public override string ToString()
values.Add($"{EndDateName}={EndDate.Value.ToTraktSortDateTimeString()}");
}

AddParentalRange(values, ParentalNudity, ParentalNudityName);
AddParentalRange(values, ParentalViolence, ParentalViolenceName);
AddParentalRange(values, ParentalProfanity, ParentalProfanityName);
AddParentalRange(values, ParentalAlcohol, ParentalAlcoholName);
AddParentalRange(values, ParentalFrightening, ParentalFrighteningName);

if (ParentalIncludeUnrated.HasValue)
{
values.Add($"{ParentalIncludeUnratedName}={ParentalIncludeUnrated.Value.ToString().ToLower(CultureInfo.CurrentCulture)}");
}

return string.Join("&", values);
}

private static void AddParentalRange(List<string> values, Range<uint>? range, string name)
{
if (range.HasValue)
{
uint firstValue = range.Value.From;
uint secondValue = range.Value.To;

if (firstValue <= secondValue)
{
values.Add($"{name}={firstValue}-{secondValue}");
}
else
{
values.Add($"{name}={secondValue}-{firstValue}");
}
}
}

private static void AddRange(List<string> values, Range<uint>? range, string name)
{
if (range.HasValue && range.Value.From > 0 && range.Value.To > 0)
Expand Down
12 changes: 12 additions & 0 deletions src/libs/Trakt.NET/Internal/Requests/SmartListRequests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,24 @@ internal sealed partial class SmartListGetRequest
SupportsExtendedInfo = true, SupportsPagination = true, OAuthRequirement = TraktOAuthRequirement.OptionalButMightBeRequired)]
internal sealed partial class SmartListItemsGetRequest
{
[TraktRequestParameter]
internal TraktSmartListItemType? Type { get; set; }

[TraktRequestParameter]
internal TraktSortBy? SortBy { get; set; }

[TraktRequestParameter]
internal TraktSortHow? SortHow { get; set; }

[TraktRequestQuery("filter")]
internal TraktFilter? Filter { get; set; }

[TraktRequestQuery("watchnow")]
internal string? Watchnow { get; set; }

[TraktRequestQuery("watchnow_country")]
internal string? WatchnowCountry { get; set; }

internal override TraktRequestObjectType RequestObjectType => TraktRequestObjectType.List;
}
}
21 changes: 21 additions & 0 deletions src/libs/Trakt.NET/Json/SmartLists/TraktSmartListFilters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public record class TraktSmartListFilters
/// <summary>Collection of watchnow streaming service options.</summary>
public string[]? Watchnow { get; set; }

/// <summary>2-character country code for watchnow.</summary>
public string? WatchnowCountry { get; set; }

/// <summary>Year range [min, max]. Max 2 items.</summary>
public uint[]? Years { get; set; }

Expand All @@ -66,6 +69,24 @@ public record class TraktSmartListFilters
/// <summary>MyAnimeList ratings range [min, max]. Max 2 items.</summary>
public float[]? MalRatings { get; set; }

/// <summary>Parental guide nudity severity range [min, max] from 0 (none) to 3 (severe). Max 2 items.</summary>
public uint[]? ParentalNudity { get; set; }

/// <summary>Parental guide violence severity range [min, max] from 0 (none) to 3 (severe). Max 2 items.</summary>
public uint[]? ParentalViolence { get; set; }

/// <summary>Parental guide profanity severity range [min, max] from 0 (none) to 3 (severe). Max 2 items.</summary>
public uint[]? ParentalProfanity { get; set; }

/// <summary>Parental guide alcohol severity range [min, max] from 0 (none) to 3 (severe). Max 2 items.</summary>
public uint[]? ParentalAlcohol { get; set; }

/// <summary>Parental guide frightening severity range [min, max] from 0 (none) to 3 (severe). Max 2 items.</summary>
public uint[]? ParentalFrightening { get; set; }

/// <summary>Gets or sets whether to keep titles without a parental guide when a parental range is set.</summary>
public bool? ParentalIncludeUnrated { get; set; }

/// <summary>Gets or sets whether watched items should be ignored.</summary>
public bool? IgnoreWatched { get; set; }

Expand Down
36 changes: 28 additions & 8 deletions src/libs/Trakt.NET/Modules/TraktSmartListsModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,12 @@ public Task<TraktResponse<TraktSmartList>> GetSmartListAsync(TraktSmartList list

/// <summary>Gets items of a smart list.</summary>
/// <param name="listIdOrSlug">The id or slug of the smart list, for which items should be retrieved.</param>
/// <param name="type">Determines, which type of smart list items should be queried. See also <seealso cref="TraktSmartListItemType" />.</param>
/// <param name="sortBy">Determines, how to sort the smart list items. See also <seealso cref="TraktSortBy" />.</param>
/// <param name="sortHow">Determines, the sort direction for the smart list items. See also <seealso cref="TraktSortHow" />.</param>
/// <param name="filter">Optional filters. See also <seealso cref="TraktFilter" />.</param>
/// <param name="watchnow">Optional watchnow streaming service options.</param>
/// <param name="watchnowCountry">Optional 2-letter country code for watchnow streaming services.</param>
/// <param name="extendedInfo">The extended information options. See also <seealso cref="TraktExtendedInfo" />.</param>
/// <param name="page">The page number of items to retrieve.</param>
/// <param name="limit">The page limit of items to retrieve.</param>
Expand All @@ -141,14 +145,19 @@ public Task<TraktResponse<TraktSmartList>> GetSmartListAsync(TraktSmartList list
/// <exception cref="TraktApiException">Thrown, if the request fails.</exception>
/// <exception cref="TraktRequestValidationException">Thrown, if validation of request data fails.</exception>
public Task<TraktPagedResponse<TraktListItem>> GetSmartListItemsAsync(
string listIdOrSlug, TraktFilter? filter = null, string? watchnow = null,
string listIdOrSlug, TraktSmartListItemType? type = null, TraktSortBy? sortBy = null, TraktSortHow? sortHow = null,
TraktFilter? filter = null, string? watchnow = null, string? watchnowCountry = null,
TraktExtendedInfo? extendedInfo = null, uint? page = null, uint? limit = null, CancellationToken cancellationToken = default)
=> GetSmartListItemsImplAsync(listIdOrSlug, filter, watchnow, extendedInfo, page, limit, cancellationToken);
=> GetSmartListItemsImplAsync(listIdOrSlug, type, sortBy, sortHow, filter, watchnow, watchnowCountry, extendedInfo, page, limit, cancellationToken);

/// <summary>Gets items of a smart list.</summary>
/// <param name="traktListId">The Trakt-ID of the smart list, for which items should be retrieved.</param>
/// <param name="type">Determines, which type of smart list items should be queried. See also <seealso cref="TraktSmartListItemType" />.</param>
/// <param name="sortBy">Determines, how to sort the smart list items. See also <seealso cref="TraktSortBy" />.</param>
/// <param name="sortHow">Determines, the sort direction for the smart list items. See also <seealso cref="TraktSortHow" />.</param>
/// <param name="filter">Optional filters. See also <seealso cref="TraktFilter" />.</param>
/// <param name="watchnow">Optional watchnow streaming service options.</param>
/// <param name="watchnowCountry">Optional 2-letter country code for watchnow streaming services.</param>
/// <param name="extendedInfo">The extended information options. See also <seealso cref="TraktExtendedInfo" />.</param>
/// <param name="page">The page number of items to retrieve.</param>
/// <param name="limit">The page limit of items to retrieve.</param>
Expand All @@ -170,19 +179,24 @@ public Task<TraktPagedResponse<TraktListItem>> GetSmartListItemsAsync(
/// <exception cref="TraktRequestValidationException">Thrown, if validation of request data fails.</exception>
/// <exception cref="ArgumentException">Thrown, if the given <paramref name="traktListId"/> is 0.</exception>
public Task<TraktPagedResponse<TraktListItem>> GetSmartListItemsAsync(
uint traktListId, TraktFilter? filter = null, string? watchnow = null,
uint traktListId, TraktSmartListItemType? type = null, TraktSortBy? sortBy = null, TraktSortHow? sortHow = null,
TraktFilter? filter = null, string? watchnow = null, string? watchnowCountry = null,
TraktExtendedInfo? extendedInfo = null, uint? page = null, uint? limit = null, CancellationToken cancellationToken = default)
{
if (traktListId == 0)
throw new ArgumentException("list id must not be 0", nameof(traktListId));

return GetSmartListItemsAsync(traktListId.ToInvariantCultureString(), filter, watchnow, extendedInfo, page, limit, cancellationToken);
return GetSmartListItemsAsync(traktListId.ToInvariantCultureString(), type, sortBy, sortHow, filter, watchnow, watchnowCountry, extendedInfo, page, limit, cancellationToken);
}

/// <summary>Gets items of a smart list.</summary>
/// <param name="listIds">The ids of the smart list, for which items should be retrieved.</param>
/// <param name="type">Determines, which type of smart list items should be queried. See also <seealso cref="TraktSmartListItemType" />.</param>
/// <param name="sortBy">Determines, how to sort the smart list items. See also <seealso cref="TraktSortBy" />.</param>
/// <param name="sortHow">Determines, the sort direction for the smart list items. See also <seealso cref="TraktSortHow" />.</param>
/// <param name="filter">Optional filters. See also <seealso cref="TraktFilter" />.</param>
/// <param name="watchnow">Optional watchnow streaming service options.</param>
/// <param name="watchnowCountry">Optional 2-letter country code for watchnow streaming services.</param>
/// <param name="extendedInfo">The extended information options. See also <seealso cref="TraktExtendedInfo" />.</param>
/// <param name="page">The page number of items to retrieve.</param>
/// <param name="limit">The page limit of items to retrieve.</param>
Expand All @@ -205,21 +219,26 @@ public Task<TraktPagedResponse<TraktListItem>> GetSmartListItemsAsync(
/// <exception cref="ArgumentNullException">Thrown, if the given <paramref name="listIds"/> is null.</exception>
/// <exception cref="ArgumentException">Thrown, if the given <paramref name="listIds"/> has not any ids set.</exception>
public Task<TraktPagedResponse<TraktListItem>> GetSmartListItemsAsync(
TraktListIDs listIds, TraktFilter? filter = null, string? watchnow = null,
TraktListIDs listIds, TraktSmartListItemType? type = null, TraktSortBy? sortBy = null, TraktSortHow? sortHow = null,
TraktFilter? filter = null, string? watchnow = null, string? watchnowCountry = null,
TraktExtendedInfo? extendedInfo = null, uint? page = null, uint? limit = null, CancellationToken cancellationToken = default)
{
ArgumentValidator.ThrowIfNull(listIds);

if (!listIds.HasAnyID)
throw new ArgumentException($"{nameof(listIds)} has not any ids set", nameof(listIds));

return GetSmartListItemsAsync(listIds.BestID, filter, watchnow, extendedInfo, page, limit, cancellationToken);
return GetSmartListItemsAsync(listIds.BestID, type, sortBy, sortHow, filter, watchnow, watchnowCountry, extendedInfo, page, limit, cancellationToken);
}

/// <summary>Gets items of a smart list.</summary>
/// <param name="list">The smart list, for which items should be retrieved.</param>
/// <param name="type">Determines, which type of smart list items should be queried. See also <seealso cref="TraktSmartListItemType" />.</param>
/// <param name="sortBy">Determines, how to sort the smart list items. See also <seealso cref="TraktSortBy" />.</param>
/// <param name="sortHow">Determines, the sort direction for the smart list items. See also <seealso cref="TraktSortHow" />.</param>
/// <param name="filter">Optional filters. See also <seealso cref="TraktFilter" />.</param>
/// <param name="watchnow">Optional watchnow streaming service options.</param>
/// <param name="watchnowCountry">Optional 2-letter country code for watchnow streaming services.</param>
/// <param name="extendedInfo">The extended information options. See also <seealso cref="TraktExtendedInfo" />.</param>
/// <param name="page">The page number of items to retrieve.</param>
/// <param name="limit">The page limit of items to retrieve.</param>
Expand All @@ -241,11 +260,12 @@ public Task<TraktPagedResponse<TraktListItem>> GetSmartListItemsAsync(
/// <exception cref="TraktRequestValidationException">Thrown, if validation of request data fails.</exception>
/// <exception cref="ArgumentNullException">Thrown, if the given <paramref name="list"/> is null.</exception>
public Task<TraktPagedResponse<TraktListItem>> GetSmartListItemsAsync(
TraktSmartList list, TraktFilter? filter = null, string? watchnow = null,
TraktSmartList list, TraktSmartListItemType? type = null, TraktSortBy? sortBy = null, TraktSortHow? sortHow = null,
TraktFilter? filter = null, string? watchnow = null, string? watchnowCountry = null,
TraktExtendedInfo? extendedInfo = null, uint? page = null, uint? limit = null, CancellationToken cancellationToken = default)
{
ArgumentValidator.ThrowIfNull(list);
return GetSmartListItemsAsync(list.IDs!, filter, watchnow, extendedInfo, page, limit, cancellationToken);
return GetSmartListItemsAsync(list.IDs!, type, sortBy, sortHow, filter, watchnow, watchnowCountry, extendedInfo, page, limit, cancellationToken);
}
}
}
18 changes: 18 additions & 0 deletions src/libs/Trakt.NET/Parameters/TraktFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,23 @@ public sealed partial class TraktFilter

/// <summary>Gets or sets the end date constraint.</summary>
public DateTime? EndDate { get; set; }

/// <summary>Parental guide nudity severity range between 0 (none) and 3 (severe).</summary>
public Range<uint>? ParentalNudity { get; set; }

/// <summary>Parental guide violence severity range between 0 (none) and 3 (severe).</summary>
public Range<uint>? ParentalViolence { get; set; }

/// <summary>Parental guide profanity severity range between 0 (none) and 3 (severe).</summary>
public Range<uint>? ParentalProfanity { get; set; }

/// <summary>Parental guide alcohol severity range between 0 (none) and 3 (severe).</summary>
public Range<uint>? ParentalAlcohol { get; set; }

/// <summary>Parental guide frightening severity range between 0 (none) and 3 (severe).</summary>
public Range<uint>? ParentalFrightening { get; set; }

/// <summary>Gets or sets whether to keep titles without a parental guide when a parental range is set.</summary>
public bool? ParentalIncludeUnrated { get; set; }
}
}
22 changes: 22 additions & 0 deletions src/tests/libs/JsonData/SmartLists/smartlist.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"watchnow": [
"netflix"
],
"watchnow_country": "us",
"years": [
2010,
2020
Expand Down Expand Up @@ -77,6 +78,27 @@
7.0,
9.5
],
"parental_nudity": [
0,
1
],
"parental_violence": [
0,
2
],
"parental_profanity": [
1,
3
],
"parental_alcohol": [
0,
0
],
"parental_frightening": [
2,
3
],
"parental_include_unrated": true,
"ignore_watched": true,
"ignore_watchlisted": false,
"ignore_watching": true,
Expand Down
Loading
Loading