1
0
Fork 0
mirror of https://github.com/Jackett/Jackett synced 2025-03-10 06:03:09 +00:00

torrent-paradise-ml: C# -> yaml

This commit is contained in:
Garfield69 2021-10-25 12:01:14 +13:00
parent 5d00fda03e
commit 5822194133
2 changed files with 58 additions and 159 deletions

View file

@ -0,0 +1,58 @@
---
id: torrent-paradise-ml
name: Torrent Paradise (ML)
description: "The most innovative torrent site"
language: en-US
type: public
encoding: UTF-8
links:
- https://torrent-paradise.ml/
caps:
categorymappings:
- {id: 8000, cat: Other, desc: Other}
modes:
search: [q]
tv-search: [q, season, ep]
movie-search: [q]
music-search: [q]
book-search: [q]
settings: []
search:
paths:
# https://torrent-paradise.ml/api/search?q=2021
- path: api/search
response:
type: json
noResultsMessage: "null"
inputs:
q: "{{ if .Keywords }}{{ .Keywords }}{{ else }}{{ .Today.Year }}{{ end }}"
rows:
selector: $
fields:
category:
text: 8000
title:
selector: text
details:
text: "{{ .Config.sitelink }}"
infohash:
selector: id
date:
text: now
size:
selector: len
seeders:
selector: s
leechers:
selector: l
downloadvolumefactor:
text: 0
uploadvolumefactor:
text: 1
# json engine n/a

View file

@ -1,159 +0,0 @@
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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;
using Newtonsoft.Json.Linq;
using NLog;
namespace Jackett.Common.Indexers
{
public class TorrentParadiseMl : BaseWebIndexer
{
private string ApiUrl => SiteLink + "api/";
public TorrentParadiseMl(IIndexerConfigurationService configService, WebClient wc, Logger l, IProtectionService ps,
ICacheService cs)
: base(id: "torrent-paradise-ml",
name: "Torrent Paradise (ML)",
description: "The most innovative torrent site",
link: "https://torrent-paradise.ml/",
caps: new TorznabCapabilities
{
TvSearchParams = new List<TvSearchParam>
{
TvSearchParam.Q, TvSearchParam.Season, TvSearchParam.Ep
},
MovieSearchParams = new List<MovieSearchParam>
{
MovieSearchParam.Q
},
MusicSearchParams = new List<MusicSearchParam>
{
MusicSearchParam.Q
},
BookSearchParams = new List<BookSearchParam>
{
BookSearchParam.Q
}
},
configService: configService,
client: wc,
logger: l,
p: ps,
cacheService: cs,
configData: new ConfigurationData())
{
Encoding = Encoding.UTF8;
Language = "en-US";
Type = "public";
AddCategoryMapping(8000, TorznabCatType.Other);
}
public override async Task<IndexerConfigurationStatus> ApplyConfiguration(JToken configJson)
{
LoadValuesFromJson(configJson);
var query = new TorznabQuery { IsTest = true };
var releases = await PerformQuery(query);
await ConfigureIfOK(string.Empty, releases.Any(),
() => throw new Exception("Could not find releases from this URL"));
return IndexerConfigurationStatus.Completed;
}
protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuery query)
{
var searchUrl = CreateSearchUrl(query);
if (string.IsNullOrWhiteSpace(searchUrl))
return new List<ReleaseInfo>();
var response = await RequestWithCookiesAndRetryAsync(searchUrl);
try
{
var results = JsonConvert.DeserializeObject<IEnumerable<TorrentParadiseResult>>(response.ContentString);
return results == null ? new List<ReleaseInfo>() : ConvertResultsIntoReleaseInfos(results);
}
catch (Exception ex)
{
throw new Exception("Error while parsing json: " + response.ContentString, ex);
}
}
private string CreateSearchUrl(TorznabQuery query)
{
var searchTerm = query.GetQueryString();
if (string.IsNullOrWhiteSpace(searchTerm))
{
searchTerm = DateTime.Now.Year.ToString();
}
var qc = new NameValueCollection
{
{"q", searchTerm}
};
return ApiUrl + "search?" + qc.GetQueryString();
}
private IEnumerable<ReleaseInfo> ConvertResultsIntoReleaseInfos(IEnumerable<TorrentParadiseResult> results)
{
foreach (var result in results)
{
yield return ConvertResultIntoReleaseInfo(result);
}
}
private ReleaseInfo ConvertResultIntoReleaseInfo(TorrentParadiseResult result)
{
return new ReleaseInfo
{
Title = result.Text,
Size = result.Size,
Seeders = result.Seeders,
Peers = result.Seeders + result.Leechers,
InfoHash = result.Id,
PublishDate = DateTime.Now,
Details = new Uri(SiteLink),
DownloadVolumeFactor = 0,
UploadVolumeFactor = 1,
Category = new List<int> { TorznabCatType.Other.ID }
};
}
private class TorrentParadiseResult
{
[JsonConstructor]
public TorrentParadiseResult(string id, string text, string len, string s, string l)
{
Id = id;
Text = text;
Size = ToLong(len);
Seeders = ToLong(s);
Leechers = ToLong(l);
}
public string Id { get; }
public string Text { get; }
public long? Size { get; }
public long? Seeders { get; }
public long? Leechers { get; }
private long? ToLong(string str) => Convert.ToInt64(str);
}
}
}