Compare commits

...

2 Commits

Author SHA1 Message Date
Andy Maesen
d171f34e4e
Update README.md 2023-07-07 14:23:33 +02:00
Andy Maesen
aa0dc4fa35 Fixes single result redirect 2023-07-06 02:09:56 +02:00
4 changed files with 54 additions and 2 deletions

View File

@ -57,6 +57,7 @@ Tranga can download Chapters and Metadata from "Scanlation" sites such as
- [MangaDex.org](https://mangadex.org/) - [MangaDex.org](https://mangadex.org/)
- [Manganato.com](https://manganato.com/) - [Manganato.com](https://manganato.com/)
- [Mangasee](https://mangasee123.com/) - [Mangasee](https://mangasee123.com/)
- [MangaKatana](https://mangakatana.com)
- ❓ Open an [issue](https://github.com/C9Glax/tranga/issues) - ❓ Open an [issue](https://github.com/C9Glax/tranga/issues)
and automatically import them with [Komga](https://komga.org/) and [Kavita](https://www.kavitareader.com/). Also Notifications will be sent to your devices using [Gotify](https://gotify.net/) and [LunaSea](https://www.lunasea.app/). and automatically import them with [Komga](https://komga.org/) and [Kavita](https://www.kavitareader.com/). Also Notifications will be sent to your devices using [Gotify](https://gotify.net/) and [LunaSea](https://www.lunasea.app/).

View File

@ -504,8 +504,30 @@ public static class Tranga_Cli
Chapter[] availableChapters = connector.GetChapters(publication, "en"); Chapter[] availableChapters = connector.GetChapters(publication, "en");
int cIndex = 0; int cIndex = 0;
Console.WriteLine("Chapters:"); Console.WriteLine("Chapters:");
System.Text.StringBuilder sb = new();
foreach(Chapter chapter in availableChapters) 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("Enter q to abort");
Console.WriteLine($"Select Chapter(s):"); Console.WriteLine($"Select Chapter(s):");

View File

@ -341,6 +341,13 @@ public abstract class Connector
logger?.WriteLine(this.GetType().ToString(), $"Request-Error {response.StatusCode}: {response.ReasonPhrase}"); logger?.WriteLine(this.GetType().ToString(), $"Request-Error {response.StatusCode}: {response.ReasonPhrase}");
return new RequestResult(response.StatusCode, Stream.Null); 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()); return new RequestResult(response.StatusCode, response.Content.ReadAsStream());
} }
@ -348,12 +355,21 @@ public abstract class Connector
{ {
public HttpStatusCode statusCode { get; } public HttpStatusCode statusCode { get; }
public Stream result { get; } public Stream result { get; }
public bool HasBeenRedirected { get; }
public string? RedirectedToUrl { get; }
public RequestResult(HttpStatusCode statusCode, Stream result) public RequestResult(HttpStatusCode statusCode, Stream result)
{ {
this.statusCode = statusCode; this.statusCode = statusCode;
this.result = result; this.result = result;
} }
public RequestResult(HttpStatusCode statusCode, Stream result, bool hasBeenRedirected, string redirectedTo)
: this(statusCode, result)
{
this.HasBeenRedirected = hasBeenRedirected;
RedirectedToUrl = redirectedTo;
}
} }
} }
} }

View File

@ -30,6 +30,14 @@ public class MangaKatana : Connector
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300) if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
return Array.Empty<Publication>(); 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); return ParsePublicationsFromHtml(requestResult.result);
} }
@ -113,9 +121,14 @@ public class MangaKatana : Connector
while (description.StartsWith('\n')) while (description.StartsWith('\n'))
description = description.Substring(1); description = description.Substring(1);
int year = DateTime.Now.Year;
string yearString = infoTable.Descendants("div").First(d => d.HasClass("updateAt")) string yearString = infoTable.Descendants("div").First(d => d.HasClass("updateAt"))
.InnerText.Split('-')[^1]; .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, return new Publication(sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl, coverFileNameInCache, links,
year, originalLanguage, status, publicationId); year, originalLanguage, status, publicationId);