Compare commits

..

79 Commits

Author SHA1 Message Date
290761bfb0 Merge branch 'refs/heads/cuttingedge-merge-ServerV2' into dev 2024-09-21 20:23:38 +02:00
d2074fae35 Readable CheckChapterIsDownloaded check 2024-09-21 20:23:21 +02:00
713bbc230f Merge branch 'refs/heads/cuttingedge-merge-ServerV2' into cuttingedge 2024-09-18 18:56:09 +02:00
32ab9a552f Also delete files on UpdateJobFile if we dont provide a filepath 2024-09-18 18:56:01 +02:00
c11c68d6d7 Merge branch 'refs/heads/cuttingedge-merge-ServerV2' into cuttingedge 2024-09-18 18:46:02 +02:00
09fdb6e5f1 Fix #250 old jobs getting re-exported. 2024-09-18 18:45:55 +02:00
e86ad03b1e Merge branch 'refs/heads/cuttingedge-merge-ServerV2' into cuttingedge 2024-09-17 00:51:30 +02:00
9dfbe89e87 include --platform=$BUILDPLATFORM in Dockerfile 2024-09-17 00:51:22 +02:00
98e75af486 Merge branch 'cuttingedge' of ssh://git.bernloehr.eu:222/glax/Tranga into cuttingedge 2024-09-16 23:21:13 +02:00
e2f5c3badc Merge branch 'refs/heads/cuttingedge-merge-ServerV2' into cuttingedge 2024-09-16 23:18:57 +02:00
cda07bb9aa Merge branch 'refs/heads/cuttingedge-merge-ServerV2' into cuttingedge 2024-09-16 23:09:43 +02:00
7c18466e95 Fix NETSDK1194 on build 2024-09-16 23:09:34 +02:00
ce1c4d3f65 Merge branch 'refs/heads/cuttingedge-merge-ServerV2' into cuttingedge 2024-09-16 22:48:06 +02:00
52d0489a1b Fix duplicate mangas on startup 2024-09-16 22:47:55 +02:00
f89aea6ac8 Merge branch 'refs/heads/cuttingedge-merge-ServerV2' into cuttingedge 2024-09-16 21:19:27 +02:00
5f05ba1049 Make SupportedLanguages public. 2024-09-16 21:19:19 +02:00
a20ee01cfa Merge branch 'refs/heads/cuttingedge-merge-ServerV2' into cuttingedge 2024-09-16 21:17:18 +02:00
cf5cbba9a8 #247 Add supported languages to Mangaconnectors 2024-09-16 21:17:07 +02:00
600b56033d Upgrade to Dotnet 8.0 LangVer 12 2024-09-16 21:11:50 +02:00
fdea3659f1 Merge branch 'refs/heads/cuttingedge-merge-ServerV2' into cuttingedge 2024-09-16 20:38:19 +02:00
7f3754fb64 Fix startup issue/issue with existing chapters: ProgressToken would not complete 2024-09-16 20:36:40 +02:00
2dac5db4da Create single Chromium Instance that is shared between all Connectors.
Fix pages staying open when page could not be loaded.
2024-09-16 20:30:23 +02:00
3456fc6564 Merge branch 'refs/heads/cuttingedge-merge-ServerV2' into cuttingedge 2024-09-16 19:52:39 +02:00
35f2625f05 Fix #249 Manhuaplus where author/tags are not set. 2024-09-16 19:52:25 +02:00
0b9948e367 Merge branch 'refs/heads/cuttingedge-merge-ServerV2' into cuttingedge 2024-09-16 18:32:45 +02:00
96f3dbce65 Throw more readable exceptions if deserialization fails for Mangaconnectors.
#249
2024-09-16 18:32:34 +02:00
895128a462 Merge remote-tracking branch 'origin/cuttingedge-merge-ServerV2' into cuttingedge-merge-ServerV2 2024-09-16 18:24:39 +02:00
a94186455b Merge branch 'refs/heads/cuttingedge-merge-ServerV2' into cuttingedge 2024-09-11 14:41:35 +02:00
7d3deee74c Remove unused constant 2024-09-11 14:40:28 +02:00
5980b64caa Readable Chapter comparison 2024-09-11 14:40:03 +02:00
cbecb257ef Remove unused constant 2024-09-11 14:39:16 +02:00
7ff9ac53ee Build all docker images with new workflow #233 2024-09-09 09:42:52 +02:00
6faaaf4139 Fix #243 Moving Publication folders, overwrite files, merge folders 2024-09-09 09:23:25 +02:00
9b8b80cd24 Fix response closed on OPTIONS request 2024-09-07 20:44:15 +02:00
15f3e2b8ec Use current time as internalId for Manga instead of BASE64 string of title
#232
Fix #237
2024-09-07 20:33:03 +02:00
2be29e4019 MangaDex only download single release for chapter.
Fix #219
2024-09-07 20:16:05 +02:00
e8dbf7a718
Merge pull request #233 from vonProteus/arm64
Added support for ARM
2024-08-31 20:57:44 +02:00
vonProteus
a968f4328d
Added support for ARM 2024-08-31 20:38:10 +02:00
398b6fff05
Merge pull request #230 from C9Glax/cuttingedge-merge-candidate
Cuttingedge merge candidate
2024-08-31 20:25:33 +02:00
f5da2f8526
Merge pull request #231 from C9Glax/dependabot/github_actions/docker/build-push-action-6.7.0
Bump docker/build-push-action from 6.6.1 to 6.7.0
2024-08-31 20:24:43 +02:00
dependabot[bot]
73093ab86c
Bump docker/build-push-action from 6.6.1 to 6.7.0
Bumps [docker/build-push-action](https://github.com/docker/build-push-action) from 6.6.1 to 6.7.0.
- [Release notes](https://github.com/docker/build-push-action/releases)
- [Commits](https://github.com/docker/build-push-action/compare/v6.6.1...v6.7.0)

---
updated-dependencies:
- dependency-name: docker/build-push-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-08-27 05:55:58 +00:00
fccaf9fcbe Merge branch 'refs/heads/cuttingedge-merge-ServerV2' into cuttingedge 2024-08-26 20:47:06 +02:00
3122aa32e8 fix #223 wrong selector 2024-08-26 20:46:50 +02:00
02fad2dd44 Merge branch 'refs/heads/cuttingedge-merge-ServerV2' into cuttingedge 2024-08-26 20:28:51 +02:00
e0a7d1a187 Fix #220 Mangaworld Chapter number parsing 2024-08-26 20:28:40 +02:00
d0f9a4102c Merge branch 'refs/heads/cuttingedge-merge-ServerV2' into cuttingedge 2024-08-26 20:18:44 +02:00
9f178821b6 Fix #223 Manganato chapter relative dates. 2024-08-26 20:18:35 +02:00
682fd0bc2a Merge branch 'refs/heads/cuttingedge-merge-ServerV2' into cuttingedge 2024-08-26 13:22:09 +02:00
dfa8e66f34 Fix try-block in Server.cs 2024-08-26 13:21:54 +02:00
8f51d22303 Fix try-block in Server.cs 2024-08-26 13:21:34 +02:00
d41de84262 Merge branch 'refs/heads/cuttingedge-merge-ServerV2' into cuttingedge
# Conflicts:
#	Tranga/Server.cs
2024-08-26 13:21:05 +02:00
1bd20791b8 Add Cache-Control headers 2024-08-26 13:18:48 +02:00
03aeab44cd Merge branch 'refs/heads/cuttingedge-merge-ServerV2' into cuttingedge 2024-08-26 13:11:41 +02:00
6d723b6355 Fix Settings not returning as JSON 2024-08-26 13:11:00 +02:00
7b91bb699f Fix Settings not loading on reload 2024-08-26 13:10:47 +02:00
14e33cc496 Fix Settings not loading on reload 2024-08-26 13:09:33 +02:00
6f3bba99b0 Fix Settings not returning as JSON 2024-08-26 12:59:19 +02:00
2d848843d0 Merge branch 'refs/heads/cuttingedge-merge-ServerV2' into cuttingedge 2024-08-26 12:37:03 +02:00
63b493fa9c Rework TrangaSettings 2024-08-26 12:36:35 +02:00
001a37b8ef Merge branch 'refs/heads/cuttingedge-merge-ServerV2' into cuttingedge 2024-08-26 11:18:12 +02:00
69d6884517 #227 Fix wrong filtering, only return top 10 results 2024-08-26 11:17:59 +02:00
db73af3bdd Fix crash when outputstream closes before response could be sent.
#227
2024-08-26 10:38:45 +02:00
59547efab2 Merge branch 'refs/heads/cuttingedge-merge-ServerV2' into cuttingedge 2024-08-26 10:35:37 +02:00
f4336f9777 #227 Mangasee Return results that have similarity over 95% or at least top ten results 2024-08-26 10:35:16 +02:00
bec3ac52a9 Merge branch 'refs/heads/cuttingedge-merge-ServerV2' into cuttingedge 2024-08-20 20:53:09 +02:00
ea37e81ece Fix last commit 2024-08-20 20:53:03 +02:00
6a20783d48 Merge branch 'refs/heads/cuttingedge-merge-ServerV2' into cuttingedge 2024-08-20 20:47:21 +02:00
21af75f410 Faster download for images-urls.
#224
2024-08-20 20:47:13 +02:00
a629792818 Merge branch 'refs/heads/cuttingedge-merge-ServerV2' into cuttingedge 2024-08-08 21:09:26 +02:00
34dd78810d Update README.md 2024-08-08 21:09:08 +02:00
e1c504226c Merge branch 'refs/heads/cuttingedge-merge-ServerV2' into cuttingedge 2024-08-08 21:04:09 +02:00
200a22228f add log output for Mangahere
https://github.com/C9Glax/tranga/issues/69
2024-08-08 21:02:13 +02:00
bc10136331 MangaHere image download sucks, you have to iterate all over all images one by one. Have some extra traffic then, idc.
https://github.com/C9Glax/tranga/issues/69
2024-08-08 21:00:37 +02:00
06df6e0767 Merge branch 'refs/heads/cuttingedge-merge-ServerV2' into cuttingedge 2024-08-08 19:00:26 +02:00
89b5aa266e Merge branch 'refs/heads/cuttingedge-merge-ServerV2' into cuttingedge 2024-07-31 19:25:03 +02:00
80e2568113 Merge branch 'refs/heads/cuttingedge-merge-ServerV2' into cuttingedge 2024-07-31 17:48:21 +02:00
2812a6dff1 Merge branch 'refs/heads/cuttingedge-merge-ServerV2' into cuttingedge 2024-07-31 17:44:37 +02:00
8e5d15ead9 Merge branch 'refs/heads/cuttingedge-merge-ServerV2' into cuttingedge 2024-07-11 15:46:27 +02:00
dd2fa3fbd7 Merge branch 'refs/heads/cuttingedge-merge-ServerV2' into cuttingedge 2024-07-09 11:17:58 +02:00
39 changed files with 639 additions and 474 deletions

View File

@ -23,3 +23,5 @@
**/values.dev.yaml **/values.dev.yaml
LICENSE LICENSE
README.md README.md
Manga
settings

View File

@ -1,43 +0,0 @@
name: Docker Image CI
on:
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
# https://github.com/docker/setup-qemu-action#usage
- name: Set up QEMU
uses: docker/setup-qemu-action@v3.2.0
# https://github.com/marketplace/actions/docker-setup-buildx
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3.6.1
# https://github.com/docker/login-action#docker-hub
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
# https://github.com/docker/build-push-action#multi-platform-image
- name: Build and push base
uses: docker/build-push-action@v6.6.1
with:
context: ./
file: ./Dockerfile-base
#platforms: linux/amd64,linux/arm64,linux/riscv64,linux/ppc64le,linux/s390x,linux/386,linux/mips64le,linux/mips64,linux/arm/v7,linux/arm/v6
platforms: linux/amd64
pull: true
push: true
tags: |
glax/tranga-base:latest

View File

@ -33,12 +33,12 @@ jobs:
# https://github.com/docker/build-push-action#multi-platform-image # https://github.com/docker/build-push-action#multi-platform-image
- name: Build and push API - name: Build and push API
uses: docker/build-push-action@v6.6.1 uses: docker/build-push-action@v6.7.0
with: with:
context: ./ context: ./
file: ./Dockerfile file: ./Dockerfile
#platforms: linux/amd64,linux/arm64,linux/riscv64,linux/ppc64le,linux/s390x,linux/386,linux/mips64le,linux/mips64,linux/arm/v7,linux/arm/v6 #platforms: linux/amd64,linux/arm64,linux/riscv64,linux/ppc64le,linux/s390x,linux/386,linux/mips64le,linux/mips64,linux/arm/v7,linux/arm/v6
platforms: linux/amd64 platforms: linux/amd64,linux/arm64
pull: true pull: true
push: true push: true
tags: | tags: |

View File

@ -33,12 +33,12 @@ jobs:
# https://github.com/docker/build-push-action#multi-platform-image # https://github.com/docker/build-push-action#multi-platform-image
- name: Build and push API - name: Build and push API
uses: docker/build-push-action@v6.6.1 uses: docker/build-push-action@v6.7.0
with: with:
context: ./ context: ./
file: ./Dockerfile file: ./Dockerfile
#platforms: linux/amd64,linux/arm64,linux/riscv64,linux/ppc64le,linux/s390x,linux/386,linux/mips64le,linux/mips64,linux/arm/v7,linux/arm/v6 #platforms: linux/amd64,linux/arm64,linux/riscv64,linux/ppc64le,linux/s390x,linux/386,linux/mips64le,linux/mips64,linux/arm/v7,linux/arm/v6
platforms: linux/amd64 platforms: linux/amd64,linux/arm64
pull: true pull: true
push: true push: true
tags: | tags: |

View File

@ -33,12 +33,12 @@ jobs:
# https://github.com/docker/build-push-action#multi-platform-image # https://github.com/docker/build-push-action#multi-platform-image
- name: Build and push API - name: Build and push API
uses: docker/build-push-action@v6.6.1 uses: docker/build-push-action@v6.7.0
with: with:
context: ./ context: ./
file: ./Dockerfile file: ./Dockerfile
#platforms: linux/amd64,linux/arm64,linux/riscv64,linux/ppc64le,linux/s390x,linux/386,linux/mips64le,linux/mips64,linux/arm/v7,linux/arm/v6 #platforms: linux/amd64,linux/arm64,linux/riscv64,linux/ppc64le,linux/s390x,linux/386,linux/mips64le,linux/mips64,linux/arm/v7,linux/arm/v6
platforms: linux/amd64 platforms: linux/amd64,linux/arm64
pull: true pull: true
push: true push: true
tags: | tags: |

View File

@ -33,12 +33,12 @@ jobs:
# https://github.com/docker/build-push-action#multi-platform-image # https://github.com/docker/build-push-action#multi-platform-image
- name: Build and push API - name: Build and push API
uses: docker/build-push-action@v6.6.1 uses: docker/build-push-action@v6.7.0
with: with:
context: ./ context: ./
file: ./Dockerfile file: ./Dockerfile
#platforms: linux/amd64,linux/arm64,linux/riscv64,linux/ppc64le,linux/s390x,linux/386,linux/mips64le,linux/mips64,linux/arm/v7,linux/arm/v6 #platforms: linux/amd64,linux/arm64,linux/riscv64,linux/ppc64le,linux/s390x,linux/386,linux/mips64le,linux/mips64,linux/arm/v7,linux/arm/v6
platforms: linux/amd64 platforms: linux/amd64,linux/arm64
pull: true pull: true
push: true push: true
tags: | tags: |

3
.gitignore vendored
View File

@ -20,3 +20,6 @@ riderModule.iml
cover.jpg cover.jpg
cover.png cover.png
/.vscode /.vscode
/Manga
/settings
*.DotSettings.user

View File

@ -2,9 +2,10 @@
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework> <TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<LangVersion>12</LangVersion>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@ -47,37 +47,18 @@ internal sealed class TrangaCli : Command<TrangaCli.Settings>
string? logFolderPath = settings.fileLoggerPath ?? ""; string? logFolderPath = settings.fileLoggerPath ?? "";
Logger logger = new(enabledLoggers.ToArray(), Console.Out, Console.OutputEncoding, logFolderPath); Logger logger = new(enabledLoggers.ToArray(), Console.Out, Console.OutputEncoding, logFolderPath);
TrangaSettings? trangaSettings = null; if(settings.workingDirectory is not null)
TrangaSettings.LoadFromWorkingDirectory(settings.workingDirectory);
if (settings.downloadLocation is not null && settings.workingDirectory is not null)
{
trangaSettings = new TrangaSettings(settings.downloadLocation, settings.workingDirectory);
}else if (settings.downloadLocation is not null)
{
if (trangaSettings is null)
trangaSettings = new TrangaSettings(downloadLocation: settings.downloadLocation);
else else
trangaSettings = new TrangaSettings(downloadLocation: settings.downloadLocation, settings.workingDirectory); TrangaSettings.CreateOrUpdate();
}else if (settings.workingDirectory is not null) if(settings.downloadLocation is not null)
{ TrangaSettings.CreateOrUpdate(downloadDirectory: settings.downloadLocation);
if (trangaSettings is null)
trangaSettings = new TrangaSettings(downloadLocation: settings.workingDirectory);
else
trangaSettings = new TrangaSettings(settings.downloadLocation, settings.workingDirectory);
}
else
{
trangaSettings = new TrangaSettings();
}
Directory.CreateDirectory(trangaSettings.downloadLocation);
Directory.CreateDirectory(trangaSettings.workingDirectory);
Tranga.Tranga? api = null; Tranga.Tranga? api = null;
Thread trangaApi = new Thread(() => Thread trangaApi = new Thread(() =>
{ {
api = new(logger, trangaSettings); api = new(logger);
}); });
trangaApi.Start(); trangaApi.Start();
@ -120,7 +101,7 @@ internal sealed class TrangaCli : Command<TrangaCli.Settings>
parameters.Add(new ValueTuple<string, string>(name, value)); parameters.Add(new ValueTuple<string, string>(name, value));
} }
string requestString = $"http://localhost:{trangaSettings.apiPortNumber}/{requestPath}"; string requestString = $"http://localhost:{TrangaSettings.apiPortNumber}/{requestPath}";
if (parameters.Any()) if (parameters.Any())
{ {
requestString += "?"; requestString += "?";

View File

@ -1,29 +1,42 @@
# syntax=docker/dockerfile:1 # syntax=docker/dockerfile:1
ARG DOTNET=8.0
FROM mcr.microsoft.com/dotnet/sdk:7.0 as build-env FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/runtime:$DOTNET AS base
WORKDIR /publish
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium
RUN apt-get update \
&& apt-get install -y libx11-6 libx11-xcb1 libatk1.0-0 libgtk-3-0 libcups2 libdrm2 libxkbcommon0 libxcomposite1 libxdamage1 libxrandr2 libgbm1 libpango-1.0-0 libcairo2 libasound2 libxshmfence1 libnss3 chromium \
&& apt-get autopurge -y \
&& apt-get autoclean -y
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:$DOTNET AS build-env
WORKDIR /src WORKDIR /src
COPY CLI /src/CLI
COPY Tranga /src/Tranga
COPY Logging /src/Logging
COPY Tranga.sln /src
RUN dotnet restore /src/Tranga/Tranga.csproj
RUN dotnet publish -c Release -o /publish
FROM glax/tranga-base:latest as runtime COPY Tranga.sln /src
COPY CLI/CLI.csproj /src/CLI/CLI.csproj
COPY Logging/Logging.csproj /src/Logging/Logging.csproj
COPY Tranga/Tranga.csproj /src/Tranga/Tranga.csproj
RUN dotnet restore /src/Tranga.sln
COPY . /src/
RUN dotnet publish -c Release --property:OutputPath=/publish -maxcpucount:1
FROM --platform=$BUILDPLATFORM base AS runtime
EXPOSE 6531 EXPOSE 6531
ARG UNAME=tranga ARG UNAME=tranga
ARG UID=1000 ARG UID=1000
ARG GID=1000 ARG GID=1000
RUN groupadd -g $GID -o $UNAME RUN groupadd -g $GID -o $UNAME \
RUN useradd -m -u $UID -g $GID -o -s /bin/bash $UNAME && useradd -m -u $UID -g $GID -o -s /bin/bash $UNAME \
RUN mkdir /usr/share/tranga-api && mkdir /usr/share/tranga-api \
RUN mkdir /Manga && mkdir /Manga \
RUN chown 1000:1000 /usr/share/tranga-api && chown 1000:1000 /usr/share/tranga-api \
RUN chown 1000:1000 /Manga && chown 1000:1000 /Manga
USER $UNAME USER $UNAME
WORKDIR /publish WORKDIR /publish
COPY --from=build-env /publish . COPY --chown=1000:1000 --from=build-env /publish .
USER 0 USER 0
RUN chown 1000:1000 /publish ENTRYPOINT ["dotnet", "/publish/Tranga.dll"]
ENTRYPOINT ["dotnet", "/publish/Tranga.dll", "-f", "-c", "-l", "/usr/share/tranga-api/logs"] CMD ["-f", "-c", "-l", "/usr/share/tranga-api/logs"]

View File

@ -1,8 +0,0 @@
# syntax=docker/dockerfile:1
#FROM mcr.microsoft.com/dotnet/aspnet:7.0 as runtime
FROM mcr.microsoft.com/dotnet/runtime:7.0 as runtime
WORKDIR /publish
RUN apt-get update
RUN apt-get install -y libx11-6 libx11-xcb1 libatk1.0-0 libgtk-3-0 libcups2 libdrm2 libxkbcommon0 libxcomposite1 libxdamage1 libxrandr2 libgbm1 libpango-1.0-0 libcairo2 libasound2 libxshmfence1 libnss3
RUN apt-get autopurge -y
RUN apt-get autoclean -y

View File

@ -1,9 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net7.0</TargetFramework> <TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<LangVersion>12</LangVersion>
</PropertyGroup> </PropertyGroup>
</Project> </Project>

View File

@ -50,6 +50,8 @@ Tranga can download Chapters and Metadata from "Scanlation" sites such as
- [Mangaworld.bz](https://www.mangaworld.bz/) (it) - [Mangaworld.bz](https://www.mangaworld.bz/) (it)
- [Bato.to](https://bato.to/v3x) (en) - [Bato.to](https://bato.to/v3x) (en)
- [Manga4Life](https://manga4life.com) (en) - [Manga4Life](https://manga4life.com) (en)
- [ManhuaPlus](https://manhuaplus.org/) (en)
- [MangaHere](https://www.mangahere.cc/) (en) (Their covers suck)
- ❓ Open an [issue](https://github.com/C9Glax/tranga/issues) - ❓ Open an [issue](https://github.com/C9Glax/tranga/issues)
and trigger a library-scan with [Komga](https://komga.org/) and [Kavita](https://www.kavitareader.com/). and trigger a library-scan with [Komga](https://komga.org/) and [Kavita](https://www.kavitareader.com/).

View File

@ -58,8 +58,9 @@ public readonly struct Chapter : IComparable
public int CompareTo(object? obj) public int CompareTo(object? obj)
{ {
if (obj is Chapter otherChapter) if(obj is not Chapter otherChapter)
{ throw new ArgumentException($"{obj} can not be compared to {this}");
if (float.TryParse(volumeNumber, GlobalBase.numberFormatDecimalPoint, out float volumeNumberFloat) && if (float.TryParse(volumeNumber, GlobalBase.numberFormatDecimalPoint, out float volumeNumberFloat) &&
float.TryParse(chapterNumber, GlobalBase.numberFormatDecimalPoint, out float chapterNumberFloat) && float.TryParse(chapterNumber, GlobalBase.numberFormatDecimalPoint, out float chapterNumberFloat) &&
float.TryParse(otherChapter.volumeNumber, GlobalBase.numberFormatDecimalPoint, float.TryParse(otherChapter.volumeNumber, GlobalBase.numberFormatDecimalPoint,
@ -67,54 +68,49 @@ public readonly struct Chapter : IComparable
float.TryParse(otherChapter.chapterNumber, GlobalBase.numberFormatDecimalPoint, float.TryParse(otherChapter.chapterNumber, GlobalBase.numberFormatDecimalPoint,
out float otherChapterNumberFloat)) out float otherChapterNumberFloat))
{ {
return volumeNumberFloat.CompareTo(otherVolumeNumberFloat) switch
switch (volumeNumberFloat.CompareTo(otherVolumeNumberFloat))
{ {
case < 0: <0 => -1,
return -1; >0 => 1,
case > 0: _ => chapterNumberFloat.CompareTo(otherChapterNumberFloat)
return 1; };
default:
return chapterNumberFloat.CompareTo(otherChapterNumberFloat);
}
} }
else throw new FormatException($"Value could not be parsed"); else throw new FormatException($"Value could not be parsed");
} }
throw new ArgumentException($"{obj} can not be compared to {this}");
}
/// <summary> /// <summary>
/// Checks if a chapter-archive is already present /// Checks if a chapter-archive is already present
/// </summary> /// </summary>
/// <returns>true if chapter is present</returns> /// <returns>true if chapter is present</returns>
internal bool CheckChapterIsDownloaded(string downloadLocation) internal bool CheckChapterIsDownloaded()
{ {
if (!Directory.Exists(Path.Join(downloadLocation, parentManga.folderName))) string mangaDirectory = Path.Join(TrangaSettings.downloadLocation, parentManga.folderName);
if (!Directory.Exists(mangaDirectory))
return false; return false;
FileInfo[] archives = new DirectoryInfo(Path.Join(downloadLocation, parentManga.folderName)).GetFiles().Where(file => file.Name.Split('.')[^1] == "cbz").ToArray(); FileInfo[] archives = new DirectoryInfo(mangaDirectory).GetFiles("*.cbz");
Regex volChRex = new(@"(?:Vol(?:ume)?\.([0-9]+)\D*)?Ch(?:apter)?\.([0-9]+(?:\.[0-9]+)*)"); Regex volChRex = new(@"(?:Vol(?:ume)?\.([0-9]+)\D*)?Ch(?:apter)?\.([0-9]+(?:\.[0-9]+)*)");
Chapter t = this; Chapter t = this;
string thisPath = GetArchiveFilePath(downloadLocation); string correctPath = GetArchiveFilePath();
FileInfo? archive = archives.FirstOrDefault(archive => FileInfo? archive = archives.FirstOrDefault(archive =>
{ {
Match m = volChRex.Match(archive.Name); Match m = volChRex.Match(archive.Name);
string archiveVolNum = m.Groups[1].Success ? m.Groups[1].Value : "0"; if (m.Groups[1].Success)
string archiveChNum = m.Groups[2].Value; return m.Groups[1].Value == t.volumeNumber && m.Groups[2].Value == t.chapterNumber;
return archiveVolNum == t.volumeNumber && archiveChNum == t.chapterNumber || else
archiveVolNum == "0" && archiveChNum == t.chapterNumber; return m.Groups[2].Value == t.chapterNumber;
}); });
if(archive is not null && thisPath != archive.FullName) if(archive is not null && archive.FullName != correctPath)
archive.MoveTo(thisPath, true); archive.MoveTo(correctPath, true);
return archive is not null; return (archive is not null);
} }
/// <summary> /// <summary>
/// Creates full file path of chapter-archive /// Creates full file path of chapter-archive
/// </summary> /// </summary>
/// <returns>Filepath</returns> /// <returns>Filepath</returns>
internal string GetArchiveFilePath(string downloadLocation) internal string GetArchiveFilePath()
{ {
return Path.Join(downloadLocation, parentManga.folderName, $"{parentManga.folderName} - {this.fileName}.cbz"); return Path.Join(TrangaSettings.downloadLocation, parentManga.folderName, $"{parentManga.folderName} - {this.fileName}.cbz");
} }
/// <summary> /// <summary>

View File

@ -11,7 +11,6 @@ public abstract class GlobalBase
{ {
[JsonIgnore] [JsonIgnore]
public Logger? logger { get; init; } public Logger? logger { get; init; }
protected TrangaSettings settings { get; init; }
protected HashSet<NotificationConnector> notificationConnectors { get; init; } protected HashSet<NotificationConnector> notificationConnectors { get; init; }
protected HashSet<LibraryConnector> libraryConnectors { get; init; } protected HashSet<LibraryConnector> libraryConnectors { get; init; }
private Dictionary<string, Manga> cachedPublications { get; init; } private Dictionary<string, Manga> cachedPublications { get; init; }
@ -21,18 +20,16 @@ public abstract class GlobalBase
protected GlobalBase(GlobalBase clone) protected GlobalBase(GlobalBase clone)
{ {
this.logger = clone.logger; this.logger = clone.logger;
this.settings = clone.settings;
this.notificationConnectors = clone.notificationConnectors; this.notificationConnectors = clone.notificationConnectors;
this.libraryConnectors = clone.libraryConnectors; this.libraryConnectors = clone.libraryConnectors;
this.cachedPublications = clone.cachedPublications; this.cachedPublications = clone.cachedPublications;
} }
protected GlobalBase(Logger? logger, TrangaSettings settings) protected GlobalBase(Logger? logger)
{ {
this.logger = logger; this.logger = logger;
this.settings = settings; this.notificationConnectors = TrangaSettings.LoadNotificationConnectors(this);
this.notificationConnectors = settings.LoadNotificationConnectors(this); this.libraryConnectors = TrangaSettings.LoadLibraryConnectors(this);
this.libraryConnectors = settings.LoadLibraryConnectors(this);
this.cachedPublications = new(); this.cachedPublications = new();
} }
@ -81,20 +78,20 @@ public abstract class GlobalBase
notificationConnectors.RemoveWhere(nc => nc.notificationConnectorType == notificationConnector.notificationConnectorType); notificationConnectors.RemoveWhere(nc => nc.notificationConnectorType == notificationConnector.notificationConnectorType);
notificationConnectors.Add(notificationConnector); notificationConnectors.Add(notificationConnector);
while(IsFileInUse(settings.notificationConnectorsFilePath)) while(IsFileInUse(TrangaSettings.notificationConnectorsFilePath))
Thread.Sleep(100); Thread.Sleep(100);
Log("Exporting notificationConnectors"); Log("Exporting notificationConnectors");
File.WriteAllText(settings.notificationConnectorsFilePath, JsonConvert.SerializeObject(notificationConnectors)); File.WriteAllText(TrangaSettings.notificationConnectorsFilePath, JsonConvert.SerializeObject(notificationConnectors));
} }
protected void DeleteNotificationConnector(NotificationConnector.NotificationConnectorType notificationConnectorType) protected void DeleteNotificationConnector(NotificationConnector.NotificationConnectorType notificationConnectorType)
{ {
Log($"Removing {notificationConnectorType}"); Log($"Removing {notificationConnectorType}");
notificationConnectors.RemoveWhere(nc => nc.notificationConnectorType == notificationConnectorType); notificationConnectors.RemoveWhere(nc => nc.notificationConnectorType == notificationConnectorType);
while(IsFileInUse(settings.notificationConnectorsFilePath)) while(IsFileInUse(TrangaSettings.notificationConnectorsFilePath))
Thread.Sleep(100); Thread.Sleep(100);
Log("Exporting notificationConnectors"); Log("Exporting notificationConnectors");
File.WriteAllText(settings.notificationConnectorsFilePath, JsonConvert.SerializeObject(notificationConnectors)); File.WriteAllText(TrangaSettings.notificationConnectorsFilePath, JsonConvert.SerializeObject(notificationConnectors));
} }
protected void UpdateLibraries() protected void UpdateLibraries()
@ -109,20 +106,20 @@ public abstract class GlobalBase
libraryConnectors.RemoveWhere(lc => lc.libraryType == libraryConnector.libraryType); libraryConnectors.RemoveWhere(lc => lc.libraryType == libraryConnector.libraryType);
libraryConnectors.Add(libraryConnector); libraryConnectors.Add(libraryConnector);
while(IsFileInUse(settings.libraryConnectorsFilePath)) while(IsFileInUse(TrangaSettings.libraryConnectorsFilePath))
Thread.Sleep(100); Thread.Sleep(100);
Log("Exporting libraryConnectors"); Log("Exporting libraryConnectors");
File.WriteAllText(settings.libraryConnectorsFilePath, JsonConvert.SerializeObject(libraryConnectors, Formatting.Indented)); File.WriteAllText(TrangaSettings.libraryConnectorsFilePath, JsonConvert.SerializeObject(libraryConnectors, Formatting.Indented));
} }
protected void DeleteLibraryConnector(LibraryConnector.LibraryType libraryType) protected void DeleteLibraryConnector(LibraryConnector.LibraryType libraryType)
{ {
Log($"Removing {libraryType}"); Log($"Removing {libraryType}");
libraryConnectors.RemoveWhere(lc => lc.libraryType == libraryType); libraryConnectors.RemoveWhere(lc => lc.libraryType == libraryType);
while(IsFileInUse(settings.libraryConnectorsFilePath)) while(IsFileInUse(TrangaSettings.libraryConnectorsFilePath))
Thread.Sleep(100); Thread.Sleep(100);
Log("Exporting libraryConnectors"); Log("Exporting libraryConnectors");
File.WriteAllText(settings.libraryConnectorsFilePath, JsonConvert.SerializeObject(libraryConnectors, Formatting.Indented)); File.WriteAllText(TrangaSettings.libraryConnectorsFilePath, JsonConvert.SerializeObject(libraryConnectors, Formatting.Indented));
} }
protected bool IsFileInUse(string filePath) => IsFileInUse(filePath, this.logger); protected bool IsFileInUse(string filePath) => IsFileInUse(filePath, this.logger);

View File

@ -33,7 +33,7 @@ public class DownloadNewChapters : Job
protected override IEnumerable<Job> ExecuteReturnSubTasksInternal(JobBoss jobBoss) protected override IEnumerable<Job> ExecuteReturnSubTasksInternal(JobBoss jobBoss)
{ {
manga.SaveSeriesInfoJson(settings.downloadLocation); manga.SaveSeriesInfoJson();
Chapter[] chapters = mangaConnector.GetNewChapters(manga, this.translatedLanguage); Chapter[] chapters = mangaConnector.GetNewChapters(manga, this.translatedLanguage);
this.progressToken.increments = chapters.Length; this.progressToken.increments = chapters.Length;
List<Job> jobs = new(); List<Job> jobs = new();

View File

@ -140,15 +140,15 @@ public class JobBoss : GlobalBase
private void LoadJobsList(HashSet<MangaConnector> connectors) private void LoadJobsList(HashSet<MangaConnector> connectors)
{ {
if (!Directory.Exists(settings.jobsFolderPath)) //No jobs to load if (!Directory.Exists(TrangaSettings.jobsFolderPath)) //No jobs to load
{ {
Directory.CreateDirectory(settings.jobsFolderPath); Directory.CreateDirectory(TrangaSettings.jobsFolderPath);
return; return;
} }
Regex idRex = new (@"(.*)\.json"); Regex idRex = new (@"(.*)\.json");
//Load json-job-files //Load json-job-files
foreach (FileInfo file in new DirectoryInfo(settings.jobsFolderPath).EnumerateFiles().Where(fileInfo => idRex.IsMatch(fileInfo.Name))) foreach (FileInfo file in new DirectoryInfo(TrangaSettings.jobsFolderPath).EnumerateFiles().Where(fileInfo => idRex.IsMatch(fileInfo.Name)))
{ {
Log($"Adding {file.Name}"); Log($"Adding {file.Name}");
Job? job = JsonConvert.DeserializeObject<Job>(File.ReadAllText(file.FullName), Job? job = JsonConvert.DeserializeObject<Job>(File.ReadAllText(file.FullName),
@ -163,6 +163,7 @@ public class JobBoss : GlobalBase
{ {
Log($"Adding Job {job}"); Log($"Adding Job {job}");
this.jobs.Add(job); this.jobs.Add(job);
UpdateJobFile(job, file.Name);
} }
} }
@ -180,30 +181,34 @@ public class JobBoss : GlobalBase
AddMangaToCache(dncJob.manga); AddMangaToCache(dncJob.manga);
} }
string[] coverFiles = Directory.GetFiles(settings.coverImageCache); string[] coverFiles = Directory.GetFiles(TrangaSettings.coverImageCache);
foreach(string fileName in coverFiles.Where(fileName => !GetAllCachedManga().Any(manga => manga.coverFileNameInCache == fileName))) foreach(string fileName in coverFiles.Where(fileName => !GetAllCachedManga().Any(manga => manga.coverFileNameInCache == fileName)))
File.Delete(fileName); File.Delete(fileName);
} }
internal void UpdateJobFile(Job job, string? oldFile = null) internal void UpdateJobFile(Job job, string? oldFile = null)
{ {
string newJobFilePath = Path.Join(settings.jobsFolderPath, $"{job.id}.json"); string newJobFilePath = Path.Join(TrangaSettings.jobsFolderPath, $"{job.id}.json");
string oldFilePath = Path.Join(TrangaSettings.jobsFolderPath, oldFile??$"{job.id}.json");
if (!this.jobs.Any(jjob => jjob.id == job.id)) //Delete old file
if (File.Exists(oldFilePath))
{ {
Log($"Deleting Job-file {oldFilePath}");
try try
{ {
Log($"Deleting Job-file {newJobFilePath}"); while(IsFileInUse(oldFilePath))
while(IsFileInUse(newJobFilePath))
Thread.Sleep(10); Thread.Sleep(10);
File.Delete(newJobFilePath); File.Delete(oldFilePath);
} }
catch (Exception e) catch (Exception e)
{ {
Log(e.ToString()); Log(e.ToString());
} }
} }
else
//Export job (in new file) if it is still in our jobs list
if (GetJobById(job.id) is not null)
{ {
Log($"Exporting Job {newJobFilePath}"); Log($"Exporting Job {newJobFilePath}");
string jobStr = JsonConvert.SerializeObject(job, Formatting.Indented); string jobStr = JsonConvert.SerializeObject(job, Formatting.Indented);
@ -211,19 +216,6 @@ public class JobBoss : GlobalBase
Thread.Sleep(10); Thread.Sleep(10);
File.WriteAllText(newJobFilePath, jobStr); File.WriteAllText(newJobFilePath, jobStr);
} }
if(oldFile is not null)
try
{
Log($"Deleting old Job-file {oldFile}");
while(IsFileInUse(oldFile))
Thread.Sleep(10);
File.Delete(oldFile);
}
catch (Exception e)
{
Log(e.ToString());
}
} }
private void UpdateAllJobFiles() private void UpdateAllJobFiles()
@ -234,7 +226,7 @@ public class JobBoss : GlobalBase
//Remove files with jobs not in this.jobs-list //Remove files with jobs not in this.jobs-list
Regex idRex = new (@"(.*)\.json"); Regex idRex = new (@"(.*)\.json");
foreach (FileInfo file in new DirectoryInfo(settings.jobsFolderPath).EnumerateFiles()) foreach (FileInfo file in new DirectoryInfo(TrangaSettings.jobsFolderPath).EnumerateFiles())
{ {
if (idRex.IsMatch(file.Name)) if (idRex.IsMatch(file.Name))
{ {

View File

@ -34,7 +34,7 @@ public class UpdateMetadata : Job
} }
this.manga = manga.WithMetadata(updatedManga); this.manga = manga.WithMetadata(updatedManga);
this.manga.SaveSeriesInfoJson(settings.downloadLocation, true); this.manga.SaveSeriesInfoJson(true);
this.mangaConnector.CopyCoverFromCacheToDownloadLocation(manga); this.mangaConnector.CopyCoverFromCacheToDownloadLocation(manga);
foreach (Job job in jobBoss.GetJobsLike(publication: this.manga)) foreach (Job job in jobBoss.GetJobsLike(publication: this.manga))
{ {

View File

@ -67,7 +67,7 @@ public struct Manga
while (this.folderName.EndsWith('.')) while (this.folderName.EndsWith('.'))
this.folderName = this.folderName.Substring(0, this.folderName.Length - 1); this.folderName = this.folderName.Substring(0, this.folderName.Length - 1);
string onlyLowerLetters = string.Concat(this.sortName.ToLower().Where(Char.IsLetter)); string onlyLowerLetters = string.Concat(this.sortName.ToLower().Where(Char.IsLetter));
this.internalId = Convert.ToBase64String(Encoding.ASCII.GetBytes($"{onlyLowerLetters}{this.year}")); this.internalId = DateTime.Now.Ticks.ToString();
this.ignoreChaptersBelow = ignoreChaptersBelow ?? 0f; this.ignoreChaptersBelow = ignoreChaptersBelow ?? 0f;
this.latestChapterDownloaded = 0; this.latestChapterDownloaded = 0;
this.latestChapterAvailable = 0; this.latestChapterAvailable = 0;
@ -128,11 +128,20 @@ public struct Manga
public void MovePublicationFolder(string downloadDirectory, string newFolderName) public void MovePublicationFolder(string downloadDirectory, string newFolderName)
{ {
string oldPath = Path.Join(downloadDirectory, this.folderName); string oldPath = Path.Join(downloadDirectory, this.folderName);
this.folderName = newFolderName; this.folderName = newFolderName;//Create new Path with the new folderName
string newPath = CreatePublicationFolder(downloadDirectory); string newPath = CreatePublicationFolder(downloadDirectory);
if (Directory.Exists(oldPath)) if (Directory.Exists(oldPath))
{
if (Directory.Exists(newPath)) //Move/Overwrite old Files, Delete old Directory
{
IEnumerable<string> newPathFileNames = new DirectoryInfo(newPath).GetFiles().Select(fi => fi.Name);
foreach(FileInfo fileInfo in new DirectoryInfo(oldPath).GetFiles().Where(fi => newPathFileNames.Contains(fi.Name) == false))
File.Move(fileInfo.FullName, Path.Join(newPath, fileInfo.Name), true);
Directory.Delete(oldPath);
}else
Directory.Move(oldPath, newPath); Directory.Move(oldPath, newPath);
} }
}
public void UpdateLatestDownloadedChapter(Chapter chapter)//TODO check files if chapters are all downloaded public void UpdateLatestDownloadedChapter(Chapter chapter)//TODO check files if chapters are all downloaded
{ {
@ -140,9 +149,9 @@ public struct Manga
latestChapterDownloaded = latestChapterDownloaded < chapterNumber ? chapterNumber : latestChapterDownloaded; latestChapterDownloaded = latestChapterDownloaded < chapterNumber ? chapterNumber : latestChapterDownloaded;
} }
public void SaveSeriesInfoJson(string downloadDirectory, bool overwrite = false) public void SaveSeriesInfoJson(bool overwrite = false)
{ {
string publicationFolder = CreatePublicationFolder(downloadDirectory); string publicationFolder = CreatePublicationFolder(TrangaSettings.downloadLocation);
string seriesInfoPath = Path.Join(publicationFolder, "series.json"); string seriesInfoPath = Path.Join(publicationFolder, "series.json");
if(overwrite || (!overwrite && !File.Exists(seriesInfoPath))) if(overwrite || (!overwrite && !File.Exists(seriesInfoPath)))
File.WriteAllText(seriesInfoPath,this.GetSeriesInfoJson()); File.WriteAllText(seriesInfoPath,this.GetSeriesInfoJson());

View File

@ -8,7 +8,7 @@ namespace Tranga.MangaConnectors;
public class Bato : MangaConnector public class Bato : MangaConnector
{ {
public Bato(GlobalBase clone) : base(clone, "Bato") public Bato(GlobalBase clone) : base(clone, "Bato", ["en"])
{ {
this.downloadClient = new HttpDownloadClient(clone); this.downloadClient = new HttpDownloadClient(clone);
} }
@ -193,7 +193,7 @@ public class Bato : MangaConnector
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), RequestType.MangaImage, comicInfoPath, "https://mangakatana.com/", progressToken:progressToken); return DownloadChapterImages(imageUrls, chapter.GetArchiveFilePath(), RequestType.MangaImage, comicInfoPath, "https://mangakatana.com/", progressToken:progressToken);
} }
private string[] ParseImageUrlsFromHtml(string mangaUrl) private string[] ParseImageUrlsFromHtml(string mangaUrl)

View File

@ -1,51 +1,22 @@
using System.Net; using System.Net;
using System.Text; using System.Text;
using System.Text.RegularExpressions;
using HtmlAgilityPack; using HtmlAgilityPack;
using PuppeteerSharp; using PuppeteerSharp;
using PuppeteerSharp.Input;
namespace Tranga.MangaConnectors; namespace Tranga.MangaConnectors;
internal class ChromiumDownloadClient : DownloadClient internal class ChromiumDownloadClient : DownloadClient
{ {
private IBrowser browser { get; set; } private static readonly IBrowser Browser = StartBrowser().Result;
private const string ChromiumVersion = "1154303"; private const int StartTimeoutMs = 10000;
private const int StartTimeoutMs = 30000; private readonly HttpDownloadClient _httpDownloadClient;
private async Task<IBrowser> DownloadBrowser() private static async Task<IBrowser> StartBrowser()
{ {
BrowserFetcher browserFetcher = new BrowserFetcher();
foreach(string rev in browserFetcher.LocalRevisions().Where(rev => rev != ChromiumVersion))
browserFetcher.Remove(rev);
if (!browserFetcher.LocalRevisions().Contains(ChromiumVersion))
{
Log("Downloading headless browser");
DateTime last = DateTime.Now.Subtract(TimeSpan.FromSeconds(5));
browserFetcher.DownloadProgressChanged += (_, args) =>
{
double currentBytes = Convert.ToDouble(args.BytesReceived) / Convert.ToDouble(args.TotalBytesToReceive);
if (args.TotalBytesToReceive == args.BytesReceived)
Log("Browser downloaded.");
else if (DateTime.Now > last.AddSeconds(1))
{
Log($"Browser download progress: {currentBytes:P2}");
last = DateTime.Now;
}
};
if (!browserFetcher.CanDownloadAsync(ChromiumVersion).Result)
{
Log($"Can't download browser version {ChromiumVersion}");
throw new Exception();
}
await browserFetcher.DownloadAsync(ChromiumVersion);
}
Log($"Starting Browser. ({StartTimeoutMs}ms timeout)");
return await Puppeteer.LaunchAsync(new LaunchOptions return await Puppeteer.LaunchAsync(new LaunchOptions
{ {
Headless = true, Headless = true,
ExecutablePath = browserFetcher.GetExecutablePath(ChromiumVersion),
Args = new [] { Args = new [] {
"--disable-gpu", "--disable-gpu",
"--disable-dev-shm-usage", "--disable-dev-shm-usage",
@ -57,12 +28,20 @@ internal class ChromiumDownloadClient : DownloadClient
public ChromiumDownloadClient(GlobalBase clone) : base(clone) public ChromiumDownloadClient(GlobalBase clone) : base(clone)
{ {
this.browser = DownloadBrowser().Result; _httpDownloadClient = new(this);
} }
protected override RequestResult MakeRequestInternal(string url, string? referrer = null, string? clickButton = null) private readonly Regex _imageUrlRex = new(@"https?:\/\/.*\.(?:p?jpe?g|gif|a?png|bmp|avif|webp)(\?.*)?");
internal override RequestResult MakeRequestInternal(string url, string? referrer = null, string? clickButton = null)
{ {
IPage page = this.browser.NewPageAsync().Result; return _imageUrlRex.IsMatch(url)
? _httpDownloadClient.MakeRequestInternal(url, referrer)
: MakeRequestBrowser(url, referrer, clickButton);
}
private RequestResult MakeRequestBrowser(string url, string? referrer = null, string? clickButton = null)
{
IPage page = Browser.NewPageAsync().Result;
page.DefaultTimeout = 10000; page.DefaultTimeout = 10000;
IResponse response; IResponse response;
try try
@ -73,6 +52,7 @@ internal class ChromiumDownloadClient : DownloadClient
catch (Exception e) catch (Exception e)
{ {
Log($"Could not load Page:\n{e.Message}"); Log($"Could not load Page:\n{e.Message}");
page.CloseAsync();
return new RequestResult(HttpStatusCode.InternalServerError, null, Stream.Null); return new RequestResult(HttpStatusCode.InternalServerError, null, Stream.Null);
} }
@ -103,9 +83,4 @@ internal class ChromiumDownloadClient : DownloadClient
page.CloseAsync(); page.CloseAsync();
return new RequestResult(response.Status, document, stream, false, ""); return new RequestResult(response.Status, document, stream, false, "");
} }
public override void Close()
{
this.browser.CloseAsync();
}
} }

View File

@ -14,15 +14,15 @@ internal abstract class DownloadClient : GlobalBase
public RequestResult MakeRequest(string url, RequestType requestType, string? referrer = null, string? clickButton = null) public RequestResult MakeRequest(string url, RequestType requestType, string? referrer = null, string? clickButton = null)
{ {
if (!settings.requestLimits.ContainsKey(requestType)) if (!TrangaSettings.requestLimits.ContainsKey(requestType))
{ {
Log("RequestType not configured for rate-limit."); Log("RequestType not configured for rate-limit.");
return new RequestResult(HttpStatusCode.NotAcceptable, null, Stream.Null); return new RequestResult(HttpStatusCode.NotAcceptable, null, Stream.Null);
} }
int rateLimit = settings.userAgent == TrangaSettings.DefaultUserAgent int rateLimit = TrangaSettings.userAgent == TrangaSettings.DefaultUserAgent
? TrangaSettings.DefaultRequestLimits[requestType] ? TrangaSettings.DefaultRequestLimits[requestType]
: settings.requestLimits[requestType]; : TrangaSettings.requestLimits[requestType];
TimeSpan timeBetweenRequests = TimeSpan.FromMinutes(1).Divide(rateLimit); TimeSpan timeBetweenRequests = TimeSpan.FromMinutes(1).Divide(rateLimit);
_lastExecutedRateLimit.TryAdd(requestType, DateTime.Now.Subtract(timeBetweenRequests)); _lastExecutedRateLimit.TryAdd(requestType, DateTime.Now.Subtract(timeBetweenRequests));
@ -40,6 +40,5 @@ internal abstract class DownloadClient : GlobalBase
return result; return result;
} }
protected abstract RequestResult MakeRequestInternal(string url, string? referrer = null, string? clickButton = null); internal abstract RequestResult MakeRequestInternal(string url, string? referrer = null, string? clickButton = null);
public abstract void Close();
} }

View File

@ -13,10 +13,10 @@ internal class HttpDownloadClient : DownloadClient
public HttpDownloadClient(GlobalBase clone) : base(clone) public HttpDownloadClient(GlobalBase clone) : base(clone)
{ {
Client.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", settings.userAgent); Client.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", TrangaSettings.userAgent);
} }
protected override RequestResult MakeRequestInternal(string url, string? referrer = null, string? clickButton = null) internal override RequestResult MakeRequestInternal(string url, string? referrer = null, string? clickButton = null)
{ {
if(clickButton is not null) if(clickButton is not null)
Log("Can not click button on static site."); Log("Can not click button on static site.");
@ -72,9 +72,4 @@ internal class HttpDownloadClient : DownloadClient
return new RequestResult(response.StatusCode, document, stream); return new RequestResult(response.StatusCode, document, stream);
} }
public override void Close()
{
Log("Closing.");
}
} }

View File

@ -14,16 +14,13 @@ namespace Tranga.MangaConnectors;
public abstract class MangaConnector : GlobalBase public abstract class MangaConnector : GlobalBase
{ {
internal DownloadClient downloadClient { get; init; } = null!; internal DownloadClient downloadClient { get; init; } = null!;
public string[] SupportedLanguages;
public void StopDownloadClient() protected MangaConnector(GlobalBase clone, string name, string[] supportedLanguages) : base(clone)
{
downloadClient.Close();
}
protected MangaConnector(GlobalBase clone, string name) : base(clone)
{ {
this.name = name; this.name = name;
Directory.CreateDirectory(settings.coverImageCache); this.SupportedLanguages = supportedLanguages;
Directory.CreateDirectory(TrangaSettings.coverImageCache);
} }
public string name { get; } //Name of the Connector (e.g. Website) public string name { get; } //Name of the Connector (e.g. Website)
@ -65,7 +62,7 @@ public abstract class MangaConnector : GlobalBase
Log($"Checking for duplicates {manga}"); Log($"Checking for duplicates {manga}");
List<Chapter> newChaptersList = allChapters.Where(nChapter => float.TryParse(nChapter.chapterNumber, numberFormatDecimalPoint, out float chapterNumber) List<Chapter> newChaptersList = allChapters.Where(nChapter => float.TryParse(nChapter.chapterNumber, numberFormatDecimalPoint, out float chapterNumber)
&& chapterNumber > manga.ignoreChaptersBelow && chapterNumber > manga.ignoreChaptersBelow
&& !nChapter.CheckChapterIsDownloaded(settings.downloadLocation)).ToList(); && !nChapter.CheckChapterIsDownloaded()).ToList();
Log($"{newChaptersList.Count} new chapters. {manga}"); Log($"{newChaptersList.Count} new chapters. {manga}");
try try
{ {
@ -167,7 +164,7 @@ public abstract class MangaConnector : GlobalBase
{ {
Log($"Copy cover {manga}"); Log($"Copy cover {manga}");
//Check if Publication already has a Folder and cover //Check if Publication already has a Folder and cover
string publicationFolder = manga.CreatePublicationFolder(settings.downloadLocation); string publicationFolder = manga.CreatePublicationFolder(TrangaSettings.downloadLocation);
DirectoryInfo dirInfo = new (publicationFolder); DirectoryInfo dirInfo = new (publicationFolder);
if (dirInfo.EnumerateFiles().Any(info => info.Name.Contains("cover", StringComparison.InvariantCultureIgnoreCase))) if (dirInfo.EnumerateFiles().Any(info => info.Name.Contains("cover", StringComparison.InvariantCultureIgnoreCase)))
{ {
@ -223,7 +220,7 @@ public abstract class MangaConnector : GlobalBase
return HttpStatusCode.RequestTimeout; return HttpStatusCode.RequestTimeout;
Log($"Downloading Images for {saveArchiveFilePath}"); Log($"Downloading Images for {saveArchiveFilePath}");
if (progressToken is not null) if (progressToken is not null)
progressToken.increments = imageUrls.Length; progressToken.increments += imageUrls.Length;
//Check if Publication Directory already exists //Check if Publication Directory already exists
string directoryPath = Path.GetDirectoryName(saveArchiveFilePath)!; string directoryPath = Path.GetDirectoryName(saveArchiveFilePath)!;
if (!Directory.Exists(directoryPath)) if (!Directory.Exists(directoryPath))
@ -234,7 +231,10 @@ public abstract class MangaConnector : GlobalBase
Directory.CreateDirectory(directoryPath); Directory.CreateDirectory(directoryPath);
if (File.Exists(saveArchiveFilePath)) //Don't download twice. if (File.Exists(saveArchiveFilePath)) //Don't download twice.
{
progressToken?.Complete();
return HttpStatusCode.Created; return HttpStatusCode.Created;
}
//Create a temporary folder to store images //Create a temporary folder to store images
string tempFolder = Directory.CreateTempSubdirectory("trangatemp").FullName; string tempFolder = Directory.CreateTempSubdirectory("trangatemp").FullName;
@ -291,7 +291,7 @@ public abstract class MangaConnector : GlobalBase
//https?:\/\/[a-zA-Z0-9-]+\.([a-zA-Z0-9-]+\.[a-zA-Z0-9]+)\/(?:.+\/)*(.+\.([a-zA-Z]+)) for only second level domains //https?:\/\/[a-zA-Z0-9-]+\.([a-zA-Z0-9-]+\.[a-zA-Z0-9]+)\/(?:.+\/)*(.+\.([a-zA-Z]+)) for only second level domains
Match match = urlRex.Match(url); Match match = urlRex.Match(url);
string filename = $"{match.Groups[1].Value}-{mangaInternalId}.{match.Groups[3].Value}"; string filename = $"{match.Groups[1].Value}-{mangaInternalId}.{match.Groups[3].Value}";
string saveImagePath = Path.Join(settings.coverImageCache, filename); string saveImagePath = Path.Join(TrangaSettings.coverImageCache, filename);
if (File.Exists(saveImagePath)) if (File.Exists(saveImagePath))
return saveImagePath; return saveImagePath;
@ -299,7 +299,7 @@ public abstract class MangaConnector : GlobalBase
RequestResult coverResult = downloadClient.MakeRequest(url, requestType); RequestResult coverResult = downloadClient.MakeRequest(url, requestType);
using MemoryStream ms = new(); using MemoryStream ms = new();
coverResult.result.CopyTo(ms); coverResult.result.CopyTo(ms);
Directory.CreateDirectory(settings.coverImageCache); Directory.CreateDirectory(TrangaSettings.coverImageCache);
File.WriteAllBytes(saveImagePath, ms.ToArray()); File.WriteAllBytes(saveImagePath, ms.ToArray());
Log($"Saving cover to {saveImagePath}"); Log($"Saving cover to {saveImagePath}");
return saveImagePath; return saveImagePath;

View File

@ -1,4 +1,6 @@
using Newtonsoft.Json; using System.Data;
using System.Diagnostics;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
namespace Tranga.MangaConnectors; namespace Tranga.MangaConnectors;
@ -22,27 +24,22 @@ public class MangaConnectorJsonConverter : JsonConverter
public override object ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer) public override object ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer)
{ {
JObject jo = JObject.Load(reader); JObject jo = JObject.Load(reader);
switch (jo.GetValue("name")!.Value<string>()!) string? connectorName = jo.Value<string>("name");
if (connectorName is null)
throw new ConstraintException("Name can not be null.");
return connectorName switch
{ {
case "MangaDex": "MangaDex" => this._connectors.First(c => c is MangaDex),
return this._connectors.First(c => c is MangaDex); "Manganato" => this._connectors.First(c => c is Manganato),
case "Manganato": "MangaKatana" => this._connectors.First(c => c is MangaKatana),
return this._connectors.First(c => c is Manganato); "Mangasee" => this._connectors.First(c => c is Mangasee),
case "MangaKatana": "Mangaworld" => this._connectors.First(c => c is Mangaworld),
return this._connectors.First(c => c is MangaKatana); "Bato" => this._connectors.First(c => c is Bato),
case "Mangasee": "Manga4Life" => this._connectors.First(c => c is MangaLife),
return this._connectors.First(c => c is Mangasee); "ManhuaPlus" => this._connectors.First(c => c is ManhuaPlus),
case "Mangaworld": "MangaHere" => this._connectors.First(c => c is MangaHere),
return this._connectors.First(c => c is Mangaworld); _ => throw new UnreachableException($"Could not find Connector with name {connectorName}")
case "Bato": };
return this._connectors.First(c => c is Bato);
case "Manga4Life":
return this._connectors.First(c => c is MangaLife);
case "ManhuaPlus":
return this._connectors.First(c => c is ManhuaPlus);
}
throw new Exception();
} }
public override bool CanWrite => false; public override bool CanWrite => false;

View File

@ -7,14 +7,17 @@ using JsonSerializer = System.Text.Json.JsonSerializer;
namespace Tranga.MangaConnectors; namespace Tranga.MangaConnectors;
public class MangaDex : MangaConnector public class MangaDex : MangaConnector
{ {
public MangaDex(GlobalBase clone) : base(clone, "MangaDex") //https://api.mangadex.org/docs/3-enumerations/#language-codes--localization
//https://en.wikipedia.org/wiki/List_of_ISO_639_language_codes
//https://gist.github.com/Josantonius/b455e315bc7f790d14b136d61d9ae469
public MangaDex(GlobalBase clone) : base(clone, "MangaDex", ["en","pt","pt-br","it","de","ru","aa","ab","ae","af","ak","am","an","ar-ae","ar-bh","ar-dz","ar-eg","ar-iq","ar-jo","ar-kw","ar-lb","ar-ly","ar-ma","ar-om","ar-qa","ar-sa","ar-sy","ar-tn","ar-ye","ar","as","av","ay","az","ba","be","bg","bh","bi","bm","bn","bo","br","bs","ca","ce","ch","co","cr","cs","cu","cv","cy","da","de-at","de-ch","de-de","de-li","de-lu","div","dv","dz","ee","el","en-au","en-bz","en-ca","en-cb","en-gb","en-ie","en-jm","en-nz","en-ph","en-tt","en-us","en-za","en-zw","eo","es-ar","es-bo","es-cl","es-co","es-cr","es-do","es-ec","es-es","es-gt","es-hn","es-la","es-mx","es-ni","es-pa","es-pe","es-pr","es-py","es-sv","es-us","es-uy","es-ve","es","et","eu","fa","ff","fi","fj","fo","fr-be","fr-ca","fr-ch","fr-fr","fr-lu","fr-mc","fr","fy","ga","gd","gl","gn","gu","gv","ha","he","hi","ho","hr-ba","hr-hr","hr","ht","hu","hy","hz","ia","id","ie","ig","ii","ik","in","io","is","it-ch","it-it","iu","iw","ja","ja-ro","ji","jv","jw","ka","kg","ki","kj","kk","kl","km","kn","ko","ko-ro","kr","ks","ku","kv","kw","ky","kz","la","lb","lg","li","ln","lo","ls","lt","lu","lv","mg","mh","mi","mk","ml","mn","mo","mr","ms-bn","ms-my","ms","mt","my","na","nb","nd","ne","ng","nl-be","nl-nl","nl","nn","no","nr","ns","nv","ny","oc","oj","om","or","os","pa","pi","pl","ps","pt-pt","qu-bo","qu-ec","qu-pe","qu","rm","rn","ro","rw","sa","sb","sc","sd","se-fi","se-no","se-se","se","sg","sh","si","sk","sl","sm","sn","so","sq","sr-ba","sr-sp","sr","ss","st","su","sv-fi","sv-se","sv","sw","sx","syr","ta","te","tg","th","ti","tk","tl","tn","to","tr","ts","tt","tw","ty","ug","uk","ur","us","uz","ve","vi","vo","wa","wo","xh","yi","yo","za","zh-cn","zh-hk","zh-mo","zh-ro","zh-sg","zh-tw","zh","zu"])
{ {
this.downloadClient = new HttpDownloadClient(clone); this.downloadClient = new HttpDownloadClient(clone);
} }
public override Manga[] GetManga(string publicationTitle = "") public override Manga[] GetManga(string publicationTitle = "")
{ {
Log($"Searching Publications. Term=\"{publicationTitle}\""); Log($"Searching Publications. Term={publicationTitle}");
const int limit = 100; //How many values we want returned at once const int limit = 100; //How many values we want returned at once
int offset = 0; //"Page" int offset = 0; //"Page"
int total = int.MaxValue; //How many total results are there, is updated on first request int total = int.MaxValue; //How many total results are there, is updated on first request
@ -54,7 +57,7 @@ public class MangaDex : MangaConnector
if(MangaFromJsonObject(mangaNode.AsObject()) is { } manga) if(MangaFromJsonObject(mangaNode.AsObject()) is { } manga)
retManga.Add(manga); //Add Publication (Manga) to result retManga.Add(manga); //Add Publication (Manga) to result
} }
Log($"Retrieved {retManga.Count} publications. Term=\"{publicationTitle}\""); Log($"Retrieved {retManga.Count} publications. Term={publicationTitle}");
return retManga.ToArray(); return retManga.ToArray();
} }
@ -243,7 +246,7 @@ public class MangaDex : MangaConnector
continue; continue;
} }
if(chapterNum is not "null") if(chapterNum is not "null" && !chapters.Any(chp => chp.volumeNumber.Equals(volume) && chp.chapterNumber.Equals(chapterNum)))
chapters.Add(new Chapter(manga, title, volume, chapterNum, chapterId)); chapters.Add(new Chapter(manga, title, volume, chapterNum, chapterId));
} }
} }
@ -290,6 +293,6 @@ public class MangaDex : MangaConnector
File.WriteAllText(comicInfoPath, chapter.GetComicInfoXmlString()); File.WriteAllText(comicInfoPath, chapter.GetComicInfoXmlString());
//Download Chapter-Images //Download Chapter-Images
return DownloadChapterImages(imageUrls.ToArray(), chapter.GetArchiveFilePath(settings.downloadLocation), RequestType.MangaImage, comicInfoPath, progressToken:progressToken); return DownloadChapterImages(imageUrls.ToArray(), chapter.GetArchiveFilePath(), RequestType.MangaImage, comicInfoPath, progressToken:progressToken);
} }
} }

View File

@ -0,0 +1,203 @@
using System.Net;
using System.Text.RegularExpressions;
using HtmlAgilityPack;
using Tranga.Jobs;
namespace Tranga.MangaConnectors;
public class MangaHere : MangaConnector
{
public MangaHere(GlobalBase clone) : base(clone, "MangaHere", ["en"])
{
this.downloadClient = new ChromiumDownloadClient(clone);
}
public override Manga[] GetManga(string publicationTitle = "")
{
Log($"Searching Publications. Term=\"{publicationTitle}\"");
string sanitizedTitle = string.Join('+', Regex.Matches(publicationTitle, "[A-z]*").Where(str => str.Length > 0)).ToLower();
string requestUrl = $"https://www.mangahere.cc/search?title={sanitizedTitle}";
RequestResult requestResult =
downloadClient.MakeRequest(requestUrl, RequestType.Default);
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300 || requestResult.htmlDocument is null)
return Array.Empty<Manga>();
Manga[] publications = ParsePublicationsFromHtml(requestResult.htmlDocument);
Log($"Retrieved {publications.Length} publications. Term=\"{publicationTitle}\"");
return publications;
}
private Manga[] ParsePublicationsFromHtml(HtmlDocument document)
{
if (document.DocumentNode.SelectNodes("//div[contains(concat(' ',normalize-space(@class),' '),' container ')]").Any(node => node.ChildNodes.Any(cNode => cNode.HasClass("search-keywords"))))
return Array.Empty<Manga>();
List<string> urls = document.DocumentNode
.SelectNodes("//a[contains(@href, '/manga/') and not(contains(@href, '.html'))]")
.Select(thumb => $"https://www.mangahere.cc{thumb.GetAttributeValue("href", "")}").Distinct().ToList();
HashSet<Manga> ret = new();
foreach (string url in urls)
{
Manga? manga = GetMangaFromUrl(url);
if (manga is not null)
ret.Add((Manga)manga);
}
return ret.ToArray();
}
public override Manga? GetMangaFromId(string publicationId)
{
return GetMangaFromUrl($"https://www.mangahere.cc/manga/{publicationId}");
}
public override Manga? GetMangaFromUrl(string url)
{
RequestResult requestResult =
downloadClient.MakeRequest(url, RequestType.MangaInfo);
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300 || requestResult.htmlDocument is null)
return null;
Regex idRex = new (@"https:\/\/www\.mangahere\.[a-z]{0,63}\/manga\/([0-9A-z\-]+).*");
string id = idRex.Match(url).Groups[1].Value;
return ParseSinglePublicationFromHtml(requestResult.htmlDocument, id, url);
}
private Manga ParseSinglePublicationFromHtml(HtmlDocument document, string publicationId, string websiteUrl)
{
string originalLanguage = "", status = "";
Dictionary<string, string> altTitles = new(), links = new();
Manga.ReleaseStatusByte releaseStatus = Manga.ReleaseStatusByte.Unreleased;
//We dont get posters, because same origin bs HtmlNode posterNode = document.DocumentNode.SelectSingleNode("//img[contains(concat(' ',normalize-space(@class),' '),' detail-info-cover-img ')]");
string posterUrl = "http://static.mangahere.cc/v20230914/mangahere/images/nopicture.jpg";
string coverFileNameInCache = SaveCoverImageToCache(posterUrl, publicationId, RequestType.MangaCover);
HtmlNode titleNode = document.DocumentNode.SelectSingleNode("//span[contains(concat(' ',normalize-space(@class),' '),' detail-info-right-title-font ')]");
string sortName = titleNode.InnerText;
List<string> authors = document.DocumentNode
.SelectNodes("//p[contains(concat(' ',normalize-space(@class),' '),' detail-info-right-say ')]/a")
.Select(node => node.InnerText)
.ToList();
HashSet<string> tags = document.DocumentNode
.SelectNodes("//p[contains(concat(' ',normalize-space(@class),' '),' detail-info-right-tag-list ')]/a")
.Select(node => node.InnerText)
.ToHashSet();
status = document.DocumentNode.SelectSingleNode("//span[contains(concat(' ',normalize-space(@class),' '),' detail-info-right-title-tip ')]").InnerText;
switch (status.ToLower())
{
case "cancelled": releaseStatus = Manga.ReleaseStatusByte.Cancelled; break;
case "hiatus": releaseStatus = Manga.ReleaseStatusByte.OnHiatus; break;
case "discontinued": releaseStatus = Manga.ReleaseStatusByte.Cancelled; break;
case "complete": releaseStatus = Manga.ReleaseStatusByte.Completed; break;
case "ongoing": releaseStatus = Manga.ReleaseStatusByte.Continuing; break;
}
HtmlNode descriptionNode = document.DocumentNode
.SelectSingleNode("//p[contains(concat(' ',normalize-space(@class),' '),' fullcontent ')]");
string description = descriptionNode.InnerText;
Manga manga = new(sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl,
coverFileNameInCache, links,
null, originalLanguage, publicationId, releaseStatus, websiteUrl: websiteUrl);
AddMangaToCache(manga);
return manga;
}
public override Chapter[] GetChapters(Manga manga, string language="en")
{
Log($"Getting chapters {manga}");
string requestUrl = $"https://www.mangahere.cc/manga/{manga.publicationId}";
RequestResult requestResult =
downloadClient.MakeRequest(requestUrl, RequestType.Default);
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300 || requestResult.htmlDocument is null)
return Array.Empty<Chapter>();
List<string> urls = requestResult.htmlDocument.DocumentNode.SelectNodes("//div[@id='list-2']/ul//li//a[contains(@href, '/manga/')]")
.Select(node => node.GetAttributeValue("href", "")).ToList();
Regex chapterRex = new(@".*\/manga\/[a-zA-Z0-9\-\._\~\!\$\&\'\(\)\*\+\,\;\=\:\@]+\/v([0-9(TBD)]+)\/c([0-9\.]+)\/.*");
List<Chapter> chapters = new();
foreach (string url in urls)
{
Match rexMatch = chapterRex.Match(url);
string volumeNumber = rexMatch.Groups[1].Value == "TBD" ? "0" : rexMatch.Groups[1].Value;
string chapterNumber = rexMatch.Groups[2].Value;
string fullUrl = $"https://www.mangahere.cc{url}";
chapters.Add(new Chapter(manga, "", volumeNumber, chapterNumber, fullUrl));
}
//Return Chapters ordered by Chapter-Number
Log($"Got {chapters.Count} chapters. {manga}");
return chapters.Order().ToArray();
}
public override HttpStatusCode DownloadChapter(Chapter chapter, ProgressToken? progressToken = null)
{
if (progressToken?.cancellationRequested ?? false)
{
progressToken.Cancel();
return HttpStatusCode.RequestTimeout;
}
Manga chapterParentManga = chapter.parentManga;
Log($"Retrieving chapter-info {chapter} {chapterParentManga}");
List<string> imageUrls = new();
int downloaded = 1;
int images = 1;
string url = string.Join('/', chapter.url.Split('/')[..^1]);
do
{
RequestResult requestResult =
downloadClient.MakeRequest($"{url}/{downloaded}.html", RequestType.Default);
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
{
progressToken?.Cancel();
return requestResult.statusCode;
}
if (requestResult.htmlDocument is null)
{
progressToken?.Cancel();
return HttpStatusCode.InternalServerError;
}
imageUrls.AddRange(ParseImageUrlsFromHtml(requestResult.htmlDocument));
images = requestResult.htmlDocument.DocumentNode
.SelectNodes("//a[contains(@href, '/manga/')]")
.MaxBy(node => node.GetAttributeValue("data-page", 0))!.GetAttributeValue("data-page", 0);
logger?.WriteLine($"MangaHere speciality: Get Image-url {downloaded}/{images}");
if (progressToken is not null)
{
progressToken.increments = images * 2;//we also have to download the images later
progressToken.Increment();
}
} while (downloaded++ <= images);
string comicInfoPath = Path.GetTempFileName();
File.WriteAllText(comicInfoPath, chapter.GetComicInfoXmlString());
if (progressToken is not null)
progressToken.increments = images;//we blip to normal length, in downloadchapterimages it is increasaed by the amount of urls again
return DownloadChapterImages(imageUrls.ToArray(), chapter.GetArchiveFilePath(), RequestType.MangaImage, comicInfoPath, progressToken:progressToken);
}
private string[] ParseImageUrlsFromHtml(HtmlDocument document)
{
return document.DocumentNode
.SelectNodes("//img[contains(concat(' ',normalize-space(@class),' '),' reader-main-img ')]")
.Select(node =>
{
string url = node.GetAttributeValue("src", "");
return url.StartsWith("//") ? $"https:{url}" : url;
})
.ToArray();
}
}

View File

@ -7,7 +7,7 @@ namespace Tranga.MangaConnectors;
public class MangaKatana : MangaConnector public class MangaKatana : MangaConnector
{ {
public MangaKatana(GlobalBase clone) : base(clone, "MangaKatana") public MangaKatana(GlobalBase clone) : base(clone, "MangaKatana", ["en"])
{ {
this.downloadClient = new HttpDownloadClient(clone); this.downloadClient = new HttpDownloadClient(clone);
} }
@ -217,7 +217,7 @@ public class MangaKatana : MangaConnector
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), RequestType.MangaImage, comicInfoPath, "https://mangakatana.com/", progressToken:progressToken); return DownloadChapterImages(imageUrls, chapter.GetArchiveFilePath(), RequestType.MangaImage, comicInfoPath, "https://mangakatana.com/", progressToken:progressToken);
} }
private string[] ParseImageUrlsFromHtml(string mangaUrl) private string[] ParseImageUrlsFromHtml(string mangaUrl)

View File

@ -7,7 +7,7 @@ namespace Tranga.MangaConnectors;
public class MangaLife : MangaConnector public class MangaLife : MangaConnector
{ {
public MangaLife(GlobalBase clone) : base(clone, "Manga4Life") public MangaLife(GlobalBase clone) : base(clone, "Manga4Life", ["en"])
{ {
this.downloadClient = new ChromiumDownloadClient(clone); this.downloadClient = new ChromiumDownloadClient(clone);
} }
@ -194,6 +194,6 @@ public class MangaLife : MangaConnector
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), RequestType.MangaImage, comicInfoPath, progressToken:progressToken); return DownloadChapterImages(urls.ToArray(), chapter.GetArchiveFilePath(), RequestType.MangaImage, comicInfoPath, progressToken:progressToken);
} }
} }

View File

@ -1,4 +1,5 @@
using System.Net; using System.Globalization;
using System.Net;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using HtmlAgilityPack; using HtmlAgilityPack;
using Tranga.Jobs; using Tranga.Jobs;
@ -7,7 +8,7 @@ namespace Tranga.MangaConnectors;
public class Manganato : MangaConnector public class Manganato : MangaConnector
{ {
public Manganato(GlobalBase clone) : base(clone, "Manganato") public Manganato(GlobalBase clone) : base(clone, "Manganato", ["en"])
{ {
this.downloadClient = new HttpDownloadClient(clone); this.downloadClient = new HttpDownloadClient(clone);
} }
@ -127,9 +128,16 @@ public class Manganato : MangaConnector
while (description.StartsWith('\n')) while (description.StartsWith('\n'))
description = description.Substring(1); description = description.Substring(1);
string yearString = document.DocumentNode.Descendants("li").Last(li => li.HasClass("a-h")).Descendants("span") string pattern = "MMM dd,yyyy HH:mm";
.First(s => s.HasClass("chapter-time")).InnerText;
int year = Convert.ToInt32(yearString.Split(',')[^1]) + 2000; HtmlNode oldestChapter = document.DocumentNode
.SelectNodes("//span[contains(concat(' ',normalize-space(@class),' '),' chapter-time ')]").MaxBy(
node => DateTime.ParseExact(node.GetAttributeValue("title", "Dec 31 2400, 23:59"), pattern,
CultureInfo.InvariantCulture).Millisecond)!;
int year = DateTime.ParseExact(oldestChapter.GetAttributeValue("title", "Dec 31 2400, 23:59"), pattern,
CultureInfo.InvariantCulture).Year;
Manga manga = new (sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl, coverFileNameInCache, links, Manga manga = new (sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl, coverFileNameInCache, links,
year, originalLanguage, publicationId, releaseStatus, websiteUrl: websiteUrl); year, originalLanguage, publicationId, releaseStatus, websiteUrl: websiteUrl);
@ -209,7 +217,7 @@ public class Manganato : MangaConnector
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), RequestType.MangaImage, comicInfoPath, "https://chapmanganato.com/", progressToken:progressToken); return DownloadChapterImages(imageUrls, chapter.GetArchiveFilePath(), RequestType.MangaImage, comicInfoPath, "https://chapmanganato.com/", progressToken:progressToken);
} }
private string[] ParseImageUrlsFromHtml(HtmlDocument document) private string[] ParseImageUrlsFromHtml(HtmlDocument document)

View File

@ -11,7 +11,7 @@ namespace Tranga.MangaConnectors;
public class Mangasee : MangaConnector public class Mangasee : MangaConnector
{ {
public Mangasee(GlobalBase clone) : base(clone, "Mangasee") public Mangasee(GlobalBase clone) : base(clone, "Mangasee", ["en"])
{ {
this.downloadClient = new ChromiumDownloadClient(clone); this.downloadClient = new ChromiumDownloadClient(clone);
} }
@ -61,21 +61,27 @@ public class Mangasee : MangaConnector
} }
} }
private readonly string[] _filterWords = {"a", "the", "of", "as", "to", "no", "for", "on", "with", "be", "and", "in", "wa", "at", "be", "ni"};
private string ToFilteredString(string input) => string.Join(' ', input.ToLower().Split(' ').Where(word => _filterWords.Contains(word) == false));
private SearchResult[] FilteredResults(string publicationTitle, SearchResult[] unfilteredSearchResults) private SearchResult[] FilteredResults(string publicationTitle, SearchResult[] unfilteredSearchResults)
{ {
Dictionary<SearchResult, int> similarity = new(); Dictionary<SearchResult, int> similarity = new();
foreach (SearchResult sr in unfilteredSearchResults) foreach (SearchResult sr in unfilteredSearchResults)
{ {
List<int> scores = new(); List<int> scores = new();
foreach (string se in sr.a) string filteredPublicationString = ToFilteredString(publicationTitle);
scores.Add(NeedlemanWunschStringUtil.CalculateSimilarity(se.ToLower(), publicationTitle.ToLower())); string filteredSString = ToFilteredString(sr.s);
scores.Add(NeedlemanWunschStringUtil.CalculateSimilarity(sr.s.ToLower(), publicationTitle.ToLower())); scores.Add(NeedlemanWunschStringUtil.CalculateSimilarity(filteredSString, filteredPublicationString));
foreach (string srA in sr.a)
{
string filteredAString = ToFilteredString(srA);
scores.Add(NeedlemanWunschStringUtil.CalculateSimilarity(filteredAString, filteredPublicationString));
}
similarity.Add(sr, scores.Sum() / scores.Count); similarity.Add(sr, scores.Sum() / scores.Count);
} }
SearchResult[] similarity90 = similarity.Where(s => s.Value < 10).Select(s => s.Key).ToArray(); List<SearchResult> ret = similarity.OrderBy(s => s.Value).Take(10).Select(s => s.Key).ToList();
return ret.ToArray();
return similarity90;
} }
public override Manga? GetMangaFromId(string publicationId) public override Manga? GetMangaFromId(string publicationId)
@ -219,6 +225,6 @@ public class Mangasee : MangaConnector
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), RequestType.MangaImage, comicInfoPath, progressToken:progressToken); return DownloadChapterImages(urls.ToArray(), chapter.GetArchiveFilePath(), RequestType.MangaImage, comicInfoPath, progressToken:progressToken);
} }
} }

