|
|
@ -1,52 +1,62 @@
|
|
|
|
using System;
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
using System.Linq;
|
|
|
|
using System.Net;
|
|
|
|
using System.Net;
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
using NzbDrone.Common.Http;
|
|
|
|
using NzbDrone.Common.Http;
|
|
|
|
using NzbDrone.Core.Indexers.Exceptions;
|
|
|
|
using NzbDrone.Core.Indexers.Exceptions;
|
|
|
|
|
|
|
|
using NzbDrone.Core.Parser;
|
|
|
|
using NzbDrone.Core.Parser.Model;
|
|
|
|
using NzbDrone.Core.Parser.Model;
|
|
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Indexers.Definitions.TorrentPotato
|
|
|
|
namespace NzbDrone.Core.Indexers.Definitions.TorrentPotato
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public class TorrentPotatoParser : IParseIndexerResponse
|
|
|
|
public class TorrentPotatoParser : IParseIndexerResponse
|
|
|
|
{
|
|
|
|
{
|
|
|
|
private static readonly Regex RegexGuid = new Regex(@"^magnet:\?xt=urn:btih:([a-f0-9]+)", RegexOptions.Compiled);
|
|
|
|
private static readonly Regex RegexGuid = new (@"^magnet:\?xt=urn:btih:([a-f0-9]+)", RegexOptions.Compiled);
|
|
|
|
|
|
|
|
|
|
|
|
public IList<ReleaseInfo> ParseResponse(IndexerResponse indexerResponse)
|
|
|
|
public IList<ReleaseInfo> ParseResponse(IndexerResponse indexerResponse)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var results = new List<ReleaseInfo>();
|
|
|
|
var releaseInfos = new List<ReleaseInfo>();
|
|
|
|
|
|
|
|
|
|
|
|
switch (indexerResponse.HttpResponse.StatusCode)
|
|
|
|
if (indexerResponse.HttpResponse.StatusCode != HttpStatusCode.OK)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
throw new IndexerException(indexerResponse, "Indexer API call returned an unexpected StatusCode [{0}]", indexerResponse.HttpResponse.StatusCode);
|
|
|
|
if (indexerResponse.HttpResponse.StatusCode != HttpStatusCode.OK)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
throw new IndexerException(indexerResponse, "Indexer API call returned an unexpected StatusCode [{0}]", indexerResponse.HttpResponse.StatusCode);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var jsonResponse = new HttpResponse<TorrentPotatoResponse>(indexerResponse.HttpResponse);
|
|
|
|
var jsonResponse = new HttpResponse<TorrentPotatoResponse>(indexerResponse.HttpResponse);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (jsonResponse.Resource?.error != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
throw new IndexerException(indexerResponse, "Indexer API call returned an error [{0}]", jsonResponse.Resource.error);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (jsonResponse.Resource?.results == null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return releaseInfos;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var torrent in jsonResponse.Resource.results)
|
|
|
|
foreach (var torrent in jsonResponse.Resource.results)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var torrentInfo = new TorrentInfo
|
|
|
|
var torrentInfo = new TorrentInfo
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Guid = GetGuid(torrent),
|
|
|
|
Guid = GetGuid(torrent),
|
|
|
|
Title = torrent.release_name,
|
|
|
|
Title = torrent.release_name,
|
|
|
|
Size = (long)torrent.size * 1000 * 1000,
|
|
|
|
Categories = new List<IndexerCategory> { NewznabStandardCategory.Movies },
|
|
|
|
|
|
|
|
Size = torrent.size * 1000 * 1000,
|
|
|
|
DownloadUrl = torrent.download_url,
|
|
|
|
DownloadUrl = torrent.download_url,
|
|
|
|
InfoUrl = torrent.details_url,
|
|
|
|
InfoUrl = torrent.details_url,
|
|
|
|
|
|
|
|
ImdbId = ParseUtil.GetImdbId(torrent.imdb_id).GetValueOrDefault(),
|
|
|
|
PublishDate = torrent.publish_date.ToUniversalTime(),
|
|
|
|
PublishDate = torrent.publish_date.ToUniversalTime(),
|
|
|
|
Seeders = torrent.seeders,
|
|
|
|
Seeders = torrent.seeders,
|
|
|
|
Peers = torrent.leechers + torrent.seeders
|
|
|
|
Peers = torrent.leechers + torrent.seeders
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
results.Add(torrentInfo);
|
|
|
|
releaseInfos.Add(torrentInfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return results;
|
|
|
|
return releaseInfos
|
|
|
|
|
|
|
|
.OrderByDescending(o => o.PublishDate)
|
|
|
|
|
|
|
|
.ToArray();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Action<IDictionary<string, string>, DateTime?> CookiesUpdater { get; set; }
|
|
|
|
public Action<IDictionary<string, string>, DateTime?> CookiesUpdater { get; set; }
|
|
|
@ -57,12 +67,10 @@ namespace NzbDrone.Core.Indexers.Definitions.TorrentPotato
|
|
|
|
|
|
|
|
|
|
|
|
if (match.Success)
|
|
|
|
if (match.Success)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return string.Format("potato-{0}", match.Groups[1].Value);
|
|
|
|
return $"potato-{match.Groups[1].Value}";
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return string.Format("potato-{0}", torrent.download_url);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $"potato-{torrent.download_url}";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|