Integrato l'import nello skraper
Modificato lo skraper per includere anche l'import del racconto Testato velocemente ToDo: - [X] Inserire un lettore per visualizzare i racconti nel DB - [0/3] Inserire funzionalità avanzate di lettura: - [ ] navigazione avanzata fra i racconti (per id, per autore, per titolo, per tag ecc... - [ ] possibilità di filtrare i racconti - [ ] Notificon per poter nascondere il reader e centralizzare i comandi - [3/3] Integrare lo scraping dei racconti dal web e l'import da file - [X] Integrare lo scraping dei racconti da web, visualizzandolo sulla progress bar e label nella status bar. - [X] Integrare l'import dei racconti da file, visualizzandolo sulla progress bar e label nella status bar. - [X] Upgradare lo skraping, importando i racconti via via che sono downloadati
This commit is contained in:
1 parent
00ad69e4e8
commit
44b9c095cd
10 files changed
+219
-550
No files matched your search
@@ -69,12 +69,6 @@
|
||||
<Compile Include="Service\Service_Crawler.cs" />
|
||||
<Compile Include="Service\Service_Importer.cs" />
|
||||
<Compile Include="Site\cSite_A69.cs" />
|
||||
<None Include="UI\frmDownloader.cs">
|
||||
<SubType>Form</SubType>
|
||||
</None>
|
||||
<None Include="UI\frmDownloader.Designer.cs">
|
||||
<DependentUpon>frmDownloader.cs</DependentUpon>
|
||||
</None>
|
||||
<Compile Include="General\Cfg.cs" />
|
||||
<Compile Include="General\cTools.cs" />
|
||||
<Compile Include="General\Logger.cs" />
|
||||
@@ -87,9 +81,6 @@
|
||||
<Compile Include="UI\frmReader.Designer.cs">
|
||||
<DependentUpon>frmReader.cs</DependentUpon>
|
||||
</Compile>
|
||||
<None Include="UI\frmDownloader.resx">
|
||||
<DependentUpon>frmDownloader.cs</DependentUpon>
|
||||
</None>
|
||||
<EmbeddedResource Include="Properties\Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using A69WD.Data;
|
||||
|
||||
namespace A69WD {
|
||||
|
||||
@@ -157,7 +158,12 @@ namespace A69WD {
|
||||
buffer[indice] = NewIdRac;
|
||||
|
||||
// Ritorno il testo del racconto:
|
||||
return DB.GetRacById(buffer[indice]).ToString();
|
||||
cRac r = DB.GetRacById(buffer[indice]);
|
||||
if (r != null) {
|
||||
return r.ToString();
|
||||
} else {
|
||||
return $"Indice {NewIdRac} non valido";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -287,6 +287,180 @@ namespace A69WD.Net {
|
||||
return rac;
|
||||
}
|
||||
|
||||
public cRac EstraiRac(HtmlDocument doc) {
|
||||
/*
|
||||
* Analisi html dei racconti aggiornata al 2025/12/27:
|
||||
*
|
||||
*
|
||||
* Per ciascun file html, si ha un unico racconto che ha un formato interno pari a:
|
||||
* <html xmlns="http://www.w3.org/1999/xhtml">
|
||||
* <body>
|
||||
* ...
|
||||
* <div class="targhetta_racconti" style=" width:100%; background-color:#5d5d5d;">incesto</div>
|
||||
* ...
|
||||
* <h1 class="titolone_nero" ...>Mia Madre , La mia Amante</h1>
|
||||
* <strong> di<a href="/user/Bambino">Bambino</a>
|
||||
* ...
|
||||
* <div style="float:left; margin-right:5px; color: #9999CC; ">
|
||||
* <span class="text_grigio" style="line-height:1.6em; color: #9999CC; font-size:13px;"> <strong>Scritto il</strong> 22.08.2015 |
|
||||
* <strong>Letture:</strong> 8.947 |
|
||||
* <strong>Votazione 8.0:</strong></span>
|
||||
* </div>
|
||||
* ...
|
||||
* <div class="testoracc" style="color:#666666; text-align:justify; padding:20px 20px 0px 0px;">
|
||||
* Eliminare i DIV interni che hanno cose grafiche
|
||||
* Il testo è quello che rimane.
|
||||
* </div>
|
||||
* </body>
|
||||
* </html>
|
||||
*
|
||||
* quindi i dati del racconto che si possono estrapolare sono:
|
||||
* Titolo: --> Testo del nodo <h1 class="titolone_nero">
|
||||
* SubTitle: --> Sempre Vuoto
|
||||
* Autore: --> Testo del nodo <strong><a>
|
||||
* Creato: --> Estrarre la parte dal <div style="float:left; margin-right:5px; color: #9999CC; ">
|
||||
* Tags: --> Testo del nodo div class="targhetta_racconti">
|
||||
* Trama: --> Testo del nodo <div class="testoracc"> a cui si levano i DIV interni.
|
||||
* Notes: --> SrcFile - Nome del file che si analizza
|
||||
* Origini: --> Sempre l'ID della sorgente web
|
||||
* Voto: --> Sempre "Non Letto"
|
||||
* Updated: --> Data attuale
|
||||
*
|
||||
*/
|
||||
cRac rac = new cRac();
|
||||
HtmlNodeCollection nodes;
|
||||
try {
|
||||
Console.WriteLine($"A69 - Importo: {FileName}");
|
||||
|
||||
// Ricavo il nodo radice del racconto:
|
||||
HtmlNode root = doc.DocumentNode;
|
||||
if (root == null) {
|
||||
// racconto non presente
|
||||
return null;
|
||||
}
|
||||
|
||||
#region Origini: --> Sempre l'ID della sorgente web
|
||||
rac.Origini = new List<string> { ID };
|
||||
#endregion
|
||||
|
||||
#region Titolo: --> Testo del nodo <h1 class="titolone_nero">
|
||||
try {
|
||||
nodes = root.SelectNodes("//h1[@class='titolone_nero']");
|
||||
rac.Title = cTools.FormattaTesto(nodes[0].InnerText.Trim(), false);
|
||||
if (string.IsNullOrEmpty(rac.Title)) {
|
||||
Logger.Error($"A69 - Import - No Title - {FileName}");
|
||||
return null;
|
||||
}
|
||||
} catch (Exception ex) { Logger.Error(string.Format("Fallita estrazione titolo dal file {0}\r\n{1}", FileName, ex.Message)); return null; }
|
||||
#endregion
|
||||
|
||||
#region SubTitle: --> Sempre Vuoto
|
||||
rac.SubTitle = "";
|
||||
#endregion
|
||||
|
||||
#region Autore: --> Testo del nodo <strong><a>
|
||||
try {
|
||||
// Autore --> Testo del nodo <span class="text_grigio><a>"
|
||||
nodes = root.SelectNodes("//span[@class='text_grigio']//a");
|
||||
List<string> items = new List<string>();
|
||||
foreach (HtmlNode nd in nodes) {
|
||||
string aut = nd.ParentNode.InnerText.Replace(" ", "").Trim();
|
||||
if (aut.StartsWith("di")) {
|
||||
items.Add(aut.Replace("di", "").Trim());
|
||||
}
|
||||
}
|
||||
items.Sort();
|
||||
string tmp = "";
|
||||
rac.Autori = new List<string>();
|
||||
// Rimuovo eventuali duplicati
|
||||
foreach (string aut in items) {
|
||||
if (tmp != aut) {
|
||||
rac.Autori.Add(aut);
|
||||
tmp = aut;
|
||||
}
|
||||
}
|
||||
if (rac.Autori == null || string.IsNullOrEmpty(rac.Autori[0])) {
|
||||
Logger.Error($"A69 - Import - No Autors - {FileName}");
|
||||
return null;
|
||||
}
|
||||
} catch (Exception ex) { Logger.Error(string.Format("Fallita estrazione autore dal file {0}\r\n{1}", FileName, ex.Message)); return null; }
|
||||
#endregion
|
||||
|
||||
#region Creato: --> Estrarre la parte dal <div style="float:left; margin-right:5px; color: #9999CC; ">
|
||||
rac.Creato = DateTime.Now;
|
||||
try {
|
||||
// Creato --> Estrarre la prima parte dal <span class="text_grigio"> che ha il testo "Data|Visite|Commenti":
|
||||
nodes = root.SelectNodes("//span[@class='text_grigio']");
|
||||
foreach (HtmlNode nd in nodes) {
|
||||
string txt = nd.InnerText.Trim().Replace(" ", "");
|
||||
string[] parts = txt.Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (parts.Length == 3) {
|
||||
CultureInfo culture = CultureInfo.CreateSpecificCulture("it-IT");
|
||||
DateTimeStyles styles = DateTimeStyles.None;
|
||||
DateTime tmpDT = DateTime.Now;
|
||||
if (!DateTime.TryParse(parts[0].Trim(), culture, styles, out tmpDT)) {
|
||||
Logger.Error($"A69 - Import - No data - {FileName}");
|
||||
}
|
||||
rac.Creato = tmpDT;
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) { Logger.Warning(string.Format("Data non riconosciuta nel file {0}\r\n{1}", FileName, ex.Message)); return null; }
|
||||
#endregion
|
||||
|
||||
#region Updated: --> Data attuale
|
||||
rac.Updated = DateTime.Now;
|
||||
#endregion
|
||||
|
||||
#region Tags: --> Testo del nodo div class="targhetta_racconti">
|
||||
try {
|
||||
nodes = root.SelectNodes("//div[@class='targhetta_racconti']");
|
||||
List<string> items = new List<string>();
|
||||
foreach (HtmlNode nd in nodes) {
|
||||
items.Add(cTools.FormattaTesto(nd.InnerText.Replace("genere", "").Trim(), false));
|
||||
}
|
||||
//items.Sort();
|
||||
items = items
|
||||
.OrderBy(s => s) // ordina alfabeticamente
|
||||
.Distinct() // elimina duplicati
|
||||
.ToList();
|
||||
Format_Insert_Tags(rac, items); // rac.Tags = items;
|
||||
} catch (Exception ex) { Logger.Warning(string.Format("Fallita estrazione Tags dal file {0}\r\n{1}", FileName, ex.Message)); return null; }
|
||||
#endregion
|
||||
|
||||
#region Trama: --> Testo del nodo <div class="testoracc"> a cui si levano i DIV interni.
|
||||
try {
|
||||
nodes = root.SelectNodes("//div[@class='testoracc']");
|
||||
foreach (HtmlNode nd in nodes) {
|
||||
foreach (HtmlNode n in nd.ChildNodes) {
|
||||
if (n.Name.ToUpper() == "#TEXT") { rac.Trama += cTools.FormattaTesto(n.InnerText.Trim(), false); }
|
||||
if (n.Name.ToUpper() == "BR") { rac.Trama += "\r"; }
|
||||
if (n.Name.ToUpper() == "DIV") {; }
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) { Logger.Error(string.Format("Fallita estrazione Trama dal file {0}\r\n{1}", FileName, ex.Message)); return null; }
|
||||
#endregion
|
||||
|
||||
#region Voto: --> Sempre "Non Letto"
|
||||
rac.Voto = "Non Letto";
|
||||
#endregion
|
||||
|
||||
#region Notes: --> SrcFile - Nome del file che si analizza
|
||||
rac.Notes = new List<Data.cNota>();
|
||||
rac.Notes.Add(new Data.cNota("SrcFile", System.IO.Path.GetFileName(FileName)));
|
||||
#endregion
|
||||
|
||||
// Formalizzo esito estrazione:
|
||||
if (!rac.Validate()) {
|
||||
rac = null;
|
||||
}
|
||||
|
||||
} catch (Exception ex) {
|
||||
Logger.Error($"A69 - Import Error - {FileName}: {ex.Message}");
|
||||
Console.WriteLine($"A69 - Import Error - {FileName}: {ex.Message}");
|
||||
return null;
|
||||
}
|
||||
return rac;
|
||||
}
|
||||
|
||||
protected virtual void Format_Insert_Tags(Data.cRac rac, List<string> items) {
|
||||
// Per ora riporto tutti i tag rilevati, mentre in futuro dovrò:
|
||||
|
||||
@@ -3,6 +3,9 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using A69WD.Data;
|
||||
using HtmlAgilityPack;
|
||||
|
||||
|
||||
namespace A69WD.Net {
|
||||
|
||||
@@ -42,6 +45,8 @@ namespace A69WD.Net {
|
||||
|
||||
eLinkState Status { get; set; }
|
||||
|
||||
cRac EstraiRac(HtmlDocument doc);
|
||||
|
||||
}//interface iLink
|
||||
|
||||
}//namespace A69WD.Net
|
||||
@@ -32,8 +32,24 @@ using System.Runtime.InteropServices;
|
||||
// È possibile specificare tutti i valori oppure impostare valori predefiniti per i numeri relativi alla revisione e alla build
|
||||
// usando l'asterisco '*' come illustrato di seguito:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("0.4.6.0")]
|
||||
[assembly: AssemblyFileVersion("0.4.6.0")]
|
||||
[assembly: AssemblyVersion("0.5.0.0")]
|
||||
[assembly: AssemblyFileVersion("0.5.0.0")]
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* Vrs 0.5.0.0
|
||||
*
|
||||
* Compilata da CSiCoAlm il 2025/12/29
|
||||
* Inserito reader basilare (solo lettura, navigazione random o sequenziale)
|
||||
* Integrato import e skraping sul reader
|
||||
*
|
||||
* ToDo:
|
||||
* - Aggiungere gestione parallela della FIFO secondo vecchi modello per aumentare il feedback alla UI
|
||||
* - Inserire anche l'estrazione dei racconti
|
||||
* - Inserire funzionalità avanzate sul lettore
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using A69WD.Data;
|
||||
using A69WD.Net;
|
||||
using HtmlAgilityPack;
|
||||
|
||||
@@ -239,6 +240,17 @@ namespace A69WD.Site {
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Estraggo il racconto dal file e lo inserisco nel DB
|
||||
if (lk.FileName.StartsWith("A69_")) {
|
||||
// Link ad un racconto
|
||||
cRac rac = lk.EstraiRac(tdoc);
|
||||
if (rac != null) {
|
||||
// Racconto estratto correttamente, lo salvo sul DB
|
||||
App.DB.ImportRac(rac);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
lk.Status = eLinkState.End;
|
||||
App.DB.LinkLog(lk);
|
||||
}
|
||||
|
||||
Generated
-153
@@ -1,153 +0,0 @@
|
||||
namespace A69WD {
|
||||
partial class frmDownloader {
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing) {
|
||||
if (disposing && (components != null)) {
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent() {
|
||||
this.btnClose = new System.Windows.Forms.Button();
|
||||
this.btnDownloadAll = new System.Windows.Forms.Button();
|
||||
this.lblST = new System.Windows.Forms.Label();
|
||||
this.btnImportLinks = new System.Windows.Forms.Button();
|
||||
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
|
||||
this.btnShowLog = new System.Windows.Forms.Button();
|
||||
this.pbST = new System.Windows.Forms.ProgressBar();
|
||||
this.btnImport = new System.Windows.Forms.Button();
|
||||
this.btnTest = new System.Windows.Forms.Button();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// btnClose
|
||||
//
|
||||
this.btnClose.Location = new System.Drawing.Point(348, 12);
|
||||
this.btnClose.Name = "btnClose";
|
||||
this.btnClose.Size = new System.Drawing.Size(79, 33);
|
||||
this.btnClose.TabIndex = 14;
|
||||
this.btnClose.Text = "Close";
|
||||
this.btnClose.UseVisualStyleBackColor = true;
|
||||
this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
|
||||
//
|
||||
// btnDownloadAll
|
||||
//
|
||||
this.btnDownloadAll.Location = new System.Drawing.Point(12, 12);
|
||||
this.btnDownloadAll.Name = "btnDownloadAll";
|
||||
this.btnDownloadAll.Size = new System.Drawing.Size(79, 33);
|
||||
this.btnDownloadAll.TabIndex = 11;
|
||||
this.btnDownloadAll.Text = "Start A69";
|
||||
this.btnDownloadAll.UseVisualStyleBackColor = true;
|
||||
this.btnDownloadAll.Click += new System.EventHandler(this.btnDownloadAll_Click);
|
||||
//
|
||||
// lblST
|
||||
//
|
||||
this.lblST.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.lblST.Dock = System.Windows.Forms.DockStyle.Bottom;
|
||||
this.lblST.Location = new System.Drawing.Point(0, 73);
|
||||
this.lblST.Name = "lblST";
|
||||
this.lblST.Size = new System.Drawing.Size(433, 22);
|
||||
this.lblST.TabIndex = 9;
|
||||
this.lblST.Text = "Status";
|
||||
this.lblST.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
|
||||
//
|
||||
// btnImportLinks
|
||||
//
|
||||
this.btnImportLinks.Enabled = false;
|
||||
this.btnImportLinks.Location = new System.Drawing.Point(97, 12);
|
||||
this.btnImportLinks.Name = "btnImportLinks";
|
||||
this.btnImportLinks.Size = new System.Drawing.Size(79, 33);
|
||||
this.btnImportLinks.TabIndex = 15;
|
||||
this.btnImportLinks.Text = "From DB";
|
||||
this.btnImportLinks.UseVisualStyleBackColor = true;
|
||||
this.btnImportLinks.Click += new System.EventHandler(this.btnImportLinks_Click);
|
||||
//
|
||||
// openFileDialog1
|
||||
//
|
||||
this.openFileDialog1.FileName = "openFileDialog1";
|
||||
this.openFileDialog1.Filter = "File Testo|*.tes|Tutti i file|*.*";
|
||||
//
|
||||
// btnShowLog
|
||||
//
|
||||
this.btnShowLog.Location = new System.Drawing.Point(263, 12);
|
||||
this.btnShowLog.Name = "btnShowLog";
|
||||
this.btnShowLog.Size = new System.Drawing.Size(79, 33);
|
||||
this.btnShowLog.TabIndex = 17;
|
||||
this.btnShowLog.Text = "Show Log";
|
||||
this.btnShowLog.UseVisualStyleBackColor = true;
|
||||
this.btnShowLog.Click += new System.EventHandler(this.btnShowLog_Click);
|
||||
//
|
||||
// pbST
|
||||
//
|
||||
this.pbST.Dock = System.Windows.Forms.DockStyle.Bottom;
|
||||
this.pbST.Location = new System.Drawing.Point(0, 55);
|
||||
this.pbST.Name = "pbST";
|
||||
this.pbST.Size = new System.Drawing.Size(433, 18);
|
||||
this.pbST.TabIndex = 18;
|
||||
//
|
||||
// btnImport
|
||||
//
|
||||
this.btnImport.Location = new System.Drawing.Point(182, 12);
|
||||
this.btnImport.Name = "btnImport";
|
||||
this.btnImport.Size = new System.Drawing.Size(79, 33);
|
||||
this.btnImport.TabIndex = 19;
|
||||
this.btnImport.Text = "Import Rac";
|
||||
this.btnImport.UseVisualStyleBackColor = true;
|
||||
this.btnImport.Click += new System.EventHandler(this.btnImport_Click);
|
||||
//
|
||||
// btnTest
|
||||
//
|
||||
this.btnTest.Location = new System.Drawing.Point(121, -1);
|
||||
this.btnTest.Name = "btnTest";
|
||||
this.btnTest.Size = new System.Drawing.Size(55, 33);
|
||||
this.btnTest.TabIndex = 20;
|
||||
this.btnTest.Text = "Test";
|
||||
this.btnTest.UseVisualStyleBackColor = true;
|
||||
this.btnTest.Click += new System.EventHandler(this.btnTest_Click);
|
||||
//
|
||||
// frmDownloader
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(433, 95);
|
||||
this.Controls.Add(this.btnTest);
|
||||
this.Controls.Add(this.btnImport);
|
||||
this.Controls.Add(this.pbST);
|
||||
this.Controls.Add(this.btnShowLog);
|
||||
this.Controls.Add(this.btnImportLinks);
|
||||
this.Controls.Add(this.btnClose);
|
||||
this.Controls.Add(this.btnDownloadAll);
|
||||
this.Controls.Add(this.lblST);
|
||||
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
|
||||
this.Name = "frmDownloader";
|
||||
this.Text = "frmDownloader";
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
private System.Windows.Forms.Button btnClose;
|
||||
private System.Windows.Forms.Button btnDownloadAll;
|
||||
private System.Windows.Forms.Label lblST;
|
||||
private System.Windows.Forms.Button btnImportLinks;
|
||||
private System.Windows.Forms.OpenFileDialog openFileDialog1;
|
||||
private System.Windows.Forms.Button btnShowLog;
|
||||
private System.Windows.Forms.ProgressBar pbST;
|
||||
private System.Windows.Forms.Button btnImport;
|
||||
private System.Windows.Forms.Button btnTest;
|
||||
}
|
||||
}
|
||||
@@ -1,259 +0,0 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using System.Diagnostics;
|
||||
using System.Threading;
|
||||
using System.Net;
|
||||
using static System.Windows.Forms.LinkLabel;
|
||||
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
||||
using A69WD.Site;
|
||||
using A69WD.Net;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Xml.Linq;
|
||||
using A69WD.Service;
|
||||
using A69WD.Data;
|
||||
|
||||
namespace A69WD {
|
||||
|
||||
public partial class frmDownloader : Form {
|
||||
|
||||
// Coda thread-safe di URL da scaricare
|
||||
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(1);
|
||||
|
||||
|
||||
|
||||
public frmDownloader() {
|
||||
InitializeComponent();
|
||||
this.Text = String.Format("A69WD - Dowloader Testi Vrs {0}", cTools.AssemblyVersion);
|
||||
//engine = new cA69Engine();
|
||||
//engine.Updating += Engine_Updating;
|
||||
}
|
||||
|
||||
//cA69Engine engine = null;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Metodo per scansionare i link da un file di testo ed inserirli come da downloadare se non ci sono già
|
||||
/// </summary>
|
||||
private void btnImportLinks_Click(object sender, EventArgs e) {
|
||||
//// Chiedo il file di testo da caricare
|
||||
//lblST.Text = " ";
|
||||
//this.openFileDialog1.InitialDirectory = Cfg.Settings.PathApplicationRoot;
|
||||
//if (this.openFileDialog1.ShowDialog() == DialogResult.OK) {
|
||||
// lblST.Text = string.Format("Importati {0} link", engine.ImportLinkFromFile(openFileDialog1.FileNames[0]));
|
||||
//}
|
||||
}
|
||||
|
||||
private async void btnDownloadAll_Click(object sender, EventArgs e) {
|
||||
btnDownloadAll.Enabled = false;
|
||||
|
||||
// - Creo istanza del client per il sito con autenticazione:
|
||||
lblST.Text = DateTime.Now.ToString() + " - Login";
|
||||
A69WD.Site.iSiteType siteA69 = new cSite_A69();
|
||||
// - Eseguo l'autenticazione
|
||||
bool res = await siteA69.Authenticate();
|
||||
if (res) {
|
||||
lblST.Text = DateTime.Now.ToString() + " - sito loggato: " + res.ToString();
|
||||
Logger.Information("Sito correttamente loggato.");
|
||||
} else {
|
||||
Logger.Information("Errore di autenticazione al sito.");
|
||||
return;
|
||||
}
|
||||
// - Verifico path per il download
|
||||
if (!System.IO.Directory.Exists(Cfg.Settings.PathDownloadWorking)) System.IO.Directory.CreateDirectory(Cfg.Settings.PathDownloadWorking);
|
||||
// // Test downloadando tutti i 10 primi link per categoria
|
||||
// List<iLink> links = cLink_A69.GetStartLink();
|
||||
// int i = 1;
|
||||
// foreach (iLink link in links) {
|
||||
// lblST.Text = "Start url " + link.FileName;
|
||||
// Logger.Information("Start url " + link.FileName);
|
||||
// await siteA69.CrawlPageAsync(link);
|
||||
// Logger.Information(" end url " + link.FileName);
|
||||
// i++;
|
||||
// }
|
||||
|
||||
// // Inserisco i link iniziali sulla coda dei download:
|
||||
// if (!cLink_A69.InsertStartLink(_urlQueue)) {
|
||||
// lblST.Text = "Inserimento A69 start link fault.";
|
||||
// return;
|
||||
// }
|
||||
// lblST.Text = "In coda vi sono: " + _urlQueue.Count.ToString() + " url.";
|
||||
//
|
||||
// // Test estrazione link dal primo indice:
|
||||
// iLink link = new cLink_A69("https://www.annunci69.it/racconti-erotici/racconti_lista.php?genere=altro&pagina=1", "Idx_altro_1.html");
|
||||
// Logger.Information("Start url " + link.FileName);
|
||||
// List<iLink> urls = await siteA69.CrawlPageAsync(link);
|
||||
// Logger.Information(" end url " + link.FileName + " - URL trovati: " + urls.Count.ToString("000"));
|
||||
// foreach (iLink url in urls) { _urlQueue.Add(url); }
|
||||
// lblST.Text = "In coda vi sono: " + _urlQueue.Count.ToString() + " url.";
|
||||
|
||||
|
||||
// Preparo il servizio
|
||||
serviceCrawler = new Service_Crawler(lblST, pbST);
|
||||
// Inserisco i link iniziali nella coda
|
||||
if (!cLink_A69.InsertStartLink(serviceCrawler)) {
|
||||
lblST.Text = "Inserimento A69 start link fault.";
|
||||
return;
|
||||
}
|
||||
// avvio il servizio
|
||||
serviceCrawler.StartWorker(siteA69);
|
||||
|
||||
|
||||
}
|
||||
private Service_Crawler serviceCrawler = null;
|
||||
|
||||
|
||||
private void btnShowLog_Click(object sender, EventArgs e) {
|
||||
cTools.ShowOnNotepad(Cfg.Settings.PathFileLogs);
|
||||
}
|
||||
|
||||
private void btnHide_Click(object sender, EventArgs e) {
|
||||
if (MessageBox.Show("Metodo ancora da terminare, la finestra non sarà più visibile, killare il processo", "ATTENZIONE", MessageBoxButtons.OKCancel) == DialogResult.OK){
|
||||
this.Hide();
|
||||
}
|
||||
}
|
||||
|
||||
private void btnClose_Click(object sender, EventArgs e) {
|
||||
//if (engine.Stop()) this.Close();
|
||||
|
||||
// fermo i servizi
|
||||
if (serviceCrawler != null) serviceCrawler.StopWorker();
|
||||
if (serviceImporter != null) serviceImporter.StopWorker();
|
||||
|
||||
this.Close();
|
||||
}
|
||||
|
||||
|
||||
|
||||
#region Gestione eventi dal engine
|
||||
//
|
||||
// private void Engine_Updating(object sender, EngineEventArgs e) { EngineUpdatingStatus(e.Message, e.NTot, e.NtoDown, e.NDown); }
|
||||
//
|
||||
// delegate void EngineUpdatingStatusCallback(string Message, int NTot, int NtoDown, int NDown);
|
||||
// private void EngineUpdatingStatus(string Message, int NTot, int NtoDown, int NDown) {
|
||||
// try {
|
||||
// // InvokeRequired required compares the thread ID of the
|
||||
// // calling thread to the thread ID of the creating thread.
|
||||
// // If these threads are different, it returns true.
|
||||
// if (lblST.InvokeRequired) {
|
||||
// EngineUpdatingStatusCallback callBack = new EngineUpdatingStatusCallback(EngineUpdatingStatus);
|
||||
// this.Invoke(callBack, new object[] { Message, NTot, NtoDown, NDown });
|
||||
// } else {
|
||||
// lblST.Text = string.Format("{4} - {3} | {2} | {1} - {0}", Message, NTot, NtoDown, NDown, DateTime.Now.ToString("HH:mm:ss"));
|
||||
// Logger.Information(lblST.Text);
|
||||
// }
|
||||
// } catch (Exception ex) {
|
||||
// Logger.Log(new object[] { "Error Code: ER05553", "Errore in EngineUpdatingStatus():", ex });
|
||||
// }
|
||||
// }
|
||||
//
|
||||
#endregion
|
||||
|
||||
private void btnImport_Click(object sender, EventArgs e) {
|
||||
// string fp = "C:\\Commesse\\_zPrivate\\A69WD\\Test\\Down\\__A69_altro_Collarini-e-fantasie_166756.html";
|
||||
// cLink_A69 lk = new cLink_A69("Tmp", "tmp");
|
||||
// cRac rac = await lk.EstraiRac(fp);
|
||||
// if (rac != null) {
|
||||
// //foreach (string tag in rac.Tags) {
|
||||
// for (int i = 0; i<rac.Tags.Count; i++) {
|
||||
// Console.WriteLine(rac.Tags[i]);
|
||||
// }
|
||||
// // Racconto estratto correttamente, lo salvo sul DB
|
||||
// App.DB.ImportRac(rac);
|
||||
// }
|
||||
|
||||
// Preparo il servizio
|
||||
serviceImporter = new Service_Importer(lblST, pbST);
|
||||
|
||||
// Per ora uso la directory di default, poi metteremo selezione
|
||||
string path = Cfg.Settings.PathDownloadWorking;
|
||||
|
||||
// avvio il servizio
|
||||
serviceImporter.StartWorker(path);
|
||||
|
||||
}
|
||||
private Service_Importer serviceImporter = null;
|
||||
|
||||
private async void btnTest_Click(object sender, EventArgs e) {
|
||||
// // Test dell'esportazione in html
|
||||
// int MaxRac = 60;
|
||||
// pbST.Maximum = MaxRac;
|
||||
// pbST.Minimum = 0;
|
||||
// pbST.Value = 0;
|
||||
// lblST.Text = "Inizio esportazione racconti";
|
||||
// for (int i = 0; i < 61; i++) {
|
||||
// cRac rac = App.DB.GetRacById(i);
|
||||
// cRac.EsportaInHtml(rac, Cfg.Settings.PathDownloadWorking);
|
||||
// pbST.Value = i;
|
||||
// lblST.Text = $"Esportato racconto ID={rac.strIDrac}";
|
||||
// }
|
||||
// lblST.Text = $"Fine esportazione {MaxRac.ToString("000")} racconti";
|
||||
|
||||
|
||||
|
||||
// // Test funzione di lettura dal DB
|
||||
// Logger.Information("-- Start test 100*50 letture originali --");
|
||||
// DateTime start = DateTime.Now;
|
||||
// for (int j = 0; j < 100; j++) {
|
||||
// for (int i = 1; i <= 50; i++) {
|
||||
// cRac rac = App.DB.GetRacById_Orig(i);
|
||||
// if (rac.IDrac != i) Logger.Information($"Letto ID={i.ToString()}");
|
||||
// }
|
||||
// }
|
||||
// TimeSpan tp = start-DateTime.Now;
|
||||
// Logger.Information($" End test in {tp.ToString()}");
|
||||
// Logger.Information("-- Start test 100*50 letture nuove --");
|
||||
// start = DateTime.Now;
|
||||
// for (int j = 0; j < 100; j++) {
|
||||
// for (int i = 1; i <= 50; i++) {
|
||||
// cRac rac = App.DB.GetRacById(i);
|
||||
// if (rac.IDrac != i) Logger.Information($"Letto ID={i.ToString()}");
|
||||
// }
|
||||
// }
|
||||
// tp = start - DateTime.Now;
|
||||
// Logger.Information($" End test in {tp.ToString()}");
|
||||
|
||||
// Test di salvataggio sul DB
|
||||
// leggo 3 nuovi racconti
|
||||
string file = @"C:\Commesse\_zPrivate\A69WD\Test\Down\A69_altro_Decisione-estrema_133364.html";
|
||||
cLink_A69 lk = new cLink_A69(file, "A69_altro_Decisione-estrema_133364.html");
|
||||
cRac rac1 = await lk.EstraiRac(file);
|
||||
file = @"C:\Commesse\_zPrivate\A69WD\Test\Down\A69_altro_Decisione_133364 - Copy.html";
|
||||
lk = new cLink_A69(file, "A69_altro_Decisione_133364 - Copy.html");
|
||||
cRac rac2 = await lk.EstraiRac(file);
|
||||
file = @"C:\Commesse\_zPrivate\A69WD\Test\Down\A69_altro_Dammi-un-bacio_153877.html";
|
||||
lk = new cLink_A69(file, "A69_altro_Dammi-un-bacio_153877.html");
|
||||
cRac rac3 = await lk.EstraiRac(file);
|
||||
file = @"C:\Commesse\_zPrivate\A69WD\Test\Down\A69_altro_dammi-la-mano_157904.html";
|
||||
lk = new cLink_A69(file, "A69_altro_dammi-la-mano_157904.html");
|
||||
cRac rac4 = await lk.EstraiRac(file);
|
||||
// // Controprova:
|
||||
// var res1 = App.DB.ImportRac(rac1);
|
||||
// var res2 = App.DB.ImportRac(rac2);
|
||||
// var res3 = App.DB.ImportRac(rac3);
|
||||
// var res4 = App.DB.ImportRac(rac4);
|
||||
// Provo a salvarli
|
||||
var res1 = App.DB.SalvaRacconto(rac1);
|
||||
var res2 = App.DB.SalvaRacconto(rac2);
|
||||
var res3 = App.DB.SalvaRacconto(rac3);
|
||||
var res4 = App.DB.SalvaRacconto(rac4);
|
||||
|
||||
//
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}//class frmDownloader
|
||||
}//namespace A69WD
|
||||
@@ -1,123 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="openFileDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
</root>
|
||||
@@ -682,10 +682,10 @@ namespace A69WD.UI {
|
||||
// - Eseguo l'autenticazione
|
||||
bool res = await siteA69.Authenticate();
|
||||
if (res) {
|
||||
sbStatusLabel.Text = "sito loggato: " + res.ToString();
|
||||
Logger.Information("A69 logged");
|
||||
sbStatusLabel.Text = "A69 logged";
|
||||
Logger.Information("Sito A69 loggato: " + res.ToString());
|
||||
} else {
|
||||
Logger.Information("Errore di autenticazione al sito A69.");
|
||||
Logger.Information("Login Fault");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user