-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
745 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using Gabriel.Cat.S.Extension; | ||
using HtmlAgilityPack; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Drawing; | ||
using System.IO; | ||
using System.Linq; | ||
|
||
namespace CheckFenix.Core | ||
{ | ||
public class Comentario | ||
{ | ||
static SortedList<string, Bitmap> DicPic = new SortedList<string, Bitmap>(); | ||
public Comentario() { } | ||
public Comentario(HtmlNode nodo) | ||
{ | ||
Picture =new Uri( nodo.GetByClass("avatar").First().GetByTagName("img").First().Attributes["src"].Value); | ||
Name = nodo.GetByClass("author").First().GetByTagName("a").First().InnerText; | ||
Mensaje = nodo.GetByClass("post-message").First().GetByTagName("p").First().InnerText; | ||
} | ||
public Uri Picture { get; set; } | ||
public Bitmap Image | ||
{ | ||
get { | ||
|
||
string name = Path.GetFileName(Picture.AbsoluteUri); | ||
if (!DicPic.ContainsKey(name)) | ||
{ | ||
DicPic.Add(name, Picture.GetBitmap()); | ||
} | ||
return DicPic[name]; | ||
|
||
} | ||
} | ||
public string Name { get; set; } | ||
public string Mensaje { get; set; } | ||
|
||
public static IEnumerable<Comentario> GetComentarios(IReadComentario reader,Uri page) | ||
{ | ||
// post-list | ||
HtmlNode posts; | ||
reader.Load(page); | ||
reader.Call("$('#showComments').click()"); | ||
posts = reader.GetDocument().GetElementbyId("post-list");//no existe hasta que se haga click en $("#showComments") | ||
return Equals(posts,default(HtmlNode))?new Comentario[0]: posts.ChildNodes.Select(p => new Comentario(p)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,4 +15,5 @@ public static Bitmap GetBitmap(this Uri url) | |
return new Bitmap(responseStream); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using HtmlAgilityPack; | ||
using System.IO; | ||
using System.Threading; | ||
|
||
namespace CheckFenix.Core | ||
{ | ||
public static class HtmlDic | ||
{ | ||
public const string URLANIMEFENIX = "https://www.animefenix.com/"; | ||
public static string CacheFolder = "CacheCapitulos"; | ||
public static TimeSpan TiempoMinimoRefresh { get; set; } | ||
static SortedList<string, KeyValuePair<long, string>> DicHtmlSerie { get; set; } | ||
static SortedList<string, string> DicHtmlCapitulo { get; set; } | ||
static Semaphore smDic = new Semaphore(1, 1); | ||
static HtmlDic() | ||
{ | ||
DicHtmlSerie = new SortedList<string, KeyValuePair<long, string>>(); | ||
DicHtmlCapitulo = new SortedList<string, string>(); | ||
TiempoMinimoRefresh = TimeSpan.FromMinutes(5); | ||
if (!Directory.Exists(CacheFolder)) | ||
Directory.CreateDirectory(CacheFolder); | ||
else | ||
{ | ||
foreach(string item in Directory.GetFiles(CacheFolder)) | ||
{ | ||
DicHtmlCapitulo.Add(Path.GetFileName(item),File.ReadAllText(item)); | ||
} | ||
} | ||
|
||
} | ||
public static HtmlDocument GetHtmlSerie(Uri url) | ||
{ | ||
|
||
return new HtmlDocument().LoadString(GetStringSerie(url)); | ||
} | ||
public static HtmlDocument GetHtmlCapitulo(Uri url) | ||
{ | ||
|
||
return new HtmlDocument().LoadString(GetStringCapitulo(url)); | ||
} | ||
public static string GetStringSerie(Uri url) | ||
{ | ||
string html; | ||
try | ||
{ | ||
smDic.WaitOne(); | ||
if (DicHtmlSerie.ContainsKey(url.AbsoluteUri)) | ||
{ | ||
if (DateTime.Now - new DateTime(DicHtmlSerie[url.AbsoluteUri].Key) > TiempoMinimoRefresh) | ||
DicHtmlSerie.Remove(url.AbsoluteUri); | ||
} | ||
if (!DicHtmlSerie.ContainsKey(url.AbsoluteUri)) | ||
{ | ||
DicHtmlSerie.Add(url.AbsoluteUri, new KeyValuePair<long, string>(DateTime.Now.Ticks, url.DownloadString())); | ||
} | ||
html = DicHtmlSerie[url.AbsoluteUri].Value; | ||
} | ||
catch | ||
{ | ||
throw; | ||
} | ||
finally | ||
{ | ||
smDic.Release(); | ||
} | ||
return html; | ||
} | ||
public static string GetStringCapitulo(Uri url) | ||
{ | ||
string html; | ||
|
||
smDic.WaitOne(); | ||
if (!DicHtmlCapitulo.ContainsKey(url.AbsoluteUri)) | ||
{ | ||
DicHtmlCapitulo.Add(url.AbsoluteUri, url.DownloadString()); | ||
} | ||
html= DicHtmlCapitulo[url.AbsoluteUri]; | ||
smDic.Release(); | ||
return html; | ||
} | ||
public static void SaveCache() | ||
{ | ||
string path; | ||
foreach (var item in DicHtmlCapitulo) | ||
{ | ||
try | ||
{ | ||
path = Path.Combine(CacheFolder, item.Key); | ||
if (!File.Exists(path)) | ||
File.WriteAllText(path, item.Value); | ||
} | ||
catch | ||
{ | ||
System.Diagnostics.Debugger.Break(); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using HtmlAgilityPack; | ||
using System; | ||
|
||
namespace CheckFenix.Core | ||
{ | ||
public interface IReadComentario | ||
{ | ||
void Load(Uri page); | ||
void Call(string js); | ||
HtmlDocument GetDocument(); | ||
} | ||
} |
Oops, something went wrong.