diff --git a/Aria2Fast/Service/MikanManager.cs b/Aria2Fast/Service/MikanManager.cs index d8d1da2..245b76b 100644 --- a/Aria2Fast/Service/MikanManager.cs +++ b/Aria2Fast/Service/MikanManager.cs @@ -173,7 +173,7 @@ public string IndexPageExtractWeeklyAnimeJson(string htmlContent) var imageAbsUrl = imageRelUrl; imageAbsUrl = imageAbsUrl.Replace("width=400", "width=460"); - imageAbsUrl = imageAbsUrl.Replace("height=400", "width=640"); + imageAbsUrl = imageAbsUrl.Replace("height=400", "height=640"); if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(url) && !string.IsNullOrEmpty(imageAbsUrl)) { @@ -210,7 +210,6 @@ public string IndexPageExtractWeeklyAnimeJson2(string htmlContent) foreach (var dayNode in bangumiNodes) { - //var dateString = dayNode.SelectSingleNode(".//div[@id='data-row-2']")?.InnerText; var dateNode = dayNode.SelectSingleNode(".//div[starts-with(@id, 'data-row-')]"); var dateString = dateNode?.InnerText; dateString = dateString?.Trim(); @@ -221,16 +220,31 @@ public string IndexPageExtractWeeklyAnimeJson2(string htmlContent) foreach (var animeNode in animeNodes) { - var name = animeNode.SelectSingleNode(".//a[@class='an-text']")?.InnerText; + var nameNode = animeNode.SelectSingleNode(".//a[@class='an-text']"); + var name = nameNode?.InnerText; + + if (string.IsNullOrWhiteSpace(name)) + { + // 从最后一个div,class=date-text中提取名称 + var lastNameNode = animeNode.SelectSingleNode(".//div[@class='an-info-group']/div[contains(@class, 'date-text')][last()]"); + name = lastNameNode?.InnerText; + + + } + + name = HtmlEntity.DeEntitize(name); var url = animeNode.SelectSingleNode(".//a[@class='an-text']")?.GetAttributeValue("href", string.Empty); - var imageNode = animeNode.SelectSingleNode(".//span[contains(@class, 'js-expand_bangumi')]"); + var imageNode = animeNode.SelectSingleNode(".//span"); var dataSrc = imageNode?.GetAttributeValue("data-src", string.Empty); var imageUrl = dataSrc; - if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(url) && !string.IsNullOrEmpty(imageUrl)) + imageUrl = imageUrl.Replace("width=400", "width=460"); + imageUrl = imageUrl.Replace("height=400", "height=640"); + + if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(imageUrl)) { animeList.Add(new { @@ -263,6 +277,11 @@ public string AnimePage(string htmlContent) var divs = htmlDoc.DocumentNode.SelectNodes("//div[contains(@class, 'subgroup-text')]"); var subgroupInfoList = new List(); + if (divs == null) + { + return "[]"; + } + foreach (var div in divs) { var subgroupNames = new List(); diff --git a/Aria2Fast/Service/Model/MikanModel.cs b/Aria2Fast/Service/Model/MikanModel.cs index 84e7a50..77c7117 100644 --- a/Aria2Fast/Service/Model/MikanModel.cs +++ b/Aria2Fast/Service/Model/MikanModel.cs @@ -65,15 +65,20 @@ public int NewEpisode { get { - if (Rss == null) + if (Rss == null || Rss.Count == 0) { return 0; } - return Rss!.Max(a => + + + + int newEpisode = Rss!.Max(a => { return a.Episode; - } - ); + }); + + return newEpisode; + } } diff --git a/Aria2Fast/Utils/ImageCacheUtils.cs b/Aria2Fast/Utils/ImageCacheUtils.cs index a68cf14..3b348cf 100644 --- a/Aria2Fast/Utils/ImageCacheUtils.cs +++ b/Aria2Fast/Utils/ImageCacheUtils.cs @@ -20,29 +20,24 @@ public static async Task PreloadImageCache() { var dirPath = Path.Combine(Directory.GetCurrentDirectory(), "ImageCached"); var files = Directory.GetFiles(dirPath); - MemoryCache cache = MemoryCache.Default; + //MemoryCache cache = MemoryCache.Default; await Task.Run(() => { foreach (var file in files) { var fileName = Path.GetFileName(file); string cacheKey = fileName; - if (!cache.Contains(cacheKey)) - { - - BitmapImage bitmap = new BitmapImage(); - bitmap.BeginInit(); - bitmap.CreateOptions = BitmapCreateOptions.IgnoreImageCache | BitmapCreateOptions.DelayCreation; - bitmap.CacheOption = BitmapCacheOption.OnLoad; - bitmap.UriSource = new Uri(file); - bitmap.EndInit(); + BitmapImage bitmap = new BitmapImage(); + bitmap.BeginInit(); + bitmap.CreateOptions = BitmapCreateOptions.IgnoreImageCache | BitmapCreateOptions.DelayCreation; + bitmap.CacheOption = BitmapCacheOption.OnLoad; + bitmap.UriSource = new Uri(file); + bitmap.EndInit(); - bitmap.Freeze(); + bitmap.Freeze(); - cache.Set(cacheKey, bitmap, new CacheItemPolicy()); - Debug.WriteLine($"[缓存]{cacheKey}"); - - } + //cache.Set(cacheKey, bitmap, new CacheItemPolicy()); + Debug.WriteLine($"[缓存]{cacheKey}"); } }); @@ -56,14 +51,14 @@ await Task.Run(() => { /// public static BitmapImage GetImageWithLocalCache(Uri uri) { - MemoryCache cache = MemoryCache.Default; + //MemoryCache cache = MemoryCache.Default; var fileName = Path.GetFileName(uri.LocalPath); - if (cache.Contains(fileName)) - { - var bmp = (BitmapImage)cache.Get(fileName); - //bmp.Freeze(); - return bmp; - } + //if (cache.Contains(fileName)) + //{ + // var bmp = (BitmapImage)cache.Get(fileName); + // //bmp.Freeze(); + // return bmp; + //} var dirPath = Path.Combine(Directory.GetCurrentDirectory(), "ImageCached"); if (!Directory.Exists(dirPath)) @@ -80,12 +75,22 @@ public static BitmapImage GetImageWithLocalCache(Uri uri) } else { - var result = uri.GetBytesAsync().Result; - if (result != null && result.Length > 0) + try + { + var result = uri.GetBytesAsync().Result; + if (result != null && result.Length > 0) + { + img.StreamSource = new MemoryStream(result); + File.WriteAllBytes(localFilePath, result); + } + } + catch (Exception ex) { - img.StreamSource = new MemoryStream(result); - File.WriteAllBytes(localFilePath, result); + } + + + } img.CacheOption = BitmapCacheOption.OnLoad; @@ -98,30 +103,5 @@ public static BitmapImage GetImageWithLocalCache(Uri uri) return img; } - public static BitmapImage GetImageFromCache(Uri uri) - { - BitmapImage img = null; - - MemoryCache cache = MemoryCache.Default; - - var fileName = Path.GetFileName(uri.LocalPath); - string cacheKey = fileName; - - if (cache.Contains(cacheKey)) - { - img = (BitmapImage)cache.Get(cacheKey); - } - else - { - img = new BitmapImage(uri); - img.CacheOption = BitmapCacheOption.OnLoad; - img.DownloadCompleted += (s, e) => - { - cache.Set(cacheKey, img, new CacheItemPolicy()); - }; - } - - return img; - } } }