Skip to content

Commit

Permalink
exoticaz: rewrite in c# to use the api. resolves #8873 (#8900)
Browse files Browse the repository at this point in the history
  • Loading branch information
ngosang committed Jun 7, 2020
1 parent d490b00 commit 03cc3f4
Show file tree
Hide file tree
Showing 7 changed files with 171 additions and 163 deletions.
89 changes: 0 additions & 89 deletions src/Jackett.Common/Definitions/exoticaz.yml

This file was deleted.

147 changes: 76 additions & 71 deletions src/Jackett.Common/Indexers/Abstract/AvistazTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,79 @@ public abstract class AvistazTracker : BaseWebIndexer
// hook to adjust the search term
protected virtual string GetSearchTerm(TorznabQuery query) => $"{query.SearchTerm} {query.GetEpisodeSearchString()}";

// hook to adjust the search category
protected virtual List<KeyValuePair<string, string>> GetSearchQueryParameters(TorznabQuery query)
{
var categoryMapping = MapTorznabCapsToTrackers(query).Distinct().ToList();
var qc = new List<KeyValuePair<string, string>> // NameValueCollection don't support cat[]=19&cat[]=6
{
{"in", "1"},
{"type", categoryMapping.Any() ? categoryMapping.First() : "0"}
};

// resolution filter to improve the search
if (!query.Categories.Contains(TorznabCatType.Movies.ID) && !query.Categories.Contains(TorznabCatType.TV.ID) &&
!query.Categories.Contains(TorznabCatType.Audio.ID))
{
if (query.Categories.Contains(TorznabCatType.MoviesUHD.ID) || query.Categories.Contains(TorznabCatType.TVUHD.ID))
qc.Add("video_quality[]", "6"); // 2160p
if (query.Categories.Contains(TorznabCatType.MoviesHD.ID) || query.Categories.Contains(TorznabCatType.TVHD.ID))
{
qc.Add("video_quality[]", "2"); // 720p
qc.Add("video_quality[]", "7"); // 1080i
qc.Add("video_quality[]", "3"); // 1080p
}
if (query.Categories.Contains(TorznabCatType.MoviesSD.ID) || query.Categories.Contains(TorznabCatType.TVSD.ID))
qc.Add("video_quality[]", "1"); // SD
}

// note, search by tmdb and tvdb are supported too
// https://privatehd.to/api/v1/jackett/torrents?tmdb=1234
// https://privatehd.to/api/v1/jackett/torrents?tvdb=3653
if (query.IsImdbQuery)
qc.Add("imdb", query.ImdbID);
else
qc.Add("search", GetSearchTerm(query).Trim());

return qc;
}

// hook to adjust category parsing
protected virtual List<int> ParseCategories(TorznabQuery query, JToken row)
{
var cats = new List<int>();
var resolution = row.Value<string>("video_quality");
switch(row.Value<string>("type"))
{
case "Movie":
if (query.Categories.Contains(TorznabCatType.Movies.ID))
cats.Add(TorznabCatType.Movies.ID);
cats.Add(resolution switch
{
var res when _hdResolutions.Contains(res) => TorznabCatType.MoviesHD.ID,
"2160p" => TorznabCatType.MoviesUHD.ID,
_ => TorznabCatType.MoviesSD.ID
});
break;
case "TV-Show":
if (query.Categories.Contains(TorznabCatType.TV.ID))
cats.Add(TorznabCatType.TV.ID);
cats.Add(resolution switch
{
var res when _hdResolutions.Contains(res) => TorznabCatType.TVHD.ID,
"2160p" => TorznabCatType.TVUHD.ID,
_ => TorznabCatType.TVSD.ID
});
break;
case "Music":
cats.Add(TorznabCatType.Audio.ID);
break;
default:
throw new Exception("Error parsing category!");
}
return cats;
}

protected AvistazTracker(string link, string id, string name, string description,
IIndexerConfigurationService configService, WebClient client, Logger logger,
IProtectionService p, TorznabCapabilities caps)
Expand All @@ -51,16 +124,7 @@ public abstract class AvistazTracker : BaseWebIndexer
{
Encoding = Encoding.UTF8;
Language = "en-us";

AddCategoryMapping(1, TorznabCatType.Movies);
AddCategoryMapping(1, TorznabCatType.MoviesUHD);
AddCategoryMapping(1, TorznabCatType.MoviesHD);
AddCategoryMapping(1, TorznabCatType.MoviesSD);
AddCategoryMapping(2, TorznabCatType.TV);
AddCategoryMapping(2, TorznabCatType.TVUHD);
AddCategoryMapping(2, TorznabCatType.TVHD);
AddCategoryMapping(2, TorznabCatType.TVSD);
AddCategoryMapping(3, TorznabCatType.Audio);
Type = "private";
}