View File

@ -7,7 +7,7 @@ namespace Tranga.MangaConnectors;
public class Mangaworld: MangaConnector public class Mangaworld: MangaConnector
{ {
public Mangaworld(GlobalBase clone) : base(clone, "Mangaworld") public Mangaworld(GlobalBase clone) : base(clone, "Mangaworld", ["it"])
{ {
this.downloadClient = new HttpDownloadClient(clone); this.downloadClient = new HttpDownloadClient(clone);
} }
@ -169,7 +169,8 @@ public class Mangaworld: MangaConnector
{ {
foreach (HtmlNode chNode in chaptersWrapper.SelectNodes("div").Where(node => node.HasClass("chapter"))) foreach (HtmlNode chNode in chaptersWrapper.SelectNodes("div").Where(node => node.HasClass("chapter")))
{ {
string number = chNode.SelectSingleNode("a").SelectSingleNode("span").InnerText.Split(" ")[^1]; string number = Regex.Match(chNode.SelectSingleNode("a").SelectSingleNode("span").InnerText,
@"[Cc]apitolo ([0-9]+).*").Groups[1].Value;
string url = chNode.SelectSingleNode("a").GetAttributeValue("href", ""); string url = chNode.SelectSingleNode("a").GetAttributeValue("href", "");
ret.Add(new Chapter(manga, null, null, number, url)); ret.Add(new Chapter(manga, null, null, number, url));
} }
@ -209,7 +210,7 @@ public class Mangaworld: MangaConnector
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), RequestType.MangaImage, comicInfoPath, "https://www.mangaworld.bz/", progressToken:progressToken); return DownloadChapterImages(imageUrls, chapter.GetArchiveFilePath(), RequestType.MangaImage, comicInfoPath, "https://www.mangaworld.bz/", progressToken:progressToken);
} }
private string[] ParseImageUrlsFromHtml(HtmlDocument document) private string[] ParseImageUrlsFromHtml(HtmlDocument document)

