Fixes single result redirect
This commit is contained in:
parent
25f48592c0
commit
aa0dc4fa35
@ -504,8 +504,30 @@ public static class Tranga_Cli
|
||||
Chapter[] availableChapters = connector.GetChapters(publication, "en");
|
||||
int cIndex = 0;
|
||||
Console.WriteLine("Chapters:");
|
||||
|
||||
System.Text.StringBuilder sb = new();
|
||||
foreach(Chapter chapter in availableChapters)
|
||||
Console.WriteLine($"{cIndex++}: Vol.{chapter.volumeNumber} Ch.{chapter.chapterNumber} - {chapter.name}");
|
||||
{
|
||||
sb.Append($"{cIndex++}: ");
|
||||
|
||||
if(string.IsNullOrWhiteSpace(chapter.volumeNumber) == false)
|
||||
{
|
||||
sb.Append($"Vol.{chapter.volumeNumber} ");
|
||||
}
|
||||
|
||||
if(string.IsNullOrWhiteSpace(chapter.chapterNumber) == false)
|
||||
{
|
||||
sb.Append($"Ch.{chapter.chapterNumber} ");
|
||||
}
|
||||
|
||||
if(string.IsNullOrWhiteSpace(chapter.name) == false)
|
||||
{
|
||||
sb.Append($" - {chapter.name}");
|
||||
}
|
||||
|
||||
Console.WriteLine(sb.ToString());
|
||||
sb.Clear();
|
||||
}
|
||||
|
||||
Console.WriteLine("Enter q to abort");
|
||||
Console.WriteLine($"Select Chapter(s):");
|
||||
|
@ -341,6 +341,13 @@ public abstract class Connector
|
||||
logger?.WriteLine(this.GetType().ToString(), $"Request-Error {response.StatusCode}: {response.ReasonPhrase}");
|
||||
return new RequestResult(response.StatusCode, Stream.Null);
|
||||
}
|
||||
|
||||
// Request has been redirected to another page. For example, it redirects directly to the results when there is only 1 result
|
||||
if(response.RequestMessage is not null && response.RequestMessage.RequestUri is not null)
|
||||
{
|
||||
return new RequestResult(response.StatusCode, response.Content.ReadAsStream(), true, response.RequestMessage.RequestUri.AbsoluteUri);
|
||||
}
|
||||
|
||||
return new RequestResult(response.StatusCode, response.Content.ReadAsStream());
|
||||
}
|
||||
|
||||
@ -348,12 +355,21 @@ public abstract class Connector
|
||||
{
|
||||
public HttpStatusCode statusCode { get; }
|
||||
public Stream result { get; }
|
||||
public bool HasBeenRedirected { get; }
|
||||
public string? RedirectedToUrl { get; }
|
||||
|
||||
public RequestResult(HttpStatusCode statusCode, Stream result)
|
||||
{
|
||||
this.statusCode = statusCode;
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
public RequestResult(HttpStatusCode statusCode, Stream result, bool hasBeenRedirected, string redirectedTo)
|
||||
: this(statusCode, result)
|
||||
{
|
||||
this.HasBeenRedirected = hasBeenRedirected;
|
||||
RedirectedToUrl = redirectedTo;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -30,6 +30,14 @@ public class MangaKatana : Connector
|
||||
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
||||
return Array.Empty<Publication>();
|
||||
|
||||
// If a single result is found, the user will be redirected to the results directly instead of a result page
|
||||
if(requestResult.HasBeenRedirected
|
||||
&& requestResult.RedirectedToUrl is not null
|
||||
&& requestResult.RedirectedToUrl.Contains("mangakatana.com/manga"))
|
||||
{
|
||||
return new Publication[] { ParseSinglePublicationFromHtml(requestResult.result, requestResult.RedirectedToUrl.Split('/')[^1]) };
|
||||
}
|
||||
|
||||
return ParsePublicationsFromHtml(requestResult.result);
|
||||
}
|
||||
|
||||
@ -113,9 +121,14 @@ public class MangaKatana : Connector
|
||||
while (description.StartsWith('\n'))
|
||||
description = description.Substring(1);
|
||||
|
||||
int year = DateTime.Now.Year;
|
||||
string yearString = infoTable.Descendants("div").First(d => d.HasClass("updateAt"))
|
||||
.InnerText.Split('-')[^1];
|
||||
int year = Convert.ToInt32(yearString);
|
||||
|
||||
if(yearString.Contains("ago") == false)
|
||||
{
|
||||
year = Convert.ToInt32(yearString);
|
||||
}
|
||||
|
||||
return new Publication(sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl, coverFileNameInCache, links,
|
||||
year, originalLanguage, status, publicationId);
|
||||
|
Loading…
Reference in New Issue
Block a user