- Autocommit - 2021/10/27 11:01:11
This commit is contained in:
1 parent
b0b60c14a5
commit
ae8d3b0dce
7 files changed
+309
-40
No files matched your search
@@ -50,6 +50,7 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="App.cs" />
|
||||
<Compile Include="Data\DBTools.cs" />
|
||||
<Compile Include="Net\cA69Engine.cs" />
|
||||
<Compile Include="Net\frmDownloader.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
|
||||
+34
-34
@@ -140,43 +140,43 @@ namespace A69WD {
|
||||
#endregion
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Ricava dal DB tutti i dati
|
||||
/// </summary>
|
||||
/// <returns>Numero di link inseriti nell'engine. Un numero negativo se si è avuto un errore.</returns>
|
||||
public long RetrieveLinks() {
|
||||
// MRK: TODO:
|
||||
// Può essere utile amplificare questa funzione in modo che si possa specificare quali link reinserire:
|
||||
// Ad esempio dei filtri tipo:
|
||||
// - solo link con Status pari a ErrorDownload o CancelDownload
|
||||
// - solo link con Status pari a OnDownload
|
||||
// - ecc...
|
||||
///// <summary>
|
||||
///// Ricava dal DB tutti i dati
|
||||
///// </summary>
|
||||
///// <returns>Numero di link inseriti nell'engine. Un numero negativo se si è avuto un errore.</returns>
|
||||
//public long RetrieveLinks() {
|
||||
// // MRK: TODO:
|
||||
// // Può essere utile amplificare questa funzione in modo che si possa specificare quali link reinserire:
|
||||
// // Ad esempio dei filtri tipo:
|
||||
// // - solo link con Status pari a ErrorDownload o CancelDownload
|
||||
// // - solo link con Status pari a OnDownload
|
||||
// // - ecc...
|
||||
|
||||
//return 0; // MRK: BYPASSATO TUTTO PER EVITARE CHE ALL'INIZIO CARICHI I LINK IN SOSPESO.
|
||||
// //return 0; // MRK: BYPASSATO TUTTO PER EVITARE CHE ALL'INIZIO CARICHI I LINK IN SOSPESO.
|
||||
|
||||
object obj = new Object();
|
||||
lock (obj) {
|
||||
long Res = 0;
|
||||
System.Data.DataTable table = new System.Data.DataTable("LinksLog");
|
||||
try {
|
||||
System.Data.SQLite.SQLiteCommand cmd = new SQLiteCommand("SELECT [URL], [Tipo], [Status], [LastUp] FROM [LinksLog] WHERE [Tipo]='Testo' AND [Status]<>4", cn); // Donwloaded = 4
|
||||
SQLiteDataReader rdr = cmd.ExecuteReader();
|
||||
while (rdr.Read()) {
|
||||
string url = rdr["URL"] as string;
|
||||
ATLinkState status = ATLinkState.ToDownload;
|
||||
try { status = ((ATLinkState)((long)rdr["Status"])); } catch (Exception ex) { throw new Exception("ERRORE AFFABULANTE \n" + ex.Message); }
|
||||
// object obj = new Object();
|
||||
// lock (obj) {
|
||||
// long Res = 0;
|
||||
// System.Data.DataTable table = new System.Data.DataTable("LinksLog");
|
||||
// try {
|
||||
// System.Data.SQLite.SQLiteCommand cmd = new SQLiteCommand("SELECT [URL], [Tipo], [Status], [LastUp] FROM [LinksLog] WHERE [Tipo]='Testo' AND [Status]<>4", cn); // Donwloaded = 4
|
||||
// SQLiteDataReader rdr = cmd.ExecuteReader();
|
||||
// while (rdr.Read()) {
|
||||
// string url = rdr["URL"] as string;
|
||||
// ATLinkState status = ATLinkState.ToDownload;
|
||||
// try { status = ((ATLinkState)((long)rdr["Status"])); } catch (Exception ex) { throw new Exception("ERRORE AFFABULANTE \n" + ex.Message); }
|
||||
|
||||
ATLib.Net.ATLink lk = new ATLib.Net.ATLink(plugin, url, fileName, status);
|
||||
ATLib.ATWDEngine.Instance.AddLink(lk);
|
||||
Res++;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ATLib.Logger.Log(new object[] { "Error Code: DB07003", "Errore in ATLib.Data.DBTools.RetrieveLinks()", ex });
|
||||
if (Res > 0) Res = -1 * Res;
|
||||
}
|
||||
return Res;
|
||||
}
|
||||
}
|
||||
// ATLib.Net.ATLink lk = new ATLib.Net.ATLink(plugin, url, fileName, status);
|
||||
// ATLib.ATWDEngine.Instance.AddLink(lk);
|
||||
// Res++;
|
||||
// }
|
||||
// } catch (Exception ex) {
|
||||
// ATLib.Logger.Log(new object[] { "Error Code: DB07003", "Errore in ATLib.Data.DBTools.RetrieveLinks()", ex });
|
||||
// if (Res > 0) Res = -1 * Res;
|
||||
// }
|
||||
// return Res;
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -161,7 +161,7 @@ namespace A69WD {
|
||||
public virtual string PathDownloadWorking { get { return Path.Combine(PathApplicationRoot, "Down"); } }
|
||||
|
||||
/// <summary>
|
||||
/// Path della directory su cui riporto i file di indice correttamente analizzati.
|
||||
/// Path della directory su cui riporto i file di indice, correttamente analizzati.
|
||||
/// </summary>
|
||||
public virtual string PathAnalizadedIndexFile {
|
||||
get {
|
||||
@@ -177,7 +177,7 @@ namespace A69WD {
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Path della directory su cui riporto i file di indice correttamente analizzati.
|
||||
/// Path della directory su cui riporto i file dei racconti, correttamente analizzati.
|
||||
/// </summary>
|
||||
public virtual string PathAnalizadedRaccFile {
|
||||
get {
|
||||
|
||||
@@ -0,0 +1,233 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
|
||||
namespace A69WD {
|
||||
|
||||
public class cA69Engine {
|
||||
|
||||
|
||||
#region Property: State, Tipologie, BASE_URL, BASE_LINK_IDX, BASE_LINK_RAC
|
||||
|
||||
public EngineStatusEnum State { get { return state; } }
|
||||
|
||||
public int NumDownload { get { return downloaded.Count; } }
|
||||
|
||||
string[] Tipologie = { "altro", "bdsm", "gay", "incesto", "lesbo", "orge", "prime", "scambio", "tradimenti", "trans", "trio" };
|
||||
|
||||
const string BASE_URL = "https://www.annunci69.it/racconti-erotici/{Tip}.html";
|
||||
const string BASE_LINK_IDX = "https://www.annunci69.it/racconti-erotici/racconti_lista.php";
|
||||
const string BASE_LINK_RAC = "https://www.annunci69.it/racconti-erotici/";
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Fields: allLinks, toDownload, downloaded, racLinks, dtStartTime, aborting, downRac, state, wb
|
||||
|
||||
List<string> allLinks = null;
|
||||
List<string> toDownload = null;
|
||||
List<string> downloaded = null;
|
||||
List<string> racLinks = null;
|
||||
|
||||
DateTime dtStartTime;
|
||||
|
||||
bool aborting = false;
|
||||
bool downRac = false;
|
||||
|
||||
EngineStatusEnum state = EngineStatusEnum.NotReady;
|
||||
|
||||
WebBrowser wb = null;
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Costruttore e distruttore
|
||||
|
||||
public cA69Engine(WebBrowser WB) {
|
||||
// Inizializzo gli archivi (dai file in memoria)
|
||||
allLinks = new List<string>();
|
||||
toDownload = new List<string>();
|
||||
downloaded = new List<string>();
|
||||
racLinks = new List<string>();
|
||||
wb = WB;
|
||||
wb.DocumentCompleted += Wb_DocumentCompleted;
|
||||
// Per ora non serializzo gli archivi e quindi carico le pagine iniziali delle 11 tipologie:
|
||||
foreach (string tipologia in Tipologie) {
|
||||
toDownload.Add(BASE_URL.Replace("{Tip}", tipologia));
|
||||
allLinks.Add(BASE_URL.Replace("{Tip}", tipologia));
|
||||
}
|
||||
state = EngineStatusEnum.StandBy;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Method:
|
||||
|
||||
public bool Start(bool DownRac) {
|
||||
if (state != EngineStatusEnum.StandBy) return false;
|
||||
|
||||
dtStartTime = DateTime.Now;
|
||||
downRac = DownRac;
|
||||
|
||||
UpdateST("Inizio lo scrap dei link dei racconti");
|
||||
|
||||
state = EngineStatusEnum.Starting;
|
||||
|
||||
if (toDownload.Count > 0) {
|
||||
// proseguo con il download:
|
||||
string lk = toDownload.First();
|
||||
toDownload.Remove(lk);
|
||||
wb.Navigate(lk);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Stop() {
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
private void Wb_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) {
|
||||
object obj = new Object();
|
||||
lock (obj) {
|
||||
|
||||
StringBuilder sb;
|
||||
if (state == EngineStatusEnum.Starting) state = EngineStatusEnum.Started;
|
||||
|
||||
WebBrowser wb = sender as WebBrowser;
|
||||
string link = wb.Url.ToString();
|
||||
|
||||
// aggiorno UI
|
||||
UpdateST(wb.Name + " - Donwloaded: " + link);
|
||||
|
||||
// Se pagina è un racconto, lo salvo
|
||||
if (IsRacLink(link)) {
|
||||
sb = new StringBuilder();
|
||||
sb.Append(wb.DocumentText);
|
||||
string fn = Path.Combine(Cfg.Settings.PathAnalizadedRaccFile, GetFileName(link));
|
||||
cTools.WriteTextFile(fn, sb);
|
||||
}
|
||||
|
||||
// Registro che ho eseguito il download del link
|
||||
downloaded.Add(link);
|
||||
|
||||
// Ciclo su tutti i link estratti dalla pagina:
|
||||
foreach (HtmlElement item in wb.Document.Links) {
|
||||
link = item.GetAttribute("href");
|
||||
// Se link nuovo:
|
||||
if (!allLinks.Contains(link)) {
|
||||
// Link nuovo, mi comporto di conseguenza alla tipologia:
|
||||
if (IsRacLink(link)) {
|
||||
// Link ad un racconto
|
||||
allLinks.Add(link);
|
||||
if (downRac) { toDownload.Add(link); }
|
||||
racLinks.Add(link);
|
||||
} else {
|
||||
if (IsIdxLink(link)) {
|
||||
// Link ad un indice
|
||||
allLinks.Add(link);
|
||||
toDownload.Add(link);
|
||||
} else {
|
||||
// Link non riconosciuto, lo scarto
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // fine ciclo sui link estratti
|
||||
|
||||
// Se ho raggiunto il massimo numero di link, o non vi sono link da downloadare, mi fermo:
|
||||
if ((toDownload.Count > 0) && (state==EngineStatusEnum.Started)) {
|
||||
// proseguo con il download:
|
||||
string lk = toDownload.First();
|
||||
toDownload.Remove(lk);
|
||||
wb.Navigate(lk);
|
||||
} else {
|
||||
// Finito download:
|
||||
state = EngineStatusEnum.Stopping;
|
||||
// salvo gli archivi:
|
||||
SaveState();
|
||||
}
|
||||
|
||||
}//lock
|
||||
}
|
||||
|
||||
|
||||
private void SaveState() {
|
||||
StringBuilder sb;
|
||||
|
||||
// Finito download, salvo gli archivi:
|
||||
string dt = DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss");
|
||||
|
||||
// Salvo archivio: AllLinks
|
||||
sb = new StringBuilder();
|
||||
allLinks.Sort();
|
||||
foreach (string lnk in allLinks) { sb.AppendLine(lnk); }
|
||||
cTools.WriteTextFile(Path.Combine(Cfg.Settings.PathAnalizadedIndexFile, string.Format("_A69_AllLinks_{0}.tes", dt)), sb);
|
||||
|
||||
// Salvo archivio: toDownload
|
||||
sb = new StringBuilder();
|
||||
toDownload.Sort();
|
||||
foreach (string lnk in toDownload) { sb.AppendLine(lnk); }
|
||||
cTools.WriteTextFile(Path.Combine(Cfg.Settings.PathAnalizadedIndexFile, string.Format("_A69_toDownload_{0}.tes", dt)), sb);
|
||||
|
||||
// Salvo archivio: Downloaded
|
||||
sb = new StringBuilder();
|
||||
downloaded.Sort();
|
||||
foreach (string lnk in downloaded) { sb.AppendLine(lnk); }
|
||||
cTools.WriteTextFile(Path.Combine(Cfg.Settings.PathAnalizadedIndexFile, string.Format("_A69_Downloaded_{0}.tes", dt)), sb);
|
||||
|
||||
// Salvo archivio: RacLinks
|
||||
sb = new StringBuilder();
|
||||
racLinks.Sort();
|
||||
foreach (string lnk in racLinks) { sb.AppendLine(lnk); }
|
||||
cTools.WriteTextFile(Path.Combine(Cfg.Settings.PathAnalizadedIndexFile, string.Format("_A69_RacLinks_{0}.tes", dt)), sb);
|
||||
|
||||
// avviso utente:
|
||||
UpdateST(string.Format("Finito il download in {0}", DateTime.Now - dtStartTime));
|
||||
|
||||
state = EngineStatusEnum.Stopped;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private void UpdateST(string Msg) {
|
||||
//lblST.Text = string.Format("{0} - {1} - {2}", DateTime.Now.ToString("HH:mm:ss"), cnt.ToString("0000"), Msg);
|
||||
}
|
||||
private string GetFileName(string url) { return url.Replace("https://www.annunci69.it/racconti-erotici/", "A69_").Replace("/", "_").Replace(":", "_").Replace(@"\", "_"); }
|
||||
private bool IsIdxLink(string link) { return link.StartsWith(BASE_LINK_IDX); }
|
||||
private bool IsRacLink(string link) { foreach (string tip in Tipologie) { if (link.StartsWith(BASE_LINK_RAC + tip + "/")) return true; } return false; }
|
||||
|
||||
|
||||
}//class cA69Engine
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Enumerazione di tutti i possibili stati dell'engine:
|
||||
/// </summary>
|
||||
public enum EngineStatusEnum {
|
||||
/// <summary>
|
||||
/// Engine da inizializzare
|
||||
/// </summary>
|
||||
NotReady = 1,
|
||||
/// <summary>
|
||||
/// Engine inizializzato e pronto a partire
|
||||
/// </summary>
|
||||
StandBy = 1,
|
||||
Starting = 2,
|
||||
Started = 3,
|
||||
Stopping = 4,
|
||||
Stopped = 5,
|
||||
} // enum EngineStatusEnum
|
||||
|
||||
}//namespace A69WD
|
||||
Generated
+4
@@ -61,6 +61,7 @@
|
||||
this.btnClose.TabIndex = 14;
|
||||
this.btnClose.Text = "Close";
|
||||
this.btnClose.UseVisualStyleBackColor = true;
|
||||
this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
|
||||
//
|
||||
// btnHide
|
||||
//
|
||||
@@ -70,6 +71,7 @@
|
||||
this.btnHide.TabIndex = 13;
|
||||
this.btnHide.Text = "Hide";
|
||||
this.btnHide.UseVisualStyleBackColor = true;
|
||||
this.btnHide.Click += new System.EventHandler(this.btnHide_Click);
|
||||
//
|
||||
// btnDownloadAll
|
||||
//
|
||||
@@ -79,6 +81,7 @@
|
||||
this.btnDownloadAll.TabIndex = 11;
|
||||
this.btnDownloadAll.Text = "Download All";
|
||||
this.btnDownloadAll.UseVisualStyleBackColor = true;
|
||||
this.btnDownloadAll.Click += new System.EventHandler(this.btnDownloadAll_Click);
|
||||
//
|
||||
// lblST
|
||||
//
|
||||
@@ -111,6 +114,7 @@
|
||||
this.btnDownloadLink.TabIndex = 10;
|
||||
this.btnDownloadLink.Text = "Download only Link";
|
||||
this.btnDownloadLink.UseVisualStyleBackColor = true;
|
||||
this.btnDownloadLink.Click += new System.EventHandler(this.btnDownloadLink_Click);
|
||||
//
|
||||
// frmDownloader
|
||||
//
|
||||
|
||||
@@ -8,9 +8,39 @@ using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace A69WD {
|
||||
|
||||
public partial class frmDownloader : Form {
|
||||
|
||||
|
||||
public frmDownloader() {
|
||||
InitializeComponent();
|
||||
engine = new cA69Engine(this.wb1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cA69Engine engine = null;
|
||||
|
||||
|
||||
private void btnDownloadLink_Click(object sender, EventArgs e) {
|
||||
engine.Start(false);
|
||||
}
|
||||
|
||||
private void btnDownloadAll_Click(object sender, EventArgs e) {
|
||||
engine.Start(true);
|
||||
}
|
||||
|
||||
private void btnHide_Click(object sender, EventArgs e) {
|
||||
this.Hide();
|
||||
}
|
||||
|
||||
private void btnClose_Click(object sender, EventArgs e) {
|
||||
if ((engine.State == EngineStatusEnum.Stopped) || (engine.State == EngineStatusEnum.StandBy)) {
|
||||
this.Close();
|
||||
} else {
|
||||
engine.Stop();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}//class frmDownloader
|
||||
}//namespace A69WD
|
||||
@@ -3,8 +3,9 @@
|
||||
|
||||
|
||||
<!-- Path root dell'applicazione. Da questo derivano tutti gli altri path. -->
|
||||
<PathApplicationRoot>C:\Temporary\A69WD</PathApplicationRoot>
|
||||
|
||||
<!-- <PathApplicationRoot>C:\Temporary\A69WD</PathApplicationRoot> -->
|
||||
<PathApplicationRoot>D:\Project\Private\Prj\MyTools\A69WD\Test</PathApplicationRoot>
|
||||
|
||||
<!-- Nome del database usato dall'applicazione. -->
|
||||
<DBName>A69DB.db</DBName>
|
||||
|
||||
|
||||
Reference in new issue
Block a user