public override async Task<IndexerConfigurationStatus> ApplyConfiguration(JToken configJson)
Expand Down Expand Up @@ -95,37 +159,7 @@ protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuer
{
var releases = new List<ReleaseInfo>();

var categoryMapping = MapTorznabCapsToTrackers(query).Distinct().ToList();
var qc = new List<KeyValuePair<string, string>> // NameValueCollection don't support cat[]=19&cat[]=6
{
{"in", "1"},
{"type", categoryMapping.Any() ? categoryMapping.First() : "0"} // type=0 => all categories
};

// resolution filter to improve the search
if (!query.Categories.Contains(TorznabCatType.Movies.ID) && !query.Categories.Contains(TorznabCatType.TV.ID) &&
!query.Categories.Contains(TorznabCatType.Audio.ID))
{
if (query.Categories.Contains(TorznabCatType.MoviesUHD.ID) || query.Categories.Contains(TorznabCatType.TVUHD.ID))
qc.Add("video_quality[]", "6"); // 2160p
if (query.Categories.Contains(TorznabCatType.MoviesHD.ID) || query.Categories.Contains(TorznabCatType.TVHD.ID))
{
qc.Add("video_quality[]", "2"); // 720p
qc.Add("video_quality[]", "7"); // 1080i
qc.Add("video_quality[]", "3"); // 1080p
}
if (query.Categories.Contains(TorznabCatType.MoviesSD.ID) || query.Categories.Contains(TorznabCatType.TVSD.ID))
qc.Add("video_quality[]", "1"); // SD
}

// note, search by tmdb and tvdb are supported too
// https://privatehd.to/api/v1/jackett/torrents?tmdb=1234
// https://privatehd.to/api/v1/jackett/torrents?tvdb=3653
if (query.IsImdbQuery)
qc.Add("imdb", query.ImdbID);
else
qc.Add("search", GetSearchTerm(query).Trim());

var qc = GetSearchQueryParameters(query);
var episodeSearchUrl = SearchUrl + "?" + qc.GetQueryString();
var response = await RequestStringWithCookiesAndRetry(episodeSearchUrl, headers: GetSearchHeaders());
if (response.Status == HttpStatusCode.Unauthorized || response.Status == HttpStatusCode.PreconditionFailed)
Expand Down Expand Up @@ -172,36 +206,7 @@ protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuer
description += $"<br/>Subtitles: {string.Join(", ", subtitleList)}";
}

var cats = new List<int>();
var resolution = row.Value<string>("video_quality");
switch(row.Value<string>("type"))
{
case "Movie":
if (query.Categories.Contains(TorznabCatType.Movies.ID))
cats.Add(TorznabCatType.Movies.ID);
cats.Add(resolution switch
{
var res when _hdResolutions.Contains(res) => TorznabCatType.MoviesHD.ID,
"2160p" => TorznabCatType.MoviesUHD.ID,
_ => TorznabCatType.MoviesSD.ID
});
break;
case "TV-Show":
if (query.Categories.Contains(TorznabCatType.TV.ID))
cats.Add(TorznabCatType.TV.ID);
cats.Add(resolution switch
{
var res when _hdResolutions.Contains(res) => TorznabCatType.TVHD.ID,
"2160p" => TorznabCatType.TVUHD.ID,
_ => TorznabCatType.TVSD.ID
});
break;
case "Music":
cats.Add(TorznabCatType.Audio.ID);
break;
default:
throw new Exception("Error parsing category!");
}
var cats = ParseCategories(query, row);

