2
0

Cleanup build warnings, ReShaper, Dictionary

This commit is contained in:
glax 2023-07-30 17:25:04 +02:00
parent d83aa1ef5b
commit 1afa3df316
19 changed files with 84 additions and 58 deletions

View File

@ -1,6 +1,9 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> <wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/UserDictionary/Words/=altnames/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=authorsartists/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Gotify/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Gotify/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Komga/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Komga/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=mangakatana/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Manganato/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Manganato/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Mangasee/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Mangasee/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Taskmanager/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Taskmanager/@EntryIndexedValue">True</s:Boolean>

View File

@ -9,11 +9,13 @@ namespace Tranga;
/// </summary> /// </summary>
public readonly struct Chapter public readonly struct Chapter
{ {
// ReSharper disable once MemberCanBePrivate.Global
public Publication parentPublication { get; } public Publication parentPublication { get; }
public string? name { get; } public string? name { get; }
public string? volumeNumber { get; } public string? volumeNumber { get; }
public string chapterNumber { get; } public string chapterNumber { get; }
public string url { get; } public string url { get; }
// ReSharper disable once MemberCanBePrivate.Global
public string fileName { get; } public string fileName { get; }
private static readonly Regex LegalCharacters = new (@"([A-z]*[0-9]* *\.*-*,*\]*\[*'*\'*\)*\(*~*!*)*"); private static readonly Regex LegalCharacters = new (@"([A-z]*[0-9]* *\.*-*,*\]*\[*'*\'*\)*\(*~*!*)*");

View File

@ -159,8 +159,7 @@ public abstract class Connector
/// Copies the already downloaded cover from cache to downloadLocation /// Copies the already downloaded cover from cache to downloadLocation
/// </summary> /// </summary>
/// <param name="publication">Publication to retrieve Cover for</param> /// <param name="publication">Publication to retrieve Cover for</param>
/// <param name="settings">TrangaSettings</param> public void CopyCoverFromCacheToDownloadLocation(Publication publication)
public void CopyCoverFromCacheToDownloadLocation(Publication publication, TrangaSettings settings)
{ {
settings.logger?.WriteLine(this.GetType().ToString(), $"Cloning cover {publication.sortName} -> {publication.internalId}"); settings.logger?.WriteLine(this.GetType().ToString(), $"Cloning cover {publication.sortName} -> {publication.internalId}");
//Check if Publication already has a Folder and cover //Check if Publication already has a Folder and cover

View File

@ -15,7 +15,7 @@ public class MangaKatana : Connector
this.name = "MangaKatana"; this.name = "MangaKatana";
this.downloadClient = new DownloadClient(new Dictionary<byte, int>() this.downloadClient = new DownloadClient(new Dictionary<byte, int>()
{ {
{(byte)1, 60} {1, 60}
}, settings.logger); }, settings.logger);
} }
@ -25,16 +25,17 @@ public class MangaKatana : Connector
string sanitizedTitle = string.Concat(Regex.Matches(publicationTitle, "[A-z]* *")).ToLower().Replace(' ', '_'); string sanitizedTitle = string.Concat(Regex.Matches(publicationTitle, "[A-z]* *")).ToLower().Replace(' ', '_');
string requestUrl = $"https://mangakatana.com/?search={sanitizedTitle}&search_by=book_name"; string requestUrl = $"https://mangakatana.com/?search={sanitizedTitle}&search_by=book_name";
DownloadClient.RequestResult requestResult = DownloadClient.RequestResult requestResult =
downloadClient.MakeRequest(requestUrl, (byte)1); downloadClient.MakeRequest(requestUrl, 1);
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>();
// ReSharper disable once MergeIntoPattern
// If a single result is found, the user will be redirected to the results directly instead of a result page // If a single result is found, the user will be redirected to the results directly instead of a result page
if(requestResult.HasBeenRedirected if(requestResult.hasBeenRedirected
&& requestResult.RedirectedToUrl is not null && requestResult.redirectedToUrl is not null
&& requestResult.RedirectedToUrl.Contains("mangakatana.com/manga")) && requestResult.redirectedToUrl.Contains("mangakatana.com/manga"))
{ {
return new Publication[] { ParseSinglePublicationFromHtml(requestResult.result, requestResult.RedirectedToUrl.Split('/')[^1]) }; return new [] { ParseSinglePublicationFromHtml(requestResult.result, requestResult.redirectedToUrl.Split('/')[^1]) };
} }
return ParsePublicationsFromHtml(requestResult.result); return ParsePublicationsFromHtml(requestResult.result);
@ -58,7 +59,7 @@ public class MangaKatana : Connector
foreach (string url in urls) foreach (string url in urls)
{ {
DownloadClient.RequestResult requestResult = DownloadClient.RequestResult requestResult =
downloadClient.MakeRequest(url, (byte)1); downloadClient.MakeRequest(url, 1);
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>();
@ -107,7 +108,6 @@ public class MangaKatana : Connector
case "genres": case "genres":
tags = row.SelectNodes("div").Last().Descendants("a").Select(a => a.InnerText).ToHashSet(); tags = row.SelectNodes("div").Last().Descendants("a").Select(a => a.InnerText).ToHashSet();
break; break;
default: break;
} }
} }
@ -139,7 +139,7 @@ public class MangaKatana : Connector
string requestUrl = $"https://mangakatana.com/manga/{publication.publicationId}"; string requestUrl = $"https://mangakatana.com/manga/{publication.publicationId}";
// Leaving this in for verification if the page exists // Leaving this in for verification if the page exists
DownloadClient.RequestResult requestResult = DownloadClient.RequestResult requestResult =
downloadClient.MakeRequest(requestUrl, (byte)1); downloadClient.MakeRequest(requestUrl, 1);
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300) if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
return Array.Empty<Chapter>(); return Array.Empty<Chapter>();
@ -168,7 +168,7 @@ public class MangaKatana : Connector
string fullString = chapterInfo.Descendants("a").First().InnerText; string fullString = chapterInfo.Descendants("a").First().InnerText;
string? volumeNumber = fullString.Contains("Vol.") ? fullString.Replace("Vol.", "").Split(' ')[0] : null; string? volumeNumber = fullString.Contains("Vol.") ? fullString.Replace("Vol.", "").Split(' ')[0] : null;
string? chapterNumber = fullString.Split(':')[0].Split("Chapter ")[1].Split(" ")[0].Replace('-', '.'); string chapterNumber = fullString.Split(':')[0].Split("Chapter ")[1].Split(" ")[0].Replace('-', '.');
string chapterName = string.Concat(fullString.Split(':')[1..]); string chapterName = string.Concat(fullString.Split(':')[1..]);
string url = chapterInfo.Descendants("a").First() string url = chapterInfo.Descendants("a").First()
.GetAttributeValue("href", ""); .GetAttributeValue("href", "");
@ -186,7 +186,7 @@ public class MangaKatana : Connector
string requestUrl = chapter.url; string requestUrl = chapter.url;
// Leaving this in to check if the page exists // Leaving this in to check if the page exists
DownloadClient.RequestResult requestResult = DownloadClient.RequestResult requestResult =
downloadClient.MakeRequest(requestUrl, (byte)1); downloadClient.MakeRequest(requestUrl, 1);
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300) if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
return requestResult.statusCode; return requestResult.statusCode;
@ -195,7 +195,7 @@ public class MangaKatana : Connector
string comicInfoPath = Path.GetTempFileName(); string comicInfoPath = Path.GetTempFileName();
File.WriteAllText(comicInfoPath, chapter.GetComicInfoXmlString()); File.WriteAllText(comicInfoPath, chapter.GetComicInfoXmlString());
return DownloadChapterImages(imageUrls, chapter.GetArchiveFilePath(settings.downloadLocation), (byte)1, parentTask, comicInfoPath, "https://mangakatana.com/", cancellationToken); return DownloadChapterImages(imageUrls, chapter.GetArchiveFilePath(settings.downloadLocation), 1, parentTask, comicInfoPath, "https://mangakatana.com/", cancellationToken);
} }
private string[] ParseImageUrlsFromHtml(string mangaUrl) private string[] ParseImageUrlsFromHtml(string mangaUrl)
@ -208,6 +208,8 @@ public class MangaKatana : Connector
.Replace("\r", "") .Replace("\r", "")
.Replace("\n", "") .Replace("\n", "")
.Replace("\t", ""); .Replace("\t", "");
// ReSharper disable once StringLiteralTypo
string regexPat = @"(var thzq=\[')(.*)(,];function)"; string regexPat = @"(var thzq=\[')(.*)(,];function)";
var group = Regex.Matches(js, regexPat).First().Groups[2].Value.Replace("'", ""); var group = Regex.Matches(js, regexPat).First().Groups[2].Value.Replace("'", "");
var urls = group.Split(','); var urls = group.Split(',');

View File

@ -15,7 +15,7 @@ public class Manganato : Connector
this.name = "Manganato"; this.name = "Manganato";
this.downloadClient = new DownloadClient(new Dictionary<byte, int>() this.downloadClient = new DownloadClient(new Dictionary<byte, int>()
{ {
{(byte)1, 60} {1, 60}
}, settings.logger); }, settings.logger);
} }
@ -25,7 +25,7 @@ public class Manganato : Connector
string sanitizedTitle = string.Join('_', Regex.Matches(publicationTitle, "[A-z]*")).ToLower(); string sanitizedTitle = string.Join('_', Regex.Matches(publicationTitle, "[A-z]*")).ToLower();
string requestUrl = $"https://manganato.com/search/story/{sanitizedTitle}"; string requestUrl = $"https://manganato.com/search/story/{sanitizedTitle}";
DownloadClient.RequestResult requestResult = DownloadClient.RequestResult requestResult =
downloadClient.MakeRequest(requestUrl, (byte)1); downloadClient.MakeRequest(requestUrl, 1);
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>();
@ -50,7 +50,7 @@ public class Manganato : Connector
foreach (string url in urls) foreach (string url in urls)
{ {
DownloadClient.RequestResult requestResult = DownloadClient.RequestResult requestResult =
downloadClient.MakeRequest(url, (byte)1); downloadClient.MakeRequest(url, 1);
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>();
@ -102,7 +102,6 @@ public class Manganato : Connector
string[] genres = value.Split(" - "); string[] genres = value.Split(" - ");
tags = genres.ToHashSet(); tags = genres.ToHashSet();
break; break;
default: break;
} }
} }
@ -129,7 +128,7 @@ public class Manganato : Connector
settings.logger?.WriteLine(this.GetType().ToString(), $"Getting Chapters for {publication.sortName} {publication.internalId} (language={language})"); settings.logger?.WriteLine(this.GetType().ToString(), $"Getting Chapters for {publication.sortName} {publication.internalId} (language={language})");
string requestUrl = $"https://chapmanganato.com/{publication.publicationId}"; string requestUrl = $"https://chapmanganato.com/{publication.publicationId}";
DownloadClient.RequestResult requestResult = DownloadClient.RequestResult requestResult =
downloadClient.MakeRequest(requestUrl, (byte)1); downloadClient.MakeRequest(requestUrl, 1);
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300) if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
return Array.Empty<Chapter>(); return Array.Empty<Chapter>();
@ -158,7 +157,7 @@ public class Manganato : Connector
string fullString = chapterInfo.Descendants("a").First(d => d.HasClass("chapter-name")).InnerText; string fullString = chapterInfo.Descendants("a").First(d => d.HasClass("chapter-name")).InnerText;
string? volumeNumber = fullString.Contains("Vol.") ? fullString.Replace("Vol.", "").Split(' ')[0] : null; string? volumeNumber = fullString.Contains("Vol.") ? fullString.Replace("Vol.", "").Split(' ')[0] : null;
string? chapterNumber = fullString.Split(':')[0].Split("Chapter ")[1].Replace('-','.'); string chapterNumber = fullString.Split(':')[0].Split("Chapter ")[1].Replace('-','.');
string chapterName = string.Concat(fullString.Split(':')[1..]); string chapterName = string.Concat(fullString.Split(':')[1..]);
string url = chapterInfo.Descendants("a").First(d => d.HasClass("chapter-name")) string url = chapterInfo.Descendants("a").First(d => d.HasClass("chapter-name"))
.GetAttributeValue("href", ""); .GetAttributeValue("href", "");
@ -175,7 +174,7 @@ public class Manganato : Connector
settings.logger?.WriteLine(this.GetType().ToString(), $"Downloading Chapter-Info {publication.sortName} {publication.internalId} {chapter.volumeNumber}-{chapter.chapterNumber}"); settings.logger?.WriteLine(this.GetType().ToString(), $"Downloading Chapter-Info {publication.sortName} {publication.internalId} {chapter.volumeNumber}-{chapter.chapterNumber}");
string requestUrl = chapter.url; string requestUrl = chapter.url;
DownloadClient.RequestResult requestResult = DownloadClient.RequestResult requestResult =
downloadClient.MakeRequest(requestUrl, (byte)1); downloadClient.MakeRequest(requestUrl, 1);
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300) if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
return requestResult.statusCode; return requestResult.statusCode;
@ -184,7 +183,7 @@ public class Manganato : Connector
string comicInfoPath = Path.GetTempFileName(); string comicInfoPath = Path.GetTempFileName();
File.WriteAllText(comicInfoPath, chapter.GetComicInfoXmlString()); File.WriteAllText(comicInfoPath, chapter.GetComicInfoXmlString());
return DownloadChapterImages(imageUrls, chapter.GetArchiveFilePath(settings.downloadLocation), (byte)1, parentTask, comicInfoPath, "https://chapmanganato.com/", cancellationToken); return DownloadChapterImages(imageUrls, chapter.GetArchiveFilePath(settings.downloadLocation), 1, parentTask, comicInfoPath, "https://chapmanganato.com/", cancellationToken);
} }
private string[] ParseImageUrlsFromHtml(Stream html) private string[] ParseImageUrlsFromHtml(Stream html)

