diff --git a/src/NzbDrone.Core/ImportLists/RadarrList2/IMDb/IMDbListImport.cs b/src/NzbDrone.Core/ImportLists/RadarrList2/IMDb/IMDbListImport.cs index 14d437d78..813e532d4 100644 --- a/src/NzbDrone.Core/ImportLists/RadarrList2/IMDb/IMDbListImport.cs +++ b/src/NzbDrone.Core/ImportLists/RadarrList2/IMDb/IMDbListImport.cs @@ -72,7 +72,7 @@ namespace NzbDrone.Core.ImportLists.RadarrList2.IMDbList public override IParseImportListResponse GetParser() { - return new RadarrList2Parser(); + return new IMDbListParser(Settings); } } } diff --git a/src/NzbDrone.Core/ImportLists/RadarrList2/IMDb/IMDbListParser.cs b/src/NzbDrone.Core/ImportLists/RadarrList2/IMDb/IMDbListParser.cs new file mode 100644 index 000000000..22c39f152 --- /dev/null +++ b/src/NzbDrone.Core/ImportLists/RadarrList2/IMDb/IMDbListParser.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Newtonsoft.Json; +using NzbDrone.Common.Extensions; +using NzbDrone.Core.ImportLists.ImportListMovies; +using NzbDrone.Core.MetadataSource.SkyHook.Resource; + +namespace NzbDrone.Core.ImportLists.RadarrList2.IMDbList +{ + public class IMDbListParser : RadarrList2Parser + { + private readonly IMDbListSettings _settings; + + public IMDbListParser(IMDbListSettings settings) + : base() + { + _settings = settings; + } + + public override IList ParseResponse(ImportListResponse importListResponse) + { + var importResponse = importListResponse; + + var movies = new List(); + + if (!PreProcess(importResponse)) + { + return movies; + } + + if (_settings.ListId.StartsWith("ls", StringComparison.OrdinalIgnoreCase)) + { + //Parse TSV response from IMDB export + var row = importResponse.Content.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); + + movies = row.Skip(1).SelectList(m => new ImportListMovie { ImdbId = m.Split(',')[1] }); + + return movies; + } + else + { + var jsonResponse = JsonConvert.DeserializeObject>(importResponse.Content); + + if (jsonResponse == null) + { + return movies; + } + + return jsonResponse.SelectList(m => new ImportListMovie { TmdbId = m.TmdbId }); + } + } + } +} diff --git a/src/NzbDrone.Core/ImportLists/RadarrList2/IMDb/IMDbListRequestGenerator.cs b/src/NzbDrone.Core/ImportLists/RadarrList2/IMDb/IMDbListRequestGenerator.cs index bfdb27487..17e9e2a49 100644 --- a/src/NzbDrone.Core/ImportLists/RadarrList2/IMDb/IMDbListRequestGenerator.cs +++ b/src/NzbDrone.Core/ImportLists/RadarrList2/IMDb/IMDbListRequestGenerator.cs @@ -1,4 +1,5 @@ -using NzbDrone.Common.Http; +using System; +using NzbDrone.Common.Http; namespace NzbDrone.Core.ImportLists.RadarrList2.IMDbList { @@ -8,8 +9,15 @@ namespace NzbDrone.Core.ImportLists.RadarrList2.IMDbList protected override HttpRequest GetHttpRequest() { + //Use IMDb list Export for user lists to bypass RadarrAPI caching + if (Settings.ListId.StartsWith("ls", StringComparison.OrdinalIgnoreCase)) + { + return new HttpRequest($"https://www.imdb.com/list/{Settings.ListId}/export", new HttpAccept("*/*")); + } + return RequestBuilder.Create() .SetSegment("route", $"list/imdb/{Settings.ListId}") + .Accept(HttpAccept.Json) .Build(); } } diff --git a/src/NzbDrone.Core/ImportLists/RadarrList2/RadarrList2Parser.cs b/src/NzbDrone.Core/ImportLists/RadarrList2/RadarrList2Parser.cs index 9ce49a558..15b7f7a46 100644 --- a/src/NzbDrone.Core/ImportLists/RadarrList2/RadarrList2Parser.cs +++ b/src/NzbDrone.Core/ImportLists/RadarrList2/RadarrList2Parser.cs @@ -10,7 +10,7 @@ namespace NzbDrone.Core.ImportLists.RadarrList2 { public class RadarrList2Parser : IParseImportListResponse { - public IList ParseResponse(ImportListResponse importListResponse) + public virtual IList ParseResponse(ImportListResponse importListResponse) { var importResponse = importListResponse; diff --git a/src/NzbDrone.Core/ImportLists/RadarrList2/RadarrList2RequestGenerator.cs b/src/NzbDrone.Core/ImportLists/RadarrList2/RadarrList2RequestGenerator.cs index ea0ca7320..d464d3458 100644 --- a/src/NzbDrone.Core/ImportLists/RadarrList2/RadarrList2RequestGenerator.cs +++ b/src/NzbDrone.Core/ImportLists/RadarrList2/RadarrList2RequestGenerator.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using NLog; using NzbDrone.Common.Http; @@ -18,7 +18,7 @@ namespace NzbDrone.Core.ImportLists.RadarrList2 var httpRequest = GetHttpRequest(); - var request = new ImportListRequest(httpRequest.Url.ToString(), HttpAccept.Json); + var request = new ImportListRequest(httpRequest.Url.ToString(), new HttpAccept(httpRequest.Headers.Accept)); request.HttpRequest.SuppressHttpError = true;