2017-09-15 16:57:43 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Collections.Specialized;
|
2020-05-03 23:35:52 +00:00
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2017-09-15 16:57:43 +00:00
|
|
|
using System.Threading.Tasks;
|
2018-03-10 08:05:56 +00:00
|
|
|
using Jackett.Common.Models;
|
|
|
|
using Jackett.Common.Models.IndexerConfig;
|
|
|
|
using Jackett.Common.Services.Interfaces;
|
|
|
|
using Jackett.Common.Utils;
|
|
|
|
using Jackett.Common.Utils.Clients;
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
using NLog;
|
2017-09-15 16:57:43 +00:00
|
|
|
|
2018-03-10 08:05:56 +00:00
|
|
|
namespace Jackett.Common.Indexers.Abstract
|
2017-09-15 16:57:43 +00:00
|
|
|
{
|
2020-05-03 23:35:52 +00:00
|
|
|
[ExcludeFromCodeCoverage]
|
2017-09-15 16:57:43 +00:00
|
|
|
public abstract class CouchPotatoTracker : BaseWebIndexer
|
|
|
|
{
|
|
|
|
protected string endpoint;
|
2020-02-25 16:08:03 +00:00
|
|
|
protected string APIUrl => SiteLink + endpoint;
|
2017-09-15 16:57:43 +00:00
|
|
|
|
2020-02-10 22:16:19 +00:00
|
|
|
private new ConfigurationDataUserPasskey configData
|
2017-09-15 16:57:43 +00:00
|
|
|
{
|
2020-02-25 16:08:03 +00:00
|
|
|
get => (ConfigurationDataUserPasskey)base.configData;
|
|
|
|
set => base.configData = value;
|
2017-09-15 16:57:43 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 19:59:28 +00:00
|
|
|
protected CouchPotatoTracker(string link, string id, string name, string description,
|
|
|
|
IIndexerConfigurationService configService, WebClient client, Logger logger,
|
|
|
|
IProtectionService p, TorznabCapabilities caps, ConfigurationData configData,
|
|
|
|
string endpoint)
|
|
|
|
: base(id: id,
|
|
|
|
name: name,
|
2020-04-04 06:56:51 +00:00
|
|
|
description: description,
|
|
|
|
link: link,
|
|
|
|
caps: caps,
|
|
|
|
configService: configService,
|
|
|
|
client: client,
|
|
|
|
logger: logger,
|
|
|
|
p: p,
|
|
|
|
configData: configData)
|
2017-09-15 16:57:43 +00:00
|
|
|
{
|
|
|
|
this.endpoint = endpoint;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<IndexerConfigurationStatus> ApplyConfiguration(JToken configJson)
|
|
|
|
{
|
|
|
|
LoadValuesFromJson(configJson);
|
|
|
|
IsConfigured = true;
|
|
|
|
SaveConfig();
|
2017-10-29 08:42:25 +00:00
|
|
|
return await Task.FromResult(IndexerConfigurationStatus.RequiresTesting);
|
2017-09-15 16:57:43 +00:00
|
|
|
}
|
|
|
|
|
2020-02-25 16:08:03 +00:00
|
|
|
// can be overriden to alter the search string
|
|
|
|
protected virtual string GetSearchString(TorznabQuery query) => query.GetQueryString();
|
2017-09-19 09:32:12 +00:00
|
|
|
|
2017-09-15 16:57:43 +00:00
|
|
|
protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuery query)
|
|
|
|
{
|
|
|
|
var releases = new List<ReleaseInfo>();
|
2017-09-19 09:32:12 +00:00
|
|
|
var searchString = GetSearchString(query);
|
2017-09-15 16:57:43 +00:00
|
|
|
|
|
|
|
var searchUrl = APIUrl;
|
|
|
|
var queryCollection = new NameValueCollection();
|
2020-02-09 02:35:16 +00:00
|
|
|
|
2017-09-15 16:57:43 +00:00
|
|
|
if (!string.IsNullOrEmpty(query.ImdbID))
|
2020-02-09 02:35:16 +00:00
|
|
|
{
|
2018-08-25 16:53:47 +00:00
|
|
|
queryCollection.Add("imdbid", query.ImdbID);
|
2017-09-15 16:57:43 +00:00
|
|
|
}
|
|
|
|
if (searchString != null)
|
|
|
|
{
|
|
|
|
queryCollection.Add("search", searchString);
|
|
|
|
}
|
|
|
|
queryCollection.Add("passkey", configData.Passkey.Value);
|
|
|
|
queryCollection.Add("user", configData.Username.Value);
|
|
|
|
|
|
|
|
searchUrl += "?" + queryCollection.GetQueryString();
|
|
|
|
|
2020-09-21 06:02:53 +00:00
|
|
|
var response = await RequestStringWithCookiesAndRetry(searchUrl);
|
2017-09-15 16:57:43 +00:00
|
|
|
|
|
|
|
JObject json = null;
|
|
|
|
try
|
|
|
|
{
|
2020-09-21 06:04:26 +00:00
|
|
|
json = JObject.Parse(response.Content);
|
2017-09-15 16:57:43 +00:00
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
2020-09-21 06:04:26 +00:00
|
|
|
throw new Exception("Error while parsing json: " + response.Content, ex);
|
2017-09-15 16:57:43 +00:00
|
|
|
}
|
|
|
|
var error = (string)json["error"];
|
|
|
|
if (error != null)
|
|
|
|
throw new Exception(error);
|
|
|
|
|
2017-09-19 09:32:12 +00:00
|
|
|
if ((int)json["total_results"] == 0)
|
|
|
|
return releases;
|
|
|
|
|
2017-09-15 16:57:43 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
foreach (JObject r in json["results"])
|
|
|
|
{
|
2020-02-25 16:08:03 +00:00
|
|
|
var release = new ReleaseInfo
|
|
|
|
{
|
|
|
|
Title = (string)r["release_name"],
|
|
|
|
Comments = new Uri((string)r["details_url"]),
|
|
|
|
Link = new Uri((string)r["download_url"])
|
|
|
|
};
|
2017-09-15 16:57:43 +00:00
|
|
|
release.Guid = release.Link;
|
|
|
|
release.Imdb = ParseUtil.GetImdbID((string)r["imdb_id"]);
|
|
|
|
var freeleech = (bool)r["freeleech"];
|
|
|
|
if (freeleech)
|
|
|
|
release.DownloadVolumeFactor = 0;
|
|
|
|
else
|
|
|
|
release.DownloadVolumeFactor = 1;
|
|
|
|
release.UploadVolumeFactor = 1;
|
|
|
|
var type = (string)r["type"];
|
|
|
|
release.Category = MapTrackerCatToNewznab(type);
|
|
|
|
release.Size = (long?)r["size"] * 1024 * 1024;
|
|
|
|
release.Seeders = (int?)r["seeders"];
|
|
|
|
release.Peers = release.Seeders + (int?)r["leechers"];
|
|
|
|
release.PublishDate = DateTimeUtil.FromUnknown((string)r["publish_date"]);
|
|
|
|
releases.Add(release);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
2020-09-21 06:04:26 +00:00
|
|
|
OnParseError(response.Content, ex);
|
2017-09-15 16:57:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return releases;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|