Merge pull request #573 from Radarr/patch/more-trakt-options

Added more options to trakt, popular movies, upcoming, anticipated etc..
pull/2/head
Devin Buhl 8 years ago committed by GitHub
commit a282ad7809

@ -21,9 +21,18 @@ namespace NzbDrone.Core.NetImport.Trakt
public class TraktResponse
{
public int rank { get; set; }
public int? rank { get; set; }
public string listed_at { get; set; }
public string type { get; set; }
public int? watchers { get; set; }
public long? revenue { get; set; }
public long? watcher_count { get; set; }
public long? play_count { get; set; }
public long? collected_count { get; set; }
public Movie movie { get; set; }
}
}

@ -1,9 +1,32 @@
namespace NzbDrone.Core.NetImport.Trakt
using System.Runtime.Serialization;
namespace NzbDrone.Core.NetImport.Trakt
{
public enum TraktListType
{
WatchList = 0,
Watched = 1,
CustomList = 2
[EnumMember(Value = "User Watch List")]
UserWatchList = 0,
[EnumMember(Value = "User Watched List")]
UserWatchedList = 1,
[EnumMember(Value = "User Custom List")]
UserCustomList = 2,
[EnumMember(Value = "Trending Movies")]
TrendingMovies = 3,
[EnumMember(Value = "Popular Movies")]
PopularMovies = 4,
[EnumMember(Value = "Top Anticipated Movies")]
AnticipatedMovies = 5,
[EnumMember(Value = "Top Box Office Movies")]
BoxOfficeMovies = 6,
[EnumMember(Value = "Top Watched Movies By Week")]
TopWatchedByWeek = 7,
[EnumMember(Value = "Top Watched Movies By Month")]
TopWatchedByMonth = 8,
[EnumMember(Value = "Top Watched Movies By Year")]
TopWatchedByYear = 9,
[EnumMember(Value = "Top Watched Movies Of All Time")]
TopWatchedByAllTime = 10
}
}

@ -42,26 +42,45 @@ namespace NzbDrone.Core.NetImport.Trakt
return movies;
}
var jsonResponse = JsonConvert.DeserializeObject<List<TraktResponse>>(_importResponse.Content);
// no movies were return
if (jsonResponse == null)
if (_settings.ListType == (int) TraktListType.PopularMovies)
{
return movies;
}
var jsonResponse = JsonConvert.DeserializeObject<List<Movie>>(_importResponse.Content);
foreach (var movie in jsonResponse)
foreach (var movie in jsonResponse)
{
movies.AddIfNotNull(new Tv.Movie()
{
Title = movie.title,
ImdbId = movie.ids.imdb,
TmdbId = movie.ids.tmdb,
Year = (movie.year ?? 0)
});
}
}
else
{
movies.AddIfNotNull(new Tv.Movie()
var jsonResponse = JsonConvert.DeserializeObject<List<TraktResponse>>(_importResponse.Content);
// no movies were return
if (jsonResponse == null)
{
return movies;
}
foreach (var movie in jsonResponse)
{
Title = movie.movie.title,
ImdbId = movie.movie.ids.imdb,
TmdbId = movie.movie.ids.tmdb,
Year = (movie.movie.year ?? 0)
});
movies.AddIfNotNull(new Tv.Movie()
{
Title = movie.movie.title,
ImdbId = movie.movie.ids.imdb,
TmdbId = movie.movie.ids.tmdb,
Year = (movie.movie.year ?? 0)
});
}
}
return movies;
}
protected virtual bool PreProcess(NetImportResponse indexerResponse)

@ -21,18 +21,42 @@ namespace NzbDrone.Core.NetImport.Trakt
private IEnumerable<NetImportRequest> GetMovies(string searchParameters)
{
var link = $"{Settings.Link.Trim()}{Settings.Username.Trim()}";
var link = Settings.Link.Trim();
switch (Settings.ListType)
{
case (int)TraktListType.CustomList:
link = link + $"/lists/{Settings.Listname.Trim()}/items/movies";
case (int)TraktListType.UserCustomList:
link = link + $"/users/{Settings.Username.Trim()}/lists/{Settings.Listname.Trim()}/items/movies";
break;
case (int)TraktListType.WatchList:
link = link + "/watchlist/movies";
case (int)TraktListType.UserWatchList:
link = link + $"/users/{Settings.Username.Trim()}/watchlist/movies";
break;
case (int)TraktListType.Watched:
link = link + "/watched/movies";
case (int)TraktListType.UserWatchedList:
link = link + $"/users/{Settings.Username.Trim()}/watched/movies";
break;
case (int)TraktListType.TrendingMovies:
link = link + "/movies/trending";
break;
case (int)TraktListType.PopularMovies:
link = link + "/movies/popular";
break;
case (int)TraktListType.AnticipatedMovies:
link = link + "/movies/anticipated";
break;
case (int)TraktListType.BoxOfficeMovies:
link = link + "/movies/boxoffice";
break;
case (int)TraktListType.TopWatchedByWeek:
link = link + "/movies/watched/weekly";
break;
case (int)TraktListType.TopWatchedByMonth:
link = link + "/movies/watched/monthly";
break;
case (int)TraktListType.TopWatchedByYear:
link = link + "/movies/watched/yearly";
break;
case (int)TraktListType.TopWatchedByAllTime:
link = link + "/movies/watched/all";
break;
}

@ -1,7 +1,5 @@
using FluentValidation;
using NzbDrone.Core.Annotations;
using NzbDrone.Core.Profiles;
using NzbDrone.Core.ThingiProvider;
using NzbDrone.Core.Validation;
namespace NzbDrone.Core.NetImport.Trakt
@ -20,7 +18,7 @@ namespace NzbDrone.Core.NetImport.Trakt
{
public TraktSettings()
{
Link = "https://api.trakt.tv/users/";
Link = "https://api.trakt.tv";
Username = "";
Listname = "";
}
@ -31,7 +29,7 @@ namespace NzbDrone.Core.NetImport.Trakt
[FieldDefinition(1, Label = "Trakt List Type", Type = FieldType.Select, SelectOptions = typeof(TraktListType), HelpText = "Trakt list type, custom or watchlist")]
public int ListType { get; set; }
[FieldDefinition(2, Label = "Trakt Username", HelpText = "Trakt Username the list belongs to.")]
[FieldDefinition(2, Label = "Trakt Username", HelpText = "Required for User List")]
public string Username { get; set; }
[FieldDefinition(3, Label = "Trakt List Name", HelpText = "Required for Custom List")]
@ -39,4 +37,6 @@ namespace NzbDrone.Core.NetImport.Trakt
}
}

@ -99,6 +99,7 @@
<Reference Include="System.Core" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Web" />
<Reference Include="System.Web.Extensions" />
<Reference Include="System.Windows.Forms" />

Loading…
Cancel
Save