diff --git a/Emby.Plugins.JavScraper/Scrapers/R18.cs b/Emby.Plugins.JavScraper/Scrapers/R18.cs new file mode 100644 index 0000000..638739d --- /dev/null +++ b/Emby.Plugins.JavScraper/Scrapers/R18.cs @@ -0,0 +1,215 @@ +using HtmlAgilityPack; + +#if __JELLYFIN__ +using Microsoft.Extensions.Logging; +#else + +using MediaBrowser.Model.Logging; + +#endif + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using System.Web; + +namespace Emby.Plugins.JavScraper.Scrapers +{ + /// + /// https://www.r18.com/videos/vod/movies/detail/-/id=118abw00032/?i3_ref=search&i3_ord=1 + /// + public class R18 : AbstractScraper + { + /// + /// 适配器名称 + /// + public override string Name => "R18"; + + /// + /// 构造 + /// + /// + public R18(ILogger log = null) + : base("https://www.r18.com/", log) + { + } + + /// + /// 检查关键字是否符合 + /// + /// + /// + public override bool CheckKey(string key) + => JavIdRecognizer.FC2(key) == null; + + /// + /// 获取列表 + /// + /// 关键字 + /// + protected override async Task> DoQyery(List ls, string key) + { + //https://www.r18.com/common/search/searchword=ABW-032/ + var doc = await GetHtmlDocumentAsync($"/common/search/searchword={key}/?lg=zh"); + if (doc != null) + { + ParseIndex(ls, doc); + } + + SortIndex(key, ls); + return ls; + } + + /// + /// 解析列表 + /// + /// + /// + /// + protected override List ParseIndex(List ls, HtmlDocument doc) + { + if (doc == null) + return ls; + var nodes = doc.DocumentNode.SelectNodes("//li[@class='item-list']"); + if (nodes?.Any() != true) + return ls; + + foreach (var node in nodes) + { + var title_node = node.SelectSingleNode("./a"); + if (title_node == null) + continue; + var url = title_node.GetAttributeValue("href", null); + if (string.IsNullOrWhiteSpace(url)) + continue; + var img = title_node.SelectSingleNode(".//img"); + if (img == null) + continue; + var t2 = title_node.SelectSingleNode(".//dt"); + var m = new JavVideoIndex() + { + Provider = Name, + Url = url + "&lg=zh", + Num = img.GetAttributeValue("alt", null), + Title = t2?.InnerText.Trim(), + Cover = img.GetAttributeValue("src", null), + }; + if (string.IsNullOrWhiteSpace(m.Title)) + m.Title = m.Num; + + ls.Add(m); + } + + return ls; + } + + /// + /// 获取详情 + /// + /// 地址 + /// + public override async Task Get(string url) + { + //https://www.r18.com/videos/vod/movies/detail/-/id=ssni00879/?dmmref=video.movies.popular&i3_ref=list&i3_ord=4 + var doc = await GetHtmlDocumentAsync(url); + if (doc == null) + return null; + + var node = doc.DocumentNode.SelectSingleNode("//div[@class='product-details-page']"); + if (node == null) + return null; + + var product_details = node.SelectSingleNode(".//div[@class='product-details']"); + + string GetValueByItemprop(string name) + => product_details.SelectSingleNode($".//dd[@itemprop='{name}']")?.InnerText.Trim().Trim('-'); + + string GetDuration() + { + var _d = GetValueByItemprop("duration"); + if (string.IsNullOrWhiteSpace(_d)) + return null; + var _m = Regex.Match(_d, @"[\d]+"); + if (_m.Success) + return _m.Value; + return null; + } + var dic = new Dictionary(); + var nodes = product_details.SelectNodes(".//dt"); + foreach (var n in nodes) + { + var name = n.InnerText.Trim(); + if (string.IsNullOrWhiteSpace(name)) + continue; + //获取下一个标签 + var nx = n; + do + { + nx = nx.NextSibling; + if (nx == null || nx.Name == "dt") + { + nx = null; + break; + } + if (nx.Name == "dd") + break; + } while (true); + if (nx == null) + continue; + + var aa = nx.SelectNodes(".//a"); + var value = aa?.Any() == true ? string.Join(", ", aa.Select(o => o.InnerText.Trim()?.Trim('-')).Where(o => string.IsNullOrWhiteSpace(o) == false)) + : nx?.InnerText?.Trim()?.Trim('-'); + + if (string.IsNullOrWhiteSpace(value) == false) + dic[name] = value; + } + + string GetValue(string _key) + => dic.Where(o => o.Key.Contains(_key)).Select(o => o.Value).FirstOrDefault(); + + var genres = product_details.SelectNodes(".//*[@itemprop='genre']") + .Select(o => o.InnerText.Trim()?.Trim('-')).Where(o => string.IsNullOrWhiteSpace(o) == false).ToList(); + + var actors = product_details.SelectNodes(".//div[@itemprop='actors']//*[@itemprop='name']") + .Select(o => o.InnerText.Trim()?.Trim('-')).Where(o => string.IsNullOrWhiteSpace(o) == false).ToList(); + + var product_gallery = doc.GetElementbyId("product-gallery"); + var samples = product_gallery.SelectNodes(".//img")? + .Select(o => o.GetAttributeValue("data-src", null) ?? o.GetAttributeValue("src", null)).Where(o => o != null).ToList(); + + var m = new JavVideo() + { + Provider = Name, + Url = url, + Title = HttpUtility.HtmlDecode(node.SelectSingleNode(".//cite")?.InnerText?.Trim() ?? string.Empty), + Cover = node.SelectSingleNode(".//img[@itemprop='image']")?.GetAttributeValue("src", null)?.Replace("ps.", "pl."), + Num = GetValue("DVD ID:"), + Date = GetValueByItemprop("dateCreated")?.Replace('/', '-'), + Runtime = GetDuration(), + Maker = GetValue("片商:"), + Studio = GetValue("廠牌:"), + Set = GetValue("系列:"), + Director = GetValueByItemprop("director"), + //Plot = node.SelectSingleNode("//p[@class='txt introduction']")?.InnerText, + Genres = genres, + Actors = actors, + Samples = samples, + }; + + if (string.IsNullOrWhiteSpace(m.Title)) + m.Title = m.Num; + + if (string.IsNullOrWhiteSpace(m.Plot)) + m.Plot = await GetDmmPlot(m.Num); + + //去除标题中的番号 + if (string.IsNullOrWhiteSpace(m.Num) == false && m.Title?.StartsWith(m.Num, StringComparison.OrdinalIgnoreCase) == true) + m.Title = m.Title.Substring(m.Num.Length).Trim(); + + return m; + } + } +} \ No newline at end of file