- Autocommit - 2022/09/22 10:48:33
This commit is contained in:
1 parent
edfeae72a6
commit
e2dd13631a
5 files changed
+625
-11
No files matched your search
@@ -63,6 +63,7 @@
|
|||||||
<Compile Include="Net\ATLink.cs" />
|
<Compile Include="Net\ATLink.cs" />
|
||||||
<Compile Include="Net\ATLinkState.cs" />
|
<Compile Include="Net\ATLinkState.cs" />
|
||||||
<Compile Include="Net\cA69Engine.cs" />
|
<Compile Include="Net\cA69Engine.cs" />
|
||||||
|
<Compile Include="Net\cA69Engine3.cs" />
|
||||||
<Compile Include="Net\cA69Engine2.cs" />
|
<Compile Include="Net\cA69Engine2.cs" />
|
||||||
<Compile Include="Net\DownloadClient.cs" />
|
<Compile Include="Net\DownloadClient.cs" />
|
||||||
<Compile Include="Net\frmDownloader.cs">
|
<Compile Include="Net\frmDownloader.cs">
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ using System.Collections;
|
|||||||
|
|
||||||
namespace A69WD {
|
namespace A69WD {
|
||||||
|
|
||||||
public class cA69Engine2 {
|
public class cA69Engine3 {
|
||||||
|
|
||||||
|
|
||||||
#region Property: State, NumDownload, Tipologie, BASE_URL, BASE_LINK_IDX, BASE_LINK_RAC
|
#region Property: State, NumDownload, Tipologie, BASE_URL, BASE_LINK_IDX, BASE_LINK_RAC
|
||||||
@@ -50,7 +50,7 @@ namespace A69WD {
|
|||||||
|
|
||||||
#region Costruttore e distruttore
|
#region Costruttore e distruttore
|
||||||
|
|
||||||
public cA69Engine2() {
|
public cA69Engine3() {
|
||||||
try {
|
try {
|
||||||
// Inizializzo gli archivi (dai file in memoria)
|
// Inizializzo gli archivi (dai file in memoria)
|
||||||
allLinks = new List<string>();
|
allLinks = new List<string>();
|
||||||
@@ -90,9 +90,9 @@ namespace A69WD {
|
|||||||
// proseguo con il download:
|
// proseguo con il download:
|
||||||
string lk = toDownload.First();
|
string lk = toDownload.First();
|
||||||
toDownload.Remove(lk);
|
toDownload.Remove(lk);
|
||||||
using (WebClient client = new WebClient()) {
|
string fn = Path.Combine(Cfg.Settings.PathAnalizadedRaccFile, GetFileName(lk));
|
||||||
string fn = Path.Combine(Cfg.Settings.PathAnalizadedRaccFile, GetFileName(lk));
|
using (MyWebClient client = new MyWebClient(lk, fn)) {
|
||||||
client.Encoding = Encoding.Unicode;
|
//client.Encoding = Encoding.ASCII;
|
||||||
client.Headers.Add("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:88.0) Gecko/20100101 Firefox/88.0");
|
client.Headers.Add("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:88.0) Gecko/20100101 Firefox/88.0");
|
||||||
client.Headers.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
|
client.Headers.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
|
||||||
client.Headers.Add("Cookie", "euconsent-v2=CPG74goPG74goAKAeAENBcCsAP_AAH_AAAwIH3tf_X__bX9j-_59__t0eY1f9_7_v-wzjhfdt-8N2P_X_L0X42E7PF36pq4KuR4Eu3LBIQNlHOHUTUmw6okVrTPsak2Mr7NKJ7LEmnMZe2dYGHtfn91TuZKY7_78_9fz3_-v_v___9f3r-3_3__59X---_e_V399zLv9__3__9gfiASYal8AF2JY4Mk0aVQogQhWEh0AoAKKAYWiawgYXBTsrAI9QQMAEJqAjAiBBiCjFgEAAgEASERASAHggEQBEAgABACpAQgAImAQWAFgYBAAKAaFiBFAEIEhBkcFRymBARItFBPZWAJRd7GmEIZRYAUCj-iowEShBAsDISFg5gAA.YAAAAAAAAAAA");
|
client.Headers.Add("Cookie", "euconsent-v2=CPG74goPG74goAKAeAENBcCsAP_AAH_AAAwIH3tf_X__bX9j-_59__t0eY1f9_7_v-wzjhfdt-8N2P_X_L0X42E7PF36pq4KuR4Eu3LBIQNlHOHUTUmw6okVrTPsak2Mr7NKJ7LEmnMZe2dYGHtfn91TuZKY7_78_9fz3_-v_v___9f3r-3_3__59X---_e_V399zLv9__3__9gfiASYal8AF2JY4Mk0aVQogQhWEh0AoAKKAYWiawgYXBTsrAI9QQMAEJqAjAiBBiCjFgEAAgEASERASAHggEQBEAgABACpAQgAImAQWAFgYBAAKAaFiBFAEIEhBkcFRymBARItFBPZWAJRd7GmEIZRYAUCj-iowEShBAsDISFg5gAA.YAAAAAAAAAAA");
|
||||||
@@ -102,15 +102,16 @@ namespace A69WD {
|
|||||||
client.DownloadProgressChanged += Client_DownloadProgressChanged;
|
client.DownloadProgressChanged += Client_DownloadProgressChanged;
|
||||||
client.DownloadFileCompleted += Client_DownloadFileCompleted;
|
client.DownloadFileCompleted += Client_DownloadFileCompleted;
|
||||||
client.DownloadDataCompleted += Client_DownloadDataCompleted;
|
client.DownloadDataCompleted += Client_DownloadDataCompleted;
|
||||||
|
client.DownloadStringCompleted += Client_DownloadStringCompleted;
|
||||||
//client.DownloadFileAsync(new Uri(lk), fn);
|
//client.DownloadFileAsync(new Uri(lk), fn);
|
||||||
client.DownloadDataAsync(new Uri(lk));
|
//client.DownloadDataAsync(new Uri(lk));
|
||||||
|
client.DownloadStringAsync(new Uri(lk));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public bool Stop() {
|
public bool Stop() {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case EngineStatusEnum.NotReady:
|
case EngineStatusEnum.NotReady:
|
||||||
@@ -333,7 +334,13 @@ namespace A69WD {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private string GetFileName(string url) { return url.Replace("https://www.annunci69.it/racconti-erotici/", "A69_").Replace("/", "_").Replace(":", "_").Replace(@"\", "_"); }
|
private string GetFileName(string url) {
|
||||||
|
if (IsRacLink(url)) {
|
||||||
|
return url.Replace("https://www.annunci69.it/racconti-erotici/", "A69_").Replace("/", "_").Replace(":", "_").Replace(@"\", "_");
|
||||||
|
} else {
|
||||||
|
return url.Replace("https://www.annunci69.it/racconti-erotici/", "_A69_").Replace("/", "_").Replace(":", "_").Replace(@"\", "_");
|
||||||
|
}
|
||||||
|
}
|
||||||
static private bool IsIdxLink(string link) { return link.StartsWith(BASE_LINK_IDX); }
|
static private bool IsIdxLink(string link) { return link.StartsWith(BASE_LINK_IDX); }
|
||||||
static private bool IsRacLink(string link) { foreach (string tip in Tipologie) { if (link.StartsWith(BASE_LINK_RAC + tip + "/")) return true; } return false; }
|
static private bool IsRacLink(string link) { foreach (string tip in Tipologie) { if (link.StartsWith(BASE_LINK_RAC + tip + "/")) return true; } return false; }
|
||||||
|
|
||||||
@@ -460,6 +467,60 @@ namespace A69WD {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void Client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) {
|
||||||
|
object obj = new Object();
|
||||||
|
lock (obj) {
|
||||||
|
|
||||||
|
conteggioEvt++;
|
||||||
|
|
||||||
|
MyWebClient mwb = sender as MyWebClient;
|
||||||
|
|
||||||
|
// aggiorno UI
|
||||||
|
RaiseEvent_Updating("(Evt" + conteggioEvt.ToString("0000") + ") Donwloaded: " + mwb.URL.Replace("https://www.annunci69.it/racconti-erotici/", "./"));
|
||||||
|
|
||||||
|
// Salvo il testo downloadato
|
||||||
|
if (!e.Cancelled && e.Error == null) {
|
||||||
|
string textData = e.Result;
|
||||||
|
string FullFileName = mwb.FileName;
|
||||||
|
System.IO.StreamWriter sw = new System.IO.StreamWriter(FullFileName,false, Encoding.UTF8);
|
||||||
|
sw.Write(textData);
|
||||||
|
sw.Flush();
|
||||||
|
sw.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
string fn = Path.Combine(Cfg.Settings.PathAnalizadedRaccFile, GetFileName(lk));
|
||||||
|
using (MyWebClient client = new MyWebClient(lk, fn)) {
|
||||||
|
//client.Encoding = Encoding.ASCII;
|
||||||
|
client.Headers.Add("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:88.0) Gecko/20100101 Firefox/88.0");
|
||||||
|
client.Headers.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
|
||||||
|
client.Headers.Add("Cookie", "euconsent-v2=CPG74goPG74goAKAeAENBcCsAP_AAH_AAAwIH3tf_X__bX9j-_59__t0eY1f9_7_v-wzjhfdt-8N2P_X_L0X42E7PF36pq4KuR4Eu3LBIQNlHOHUTUmw6okVrTPsak2Mr7NKJ7LEmnMZe2dYGHtfn91TuZKY7_78_9fz3_-v_v___9f3r-3_3__59X---_e_V399zLv9__3__9gfiASYal8AF2JY4Mk0aVQogQhWEh0AoAKKAYWiawgYXBTsrAI9QQMAEJqAjAiBBiCjFgEAAgEASERASAHggEQBEAgABACpAQgAImAQWAFgYBAAKAaFiBFAEIEhBkcFRymBARItFBPZWAJRd7GmEIZRYAUCj-iowEShBAsDISFg5gAA.YAAAAAAAAAAA");
|
||||||
|
client.Headers.Add("DNT", "1");
|
||||||
|
client.Headers.Add("TE", "Trailers");
|
||||||
|
//client.DownloadFile(new Uri(lk), fn);
|
||||||
|
client.DownloadProgressChanged += Client_DownloadProgressChanged;
|
||||||
|
client.DownloadFileCompleted += Client_DownloadFileCompleted;
|
||||||
|
client.DownloadDataCompleted += Client_DownloadDataCompleted;
|
||||||
|
client.DownloadStringCompleted += Client_DownloadStringCompleted;
|
||||||
|
//client.DownloadFileAsync(new Uri(lk), fn);
|
||||||
|
//client.DownloadDataAsync(new Uri(lk));
|
||||||
|
client.DownloadStringAsync(new Uri(lk));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Finito download:
|
||||||
|
state = EngineStatusEnum.Stopping;
|
||||||
|
// salvo gli archivi:
|
||||||
|
SaveState();
|
||||||
|
}
|
||||||
|
|
||||||
|
}//lock
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private void Client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) {
|
private void Client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) {
|
||||||
////Update progress bar & label
|
////Update progress bar & label
|
||||||
//Invoke(new MethodInvoker(delegate () {
|
//Invoke(new MethodInvoker(delegate () {
|
||||||
@@ -473,5 +534,16 @@ namespace A69WD {
|
|||||||
}
|
}
|
||||||
}//class cA69Engine2
|
}//class cA69Engine2
|
||||||
|
|
||||||
|
public class MyWebClient : WebClient {
|
||||||
|
|
||||||
|
public string URL;
|
||||||
|
public string FileName;
|
||||||
|
public MyWebClient(string url, string fileName) {
|
||||||
|
this.URL = url;
|
||||||
|
this.FileName = fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}//namespace A69WD
|
}//namespace A69WD
|
||||||
@@ -0,0 +1,519 @@
|
|||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using System.Security.Policy;
|
||||||
|
using System.Net;
|
||||||
|
using static System.Windows.Forms.LinkLabel;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using static System.Net.Mime.MediaTypeNames;
|
||||||
|
using System.Collections;
|
||||||
|
|
||||||
|
namespace A69WD {
|
||||||
|
|
||||||
|
public class cA69Engine2 {
|
||||||
|
|
||||||
|
|
||||||
|
#region Property: State, NumDownload, Tipologie, BASE_URL, BASE_LINK_IDX, BASE_LINK_RAC
|
||||||
|
|
||||||
|
public EngineStatusEnum State { get { return state; } }
|
||||||
|
|
||||||
|
public int NumDownload { get { return downloaded.Count; } }
|
||||||
|
|
||||||
|
static 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, downRac, state
|
||||||
|
|
||||||
|
List<string> allLinks = null;
|
||||||
|
List<string> toDownload = null;
|
||||||
|
List<string> downloaded = null;
|
||||||
|
List<string> racLinks = null;
|
||||||
|
|
||||||
|
DateTime dtStartTime;
|
||||||
|
|
||||||
|
bool downRac = false;
|
||||||
|
|
||||||
|
EngineStatusEnum state = EngineStatusEnum.NotReady;
|
||||||
|
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region Costruttore e distruttore
|
||||||
|
|
||||||
|
public cA69Engine2() {
|
||||||
|
try {
|
||||||
|
// Inizializzo gli archivi (dai file in memoria)
|
||||||
|
allLinks = new List<string>();
|
||||||
|
toDownload = new List<string>();
|
||||||
|
downloaded = new List<string>();
|
||||||
|
racLinks = new List<string>();
|
||||||
|
int res = App.DB.LoadData(allLinks, toDownload, downloaded, racLinks);
|
||||||
|
RaiseEvent_Updating("Ricaricati " + res.ToString("000") + " link di racconti da scaricare");
|
||||||
|
// 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));
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
Logger.Log(new object[] { "Error Code: ER02220", "Errore in cA69Engine()", ex });
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
state = EngineStatusEnum.StandBy;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region Method:
|
||||||
|
|
||||||
|
public bool Start(bool DownRac) {
|
||||||
|
if (state != EngineStatusEnum.StandBy) return false;
|
||||||
|
|
||||||
|
dtStartTime = DateTime.Now;
|
||||||
|
downRac = DownRac;
|
||||||
|
|
||||||
|
RaiseEvent_Updating("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);
|
||||||
|
using (WebClient client = new WebClient()) {
|
||||||
|
string fn = Path.Combine(Cfg.Settings.PathAnalizadedRaccFile, GetFileName(lk));
|
||||||
|
//client.Encoding = Encoding.ASCII;
|
||||||
|
client.Headers.Add("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:88.0) Gecko/20100101 Firefox/88.0");
|
||||||
|
client.Headers.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
|
||||||
|
client.Headers.Add("Cookie", "euconsent-v2=CPG74goPG74goAKAeAENBcCsAP_AAH_AAAwIH3tf_X__bX9j-_59__t0eY1f9_7_v-wzjhfdt-8N2P_X_L0X42E7PF36pq4KuR4Eu3LBIQNlHOHUTUmw6okVrTPsak2Mr7NKJ7LEmnMZe2dYGHtfn91TuZKY7_78_9fz3_-v_v___9f3r-3_3__59X---_e_V399zLv9__3__9gfiASYal8AF2JY4Mk0aVQogQhWEh0AoAKKAYWiawgYXBTsrAI9QQMAEJqAjAiBBiCjFgEAAgEASERASAHggEQBEAgABACpAQgAImAQWAFgYBAAKAaFiBFAEIEhBkcFRymBARItFBPZWAJRd7GmEIZRYAUCj-iowEShBAsDISFg5gAA.YAAAAAAAAAAA");
|
||||||
|
client.Headers.Add("DNT", "1");
|
||||||
|
client.Headers.Add("TE", "Trailers");
|
||||||
|
//client.DownloadFile(new Uri(lk), fn);
|
||||||
|
client.DownloadProgressChanged += Client_DownloadProgressChanged;
|
||||||
|
client.DownloadFileCompleted += Client_DownloadFileCompleted;
|
||||||
|
client.DownloadDataCompleted += Client_DownloadDataCompleted;
|
||||||
|
client.DownloadStringCompleted += Client_DownloadStringCompleted;
|
||||||
|
//client.DownloadFileAsync(new Uri(lk), fn);
|
||||||
|
//client.DownloadDataAsync(new Uri(lk));
|
||||||
|
client.DownloadStringAsync(new Uri(lk));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Stop() {
|
||||||
|
switch (state) {
|
||||||
|
case EngineStatusEnum.NotReady:
|
||||||
|
case EngineStatusEnum.StandBy:
|
||||||
|
SaveState();
|
||||||
|
state = EngineStatusEnum.Stopped;
|
||||||
|
return true;
|
||||||
|
case EngineStatusEnum.Starting:
|
||||||
|
case EngineStatusEnum.Started:
|
||||||
|
case EngineStatusEnum.Stopping:
|
||||||
|
state = EngineStatusEnum.Stopping;
|
||||||
|
return false;
|
||||||
|
case EngineStatusEnum.Stopped:
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int ImportLinkFromFile(string SrcFilePath) {
|
||||||
|
int res = 0;
|
||||||
|
try {
|
||||||
|
if (File.Exists(SrcFilePath)) {
|
||||||
|
StreamReader sr = new StreamReader(SrcFilePath, Encoding.UTF8);
|
||||||
|
string row = sr.ReadLine().Trim();
|
||||||
|
while (row != null) {
|
||||||
|
// verifico che non sia un commento:
|
||||||
|
if (!(row.StartsWith("#") || row.StartsWith("//"))) {
|
||||||
|
// Se link nuovo:
|
||||||
|
if (!allLinks.Contains(row)) {
|
||||||
|
// Link nuovo, mi comporto di conseguenza alla tipologia:
|
||||||
|
if (IsRacLink(row)) {
|
||||||
|
// Link ad un racconto
|
||||||
|
allLinks.Add(row);
|
||||||
|
toDownload.Add(row);
|
||||||
|
racLinks.Add(row);
|
||||||
|
res++;
|
||||||
|
} else {
|
||||||
|
if (IsIdxLink(row)) {
|
||||||
|
// Link ad un indice
|
||||||
|
allLinks.Add(row);
|
||||||
|
toDownload.Add(row);
|
||||||
|
res++;
|
||||||
|
} else {
|
||||||
|
// Link non riconosciuto, lo scarto
|
||||||
|
;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//Read the next line
|
||||||
|
row = sr.ReadLine();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception ex) {
|
||||||
|
Logger.Log(new object[] { "Error Code: DB07403", "Errore in ImportLinkFromFile()", ex });
|
||||||
|
if (res > 0) res = -1 * res;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region Eventi:
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Evento che indica un cambiamento di stato nell'AnalizeManager
|
||||||
|
/// </summary>
|
||||||
|
public event EventHandler<EngineEventArgs> Updating;
|
||||||
|
|
||||||
|
|
||||||
|
#region Generazione degli eventi dell'engine verso le classi chiamanti:
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Attiva l'evento che segnala un cambiamento di stato nel engine (per esempio, terminato il download di un singolo file)
|
||||||
|
/// </summary>
|
||||||
|
void RaiseEvent_Updating(string msg, int tot, int toDown, int down) {
|
||||||
|
EventHandler<EngineEventArgs> tmp = Updating;
|
||||||
|
if (null != tmp) tmp(this, new EngineEventArgs(msg, tot, toDown, down));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Attiva l'evento che segnala un cambiamento di stato nel engine (per esempio, terminato il download di un singolo file)
|
||||||
|
/// </summary>
|
||||||
|
void RaiseEvent_Updating(string msg) {
|
||||||
|
EventHandler<EngineEventArgs> tmp = Updating;
|
||||||
|
if (null != tmp) tmp(this, new EngineEventArgs(msg, allLinks.Count, toDownload.Count, downloaded.Count));
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
int conteggioEvt = 0;
|
||||||
|
|
||||||
|
|
||||||
|
private void Wb_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) {
|
||||||
|
object obj = new Object();
|
||||||
|
lock (obj) {
|
||||||
|
|
||||||
|
conteggioEvt++;
|
||||||
|
|
||||||
|
StringBuilder sb;
|
||||||
|
if (state == EngineStatusEnum.Starting) state = EngineStatusEnum.Started;
|
||||||
|
|
||||||
|
WebBrowser wb = sender as WebBrowser;
|
||||||
|
string link = wb.Url.ToString();
|
||||||
|
|
||||||
|
// Se link di logon, devo terminare i download
|
||||||
|
if (link == "https://www.annunci69.it/accedi.php?nop") {
|
||||||
|
// Finito download:
|
||||||
|
state = EngineStatusEnum.Stopping;
|
||||||
|
// salvo gli archivi:
|
||||||
|
SaveState();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Elimino ulteriori ripetizioni dell'evento:
|
||||||
|
if (downloaded.Contains(link)) return;
|
||||||
|
|
||||||
|
// aggiorno UI
|
||||||
|
RaiseEvent_Updating(wb.Name + " - (Evt" + conteggioEvt.ToString("0000") + ") Donwloaded: " + link.Replace("https://www.annunci69.it/racconti-erotici/", "./"));
|
||||||
|
|
||||||
|
// Se pagina è un racconto, lo salvo
|
||||||
|
if (IsRacLink(link)) {
|
||||||
|
sb = new StringBuilder();
|
||||||
|
sb.Append(wb.Document.Body.InnerHtml);
|
||||||
|
string fn = Path.Combine(Cfg.Settings.PathAnalizadedRaccFile, GetFileName(link));
|
||||||
|
//cTools.WriteTextFile(fn, sb, Encoding.GetEncoding(wb.Document.Encoding));
|
||||||
|
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)) {
|
||||||
|
// elimino il link di logon
|
||||||
|
if (link == "https://www.annunci69.it/accedi.php?nop") break;
|
||||||
|
// 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() {
|
||||||
|
int res = App.DB.SaveData(allLinks, toDownload, downloaded, racLinks);
|
||||||
|
|
||||||
|
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:
|
||||||
|
RaiseEvent_Updating(string.Format("Finito il download in {0}", DateTime.Now - dtStartTime));
|
||||||
|
|
||||||
|
state = EngineStatusEnum.Stopped;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private string GetFileName(string url) { return url.Replace("https://www.annunci69.it/racconti-erotici/", "A69_").Replace("/", "_").Replace(":", "_").Replace(@"\", "_"); }
|
||||||
|
static private bool IsIdxLink(string link) { return link.StartsWith(BASE_LINK_IDX); }
|
||||||
|
static private bool IsRacLink(string link) { foreach (string tip in Tipologie) { if (link.StartsWith(BASE_LINK_RAC + tip + "/")) return true; } return false; }
|
||||||
|
|
||||||
|
static public string LinkType(string link) {
|
||||||
|
if (IsIdxLink(link)) return "Idx";
|
||||||
|
if (IsRacLink(link)) return "Rac";
|
||||||
|
//return "Unknown";
|
||||||
|
return "Unk";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private void Client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e) {
|
||||||
|
object obj = new Object();
|
||||||
|
lock (obj) {
|
||||||
|
|
||||||
|
conteggioEvt++;
|
||||||
|
|
||||||
|
StringBuilder sb;
|
||||||
|
if (state == EngineStatusEnum.Starting) state = EngineStatusEnum.Started;
|
||||||
|
|
||||||
|
WebClient wb = sender as WebClient;
|
||||||
|
string link = wb.BaseAddress;
|
||||||
|
|
||||||
|
return;
|
||||||
|
/*
|
||||||
|
// Se link di logon, devo terminare i download
|
||||||
|
if (link == "https://www.annunci69.it/accedi.php?nop") {
|
||||||
|
// Finito download:
|
||||||
|
state = EngineStatusEnum.Stopping;
|
||||||
|
// salvo gli archivi:
|
||||||
|
SaveState();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Elimino ulteriori ripetizioni dell'evento:
|
||||||
|
if (downloaded.Contains(link)) return;
|
||||||
|
|
||||||
|
// aggiorno UI
|
||||||
|
RaiseEvent_Updating(wb.Name + " - (Evt" + conteggioEvt.ToString("0000") + ") Donwloaded: " + link.Replace("https://www.annunci69.it/racconti-erotici/", "./"));
|
||||||
|
|
||||||
|
// Se pagina è un racconto, lo salvo
|
||||||
|
if (IsRacLink(link)) {
|
||||||
|
sb = new StringBuilder();
|
||||||
|
sb.Append(wb.Document.Body.InnerHtml);
|
||||||
|
string fn = Path.Combine(Cfg.Settings.PathAnalizadedRaccFile, GetFileName(link));
|
||||||
|
//cTools.WriteTextFile(fn, sb, Encoding.GetEncoding(wb.Document.Encoding));
|
||||||
|
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)) {
|
||||||
|
// elimino il link di logon
|
||||||
|
if (link == "https://www.annunci69.it/accedi.php?nop") break;
|
||||||
|
// 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 Client_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e) {
|
||||||
|
//System.Threading.AutoResetEvent waiter = (System.Threading.AutoResetEvent)e.UserState;
|
||||||
|
|
||||||
|
try {
|
||||||
|
// If the request was not canceled and did not throw
|
||||||
|
// an exception, display the resource.
|
||||||
|
if (!e.Cancelled && e.Error == null) {
|
||||||
|
byte[] data = (byte[])e.Result;
|
||||||
|
string textData = System.Text.Encoding.Unicode.GetString(data);
|
||||||
|
string FullFileName = @"C:\VMS\Prj\C#\A69WD\Test\Txt\Src\2022-09-22\A69_altroz.html";
|
||||||
|
|
||||||
|
//System.IO.StreamWriter sw = new System.IO.StreamWriter(FullFileName, false, Encoding.Unicode);
|
||||||
|
//sw.Write(textData);
|
||||||
|
//sw.Flush();
|
||||||
|
//sw.Close();
|
||||||
|
|
||||||
|
using (var fs = new FileStream(FullFileName, FileMode.Create, FileAccess.Write)) {
|
||||||
|
fs.Write(data, 0, data.Length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
// Let the main application thread resume.
|
||||||
|
//waiter.Set();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) {
|
||||||
|
object obj = new Object();
|
||||||
|
lock (obj) {
|
||||||
|
|
||||||
|
conteggioEvt++;
|
||||||
|
|
||||||
|
if (!e.Cancelled && e.Error == null) {
|
||||||
|
string textData = e.Result;
|
||||||
|
string FullFileName = @"C:\VMS\Prj\C#\A69WD\Test\Txt\Src\2022-09-22\A69_altroZZ.html";
|
||||||
|
//System.IO.StreamWriter sw = new System.IO.StreamWriter(FullFileName, false, Encoding.Unicode);
|
||||||
|
System.IO.StreamWriter sw = new System.IO.StreamWriter(FullFileName,false, Encoding.UTF8);
|
||||||
|
sw.Write(textData);
|
||||||
|
sw.Flush();
|
||||||
|
sw.Close();
|
||||||
|
|
||||||
|
string lk = toDownload.First();
|
||||||
|
toDownload.Remove(lk);
|
||||||
|
using (WebClient client = new WebClient()) {
|
||||||
|
string fn = Path.Combine(Cfg.Settings.PathAnalizadedRaccFile, GetFileName(lk));
|
||||||
|
//client.Encoding = Encoding.ASCII;
|
||||||
|
client.Headers.Add("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:88.0) Gecko/20100101 Firefox/88.0");
|
||||||
|
client.Headers.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
|
||||||
|
client.Headers.Add("Cookie", "euconsent-v2=CPG74goPG74goAKAeAENBcCsAP_AAH_AAAwIH3tf_X__bX9j-_59__t0eY1f9_7_v-wzjhfdt-8N2P_X_L0X42E7PF36pq4KuR4Eu3LBIQNlHOHUTUmw6okVrTPsak2Mr7NKJ7LEmnMZe2dYGHtfn91TuZKY7_78_9fz3_-v_v___9f3r-3_3__59X---_e_V399zLv9__3__9gfiASYal8AF2JY4Mk0aVQogQhWEh0AoAKKAYWiawgYXBTsrAI9QQMAEJqAjAiBBiCjFgEAAgEASERASAHggEQBEAgABACpAQgAImAQWAFgYBAAKAaFiBFAEIEhBkcFRymBARItFBPZWAJRd7GmEIZRYAUCj-iowEShBAsDISFg5gAA.YAAAAAAAAAAA");
|
||||||
|
client.Headers.Add("DNT", "1");
|
||||||
|
client.Headers.Add("TE", "Trailers");
|
||||||
|
//client.DownloadFile(new Uri(lk), fn);
|
||||||
|
client.DownloadProgressChanged += Client_DownloadProgressChanged;
|
||||||
|
client.DownloadFileCompleted += Client_DownloadFileCompleted;
|
||||||
|
client.DownloadDataCompleted += Client_DownloadDataCompleted;
|
||||||
|
client.DownloadStringCompleted += Client_DownloadStringCompleted;
|
||||||
|
client.DownloadFileAsync(new Uri(lk), fn);
|
||||||
|
//client.DownloadDataAsync(new Uri(lk));
|
||||||
|
//client.DownloadStringAsync(new Uri(fn));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}//lock
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) {
|
||||||
|
////Update progress bar & label
|
||||||
|
//Invoke(new MethodInvoker(delegate () {
|
||||||
|
// progressBar.Minimum = 0;
|
||||||
|
// double receive = double.Parse(e.BytesReceived.ToString());
|
||||||
|
// double total = double.Parse(e.TotalBytesToReceive.ToString());
|
||||||
|
// double percentage = receive / total * 100;
|
||||||
|
// lblStatus.Text = $"Downloaded {string.Format("{0:0.##}", percentage)}%";
|
||||||
|
// progressBar.Value = int.Parse(Math.Truncate(percentage).ToString());
|
||||||
|
//}));
|
||||||
|
}
|
||||||
|
}//class cA69Engine2
|
||||||
|
|
||||||
|
|
||||||
|
}//namespace A69WD
|
||||||
Generated
+16
-3
@@ -34,6 +34,7 @@
|
|||||||
this.btnDownloadAll2 = new System.Windows.Forms.Button();
|
this.btnDownloadAll2 = new System.Windows.Forms.Button();
|
||||||
this.btnTest = new System.Windows.Forms.Button();
|
this.btnTest = new System.Windows.Forms.Button();
|
||||||
this.button1 = new System.Windows.Forms.Button();
|
this.button1 = new System.Windows.Forms.Button();
|
||||||
|
this.button2 = new System.Windows.Forms.Button();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
//
|
//
|
||||||
// btnClose
|
// btnClose
|
||||||
@@ -116,7 +117,7 @@
|
|||||||
//
|
//
|
||||||
// btnDownloadAll2
|
// btnDownloadAll2
|
||||||
//
|
//
|
||||||
this.btnDownloadAll2.Location = new System.Drawing.Point(69, 1);
|
this.btnDownloadAll2.Location = new System.Drawing.Point(45, 1);
|
||||||
this.btnDownloadAll2.Name = "btnDownloadAll2";
|
this.btnDownloadAll2.Name = "btnDownloadAll2";
|
||||||
this.btnDownloadAll2.Size = new System.Drawing.Size(97, 33);
|
this.btnDownloadAll2.Size = new System.Drawing.Size(97, 33);
|
||||||
this.btnDownloadAll2.TabIndex = 18;
|
this.btnDownloadAll2.TabIndex = 18;
|
||||||
@@ -126,7 +127,7 @@
|
|||||||
//
|
//
|
||||||
// btnTest
|
// btnTest
|
||||||
//
|
//
|
||||||
this.btnTest.Location = new System.Drawing.Point(187, 1);
|
this.btnTest.Location = new System.Drawing.Point(148, 1);
|
||||||
this.btnTest.Name = "btnTest";
|
this.btnTest.Name = "btnTest";
|
||||||
this.btnTest.Size = new System.Drawing.Size(97, 33);
|
this.btnTest.Size = new System.Drawing.Size(97, 33);
|
||||||
this.btnTest.TabIndex = 19;
|
this.btnTest.TabIndex = 19;
|
||||||
@@ -136,7 +137,7 @@
|
|||||||
//
|
//
|
||||||
// button1
|
// button1
|
||||||
//
|
//
|
||||||
this.button1.Location = new System.Drawing.Point(290, 1);
|
this.button1.Location = new System.Drawing.Point(251, 1);
|
||||||
this.button1.Name = "button1";
|
this.button1.Name = "button1";
|
||||||
this.button1.Size = new System.Drawing.Size(97, 33);
|
this.button1.Size = new System.Drawing.Size(97, 33);
|
||||||
this.button1.TabIndex = 20;
|
this.button1.TabIndex = 20;
|
||||||
@@ -144,11 +145,22 @@
|
|||||||
this.button1.UseVisualStyleBackColor = true;
|
this.button1.UseVisualStyleBackColor = true;
|
||||||
this.button1.Click += new System.EventHandler(this.button1_Click);
|
this.button1.Click += new System.EventHandler(this.button1_Click);
|
||||||
//
|
//
|
||||||
|
// button2
|
||||||
|
//
|
||||||
|
this.button2.Location = new System.Drawing.Point(354, 1);
|
||||||
|
this.button2.Name = "button2";
|
||||||
|
this.button2.Size = new System.Drawing.Size(97, 33);
|
||||||
|
this.button2.TabIndex = 21;
|
||||||
|
this.button2.Text = "Test Engine3";
|
||||||
|
this.button2.UseVisualStyleBackColor = true;
|
||||||
|
this.button2.Click += new System.EventHandler(this.button2_Click);
|
||||||
|
//
|
||||||
// frmDownloader
|
// frmDownloader
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
this.ClientSize = new System.Drawing.Size(524, 74);
|
this.ClientSize = new System.Drawing.Size(524, 74);
|
||||||
|
this.Controls.Add(this.button2);
|
||||||
this.Controls.Add(this.button1);
|
this.Controls.Add(this.button1);
|
||||||
this.Controls.Add(this.btnTest);
|
this.Controls.Add(this.btnTest);
|
||||||
this.Controls.Add(this.btnDownloadAll2);
|
this.Controls.Add(this.btnDownloadAll2);
|
||||||
@@ -178,5 +190,6 @@
|
|||||||
private System.Windows.Forms.Button btnDownloadAll2;
|
private System.Windows.Forms.Button btnDownloadAll2;
|
||||||
private System.Windows.Forms.Button btnTest;
|
private System.Windows.Forms.Button btnTest;
|
||||||
private System.Windows.Forms.Button button1;
|
private System.Windows.Forms.Button button1;
|
||||||
|
private System.Windows.Forms.Button button2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -25,10 +25,13 @@ namespace A69WD {
|
|||||||
engine.Updating += Engine_Updating;
|
engine.Updating += Engine_Updating;
|
||||||
engine2 = new cA69Engine2();
|
engine2 = new cA69Engine2();
|
||||||
engine2.Updating += Engine_Updating;
|
engine2.Updating += Engine_Updating;
|
||||||
|
engine3 = new cA69Engine3();
|
||||||
|
engine3.Updating += Engine_Updating;
|
||||||
}
|
}
|
||||||
|
|
||||||
cA69Engine engine = null;
|
cA69Engine engine = null;
|
||||||
cA69Engine2 engine2 = null;
|
cA69Engine2 engine2 = null;
|
||||||
|
cA69Engine3 engine3 = null;
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -187,8 +190,14 @@ namespace A69WD {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
private void button2_Click(object sender, EventArgs e) {
|
||||||
|
engine3.Start(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}//class frmDownloader
|
}//class frmDownloader
|
||||||
|
|||||||
Reference in new issue
Block a user