var release = new ReleaseInfo
{
Expand Down
12 changes: 11 additions & 1 deletion src/Jackett.Common/Indexers/AvistaZ.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,17 @@ public AvistaZ(IIndexerConfigurationService configService, WebClient wc, Logger
client: wc,
logger: l,
p: ps)
=> Type = "private";
{
AddCategoryMapping(1, TorznabCatType.Movies);
AddCategoryMapping(1, TorznabCatType.MoviesUHD);
AddCategoryMapping(1, TorznabCatType.MoviesHD);
AddCategoryMapping(1, TorznabCatType.MoviesSD);
AddCategoryMapping(2, TorznabCatType.TV);
AddCategoryMapping(2, TorznabCatType.TVUHD);
AddCategoryMapping(2, TorznabCatType.TVHD);
AddCategoryMapping(2, TorznabCatType.TVSD);
AddCategoryMapping(3, TorznabCatType.Audio);
}

// Avistaz has episodes without season. eg Running Man E323
protected override string GetSearchTerm(TorznabQuery query) =>
Expand Down
12 changes: 11 additions & 1 deletion src/Jackett.Common/Indexers/CinemaZ.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ public CinemaZ(IIndexerConfigurationService configService, WebClient wc, Logger
client: wc,
logger: l,
p: ps)
=> Type = "private";
{
AddCategoryMapping(1, TorznabCatType.Movies);
AddCategoryMapping(1, TorznabCatType.MoviesUHD);
AddCategoryMapping(1, TorznabCatType.MoviesHD);
AddCategoryMapping(1, TorznabCatType.MoviesSD);
AddCategoryMapping(2, TorznabCatType.TV);
AddCategoryMapping(2, TorznabCatType.TVUHD);
AddCategoryMapping(2, TorznabCatType.TVHD);
AddCategoryMapping(2, TorznabCatType.TVSD);
AddCategoryMapping(3, TorznabCatType.Audio);
}
}
}
61 changes: 61 additions & 0 deletions src/Jackett.Common/Indexers/ExoticaZ.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Jackett.Common.Indexers.Abstract;
using Jackett.Common.Models;
using Jackett.Common.Services.Interfaces;
using Jackett.Common.Utils;
using Jackett.Common.Utils.Clients;
using Newtonsoft.Json.Linq;
using NLog;

namespace Jackett.Common.Indexers
{
[ExcludeFromCodeCoverage]
public class ExoticaZ : AvistazTracker
{
public override string[] LegacySiteLinks { get; protected set; } =
{
"https://torrents.yourexotic.com/"
};

public ExoticaZ(IIndexerConfigurationService configService, WebClient wc, Logger l, IProtectionService ps)
: base(id: "exoticaz",
name: "ExoticaZ",
description: "ExoticaZ (YourExotic) is a Private Torrent Tracker for 3X",
link: "https://exoticaz.to/",
caps: new TorznabCapabilities(),
configService: configService,
client: wc,
logger: l,
p: ps)
{
AddCategoryMapping(1, TorznabCatType.XXXx264);
AddCategoryMapping(2, TorznabCatType.XXXPacks);
AddCategoryMapping(3, TorznabCatType.XXXPacks);
AddCategoryMapping(4, TorznabCatType.XXXPacks);
AddCategoryMapping(5, TorznabCatType.XXXDVD);
AddCategoryMapping(6, TorznabCatType.XXXOther);
AddCategoryMapping(7, TorznabCatType.XXXImageset);
}

protected override List<KeyValuePair<string, string>> GetSearchQueryParameters(TorznabQuery query)
{
var categoryMapping = MapTorznabCapsToTrackers(query).Distinct().ToList();
var qc = new List<KeyValuePair<string, string>> // NameValueCollection don't support cat[]=19&cat[]=6
{
{"in", "1"},
{"category", categoryMapping.Any() ? categoryMapping.First() : "0"},
{"search", GetSearchTerm(query).Trim()}
};

return qc;
}

protected override List<int> ParseCategories(TorznabQuery query, JToken row)
{
var cat = row.Value<JObject>("category").Properties().First().Name;
return MapTrackerCatToNewznab(cat).ToList();
}
}
}
12 changes: 11 additions & 1 deletion src/Jackett.Common/Indexers/PrivateHD.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ public PrivateHD(IIndexerConfigurationService configService, WebClient wc, Logge
client: wc,
logger: l,
p: ps)
=> Type = "private";
{
AddCategoryMapping(1, TorznabCatType.Movies);
AddCategoryMapping(1, TorznabCatType.MoviesUHD);
AddCategoryMapping(1, TorznabCatType.MoviesHD);
AddCategoryMapping(1, TorznabCatType.MoviesSD);
AddCategoryMapping(2, TorznabCatType.TV);
AddCategoryMapping(2, TorznabCatType.TVUHD);
AddCategoryMapping(2, TorznabCatType.TVHD);
AddCategoryMapping(2, TorznabCatType.TVSD);
AddCategoryMapping(3, TorznabCatType.Audio);
}
}
}
1 change: 1 addition & 0 deletions src/Jackett.Updater/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ private void ProcessUpdate(UpdaterConsoleOptions options)
"Definitions/eotforum.yml",
"Definitions/estrenosdtl.yml",
"Definitions/evolutionpalace.yml",
"Definitions/exoticaz.yml", // migrated to C#
"Definitions/extratorrentclone.yml",
"Definitions/feedurneed.yml",
"Definitions/freakstrackingsystem.yml",
Expand Down

0 comments on commit 03cc3f4

Please sign in to comment.