View File

@ -7,7 +7,7 @@ namespace Tranga.MangaConnectors;
public class ManhuaPlus : MangaConnector public class ManhuaPlus : MangaConnector
{ {
public ManhuaPlus(GlobalBase clone) : base(clone, "ManhuaPlus") public ManhuaPlus(GlobalBase clone) : base(clone, "ManhuaPlus", ["en"])
{ {
this.downloadClient = new ChromiumDownloadClient(clone); this.downloadClient = new ChromiumDownloadClient(clone);
} }
@ -82,17 +82,31 @@ public class ManhuaPlus : MangaConnector
HtmlNode titleNode = document.DocumentNode.SelectSingleNode("//h1"); HtmlNode titleNode = document.DocumentNode.SelectSingleNode("//h1");
string sortName = titleNode.InnerText.Replace("\n", ""); string sortName = titleNode.InnerText.Replace("\n", "");
List<string> authors = new();
try
{
HtmlNode[] authorsNodes = document.DocumentNode HtmlNode[] authorsNodes = document.DocumentNode
.SelectNodes("//a[contains(@href, 'https://manhuaplus.org/authors/')]") .SelectNodes("//a[contains(@href, 'https://manhuaplus.org/authors/')]")
.ToArray(); .ToArray();
List<string> authors = new();
foreach (HtmlNode authorNode in authorsNodes) foreach (HtmlNode authorNode in authorsNodes)
authors.Add(authorNode.InnerText); authors.Add(authorNode.InnerText);
}
catch (ArgumentNullException e)
{
Log("No authors found.");
}
try
{
HtmlNode[] genreNodes = document.DocumentNode HtmlNode[] genreNodes = document.DocumentNode
.SelectNodes("//a[contains(@href, 'https://manhuaplus.org/genres/')]").ToArray(); .SelectNodes("//a[contains(@href, 'https://manhuaplus.org/genres/')]").ToArray();
foreach (HtmlNode genreNode in genreNodes) foreach (HtmlNode genreNode in genreNodes)
tags.Add(genreNode.InnerText.Replace("\n", "")); tags.Add(genreNode.InnerText.Replace("\n", ""));
}
catch (ArgumentNullException e)
{
Log("No genres found");
}
string yearNodeStr = document.DocumentNode string yearNodeStr = document.DocumentNode
.SelectSingleNode("//aside//i[contains(concat(' ',normalize-space(@class),' '),' fa-clock ')]/../span").InnerText.Replace("\n", ""); .SelectSingleNode("//aside//i[contains(concat(' ',normalize-space(@class),' '),' fa-clock ')]/../span").InnerText.Replace("\n", "");
@ -179,6 +193,6 @@ public class ManhuaPlus : MangaConnector
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), RequestType.MangaImage, comicInfoPath, progressToken:progressToken); return DownloadChapterImages(urls.ToArray(), chapter.GetArchiveFilePath(), RequestType.MangaImage, comicInfoPath, progressToken:progressToken);
} }
} }

View File

@ -19,9 +19,9 @@ public class Server : GlobalBase
{ {
this._parent = parent; this._parent = parent;
if(RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) if(RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
this._listener.Prefixes.Add($"http://*:{settings.apiPortNumber}/"); this._listener.Prefixes.Add($"http://*:{TrangaSettings.apiPortNumber}/");
else else
this._listener.Prefixes.Add($"http://localhost:{settings.apiPortNumber}/"); this._listener.Prefixes.Add($"http://localhost:{TrangaSettings.apiPortNumber}/");
Thread listenThread = new (Listen); Thread listenThread = new (Listen);
listenThread.Start(); listenThread.Start();
Thread watchThread = new(WatchRunning); Thread watchThread = new(WatchRunning);
@ -63,10 +63,11 @@ public class Server : GlobalBase
{ {
HttpListenerRequest request = context.Request; HttpListenerRequest request = context.Request;
HttpListenerResponse response = context.Response; HttpListenerResponse response = context.Response;
if(request.HttpMethod == "OPTIONS")
SendResponse(HttpStatusCode.OK, context.Response);
if (request.Url!.LocalPath.Contains("favicon")) if (request.Url!.LocalPath.Contains("favicon"))
{
SendResponse(HttpStatusCode.NoContent, response); SendResponse(HttpStatusCode.NoContent, response);
return;
}
switch (request.HttpMethod) switch (request.HttpMethod)
{ {
@ -79,6 +80,9 @@ public class Server : GlobalBase
case "DELETE": case "DELETE":
HandleDelete(request, response); HandleDelete(request, response);
break; break;
case "OPTIONS":
SendResponse(HttpStatusCode.OK, context.Response);
break;
default: default:
SendResponse(HttpStatusCode.BadRequest, response); SendResponse(HttpStatusCode.BadRequest, response);
break; break;
@ -198,16 +202,16 @@ public class Server : GlobalBase
SendResponse(HttpStatusCode.OK, response, _parent.jobBoss.jobs.Where(jjob => jjob is DownloadNewChapters).OrderBy(jjob => ((DownloadNewChapters)jjob).manga.sortName)); SendResponse(HttpStatusCode.OK, response, _parent.jobBoss.jobs.Where(jjob => jjob is DownloadNewChapters).OrderBy(jjob => ((DownloadNewChapters)jjob).manga.sortName));
break; break;
case "Settings": case "Settings":
SendResponse(HttpStatusCode.OK, response, settings); SendResponse(HttpStatusCode.OK, response, TrangaSettings.AsJObject());
break; break;
case "Settings/userAgent": case "Settings/userAgent":
SendResponse(HttpStatusCode.OK, response, settings.userAgent); SendResponse(HttpStatusCode.OK, response, TrangaSettings.userAgent);
break; break;
case "Settings/customRequestLimit": case "Settings/customRequestLimit":
SendResponse(HttpStatusCode.OK, response, settings.requestLimits); SendResponse(HttpStatusCode.OK, response, TrangaSettings.requestLimits);
break; break;
case "Settings/AprilFoolsMode": case "Settings/AprilFoolsMode":
SendResponse(HttpStatusCode.OK, response, settings.aprilFoolsMode); SendResponse(HttpStatusCode.OK, response, TrangaSettings.aprilFoolsMode);
break; break;
case "NotificationConnectors": case "NotificationConnectors":
SendResponse(HttpStatusCode.OK, response, notificationConnectors); SendResponse(HttpStatusCode.OK, response, notificationConnectors);
@ -314,7 +318,7 @@ public class Server : GlobalBase
} }
if (requestVariables.TryGetValue("customFolderName", out customFolderName)) if (requestVariables.TryGetValue("customFolderName", out customFolderName))
manga.MovePublicationFolder(settings.downloadLocation, customFolderName); manga.MovePublicationFolder(TrangaSettings.downloadLocation, customFolderName);
requestVariables.TryGetValue("translatedLanguage", out translatedLanguage); requestVariables.TryGetValue("translatedLanguage", out translatedLanguage);
_parent.jobBoss.AddJob(new DownloadNewChapters(this, connector!, manga, true, interval, translatedLanguage: translatedLanguage??"en")); _parent.jobBoss.AddJob(new DownloadNewChapters(this, connector!, manga, true, interval, translatedLanguage: translatedLanguage??"en"));
@ -343,7 +347,7 @@ public class Server : GlobalBase
} }
if (requestVariables.TryGetValue("customFolderName", out customFolderName)) if (requestVariables.TryGetValue("customFolderName", out customFolderName))
manga.MovePublicationFolder(settings.downloadLocation, customFolderName); manga.MovePublicationFolder(TrangaSettings.downloadLocation, customFolderName);
requestVariables.TryGetValue("translatedLanguage", out translatedLanguage); requestVariables.TryGetValue("translatedLanguage", out translatedLanguage);
_parent.jobBoss.AddJob(new DownloadNewChapters(this, connector!, manga, false, translatedLanguage: translatedLanguage??"en")); _parent.jobBoss.AddJob(new DownloadNewChapters(this, connector!, manga, false, translatedLanguage: translatedLanguage??"en"));
@ -405,7 +409,7 @@ public class Server : GlobalBase
SendResponse(HttpStatusCode.BadRequest, response); SendResponse(HttpStatusCode.BadRequest, response);
break; break;
} }
settings.UpdateDownloadLocation(downloadLocation, moveFiles); TrangaSettings.UpdateDownloadLocation(downloadLocation, moveFiles);
SendResponse(HttpStatusCode.Accepted, response); SendResponse(HttpStatusCode.Accepted, response);
break; break;
case "Settings/AprilFoolsMode": case "Settings/AprilFoolsMode":
@ -415,7 +419,7 @@ public class Server : GlobalBase
SendResponse(HttpStatusCode.BadRequest, response); SendResponse(HttpStatusCode.BadRequest, response);
break; break;
} }
settings.UpdateAprilFoolsMode(aprilFoolsModeEnabled); TrangaSettings.UpdateAprilFoolsMode(aprilFoolsModeEnabled);
SendResponse(HttpStatusCode.Accepted, response); SendResponse(HttpStatusCode.Accepted, response);
break; break;
/*case "Settings/UpdateWorkingDirectory": /*case "Settings/UpdateWorkingDirectory":
@ -433,11 +437,11 @@ public class Server : GlobalBase
SendResponse(HttpStatusCode.BadRequest, response); SendResponse(HttpStatusCode.BadRequest, response);
break; break;
} }
settings.UpdateUserAgent(customUserAgent); TrangaSettings.UpdateUserAgent(customUserAgent);
SendResponse(HttpStatusCode.Accepted, response); SendResponse(HttpStatusCode.Accepted, response);
break; break;
case "Settings/userAgent/Reset": case "Settings/userAgent/Reset":
settings.UpdateUserAgent(null); TrangaSettings.UpdateUserAgent(null);
SendResponse(HttpStatusCode.Accepted, response); SendResponse(HttpStatusCode.Accepted, response);
break; break;
case "Settings/customRequestLimit": case "Settings/customRequestLimit":
@ -450,17 +454,11 @@ public class Server : GlobalBase
break; break;
} }
if (settings.requestLimits.ContainsKey(requestType)) TrangaSettings.UpdateRateLimit(requestType, requestsPerMinute);
{
settings.requestLimits[requestType] = requestsPerMinute;
SendResponse(HttpStatusCode.Accepted, response); SendResponse(HttpStatusCode.Accepted, response);
}else
SendResponse(HttpStatusCode.BadRequest, response);
settings.ExportSettings();
break; break;
case "Settings/customRequestLimit/Reset": case "Settings/customRequestLimit/Reset":
settings.requestLimits = TrangaSettings.DefaultRequestLimits; TrangaSettings.ResetRateLimits();
settings.ExportSettings();
break; break;
case "NotificationConnectors/Update": case "NotificationConnectors/Update":
if (!requestVariables.TryGetValue("notificationConnector", out notificationConnectorStr) || if (!requestVariables.TryGetValue("notificationConnector", out notificationConnectorStr) ||
@ -713,30 +711,28 @@ public class Server : GlobalBase
private void SendResponse(HttpStatusCode statusCode, HttpListenerResponse response, object? content = null) private void SendResponse(HttpStatusCode statusCode, HttpListenerResponse response, object? content = null)
{ {
//Log($"Response: {statusCode} {content}"); //Log($"Response: {statusCode} {content}");
response.StatusCode = (int)statusCode; response.StatusCode = (int)statusCode;
response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With"); response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With");
response.AddHeader("Access-Control-Allow-Methods", "GET, POST, DELETE"); response.AddHeader("Access-Control-Allow-Methods", "GET, POST, DELETE");
response.AddHeader("Access-Control-Max-Age", "1728000"); response.AddHeader("Access-Control-Max-Age", "1728000");
response.AppendHeader("Access-Control-Allow-Origin", "*"); response.AppendHeader("Access-Control-Allow-Origin", "*");
try
{
if (content is not Stream) if (content is not Stream)
{ {
response.ContentType = "application/json"; response.ContentType = "application/json";
try response.AddHeader("Cache-Control", "no-store");
{
response.OutputStream.Write(content is not null response.OutputStream.Write(content is not null
? Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(content)) ? Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(content))
: Array.Empty<byte>()); : Array.Empty<byte>());
response.OutputStream.Close(); response.OutputStream.Close();
} }
catch (HttpListenerException e)
{
Log(e.ToString());
}
}
else if (content is FileStream stream) else if (content is FileStream stream)
{ {
string contentType = stream.Name.Split('.')[^1]; string contentType = stream.Name.Split('.')[^1];
response.AddHeader("Cache-Control", "max-age=600");
switch (contentType.ToLower()) switch (contentType.ToLower())
{ {
case "gif": case "gif":
@ -753,9 +749,15 @@ public class Server : GlobalBase
response.ContentType = "text/plain"; response.ContentType = "text/plain";
break; break;
} }
stream.CopyTo(response.OutputStream); stream.CopyTo(response.OutputStream);
response.OutputStream.Close(); response.OutputStream.Close();
stream.Close(); stream.Close();
} }
} }
catch (Exception e)
{
Log(e.ToString());
}
}
} }

View File

@ -11,10 +11,9 @@ public partial class Tranga : GlobalBase
private Server _server; private Server _server;
private HashSet<MangaConnector> _connectors; private HashSet<MangaConnector> _connectors;
public Tranga(Logger? logger, TrangaSettings settings) : base(logger, settings) public Tranga(Logger? logger) : base(logger)
{ {
Log("\n\n _______ \n|_ _|.----..---.-..-----..-----..---.-.\n | | | _|| _ || || _ || _ |\n |___| |__| |___._||__|__||___ ||___._|\n |_____| \n\n"); Log("\n\n _______ \n|_ _|.----..---.-..-----..-----..---.-.\n | | | _|| _ || || _ || _ |\n |___| |__| |___._||__|__||___ ||___._|\n |_____| \n\n");
Log(settings.ToString());
keepRunning = true; keepRunning = true;
_connectors = new HashSet<MangaConnector>() _connectors = new HashSet<MangaConnector>()
{ {
@ -25,7 +24,8 @@ public partial class Tranga : GlobalBase
new Mangaworld(this), new Mangaworld(this),
new Bato(this), new Bato(this),
new MangaLife(this), new MangaLife(this),
new ManhuaPlus(this) new ManhuaPlus(this),
new MangaHere(this),
}; };
foreach(DirectoryInfo dir in new DirectoryInfo(Path.GetTempPath()).GetDirectories("trangatemp"))//Cleanup old temp folders foreach(DirectoryInfo dir in new DirectoryInfo(Path.GetTempPath()).GetDirectories("trangatemp"))//Cleanup old temp folders
dir.Delete(); dir.Delete();
@ -69,7 +69,7 @@ public partial class Tranga : GlobalBase
{ {
while (keepRunning) while (keepRunning)
{ {
if(!settings.aprilFoolsMode || !IsAprilFirst()) if(!TrangaSettings.aprilFoolsMode || !IsAprilFirst())
jobBoss.CheckJobs(); jobBoss.CheckJobs();
else else
Log("April Fools Mode in Effect"); Log("April Fools Mode in Effect");

View File

@ -1,10 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net7.0</TargetFramework> <TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<LangVersion>12</LangVersion>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@ -36,34 +36,16 @@ public partial class Tranga : GlobalBase
enabledLoggers.Add(Logger.LoggerType.FileLogger); enabledLoggers.Add(Logger.LoggerType.FileLogger);
Logger logger = new(enabledLoggers.ToArray(), Console.Out, Console.OutputEncoding, directoryPath); Logger logger = new(enabledLoggers.ToArray(), Console.Out, Console.OutputEncoding, directoryPath);
TrangaSettings? settings = null;
bool dlp = fetched.TryGetValue(downloadLocation, out string[]? downloadLocationPath); bool dlp = fetched.TryGetValue(downloadLocation, out string[]? downloadLocationPath);
bool wdp = fetched.TryGetValue(downloadLocation, out string[]? workingDirectoryPath); bool wdp = fetched.TryGetValue(workingDirectory, out string[]? workingDirectoryPath);
if (dlp && wdp) if (wdp)
{ TrangaSettings.LoadFromWorkingDirectory(workingDirectoryPath![0]);
settings = new TrangaSettings(downloadLocationPath![0], workingDirectoryPath![0]);
}else if (dlp)
{
if (settings is null)
settings = new TrangaSettings(downloadLocation: downloadLocationPath![0]);
else else
settings = new TrangaSettings(downloadLocation: downloadLocationPath![0], settings.workingDirectory); TrangaSettings.CreateOrUpdate();
}else if (wdp) if(dlp)
{ TrangaSettings.CreateOrUpdate(downloadDirectory: downloadLocationPath![0]);
if (settings is null)
settings = new TrangaSettings(downloadLocation: workingDirectoryPath![0]);
else
settings = new TrangaSettings(settings.downloadLocation, workingDirectoryPath![0]);
}
else
{
settings = new TrangaSettings();
}
Directory.CreateDirectory(settings.downloadLocation);//TODO validate path Tranga _ = new (logger);
Directory.CreateDirectory(settings.workingDirectory);//TODO validate path
Tranga _ = new (logger, settings);
} }
} }

View File

@ -1,7 +1,6 @@
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text.Json.Nodes;
using System.Text.RegularExpressions;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Tranga.LibraryConnectors; using Tranga.LibraryConnectors;
using Tranga.MangaConnectors; using Tranga.MangaConnectors;
using Tranga.NotificationConnectors; using Tranga.NotificationConnectors;
@ -9,20 +8,20 @@ using static System.IO.UnixFileMode;
namespace Tranga; namespace Tranga;
public class TrangaSettings public static class TrangaSettings
{ {
public string downloadLocation { get; private set; }
public string workingDirectory { get; private set; }
public int apiPortNumber { get; init; }
public string userAgent { get; private set; } = DefaultUserAgent;
[JsonIgnore] public string settingsFilePath => Path.Join(workingDirectory, "settings.json");
[JsonIgnore] public string libraryConnectorsFilePath => Path.Join(workingDirectory, "libraryConnectors.json");
[JsonIgnore] public string notificationConnectorsFilePath => Path.Join(workingDirectory, "notificationConnectors.json");
[JsonIgnore] public string jobsFolderPath => Path.Join(workingDirectory, "jobs");
[JsonIgnore] public string coverImageCache => Path.Join(workingDirectory, "imageCache");
[JsonIgnore] internal static readonly string DefaultUserAgent = $"Tranga ({Enum.GetName(Environment.OSVersion.Platform)}; {(Environment.Is64BitOperatingSystem ? "x64" : "")}) / 1.0"; [JsonIgnore] internal static readonly string DefaultUserAgent = $"Tranga ({Enum.GetName(Environment.OSVersion.Platform)}; {(Environment.Is64BitOperatingSystem ? "x64" : "")}) / 1.0";
public ushort? version { get; } = 2; public static string downloadLocation { get; private set; } = (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? "/Manga" : Path.Join(Directory.GetCurrentDirectory(), "Downloads"));
public bool aprilFoolsMode { get; private set; } = true; public static string workingDirectory { get; private set; } = Path.Join(RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? "/usr/share" : Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "tranga-api");
public static int apiPortNumber { get; private set; } = 6531;
public static string userAgent { get; private set; } = DefaultUserAgent;
[JsonIgnore] public static string settingsFilePath => Path.Join(workingDirectory, "settings.json");
[JsonIgnore] public static string libraryConnectorsFilePath => Path.Join(workingDirectory, "libraryConnectors.json");
[JsonIgnore] public static string notificationConnectorsFilePath => Path.Join(workingDirectory, "notificationConnectors.json");
[JsonIgnore] public static string jobsFolderPath => Path.Join(workingDirectory, "jobs");
[JsonIgnore] public static string coverImageCache => Path.Join(workingDirectory, "imageCache");
public static ushort? version { get; } = 2;
public static bool aprilFoolsMode { get; private set; } = true;
[JsonIgnore]internal static readonly Dictionary<RequestType, int> DefaultRequestLimits = new () [JsonIgnore]internal static readonly Dictionary<RequestType, int> DefaultRequestLimits = new ()
{ {
{RequestType.MangaInfo, 250}, {RequestType.MangaInfo, 250},
@ -33,50 +32,35 @@ public class TrangaSettings
{RequestType.Default, 60} {RequestType.Default, 60}
}; };
public Dictionary<RequestType, int> requestLimits { get; set; } = DefaultRequestLimits; public static Dictionary<RequestType, int> requestLimits { get; set; } = DefaultRequestLimits;
public TrangaSettings(string? downloadLocation = null, string? workingDirectory = null, int? apiPortNumber = null) public static void LoadFromWorkingDirectory(string directory)
{ {
string wd = workingDirectory ?? Path.Join(RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? "/usr/share" : Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "tranga-api"); TrangaSettings.workingDirectory = directory;
string sfp = Path.Join(wd, "settings.json"); if(File.Exists(settingsFilePath))
Deserialize(File.ReadAllText(settingsFilePath));
else return;
string lockFilePath = $"{sfp}.lock"; Directory.CreateDirectory(downloadLocation);
if (File.Exists(sfp) && !File.Exists(lockFilePath)) Directory.CreateDirectory(workingDirectory);
{//Load from settings file
FileStream lockFile = File.Create(lockFilePath,0, FileOptions.DeleteOnClose); //lock settingsfile
string settingsStr = File.ReadAllText(sfp);
settingsStr = Regex.Replace(settingsStr, @"""MangaDexAuthor"": [0-9]+,", "");//https://github.com/C9Glax/tranga/pull/161 Remove sometime in the future :3
TrangaSettings settings = JsonConvert.DeserializeObject<TrangaSettings>(settingsStr)!;
this.requestLimits = settings.requestLimits;
this.userAgent = settings.userAgent;
this.downloadLocation = downloadLocation ?? settings.downloadLocation;
this.workingDirectory = workingDirectory ?? settings.workingDirectory;
this.apiPortNumber = apiPortNumber ?? settings.apiPortNumber;
lockFile.Close(); //unlock settingsfile
}
else if(!File.Exists(sfp))
{//No settings file exists
if (downloadLocation?.Length < 1 || workingDirectory?.Length < 1)
throw new ArgumentException("Download-location and working-directory paths can not be empty!");
this.requestLimits = DefaultRequestLimits;
this.userAgent = DefaultUserAgent;
this.apiPortNumber = apiPortNumber ?? 6531;
this.downloadLocation = downloadLocation ?? (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? "/Manga" : Path.Join(Directory.GetCurrentDirectory(), "Downloads"));
this.workingDirectory = workingDirectory ?? Path.Join(RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? "/usr/share" : Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "tranga-api");
ExportSettings(); ExportSettings();
} }
else
{//Settingsfile is locked public static void CreateOrUpdate(string? downloadDirectory = null, string? pWorkingDirectory = null, int? pApiPortNumber = null, string? pUserAgent = null, bool? pAprilFoolsMode = null)
this.requestLimits = DefaultRequestLimits; {
this.userAgent = DefaultUserAgent; if(pWorkingDirectory is null && File.Exists(settingsFilePath))
this.apiPortNumber = apiPortNumber!.Value; LoadFromWorkingDirectory(workingDirectory);
this.downloadLocation = downloadLocation!; TrangaSettings.downloadLocation = downloadDirectory ?? TrangaSettings.downloadLocation;
this.workingDirectory = workingDirectory!; TrangaSettings.workingDirectory = pWorkingDirectory ?? TrangaSettings.workingDirectory;
} TrangaSettings.apiPortNumber = pApiPortNumber ?? TrangaSettings.apiPortNumber;
UpdateDownloadLocation(this.downloadLocation, false); TrangaSettings.userAgent = pUserAgent ?? TrangaSettings.userAgent;
TrangaSettings.aprilFoolsMode = pAprilFoolsMode ?? TrangaSettings.aprilFoolsMode;
Directory.CreateDirectory(downloadLocation);
Directory.CreateDirectory(workingDirectory);
ExportSettings();
} }
public HashSet<LibraryConnector> LoadLibraryConnectors(GlobalBase clone) public static HashSet<LibraryConnector> LoadLibraryConnectors(GlobalBase clone)
{ {
if (!File.Exists(libraryConnectorsFilePath)) if (!File.Exists(libraryConnectorsFilePath))
return new HashSet<LibraryConnector>(); return new HashSet<LibraryConnector>();
@ -90,7 +74,7 @@ public class TrangaSettings
})!; })!;
} }
public HashSet<NotificationConnector> LoadNotificationConnectors(GlobalBase clone) public static HashSet<NotificationConnector> LoadNotificationConnectors(GlobalBase clone)
{ {
if (!File.Exists(notificationConnectorsFilePath)) if (!File.Exists(notificationConnectorsFilePath))
return new HashSet<NotificationConnector>(); return new HashSet<NotificationConnector>();
@ -104,13 +88,13 @@ public class TrangaSettings
})!; })!;
} }
public void UpdateAprilFoolsMode(bool enabled) public static void UpdateAprilFoolsMode(bool enabled)
{ {
this.aprilFoolsMode = enabled; TrangaSettings.aprilFoolsMode = enabled;
ExportSettings(); ExportSettings();
} }
public void UpdateDownloadLocation(string newPath, bool moveFiles = true) public static void UpdateDownloadLocation(string newPath, bool moveFiles = true)
{ {
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
Directory.CreateDirectory(newPath, Directory.CreateDirectory(newPath,
@ -118,32 +102,44 @@ public class TrangaSettings
else else
Directory.CreateDirectory(newPath); Directory.CreateDirectory(newPath);
if (moveFiles && Directory.Exists(this.downloadLocation)) if (moveFiles && Directory.Exists(TrangaSettings.downloadLocation))
Directory.Move(this.downloadLocation, newPath); Directory.Move(TrangaSettings.downloadLocation, newPath);
this.downloadLocation = newPath; TrangaSettings.downloadLocation = newPath;
ExportSettings(); ExportSettings();
} }
public void UpdateWorkingDirectory(string newPath) public static void UpdateWorkingDirectory(string newPath)
{ {
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
Directory.CreateDirectory(newPath, Directory.CreateDirectory(newPath,
GroupRead | GroupWrite | None | OtherRead | OtherWrite | UserRead | UserWrite); GroupRead | GroupWrite | None | OtherRead | OtherWrite | UserRead | UserWrite);
else else
Directory.CreateDirectory(newPath); Directory.CreateDirectory(newPath);
Directory.Move(this.workingDirectory, newPath); Directory.Move(TrangaSettings.workingDirectory, newPath);
this.workingDirectory = newPath; TrangaSettings.workingDirectory = newPath;
ExportSettings(); ExportSettings();
} }
public void UpdateUserAgent(string? customUserAgent) public static void UpdateUserAgent(string? customUserAgent)
{ {
this.userAgent = customUserAgent ?? DefaultUserAgent; TrangaSettings.userAgent = customUserAgent ?? DefaultUserAgent;
ExportSettings(); ExportSettings();
} }
public void ExportSettings() public static void UpdateRateLimit(RequestType requestType, int newLimit)
{
TrangaSettings.requestLimits[requestType] = newLimit;
ExportSettings();
}
public static void ResetRateLimits()
{
TrangaSettings.requestLimits = DefaultRequestLimits;
ExportSettings();
}
public static void ExportSettings()
{ {
if (File.Exists(settingsFilePath)) if (File.Exists(settingsFilePath))
{ {
@ -152,22 +148,38 @@ public class TrangaSettings
} }
else else
Directory.CreateDirectory(new FileInfo(settingsFilePath).DirectoryName!); Directory.CreateDirectory(new FileInfo(settingsFilePath).DirectoryName!);
File.WriteAllText(settingsFilePath, JsonConvert.SerializeObject(this, Formatting.Indented)); File.WriteAllText(settingsFilePath, Serialize());
} }
public string GetFullCoverPath(Manga manga) public static JObject AsJObject()
{ {
return Path.Join(this.coverImageCache, manga.coverFileNameInCache); JObject jobj = new JObject();
jobj.Add("downloadLocation", JToken.FromObject(TrangaSettings.downloadLocation));
jobj.Add("workingDirectory", JToken.FromObject(TrangaSettings.workingDirectory));
jobj.Add("apiPortNumber", JToken.FromObject(TrangaSettings.apiPortNumber));
jobj.Add("userAgent", JToken.FromObject(TrangaSettings.userAgent));
jobj.Add("aprilFoolsMode", JToken.FromObject(TrangaSettings.aprilFoolsMode));
jobj.Add("version", JToken.FromObject(TrangaSettings.version));
jobj.Add("requestLimits", JToken.FromObject(TrangaSettings.requestLimits));
return jobj;
} }
public override string ToString() public static string Serialize() => AsJObject().ToString();
public static void Deserialize(string serialized)
{ {
return $"TrangaSettings:\n" + JObject jobj = JObject.Parse(serialized);
$"\tDownloadLocation: {downloadLocation}\n" + if (jobj.TryGetValue("downloadLocation", out JToken? dl))
$"\tworkingDirectory: {workingDirectory}\n" + TrangaSettings.downloadLocation = dl.Value<string>()!;
$"\tjobsFolderPath: {jobsFolderPath}\n" + if (jobj.TryGetValue("workingDirectory", out JToken? wd))
$"\tsettingsFilePath: {settingsFilePath}\n" + TrangaSettings.workingDirectory = wd.Value<string>()!;
$"\t\tnotificationConnectors: {notificationConnectorsFilePath}\n" + if (jobj.TryGetValue("apiPortNumber", out JToken? apn))
$"\t\tlibraryConnectors: {libraryConnectorsFilePath}\n"; TrangaSettings.apiPortNumber = apn.Value<int>();
if (jobj.TryGetValue("userAgent", out JToken? ua))
TrangaSettings.userAgent = ua.Value<string>()!;
if (jobj.TryGetValue("aprilFoolsMode", out JToken? afm))
TrangaSettings.aprilFoolsMode = afm.Value<bool>()!;
if (jobj.TryGetValue("requestLimits", out JToken? rl))
TrangaSettings.requestLimits = rl.ToObject<Dictionary<RequestType, int>>()!;
} }
} }

21
docker-compose.local.yaml Normal file
View File

@ -0,0 +1,21 @@
version: '3'
services:
tranga-api:
build:
dockerfile: Dockerfile
context: .
container_name: tranga-api
volumes:
- ./Manga:/Manga
- ./settings:/usr/share/tranga-api
ports:
- "6531:6531"
restart: unless-stopped
tranga-website:
image: glax/tranga-website:latest
container_name: tranga-website
ports:
- "9555:80"
depends_on:
- tranga-api
restart: unless-stopped