Corretto la validazione dei link

i link vengono analizzati più volte, per evitarlo devo anticipare il check sul link prima di inserirlo sulla fifo farlo così:
- Se url non nel DB, lo inserisco in FIFO con ToDownload
- Se url nel DB:
  - se è un Idx, con data di update precedente di un giorno, lo inserisco in FIFO con ToDownload per qualsiasi status
  - se è un Rac, con data di update precedente di un giorno, lo inserisco in FIFO con ToDownload solo se ha status non Done

ToDo:
- Aggiungere gestione parallela
- Aggiungere analisi di quanto downloadato per estrarre altri link e proseguire con lo skraping
- Aumentare i log in modo da tenere traccia di quanto succede
- Animare la UI in modo da far capire cosa succede
This commit is contained in:
CSiCoAlm committed 2025-12-27 11:44:02 +01:00
1 parent e8f18a173b
commit 3313b6b888
6 files changed
+78 -23

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectView>ShowAllFiles</ProjectView>
<ProjectView>ProjectFiles</ProjectView>
</PropertyGroup>
</Project>
+34 -1
View File
@@ -32,7 +32,7 @@ namespace A69WD {
public System.Data.SQLite.SQLiteConnection cn { get; set; }
/// <summary>
/// Indicatore che il DB è ready
/// Indicatore che il DB è ready
/// </summary>
public bool DB_ok { get; set; }
@@ -314,6 +314,39 @@ namespace A69WD {
}
public bool IsPresent(string url, int timeOffset = 0) {
lock (objLock) {
try {
string query = timeOffset != 0 ?
"SELECT Status FROM LinksLog WHERE LinkURL=@LinkURL AND LastUpdate>=@LastUpdate LIMIT 1" :
"SELECT Status FROM LinksLog WHERE LinkURL=@LinkURL LIMIT 1" ;
System.Data.SQLite.SQLiteCommand cmd = new System.Data.SQLite.SQLiteCommand();
cmd.Connection = cn;
cmd.CommandText = query;
cmd.CommandType = System.Data.CommandType.Text;
System.Data.SQLite.SQLiteParameter param = new System.Data.SQLite.SQLiteParameter();
param.ParameterName = "@LinkURL";
param.DbType = global::System.Data.DbType.String;
param.SourceColumn = "LinkURL";
cmd.Parameters.Add(param);
param = new System.Data.SQLite.SQLiteParameter();
param.ParameterName = "@LastUpdate";
param.DbType = global::System.Data.DbType.DateTime;
param.SourceColumn = "LastUpdate";
cmd.Parameters.Add(param);
cmd.Parameters[0].Value = url;
cmd.Parameters[1].Value = DateTime.Now.AddHours(timeOffset);
object obj = cmd.ExecuteScalar();
if (obj != null) return true;
return false;
} catch (Exception ex) {
Logger.Log(new object[] { "Error Code: DB06521", string.Format("MyDownloader.DBTools.GetStateByURL({0})", url), ex });
return false;
}
}
}
/// <summary>
/// Aggiorna il log relativo al link nel DB.
/// </summary>
+13 -3
View File
@@ -29,7 +29,17 @@ namespace A69WD.Net {
public string FilePath { get => filepath; }
public bool Validate => true;
public bool Validate {
get {
if (URL.StartsWith("https://www.annunci69.it/racconti-erotici/racconti_lista.php?genere=")) {
// URL di tipo Idx, devo lavorare i link nuovo o rilavorare i link più obsoleti di 6 ore.
return !App.DB.IsPresent(URL, -6);
} else {
// URL di tipo Rac, devo lavorare solo i link nuovi
return !App.DB.IsPresent(URL);
}
}
}
public eLinkState Status { get => status; set { status = value; } }
@@ -86,8 +96,8 @@ namespace A69WD.Net {
// Logger.Error("Errore inserendo A69 Start Link - " + ex.Message);
// return false;
//}
string url = LinkIdxBase.Replace("{Categoria}", "trio").Replace("{ID}", "1");
string name = "_A69_trio_0001.html";
string url = LinkIdxBase.Replace("{Categoria}", "altro").Replace("{ID}", "1"); //LinkIdxBase.Replace("{Categoria}", "trio").Replace("{ID}", "1");
string name = "_A69_altro_0001.html"; //"_A69_trio_0001.html";
service.EnqueueUrl(new cLink_A69(url, name));
return true;
}
+4 -4
View File
@@ -20,7 +20,7 @@ namespace A69WD.Net {
/// </summary>
ToDownload = 2,
/// <summary>
/// Indica un iLink che è in download
/// Indica un iLink che è in download
/// </summary>
OnDownload = 3,
/// <summary>
@@ -28,7 +28,7 @@ namespace A69WD.Net {
/// </summary>
ToAnalize = 4,
/// <summary>
/// Indica un iLink in cui si è concluso il lavoro.
/// Indica un iLink in cui si è concluso il lavoro.
/// </summary>
End = 5,
/// <summary>
@@ -36,11 +36,11 @@ namespace A69WD.Net {
/// </summary>
Error = 6,
/// <summary>
/// Indica un iLink il cui download/analisi è stato abortito
/// Indica un iLink il cui download/analisi è stato abortito
/// </summary>
Abort = 7,
/// <summary>
/// Indica un iLink il cui download/analisi è stato cancellato
/// Indica un iLink il cui download/analisi è stato cancellato
/// </summary>
Cancel = 8,
+10 -2
View File
@@ -22,7 +22,7 @@ namespace A69WD.Service {
private readonly BlockingCollection<iLink> _urlQueue = new BlockingCollection<iLink>(new ConcurrentQueue<iLink>());
// Semaforo per limitare il numero massimo di download simultanei
private readonly SemaphoreSlim _semaphore = new SemaphoreSlim(99);
private readonly SemaphoreSlim _semaphore = new SemaphoreSlim(9);
// Contatori
private int _inCorso = 0;
@@ -91,7 +91,15 @@ namespace A69WD.Service {
try {
List<iLink> urls = await _site.CrawlPageAsync(link);
Logger.Information("ProcessQueue: end url " + link.FileName + " - URL trovati: " + urls.Count.ToString("000"));
foreach (iLink url in urls) { _urlQueue.Add(url); }
foreach (iLink url in urls) {
if (url.Validate) {
// Logger.Warning("URL Validato: " + url.FileName);
App.DB.LinkLog(url);
_urlQueue.Add(url);
//} else {
// Logger.Warning("URL NON Validato: " + url.FileName);
}
}
} catch (Exception ex) {
Interlocked.Increment(ref _errori);
Logger.Error($"Errore su {link}: {ex.Message}");
+16 -12
View File
@@ -104,20 +104,24 @@ namespace A69WD.Site {
HtmlDocument tdoc = null;
#region ToConfirm
//if (lk.Status == eLinkState.ToConfirm) {
// // Eseguo la verifica se link da downloadare
// eLinkState tstate = App.DB.GetStateByURL(lk.URL);
// if (
// (tstate == eLinkState.ToConfirm) ||
// (tstate == eLinkState.ToDownload) ||
// (tstate == eLinkState.Error)
// ) {
// lk.Status = eLinkState.ToDownload;
// App.DB.LinkLog(lk);
// } else {
// lk.Status = eLinkState.End;
// App.DB.LinkLog(lk);
// }
//}
if (lk.Status == eLinkState.ToConfirm) {
// Eseguo la verifica se link da downloadare
eLinkState tstate = App.DB.GetStateByURL(lk.URL);
if (
(tstate == eLinkState.ToConfirm) ||
(tstate == eLinkState.ToDownload) ||
(tstate == eLinkState.Error)
) {
lk.Status = eLinkState.ToDownload;
App.DB.LinkLog(lk);
} else {
lk.Status = eLinkState.End;
App.DB.LinkLog(lk);
}
lk.Status = eLinkState.ToDownload;
}
#endregion