2020-02-09 02:35:16 +00:00
|
|
|
using System;
|
2018-05-12 01:55:24 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Globalization;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Text;
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
using System.Threading.Tasks;
|
2019-01-20 00:09:27 +00:00
|
|
|
using AngleSharp.Html.Parser;
|
2018-05-12 01:55:24 +00:00
|
|
|
using Jackett.Common.Models;
|
|
|
|
using Jackett.Common.Models.IndexerConfig;
|
|
|
|
using Jackett.Common.Services.Interfaces;
|
|
|
|
using Jackett.Common.Utils.Clients;
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
using NLog;
|
|
|
|
using static Jackett.Common.Models.IndexerConfig.ConfigurationData;
|
|
|
|
|
|
|
|
namespace Jackett.Common.Indexers
|
|
|
|
{
|
|
|
|
public class Newpct : BaseCachingWebIndexer
|
|
|
|
{
|
2020-02-10 22:16:19 +00:00
|
|
|
private enum ReleaseType
|
2018-05-12 01:55:24 +00:00
|
|
|
{
|
2020-03-29 20:40:31 +00:00
|
|
|
Tv,
|
2018-05-12 01:55:24 +00:00
|
|
|
Movie,
|
|
|
|
}
|
|
|
|
|
2020-02-10 22:16:19 +00:00
|
|
|
private class NewpctRelease : ReleaseInfo
|
2018-05-12 01:55:24 +00:00
|
|
|
{
|
2018-08-29 09:21:07 +00:00
|
|
|
public ReleaseType NewpctReleaseType;
|
|
|
|
public string SeriesName;
|
2018-05-12 01:55:24 +00:00
|
|
|
public int? Season;
|
|
|
|
public int? Episode;
|
|
|
|
public int? EpisodeTo;
|
2018-11-19 10:50:24 +00:00
|
|
|
public int Score;
|
2018-08-29 09:21:07 +00:00
|
|
|
|
|
|
|
public NewpctRelease()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-11-19 10:50:24 +00:00
|
|
|
public NewpctRelease(NewpctRelease copyFrom) :
|
2018-08-29 09:21:07 +00:00
|
|
|
base(copyFrom)
|
|
|
|
{
|
|
|
|
NewpctReleaseType = copyFrom.NewpctReleaseType;
|
|
|
|
SeriesName = copyFrom.SeriesName;
|
|
|
|
Season = copyFrom.Season;
|
|
|
|
Episode = copyFrom.Episode;
|
|
|
|
EpisodeTo = copyFrom.EpisodeTo;
|
2018-11-19 10:50:24 +00:00
|
|
|
Score = copyFrom.Score;
|
2018-08-29 09:21:07 +00:00
|
|
|
}
|
|
|
|
|
2020-02-25 16:08:03 +00:00
|
|
|
public override object Clone() => new NewpctRelease(this);
|
2018-05-12 01:55:24 +00:00
|
|
|
}
|
|
|
|
|
2020-02-10 22:16:19 +00:00
|
|
|
private class DownloadMatcher
|
2019-06-13 22:41:34 +00:00
|
|
|
{
|
|
|
|
public Regex MatchRegex;
|
|
|
|
public MatchEvaluator MatchEvaluator;
|
|
|
|
}
|
|
|
|
|
2020-02-10 22:16:19 +00:00
|
|
|
private readonly char[] _wordSeparators = new char[] { ' ', '.', ',', ';', '(', ')', '[', ']', '-', '_' };
|
|
|
|
private readonly int _wordNotFoundScore = 100000;
|
|
|
|
private readonly Regex _searchStringRegex = new Regex(@"(.+?)S0?(\d+)(E0?(\d+))?$", RegexOptions.IgnoreCase);
|
|
|
|
private readonly Regex _titleListRegex = new Regex(@"Serie( *Descargar)?(.+?)(Temporada(.+?)(\d+)(.+?))?Capitulos?(.+?)(\d+)((.+?)(\d+))?(.+?)-(.+?)Calidad(.*)", RegexOptions.IgnoreCase);
|
|
|
|
private readonly Regex _titleClassicRegex = new Regex(@"(\[[^\]]*\])?\[Cap\.(\d{1,2})(\d{2})([_-](\d{1,2})(\d{2}))?\]", RegexOptions.IgnoreCase);
|
|
|
|
private readonly Regex _titleClassicTvQualityRegex = new Regex(@"\[([^\]]*HDTV[^\]]*)", RegexOptions.IgnoreCase);
|
2020-03-10 02:53:57 +00:00
|
|
|
private readonly Regex _titleYearRegex = new Regex(@"[\[\(] *(\d{4}) *[\]\)]");
|
2020-02-10 22:16:19 +00:00
|
|
|
private readonly DownloadMatcher[] _downloadMatchers = new DownloadMatcher[]
|
2019-06-13 22:41:34 +00:00
|
|
|
{
|
2020-01-12 03:25:26 +00:00
|
|
|
new DownloadMatcher()
|
|
|
|
{
|
|
|
|
MatchRegex = new Regex("(/descargar-torrent/[^\"]+)\"")
|
|
|
|
},
|
2019-06-13 22:41:34 +00:00
|
|
|
new DownloadMatcher()
|
|
|
|
{
|
|
|
|
MatchRegex = new Regex(@"nalt\s*=\s*'([^\/]*)"),
|
|
|
|
MatchEvaluator = m => string.Format("/download/{0}.torrent", m.Groups[1])
|
|
|
|
},
|
|
|
|
};
|
2018-05-12 01:55:24 +00:00
|
|
|
|
2020-03-29 20:40:31 +00:00
|
|
|
private readonly int _maxDailyPages = 4;
|
|
|
|
private readonly int _maxMoviesPages = 10;
|
2020-02-10 22:16:19 +00:00
|
|
|
private readonly int[] _allTvCategories = (new TorznabCategory[] { TorznabCatType.TV }).Concat(TorznabCatType.TV.SubCategories).Select(c => c.ID).ToArray();
|
|
|
|
private readonly int[] _allMoviesCategories = (new TorznabCategory[] { TorznabCatType.Movies }).Concat(TorznabCatType.Movies.SubCategories).Select(c => c.ID).ToArray();
|
2020-03-10 02:53:57 +00:00
|
|
|
private readonly int _firstYearAllowed = 1885;
|
|
|
|
private readonly int _lastYearAllowedFromNow = 3;
|
2018-05-12 01:55:24 +00:00
|
|
|
|
2018-10-20 05:48:53 +00:00
|
|
|
private bool _includeVo;
|
2018-11-19 10:50:24 +00:00
|
|
|
private bool _filterMovies;
|
2019-08-18 20:53:14 +00:00
|
|
|
private bool _removeMovieAccents;
|
2020-03-10 02:53:57 +00:00
|
|
|
private bool _removeMovieYear;
|
2018-08-29 09:21:07 +00:00
|
|
|
private DateTime _dailyNow;
|
|
|
|
private int _dailyResultIdx;
|
|
|
|
|
2020-03-29 20:40:31 +00:00
|
|
|
private readonly string _searchJsonUrl = "get/result/";
|
|
|
|
private readonly string _dailyUrl = "ultimas-descargas/pg/{0}";
|
|
|
|
private readonly string[] _seriesLetterUrls = { "series/letter/{0}", "series-hd/letter/{0}" };
|
|
|
|
private readonly string[] _seriesVoLetterUrls = { "series-vo/letter/{0}" };
|
|
|
|
private readonly string[] _voUrls = { "serie-vo", "serievo" };
|
2018-05-12 01:55:24 +00:00
|
|
|
|
2020-03-29 20:40:31 +00:00
|
|
|
public override string[] AlternativeSiteLinks { get; protected set; } = {
|
|
|
|
"https://descargas2020.org/",
|
|
|
|
"https://pctnew.org/",
|
|
|
|
"https://pctreload.com/"
|
|
|
|
};
|
|
|
|
|
|
|
|
public override string[] LegacySiteLinks { get; protected set; } = {
|
|
|
|
"http://descargas2020.com/",
|
|
|
|
"http://www.tvsinpagar.com/",
|
|
|
|
"http://torrentlocura.com/",
|
|
|
|
"https://pctnew.site",
|
|
|
|
"https://descargas2020.site",
|
|
|
|
"http://torrentrapid.com/",
|
|
|
|
"http://tumejortorrent.com/",
|
|
|
|
"http://pctnew.com/",
|
|
|
|
};
|
2018-12-16 00:40:40 +00:00
|
|
|
|
2018-05-12 01:55:24 +00:00
|
|
|
public Newpct(IIndexerConfigurationService configService, WebClient wc, Logger l, IProtectionService ps)
|
2020-03-29 20:40:31 +00:00
|
|
|
: base("Newpct",
|
|
|
|
description: "Newpct - Descargar peliculas, series y estrenos torrent gratis",
|
|
|
|
link: "https://descargas2020.org/",
|
2018-05-12 01:55:24 +00:00
|
|
|
caps: new TorznabCapabilities(TorznabCatType.TV,
|
|
|
|
TorznabCatType.TVSD,
|
|
|
|
TorznabCatType.TVHD,
|
|
|
|
TorznabCatType.Movies),
|
|
|
|
configService: configService,
|
|
|
|
client: wc,
|
|
|
|
logger: l,
|
|
|
|
p: ps,
|
|
|
|
configData: new ConfigurationData())
|
|
|
|
{
|
|
|
|
Encoding = Encoding.GetEncoding("windows-1252");
|
|
|
|
Language = "es-es";
|
|
|
|
Type = "public";
|
|
|
|
|
|
|
|
var voItem = new BoolItem() { Name = "Include original versions in search results", Value = false };
|
|
|
|
configData.AddDynamic("IncludeVo", voItem);
|
2018-11-19 10:50:24 +00:00
|
|
|
|
|
|
|
var filterMoviesItem = new BoolItem() { Name = "Only full match movies", Value = true };
|
|
|
|
configData.AddDynamic("FilterMovies", filterMoviesItem);
|
2019-08-18 20:53:14 +00:00
|
|
|
|
2020-03-29 20:40:31 +00:00
|
|
|
var removeMovieAccentsItem = new BoolItem() { Name = "Remove accents in movie searches", Value = true };
|
2019-08-18 20:53:14 +00:00
|
|
|
configData.AddDynamic("RemoveMovieAccents", removeMovieAccentsItem);
|
2020-03-10 02:53:57 +00:00
|
|
|
|
|
|
|
var removeMovieYearItem = new BoolItem() { Name = "Remove year from movie results", Value = false };
|
|
|
|
configData.AddDynamic("RemoveMovieYear", removeMovieYearItem);
|
2018-05-12 01:55:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<IndexerConfigurationStatus> ApplyConfiguration(JToken configJson)
|
|
|
|
{
|
|
|
|
configData.LoadValuesFromJson(configJson);
|
2020-03-29 20:40:31 +00:00
|
|
|
|
|
|
|
// TODO: must be a simpler way to set the configured SiteLink
|
|
|
|
SiteLink = configData.SiteLink.Value;
|
|
|
|
|
2018-05-12 01:55:24 +00:00
|
|
|
var releases = await PerformQuery(new TorznabQuery());
|
|
|
|
|
2020-02-25 16:08:03 +00:00
|
|
|
await ConfigureIfOK(string.Empty, releases.Any(), () =>
|
|
|
|
throw new Exception("Could not find releases from this URL"));
|
2018-05-12 01:55:24 +00:00
|
|
|
|
|
|
|
return IndexerConfigurationStatus.Completed;
|
|
|
|
}
|
|
|
|
|
2018-12-14 21:56:33 +00:00
|
|
|
public override async Task<byte[]> Download(Uri linkParam)
|
2018-05-12 01:55:24 +00:00
|
|
|
{
|
2020-03-29 20:40:31 +00:00
|
|
|
var results = await RequestStringWithCookiesAndRetry(linkParam.AbsoluteUri);
|
2018-12-14 21:56:33 +00:00
|
|
|
|
2020-03-29 20:40:31 +00:00
|
|
|
var uriLink = ExtractDownloadUri(results.Content, linkParam.AbsoluteUri);
|
|
|
|
if (uriLink == null)
|
|
|
|
throw new Exception("Download link not found!");
|
2018-12-14 21:56:33 +00:00
|
|
|
|
2020-03-29 20:40:31 +00:00
|
|
|
return await base.Download(uriLink);
|
2018-05-12 01:55:24 +00:00
|
|
|
}
|
|
|
|
|
2019-06-13 22:41:34 +00:00
|
|
|
private Uri ExtractDownloadUri(string content, string baseLink)
|
|
|
|
{
|
2020-02-10 22:16:19 +00:00
|
|
|
foreach (var matcher in _downloadMatchers)
|
2019-06-13 22:41:34 +00:00
|
|
|
{
|
2020-02-10 22:16:19 +00:00
|
|
|
var match = matcher.MatchRegex.Match(content);
|
2019-06-13 22:41:34 +00:00
|
|
|
if (match.Success)
|
|
|
|
{
|
2019-12-09 23:25:25 +00:00
|
|
|
string linkText;
|
|
|
|
|
2019-06-13 22:41:34 +00:00
|
|
|
if (matcher.MatchEvaluator != null)
|
|
|
|
linkText = (string)matcher.MatchEvaluator.DynamicInvoke(match);
|
|
|
|
else
|
|
|
|
linkText = match.Groups[1].Value;
|
|
|
|
|
|
|
|
return new Uri(new Uri(baseLink), linkText);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-03-29 20:40:31 +00:00
|
|
|
protected override async Task<IEnumerable<ReleaseInfo>> PerformQuery(TorznabQuery query)
|
2018-05-12 01:55:24 +00:00
|
|
|
{
|
|
|
|
var releases = new List<ReleaseInfo>();
|
|
|
|
|
2018-10-20 05:48:53 +00:00
|
|
|
_includeVo = ((BoolItem)configData.GetDynamic("IncludeVo")).Value;
|
2018-11-19 10:50:24 +00:00
|
|
|
_filterMovies = ((BoolItem)configData.GetDynamic("FilterMovies")).Value;
|
2019-08-18 20:53:14 +00:00
|
|
|
_removeMovieAccents = ((BoolItem)configData.GetDynamic("RemoveMovieAccents")).Value;
|
2020-03-10 02:53:57 +00:00
|
|
|
_removeMovieYear = ((BoolItem)configData.GetDynamic("RemoveMovieYear")).Value;
|
2018-08-29 09:21:07 +00:00
|
|
|
_dailyNow = DateTime.Now;
|
|
|
|
_dailyResultIdx = 0;
|
2020-02-10 22:16:19 +00:00
|
|
|
var rssMode = string.IsNullOrEmpty(query.SanitizedSearchTerm);
|
2018-05-12 01:55:24 +00:00
|
|
|
|
|
|
|
if (rssMode)
|
|
|
|
{
|
2020-02-10 22:16:19 +00:00
|
|
|
var pg = 1;
|
2018-05-12 01:55:24 +00:00
|
|
|
while (pg <= _maxDailyPages)
|
|
|
|
{
|
2020-03-29 20:40:31 +00:00
|
|
|
var pageUrl = SiteLink + string.Format(_dailyUrl, pg);
|
|
|
|
var results = await RequestStringWithCookiesAndRetry(pageUrl);
|
|
|
|
if (results == null || string.IsNullOrEmpty(results.Content))
|
|
|
|
break;
|
2018-05-12 01:55:24 +00:00
|
|
|
|
2020-03-29 20:40:31 +00:00
|
|
|
var items = ParseDailyContent(results.Content);
|
2018-05-12 01:55:24 +00:00
|
|
|
if (items == null || !items.Any())
|
|
|
|
break;
|
|
|
|
|
|
|
|
releases.AddRange(items);
|
|
|
|
pg++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-02-10 22:16:19 +00:00
|
|
|
var isTvSearch = query.Categories == null || query.Categories.Length == 0 ||
|
2018-05-12 01:55:24 +00:00
|
|
|
query.Categories.Any(c => _allTvCategories.Contains(c));
|
|
|
|
if (isTvSearch)
|
2020-03-29 20:40:31 +00:00
|
|
|
releases.AddRange(await TvSearch(query));
|
2018-11-19 10:50:24 +00:00
|
|
|
|
2020-02-10 22:16:19 +00:00
|
|
|
var isMovieSearch = query.Categories == null || query.Categories.Length == 0 ||
|
2018-11-19 10:50:24 +00:00
|
|
|
query.Categories.Any(c => _allMoviesCategories.Contains(c));
|
|
|
|
if (isMovieSearch)
|
2020-03-29 20:40:31 +00:00
|
|
|
releases.AddRange(await MovieSearch(query));
|
|
|
|
|
2018-07-03 12:29:06 +00:00
|
|
|
}
|
2018-05-12 01:55:24 +00:00
|
|
|
|
2020-02-08 01:49:33 +00:00
|
|
|
// Database lost on 2018/04/05, all previous torrents don't have download links
|
|
|
|
var failureDay = new DateTime(2018, 04, 05);
|
|
|
|
releases = releases.Where(r => r.PublishDate > failureDay).ToList();
|
|
|
|
|
2018-07-03 12:29:06 +00:00
|
|
|
return releases;
|
|
|
|
}
|
2018-05-12 01:55:24 +00:00
|
|
|
|
2020-03-29 20:40:31 +00:00
|
|
|
private async Task<IEnumerable<ReleaseInfo>> TvSearch(TorznabQuery query)
|
2018-07-03 12:29:06 +00:00
|
|
|
{
|
2020-02-10 22:16:19 +00:00
|
|
|
var seriesName = query.SanitizedSearchTerm;
|
|
|
|
var season = query.Season > 0 ? (int?)query.Season : null;
|
2018-07-03 12:29:06 +00:00
|
|
|
int? episode = null;
|
2020-02-10 22:16:19 +00:00
|
|
|
if (!string.IsNullOrWhiteSpace(query.Episode) && int.TryParse(query.Episode, out var episodeTemp))
|
2018-07-03 12:29:06 +00:00
|
|
|
episode = episodeTemp;
|
|
|
|
|
|
|
|
//If query has no season/episode info, try to parse title
|
|
|
|
if (season == null && episode == null)
|
|
|
|
{
|
2020-02-10 22:16:19 +00:00
|
|
|
var searchMatch = _searchStringRegex.Match(query.SanitizedSearchTerm);
|
2018-07-03 12:29:06 +00:00
|
|
|
if (searchMatch.Success)
|
|
|
|
{
|
|
|
|
seriesName = searchMatch.Groups[1].Value.Trim();
|
|
|
|
season = int.Parse(searchMatch.Groups[2].Value);
|
|
|
|
episode = searchMatch.Groups[4].Success ? (int?)int.Parse(searchMatch.Groups[4].Value) : null;
|
|
|
|
}
|
|
|
|
}
|
2018-05-12 01:55:24 +00:00
|
|
|
|
2020-03-29 20:40:31 +00:00
|
|
|
var releases = new List<ReleaseInfo>();
|
2018-07-03 12:29:06 +00:00
|
|
|
|
2020-03-29 20:40:31 +00:00
|
|
|
//Search series url
|
|
|
|
foreach (var seriesListUrl in SeriesListUris(seriesName))
|
|
|
|
releases.AddRange(await GetReleasesFromUri(seriesListUrl, seriesName));
|
2018-05-12 01:55:24 +00:00
|
|
|
|
2020-03-29 20:40:31 +00:00
|
|
|
//Sonarr removes "the" from shows. If there is nothing try prepending "the"
|
|
|
|
if (releases.Count == 0 && !(seriesName.ToLower().StartsWith("the")))
|
|
|
|
{
|
|
|
|
seriesName = "The " + seriesName;
|
|
|
|
foreach (var seriesListUrl in SeriesListUris(seriesName))
|
|
|
|
releases.AddRange(await GetReleasesFromUri(seriesListUrl, seriesName));
|
2018-05-12 01:55:24 +00:00
|
|
|
}
|
|
|
|
|
2020-01-12 03:25:26 +00:00
|
|
|
// remove duplicates
|
2020-03-29 20:40:31 +00:00
|
|
|
releases = releases.GroupBy(x => x.Guid).Select(y => y.First()).ToList();
|
2020-01-12 03:25:26 +00:00
|
|
|
|
2018-07-03 12:29:06 +00:00
|
|
|
//Filter only episodes needed
|
2020-03-29 20:40:31 +00:00
|
|
|
return releases.Where(r =>
|
2018-07-03 12:29:06 +00:00
|
|
|
{
|
2020-02-10 22:16:19 +00:00
|
|
|
var nr = r as NewpctRelease;
|
2018-10-20 05:48:53 +00:00
|
|
|
return (
|
|
|
|
nr.Season.HasValue != season.HasValue || //Can't determine if same season
|
2018-07-03 12:29:06 +00:00
|
|
|
nr.Season.HasValue && season.Value == nr.Season.Value && //Same season and ...
|
|
|
|
(
|
|
|
|
nr.Episode.HasValue != episode.HasValue || //Can't determine if same episode
|
|
|
|
nr.Episode.HasValue &&
|
|
|
|
(
|
|
|
|
nr.Episode.Value == episode.Value || //Same episode
|
|
|
|
nr.EpisodeTo.HasValue && episode.Value >= nr.Episode.Value && episode.Value <= nr.EpisodeTo.Value //Episode in interval
|
|
|
|
)
|
2018-10-20 05:48:53 +00:00
|
|
|
)
|
|
|
|
);
|
2018-07-03 12:29:06 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private async Task<IEnumerable<ReleaseInfo>> GetReleasesFromUri(Uri uri, string seriesName)
|
|
|
|
{
|
2020-03-29 20:40:31 +00:00
|
|
|
var releases = new List<ReleaseInfo>();
|
2018-07-03 12:29:06 +00:00
|
|
|
|
2020-03-29 20:40:31 +00:00
|
|
|
// Episodes list
|
|
|
|
var results = await RequestStringWithCookiesAndRetry(uri.AbsoluteUri);
|
2020-02-10 22:16:19 +00:00
|
|
|
var seriesEpisodesUrl = ParseSeriesListContent(results.Content, seriesName);
|
2020-03-29 20:40:31 +00:00
|
|
|
|
|
|
|
// TV serie list
|
2018-07-03 12:29:06 +00:00
|
|
|
if (!string.IsNullOrEmpty(seriesEpisodesUrl))
|
|
|
|
{
|
2020-03-29 20:40:31 +00:00
|
|
|
results = await RequestStringWithCookiesAndRetry(seriesEpisodesUrl);
|
|
|
|
var items = ParseEpisodesListContent(results.Content);
|
|
|
|
if (items != null && items.Any())
|
2020-04-07 16:17:17 +00:00
|
|
|
releases.AddRange(items);
|
2018-07-03 12:29:06 +00:00
|
|
|
}
|
2020-03-29 20:40:31 +00:00
|
|
|
return releases;
|
2018-07-03 12:29:06 +00:00
|
|
|
}
|
|
|
|
|
2020-03-29 20:40:31 +00:00
|
|
|
private IEnumerable<Uri> SeriesListUris(string seriesName)
|
2018-07-03 12:29:06 +00:00
|
|
|
{
|
|
|
|
IEnumerable<string> lettersUrl;
|
2018-10-20 05:48:53 +00:00
|
|
|
if (!_includeVo)
|
2018-07-03 12:29:06 +00:00
|
|
|
lettersUrl = _seriesLetterUrls;
|
|
|
|
else
|
2020-03-29 20:40:31 +00:00
|
|
|
lettersUrl = _seriesLetterUrls.Concat(_seriesVoLetterUrls);
|
2020-02-10 22:16:19 +00:00
|
|
|
var seriesLetter = !char.IsDigit(seriesName[0]) ? seriesName[0].ToString() : "0-9";
|
2020-03-29 20:40:31 +00:00
|
|
|
return lettersUrl.Select(
|
|
|
|
urlFormat => new Uri(SiteLink + string.Format(urlFormat, seriesLetter.ToLower())));
|
2018-05-12 01:55:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private IEnumerable<NewpctRelease> ParseDailyContent(string content)
|
|
|
|
{
|
2020-03-29 20:40:31 +00:00
|
|
|
var parser = new HtmlParser();
|
|
|
|
var doc = parser.ParseDocument(content);
|
2018-05-12 01:55:24 +00:00
|
|
|
|
2020-02-10 22:16:19 +00:00
|
|
|
var releases = new List<NewpctRelease>();
|
2018-05-12 01:55:24 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
var rows = doc.QuerySelectorAll(".content .info");
|
|
|
|
foreach (var row in rows)
|
|
|
|
{
|
|
|
|
var anchor = row.QuerySelector("a");
|
2018-08-29 09:21:07 +00:00
|
|
|
var title = Regex.Replace(anchor.TextContent, @"\s+", " ").Trim();
|
|
|
|
var title2 = Regex.Replace(anchor.GetAttribute("title"), @"\s+", " ").Trim();
|
|
|
|
if (title2.Length >= title.Length)
|
|
|
|
title = title2;
|
|
|
|
|
2018-05-12 01:55:24 +00:00
|
|
|
var detailsUrl = anchor.GetAttribute("href");
|
2018-10-20 05:48:53 +00:00
|
|
|
if (!_includeVo && _voUrls.Any(vo => detailsUrl.ToLower().Contains(vo.ToLower())))
|
|
|
|
continue;
|
2018-05-12 01:55:24 +00:00
|
|
|
|
|
|
|
var span = row.QuerySelector("span");
|
|
|
|
var quality = span.ChildNodes[0].TextContent.Trim();
|
2020-02-10 22:16:19 +00:00
|
|
|
var releaseType = ReleaseTypeFromQuality(quality);
|
2018-05-12 01:55:24 +00:00
|
|
|
var sizeText = span.ChildNodes[1].TextContent.Replace("Tama\u00F1o", "").Trim();
|
|
|
|
|
|
|
|
var div = row.QuerySelector("div");
|
|
|
|
var language = div.ChildNodes[1].TextContent.Trim();
|
2018-08-29 09:21:07 +00:00
|
|
|
_dailyResultIdx++;
|
2018-05-12 01:55:24 +00:00
|
|
|
|
2020-03-29 20:40:31 +00:00
|
|
|
var rSize = ReleaseInfo.GetBytes(sizeText);
|
|
|
|
var rPublishDate = _dailyNow - TimeSpan.FromMilliseconds(_dailyResultIdx);
|
|
|
|
var rTitle = releaseType == ReleaseType.Tv
|
|
|
|
? $"Serie {title} - {language} Calidad [{quality}]"
|
|
|
|
: $"{title} [{quality}][{language}]";
|
2018-05-12 01:55:24 +00:00
|
|
|
|
2020-03-29 20:40:31 +00:00
|
|
|
var release = GetReleaseFromData(releaseType, rTitle, detailsUrl, quality, language, rSize, rPublishDate);
|
|
|
|
releases.Add(release);
|
2018-05-12 01:55:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
OnParseError(content, ex);
|
|
|
|
}
|
|
|
|
|
|
|
|
return releases;
|
|
|
|
}
|
|
|
|
|
|
|
|
private string ParseSeriesListContent(string content, string title)
|
|
|
|
{
|
2020-03-29 20:40:31 +00:00
|
|
|
var parser = new HtmlParser();
|
|
|
|
var doc = parser.ParseDocument(content);
|
2018-05-12 01:55:24 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
var rows = doc.QuerySelectorAll(".pelilist li a");
|
|
|
|
foreach (var anchor in rows)
|
|
|
|
{
|
|
|
|
var h2 = anchor.QuerySelector("h2");
|
|
|
|
if (h2.TextContent.Trim().ToLower() == title.Trim().ToLower())
|
|
|
|
return anchor.GetAttribute("href");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
OnParseError(content, ex);
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
private IEnumerable<NewpctRelease> ParseEpisodesListContent(string content)
|
|
|
|
{
|
2020-03-29 20:40:31 +00:00
|
|
|
var parser = new HtmlParser();
|
|
|
|
var doc = parser.ParseDocument(content);
|
2018-05-12 01:55:24 +00:00
|
|
|
|
2020-02-10 22:16:19 +00:00
|
|
|
var releases = new List<NewpctRelease>();
|
2018-05-12 01:55:24 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
var rows = doc.QuerySelectorAll(".content .info");
|
|
|
|
foreach (var row in rows)
|
|
|
|
{
|
|
|
|
var anchor = row.QuerySelector("a");
|
|
|
|
var title = anchor.TextContent.Replace("\t", "").Trim();
|
|
|
|
var detailsUrl = anchor.GetAttribute("href");
|
|
|
|
|
|
|
|
var pubDateText = row.ChildNodes[3].TextContent.Trim();
|
|
|
|
var sizeText = row.ChildNodes[5].TextContent.Trim();
|
|
|
|
|
2020-02-10 22:16:19 +00:00
|
|
|
var size = ReleaseInfo.GetBytes(sizeText);
|
|
|
|
var publishDate = DateTime.ParseExact(pubDateText, "dd-MM-yyyy", null);
|
2018-05-12 01:55:24 +00:00
|
|
|
|
2020-03-29 20:40:31 +00:00
|
|
|
var release = GetReleaseFromData(ReleaseType.Tv, title, detailsUrl, null, null, size, publishDate);
|
|
|
|
releases.Add(release);
|
2018-05-12 01:55:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
OnParseError(content, ex);
|
|
|
|
}
|
|
|
|
|
|
|
|
return releases;
|
|
|
|
}
|
|
|
|
|
2020-03-29 20:40:31 +00:00
|
|
|
private async Task<IEnumerable<ReleaseInfo>> MovieSearch(TorznabQuery query)
|
2018-11-19 10:50:24 +00:00
|
|
|
{
|
|
|
|
var releases = new List<NewpctRelease>();
|
|
|
|
|
2020-02-10 22:16:19 +00:00
|
|
|
var searchStr = query.SanitizedSearchTerm;
|
2019-08-18 20:53:14 +00:00
|
|
|
if (_removeMovieAccents)
|
|
|
|
searchStr = RemoveDiacritics(searchStr);
|
2018-11-19 10:50:24 +00:00
|
|
|
|
2020-03-29 20:40:31 +00:00
|
|
|
var searchJsonUrl = SiteLink + _searchJsonUrl;
|
|
|
|
|
2020-02-10 22:16:19 +00:00
|
|
|
var pg = 1;
|
2018-11-19 10:50:24 +00:00
|
|
|
while (pg <= _maxMoviesPages)
|
|
|
|
{
|
2020-03-26 22:15:28 +00:00
|
|
|
var queryCollection = new Dictionary<string, string>
|
|
|
|
{
|
2020-03-29 20:40:31 +00:00
|
|
|
{"s", searchStr},
|
|
|
|
{"pg", pg.ToString()}
|
2020-03-26 22:15:28 +00:00
|
|
|
};
|
2018-11-19 10:50:24 +00:00
|
|
|
|
2020-03-29 20:40:31 +00:00
|
|
|
var results = await PostDataWithCookies(searchJsonUrl, queryCollection);
|
|
|
|
if (results == null || string.IsNullOrEmpty(results.Content))
|
|
|
|
break;
|
|
|
|
var items = ParseSearchJsonContent(results.Content);
|
2018-12-14 21:56:33 +00:00
|
|
|
if (items == null)
|
2018-11-19 10:50:24 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
releases.AddRange(items);
|
|
|
|
pg++;
|
|
|
|
}
|
|
|
|
|
|
|
|
ScoreReleases(releases, searchStr);
|
|
|
|
|
|
|
|
if (_filterMovies)
|
|
|
|
releases = releases.Where(r => r.Score < _wordNotFoundScore).ToList();
|
|
|
|
|
|
|
|
return releases;
|
|
|
|
}
|
|
|
|
|
2020-03-29 20:40:31 +00:00
|
|
|
private IEnumerable<NewpctRelease> ParseSearchJsonContent(string content)
|
2019-09-28 20:57:03 +00:00
|
|
|
{
|
2020-02-10 22:16:19 +00:00
|
|
|
var someFound = false;
|
|
|
|
var releases = new List<NewpctRelease>();
|
2019-09-28 20:57:03 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
var jo = JObject.Parse(content);
|
|
|
|
|
2020-02-10 22:16:19 +00:00
|
|
|
var numItems = int.Parse(jo["data"]["items"].ToString());
|
|
|
|
for (var i = 0; i < numItems; i++)
|
2019-09-28 20:57:03 +00:00
|
|
|
{
|
|
|
|
var item = jo["data"]["torrents"]["0"][i.ToString()];
|
|
|
|
|
2020-02-10 22:16:19 +00:00
|
|
|
var url = item["guid"].ToString();
|
|
|
|
var title = item["torrentName"].ToString();
|
|
|
|
var pubDateText = item["torrentDateAdded"].ToString();
|
|
|
|
var calidad = item["calidad"].ToString();
|
|
|
|
var sizeText = item["torrentSize"].ToString();
|
2019-09-28 20:57:03 +00:00
|
|
|
|
|
|
|
someFound = true;
|
|
|
|
|
2020-02-10 22:16:19 +00:00
|
|
|
var isSeries = calidad != null && calidad.ToLower().Contains("hdtv");
|
|
|
|
var isGame = title.ToLower().Contains("pcdvd");
|
2019-09-28 20:57:03 +00:00
|
|
|
if (isSeries || isGame)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
long size = 0;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
size = ReleaseInfo.GetBytes(sizeText);
|
|
|
|
}
|
|
|
|
catch
|
|
|
|
{
|
|
|
|
}
|
2020-02-10 22:16:19 +00:00
|
|
|
DateTime.TryParseExact(pubDateText, "dd/MM/yyyy", null, DateTimeStyles.None, out var publishDate);
|
2019-09-28 20:57:03 +00:00
|
|
|
|
2020-03-29 20:40:31 +00:00
|
|
|
var detailsUrl = SiteLink + url;
|
2019-09-28 20:57:03 +00:00
|
|
|
|
2020-03-29 20:40:31 +00:00
|
|
|
var release = GetReleaseFromData(ReleaseType.Movie, title, detailsUrl, calidad, null, size, publishDate);
|
|
|
|
releases.Add(release);
|
2019-09-28 20:57:03 +00:00
|
|
|
}
|
|
|
|
}
|
2020-01-04 19:16:28 +00:00
|
|
|
catch (Exception)
|
2019-09-28 20:57:03 +00:00
|
|
|
{
|
2019-12-09 23:25:25 +00:00
|
|
|
return null;
|
2019-09-28 20:57:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!someFound)
|
|
|
|
return null;
|
|
|
|
|
2018-11-19 10:50:24 +00:00
|
|
|
return releases;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void ScoreReleases(IEnumerable<NewpctRelease> releases, string searchTerm)
|
|
|
|
{
|
2020-02-10 22:16:19 +00:00
|
|
|
var searchWords = searchTerm.ToLower().Split(_wordSeparators, StringSplitOptions.None).
|
2018-11-19 10:50:24 +00:00
|
|
|
Select(s => s.Trim()).
|
|
|
|
Where(s => !string.IsNullOrEmpty(s)).ToArray();
|
|
|
|
|
2020-02-10 22:16:19 +00:00
|
|
|
foreach (var release in releases)
|
2018-11-19 10:50:24 +00:00
|
|
|
{
|
|
|
|
release.Score = 0;
|
2020-02-10 22:16:19 +00:00
|
|
|
var releaseWords = release.Title.ToLower().Split(_wordSeparators, StringSplitOptions.None).
|
2018-11-19 10:50:24 +00:00
|
|
|
Select(s => s.Trim()).
|
|
|
|
Where(s => !string.IsNullOrEmpty(s)).ToArray();
|
|
|
|
|
2020-02-10 22:16:19 +00:00
|
|
|
foreach (var search in searchWords)
|
2018-11-19 10:50:24 +00:00
|
|
|
{
|
2020-02-10 22:16:19 +00:00
|
|
|
var index = Array.IndexOf(releaseWords, search);
|
2018-11-19 10:50:24 +00:00
|
|
|
if (index >= 0)
|
|
|
|
{
|
|
|
|
release.Score += index;
|
|
|
|
releaseWords[index] = null;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
release.Score += _wordNotFoundScore;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-25 16:08:03 +00:00
|
|
|
private static ReleaseType ReleaseTypeFromQuality(string quality) =>
|
|
|
|
quality.Trim().ToLower().StartsWith("hdtv")
|
2020-03-29 20:40:31 +00:00
|
|
|
? ReleaseType.Tv
|
2020-02-25 16:08:03 +00:00
|
|
|
: ReleaseType.Movie;
|
2018-05-12 01:55:24 +00:00
|
|
|
|
2020-03-29 20:40:31 +00:00
|
|
|
private NewpctRelease GetReleaseFromData(ReleaseType releaseType, string title, string detailsUrl, string quality,
|
|
|
|
string language, long size, DateTime publishDate)
|
2018-05-12 01:55:24 +00:00
|
|
|
{
|
2020-03-26 22:15:28 +00:00
|
|
|
var result = new NewpctRelease
|
|
|
|
{
|
|
|
|
NewpctReleaseType = releaseType
|
|
|
|
};
|
2018-05-12 01:55:24 +00:00
|
|
|
|
|
|
|
//Sanitize
|
|
|
|
title = title.Replace("\t", "").Replace("\x2013", "-");
|
|
|
|
|
2020-02-10 22:16:19 +00:00
|
|
|
var match = _titleListRegex.Match(title);
|
2018-05-12 01:55:24 +00:00
|
|
|
if (match.Success)
|
|
|
|
{
|
2018-08-29 09:21:07 +00:00
|
|
|
result.SeriesName = match.Groups[2].Value.Trim(' ', '-');
|
|
|
|
result.Season = int.Parse(match.Groups[5].Success ? match.Groups[5].Value.Trim() : "1");
|
|
|
|
result.Episode = int.Parse(match.Groups[8].Value.Trim().PadLeft(2, '0'));
|
|
|
|
result.EpisodeTo = match.Groups[11].Success ? (int?)int.Parse(match.Groups[11].Value.Trim()) : null;
|
2020-02-10 22:16:19 +00:00
|
|
|
var audioQuality = match.Groups[13].Value.Trim(' ', '[', ']');
|
2018-10-20 05:48:53 +00:00
|
|
|
if (string.IsNullOrEmpty(language))
|
|
|
|
language = audioQuality;
|
2018-08-29 09:21:07 +00:00
|
|
|
quality = match.Groups[14].Value.Trim(' ', '[', ']');
|
2018-05-12 01:55:24 +00:00
|
|
|
|
2020-02-10 22:16:19 +00:00
|
|
|
var seasonText = result.Season.ToString();
|
|
|
|
var episodeText = seasonText + result.Episode.ToString().PadLeft(2, '0');
|
|
|
|
var episodeToText = result.EpisodeTo.HasValue ? "_" + seasonText + result.EpisodeTo.ToString().PadLeft(2, '0') : "";
|
2018-05-12 01:55:24 +00:00
|
|
|
|
|
|
|
result.Title = string.Format("{0} - Temporada {1} [{2}][Cap.{3}{4}][{5}]",
|
2018-08-29 09:21:07 +00:00
|
|
|
result.SeriesName, seasonText, quality, episodeText, episodeToText, audioQuality);
|
2018-05-12 01:55:24 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-02-10 22:16:19 +00:00
|
|
|
var matchClassic = _titleClassicRegex.Match(title);
|
2018-05-12 01:55:24 +00:00
|
|
|
if (matchClassic.Success)
|
|
|
|
{
|
2018-10-20 05:48:53 +00:00
|
|
|
result.Season = matchClassic.Groups[2].Success ? (int?)int.Parse(matchClassic.Groups[2].Value) : null;
|
|
|
|
result.Episode = matchClassic.Groups[3].Success ? (int?)int.Parse(matchClassic.Groups[3].Value) : null;
|
|
|
|
result.EpisodeTo = matchClassic.Groups[6].Success ? (int?)int.Parse(matchClassic.Groups[6].Value) : null;
|
|
|
|
if (matchClassic.Groups[1].Success)
|
|
|
|
quality = matchClassic.Groups[1].Value;
|
2018-05-12 01:55:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
result.Title = title;
|
|
|
|
}
|
|
|
|
|
2020-03-29 20:40:31 +00:00
|
|
|
if (releaseType == ReleaseType.Tv)
|
2018-05-12 01:55:24 +00:00
|
|
|
{
|
|
|
|
if (!string.IsNullOrWhiteSpace(quality) && (quality.Contains("720") || quality.Contains("1080")))
|
|
|
|
result.Category = new List<int> { TorznabCatType.TVHD.ID };
|
|
|
|
else
|
|
|
|
result.Category = new List<int> { TorznabCatType.TV.ID };
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result.Title = title;
|
|
|
|
result.Category = new List<int> { TorznabCatType.Movies.ID };
|
|
|
|
}
|
|
|
|
|
2020-03-29 20:40:31 +00:00
|
|
|
// TODO: add banner
|
|
|
|
|
2019-01-10 14:53:15 +00:00
|
|
|
if (size > 0)
|
|
|
|
result.Size = size;
|
2018-05-12 01:55:24 +00:00
|
|
|
result.Link = new Uri(detailsUrl);
|
2018-07-03 14:17:16 +00:00
|
|
|
result.Guid = result.Link;
|
2019-02-19 23:06:53 +00:00
|
|
|
result.Comments = result.Link;
|
2018-05-12 01:55:24 +00:00
|
|
|
result.PublishDate = publishDate;
|
|
|
|
result.Seeders = 1;
|
|
|
|
result.Peers = 1;
|
|
|
|
|
2018-10-20 05:48:53 +00:00
|
|
|
result.Title = FixedTitle(result, quality, language);
|
2020-01-11 18:07:19 +00:00
|
|
|
result.MinimumRatio = 1;
|
|
|
|
result.MinimumSeedTime = 172800; // 48 hours
|
2019-12-13 22:30:16 +00:00
|
|
|
result.DownloadVolumeFactor = 0;
|
|
|
|
result.UploadVolumeFactor = 1;
|
2018-07-02 10:56:53 +00:00
|
|
|
|
2018-05-12 01:55:24 +00:00
|
|
|
return result;
|
|
|
|
}
|
2018-07-02 10:56:53 +00:00
|
|
|
|
2018-10-20 05:48:53 +00:00
|
|
|
private string FixedTitle(NewpctRelease release, string quality, string language)
|
2018-07-02 10:56:53 +00:00
|
|
|
{
|
2020-02-10 22:16:19 +00:00
|
|
|
if (string.IsNullOrEmpty(release.SeriesName))
|
2018-07-03 09:01:08 +00:00
|
|
|
{
|
2018-08-29 09:21:07 +00:00
|
|
|
release.SeriesName = release.Title;
|
2020-03-29 20:40:31 +00:00
|
|
|
if (release.NewpctReleaseType == ReleaseType.Tv && release.SeriesName.Contains("-"))
|
2018-11-19 10:50:24 +00:00
|
|
|
release.SeriesName = release.Title.Substring(0, release.SeriesName.IndexOf('-') - 1);
|
2018-07-03 09:01:08 +00:00
|
|
|
}
|
2018-10-20 05:48:53 +00:00
|
|
|
|
2020-03-26 22:15:28 +00:00
|
|
|
var titleParts = new List<string>
|
|
|
|
{
|
|
|
|
release.SeriesName
|
|
|
|
};
|
2018-10-20 05:48:53 +00:00
|
|
|
|
2020-03-29 20:40:31 +00:00
|
|
|
if (release.NewpctReleaseType == ReleaseType.Tv)
|
2018-07-03 09:01:08 +00:00
|
|
|
{
|
2020-02-10 22:16:19 +00:00
|
|
|
if (string.IsNullOrEmpty(quality))
|
2018-11-19 10:50:24 +00:00
|
|
|
quality = "HDTV";
|
|
|
|
|
2018-08-29 09:21:07 +00:00
|
|
|
var seasonAndEpisode = "S" + release.Season.ToString().PadLeft(2, '0');
|
|
|
|
seasonAndEpisode += "E" + release.Episode.ToString().PadLeft(2, '0');
|
|
|
|
if (release.EpisodeTo != release.Episode && release.EpisodeTo != null && release.EpisodeTo != 0)
|
|
|
|
{
|
|
|
|
seasonAndEpisode += "-" + release.EpisodeTo.ToString().PadLeft(2, '0');
|
|
|
|
}
|
|
|
|
titleParts.Add(seasonAndEpisode);
|
2018-07-03 09:01:08 +00:00
|
|
|
}
|
2018-10-20 05:48:53 +00:00
|
|
|
|
2018-11-19 10:50:24 +00:00
|
|
|
if (!string.IsNullOrEmpty(quality) && !release.SeriesName.Contains(quality))
|
2018-10-20 05:48:53 +00:00
|
|
|
{
|
|
|
|
titleParts.Add(quality);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(language) && !release.SeriesName.Contains(language))
|
|
|
|
{
|
|
|
|
titleParts.Add(language);
|
|
|
|
}
|
|
|
|
|
2018-11-19 10:50:24 +00:00
|
|
|
if (release.Title.ToLower().Contains("espa\u00F1ol") ||
|
|
|
|
release.Title.ToLower().Contains("espanol") ||
|
|
|
|
release.Title.ToLower().Contains("castellano") ||
|
|
|
|
release.Title.ToLower().EndsWith("espa"))
|
2018-07-02 10:56:53 +00:00
|
|
|
{
|
|
|
|
titleParts.Add("Spanish");
|
|
|
|
}
|
2018-10-20 05:48:53 +00:00
|
|
|
|
2020-02-10 22:16:19 +00:00
|
|
|
var result = string.Join(".", titleParts);
|
2018-10-20 05:48:53 +00:00
|
|
|
|
2020-03-10 02:53:57 +00:00
|
|
|
if (release.NewpctReleaseType == ReleaseType.Movie)
|
|
|
|
{
|
|
|
|
if (_removeMovieYear)
|
|
|
|
{
|
|
|
|
Match match = _titleYearRegex.Match(result);
|
|
|
|
if (match.Success)
|
|
|
|
{
|
|
|
|
int year = int.Parse(match.Groups[1].Value);
|
|
|
|
if (year >= _firstYearAllowed && year <= DateTime.Now.Year + _lastYearAllowedFromNow)
|
|
|
|
result = result.Replace(match.Groups[0].Value, "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-20 05:48:53 +00:00
|
|
|
result = Regex.Replace(result, @"[\[\]]+", ".");
|
2018-11-19 10:50:24 +00:00
|
|
|
result = Regex.Replace(result, @"\.[ \.]*\.", ".");
|
2018-10-20 05:48:53 +00:00
|
|
|
|
|
|
|
return result;
|
2018-07-02 10:56:53 +00:00
|
|
|
}
|
2019-08-18 20:53:14 +00:00
|
|
|
|
|
|
|
private string RemoveDiacritics(string text)
|
|
|
|
{
|
|
|
|
var normalizedString = text.Normalize(NormalizationForm.FormD);
|
2020-03-26 22:15:28 +00:00
|
|
|
|
|
|
|
// https://stackoverflow.com/a/14812065/9719178
|
|
|
|
// TODO Better performance version in .Net-Core:
|
|
|
|
// return string.Concat(normalizedString.Where(c => CharUnicodeInfo.GetUnicodeCategory(c) != UnicodeCategory.NonSpacingMark))
|
|
|
|
// .Normalize(NormalizationForm.FormC);
|
|
|
|
|
2019-08-18 20:53:14 +00:00
|
|
|
var stringBuilder = new StringBuilder();
|
|
|
|
|
|
|
|
foreach (var c in normalizedString)
|
|
|
|
{
|
|
|
|
var unicodeCategory = CharUnicodeInfo.GetUnicodeCategory(c);
|
|
|
|
if (unicodeCategory != UnicodeCategory.NonSpacingMark)
|
|
|
|
{
|
|
|
|
stringBuilder.Append(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return stringBuilder.ToString().Normalize(NormalizationForm.FormC);
|
|
|
|
}
|
2018-05-12 01:55:24 +00:00
|
|
|
}
|
|
|
|
}
|