mirror of
https://github.com/Sonarr/Sonarr.git
synced 2025-04-22 21:37:12 -04:00
parent
11c945c2dc
commit
33da537a63
4 changed files with 0 additions and 160 deletions
|
@ -1,53 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Http;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.Localization;
|
||||
using NzbDrone.Core.Parser;
|
||||
using NzbDrone.Core.ThingiProvider;
|
||||
|
||||
namespace NzbDrone.Core.ImportLists.Imdb
|
||||
{
|
||||
public class ImdbListImport : HttpImportListBase<ImdbListSettings>
|
||||
{
|
||||
public override string Name => _localizationService.GetLocalizedString("TypeOfList", new Dictionary<string, object> { { "typeOfList", "IMDb" } });
|
||||
|
||||
public override ImportListType ListType => ImportListType.Other;
|
||||
public override TimeSpan MinRefreshInterval => TimeSpan.FromHours(12);
|
||||
|
||||
public ImdbListImport(IHttpClient httpClient,
|
||||
IImportListStatusService importListStatusService,
|
||||
IConfigService configService,
|
||||
IParsingService parsingService,
|
||||
ILocalizationService localizationService,
|
||||
Logger logger)
|
||||
: base(httpClient, importListStatusService, configService, parsingService, localizationService, logger)
|
||||
{
|
||||
}
|
||||
|
||||
public override IEnumerable<ProviderDefinition> DefaultDefinitions
|
||||
{
|
||||
get
|
||||
{
|
||||
foreach (var def in base.DefaultDefinitions)
|
||||
{
|
||||
yield return def;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override IImportListRequestGenerator GetRequestGenerator()
|
||||
{
|
||||
return new ImdbListRequestGenerator()
|
||||
{
|
||||
Settings = Settings
|
||||
};
|
||||
}
|
||||
|
||||
public override IParseImportListResponse GetParser()
|
||||
{
|
||||
return new ImdbListParser();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,53 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.ImportLists.Exceptions;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
|
||||
namespace NzbDrone.Core.ImportLists.Imdb
|
||||
{
|
||||
public class ImdbListParser : IParseImportListResponse
|
||||
{
|
||||
public IList<ImportListItemInfo> ParseResponse(ImportListResponse importListResponse)
|
||||
{
|
||||
var importResponse = importListResponse;
|
||||
|
||||
var series = new List<ImportListItemInfo>();
|
||||
|
||||
if (!PreProcess(importResponse))
|
||||
{
|
||||
return series;
|
||||
}
|
||||
|
||||
// Parse TSV response from IMDB export
|
||||
var rows = importResponse.Content.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
series = rows.Skip(1).SelectList(m => m.Split(',')).Where(m => m.Length > 5).SelectList(i => new ImportListItemInfo { ImdbId = i[1], Title = i[5] });
|
||||
|
||||
return series;
|
||||
}
|
||||
|
||||
protected virtual bool PreProcess(ImportListResponse listResponse)
|
||||
{
|
||||
if (listResponse.HttpResponse.StatusCode != HttpStatusCode.OK)
|
||||
{
|
||||
throw new ImportListException(listResponse,
|
||||
"Imdb call resulted in an unexpected StatusCode [{0}]",
|
||||
listResponse.HttpResponse.StatusCode);
|
||||
}
|
||||
|
||||
if (listResponse.HttpResponse.Headers.ContentType != null &&
|
||||
listResponse.HttpResponse.Headers.ContentType.Contains("text/json") &&
|
||||
listResponse.HttpRequest.Headers.Accept != null &&
|
||||
!listResponse.HttpRequest.Headers.Accept.Contains("text/json"))
|
||||
{
|
||||
throw new ImportListException(listResponse,
|
||||
"Imdb responded with html content. Site is likely blocked or unavailable.");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
using System.Collections.Generic;
|
||||
using NzbDrone.Common.Http;
|
||||
|
||||
namespace NzbDrone.Core.ImportLists.Imdb
|
||||
{
|
||||
public class ImdbListRequestGenerator : IImportListRequestGenerator
|
||||
{
|
||||
public ImdbListSettings Settings { get; set; }
|
||||
|
||||
public virtual ImportListPageableRequestChain GetListItems()
|
||||
{
|
||||
var pageableRequests = new ImportListPageableRequestChain();
|
||||
var httpRequest = new HttpRequest($"https://www.imdb.com/list/{Settings.ListId}/export", new HttpAccept("*/*"));
|
||||
var request = new ImportListRequest(httpRequest.Url.ToString(), new HttpAccept(httpRequest.Headers.Accept));
|
||||
|
||||
request.HttpRequest.SuppressHttpError = true;
|
||||
|
||||
pageableRequests.Add(new List<ImportListRequest> { request });
|
||||
|
||||
return pageableRequests;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
using FluentValidation;
|
||||
using NzbDrone.Core.Annotations;
|
||||
using NzbDrone.Core.Validation;
|
||||
|
||||
namespace NzbDrone.Core.ImportLists.Imdb
|
||||
{
|
||||
public class ImdbSettingsValidator : AbstractValidator<ImdbListSettings>
|
||||
{
|
||||
public ImdbSettingsValidator()
|
||||
{
|
||||
RuleFor(c => c.ListId)
|
||||
.Matches(@"^ls\d+$")
|
||||
.WithMessage("List ID mist be an IMDb List ID of the form 'ls12345678'");
|
||||
}
|
||||
}
|
||||
|
||||
public class ImdbListSettings : ImportListSettingsBase<ImdbListSettings>
|
||||
{
|
||||
private static readonly ImdbSettingsValidator Validator = new ();
|
||||
|
||||
public override string BaseUrl { get; set; }
|
||||
|
||||
[FieldDefinition(1, Label = "ImportListsImdbSettingsListId", HelpText = "ImportListsImdbSettingsListIdHelpText")]
|
||||
public string ListId { get; set; }
|
||||
|
||||
public override NzbDroneValidationResult Validate()
|
||||
{
|
||||
return new NzbDroneValidationResult(Validator.Validate(this));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue