From 7e5d5fe29edd67758b98fb449233c3225d11cbe5 Mon Sep 17 00:00:00 2001 From: Qstick Date: Thu, 24 Sep 2020 22:30:20 -0400 Subject: [PATCH] New: Avoid cache on IMDb user lists --- .../RadarrList2/IMDb/IMDbListImport.cs | 2 +- .../RadarrList2/IMDb/IMDbListParser.cs | 54 +++++++++++++++++++ .../IMDb/IMDbListRequestGenerator.cs | 10 +++- .../RadarrList2/RadarrList2Parser.cs | 2 +- .../RadarrList2RequestGenerator.cs | 4 +- 5 files changed, 67 insertions(+), 5 deletions(-) create mode 100644 src/NzbDrone.Core/ImportLists/RadarrList2/IMDb/IMDbListParser.cs 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 @@ public override IImportListRequestGenerator GetRequestGenerator() 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 @@ public class IMDbListRequestGenerator : RadarrList2RequestGeneratorBase 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 @@ public virtual ImportListPageableRequestChain GetMovies() 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;