mirror of
https://github.com/Jackett/Jackett.git
synced 2025-09-17 17:34:09 +02:00
mejortorrent: fix download link and code clean up (#8420)
This commit is contained in:
@@ -19,7 +19,6 @@ using WebClient = Jackett.Common.Utils.Clients.WebClient;
|
|||||||
|
|
||||||
namespace Jackett.Common.Indexers
|
namespace Jackett.Common.Indexers
|
||||||
{
|
{
|
||||||
//TODO fix ReSharper notice
|
|
||||||
// ReSharper disable once UnusedType.Global
|
// ReSharper disable once UnusedType.Global
|
||||||
public class MejorTorrent : BaseWebIndexer
|
public class MejorTorrent : BaseWebIndexer
|
||||||
{
|
{
|
||||||
@@ -96,25 +95,22 @@ namespace Jackett.Common.Indexers
|
|||||||
|
|
||||||
public override async Task<byte[]> Download(Uri link)
|
public override async Task<byte[]> Download(Uri link)
|
||||||
{
|
{
|
||||||
|
var parser = new HtmlParser();
|
||||||
var downloadUrl = link.ToString();
|
var downloadUrl = link.ToString();
|
||||||
|
|
||||||
// Eg http://www.mejortorrentt.org/peli-descargar-torrent-11995-Harry-Potter-y-la-piedra-filosofal.html
|
// Eg http://www.mejortorrentt.org/peli-descargar-torrent-11995-Harry-Potter-y-la-piedra-filosofal.html
|
||||||
var result = await RequestStringWithCookies(downloadUrl);
|
var result = await RequestStringWithCookies(downloadUrl);
|
||||||
if (result.Status != HttpStatusCode.OK)
|
if (result.Status != HttpStatusCode.OK)
|
||||||
throw new ExceptionWithConfigData(result.Content, configData);
|
throw new ExceptionWithConfigData(result.Content, configData);
|
||||||
var searchResultParser = new HtmlParser();
|
var dom = parser.ParseDocument(result.Content);
|
||||||
var html = searchResultParser.ParseDocument(result.Content);
|
downloadUrl = SiteLink + dom.QuerySelector("a[href*=\"sec=descargas\"]").GetAttribute("href");
|
||||||
downloadUrl = SiteLink + html.QuerySelector("a[href*=\"sec=descargas\"]").GetAttribute("href");
|
|
||||||
|
|
||||||
// Eg http://www.mejortorrentt.org/secciones.php?sec=descargas&ap=contar&tabla=peliculas&id=11995&link_bajar=1
|
// Eg http://www.mejortorrentt.org/secciones.php?sec=descargas&ap=contar&tabla=peliculas&id=11995&link_bajar=1
|
||||||
result = await RequestStringWithCookies(downloadUrl);
|
result = await RequestStringWithCookies(downloadUrl);
|
||||||
if (result.Status != HttpStatusCode.OK)
|
if (result.Status != HttpStatusCode.OK)
|
||||||
throw new ExceptionWithConfigData(result.Content, configData);
|
throw new ExceptionWithConfigData(result.Content, configData);
|
||||||
searchResultParser = new HtmlParser();
|
dom = parser.ParseDocument(result.Content);
|
||||||
html = searchResultParser.ParseDocument(result.Content);
|
downloadUrl = SiteLink + dom.QuerySelector("a[href*=\".torrent\"]").GetAttribute("href").TrimStart('/');
|
||||||
var onclick = html.QuerySelector("a[onclick*=\"/uploads/\"]").GetAttribute("onclick");
|
|
||||||
var table = onclick.Split(new[] { "table: '" }, StringSplitOptions.None)[1].Split(new[] { "'" }, StringSplitOptions.None)[0];
|
|
||||||
var name = onclick.Split(new[] { "name: '" }, StringSplitOptions.None)[1].Split(new[] { "'" }, StringSplitOptions.None)[0];
|
|
||||||
downloadUrl = SiteLink + "uploads/torrents/" + table + "/" + name;
|
|
||||||
|
|
||||||
// Eg https://www.mejortorrentt.org/uploads/torrents/peliculas/Harry_Potter_1_y_la_Piedra_Filosofal_MicroHD_1080p.torrent
|
// Eg https://www.mejortorrentt.org/uploads/torrents/peliculas/Harry_Potter_1_y_la_Piedra_Filosofal_MicroHD_1080p.torrent
|
||||||
var content = await base.Download(new Uri(downloadUrl));
|
var content = await base.Download(new Uri(downloadUrl));
|
||||||
@@ -141,20 +137,15 @@ namespace Jackett.Common.Indexers
|
|||||||
string rowQuality = null;
|
string rowQuality = null;
|
||||||
|
|
||||||
foreach (var row in container.Children)
|
foreach (var row in container.Children)
|
||||||
{
|
|
||||||
if (row.TagName.Equals("A"))
|
if (row.TagName.Equals("A"))
|
||||||
{
|
{
|
||||||
rowTitle = row.TextContent;
|
rowTitle = row.TextContent;
|
||||||
rowCommentsLink = SiteLink + row.GetAttribute("href");
|
rowCommentsLink = SiteLink + row.GetAttribute("href");
|
||||||
}
|
}
|
||||||
else if (rowPublishDate == null && row.TagName.Equals("SPAN"))
|
else if (rowPublishDate == null && row.TagName.Equals("SPAN"))
|
||||||
{
|
|
||||||
rowPublishDate = row.TextContent;
|
rowPublishDate = row.TextContent;
|
||||||
}
|
|
||||||
else if (rowPublishDate != null && row.TagName.Equals("SPAN"))
|
else if (rowPublishDate != null && row.TagName.Equals("SPAN"))
|
||||||
{
|
|
||||||
rowQuality = row.TextContent;
|
rowQuality = row.TextContent;
|
||||||
}
|
|
||||||
else if (row.TagName.Equals("BR"))
|
else if (row.TagName.Equals("BR"))
|
||||||
{
|
{
|
||||||
// we add parsed items to parsedCommentsLink to avoid duplicates in newest torrents
|
// we add parsed items to parsedCommentsLink to avoid duplicates in newest torrents
|
||||||
@@ -171,8 +162,6 @@ namespace Jackett.Common.Indexers
|
|||||||
rowPublishDate = null;
|
rowPublishDate = null;
|
||||||
rowQuality = null;
|
rowQuality = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -200,13 +189,12 @@ namespace Jackett.Common.Indexers
|
|||||||
|
|
||||||
var table = doc.QuerySelector("#main_table_center_center2 table table");
|
var table = doc.QuerySelector("#main_table_center_center2 table table");
|
||||||
// check the search term is valid
|
// check the search term is valid
|
||||||
if (table != null && table.QuerySelector("tr table") != null)
|
if (table?.QuerySelector("tr table") != null)
|
||||||
{
|
{
|
||||||
// check there are results
|
// check there are results
|
||||||
table = table.QuerySelector("tr table");
|
table = table.QuerySelector("tr table");
|
||||||
var rows = table.QuerySelectorAll("tr");
|
var rows = table.QuerySelectorAll("tr");
|
||||||
if (rows != null && rows.Length > 0 && rows[0].QuerySelectorAll("td").Length == 2)
|
if (rows != null && rows.Length > 0 && rows[0].QuerySelectorAll("td").Length == 2)
|
||||||
{
|
|
||||||
foreach (var row in rows)
|
foreach (var row in rows)
|
||||||
{
|
{
|
||||||
var link = row.QuerySelector("td a");
|
var link = row.QuerySelector("td a");
|
||||||
@@ -222,7 +210,6 @@ namespace Jackett.Common.Indexers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
OnParseError(result.Content, ex);
|
OnParseError(result.Content, ex);
|
||||||
@@ -253,9 +240,7 @@ namespace Jackett.Common.Indexers
|
|||||||
|
|
||||||
// parsing is different for each category
|
// parsing is different for each category
|
||||||
if (cat == MejorTorrentCatType.Serie || cat == MejorTorrentCatType.SerieHd)
|
if (cat == MejorTorrentCatType.Serie || cat == MejorTorrentCatType.SerieHd)
|
||||||
{
|
|
||||||
await ParseSeriesRelease(releases, query, title, commentsLink, cat, publishDate);
|
await ParseSeriesRelease(releases, query, title, commentsLink, cat, publishDate);
|
||||||
}
|
|
||||||
else if (query.Episode == null) // if it's scene series, we don't return other categories
|
else if (query.Episode == null) // if it's scene series, we don't return other categories
|
||||||
{
|
{
|
||||||
if (cat == MejorTorrentCatType.Pelicula)
|
if (cat == MejorTorrentCatType.Pelicula)
|
||||||
@@ -263,7 +248,8 @@ namespace Jackett.Common.Indexers
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
const long size = 104857600L; // 100 MB
|
const long size = 104857600L; // 100 MB
|
||||||
GenerateRelease(releases, title, commentsLink, commentsLink, cat, publishDate, size);
|
var release = GenerateRelease(title, commentsLink, commentsLink, cat, publishDate, size);
|
||||||
|
releases.Add(release);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -303,7 +289,8 @@ namespace Jackett.Common.Indexers
|
|||||||
if (episodeTitle.ToLower().Contains("720p"))
|
if (episodeTitle.ToLower().Contains("720p"))
|
||||||
size = 1288490188L; // 1.2 GB
|
size = 1288490188L; // 1.2 GB
|
||||||
|
|
||||||
GenerateRelease(releases, episodeTitle, commentsLink, downloadLink, cat, episodePublish, size);
|
var release = GenerateRelease(episodeTitle, commentsLink, downloadLink, cat, episodePublish, size);
|
||||||
|
releases.Add(release);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -363,11 +350,12 @@ namespace Jackett.Common.Indexers
|
|||||||
else if (title.ToLower().Contains("bdremux"))
|
else if (title.ToLower().Contains("bdremux"))
|
||||||
size = 21474836480L; // 20 GB
|
size = 21474836480L; // 20 GB
|
||||||
|
|
||||||
GenerateRelease(releases, title, commentsLink, commentsLink, cat, publishDate, size);
|
var release = GenerateRelease(title, commentsLink, commentsLink, cat, publishDate, size);
|
||||||
|
releases.Add(release);
|
||||||
}
|
}
|
||||||
// TODO refactor for IEnumerable
|
|
||||||
private void GenerateRelease(ICollection<ReleaseInfo> releases, string title, string commentsLink,
|
private ReleaseInfo GenerateRelease(string title, string commentsLink, string downloadLink, string cat,
|
||||||
string downloadLink, string cat, DateTime publishDate, long size)
|
DateTime publishDate, long size)
|
||||||
{
|
{
|
||||||
var link = new Uri(downloadLink);
|
var link = new Uri(downloadLink);
|
||||||
var comments = new Uri(commentsLink);
|
var comments = new Uri(commentsLink);
|
||||||
@@ -388,7 +376,7 @@ namespace Jackett.Common.Indexers
|
|||||||
DownloadVolumeFactor = 0,
|
DownloadVolumeFactor = 0,
|
||||||
UploadVolumeFactor = 1
|
UploadVolumeFactor = 1
|
||||||
};
|
};
|
||||||
releases.Add(release);
|
return release;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool CheckTitleMatchWords(string queryStr, string title)
|
private static bool CheckTitleMatchWords(string queryStr, string title)
|
||||||
@@ -460,17 +448,11 @@ namespace Jackett.Common.Indexers
|
|||||||
{
|
{
|
||||||
newEpisodeTitle = "";
|
newEpisodeTitle = "";
|
||||||
foreach (Match m in matches)
|
foreach (Match m in matches)
|
||||||
{
|
|
||||||
if (newEpisodeTitle.Equals(""))
|
if (newEpisodeTitle.Equals(""))
|
||||||
{
|
|
||||||
newEpisodeTitle += "S" + m.Groups[1].Value.PadLeft(2, '0')
|
newEpisodeTitle += "S" + m.Groups[1].Value.PadLeft(2, '0')
|
||||||
+ "E" + m.Groups[2].Value.PadLeft(2, '0');
|
+ "E" + m.Groups[2].Value.PadLeft(2, '0');
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
newEpisodeTitle += "-E" + m.Groups[2].Value.PadLeft(2, '0');
|
newEpisodeTitle += "-E" + m.Groups[2].Value.PadLeft(2, '0');
|
||||||
}
|
|
||||||
}
|
|
||||||
// newEpisodeTitle = S05E08-E13
|
// newEpisodeTitle = S05E08-E13
|
||||||
// newEpisodeTitle = S02E01-E02-E03
|
// newEpisodeTitle = S02E01-E02-E03
|
||||||
}
|
}
|
||||||
@@ -479,12 +461,10 @@ namespace Jackett.Common.Indexers
|
|||||||
// episodeTitle = 1x04 - 05.
|
// episodeTitle = 1x04 - 05.
|
||||||
var m = Regex.Match(newEpisodeTitle, "^([0-9]+)x([0-9]+)[^0-9]+([0-9]+)[.]?$", RegexOptions.IgnoreCase);
|
var m = Regex.Match(newEpisodeTitle, "^([0-9]+)x([0-9]+)[^0-9]+([0-9]+)[.]?$", RegexOptions.IgnoreCase);
|
||||||
if (m.Success)
|
if (m.Success)
|
||||||
{
|
|
||||||
newEpisodeTitle = "S" + m.Groups[1].Value.PadLeft(2, '0')
|
newEpisodeTitle = "S" + m.Groups[1].Value.PadLeft(2, '0')
|
||||||
+ "E" + m.Groups[2].Value.PadLeft(2, '0') + "-"
|
+ "E" + m.Groups[2].Value.PadLeft(2, '0') + "-"
|
||||||
+ "E" + m.Groups[3].Value.PadLeft(2, '0');
|
+ "E" + m.Groups[3].Value.PadLeft(2, '0');
|
||||||
// newEpisodeTitle = S01E04-E05
|
// newEpisodeTitle = S01E04-E05
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// episodeTitle = 1x02
|
// episodeTitle = 1x02
|
||||||
@@ -534,9 +514,7 @@ namespace Jackett.Common.Indexers
|
|||||||
else if (mejortorrentCat.Equals(MejorTorrentCatType.Pelicula) ||
|
else if (mejortorrentCat.Equals(MejorTorrentCatType.Pelicula) ||
|
||||||
mejortorrentCat.Equals(MejorTorrentCatType.Serie) ||
|
mejortorrentCat.Equals(MejorTorrentCatType.Serie) ||
|
||||||
mejortorrentCat.Equals(MejorTorrentCatType.Musica))
|
mejortorrentCat.Equals(MejorTorrentCatType.Musica))
|
||||||
{
|
|
||||||
cat = mejortorrentCat;
|
cat = mejortorrentCat;
|
||||||
}
|
|
||||||
|
|
||||||
// hack to separate SD & HD series
|
// hack to separate SD & HD series
|
||||||
if (cat.Equals(MejorTorrentCatType.Serie) && title.ToLower().Contains("720p"))
|
if (cat.Equals(MejorTorrentCatType.Serie) && title.ToLower().Contains("720p"))
|
||||||
@@ -552,10 +530,8 @@ namespace Jackett.Common.Indexers
|
|||||||
return null;
|
return null;
|
||||||
var longestWord = words.First();
|
var longestWord = words.First();
|
||||||
foreach (var word in words)
|
foreach (var word in words)
|
||||||
{
|
|
||||||
if (word.Length >= longestWord.Length)
|
if (word.Length >= longestWord.Length)
|
||||||
longestWord = word;
|
longestWord = word;
|
||||||
}
|
|
||||||
return longestWord;
|
return longestWord;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user