forked from Radarr/Radarr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start adding a Simkl integration. Copied Trakt integration and starte…
…d modifying it...
- Loading branch information
Showing
30 changed files
with
1,387 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ public enum ImportListType | |
Program, | ||
TMDB, | ||
Trakt, | ||
Simkl, | ||
Other, | ||
Advanced | ||
} | ||
|
34 changes: 34 additions & 0 deletions
34
src/NzbDrone.Core/ImportLists/Simkl/List/SimklListImport.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using NLog; | ||
using NzbDrone.Common.Http; | ||
using NzbDrone.Core.Configuration; | ||
using NzbDrone.Core.Notifications.Simkl; | ||
using NzbDrone.Core.Parser; | ||
|
||
namespace NzbDrone.Core.ImportLists.Simkl.List | ||
{ | ||
public class SimklListImport : SimklImportBase<SimklListSettings> | ||
{ | ||
public SimklListImport(IImportListRepository importListRepository, | ||
ISimklProxy simklProxy, | ||
IHttpClient httpClient, | ||
IImportListStatusService importListStatusService, | ||
IConfigService configService, | ||
IParsingService parsingService, | ||
Logger logger) | ||
: base(importListRepository, simklProxy, httpClient, importListStatusService, configService, parsingService, logger) | ||
{ | ||
} | ||
|
||
public override string Name => "Simkl List"; | ||
public override bool Enabled => true; | ||
public override bool EnableAuto => false; | ||
|
||
public override IImportListRequestGenerator GetRequestGenerator() | ||
{ | ||
return new SimklListRequestGenerator(_SimklProxy) | ||
{ | ||
Settings = Settings | ||
}; | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/NzbDrone.Core/ImportLists/Simkl/List/SimklListRequestGenerator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System.Collections.Generic; | ||
using NzbDrone.Common.Http; | ||
using NzbDrone.Core.Notifications.Simkl; | ||
|
||
namespace NzbDrone.Core.ImportLists.Simkl.List | ||
{ | ||
public class SimklListRequestGenerator : IImportListRequestGenerator | ||
{ | ||
private readonly ISimklProxy _simklProxy; | ||
public SimklListSettings Settings { get; set; } | ||
|
||
public SimklListRequestGenerator(ISimklProxy simklProxy) | ||
{ | ||
_simklProxy = simklProxy; | ||
} | ||
|
||
public virtual ImportListPageableRequestChain GetMovies() | ||
{ | ||
var pageableRequests = new ImportListPageableRequestChain(); | ||
|
||
pageableRequests.Add(GetMoviesRequest()); | ||
|
||
return pageableRequests; | ||
} | ||
|
||
private IEnumerable<ImportListRequest> GetMoviesRequest() | ||
{ | ||
var link = string.Empty; | ||
|
||
var listName = Parser.Parser.ToUrlSlug(Settings.Listname.Trim()); | ||
link += $"users/{Settings.Username.Trim()}/lists/{listName}/items/movies?limit={Settings.Limit}"; | ||
|
||
var request = new ImportListRequest(_simklProxy.BuildSimklRequest(link, HttpMethod.GET, Settings.AccessToken)); | ||
|
||
yield return request; | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/NzbDrone.Core/ImportLists/Simkl/List/SimklListSettings.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using FluentValidation; | ||
using NzbDrone.Core.Annotations; | ||
|
||
namespace NzbDrone.Core.ImportLists.Simkl.List | ||
{ | ||
public class SimklListSettingsValidator : SimklSettingsBaseValidator<SimklListSettings> | ||
{ | ||
public SimklListSettingsValidator() | ||
: base() | ||
{ | ||
} | ||
} | ||
|
||
public class SimklListSettings : SimklSettingsBase<SimklListSettings> | ||
{ | ||
protected override AbstractValidator<SimklListSettings> Validator => new SimklListSettingsValidator(); | ||
|
||
public SimklListSettings() | ||
{ | ||
} | ||
|
||
[FieldDefinition(1, Label = "Username", Privacy = PrivacyLevel.UserName, HelpText = "Username for the List to import from")] | ||
public string Username { get; set; } | ||
|
||
[FieldDefinition(2, Label = "List Name", HelpText = "List name for import, list must be public or you must have access to the list")] | ||
public string Listname { get; set; } | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/NzbDrone.Core/ImportLists/Simkl/Popular/SimklPopularImport.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using NLog; | ||
using NzbDrone.Common.Http; | ||
using NzbDrone.Core.Configuration; | ||
using NzbDrone.Core.Notifications.Simkl; | ||
using NzbDrone.Core.Parser; | ||
|
||
namespace NzbDrone.Core.ImportLists.Simkl.Popular | ||
{ | ||
public class SimklPopularImport : SimklImportBase<SimklPopularSettings> | ||
{ | ||
public SimklPopularImport(IImportListRepository importListRepository, | ||
ISimklProxy simklProxy, | ||
IHttpClient httpClient, | ||
IImportListStatusService importListStatusService, | ||
IConfigService configService, | ||
IParsingService parsingService, | ||
Logger logger) | ||
: base(importListRepository, simklProxy, httpClient, importListStatusService, configService, parsingService, logger) | ||
{ | ||
} | ||
|
||
public override string Name => "Simkl Popular List"; | ||
public override bool Enabled => true; | ||
public override bool EnableAuto => false; | ||
|
||
public override IParseImportListResponse GetParser() | ||
{ | ||
return new SimklPopularParser(Settings); | ||
} | ||
|
||
public override IImportListRequestGenerator GetRequestGenerator() | ||
{ | ||
return new SimklPopularRequestGenerator(_SimklProxy) | ||
{ | ||
Settings = Settings | ||
}; | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/NzbDrone.Core/ImportLists/Simkl/Popular/SimklPopularListType.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System.Runtime.Serialization; | ||
|
||
namespace NzbDrone.Core.ImportLists.Simkl.Popular | ||
{ | ||
public enum SimklPopularListType | ||
{ | ||
[EnumMember(Value = "Trending Movies")] | ||
Trending = 0, | ||
[EnumMember(Value = "Popular Movies")] | ||
Popular = 1, | ||
[EnumMember(Value = "Top Anticipated Movies")] | ||
Anticipated = 2, | ||
[EnumMember(Value = "Top Box Office Movies")] | ||
BoxOffice = 3, | ||
|
||
[EnumMember(Value = "Top Watched Movies By Week")] | ||
TopWatchedByWeek = 4, | ||
[EnumMember(Value = "Top Watched Movies By Month")] | ||
TopWatchedByMonth = 5, | ||
[EnumMember(Value = "Top Watched Movies By Year")] | ||
TopWatchedByYear = 6, | ||
[EnumMember(Value = "Top Watched Movies Of All Time")] | ||
TopWatchedByAllTime = 7 | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
src/NzbDrone.Core/ImportLists/Simkl/Popular/SimklPopularParser.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using System.Collections.Generic; | ||
using Newtonsoft.Json; | ||
using NzbDrone.Common.Extensions; | ||
using NzbDrone.Core.ImportLists.ImportListMovies; | ||
using NzbDrone.Core.Notifications.Simkl.Resource; | ||
|
||
namespace NzbDrone.Core.ImportLists.Simkl.Popular | ||
{ | ||
public class SimklPopularParser : SimklParser | ||
{ | ||
private readonly SimklPopularSettings _settings; | ||
private ImportListResponse _importResponse; | ||
|
||
public SimklPopularParser(SimklPopularSettings settings) | ||
{ | ||
_settings = settings; | ||
} | ||
|
||
public override IList<ImportListMovie> ParseResponse(ImportListResponse importResponse) | ||
{ | ||
_importResponse = importResponse; | ||
|
||
var movies = new List<ImportListMovie>(); | ||
|
||
if (!PreProcess(_importResponse)) | ||
{ | ||
return movies; | ||
} | ||
|
||
var jsonResponse = new List<SimklMovieResource>(); | ||
|
||
if (_settings.SimklListType == (int)SimklPopularListType.Popular) | ||
{ | ||
jsonResponse = JsonConvert.DeserializeObject<List<SimklMovieResource>>(_importResponse.Content); | ||
} | ||
else | ||
{ | ||
jsonResponse = JsonConvert.DeserializeObject<List<SimklListResource>>(_importResponse.Content).SelectList(c => c.Movie); | ||
} | ||
|
||
// no movies were return | ||
if (jsonResponse == null) | ||
{ | ||
return movies; | ||
} | ||
|
||
foreach (var movie in jsonResponse) | ||
{ | ||
movies.AddIfNotNull(new ImportListMovie() | ||
{ | ||
Title = movie.Title, | ||
ImdbId = movie.Ids.Imdb, | ||
TmdbId = movie.Ids.Tmdb, | ||
Year = movie.Year ?? 0 | ||
}); | ||
} | ||
|
||
return movies; | ||
} | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
src/NzbDrone.Core/ImportLists/Simkl/Popular/SimklPopularRequestGenerator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using System.Collections.Generic; | ||
using NzbDrone.Common.Http; | ||
using NzbDrone.Core.Notifications.Simkl; | ||
|
||
namespace NzbDrone.Core.ImportLists.Simkl.Popular | ||
{ | ||
public class SimklPopularRequestGenerator : IImportListRequestGenerator | ||
{ | ||
private readonly ISimklProxy _simklProxy; | ||
public SimklPopularSettings Settings { get; set; } | ||
|
||
public SimklPopularRequestGenerator(ISimklProxy simklProxy) | ||
{ | ||
_simklProxy = simklProxy; | ||
} | ||
|
||
public virtual ImportListPageableRequestChain GetMovies() | ||
{ | ||
var pageableRequests = new ImportListPageableRequestChain(); | ||
|
||
pageableRequests.Add(GetMoviesRequest()); | ||
|
||
return pageableRequests; | ||
} | ||
|
||
private IEnumerable<ImportListRequest> GetMoviesRequest() | ||
{ | ||
var link = string.Empty; | ||
|
||
var filtersAndLimit = $"?years={Settings.Years}&genres={Settings.Genres.ToLower()}&ratings={Settings.Rating}&certifications={Settings.Certification.ToLower()}&limit={Settings.Limit}{Settings.SimklAdditionalParameters}"; | ||
|
||
switch (Settings.SimklListType) | ||
{ | ||
case (int)SimklPopularListType.Trending: | ||
link += "movies/trending" + filtersAndLimit; | ||
break; | ||
case (int)SimklPopularListType.Popular: | ||
link += "movies/popular" + filtersAndLimit; | ||
break; | ||
case (int)SimklPopularListType.Anticipated: | ||
link += "movies/anticipated" + filtersAndLimit; | ||
break; | ||
case (int)SimklPopularListType.BoxOffice: | ||
link += "movies/boxoffice" + filtersAndLimit; | ||
break; | ||
case (int)SimklPopularListType.TopWatchedByWeek: | ||
link += "movies/watched/weekly" + filtersAndLimit; | ||
break; | ||
case (int)SimklPopularListType.TopWatchedByMonth: | ||
link += "movies/watched/monthly" + filtersAndLimit; | ||
break; | ||
case (int)SimklPopularListType.TopWatchedByYear: | ||
link += "movies/watched/yearly" + filtersAndLimit; | ||
break; | ||
case (int)SimklPopularListType.TopWatchedByAllTime: | ||
link += "movies/watched/all" + filtersAndLimit; | ||
break; | ||
} | ||
|
||
var request = new ImportListRequest(_simklProxy.BuildSimklRequest(link, HttpMethod.GET, Settings.AccessToken)); | ||
|
||
yield return request; | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/NzbDrone.Core/ImportLists/Simkl/Popular/SimklPopularSettings.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using FluentValidation; | ||
using NzbDrone.Core.Annotations; | ||
|
||
namespace NzbDrone.Core.ImportLists.Simkl.Popular | ||
{ | ||
public class SimklPopularSettingsValidator : SimklSettingsBaseValidator<SimklPopularSettings> | ||
{ | ||
public SimklPopularSettingsValidator() | ||
: base() | ||
{ | ||
RuleFor(c => c.SimklListType).NotNull(); | ||
} | ||
} | ||
|
||
public class SimklPopularSettings : SimklSettingsBase<SimklPopularSettings> | ||
{ | ||
protected override AbstractValidator<SimklPopularSettings> Validator => new SimklPopularSettingsValidator(); | ||
|
||
public SimklPopularSettings() | ||
{ | ||
SimklListType = (int)SimklPopularListType.Popular; | ||
} | ||
|
||
[FieldDefinition(1, Label = "List Type", Type = FieldType.Select, SelectOptions = typeof(SimklPopularListType), HelpText = "Type of list you're seeking to import from")] | ||
public int SimklListType { get; set; } | ||
} | ||
} |
Oops, something went wrong.