2023-05-18 12:26:15 +02:00
|
|
|
|
using System.Net;
|
|
|
|
|
|
|
|
|
|
namespace Tranga;
|
|
|
|
|
|
|
|
|
|
public abstract class Connector
|
|
|
|
|
{
|
2023-05-18 16:40:11 +02:00
|
|
|
|
internal abstract string downloadLocation { get; }
|
2023-05-18 12:26:15 +02:00
|
|
|
|
public abstract string name { get; }
|
2023-05-18 16:41:14 +02:00
|
|
|
|
public abstract Publication[] GetPublications(string publicationTitle = "");
|
2023-05-18 15:47:48 +02:00
|
|
|
|
public abstract Chapter[] GetChapters(Publication publication);
|
2023-05-18 16:21:02 +02:00
|
|
|
|
public abstract void DownloadChapter(Publication publication, Chapter chapter); //where to?
|
|
|
|
|
|
|
|
|
|
internal void DownloadChapter(string url)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
2023-05-18 12:26:15 +02:00
|
|
|
|
|
|
|
|
|
internal class DownloadClient
|
|
|
|
|
{
|
|
|
|
|
static readonly HttpClient client = new HttpClient();
|
|
|
|
|
public RequestResult GetPage(string url)
|
|
|
|
|
{
|
|
|
|
|
HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Get, url);
|
|
|
|
|
HttpResponseMessage response = client.Send(requestMessage);
|
|
|
|
|
Stream resultString = response.IsSuccessStatusCode ? response.Content.ReadAsStream() : Stream.Null;
|
|
|
|
|
return new RequestResult(response.StatusCode, resultString);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public struct RequestResult
|
|
|
|
|
{
|
|
|
|
|
public HttpStatusCode statusCode { get; }
|
|
|
|
|
public Stream result { get; }
|
|
|
|
|
|
|
|
|
|
public RequestResult(HttpStatusCode statusCode, Stream result)
|
|
|
|
|
{
|
|
|
|
|
this.statusCode = statusCode;
|
|
|
|
|
this.result = result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|