View File

@ -12,7 +12,7 @@ namespace Tranga.Connectors;
public class Mangasee : Connector public class Mangasee : Connector
{ {
public override string name { get; } public override string name { get; }
private IBrowser? _browser = null; private IBrowser? _browser;
private const string ChromiumVersion = "1154303"; private const string ChromiumVersion = "1154303";
public Mangasee(TrangaSettings settings) : base(settings) public Mangasee(TrangaSettings settings) : base(settings)
@ -20,7 +20,7 @@ public class Mangasee : Connector
this.name = "Mangasee"; this.name = "Mangasee";
this.downloadClient = new DownloadClient(new Dictionary<byte, int>() this.downloadClient = new DownloadClient(new Dictionary<byte, int>()
{ {
{ (byte)1, 60 } { 1, 60 }
}, settings.logger); }, settings.logger);
Task d = new Task(DownloadBrowser); Task d = new Task(DownloadBrowser);
@ -36,7 +36,7 @@ public class Mangasee : Connector
{ {
settings.logger?.WriteLine(this.GetType().ToString(), "Downloading headless browser"); settings.logger?.WriteLine(this.GetType().ToString(), "Downloading headless browser");
DateTime last = DateTime.Now.Subtract(TimeSpan.FromSeconds(5)); DateTime last = DateTime.Now.Subtract(TimeSpan.FromSeconds(5));
browserFetcher.DownloadProgressChanged += (sender, args) => browserFetcher.DownloadProgressChanged += (_, args) =>
{ {
double currentBytes = Convert.ToDouble(args.BytesReceived) / Convert.ToDouble(args.TotalBytesToReceive); double currentBytes = Convert.ToDouble(args.BytesReceived) / Convert.ToDouble(args.TotalBytesToReceive);
if (args.TotalBytesToReceive == args.BytesReceived) if (args.TotalBytesToReceive == args.BytesReceived)
@ -76,7 +76,7 @@ public class Mangasee : Connector
settings.logger?.WriteLine(this.GetType().ToString(), $"Getting Publications (title={publicationTitle})"); settings.logger?.WriteLine(this.GetType().ToString(), $"Getting Publications (title={publicationTitle})");
string requestUrl = $"https://mangasee123.com/_search.php"; string requestUrl = $"https://mangasee123.com/_search.php";
DownloadClient.RequestResult requestResult = DownloadClient.RequestResult requestResult =
downloadClient.MakeRequest(requestUrl, (byte)1); downloadClient.MakeRequest(requestUrl, 1);
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>();
@ -108,7 +108,7 @@ public class Mangasee : Connector
foreach (SearchResultItem orderedItem in orderedFiltered) foreach (SearchResultItem orderedItem in orderedFiltered)
{ {
DownloadClient.RequestResult requestResult = DownloadClient.RequestResult requestResult =
downloadClient.MakeRequest($"https://mangasee123.com/manga/{orderedItem.i}", (byte)1); downloadClient.MakeRequest($"https://mangasee123.com/manga/{orderedItem.i}", 1);
if ((int)requestResult.statusCode >= 200 || (int)requestResult.statusCode < 300) if ((int)requestResult.statusCode >= 200 || (int)requestResult.statusCode < 300)
{ {
settings.logger?.WriteLine(this.GetType().ToString(), $"Retrieving Publication info: {orderedItem.s} {index++}/{orderedFiltered.Count}"); settings.logger?.WriteLine(this.GetType().ToString(), $"Retrieving Publication info: {orderedItem.s} {index++}/{orderedFiltered.Count}");
@ -177,11 +177,17 @@ public class Mangasee : Connector
// ReSharper disable once ClassNeverInstantiated.Local Will be instantiated during deserialization // ReSharper disable once ClassNeverInstantiated.Local Will be instantiated during deserialization
private class SearchResultItem private class SearchResultItem
{ {
#pragma warning disable CS8618 //Will always be set public string i { get; init; }
public string i { get; set; } public string s { get; init; }
public string s { get; set; } public string[] a { get; init; }
public string[] a { get; set; }
#pragma warning restore CS8618 [JsonConstructor]
public SearchResultItem(string i, string s, string[] a)
{
this.i = i;
this.s = s;
this.a = a;
}
public int GetMatches(string title) public int GetMatches(string title)
{ {
@ -215,7 +221,7 @@ public class Mangasee : Connector
List<Chapter> ret = new(); List<Chapter> ret = new();
foreach (XElement chapter in chapterItems) foreach (XElement chapter in chapterItems)
{ {
string? volumeNumber = "1"; string volumeNumber = "1";
string chapterName = chapter.Descendants("title").First().Value; string chapterName = chapter.Descendants("title").First().Value;
string chapterNumber = Regex.Matches(chapterName, "[0-9]+")[^1].ToString(); string chapterNumber = Regex.Matches(chapterName, "[0-9]+")[^1].ToString();
@ -262,7 +268,7 @@ public class Mangasee : Connector
string comicInfoPath = Path.GetTempFileName(); string comicInfoPath = Path.GetTempFileName();
File.WriteAllText(comicInfoPath, chapter.GetComicInfoXmlString()); File.WriteAllText(comicInfoPath, chapter.GetComicInfoXmlString());
return DownloadChapterImages(urls.ToArray(), chapter.GetArchiveFilePath(settings.downloadLocation), (byte)1, parentTask, comicInfoPath, cancellationToken:cancellationToken); return DownloadChapterImages(urls.ToArray(), chapter.GetArchiveFilePath(settings.downloadLocation), 1, parentTask, comicInfoPath, cancellationToken:cancellationToken);
} }
return response.Status; return response.Status;
} }

View File

@ -89,8 +89,8 @@ internal class DownloadClient
{ {
public HttpStatusCode statusCode { get; } public HttpStatusCode statusCode { get; }
public Stream result { get; } public Stream result { get; }
public bool HasBeenRedirected { get; } public bool hasBeenRedirected { get; }
public string? RedirectedToUrl { get; } public string? redirectedToUrl { get; }
public RequestResult(HttpStatusCode statusCode, Stream result) public RequestResult(HttpStatusCode statusCode, Stream result)
{ {
@ -101,8 +101,8 @@ internal class DownloadClient
public RequestResult(HttpStatusCode statusCode, Stream result, bool hasBeenRedirected, string redirectedTo) public RequestResult(HttpStatusCode statusCode, Stream result, bool hasBeenRedirected, string redirectedTo)
: this(statusCode, result) : this(statusCode, result)
{ {
this.HasBeenRedirected = hasBeenRedirected; this.hasBeenRedirected = hasBeenRedirected;
RedirectedToUrl = redirectedTo; redirectedToUrl = redirectedTo;
} }
} }
} }

View File

@ -36,7 +36,7 @@ public class Kavita : LibraryManager
HttpResponseMessage response = client.Send(requestMessage); HttpResponseMessage response = client.Send(requestMessage);
JsonObject? result = JsonSerializer.Deserialize<JsonObject>(response.Content.ReadAsStream()); JsonObject? result = JsonSerializer.Deserialize<JsonObject>(response.Content.ReadAsStream());
if (result is not null) if (result is not null)
return result!["token"]!.GetValue<string>(); return result["token"]!.GetValue<string>();
else return ""; else return "";
} }
@ -73,7 +73,7 @@ public class Kavita : LibraryManager
{ {
var jObject = (JsonObject?)jsonNode; var jObject = (JsonObject?)jsonNode;
int libraryId = jObject!["id"]!.GetValue<int>(); int libraryId = jObject!["id"]!.GetValue<int>();
string libraryName = jObject!["name"]!.GetValue<string>(); string libraryName = jObject["name"]!.GetValue<string>();
ret.Add(new KavitaLibrary(libraryId, libraryName)); ret.Add(new KavitaLibrary(libraryId, libraryName));
} }
@ -83,6 +83,7 @@ public class Kavita : LibraryManager
private struct KavitaLibrary private struct KavitaLibrary
{ {
public int id { get; } public int id { get; }
// ReSharper disable once UnusedAutoPropertyAccessor.Local
public string name { get; } public string name { get; }
public KavitaLibrary(int id, string name) public KavitaLibrary(int id, string name)

View File

@ -54,7 +54,7 @@ public class Komga : LibraryManager
{ {
var jObject = (JsonObject?)jsonNode; var jObject = (JsonObject?)jsonNode;
string libraryId = jObject!["id"]!.GetValue<string>(); string libraryId = jObject!["id"]!.GetValue<string>();
string libraryName = jObject!["name"]!.GetValue<string>(); string libraryName = jObject["name"]!.GetValue<string>();
ret.Add(new KomgaLibrary(libraryId, libraryName)); ret.Add(new KomgaLibrary(libraryId, libraryName));
} }
@ -64,6 +64,7 @@ public class Komga : LibraryManager
private struct KomgaLibrary private struct KomgaLibrary
{ {
public string id { get; } public string id { get; }
// ReSharper disable once UnusedAutoPropertyAccessor.Local
public string name { get; } public string name { get; }
public KomgaLibrary(string id, string name) public KomgaLibrary(string id, string name)

View File

@ -3,7 +3,6 @@ using System.Net.Http.Headers;
using Logging; using Logging;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using Tranga.LibraryManagers;
namespace Tranga.LibraryManagers; namespace Tranga.LibraryManagers;
@ -15,8 +14,10 @@ public abstract class LibraryManager
Kavita = 1 Kavita = 1
} }
// ReSharper disable once UnusedAutoPropertyAccessor.Global
public LibraryType libraryType { get; } public LibraryType libraryType { get; }
public string baseUrl { get; } public string baseUrl { get; }
// ReSharper disable once MemberCanBeProtected.Global
public string auth { get; } //Base64 encoded, if you use your password everywhere, you have problems public string auth { get; } //Base64 encoded, if you use your password everywhere, you have problems
protected Logger? logger; protected Logger? logger;

View File

@ -1,5 +1,4 @@
using Logging; using Newtonsoft.Json;
using Newtonsoft.Json;
using Tranga.TrangaTasks; using Tranga.TrangaTasks;
namespace Tranga; namespace Tranga;

View File

@ -7,9 +7,11 @@ namespace Tranga.NotificationManagers;
public class Gotify : NotificationManager public class Gotify : NotificationManager
{ {
public string endpoint { get; } public string endpoint { get; }
// ReSharper disable once MemberCanBePrivate.Global
public string appToken { get; } public string appToken { get; }
private readonly HttpClient _client = new(); private readonly HttpClient _client = new();
[JsonConstructor]
public Gotify(string endpoint, string appToken, Logger? logger = null) : base(NotificationManagerType.Gotify, logger) public Gotify(string endpoint, string appToken, Logger? logger = null) : base(NotificationManagerType.Gotify, logger)
{ {
this.endpoint = endpoint; this.endpoint = endpoint;
@ -33,6 +35,7 @@ public class Gotify : NotificationManager
private class MessageData private class MessageData
{ {
// ReSharper disable four times UnusedAutoPropertyAccessor.Local
public string message { get; } public string message { get; }
public long priority { get; } public long priority { get; }
public string title { get; } public string title { get; }

View File

@ -6,8 +6,11 @@ namespace Tranga.NotificationManagers;
public class LunaSea : NotificationManager public class LunaSea : NotificationManager
{ {
public string id { get; } // ReSharper disable once MemberCanBePrivate.Global
public string id { get; init; }
private readonly HttpClient _client = new(); private readonly HttpClient _client = new();
[JsonConstructor]
public LunaSea(string id, Logger? logger = null) : base(NotificationManagerType.LunaSea, logger) public LunaSea(string id, Logger? logger = null) : base(NotificationManagerType.LunaSea, logger)
{ {
this.id = id; this.id = id;
@ -29,6 +32,7 @@ public class LunaSea : NotificationManager
private class MessageData private class MessageData
{ {
// ReSharper disable twice UnusedAutoPropertyAccessor.Local
public string title { get; } public string title { get; }
public string body { get; } public string body { get; }

View File

@ -13,15 +13,20 @@ public struct Publication
{ {
public string sortName { get; } public string sortName { get; }
public List<string> authors { get; } public List<string> authors { get; }
// ReSharper disable once UnusedAutoPropertyAccessor.Global
public Dictionary<string,string> altTitles { get; } public Dictionary<string,string> altTitles { get; }
// ReSharper disable trice MemberCanBePrivate.Global, trust // ReSharper disable once MemberCanBePrivate.Global
public string? description { get; } public string? description { get; }
public string[] tags { get; } public string[] tags { get; }
// ReSharper disable once UnusedAutoPropertyAccessor.Global
public string? posterUrl { get; } public string? posterUrl { get; }
public string? coverFileNameInCache { get; } public string? coverFileNameInCache { get; }
// ReSharper disable once UnusedAutoPropertyAccessor.Global
public Dictionary<string,string> links { get; } public Dictionary<string,string> links { get; }
// ReSharper disable once MemberCanBePrivate.Global
public int? year { get; } public int? year { get; }
public string? originalLanguage { get; } public string? originalLanguage { get; }
// ReSharper disable once MemberCanBePrivate.Global
public string status { get; } public string status { get; }
public string folderName { get; } public string folderName { get; }
public string publicationId { get; } public string publicationId { get; }
@ -74,7 +79,7 @@ public struct Publication
} }
/// <returns>Serialized JSON String for series.json</returns> /// <returns>Serialized JSON String for series.json</returns>
public string GetSeriesInfoJson() private string GetSeriesInfoJson()
{ {
SeriesInfo si = new (new Metadata(this.sortName, this.year.ToString() ?? string.Empty, this.status, this.description ?? "")); SeriesInfo si = new (new Metadata(this.sortName, this.year.ToString() ?? string.Empty, this.status, this.description ?? ""));
return System.Text.Json.JsonSerializer.Serialize(si); return System.Text.Json.JsonSerializer.Serialize(si);

View File

@ -1,5 +1,4 @@
using Logging; using Newtonsoft.Json;
using Newtonsoft.Json;
using Tranga.Connectors; using Tranga.Connectors;
using Tranga.TrangaTasks; using Tranga.TrangaTasks;
@ -182,6 +181,7 @@ public class TaskManager
ExportDataAndSettings(); ExportDataAndSettings();
} }
// ReSharper disable once MemberCanBePrivate.Global
public IEnumerable<TrangaTask> GetTasksMatching(TrangaTask mTask) public IEnumerable<TrangaTask> GetTasksMatching(TrangaTask mTask)
{ {
switch (mTask.task) switch (mTask.task)
@ -336,11 +336,10 @@ public class TaskManager
private void ImportData() private void ImportData()
{ {
settings.logger?.WriteLine(this.GetType().ToString(), "Importing Data"); settings.logger?.WriteLine(this.GetType().ToString(), "Importing Data");
string buffer;
if (File.Exists(settings.tasksFilePath)) if (File.Exists(settings.tasksFilePath))
{ {
settings.logger?.WriteLine(this.GetType().ToString(), $"Importing tasks from {settings.tasksFilePath}"); settings.logger?.WriteLine(this.GetType().ToString(), $"Importing tasks from {settings.tasksFilePath}");
buffer = File.ReadAllText(settings.tasksFilePath); string buffer = File.ReadAllText(settings.tasksFilePath);
this._allTasks = JsonConvert.DeserializeObject<HashSet<TrangaTask>>(buffer, new JsonSerializerSettings() { Converters = { new TrangaTask.TrangaTaskJsonConverter() } })!; this._allTasks = JsonConvert.DeserializeObject<HashSet<TrangaTask>>(buffer, new JsonSerializerSettings() { Converters = { new TrangaTask.TrangaTaskJsonConverter() } })!;
} }

View File

@ -9,10 +9,11 @@ public class DownloadChapterTask : TrangaTask
{ {
public string connectorName { get; } public string connectorName { get; }
public Publication publication { get; } public Publication publication { get; }
// ReSharper disable once MemberCanBePrivate.Global
public string language { get; } public string language { get; }
public Chapter chapter { get; } public Chapter chapter { get; }
private double _dctProgress = 0; private double _dctProgress;
public DownloadChapterTask(string connectorName, Publication publication, Chapter chapter, string language = "en", MonitorPublicationTask? parentTask = null) : base(Task.DownloadChapter, TimeSpan.Zero, parentTask) public DownloadChapterTask(string connectorName, Publication publication, Chapter chapter, string language = "en", MonitorPublicationTask? parentTask = null) : base(Task.DownloadChapter, TimeSpan.Zero, parentTask)
{ {
@ -27,7 +28,7 @@ public class DownloadChapterTask : TrangaTask
if (cancellationToken?.IsCancellationRequested ?? false) if (cancellationToken?.IsCancellationRequested ?? false)
return HttpStatusCode.RequestTimeout; return HttpStatusCode.RequestTimeout;
Connector connector = taskManager.GetConnector(this.connectorName); Connector connector = taskManager.GetConnector(this.connectorName);
connector.CopyCoverFromCacheToDownloadLocation(this.publication, taskManager.settings); connector.CopyCoverFromCacheToDownloadLocation(this.publication);
HttpStatusCode downloadSuccess = connector.DownloadChapter(this.publication, this.chapter, this, cancellationToken); HttpStatusCode downloadSuccess = connector.DownloadChapter(this.publication, this.chapter, this, cancellationToken);
if ((int)downloadSuccess >= 200 && (int)downloadSuccess < 300) if ((int)downloadSuccess >= 200 && (int)downloadSuccess < 300)
{ {

View File

@ -7,6 +7,7 @@ public class MonitorPublicationTask : TrangaTask
{ {
public string connectorName { get; } public string connectorName { get; }
public Publication publication { get; } public Publication publication { get; }
// ReSharper disable once MemberCanBePrivate.Global
public string language { get; } public string language { get; }
public MonitorPublicationTask(string connectorName, Publication publication, TimeSpan reoccurrence, string language = "en") : base(Task.MonitorPublication, reoccurrence) public MonitorPublicationTask(string connectorName, Publication publication, TimeSpan reoccurrence, string language = "en") : base(Task.MonitorPublication, reoccurrence)
{ {
@ -25,7 +26,7 @@ public class MonitorPublicationTask : TrangaTask
publication.CreatePublicationFolder(taskManager.settings.downloadLocation); publication.CreatePublicationFolder(taskManager.settings.downloadLocation);
List<Chapter> newChapters = connector.GetNewChaptersList(publication, language, ref taskManager.collection); List<Chapter> newChapters = connector.GetNewChaptersList(publication, language, ref taskManager.collection);
connector.CopyCoverFromCacheToDownloadLocation(publication, taskManager.settings); connector.CopyCoverFromCacheToDownloadLocation(publication);
publication.SaveSeriesInfoJson(taskManager.settings.downloadLocation); publication.SaveSeriesInfoJson(taskManager.settings.downloadLocation);

View File

@ -1,6 +1,5 @@
using System.Net; using System.Net;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
using Logging;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using JsonConverter = Newtonsoft.Json.JsonConverter; using JsonConverter = Newtonsoft.Json.JsonConverter;
@ -15,8 +14,7 @@ namespace Tranga.TrangaTasks;
[JsonDerivedType(typeof(DownloadChapterTask), 4)] [JsonDerivedType(typeof(DownloadChapterTask), 4)]
public abstract class TrangaTask public abstract class TrangaTask
{ {
// ReSharper disable once CommentTypo ...Tell me why! // ReSharper disable once MemberCanBeProtected.Global
// ReSharper disable once MemberCanBePrivate.Global I want it thaaat way
public TimeSpan reoccurrence { get; } public TimeSpan reoccurrence { get; }
public DateTime lastExecuted { get; set; } public DateTime lastExecuted { get; set; }
[Newtonsoft.Json.JsonIgnore] public ExecutionState state { get; set; } [Newtonsoft.Json.JsonIgnore] public ExecutionState state { get; set; }
@ -26,9 +24,12 @@ public abstract class TrangaTask
public string? parentTaskId { get; set; } public string? parentTaskId { get; set; }
[Newtonsoft.Json.JsonIgnore] internal HashSet<TrangaTask> childTasks { get; } [Newtonsoft.Json.JsonIgnore] internal HashSet<TrangaTask> childTasks { get; }
public double progress => GetProgress(); public double progress => GetProgress();
// ReSharper disable once MemberCanBePrivate.Global
[Newtonsoft.Json.JsonIgnore]public DateTime executionStarted { get; private set; } [Newtonsoft.Json.JsonIgnore]public DateTime executionStarted { get; private set; }
[Newtonsoft.Json.JsonIgnore]public DateTime lastChange { get; internal set; } [Newtonsoft.Json.JsonIgnore]public DateTime lastChange { get; internal set; }
// ReSharper disable once MemberCanBePrivate.Global
[Newtonsoft.Json.JsonIgnore]public DateTime executionApproximatelyFinished => lastChange.Add(GetRemainingTime()); [Newtonsoft.Json.JsonIgnore]public DateTime executionApproximatelyFinished => lastChange.Add(GetRemainingTime());
// ReSharper disable once MemberCanBePrivate.Global
public TimeSpan executionApproximatelyRemaining => executionApproximatelyFinished.Subtract(DateTime.Now); public TimeSpan executionApproximatelyRemaining => executionApproximatelyFinished.Subtract(DateTime.Now);
[Newtonsoft.Json.JsonIgnore]public DateTime nextExecution => lastExecuted.Add(reoccurrence); [Newtonsoft.Json.JsonIgnore]public DateTime nextExecution => lastExecuted.Add(reoccurrence);

View File

@ -1,5 +1,4 @@
using System.Net; using System.Net;
using Logging;
namespace Tranga.TrangaTasks; namespace Tranga.TrangaTasks;