mirror of
https://github.com/C9Glax/tranga.git
synced 2025-07-02 00:44:16 +02:00
Compare commits
537 Commits
0.4
...
2d82279d98
Author | SHA1 | Date | |
---|---|---|---|
2d82279d98 | |||
c5559a4ceb | |||
2572a537ab | |||
58db049496 | |||
8f309fcfd7 | |||
11461051f3 | |||
a4aa571870 | |||
e4086a8892 | |||
c45e4ddf90 | |||
675effd317 | |||
a4f67c9ab4 | |||
2538a29788 | |||
81d5802092 | |||
436edfde66 | |||
00c1cd56b8 | |||
a63154b581 | |||
53fe7ee983 | |||
6fb4098c16 | |||
7a024e8733 | |||
835e239be5 | |||
df8538c3b4 | |||
f832fe0de3 | |||
ebdb38bd57 | |||
e3201a9b99 | |||
eb50b84266 | |||
b3d778ff56 | |||
00861c406a | |||
01c8784bab | |||
3aa299e48a | |||
d1ce244135 | |||
c91754614b | |||
70b1ae4812 | |||
336e08aebf | |||
18134cdf01 | |||
5b89cbd042 | |||
74aca86b62 | |||
e5abaa4549 | |||
eb0eb71e86 | |||
4e73b0a4cf | |||
140074208f | |||
fa19d3da14 | |||
3d6657b483 | |||
f9b5e05974 | |||
ad4027779f | |||
98ec0b837f | |||
1afa3df316 | |||
d83aa1ef5b | |||
b610ec734e | |||
abf587377c | |||
437349bd27 | |||
000539d6a6 | |||
b4bef25a22 | |||
579e400a5d | |||
8af2b12fc0 | |||
bad4330330 | |||
42596752d3 | |||
16238c590b | |||
9f38dc3b6a | |||
485637d99a | |||
de14ff0b75 | |||
f947c37bd6 | |||
77eec0f696 | |||
18323f9f51 | |||
2cd2b6842d | |||
09f815903f | |||
c108478039 | |||
74289e43b7 | |||
2779f9ba09 | |||
59a8e556f0 | |||
074b137b5c | |||
3cb2540794 | |||
02c9934896 | |||
b2e1c95bca | |||
8c9e3ea6b6 | |||
db441607ad | |||
91c56783dc | |||
2c288eeeea | |||
57a1ea91fc | |||
06138a3927 | |||
84b053e672 | |||
0fe0cbc4ad | |||
62e6ce8363 | |||
a4f3ec6580 | |||
8b4e996b7e | |||
964540d30f | |||
fa69f4488f | |||
42c2876188 | |||
715244ff1b | |||
2333cd9095 | |||
c8225db4fe | |||
6741ca096b | |||
a897a7b3a2 | |||
0f8932e712 | |||
78023ef0fd | |||
d171f34e4e | |||
aa0dc4fa35 | |||
25f48592c0 | |||
398ac304d2 | |||
58a62f8272 | |||
86752c9a7e | |||
f9a7828d02 | |||
c97ff69148 | |||
1735bbcf8a | |||
9ae8ca65df | |||
00599cd24e | |||
6d5618a1f7 | |||
a1202a875d | |||
98946b4aa3 | |||
41b6bb77b6 | |||
e70a14ca56 | |||
b099da1156 | |||
01d1f922c2 | |||
47a80d67a8 | |||
16e3549455 | |||
be8c6b50ba | |||
a38fcf50ca | |||
82f6c7b3fe | |||
5586d2c104 | |||
62dc9fee2a | |||
ac96fca6dc | |||
25a6ceff10 | |||
b3e1d39d0f | |||
2833b7f22a | |||
cbdd305b69 | |||
b88890817e | |||
f66ab7d40b | |||
4cb3694cd5 | |||
a05d4c8bd9 | |||
22f87a74b2 | |||
ba57282879 | |||
9ccba6fba6 | |||
4f01c1166f | |||
0a51e7ad3d | |||
e541b922dc | |||
604abd5f9a | |||
7b311eae75 | |||
d4eb72cd99 | |||
b515215f4b | |||
a16686dfbf | |||
4275703941 | |||
c3342984ea | |||
ed4bdb5b33 | |||
0f0902c932 | |||
6508055b43 | |||
abc66511d8 | |||
9ed36c47b5 | |||
fd1b2a8470 | |||
8058749ab5 | |||
8737617e5f | |||
7e4f43f1e2 | |||
12b1b2afd6 | |||
0f9ac60fcd | |||
8c87f2948c | |||
e0fb817256 | |||
cdd2d94ba1 | |||
d5b7645cd2 | |||
9af5c1603e | |||
1035939309 | |||
3b542c04f6 | |||
a809b7c285 | |||
e883277400 | |||
23dfdc0933 | |||
edc24fff5b | |||
6cdccdf66b | |||
a4c9168551 | |||
821a1b7c3a | |||
b2b4256972 | |||
d2f46e4637 | |||
303fc293ba | |||
36c145da26 | |||
c822c74f42 | |||
dda4054d34 | |||
5b2546fdbc | |||
c11e3993ea | |||
02a382a99a | |||
c6c8f5cdf6 | |||
84842aed3c | |||
d9ced11cd1 | |||
25c90782dc | |||
e789c429cd | |||
93de471836 | |||
8b58e7dd13 | |||
b571bfa43d | |||
088d1c4647 | |||
f280c01802 | |||
1be10b310d | |||
a0469f3145 | |||
fcd81f03b3 | |||
76604d84d8 | |||
af822febbe | |||
8e207c3119 | |||
b6f8c8aab5 | |||
36f7cbd3e9 | |||
3b2643d949 | |||
9fd8bf1741 | |||
d5c9c5ba96 | |||
c8e27921ab | |||
6eaba07801 | |||
41929e0c72 | |||
4fcaca1a6e | |||
0e3c7f32d7 | |||
1c94625840 | |||
32f89f9dce | |||
234735a562 | |||
8b916eb854 | |||
29e1790c93 | |||
ac4c799a74 | |||
7c62883c37 | |||
02018253bf | |||
2aec884009 | |||
b3321ff030 | |||
16c1094875 | |||
5763d50409 | |||
ad43297358 | |||
b17800e0ef | |||
89c80d2997 | |||
6485b8744f | |||
a3a96b6b55 | |||
5bce3c6fdd | |||
5fa0c98d05 | |||
b166013770 | |||
02fe849046 | |||
d42393c83a | |||
c685bd622f | |||
dc83cc2194 | |||
7784f2024e | |||
4895079887 | |||
ab1ddc6dc8 | |||
87eade10cf | |||
1f3ac41b30 | |||
6a304bb330 | |||
b0642d1251 | |||
63b5139e93 | |||
e938784388 | |||
c436389426 | |||
5099e25f3f | |||
cf6fc3b8f6 | |||
f5141d0f8e | |||
5c753e7a7d | |||
17ce820cf3 | |||
5b4a3b9d7c | |||
f73997e563 | |||
437136804d | |||
e14683d21a | |||
5ae02ee0ed | |||
a2e9a3f34a | |||
bbf05e3dec | |||
d95839e5df | |||
5a303598fe | |||
db2103963e | |||
2c1105527a | |||
ed19dcb5c3 | |||
46f06c2685 | |||
d4f47e057c | |||
61712d0537 | |||
1f8f8c09e3 | |||
0522fa6215 | |||
0383a7d686 | |||
bd189984a9 | |||
58c01b2174 | |||
459558a514 | |||
721b316209 | |||
b1befa2ecc | |||
57a4cc4ab5 | |||
655e8db2b6 | |||
7cdf77cbb9 | |||
5a9aed4969 | |||
5b41f687d0 | |||
d6a62dc315 | |||
6d91788655 | |||
14785e5672 | |||
496d502cd2 | |||
7612411917 | |||
ed1402b5ec | |||
5adaee4821 | |||
2d82fe1489 | |||
783fd8129e | |||
4f29eff48e | |||
e0e7abb62b | |||
ae63a216a5 | |||
5d98295c59 | |||
0c580933f9 | |||
06f735aadd | |||
439d69d8e0 | |||
933df58712 | |||
165bbc412e | |||
6158fa072b | |||
0d3799e00d | |||
e977bed5a5 | |||
cacd5fede2 | |||
1bca99cb6a | |||
15fc367263 | |||
8bb6fb902b | |||
a57903cd5a | |||
1cd819b21d | |||
27afedc1b4 | |||
fac0a3f7eb | |||
03ca480fe8 | |||
c2915468a5 | |||
8805c53cb8 | |||
adbbe3f6cc | |||
14b694d3be | |||
72ce75c6e0 | |||
8381951168 | |||
b24032d124 | |||
8bc23f7c69 | |||
48b7371a18 | |||
61ecefb615 | |||
8ff65bf400 | |||
932057cca0 | |||
67d06cd887 | |||
cbb012a659 | |||
e4f33bcca9 | |||
fbba7c45b9 | |||
d9b6062767 | |||
d477cd1ccd | |||
f892db7dda | |||
16c1b5c506 | |||
d5ecc1c37d | |||
1b9ebd096b | |||
8619630269 | |||
2bc92556e3 | |||
f1ab823e7f | |||
8261d02cc7 | |||
8d3b8be95c | |||
60519910de | |||
0940afe41f | |||
3dc376c19f | |||
3e56ef842b | |||
5a44e3b8b9 | |||
732c2f119c | |||
81638f4b4a | |||
c547aa6422 | |||
d80980512e | |||
f9f802155d | |||
eef0955009 | |||
ec25900ac0 | |||
e5fe14a09e | |||
5dc91095f8 | |||
985ac8fc7a | |||
c9537a9963 | |||
4fd3c03804 | |||
a1e9dd0232 | |||
aa1f9b1b56 | |||
6069578b6e | |||
a84b768e24 | |||
d1a21af15d | |||
7423ae6ace | |||
3aa7ba9d96 | |||
fdbb4570be | |||
b643a0c2a9 | |||
6fa6f897aa | |||
2bfab0298d | |||
147a20385b | |||
afa18d6a2c | |||
66980eef23 | |||
65f468a30a | |||
a91c33ee4f | |||
f39482fe4c | |||
41f47b4d6b | |||
be40091102 | |||
665092be6a | |||
653cb699d0 | |||
8dbc5446ad | |||
750df4ed52 | |||
4772ae0756 | |||
23f703d5a5 | |||
6aa0ea277b | |||
780df1cd6e | |||
0b7da2e9cb | |||
01a059d26b | |||
a8dbece237 | |||
5efa00e059 | |||
02075ed1b1 | |||
fabd16ccea | |||
79928075b0 | |||
9b8eb6a197 | |||
1d263ef45a | |||
e0877add30 | |||
046cad8072 | |||
b2ce55be96 | |||
a6e9013495 | |||
14c69631a6 | |||
ccc4e42a49 | |||
d6e75fda31 | |||
fc89537f63 | |||
fd3423d03c | |||
878f77766f | |||
08001fd684 | |||
e2917d2f2e | |||
32dc58715e | |||
add0583776 | |||
6fed0e5473 | |||
a0636ac7a2 | |||
7aeb78e2f6 | |||
5cf512f2b2 | |||
7d96b0901f | |||
68e80bc066 | |||
ad971fb065 | |||
86052472bc | |||
ec30bb40fa | |||
2fa96e9793 | |||
78e44b7704 | |||
8bf9df4419 | |||
4bd54f096d | |||
877daf0a1e | |||
6d0fcc13fb | |||
f0256494fd | |||
39fa905733 | |||
c557389967 | |||
201773af50 | |||
f85e02fb0a | |||
73d98b9c0f | |||
b0ee888c82 | |||
5c4431778e | |||
ccfa213b77 | |||
22d6389d38 | |||
f53dfb0822 | |||
a966bd788d | |||
dd651adc15 | |||
ba5ae67aa7 | |||
da4a5bed09 | |||
947b521163 | |||
5674adbd5e | |||
290819de09 | |||
0d0b68a8f9 | |||
87d2357b41 | |||
e3186aebb0 | |||
1cd37e2b1b | |||
9c267f395f | |||
e2b8888130 | |||
b6ac2682f6 | |||
eddf50483f | |||
a71d65e666 | |||
9a640aed27 | |||
30b6c4680b | |||
7b6253de0f | |||
5aa3214ce5 | |||
9b70994f71 | |||
93cf341f2d | |||
01cb74c088 | |||
ec480dffad | |||
b7014cbff5 | |||
0cab921402 | |||
0e0ba1796e | |||
27d8565dc1 | |||
79dc44d707 | |||
bb6a0ad0d4 | |||
43db463ba6 | |||
9eb8ddbc40 | |||
972cba69ec | |||
962fe9529e | |||
da1b0cb1cd | |||
7f88e57e47 | |||
8865bf284f | |||
5fc2de5fcb | |||
4bae223d95 | |||
0486168b43 | |||
b64ab5c6d4 | |||
578fa5e6be | |||
4d33e78123 | |||
52ac3e4e4e | |||
8b99a98e24 | |||
cf171d5c38 | |||
6d49b4b934 | |||
b55d2a2d06 | |||
737eebf599 | |||
aef01b684c | |||
53bff61174 | |||
431a602a40 | |||
9afb81cee2 | |||
ea69b355b5 | |||
84dbc36bbf | |||
455c87b2e1 | |||
df991e3da6 | |||
13c96fd09a | |||
6f1a6a43ee | |||
e2afc09c4a | |||
e9db7cfacc | |||
755167c39a | |||
1cff93fbac | |||
6c775d6e0c | |||
876b1ab78b | |||
a321ecb1bc | |||
674c8fc37b | |||
e24652b83e | |||
5dee13c402 | |||
942a552c8e | |||
b5bd5d6126 | |||
715cf1f4f3 | |||
168bf5a358 | |||
636d17d287 | |||
294b819ff0 | |||
d763610383 | |||
2910473fec | |||
ca2d13226f | |||
95c65c981e | |||
e72efa3731 | |||
597eedb6d4 | |||
8829132046 | |||
32467191f6 | |||
fe52d2c3b5 | |||
554f6b4acc | |||
9d0fc18051 | |||
e02b00e0ef | |||
06a8e4e895 | |||
a557f8cab5 | |||
e564be08f5 | |||
b8bf7bdf30 | |||
d6af014cb7 | |||
2dcaaf4d66 | |||
e3ec5420c0 | |||
5d66bce5b6 | |||
07ae4af209 | |||
d62b0bdf34 | |||
a367ebb230 | |||
4d3861d31b | |||
497ec74b9a | |||
18b5d17994 | |||
1916018fba | |||
a6a2d20981 | |||
1449292e53 | |||
67f3695be8 | |||
086d72565a | |||
e54e83c2ae | |||
73f19c3989 | |||
2c84688925 | |||
a58f113d14 | |||
fcb1848a93 | |||
337111d833 | |||
bb77e5348f | |||
b1850bf5f3 | |||
f2bd5c5e85 | |||
f396640001 | |||
05763d9f22 | |||
a11830b6b5 | |||
c76f3991d9 |
7
.github/dependabot.yml
vendored
Normal file
7
.github/dependabot.yml
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
version: 2
|
||||
updates:
|
||||
# Maintain dependencies for GitHub Actions
|
||||
- package-ecosystem: "github-actions"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "daily"
|
43
.github/workflows/docker-base.yml
vendored
Normal file
43
.github/workflows/docker-base.yml
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
name: Docker Image CI
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
|
||||
# https://github.com/docker/setup-qemu-action#usage
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v2.2.0
|
||||
|
||||
# https://github.com/marketplace/actions/docker-setup-buildx
|
||||
- name: Set up Docker Buildx
|
||||
id: buildx
|
||||
uses: docker/setup-buildx-action@v2.9.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@v4.1.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
|
45
.github/workflows/docker-image-cuttingedge.yml
vendored
Normal file
45
.github/workflows/docker-image-cuttingedge.yml
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
name: Docker Image CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "cuttingedge" ]
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
|
||||
# https://github.com/docker/setup-qemu-action#usage
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v2.2.0
|
||||
|
||||
# https://github.com/marketplace/actions/docker-setup-buildx
|
||||
- name: Set up Docker Buildx
|
||||
id: buildx
|
||||
uses: docker/setup-buildx-action@v2.9.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 API
|
||||
uses: docker/build-push-action@v4.1.1
|
||||
with:
|
||||
context: ./
|
||||
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
|
||||
pull: true
|
||||
push: true
|
||||
tags: |
|
||||
glax/tranga-api:cuttingedge
|
47
.github/workflows/docker-image-master.yml
vendored
Normal file
47
.github/workflows/docker-image-master.yml
vendored
Normal file
@ -0,0 +1,47 @@
|
||||
name: Docker Image CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "master" ]
|
||||
pull_request:
|
||||
branches: [ "master" ]
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
|
||||
# https://github.com/docker/setup-qemu-action#usage
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v2.2.0
|
||||
|
||||
# https://github.com/marketplace/actions/docker-setup-buildx
|
||||
- name: Set up Docker Buildx
|
||||
id: buildx
|
||||
uses: docker/setup-buildx-action@v2.9.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 API
|
||||
uses: docker/build-push-action@v4.1.1
|
||||
with:
|
||||
context: ./
|
||||
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
|
||||
pull: true
|
||||
push: true
|
||||
tags: |
|
||||
glax/tranga-api:latest
|
4
.gitignore
vendored
4
.gitignore
vendored
@ -16,4 +16,6 @@ riderModule.iml
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
/.idea
|
||||
/.idea
|
||||
cover.jpg
|
||||
cover.png
|
15
Dockerfile
Normal file
15
Dockerfile
Normal file
@ -0,0 +1,15 @@
|
||||
# syntax=docker/dockerfile:1
|
||||
|
||||
FROM mcr.microsoft.com/dotnet/sdk:7.0 as build-env
|
||||
WORKDIR /src
|
||||
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
|
||||
WORKDIR /publish
|
||||
COPY --from=build-env /publish .
|
||||
EXPOSE 6531
|
||||
ENTRYPOINT ["dotnet", "/publish/Tranga.dll"]
|
8
Dockerfile-base
Normal file
8
Dockerfile-base
Normal file
@ -0,0 +1,8 @@
|
||||
# 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
|
674
LICENSE.txt
Normal file
674
LICENSE.txt
Normal file
@ -0,0 +1,674 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
31
Logging/FileLogger.cs
Normal file
31
Logging/FileLogger.cs
Normal file
@ -0,0 +1,31 @@
|
||||
using System.Text;
|
||||
|
||||
namespace Logging;
|
||||
|
||||
public class FileLogger : LoggerBase
|
||||
{
|
||||
private string logFilePath { get; }
|
||||
private const int MaxNumberOfLogFiles = 5;
|
||||
|
||||
public FileLogger(string logFilePath, Encoding? encoding = null) : base (encoding)
|
||||
{
|
||||
this.logFilePath = logFilePath;
|
||||
|
||||
//Remove oldest logfile if more than MaxNumberOfLogFiles
|
||||
string parentFolderPath = Path.GetDirectoryName(logFilePath)!;
|
||||
for (int fileCount = new DirectoryInfo(parentFolderPath).EnumerateFiles().Count(); fileCount > MaxNumberOfLogFiles - 1; fileCount--) //-1 because we create own logfile later
|
||||
File.Delete(new DirectoryInfo(parentFolderPath).EnumerateFiles().MinBy(file => file.LastWriteTime)!.FullName);
|
||||
}
|
||||
|
||||
protected override void Write(LogMessage logMessage)
|
||||
{
|
||||
try
|
||||
{
|
||||
File.AppendAllText(logFilePath, logMessage.formattedMessage);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
}
|
||||
}
|
17
Logging/FormattedConsoleLogger.cs
Normal file
17
Logging/FormattedConsoleLogger.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System.Text;
|
||||
|
||||
namespace Logging;
|
||||
|
||||
public class FormattedConsoleLogger : LoggerBase
|
||||
{
|
||||
private readonly TextWriter _stdOut;
|
||||
public FormattedConsoleLogger(TextWriter stdOut, Encoding? encoding = null) : base(encoding)
|
||||
{
|
||||
this._stdOut = stdOut;
|
||||
}
|
||||
|
||||
protected override void Write(LogMessage message)
|
||||
{
|
||||
this._stdOut.Write(message.formattedMessage);
|
||||
}
|
||||
}
|
23
Logging/LogMessage.cs
Normal file
23
Logging/LogMessage.cs
Normal file
@ -0,0 +1,23 @@
|
||||
namespace Logging;
|
||||
|
||||
public class LogMessage
|
||||
{
|
||||
public DateTime logTime { get; }
|
||||
public string caller { get; }
|
||||
public string value { get; }
|
||||
public string formattedMessage => ToString();
|
||||
|
||||
public LogMessage(DateTime messageTime, string caller, string value)
|
||||
{
|
||||
this.logTime = messageTime;
|
||||
this.caller = caller;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string dateTimeString = $"{logTime.ToShortDateString()} {logTime.ToLongTimeString()}.{logTime.Millisecond,-3}";
|
||||
string name = caller.Split(new char[] { '.', '+' }).Last();
|
||||
return $"[{dateTimeString}] {name.Substring(0, name.Length >= 13 ? 13 : name.Length),13} | {value}";
|
||||
}
|
||||
}
|
67
Logging/Logger.cs
Normal file
67
Logging/Logger.cs
Normal file
@ -0,0 +1,67 @@
|
||||
using System.Text;
|
||||
|
||||
namespace Logging;
|
||||
|
||||
public class Logger : TextWriter
|
||||
{
|
||||
public override Encoding Encoding { get; }
|
||||
public enum LoggerType
|
||||
{
|
||||
FileLogger,
|
||||
ConsoleLogger
|
||||
}
|
||||
|
||||
private readonly FileLogger? _fileLogger;
|
||||
private readonly FormattedConsoleLogger? _formattedConsoleLogger;
|
||||
private readonly MemoryLogger _memoryLogger;
|
||||
|
||||
public Logger(LoggerType[] enabledLoggers, TextWriter? stdOut, Encoding? encoding, string? logFilePath)
|
||||
{
|
||||
this.Encoding = encoding ?? Encoding.ASCII;
|
||||
if (enabledLoggers.Contains(LoggerType.FileLogger) && logFilePath is not null)
|
||||
_fileLogger = new FileLogger(logFilePath, encoding);
|
||||
else if(enabledLoggers.Contains(LoggerType.FileLogger) && logFilePath is null)
|
||||
{
|
||||
_fileLogger = null;
|
||||
throw new ArgumentException($"logFilePath can not be null for LoggerType {LoggerType.FileLogger}");
|
||||
}
|
||||
|
||||
if (enabledLoggers.Contains(LoggerType.ConsoleLogger) && stdOut is not null)
|
||||
{
|
||||
_formattedConsoleLogger = new FormattedConsoleLogger(stdOut, encoding);
|
||||
}
|
||||
else if (enabledLoggers.Contains(LoggerType.ConsoleLogger) && stdOut is null)
|
||||
{
|
||||
_formattedConsoleLogger = null;
|
||||
throw new ArgumentException($"stdOut can not be null for LoggerType {LoggerType.ConsoleLogger}");
|
||||
}
|
||||
_memoryLogger = new MemoryLogger(encoding);
|
||||
}
|
||||
|
||||
public void WriteLine(string caller, string? value)
|
||||
{
|
||||
value = value is null ? Environment.NewLine : string.Concat(value, Environment.NewLine);
|
||||
|
||||
Write(caller, value);
|
||||
}
|
||||
|
||||
public void Write(string caller, string? value)
|
||||
{
|
||||
if (value is null)
|
||||
return;
|
||||
|
||||
_fileLogger?.Write(caller, value);
|
||||
_formattedConsoleLogger?.Write(caller, value);
|
||||
_memoryLogger.Write(caller, value);
|
||||
}
|
||||
|
||||
public string[] Tail(uint? lines)
|
||||
{
|
||||
return _memoryLogger.Tail(lines);
|
||||
}
|
||||
|
||||
public string[] GetNewLines()
|
||||
{
|
||||
return _memoryLogger.GetNewLines();
|
||||
}
|
||||
}
|
25
Logging/LoggerBase.cs
Normal file
25
Logging/LoggerBase.cs
Normal file
@ -0,0 +1,25 @@
|
||||
using System.Text;
|
||||
|
||||
namespace Logging;
|
||||
|
||||
public abstract class LoggerBase : TextWriter
|
||||
{
|
||||
public override Encoding Encoding { get; }
|
||||
|
||||
public LoggerBase(Encoding? encoding = null)
|
||||
{
|
||||
this.Encoding = encoding ?? Encoding.ASCII;
|
||||
}
|
||||
|
||||
public void Write(string caller, string? value)
|
||||
{
|
||||
if (value is null)
|
||||
return;
|
||||
|
||||
LogMessage message = new (DateTime.Now, caller, value);
|
||||
|
||||
Write(message);
|
||||
}
|
||||
|
||||
protected abstract void Write(LogMessage message);
|
||||
}
|
9
Logging/Logging.csproj
Normal file
9
Logging/Logging.csproj
Normal file
@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
58
Logging/MemoryLogger.cs
Normal file
58
Logging/MemoryLogger.cs
Normal file
@ -0,0 +1,58 @@
|
||||
using System.Text;
|
||||
|
||||
namespace Logging;
|
||||
|
||||
public class MemoryLogger : LoggerBase
|
||||
{
|
||||
private readonly SortedList<DateTime, LogMessage> _logMessages = new();
|
||||
private int _lastLogMessageIndex = 0;
|
||||
|
||||
public MemoryLogger(Encoding? encoding = null) : base(encoding)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected override void Write(LogMessage value)
|
||||
{
|
||||
while(!_logMessages.TryAdd(value.logTime, value))
|
||||
Thread.Sleep(10);
|
||||
}
|
||||
|
||||
public string[] GetLogMessage()
|
||||
{
|
||||
return Tail(Convert.ToUInt32(_logMessages.Count));
|
||||
}
|
||||
|
||||
public string[] Tail(uint? length)
|
||||
{
|
||||
int retLength;
|
||||
if (length is null || length > _logMessages.Count)
|
||||
retLength = _logMessages.Count;
|
||||
else
|
||||
retLength = (int)length;
|
||||
|
||||
string[] ret = new string[retLength];
|
||||
|
||||
for (int retIndex = 0; retIndex < ret.Length; retIndex++)
|
||||
{
|
||||
ret[retIndex] = _logMessages.GetValueAtIndex(_logMessages.Count - retLength + retIndex).ToString();
|
||||
}
|
||||
|
||||
_lastLogMessageIndex = _logMessages.Count - 1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
public string[] GetNewLines()
|
||||
{
|
||||
int logMessageCount = _logMessages.Count;
|
||||
string[] ret = new string[logMessageCount - _lastLogMessageIndex];
|
||||
|
||||
for (int retIndex = 0; retIndex < ret.Length; retIndex++)
|
||||
{
|
||||
ret[retIndex] = _logMessages.GetValueAtIndex(_lastLogMessageIndex + retIndex).ToString();
|
||||
}
|
||||
|
||||
_lastLogMessageIndex = logMessageCount;
|
||||
return ret;
|
||||
}
|
||||
}
|
191
README.md
191
README.md
@ -1,5 +1,190 @@
|
||||
Has a interactive CLI-Version as well as API-Version (no documentation of API yet).
|
||||
<!-- PROJECT SHIELDS -->
|
||||
<!--
|
||||
*** I'm using markdown "reference style" links for readability.
|
||||
*** Reference links are enclosed in brackets [ ] instead of parentheses ( ).
|
||||
*** See the bottom of this document for the declaration of the reference variables
|
||||
*** for contributors-url, forks-url, etc. This is an optional, concise syntax you may use.
|
||||
*** https://www.markdownguide.org/basic-syntax/#reference-style-links
|
||||
-->
|
||||
|
||||
Only one Connector so far: MangaDex.org (Timeout between requests 750ms)
|
||||
<!-- PROJECT LOGO -->
|
||||
<br />
|
||||
<div align="center">
|
||||
|
||||
Can automatically download new Chapters every given time-period.
|
||||
<h3 align="center">Tranga</h3>
|
||||
|
||||
<p align="center">
|
||||
Automatic Manga and Metadata downloader
|
||||
</p>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<!-- TABLE OF CONTENTS -->
|
||||
<details>
|
||||
<summary>Table of Contents</summary>
|
||||
<ol>
|
||||
<li>
|
||||
<a href="#about-the-project">About The Project</a>
|
||||
<ul>
|
||||
<li><a href="#built-with">Built With</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
<a href="#screenshots">Screenshots</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="#getting-started">Getting Started</a>
|
||||
<ul>
|
||||
<li><a href="#prerequisites">Usage</a></li>
|
||||
<li><a href="#prerequisites">Prerequisites</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="#roadmap">Roadmap</a></li>
|
||||
<li><a href="#contributing">Contributing</a></li>
|
||||
<li><a href="#license">License</a></li>
|
||||
<li><a href="#acknowledgments">Acknowledgments</a></li>
|
||||
</ol>
|
||||
</details>
|
||||
|
||||
|
||||
|
||||
<!-- ABOUT THE PROJECT -->
|
||||
## About The Project
|
||||
|
||||
Tranga can download Chapters and Metadata from "Scanlation" sites such as
|
||||
|
||||
- [MangaDex.org](https://mangadex.org/)
|
||||
- [Manganato.com](https://manganato.com/)
|
||||
- [Mangasee](https://mangasee123.com/)
|
||||
- [MangaKatana](https://mangakatana.com)
|
||||
- ❓ Open an [issue](https://github.com/C9Glax/tranga/issues)
|
||||
|
||||
and automatically import them with [Komga](https://komga.org/) and [Kavita](https://www.kavitareader.com/). Also Notifications will be sent to your devices using [Gotify](https://gotify.net/) and [LunaSea](https://www.lunasea.app/).
|
||||
### Inspiration:
|
||||
|
||||
Because [Kaizoku](https://github.com/oae/kaizoku) was relying on [mangal](https://github.com/metafates/mangal) and mangal
|
||||
hasn't received bugfixes for it's issues with Titles not showing up, or throwing errors because of illegal characters,
|
||||
there were no alternatives for automatic downloads. However [Kaizoku](https://github.com/oae/kaizoku) certainly had a great Web-UI.
|
||||
|
||||
That is why I wanted to create my own project, in a language I understand, and that I am able to maintain myself.
|
||||
|
||||
<p align="right">(<a href="#readme-top">back to top</a>)</p>
|
||||
|
||||
### Built With
|
||||
|
||||
- .NET-Core
|
||||
- Newtonsoft.JSON
|
||||
- [PuppeteerSharp](https://www.puppeteersharp.com/)
|
||||
- [Html Agility Pack (HAP)](https://html-agility-pack.net/)
|
||||
- 💙 Blåhaj 🦈
|
||||
|
||||
<p align="right">(<a href="#readme-top">back to top</a>)</p>
|
||||
|
||||
|
||||
## Screenshots
|
||||
|
||||
|  |  |
|
||||
|-----------------------------------:|:----------------------------------|
|
||||
|
||||
|  |  |  |
|
||||
|-----------------------------------:|:-------------------------------------------------:|:-----------------------------------|
|
||||
|
||||
<p align="right">(<a href="#readme-top">back to top</a>)</p>
|
||||
|
||||
<!-- GETTING STARTED -->
|
||||
## Getting Started
|
||||
|
||||
There is two release types:
|
||||
|
||||
- CLI
|
||||
- Docker
|
||||
|
||||
### CLI
|
||||
|
||||
Head over to [releases](https://git.bernloehr.eu/glax/Tranga/releases) and download. The CLI will guide you through setup.
|
||||
|
||||
### Docker
|
||||
|
||||
Download [docker-compose.yaml](https://git.bernloehr.eu/glax/Tranga/src/branch/master/docker-compose.yaml) and configure to your needs.
|
||||
|
||||
Wherever you are mounting `/usr/share/Tranga-API` you also need to mount that same path + `/imageCache` in the webserver container.
|
||||
|
||||
### Docker-Website usage
|
||||
|
||||
There is two ways to download Mangas:
|
||||
- Downloading everything and monitor for new Chapters
|
||||
- Selecting specific Volumes/Chapters
|
||||
|
||||
On the website you add new tasks, by selecting the blue '+' field. Next select the connector/site you want to use, and enter a search term.
|
||||
After clicking 'Search' (or pressing Enter), the results will be presented below - this might, depending on the result-size, take a while because we are already preloading the cover-images.
|
||||
Next select the publication (by selecting the cover) and a new popup will open with two options:
|
||||
- "Monitor" - Download all chapters and monitor for new ones
|
||||
- "Download Chapter" - Download specific chapters only
|
||||
|
||||
When selecting `Monitor` you will be presented with a new window and the selection of the interval you want to check for new chapters (Default: Every 3 hours).
|
||||
When selecting `Download Chapter` a list will open with all available chapters - that have not yet been downloaded - from which you can then select a range (see below).
|
||||
|
||||
The syntax for selecting chapters is as follows:
|
||||
- To download a single Chapter enter either the index number (the number at the very start of the line) or its absolute number like so: `c(h)(apter)[number]`, spaces are allowed.
|
||||
- To download a range of chapters enter either a range of index numbers (`3-6`) or chapters (`ch 12-23`).
|
||||
- For volumes the syntax is as follows: `v(ol)[number](-[number])`, again spaces allowed.
|
||||
|
||||
Examples: `2-12`, `c1`, `ch 2`, `chapter 3`, `v 2`, `vol3-4`, `v2c4` (note: you can only specify a single chapter with this last syntax).
|
||||
|
||||
### Prerequisites
|
||||
|
||||
#### To Build
|
||||
[.NET-Core 7.0 SDK](https://dotnet.microsoft.com/en-us/download/dotnet/7.0)
|
||||
#### To Run
|
||||
[.NET-Core 7.0 Runtime](https://dotnet.microsoft.com/en-us/download/dotnet/7.0) scroll down a bit, should be on the right the second item.
|
||||
|
||||
<!-- ROADMAP -->
|
||||
## Roadmap
|
||||
|
||||
- [ ] Docker ARM support
|
||||
- [ ] ❓
|
||||
|
||||
See the [open issues](https://github.com/C9Glax/tranga/issues) for a full list of proposed features (and known issues).
|
||||
|
||||
<p align="right">(<a href="#readme-top">back to top</a>)</p>
|
||||
|
||||
|
||||
|
||||
<!-- CONTRIBUTING -->
|
||||
## Contributing
|
||||
|
||||
The following is copy & pasted:
|
||||
|
||||
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**.
|
||||
|
||||
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement".
|
||||
Don't forget to give the project a star! Thanks again!
|
||||
|
||||
1. Fork the Project
|
||||
2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)
|
||||
3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)
|
||||
4. Push to the Branch (`git push origin feature/AmazingFeature`)
|
||||
5. Open a Pull Request
|
||||
|
||||
<p align="right">(<a href="#readme-top">back to top</a>)</p>
|
||||
|
||||
|
||||
|
||||
<!-- LICENSE -->
|
||||
## License
|
||||
|
||||
Distributed under the GNU GPLv3 License. See `LICENSE.txt` for more information.
|
||||
|
||||
<p align="right">(<a href="#readme-top">back to top</a>)</p>
|
||||
|
||||
|
||||
|
||||
<!-- ACKNOWLEDGMENTS -->
|
||||
## Acknowledgments
|
||||
|
||||
* [Choose an Open Source License](https://choosealicense.com)
|
||||
* [Font Awesome](https://fontawesome.com)
|
||||
* [Best-README-Template](https://github.com/othneildrew/Best-README-Template/tree/master)
|
||||
|
||||
<p align="right">(<a href="#readme-top">back to top</a>)</p>
|
||||
|
@ -1,20 +0,0 @@
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
|
||||
WORKDIR /app
|
||||
EXPOSE 80
|
||||
EXPOSE 443
|
||||
|
||||
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
|
||||
WORKDIR /src
|
||||
COPY ["Tranga-API/Tranga-API.csproj", "Tranga-API/"]
|
||||
RUN dotnet restore "Tranga-API/Tranga-API.csproj"
|
||||
COPY . .
|
||||
WORKDIR "/src/Tranga-API"
|
||||
RUN dotnet build "Tranga-API.csproj" -c Release -o /app/build
|
||||
|
||||
FROM build AS publish
|
||||
RUN dotnet publish "Tranga-API.csproj" -c Release -o /app/publish /p:UseAppHost=false
|
||||
|
||||
FROM base AS final
|
||||
WORKDIR /app
|
||||
COPY --from=publish /app/publish .
|
||||
ENTRYPOINT ["dotnet", "Tranga-API.dll"]
|
@ -1,49 +0,0 @@
|
||||
using System.Text.Json;
|
||||
using Tranga;
|
||||
using Tranga.Connectors;
|
||||
|
||||
TaskManager taskManager = new TaskManager(Directory.GetCurrentDirectory());
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
var app = builder.Build();
|
||||
|
||||
app.MapGet("/GetConnectors", () => JsonSerializer.Serialize(taskManager.GetAvailableConnectors().Values.ToArray()));
|
||||
|
||||
app.MapGet("/GetPublications", (string connectorName, string? title) =>
|
||||
{
|
||||
Connector connector = taskManager.GetConnector(connectorName);
|
||||
|
||||
Publication[] publications;
|
||||
if (title is not null)
|
||||
publications = connector.GetPublications(title);
|
||||
else
|
||||
publications = connector.GetPublications();
|
||||
|
||||
return JsonSerializer.Serialize(publications);
|
||||
});
|
||||
|
||||
app.MapGet("/ListTasks", () => JsonSerializer.Serialize(taskManager.GetAllTasks()));
|
||||
|
||||
app.MapGet("/CreateTask",
|
||||
(TrangaTask.Task task, string connectorName, string? publicationName, TimeSpan reoccurrence, string language) =>
|
||||
{
|
||||
Publication? publication =
|
||||
taskManager.GetAllPublications().FirstOrDefault(pub => pub.downloadUrl == publicationName);
|
||||
if (publication is null)
|
||||
JsonSerializer.Serialize($"Publication {publicationName} is unknown.");
|
||||
|
||||
taskManager.AddTask(task, connectorName, publication, reoccurrence, language);
|
||||
JsonSerializer.Serialize("Success");
|
||||
});
|
||||
|
||||
app.MapGet("/RemoveTask", (TrangaTask.Task task, string connector, string? publicationName) =>
|
||||
{
|
||||
Publication? publication =
|
||||
taskManager.GetAllPublications().FirstOrDefault(pub => pub.downloadUrl == publicationName);
|
||||
if (publication is null)
|
||||
JsonSerializer.Serialize($"Publication {publicationName} is unknown.");
|
||||
|
||||
taskManager.RemoveTask(task, connector, publication);
|
||||
JsonSerializer.Serialize("Success");
|
||||
});
|
||||
|
||||
app.Run();
|
@ -1,37 +0,0 @@
|
||||
{
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:14826",
|
||||
"sslPort": 44333
|
||||
}
|
||||
},
|
||||
"profiles": {
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"applicationUrl": "http://localhost:5119",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"applicationUrl": "https://localhost:7070;http://localhost:5119",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<RootNamespace>Tranga_API</RootNamespace>
|
||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="..\.dockerignore">
|
||||
<Link>.dockerignore</Link>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Tranga\Tranga.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -1,8 +0,0 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
@ -1 +0,0 @@
|
||||
[{"reoccurrence":"00:00:00","lastExecuted":"2023-05-19T17:34:40.5349215+02:00","connectorName":"MangaDex","task":0,"publication":{"sortName":null,"description":null,"tags":null,"posterUrl":null,"year":null,"originalLanguage":null,"status":null,"folderName":null,"downloadUrl":null},"language":"en"}]
|
@ -1,18 +0,0 @@
|
||||
FROM mcr.microsoft.com/dotnet/runtime:7.0 AS base
|
||||
WORKDIR /app
|
||||
|
||||
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
|
||||
WORKDIR /src
|
||||
COPY ["Tranga-CLI/Tranga-CLI.csproj", "Tranga-CLI/"]
|
||||
RUN dotnet restore "Tranga-CLI/Tranga-CLI.csproj"
|
||||
COPY . .
|
||||
WORKDIR "/src/Tranga-CLI"
|
||||
RUN dotnet build "Tranga-CLI.csproj" -c Release -o /app/build
|
||||
|
||||
FROM build AS publish
|
||||
RUN dotnet publish "Tranga-CLI.csproj" -c Release -o /app/publish /p:UseAppHost=false
|
||||
|
||||
FROM base AS final
|
||||
WORKDIR /app
|
||||
COPY --from=publish /app/publish .
|
||||
ENTRYPOINT ["dotnet", "Tranga-CLI.dll"]
|
@ -1,22 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<RootNamespace>Tranga_CLI</RootNamespace>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="..\.dockerignore">
|
||||
<Link>.dockerignore</Link>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Tranga\Tranga.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -1,389 +0,0 @@
|
||||
using System.Globalization;
|
||||
using Tranga;
|
||||
using Tranga.Connectors;
|
||||
|
||||
namespace Tranga_CLI;
|
||||
|
||||
/*
|
||||
* This is written with pure hatred for readability.
|
||||
* At some point do this properly.
|
||||
* Read at own risk.
|
||||
*/
|
||||
|
||||
public static class Tranga_Cli
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
TaskManager.SettingsData settings;
|
||||
string settingsPath = Path.Join(Directory.GetCurrentDirectory(), "data.json");
|
||||
if (File.Exists(settingsPath))
|
||||
settings = TaskManager.LoadData(Directory.GetCurrentDirectory());
|
||||
else
|
||||
settings = new TaskManager.SettingsData(Directory.GetCurrentDirectory(), null, new HashSet<TrangaTask>());
|
||||
|
||||
|
||||
Console.WriteLine($"Output folder path [{settings.downloadLocation}]:");
|
||||
string? tmpPath = Console.ReadLine();
|
||||
while(tmpPath is null)
|
||||
tmpPath = Console.ReadLine();
|
||||
if(tmpPath.Length > 0)
|
||||
settings.downloadLocation = tmpPath;
|
||||
|
||||
Console.WriteLine($"Komga BaseURL [{settings.komga?.baseUrl}]:");
|
||||
string? tmpUrl = Console.ReadLine();
|
||||
while (tmpUrl is null)
|
||||
tmpUrl = Console.ReadLine();
|
||||
if (tmpUrl.Length > 0)
|
||||
{
|
||||
Console.WriteLine("Username:");
|
||||
string? tmpUser = Console.ReadLine();
|
||||
while (tmpUser is null || tmpUser.Length < 1)
|
||||
tmpUser = Console.ReadLine();
|
||||
|
||||
Console.WriteLine("Password:");
|
||||
string tmpPass = string.Empty;
|
||||
ConsoleKey key;
|
||||
do
|
||||
{
|
||||
var keyInfo = Console.ReadKey(intercept: true);
|
||||
key = keyInfo.Key;
|
||||
|
||||
if (key == ConsoleKey.Backspace && tmpPass.Length > 0)
|
||||
{
|
||||
Console.Write("\b \b");
|
||||
tmpPass = tmpPass[0..^1];
|
||||
}
|
||||
else if (!char.IsControl(keyInfo.KeyChar))
|
||||
{
|
||||
Console.Write("*");
|
||||
tmpPass += keyInfo.KeyChar;
|
||||
}
|
||||
} while (key != ConsoleKey.Enter);
|
||||
|
||||
settings.komga = new Komga(tmpUrl, tmpUser, tmpPass);
|
||||
}
|
||||
|
||||
//For now only TaskManager mode
|
||||
/*
|
||||
Console.Write("Mode (D: Interactive only, T: TaskManager):");
|
||||
ConsoleKeyInfo mode = Console.ReadKey();
|
||||
while (mode.Key != ConsoleKey.D && mode.Key != ConsoleKey.T)
|
||||
mode = Console.ReadKey();
|
||||
Console.WriteLine();
|
||||
|
||||
if(mode.Key == ConsoleKey.D)
|
||||
DownloadNow(settings);
|
||||
else if (mode.Key == ConsoleKey.T)
|
||||
TaskMode(settings);*/
|
||||
TaskMode(settings);
|
||||
}
|
||||
|
||||
private static void TaskMode(TaskManager.SettingsData settings)
|
||||
{
|
||||
TaskManager taskManager = new TaskManager(settings);
|
||||
ConsoleKey selection = ConsoleKey.NoName;
|
||||
int menu = 0;
|
||||
while (selection != ConsoleKey.Escape && selection != ConsoleKey.Q)
|
||||
{
|
||||
switch (menu)
|
||||
{
|
||||
case 1:
|
||||
PrintTasks(taskManager.GetAllTasks());
|
||||
Console.WriteLine("Press any key.");
|
||||
Console.ReadKey();
|
||||
menu = 0;
|
||||
break;
|
||||
case 2:
|
||||
TrangaTask.Task task = SelectTask();
|
||||
|
||||
Connector? connector = null;
|
||||
if(task != TrangaTask.Task.UpdateKomgaLibrary)
|
||||
connector = SelectConnector(settings.downloadLocation, taskManager.GetAvailableConnectors().Values.ToArray());
|
||||
|
||||
Publication? publication = null;
|
||||
if(task != TrangaTask.Task.UpdatePublications && task != TrangaTask.Task.UpdateKomgaLibrary)
|
||||
publication = SelectPublication(connector!);
|
||||
|
||||
TimeSpan reoccurrence = SelectReoccurrence();
|
||||
TrangaTask newTask = taskManager.AddTask(task, connector?.name, publication, reoccurrence, "en");
|
||||
Console.WriteLine(newTask);
|
||||
Console.WriteLine("Press any key.");
|
||||
Console.ReadKey();
|
||||
menu = 0;
|
||||
break;
|
||||
case 3:
|
||||
RemoveTask(taskManager);
|
||||
Console.WriteLine("Press any key.");
|
||||
Console.ReadKey();
|
||||
menu = 0;
|
||||
break;
|
||||
case 4:
|
||||
ExecuteTaskNow(taskManager);
|
||||
Console.WriteLine("Press any key.");
|
||||
Console.ReadKey();
|
||||
menu = 0;
|
||||
break;
|
||||
case 5:
|
||||
Console.WriteLine("Search-Query (Name):");
|
||||
string? query = Console.ReadLine();
|
||||
while (query is null || query.Length < 1)
|
||||
query = Console.ReadLine();
|
||||
PrintTasks(taskManager.GetAllTasks().Where(qTask =>
|
||||
qTask.ToString().ToLower().Contains(query, StringComparison.OrdinalIgnoreCase)).ToArray());
|
||||
Console.WriteLine("Press any key.");
|
||||
Console.ReadKey();
|
||||
menu = 0;
|
||||
break;
|
||||
case 6:
|
||||
PrintTasks(taskManager.GetAllTasks().Where(eTask => eTask.state == TrangaTask.ExecutionState.Running).ToArray());
|
||||
Console.WriteLine("Press any key.");
|
||||
Console.ReadKey();
|
||||
menu = 0;
|
||||
break;
|
||||
default:
|
||||
selection = Menu(taskManager, settings.downloadLocation);
|
||||
switch (selection)
|
||||
{
|
||||
case ConsoleKey.L:
|
||||
menu = 1;
|
||||
break;
|
||||
case ConsoleKey.C:
|
||||
menu = 2;
|
||||
break;
|
||||
case ConsoleKey.D:
|
||||
menu = 3;
|
||||
break;
|
||||
case ConsoleKey.E:
|
||||
menu = 4;
|
||||
break;
|
||||
case ConsoleKey.U:
|
||||
menu = 0;
|
||||
break;
|
||||
case ConsoleKey.S:
|
||||
menu = 5;
|
||||
break;
|
||||
case ConsoleKey.R:
|
||||
menu = 6;
|
||||
break;
|
||||
default:
|
||||
menu = 0;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (taskManager.GetAllTasks().Any(task => task.state == TrangaTask.ExecutionState.Running))
|
||||
{
|
||||
Console.WriteLine("Force quit (Even with running tasks?) y/N");
|
||||
selection = Console.ReadKey().Key;
|
||||
while(selection != ConsoleKey.Y && selection != ConsoleKey.N)
|
||||
selection = Console.ReadKey().Key;
|
||||
taskManager.Shutdown(selection == ConsoleKey.Y);
|
||||
}else
|
||||
// ReSharper disable once RedundantArgumentDefaultValue Better readability
|
||||
taskManager.Shutdown(false);
|
||||
}
|
||||
|
||||
private static ConsoleKey Menu(TaskManager taskManager, string folderPath)
|
||||
{
|
||||
int taskCount = taskManager.GetAllTasks().Length;
|
||||
int taskRunningCount = taskManager.GetAllTasks().Count(task => task.state == TrangaTask.ExecutionState.Running);
|
||||
int taskEnqueuedCount =
|
||||
taskManager.GetAllTasks().Count(task => task.state == TrangaTask.ExecutionState.Enqueued);
|
||||
Console.Clear();
|
||||
Console.WriteLine($"Download Folder: {folderPath} Tasks (Running/Queue/Total): {taskRunningCount}/{taskEnqueuedCount}/{taskCount}");
|
||||
Console.WriteLine("U: Update this Screen");
|
||||
Console.WriteLine("L: List tasks");
|
||||
Console.WriteLine("C: Create Task");
|
||||
Console.WriteLine("D: Delete Task");
|
||||
Console.WriteLine("E: Execute Task now");
|
||||
Console.WriteLine("S: Search Task");
|
||||
Console.WriteLine("R: Running Tasks");
|
||||
Console.WriteLine("Q: Exit");
|
||||
ConsoleKey selection = Console.ReadKey().Key;
|
||||
Console.WriteLine();
|
||||
return selection;
|
||||
}
|
||||
|
||||
private static void PrintTasks(TrangaTask[] tasks)
|
||||
{
|
||||
int taskCount = tasks.Length;
|
||||
int taskRunningCount = tasks.Count(task => task.state == TrangaTask.ExecutionState.Running);
|
||||
int taskEnqueuedCount = tasks.Count(task => task.state == TrangaTask.ExecutionState.Enqueued);
|
||||
Console.Clear();
|
||||
int tIndex = 0;
|
||||
Console.WriteLine($"Tasks (Running/Queue/Total): {taskRunningCount}/{taskEnqueuedCount}/{taskCount}");
|
||||
foreach(TrangaTask trangaTask in tasks)
|
||||
Console.WriteLine($"{tIndex++:000}: {trangaTask}");
|
||||
}
|
||||
|
||||
private static void ExecuteTaskNow(TaskManager taskManager)
|
||||
{
|
||||
TrangaTask[] tasks = taskManager.GetAllTasks();
|
||||
if (tasks.Length < 1)
|
||||
{
|
||||
Console.Clear();
|
||||
Console.WriteLine("There are no available Tasks.");
|
||||
return;
|
||||
}
|
||||
PrintTasks(tasks);
|
||||
|
||||
Console.WriteLine($"Select Task (0-{tasks.Length - 1}):");
|
||||
|
||||
string? selectedTask = Console.ReadLine();
|
||||
while(selectedTask is null || selectedTask.Length < 1)
|
||||
selectedTask = Console.ReadLine();
|
||||
int selectedTaskIndex = Convert.ToInt32(selectedTask);
|
||||
|
||||
taskManager.ExecuteTaskNow(tasks[selectedTaskIndex]);
|
||||
}
|
||||
|
||||
private static void RemoveTask(TaskManager taskManager)
|
||||
{
|
||||
TrangaTask[] tasks = taskManager.GetAllTasks();
|
||||
if (tasks.Length < 1)
|
||||
{
|
||||
Console.Clear();
|
||||
Console.WriteLine("There are no available Tasks.");
|
||||
return;
|
||||
}
|
||||
PrintTasks(tasks);
|
||||
|
||||
Console.WriteLine($"Select Task (0-{tasks.Length - 1}):");
|
||||
|
||||
string? selectedTask = Console.ReadLine();
|
||||
while(selectedTask is null || selectedTask.Length < 1)
|
||||
selectedTask = Console.ReadLine();
|
||||
int selectedTaskIndex = Convert.ToInt32(selectedTask);
|
||||
|
||||
taskManager.RemoveTask(tasks[selectedTaskIndex].task, tasks[selectedTaskIndex].connectorName, tasks[selectedTaskIndex].publication);
|
||||
}
|
||||
|
||||
private static TrangaTask.Task SelectTask()
|
||||
{
|
||||
Console.Clear();
|
||||
string[] taskNames = Enum.GetNames<TrangaTask.Task>();
|
||||
|
||||
int tIndex = 0;
|
||||
Console.WriteLine("Available Tasks:");
|
||||
foreach (string taskName in taskNames)
|
||||
Console.WriteLine($"{tIndex++}: {taskName}");
|
||||
Console.WriteLine($"Select Task (0-{taskNames.Length - 1}):");
|
||||
|
||||
string? selectedTask = Console.ReadLine();
|
||||
while(selectedTask is null || selectedTask.Length < 1)
|
||||
selectedTask = Console.ReadLine();
|
||||
int selectedTaskIndex = Convert.ToInt32(selectedTask);
|
||||
|
||||
string selectedTaskName = taskNames[selectedTaskIndex];
|
||||
return Enum.Parse<TrangaTask.Task>(selectedTaskName);
|
||||
}
|
||||
|
||||
private static TimeSpan SelectReoccurrence()
|
||||
{
|
||||
Console.WriteLine("Select reoccurrence Timer (Format hh:mm:ss):");
|
||||
return TimeSpan.Parse(Console.ReadLine()!, new CultureInfo("en-US"));
|
||||
}
|
||||
|
||||
private static void DownloadNow(TaskManager.SettingsData settings)
|
||||
{
|
||||
Connector connector = SelectConnector(settings.downloadLocation, new Connector[]{new MangaDex(settings.downloadLocation)});
|
||||
|
||||
Publication publication = SelectPublication(connector);
|
||||
|
||||
Chapter[] downloadChapters = SelectChapters(connector, publication);
|
||||
|
||||
if (downloadChapters.Length > 0)
|
||||
{
|
||||
connector.DownloadCover(publication);
|
||||
connector.SaveSeriesInfo(publication);
|
||||
}
|
||||
|
||||
foreach (Chapter chapter in downloadChapters)
|
||||
{
|
||||
Console.WriteLine($"Downloading {publication.sortName} V{chapter.volumeNumber}C{chapter.chapterNumber}");
|
||||
connector.DownloadChapter(publication, chapter);
|
||||
}
|
||||
}
|
||||
|
||||
private static Connector SelectConnector(string folderPath, Connector[] connectors)
|
||||
{
|
||||
Console.Clear();
|
||||
|
||||
int cIndex = 0;
|
||||
Console.WriteLine("Connectors:");
|
||||
foreach (Connector connector in connectors)
|
||||
Console.WriteLine($"{cIndex++}: {connector.name}");
|
||||
Console.WriteLine($"Select Connector (0-{connectors.Length - 1}):");
|
||||
|
||||
string? selectedConnector = Console.ReadLine();
|
||||
while(selectedConnector is null || selectedConnector.Length < 1)
|
||||
selectedConnector = Console.ReadLine();
|
||||
int selectedConnectorIndex = Convert.ToInt32(selectedConnector);
|
||||
|
||||
return connectors[selectedConnectorIndex];
|
||||
}
|
||||
|
||||
private static Publication SelectPublication(Connector connector)
|
||||
{
|
||||
Console.Clear();
|
||||
Console.WriteLine($"Connector: {connector.name}");
|
||||
Console.WriteLine("Publication search query (leave empty for all):");
|
||||
string? query = Console.ReadLine();
|
||||
|
||||
Publication[] publications = connector.GetPublications(query ?? "");
|
||||
|
||||
int pIndex = 0;
|
||||
Console.WriteLine("Publications:");
|
||||
foreach(Publication publication in publications)
|
||||
Console.WriteLine($"{pIndex++}: {publication.sortName}");
|
||||
Console.WriteLine($"Select publication to Download (0-{publications.Length - 1}):");
|
||||
|
||||
string? selected = Console.ReadLine();
|
||||
while(selected is null || selected.Length < 1)
|
||||
selected = Console.ReadLine();
|
||||
return publications[Convert.ToInt32(selected)];
|
||||
}
|
||||
|
||||
private static Chapter[] SelectChapters(Connector connector, Publication publication)
|
||||
{
|
||||
Console.Clear();
|
||||
Console.WriteLine($"Connector: {connector.name} Publication: {publication.sortName}");
|
||||
Chapter[] chapters = connector.GetChapters(publication, "en");
|
||||
|
||||
int cIndex = 0;
|
||||
Console.WriteLine("Chapters:");
|
||||
foreach (Chapter ch in chapters)
|
||||
{
|
||||
string name = cIndex.ToString();
|
||||
if (ch.name is not null && ch.name.Length > 0)
|
||||
name = ch.name;
|
||||
else if (ch.chapterNumber is not null && ch.chapterNumber.Length > 0)
|
||||
name = ch.chapterNumber;
|
||||
Console.WriteLine($"{cIndex++}: {name}");
|
||||
}
|
||||
Console.WriteLine($"Select Chapters to download (0-{chapters.Length - 1}) [range x-y or 'a' for all]: ");
|
||||
string? selected = Console.ReadLine();
|
||||
while(selected is null || selected.Length < 1)
|
||||
selected = Console.ReadLine();
|
||||
|
||||
int start = 0;
|
||||
int end;
|
||||
if (selected == "a")
|
||||
end = chapters.Length - 1;
|
||||
else if (selected.Contains('-'))
|
||||
{
|
||||
string[] split = selected.Split('-');
|
||||
start = Convert.ToInt32(split[0]);
|
||||
end = Convert.ToInt32(split[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
start = Convert.ToInt32(selected);
|
||||
end = Convert.ToInt32(selected);
|
||||
}
|
||||
|
||||
return chapters.Skip(start).Take((end + 1)-start).ToArray();
|
||||
}
|
||||
}
|
16
Tranga.sln
16
Tranga.sln
@ -2,9 +2,7 @@
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tranga", ".\Tranga\Tranga.csproj", "{545E81B9-D96B-4C8F-A97F-2C02414DE566}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tranga-CLI", "Tranga-CLI\Tranga-CLI.csproj", "{4899E3B2-B259-479A-B43E-042D043E9501}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tranga-API", "Tranga-API\Tranga-API.csproj", "{6284C936-4E90-486B-BC46-0AFAD85AD8EE}"
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Logging", "Logging\Logging.csproj", "{415BE889-BB7D-426F-976F-8D977876A462}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@ -16,13 +14,9 @@ Global
|
||||
{545E81B9-D96B-4C8F-A97F-2C02414DE566}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{545E81B9-D96B-4C8F-A97F-2C02414DE566}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{545E81B9-D96B-4C8F-A97F-2C02414DE566}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{4899E3B2-B259-479A-B43E-042D043E9501}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{4899E3B2-B259-479A-B43E-042D043E9501}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{4899E3B2-B259-479A-B43E-042D043E9501}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{4899E3B2-B259-479A-B43E-042D043E9501}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{6284C936-4E90-486B-BC46-0AFAD85AD8EE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{6284C936-4E90-486B-BC46-0AFAD85AD8EE}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{6284C936-4E90-486B-BC46-0AFAD85AD8EE}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{6284C936-4E90-486B-BC46-0AFAD85AD8EE}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{415BE889-BB7D-426F-976F-8D977876A462}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{415BE889-BB7D-426F-976F-8D977876A462}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{415BE889-BB7D-426F-976F-8D977876A462}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{415BE889-BB7D-426F-976F-8D977876A462}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
@ -1,3 +1,10 @@
|
||||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=altnames/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=authorsartists/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Gotify/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Komga/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=mangakatana/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Manganato/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Mangasee/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Taskmanager/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Tranga/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
@ -1,4 +1,5 @@
|
||||
using System.Globalization;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Tranga;
|
||||
|
||||
@ -6,28 +7,84 @@ namespace Tranga;
|
||||
/// Has to be Part of a publication
|
||||
/// Includes the Chapter-Name, -VolumeNumber, -ChapterNumber, the location of the chapter on the internet and the saveName of the local file.
|
||||
/// </summary>
|
||||
public struct Chapter
|
||||
public readonly struct Chapter
|
||||
{
|
||||
// ReSharper disable once MemberCanBePrivate.Global
|
||||
public Publication parentPublication { get; }
|
||||
public string? name { get; }
|
||||
public string? volumeNumber { get; }
|
||||
public string? chapterNumber { get; }
|
||||
public string chapterNumber { get; }
|
||||
public string url { get; }
|
||||
// ReSharper disable once MemberCanBePrivate.Global
|
||||
public string fileName { get; }
|
||||
public string sortNumber { get; }
|
||||
|
||||
public Chapter(string? name, string? volumeNumber, string? chapterNumber, string url)
|
||||
|
||||
private static readonly Regex LegalCharacters = new (@"([A-z]*[0-9]* *\.*-*,*\]*\[*'*\'*\)*\(*~*!*)*");
|
||||
private static readonly Regex IllegalStrings = new(@"Vol(ume)?.?", RegexOptions.IgnoreCase);
|
||||
public Chapter(Publication parentPublication, string? name, string? volumeNumber, string chapterNumber, string url)
|
||||
{
|
||||
this.parentPublication = parentPublication;
|
||||
this.name = name;
|
||||
this.volumeNumber = volumeNumber is { Length: > 0 } ? volumeNumber : "1";
|
||||
this.volumeNumber = volumeNumber;
|
||||
this.chapterNumber = chapterNumber;
|
||||
this.url = url;
|
||||
string chapterName = string.Concat((name ?? "").Split(Path.GetInvalidFileNameChars()));
|
||||
NumberFormatInfo nfi = new NumberFormatInfo()
|
||||
|
||||
string chapterName = string.Concat(LegalCharacters.Matches(name ?? ""));
|
||||
string volStr = this.volumeNumber is not null ? $"Vol.{this.volumeNumber} " : "";
|
||||
string chNumberStr = $"Ch.{chapterNumber} ";
|
||||
string chNameStr = chapterName.Length > 0 ? $"- {chapterName}" : "";
|
||||
chNameStr = IllegalStrings.Replace(chNameStr, "");
|
||||
this.fileName = $"{volStr}{chNumberStr}{chNameStr}";
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a chapter-archive is already present
|
||||
/// </summary>
|
||||
/// <returns>true if chapter is present</returns>
|
||||
internal bool CheckChapterIsDownloaded(string downloadLocation)
|
||||
{
|
||||
string newFilePath = GetArchiveFilePath(downloadLocation);
|
||||
if (!Directory.Exists(Path.Join(downloadLocation, parentPublication.folderName)))
|
||||
return false;
|
||||
FileInfo[] archives = new DirectoryInfo(Path.Join(downloadLocation, parentPublication.folderName)).GetFiles();
|
||||
Regex chapterInfoRex = new(@"Ch\.[0-9.]+");
|
||||
Regex chapterRex = new(@"[0-9]+(\.[0-9]+)?");
|
||||
|
||||
if (File.Exists(newFilePath))
|
||||
return true;
|
||||
|
||||
string cn = this.chapterNumber;
|
||||
if (archives.FirstOrDefault(archive => chapterRex.Match(chapterInfoRex.Match(archive.Name).Value).Value == cn) is { } path)
|
||||
{
|
||||
NumberDecimalSeparator = "."
|
||||
};
|
||||
sortNumber = decimal.Round(Convert.ToDecimal(this.volumeNumber) * Convert.ToDecimal(this.chapterNumber, nfi), 1)
|
||||
.ToString(nfi);
|
||||
this.fileName = $"{chapterName} - V{volumeNumber}C{chapterNumber} - {sortNumber}";
|
||||
File.Move(path.FullName, newFilePath);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/// <summary>
|
||||
/// Creates full file path of chapter-archive
|
||||
/// </summary>
|
||||
/// <returns>Filepath</returns>
|
||||
internal string GetArchiveFilePath(string downloadLocation)
|
||||
{
|
||||
return Path.Join(downloadLocation, parentPublication.folderName, $"{parentPublication.folderName} - {this.fileName}.cbz");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a string containing XML of publication and chapter.
|
||||
/// See ComicInfo.xml
|
||||
/// </summary>
|
||||
/// <returns>XML-string</returns>
|
||||
internal string GetComicInfoXmlString()
|
||||
{
|
||||
XElement comicInfo = new XElement("ComicInfo",
|
||||
new XElement("Tags", string.Join(',', parentPublication.tags)),
|
||||
new XElement("LanguageISO", parentPublication.originalLanguage),
|
||||
new XElement("Title", this.name),
|
||||
new XElement("Writer", string.Join(',', parentPublication.authors)),
|
||||
new XElement("Volume", this.volumeNumber),
|
||||
new XElement("Number", this.chapterNumber)
|
||||
);
|
||||
return comicInfo.ToString();
|
||||
}
|
||||
}
|
@ -1,204 +0,0 @@
|
||||
using System.IO.Compression;
|
||||
using System.Net;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Tranga;
|
||||
|
||||
/// <summary>
|
||||
/// Base-Class for all Connectors
|
||||
/// Provides some methods to be used by all Connectors, as well as a DownloadClient
|
||||
/// </summary>
|
||||
public abstract class Connector
|
||||
{
|
||||
internal string downloadLocation { get; } //Location of local files
|
||||
protected DownloadClient downloadClient { get; }
|
||||
|
||||
protected Connector(string downloadLocation, uint downloadDelay)
|
||||
{
|
||||
this.downloadLocation = downloadLocation;
|
||||
this.downloadClient = new DownloadClient(downloadDelay);
|
||||
}
|
||||
|
||||
public abstract string name { get; } //Name of the Connector (e.g. Website)
|
||||
|
||||
/// <summary>
|
||||
/// Returns all Publications with the given string.
|
||||
/// If the string is empty or null, returns all Publication of the Connector
|
||||
/// </summary>
|
||||
/// <param name="publicationTitle">Search-Query</param>
|
||||
/// <returns>Publications matching the query</returns>
|
||||
public abstract Publication[] GetPublications(string publicationTitle = "");
|
||||
|
||||
/// <summary>
|
||||
/// Returns all Chapters of the publication in the provided language.
|
||||
/// If the language is empty or null, returns all Chapters in all Languages.
|
||||
/// </summary>
|
||||
/// <param name="publication">Publication to get Chapters for</param>
|
||||
/// <param name="language">Language of the Chapters</param>
|
||||
/// <returns>Array of Chapters matching Publication and Language</returns>
|
||||
public abstract Chapter[] GetChapters(Publication publication, string language = "");
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the Chapter (+Images) from the website.
|
||||
/// Should later call DownloadChapterImages to retrieve the individual Images of the Chapter.
|
||||
/// </summary>
|
||||
/// <param name="publication">Publication that contains Chapter</param>
|
||||
/// <param name="chapter">Chapter with Images to retrieve</param>
|
||||
public abstract void DownloadChapter(Publication publication, Chapter chapter);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the Cover from the Website
|
||||
/// </summary>
|
||||
/// <param name="publication">Publication to retrieve Cover for</param>
|
||||
public abstract void DownloadCover(Publication publication);
|
||||
|
||||
/// <summary>
|
||||
/// Saves the series-info to series.json in the Publication Folder
|
||||
/// </summary>
|
||||
/// <param name="publication">Publication to save series.json for</param>
|
||||
public void SaveSeriesInfo(Publication publication)
|
||||
{
|
||||
//Check if Publication already has a Folder and a series.json
|
||||
string publicationFolder = Path.Join(downloadLocation, publication.folderName);
|
||||
if(!Directory.Exists(publicationFolder))
|
||||
Directory.CreateDirectory(publicationFolder);
|
||||
|
||||
string seriesInfoPath = Path.Join(publicationFolder, "series.json");
|
||||
if(!File.Exists(seriesInfoPath))
|
||||
File.WriteAllText(seriesInfoPath,publication.GetSeriesInfoJson());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a string containing XML of publication and chapter.
|
||||
/// See ComicInfo.xml
|
||||
/// </summary>
|
||||
/// <returns>XML-string</returns>
|
||||
protected static string CreateComicInfo(Publication publication, Chapter chapter)
|
||||
{
|
||||
XElement comicInfo = new XElement("ComicInfo",
|
||||
new XElement("Tags", string.Join(',',publication.tags)),
|
||||
new XElement("LanguageISO", publication.originalLanguage),
|
||||
new XElement("Title", chapter.name),
|
||||
new XElement("Volume", chapter.volumeNumber),
|
||||
new XElement("Number", chapter.chapterNumber) //TODO check if this is correct at some point
|
||||
);
|
||||
return comicInfo.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a chapter-archive is already present
|
||||
/// </summary>
|
||||
/// <returns>true if chapter is present</returns>
|
||||
public bool ChapterIsDownloaded(Publication publication, Chapter chapter)
|
||||
{
|
||||
return File.Exists(CreateFullFilepath(publication, chapter));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates full file path of chapter-archive
|
||||
/// </summary>
|
||||
/// <returns>Filepath</returns>
|
||||
protected string CreateFullFilepath(Publication publication, Chapter chapter)
|
||||
{
|
||||
return Path.Join(downloadLocation, publication.folderName, chapter.fileName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Downloads Image from URL and saves it to the given path(incl. fileName)
|
||||
/// </summary>
|
||||
/// <param name="imageUrl"></param>
|
||||
/// <param name="fullPath"></param>
|
||||
/// <param name="downloadClient">DownloadClient of the connector</param>
|
||||
protected static void DownloadImage(string imageUrl, string fullPath, DownloadClient downloadClient)
|
||||
{
|
||||
DownloadClient.RequestResult requestResult = downloadClient.MakeRequest(imageUrl);
|
||||
byte[] buffer = new byte[requestResult.result.Length];
|
||||
requestResult.result.ReadExactly(buffer, 0, buffer.Length);
|
||||
File.WriteAllBytes(fullPath, buffer);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Downloads all Images from URLs, Compresses to zip(cbz) and saves.
|
||||
/// </summary>
|
||||
/// <param name="imageUrls">List of URLs to download Images from</param>
|
||||
/// <param name="saveArchiveFilePath">Full path to save archive to (without file ending .cbz)</param>
|
||||
/// <param name="downloadClient">DownloadClient of the connector</param>
|
||||
/// <param name="comicInfoPath">Path of the generate Chapter ComicInfo.xml, if it was generated</param>
|
||||
protected static void DownloadChapterImages(string[] imageUrls, string saveArchiveFilePath, DownloadClient downloadClient, string? comicInfoPath = null)
|
||||
{
|
||||
//Check if Publication Directory already exists
|
||||
string[] splitPath = saveArchiveFilePath.Split(Path.DirectorySeparatorChar);
|
||||
string directoryPath = Path.Combine(splitPath.Take(splitPath.Length - 1).ToArray());
|
||||
if (!Directory.Exists(directoryPath))
|
||||
Directory.CreateDirectory(directoryPath);
|
||||
|
||||
string fullPath = $"{saveArchiveFilePath}.cbz";
|
||||
if (File.Exists(fullPath)) //Don't download twice.
|
||||
return;
|
||||
|
||||
//Create a temporary folder to store images
|
||||
string tempFolder = Directory.CreateTempSubdirectory().FullName;
|
||||
|
||||
int chapter = 0;
|
||||
//Download all Images to temporary Folder
|
||||
foreach (string imageUrl in imageUrls)
|
||||
{
|
||||
string[] split = imageUrl.Split('.');
|
||||
string extension = split[^1];
|
||||
DownloadImage(imageUrl, Path.Join(tempFolder, $"{chapter++}.{extension}"), downloadClient);
|
||||
}
|
||||
|
||||
if(comicInfoPath is not null)
|
||||
File.Copy(comicInfoPath, Path.Join(tempFolder, "ComicInfo.xml"));
|
||||
|
||||
//ZIP-it and ship-it
|
||||
ZipFile.CreateFromDirectory(tempFolder, fullPath);
|
||||
Directory.Delete(tempFolder, true); //Cleanup
|
||||
}
|
||||
|
||||
protected class DownloadClient
|
||||
{
|
||||
private readonly TimeSpan _requestSpeed;
|
||||
private DateTime _lastRequest;
|
||||
private static readonly HttpClient Client = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a httpClient
|
||||
/// </summary>
|
||||
/// <param name="delay">minimum delay between requests (to avoid spam)</param>
|
||||
public DownloadClient(uint delay)
|
||||
{
|
||||
_requestSpeed = TimeSpan.FromMilliseconds(delay);
|
||||
_lastRequest = DateTime.Now.Subtract(_requestSpeed);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request Webpage
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
/// <returns>RequestResult with StatusCode and Stream of received data</returns>
|
||||
public RequestResult MakeRequest(string url)
|
||||
{
|
||||
while((DateTime.Now - _lastRequest) < _requestSpeed)
|
||||
Thread.Sleep(10);
|
||||
_lastRequest = DateTime.Now;
|
||||
|
||||
HttpRequestMessage requestMessage = new(HttpMethod.Get, url);
|
||||
HttpResponseMessage response = Client.Send(requestMessage);
|
||||
Stream resultString = response.IsSuccessStatusCode ? response.Content.ReadAsStream() : Stream.Null;
|
||||
return new RequestResult(response.StatusCode, resultString);
|
||||
}
|
||||
|
||||
public struct RequestResult
|
||||
{
|
||||
public HttpStatusCode statusCode { get; }
|
||||
public Stream result { get; }
|
||||
|
||||
public RequestResult(HttpStatusCode statusCode, Stream result)
|
||||
{
|
||||
this.statusCode = statusCode;
|
||||
this.result = result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
89
Tranga/GlobalBase.cs
Normal file
89
Tranga/GlobalBase.cs
Normal file
@ -0,0 +1,89 @@
|
||||
using Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Tranga.LibraryConnectors;
|
||||
using Tranga.NotificationConnectors;
|
||||
|
||||
namespace Tranga;
|
||||
|
||||
public abstract class GlobalBase
|
||||
{
|
||||
protected Logger? logger { get; init; }
|
||||
protected TrangaSettings settings { get; init; }
|
||||
private HashSet<NotificationConnector> notificationConnectors { get; init; }
|
||||
private HashSet<LibraryConnector> libraryConnectors { get; init; }
|
||||
|
||||
protected GlobalBase(GlobalBase clone)
|
||||
{
|
||||
this.logger = clone.logger;
|
||||
this.settings = clone.settings;
|
||||
this.notificationConnectors = clone.notificationConnectors;
|
||||
this.libraryConnectors = clone.libraryConnectors;
|
||||
}
|
||||
|
||||
protected GlobalBase(Logger? logger, TrangaSettings settings)
|
||||
{
|
||||
this.logger = logger;
|
||||
this.settings = settings;
|
||||
this.notificationConnectors = settings.LoadNotificationConnectors();
|
||||
this.libraryConnectors = settings.LoadLibraryConnectors();
|
||||
}
|
||||
|
||||
protected void Log(string message)
|
||||
{
|
||||
logger?.WriteLine(this.GetType().Name, message);
|
||||
}
|
||||
|
||||
protected void Log(string fStr, params object?[] replace)
|
||||
{
|
||||
Log(string.Format(fStr, replace));
|
||||
}
|
||||
|
||||
protected void SendNotifications(string title, string text)
|
||||
{
|
||||
foreach (NotificationConnector nc in notificationConnectors)
|
||||
nc.SendNotification(title, text);
|
||||
}
|
||||
|
||||
protected void AddNotificationConnector(NotificationConnector notificationConnector)
|
||||
{
|
||||
notificationConnectors.RemoveWhere(nc => nc.GetType() == notificationConnector.GetType());
|
||||
notificationConnectors.Add(notificationConnector);
|
||||
|
||||
while(IsFileInUse(settings.notificationConnectorsFilePath))
|
||||
Thread.Sleep(100);
|
||||
File.WriteAllText(settings.notificationConnectorsFilePath, JsonConvert.SerializeObject(notificationConnectors));
|
||||
}
|
||||
|
||||
protected void UpdateLibraries()
|
||||
{
|
||||
foreach(LibraryConnector lc in libraryConnectors)
|
||||
lc.UpdateLibrary();
|
||||
}
|
||||
|
||||
protected void AddLibraryConnector(LibraryConnector libraryConnector)
|
||||
{
|
||||
libraryConnectors.RemoveWhere(lc => lc.GetType() == libraryConnector.GetType());
|
||||
libraryConnectors.Add(libraryConnector);
|
||||
|
||||
while(IsFileInUse(settings.libraryConnectorsFilePath))
|
||||
Thread.Sleep(100);
|
||||
File.WriteAllText(settings.libraryConnectorsFilePath, JsonConvert.SerializeObject(libraryConnectors));
|
||||
}
|
||||
|
||||
protected bool IsFileInUse(string filePath)
|
||||
{
|
||||
if (!File.Exists(filePath))
|
||||
return false;
|
||||
try
|
||||
{
|
||||
using FileStream stream = new (filePath, FileMode.Open, FileAccess.Read, FileShare.None);
|
||||
stream.Close();
|
||||
return false;
|
||||
}
|
||||
catch (IOException)
|
||||
{
|
||||
Log($"File is in use {filePath}");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
25
Tranga/Jobs/DownloadChapter.cs
Normal file
25
Tranga/Jobs/DownloadChapter.cs
Normal file
@ -0,0 +1,25 @@
|
||||
using Tranga.MangaConnectors;
|
||||
|
||||
namespace Tranga.Jobs;
|
||||
|
||||
public class DownloadChapter : Job
|
||||
{
|
||||
public Chapter chapter { get; init; }
|
||||
|
||||
public DownloadChapter(GlobalBase clone, MangaConnector connector, Chapter chapter) : base(clone, connector)
|
||||
{
|
||||
this.chapter = chapter;
|
||||
}
|
||||
|
||||
protected override IEnumerable<Job> ExecuteReturnSubTasksInternal()
|
||||
{
|
||||
Task downloadTask = new(delegate
|
||||
{
|
||||
mangaConnector.DownloadChapter(chapter, this.progressToken);
|
||||
UpdateLibraries();
|
||||
SendNotifications("Chapter downloaded", $"{chapter.parentPublication.sortName} - {chapter.chapterNumber}");
|
||||
});
|
||||
downloadTask.Start();
|
||||
return Array.Empty<Job>();
|
||||
}
|
||||
}
|
27
Tranga/Jobs/DownloadNewChapters.cs
Normal file
27
Tranga/Jobs/DownloadNewChapters.cs
Normal file
@ -0,0 +1,27 @@
|
||||
using Tranga.MangaConnectors;
|
||||
|
||||
namespace Tranga.Jobs;
|
||||
|
||||
public class DownloadNewChapters : Job
|
||||
{
|
||||
public Publication publication { get; init; }
|
||||
|
||||
public DownloadNewChapters(GlobalBase clone, MangaConnector connector, Publication publication, bool recurring = false) : base (clone, connector, recurring)
|
||||
{
|
||||
this.publication = publication;
|
||||
}
|
||||
|
||||
protected override IEnumerable<Job> ExecuteReturnSubTasksInternal()
|
||||
{
|
||||
Chapter[] chapters = mangaConnector.GetNewChapters(publication);
|
||||
this.progressToken.increments = chapters.Length;
|
||||
List<Job> subJobs = new();
|
||||
foreach (Chapter chapter in chapters)
|
||||
{
|
||||
DownloadChapter downloadChapterJob = new(this, this.mangaConnector, chapter);
|
||||
subJobs.Add(downloadChapterJob);
|
||||
}
|
||||
progressToken.Complete();
|
||||
return subJobs;
|
||||
}
|
||||
}
|
73
Tranga/Jobs/Job.cs
Normal file
73
Tranga/Jobs/Job.cs
Normal file
@ -0,0 +1,73 @@
|
||||
using Tranga.MangaConnectors;
|
||||
|
||||
namespace Tranga.Jobs;
|
||||
|
||||
public abstract class Job : GlobalBase
|
||||
{
|
||||
public MangaConnector mangaConnector { get; init; }
|
||||
public ProgressToken progressToken { get; private set; }
|
||||
public bool recurring { get; init; }
|
||||
public TimeSpan? recurrenceTime { get; set; }
|
||||
public DateTime? lastExecution { get; private set; }
|
||||
public DateTime nextExecution => NextExecution();
|
||||
|
||||
public Job(GlobalBase clone, MangaConnector connector, bool recurring = false, TimeSpan? recurrenceTime = null) : base(clone)
|
||||
{
|
||||
this.mangaConnector = connector;
|
||||
this.progressToken = new ProgressToken(0);
|
||||
this.recurring = recurring;
|
||||
if (recurring && recurrenceTime is null)
|
||||
throw new ArgumentException("If recurrence is set to true, a recurrence time has to be provided.");
|
||||
this.recurrenceTime = recurrenceTime;
|
||||
}
|
||||
|
||||
public Job(GlobalBase clone, MangaConnector connector, ProgressToken progressToken, bool recurring = false, TimeSpan? recurrenceTime = null) : base(clone)
|
||||
{
|
||||
this.mangaConnector = connector;
|
||||
this.progressToken = progressToken;
|
||||
this.recurring = recurring;
|
||||
if (recurring && recurrenceTime is null)
|
||||
throw new ArgumentException("If recurrence is set to true, a recurrence time has to be provided.");
|
||||
this.recurrenceTime = recurrenceTime;
|
||||
}
|
||||
|
||||
public Job(GlobalBase clone, MangaConnector connector, int taskIncrements, bool recurring = false, TimeSpan? recurrenceTime = null) : base(clone)
|
||||
{
|
||||
this.mangaConnector = connector;
|
||||
this.progressToken = new ProgressToken(taskIncrements);
|
||||
this.recurring = recurring;
|
||||
if (recurring && recurrenceTime is null)
|
||||
throw new ArgumentException("If recurrence is set to true, a recurrence time has to be provided.");
|
||||
this.recurrenceTime = recurrenceTime;
|
||||
}
|
||||
|
||||
private DateTime NextExecution()
|
||||
{
|
||||
if(recurring && recurrenceTime.HasValue && lastExecution.HasValue)
|
||||
return lastExecution.Value.Add(recurrenceTime.Value);
|
||||
if(recurring && recurrenceTime.HasValue && !lastExecution.HasValue)
|
||||
return DateTime.Now;
|
||||
return DateTime.MaxValue;
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
this.progressToken = new ProgressToken(this.progressToken.increments);
|
||||
}
|
||||
|
||||
public void Cancel()
|
||||
{
|
||||
this.progressToken.cancellationRequested = true;
|
||||
this.progressToken.Complete();
|
||||
}
|
||||
|
||||
public IEnumerable<Job> ExecuteReturnSubTasks()
|
||||
{
|
||||
progressToken.Start();
|
||||
IEnumerable<Job> ret = ExecuteReturnSubTasksInternal();
|
||||
lastExecution = DateTime.Now;
|
||||
return ret;
|
||||
}
|
||||
|
||||
protected abstract IEnumerable<Job> ExecuteReturnSubTasksInternal();
|
||||
}
|
65
Tranga/Jobs/JobBoss.cs
Normal file
65
Tranga/Jobs/JobBoss.cs
Normal file
@ -0,0 +1,65 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
using Tranga.MangaConnectors;
|
||||
|
||||
namespace Tranga.Jobs;
|
||||
|
||||
public class JobBoss : GlobalBase
|
||||
{
|
||||
private HashSet<Job> jobs { get; init; }
|
||||
private Dictionary<MangaConnector, Queue<Job>> mangaConnectorJobQueue { get; init; }
|
||||
|
||||
public JobBoss(GlobalBase clone) : base(clone)
|
||||
{
|
||||
this.jobs = new();
|
||||
this.mangaConnectorJobQueue = new();
|
||||
}
|
||||
|
||||
public void AddJob(Job job)
|
||||
{
|
||||
this.jobs.Add(job);
|
||||
}
|
||||
|
||||
public void RemoveJob(Job job)
|
||||
{
|
||||
job.Cancel();
|
||||
this.jobs.Remove(job);
|
||||
}
|
||||
|
||||
private bool QueueContainsJob(Job job)
|
||||
{
|
||||
mangaConnectorJobQueue.TryAdd(job.mangaConnector, new Queue<Job>());
|
||||
return mangaConnectorJobQueue[job.mangaConnector].Contains(job);
|
||||
}
|
||||
|
||||
private void AddJobToQueue(Job job)
|
||||
{
|
||||
Log($"Adding Job to Queue. {job}");
|
||||
mangaConnectorJobQueue.TryAdd(job.mangaConnector, new Queue<Job>());
|
||||
Queue<Job> connectorJobQueue = mangaConnectorJobQueue[job.mangaConnector];
|
||||
if(!connectorJobQueue.Contains(job))
|
||||
connectorJobQueue.Enqueue(job);
|
||||
}
|
||||
|
||||
public void AddJobsToQueue(IEnumerable<Job> jobs)
|
||||
{
|
||||
foreach(Job job in jobs)
|
||||
AddJobToQueue(job);
|
||||
}
|
||||
|
||||
public void CheckJobs()
|
||||
{
|
||||
foreach (Job job in jobs.Where(job => job.nextExecution < DateTime.Now && !QueueContainsJob(job)).OrderBy(job => job.nextExecution))
|
||||
AddJobToQueue(job);
|
||||
foreach (Queue<Job> jobQueue in mangaConnectorJobQueue.Values)
|
||||
{
|
||||
Job queueHead = jobQueue.Peek();
|
||||
if (queueHead.progressToken.state == ProgressToken.State.Complete)
|
||||
{
|
||||
if(queueHead.recurring)
|
||||
queueHead.Reset();
|
||||
jobQueue.Dequeue();
|
||||
AddJobsToQueue(jobQueue.Peek().ExecuteReturnSubTasks());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
44
Tranga/Jobs/ProgressToken.cs
Normal file
44
Tranga/Jobs/ProgressToken.cs
Normal file
@ -0,0 +1,44 @@
|
||||
namespace Tranga.Jobs;
|
||||
|
||||
public class ProgressToken
|
||||
{
|
||||
public bool cancellationRequested { get; set; }
|
||||
public int increments { get; set; }
|
||||
public int incrementsCompleted { get; set; }
|
||||
public float progress => GetProgress();
|
||||
|
||||
public enum State { Running, Complete, Standby }
|
||||
public State state { get; private set; }
|
||||
|
||||
public ProgressToken(int increments)
|
||||
{
|
||||
this.cancellationRequested = false;
|
||||
this.increments = increments;
|
||||
this.incrementsCompleted = 0;
|
||||
this.state = State.Standby;
|
||||
}
|
||||
|
||||
private float GetProgress()
|
||||
{
|
||||
if(increments > 0 && incrementsCompleted > 0)
|
||||
return (float)incrementsCompleted / (float)increments;
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void Increment()
|
||||
{
|
||||
this.incrementsCompleted++;
|
||||
if (incrementsCompleted > increments)
|
||||
state = State.Complete;
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
state = State.Running;
|
||||
}
|
||||
|
||||
public void Complete()
|
||||
{
|
||||
state = State.Complete;
|
||||
}
|
||||
}
|
118
Tranga/Komga.cs
118
Tranga/Komga.cs
@ -1,118 +0,0 @@
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text.Json.Nodes;
|
||||
using Newtonsoft.Json;
|
||||
using JsonSerializer = System.Text.Json.JsonSerializer;
|
||||
|
||||
namespace Tranga;
|
||||
|
||||
/// <summary>
|
||||
/// Provides connectivity to Komga-API
|
||||
/// Can fetch and update libraries
|
||||
/// </summary>
|
||||
public class Komga
|
||||
{
|
||||
public string baseUrl { get; }
|
||||
public string auth { get; } //Base64 encoded, if you use your password everywhere, you have problems
|
||||
|
||||
/// <param name="baseUrl">Base-URL of Komga instance, no trailing slashes(/)</param>
|
||||
/// <param name="username">Komga Username</param>
|
||||
/// <param name="password">Komga password, will be base64 encoded. yea</param>
|
||||
public Komga(string baseUrl, string username, string password)
|
||||
{
|
||||
this.baseUrl = baseUrl;
|
||||
this.auth = Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes($"{username}:{password}"));
|
||||
}
|
||||
|
||||
/// <param name="baseUrl">Base-URL of Komga instance, no trailing slashes(/)</param>
|
||||
/// <param name="auth">Base64 string of username and password (username):(password)</param>
|
||||
[JsonConstructor]
|
||||
public Komga(string baseUrl, string auth)
|
||||
{
|
||||
this.baseUrl = baseUrl;
|
||||
this.auth = auth;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fetches all libraries available to the user
|
||||
/// </summary>
|
||||
/// <returns>Array of KomgaLibraries</returns>
|
||||
public KomgaLibrary[] GetLibraries()
|
||||
{
|
||||
Stream data = NetClient.MakeRequest($"{baseUrl}/api/v1/libraries", auth);
|
||||
JsonArray? result = JsonSerializer.Deserialize<JsonArray>(data);
|
||||
if (result is null)
|
||||
return Array.Empty<KomgaLibrary>();
|
||||
|
||||
HashSet<KomgaLibrary> ret = new();
|
||||
|
||||
foreach (JsonNode jsonNode in result)
|
||||
{
|
||||
var jObject = (JsonObject?)jsonNode;
|
||||
string libraryId = jObject!["id"]!.GetValue<string>();
|
||||
string libraryName = jObject!["name"]!.GetValue<string>();
|
||||
ret.Add(new KomgaLibrary(libraryId, libraryName));
|
||||
}
|
||||
|
||||
return ret.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates library with given id
|
||||
/// </summary>
|
||||
/// <param name="libraryId">Id of the Komga-Library</param>
|
||||
/// <returns>true if successful</returns>
|
||||
public bool UpdateLibrary(string libraryId)
|
||||
{
|
||||
return NetClient.MakePost($"{baseUrl}/api/v1/libraries/{libraryId}/scan", auth);
|
||||
}
|
||||
|
||||
public struct KomgaLibrary
|
||||
{
|
||||
public string id { get; }
|
||||
public string name { get; }
|
||||
|
||||
public KomgaLibrary(string id, string name)
|
||||
{
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
||||
private static class NetClient
|
||||
{
|
||||
public static Stream MakeRequest(string url, string auth)
|
||||
{
|
||||
HttpClient client = new();
|
||||
HttpRequestMessage requestMessage = new HttpRequestMessage
|
||||
{
|
||||
Method = HttpMethod.Get,
|
||||
RequestUri = new Uri(url),
|
||||
Headers =
|
||||
{
|
||||
{ "Accept", "application/json" },
|
||||
{ "Authorization", new AuthenticationHeaderValue("Basic", auth).ToString() }
|
||||
}
|
||||
};
|
||||
HttpResponseMessage response = client.Send(requestMessage);
|
||||
Stream resultString = response.IsSuccessStatusCode ? response.Content.ReadAsStream() : Stream.Null;
|
||||
return resultString;
|
||||
}
|
||||
|
||||
public static bool MakePost(string url, string auth)
|
||||
{
|
||||
HttpClient client = new();
|
||||
HttpRequestMessage requestMessage = new HttpRequestMessage
|
||||
{
|
||||
Method = HttpMethod.Post,
|
||||
RequestUri = new Uri(url),
|
||||
Headers =
|
||||
{
|
||||
{ "Accept", "application/json" },
|
||||
{ "Authorization", new AuthenticationHeaderValue("Basic", auth).ToString() }
|
||||
}
|
||||
};
|
||||
HttpResponseMessage response = client.Send(requestMessage);
|
||||
return response.IsSuccessStatusCode;
|
||||
}
|
||||
}
|
||||
}
|
95
Tranga/LibraryConnectors/Kavita.cs
Normal file
95
Tranga/LibraryConnectors/Kavita.cs
Normal file
@ -0,0 +1,95 @@
|
||||
using System.Text.Json.Nodes;
|
||||
using Newtonsoft.Json;
|
||||
using JsonSerializer = System.Text.Json.JsonSerializer;
|
||||
|
||||
namespace Tranga.LibraryConnectors;
|
||||
|
||||
public class Kavita : LibraryConnector
|
||||
{
|
||||
|
||||
public Kavita(string baseUrl, string username, string password, GlobalBase clone) :
|
||||
base(baseUrl, GetToken(baseUrl, username, password), LibraryType.Kavita, clone)
|
||||
{
|
||||
}
|
||||
|
||||
[JsonConstructor]
|
||||
public Kavita(string baseUrl, string auth, GlobalBase clone) : base(baseUrl, auth, LibraryType.Kavita, clone)
|
||||
{
|
||||
}
|
||||
|
||||
private static string GetToken(string baseUrl, string username, string password)
|
||||
{
|
||||
HttpClient client = new()
|
||||
{
|
||||
DefaultRequestHeaders =
|
||||
{
|
||||
{ "Accept", "application/json" }
|
||||
}
|
||||
};
|
||||
HttpRequestMessage requestMessage = new ()
|
||||
{
|
||||
Method = HttpMethod.Post,
|
||||
RequestUri = new Uri($"{baseUrl}/api/Account/login"),
|
||||
Content = new StringContent($"{{\"username\":\"{username}\",\"password\":\"{password}\"}}", System.Text.Encoding.UTF8, "application/json")
|
||||
};
|
||||
|
||||
HttpResponseMessage response = client.Send(requestMessage);
|
||||
JsonObject? result = JsonSerializer.Deserialize<JsonObject>(response.Content.ReadAsStream());
|
||||
if (result is not null)
|
||||
return result["token"]!.GetValue<string>();
|
||||
else return "";
|
||||
}
|
||||
|
||||
public override void UpdateLibrary()
|
||||
{
|
||||
Log("Updating libraries.");
|
||||
foreach (KavitaLibrary lib in GetLibraries())
|
||||
NetClient.MakePost($"{baseUrl}/api/Library/scan?libraryId={lib.id}", "Bearer", auth, logger);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fetches all libraries available to the user
|
||||
/// </summary>
|
||||
/// <returns>Array of KavitaLibrary</returns>
|
||||
private IEnumerable<KavitaLibrary> GetLibraries()
|
||||
{
|
||||
Log("Getting libraries.");
|
||||
Stream data = NetClient.MakeRequest($"{baseUrl}/api/Library", "Bearer", auth, logger);
|
||||
if (data == Stream.Null)
|
||||
{
|
||||
Log("No libraries returned");
|
||||
return Array.Empty<KavitaLibrary>();
|
||||
}
|
||||
JsonArray? result = JsonSerializer.Deserialize<JsonArray>(data);
|
||||
if (result is null)
|
||||
{
|
||||
Log("No libraries returned");
|
||||
return Array.Empty<KavitaLibrary>();
|
||||
}
|
||||
|
||||
HashSet<KavitaLibrary> ret = new();
|
||||
|
||||
foreach (JsonNode? jsonNode in result)
|
||||
{
|
||||
var jObject = (JsonObject?)jsonNode;
|
||||
int libraryId = jObject!["id"]!.GetValue<int>();
|
||||
string libraryName = jObject["name"]!.GetValue<string>();
|
||||
ret.Add(new KavitaLibrary(libraryId, libraryName));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
private struct KavitaLibrary
|
||||
{
|
||||
public int id { get; }
|
||||
// ReSharper disable once UnusedAutoPropertyAccessor.Local
|
||||
public string name { get; }
|
||||
|
||||
public KavitaLibrary(int id, string name)
|
||||
{
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
}
|
75
Tranga/LibraryConnectors/Komga.cs
Normal file
75
Tranga/LibraryConnectors/Komga.cs
Normal file
@ -0,0 +1,75 @@
|
||||
using System.Text.Json.Nodes;
|
||||
using Newtonsoft.Json;
|
||||
using JsonSerializer = System.Text.Json.JsonSerializer;
|
||||
|
||||
namespace Tranga.LibraryConnectors;
|
||||
|
||||
/// <summary>
|
||||
/// Provides connectivity to Komga-API
|
||||
/// Can fetch and update libraries
|
||||
/// </summary>
|
||||
public class Komga : LibraryConnector
|
||||
{
|
||||
public Komga(string baseUrl, string username, string password, GlobalBase clone)
|
||||
: base(baseUrl, Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes($"{username}:{password}")), LibraryType.Komga, clone)
|
||||
{
|
||||
}
|
||||
|
||||
[JsonConstructor]
|
||||
public Komga(string baseUrl, string auth, GlobalBase clone) : base(baseUrl, auth, LibraryType.Komga, clone)
|
||||
{
|
||||
}
|
||||
|
||||
public override void UpdateLibrary()
|
||||
{
|
||||
Log("Updating libraries.");
|
||||
foreach (KomgaLibrary lib in GetLibraries())
|
||||
NetClient.MakePost($"{baseUrl}/api/v1/libraries/{lib.id}/scan", "Basic", auth, logger);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fetches all libraries available to the user
|
||||
/// </summary>
|
||||
/// <returns>Array of KomgaLibraries</returns>
|
||||
private IEnumerable<KomgaLibrary> GetLibraries()
|
||||
{
|
||||
Log("Getting Libraries");
|
||||
Stream data = NetClient.MakeRequest($"{baseUrl}/api/v1/libraries", "Basic", auth, logger);
|
||||
if (data == Stream.Null)
|
||||
{
|
||||
Log("No libraries returned");
|
||||
return Array.Empty<KomgaLibrary>();
|
||||
}
|
||||
JsonArray? result = JsonSerializer.Deserialize<JsonArray>(data);
|
||||
if (result is null)
|
||||
{
|
||||
Log("No libraries returned");
|
||||
return Array.Empty<KomgaLibrary>();
|
||||
}
|
||||
|
||||
HashSet<KomgaLibrary> ret = new();
|
||||
|
||||
foreach (JsonNode? jsonNode in result)
|
||||
{
|
||||
var jObject = (JsonObject?)jsonNode;
|
||||
string libraryId = jObject!["id"]!.GetValue<string>();
|
||||
string libraryName = jObject["name"]!.GetValue<string>();
|
||||
ret.Add(new KomgaLibrary(libraryId, libraryName));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
private struct KomgaLibrary
|
||||
{
|
||||
public string id { get; }
|
||||
// ReSharper disable once UnusedAutoPropertyAccessor.Local
|
||||
public string name { get; }
|
||||
|
||||
public KomgaLibrary(string id, string name)
|
||||
{
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
}
|
78
Tranga/LibraryConnectors/LibraryConnector.cs
Normal file
78
Tranga/LibraryConnectors/LibraryConnector.cs
Normal file
@ -0,0 +1,78 @@
|
||||
using System.Net;
|
||||
using System.Net.Http.Headers;
|
||||
using Logging;
|
||||
|
||||
namespace Tranga.LibraryConnectors;
|
||||
|
||||
public abstract class LibraryConnector : GlobalBase
|
||||
{
|
||||
public enum LibraryType : byte
|
||||
{
|
||||
Komga = 0,
|
||||
Kavita = 1
|
||||
}
|
||||
|
||||
// ReSharper disable once UnusedAutoPropertyAccessor.Global
|
||||
public LibraryType libraryType { get; }
|
||||
public string baseUrl { get; }
|
||||
// ReSharper disable once MemberCanBeProtected.Global
|
||||
public string auth { get; } //Base64 encoded, if you use your password everywhere, you have problems
|
||||
|
||||
protected LibraryConnector(string baseUrl, string auth, LibraryType libraryType, GlobalBase clone) : base(clone)
|
||||
{
|
||||
this.baseUrl = baseUrl;
|
||||
this.auth = auth;
|
||||
this.libraryType = libraryType;
|
||||
}
|
||||
public abstract void UpdateLibrary();
|
||||
|
||||
protected static class NetClient
|
||||
{
|
||||
public static Stream MakeRequest(string url, string authScheme, string auth, Logger? logger)
|
||||
{
|
||||
HttpClient client = new();
|
||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(authScheme, auth);
|
||||
|
||||
HttpRequestMessage requestMessage = new ()
|
||||
{
|
||||
Method = HttpMethod.Get,
|
||||
RequestUri = new Uri(url)
|
||||
};
|
||||
HttpResponseMessage response = client.Send(requestMessage);
|
||||
logger?.WriteLine("LibraryManager.NetClient", $"GET {url} -> {(int)response.StatusCode}: {response.ReasonPhrase}");
|
||||
|
||||
if(response.StatusCode is HttpStatusCode.Unauthorized && response.RequestMessage!.RequestUri!.AbsoluteUri != url)
|
||||
return MakeRequest(response.RequestMessage!.RequestUri!.AbsoluteUri, authScheme, auth, logger);
|
||||
else if (response.IsSuccessStatusCode)
|
||||
return response.Content.ReadAsStream();
|
||||
else
|
||||
return Stream.Null;
|
||||
}
|
||||
|
||||
public static bool MakePost(string url, string authScheme, string auth, Logger? logger)
|
||||
{
|
||||
HttpClient client = new()
|
||||
{
|
||||
DefaultRequestHeaders =
|
||||
{
|
||||
{ "Accept", "application/json" },
|
||||
{ "Authorization", new AuthenticationHeaderValue(authScheme, auth).ToString() }
|
||||
}
|
||||
};
|
||||
HttpRequestMessage requestMessage = new ()
|
||||
{
|
||||
Method = HttpMethod.Post,
|
||||
RequestUri = new Uri(url)
|
||||
};
|
||||
HttpResponseMessage response = client.Send(requestMessage);
|
||||
logger?.WriteLine("LibraryManager.NetClient", $"POST {url} -> {(int)response.StatusCode}: {response.ReasonPhrase}");
|
||||
|
||||
if(response.StatusCode is HttpStatusCode.Unauthorized && response.RequestMessage!.RequestUri!.AbsoluteUri != url)
|
||||
return MakePost(response.RequestMessage!.RequestUri!.AbsoluteUri, authScheme, auth, logger);
|
||||
else if (response.IsSuccessStatusCode)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
34
Tranga/LibraryConnectors/LibraryManagerJsonConverter.cs
Normal file
34
Tranga/LibraryConnectors/LibraryManagerJsonConverter.cs
Normal file
@ -0,0 +1,34 @@
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Tranga.LibraryConnectors;
|
||||
|
||||
public class LibraryManagerJsonConverter : JsonConverter
|
||||
{
|
||||
public override bool CanConvert(Type objectType)
|
||||
{
|
||||
return (objectType == typeof(LibraryConnector));
|
||||
}
|
||||
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer)
|
||||
{
|
||||
JObject jo = JObject.Load(reader);
|
||||
if (jo["libraryType"]!.Value<Int64>() == (Int64)LibraryConnector.LibraryType.Komga)
|
||||
return jo.ToObject<Komga>(serializer)!;
|
||||
|
||||
if (jo["libraryType"]!.Value<Int64>() == (Int64)LibraryConnector.LibraryType.Kavita)
|
||||
return jo.ToObject<Kavita>(serializer)!;
|
||||
|
||||
throw new Exception();
|
||||
}
|
||||
|
||||
public override bool CanWrite => false;
|
||||
|
||||
/// <summary>
|
||||
/// Don't call this
|
||||
/// </summary>
|
||||
public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer)
|
||||
{
|
||||
throw new Exception("Dont call this");
|
||||
}
|
||||
}
|
98
Tranga/MangaConnectors/DownloadClient.cs
Normal file
98
Tranga/MangaConnectors/DownloadClient.cs
Normal file
@ -0,0 +1,98 @@
|
||||
using System.Net;
|
||||
|
||||
namespace Tranga.MangaConnectors;
|
||||
|
||||
internal class DownloadClient : GlobalBase
|
||||
{
|
||||
private static readonly HttpClient Client = new()
|
||||
{
|
||||
Timeout = TimeSpan.FromSeconds(60)
|
||||
};
|
||||
|
||||
private readonly Dictionary<byte, DateTime> _lastExecutedRateLimit;
|
||||
private readonly Dictionary<byte, TimeSpan> _rateLimit;
|
||||
|
||||
public DownloadClient(Dictionary<byte, int> rateLimitRequestsPerMinute, GlobalBase clone) : base(clone)
|
||||
{
|
||||
_lastExecutedRateLimit = new();
|
||||
_rateLimit = new();
|
||||
foreach(KeyValuePair<byte, int> limit in rateLimitRequestsPerMinute)
|
||||
_rateLimit.Add(limit.Key, TimeSpan.FromMinutes(1).Divide(limit.Value));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request Webpage
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
/// <param name="requestType">For RateLimits: Same Endpoints use same type</param>
|
||||
/// <param name="referrer">Used in http request header</param>
|
||||
/// <returns>RequestResult with StatusCode and Stream of received data</returns>
|
||||
public RequestResult MakeRequest(string url, byte requestType, string? referrer = null)
|
||||
{
|
||||
if (_rateLimit.TryGetValue(requestType, out TimeSpan value))
|
||||
_lastExecutedRateLimit.TryAdd(requestType, DateTime.Now.Subtract(value));
|
||||
else
|
||||
{
|
||||
Log("RequestType not configured for rate-limit.");
|
||||
return new RequestResult(HttpStatusCode.NotAcceptable, Stream.Null);
|
||||
}
|
||||
|
||||
TimeSpan rateLimitTimeout = _rateLimit[requestType]
|
||||
.Subtract(DateTime.Now.Subtract(_lastExecutedRateLimit[requestType]));
|
||||
|
||||
if(rateLimitTimeout > TimeSpan.Zero)
|
||||
Thread.Sleep(rateLimitTimeout);
|
||||
|
||||
HttpResponseMessage? response = null;
|
||||
while (response is null)
|
||||
{
|
||||
try
|
||||
{
|
||||
HttpRequestMessage requestMessage = new(HttpMethod.Get, url);
|
||||
if(referrer is not null)
|
||||
requestMessage.Headers.Referrer = new Uri(referrer);
|
||||
_lastExecutedRateLimit[requestType] = DateTime.Now;
|
||||
response = Client.Send(requestMessage);
|
||||
}
|
||||
catch (HttpRequestException e)
|
||||
{
|
||||
Log("Exception:\n\t{0}\n\tWaiting {1} before retrying.", e.Message, _rateLimit[requestType] * 2);
|
||||
Thread.Sleep(_rateLimit[requestType] * 2);
|
||||
}
|
||||
}
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
Log($"Request-Error {response.StatusCode}: {response.ReasonPhrase}");
|
||||
return new RequestResult(response.StatusCode, Stream.Null);
|
||||
}
|
||||
|
||||
// Request has been redirected to another page. For example, it redirects directly to the results when there is only 1 result
|
||||
if(response.RequestMessage is not null && response.RequestMessage.RequestUri is not null)
|
||||
{
|
||||
return new RequestResult(response.StatusCode, response.Content.ReadAsStream(), true, response.RequestMessage.RequestUri.AbsoluteUri);
|
||||
}
|
||||
|
||||
return new RequestResult(response.StatusCode, response.Content.ReadAsStream());
|
||||
}
|
||||
|
||||
public struct RequestResult
|
||||
{
|
||||
public HttpStatusCode statusCode { get; }
|
||||
public Stream result { get; }
|
||||
public bool hasBeenRedirected { get; }
|
||||
public string? redirectedToUrl { get; }
|
||||
|
||||
public RequestResult(HttpStatusCode statusCode, Stream result)
|
||||
{
|
||||
this.statusCode = statusCode;
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
public RequestResult(HttpStatusCode statusCode, Stream result, bool hasBeenRedirected, string redirectedTo)
|
||||
: this(statusCode, result)
|
||||
{
|
||||
this.hasBeenRedirected = hasBeenRedirected;
|
||||
redirectedToUrl = redirectedTo;
|
||||
}
|
||||
}
|
||||
}
|
250
Tranga/MangaConnectors/MangaConnector.cs
Normal file
250
Tranga/MangaConnectors/MangaConnector.cs
Normal file
@ -0,0 +1,250 @@
|
||||
using System.Globalization;
|
||||
using System.IO.Compression;
|
||||
using System.Net;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text.RegularExpressions;
|
||||
using Tranga.Jobs;
|
||||
using static System.IO.UnixFileMode;
|
||||
|
||||
namespace Tranga.MangaConnectors;
|
||||
|
||||
/// <summary>
|
||||
/// Base-Class for all Connectors
|
||||
/// Provides some methods to be used by all Connectors, as well as a DownloadClient
|
||||
/// </summary>
|
||||
public abstract class MangaConnector : GlobalBase
|
||||
{
|
||||
internal DownloadClient downloadClient { get; init; } = null!;
|
||||
|
||||
protected MangaConnector(GlobalBase clone) : base(clone)
|
||||
{
|
||||
if (!Directory.Exists(settings.coverImageCache))
|
||||
Directory.CreateDirectory(settings.coverImageCache);
|
||||
}
|
||||
|
||||
public abstract string name { get; } //Name of the Connector (e.g. Website)
|
||||
|
||||
/// <summary>
|
||||
/// Returns all Publications with the given string.
|
||||
/// If the string is empty or null, returns all Publication of the Connector
|
||||
/// </summary>
|
||||
/// <param name="publicationTitle">Search-Query</param>
|
||||
/// <returns>Publications matching the query</returns>
|
||||
protected abstract Publication[] GetPublications(string publicationTitle = "");
|
||||
|
||||
/// <summary>
|
||||
/// Returns all Chapters of the publication in the provided language.
|
||||
/// If the language is empty or null, returns all Chapters in all Languages.
|
||||
/// </summary>
|
||||
/// <param name="publication">Publication to get Chapters for</param>
|
||||
/// <param name="language">Language of the Chapters</param>
|
||||
/// <returns>Array of Chapters matching Publication and Language</returns>
|
||||
public abstract Chapter[] GetChapters(Publication publication, string language = "");
|
||||
|
||||
/// <summary>
|
||||
/// Updates the available Chapters of a Publication
|
||||
/// </summary>
|
||||
/// <param name="publication">Publication to check</param>
|
||||
/// <param name="language">Language to receive chapters for</param>
|
||||
/// <returns>List of Chapters that were previously not in collection</returns>
|
||||
public Chapter[] GetNewChapters(Publication publication, string language = "en")
|
||||
{
|
||||
Log($"Getting new Chapters for {publication}");
|
||||
Chapter[] newChapters = this.GetChapters(publication, language);
|
||||
NumberFormatInfo decimalPoint = new (){ NumberDecimalSeparator = "." };
|
||||
Log($"Checking for duplicates {publication}");
|
||||
List<Chapter> newChaptersList = newChapters.Where(nChapter =>
|
||||
float.Parse(nChapter.chapterNumber, decimalPoint) > publication.ignoreChaptersBelow &&
|
||||
!nChapter.CheckChapterIsDownloaded(settings.downloadLocation)).ToList();
|
||||
Log($"{newChaptersList.Count} new chapters. {publication}");
|
||||
|
||||
return newChaptersList.ToArray();
|
||||
}
|
||||
|
||||
public Chapter[] SelectChapters(Publication publication, string searchTerm, string? language = null)
|
||||
{
|
||||
Chapter[] availableChapters = this.GetChapters(publication, language??"en");
|
||||
Regex volumeRegex = new ("((v(ol)*(olume)*){1} *([0-9]+(-[0-9]+)?){1})", RegexOptions.IgnoreCase);
|
||||
Regex chapterRegex = new ("((c(h)*(hapter)*){1} *([0-9]+(-[0-9]+)?){1})", RegexOptions.IgnoreCase);
|
||||
Regex singleResultRegex = new("([0-9]+)", RegexOptions.IgnoreCase);
|
||||
Regex rangeResultRegex = new("([0-9]+(-[0-9]+))", RegexOptions.IgnoreCase);
|
||||
Regex allRegex = new("a(ll)?", RegexOptions.IgnoreCase);
|
||||
if (volumeRegex.IsMatch(searchTerm) && chapterRegex.IsMatch(searchTerm))
|
||||
{
|
||||
string volume = singleResultRegex.Match(volumeRegex.Match(searchTerm).Value).Value;
|
||||
string chapter = singleResultRegex.Match(chapterRegex.Match(searchTerm).Value).Value;
|
||||
return availableChapters.Where(aCh => aCh.volumeNumber is not null &&
|
||||
aCh.volumeNumber.Equals(volume, StringComparison.InvariantCultureIgnoreCase) &&
|
||||
aCh.chapterNumber.Equals(chapter, StringComparison.InvariantCultureIgnoreCase))
|
||||
.ToArray();
|
||||
}
|
||||
else if (volumeRegex.IsMatch(searchTerm))
|
||||
{
|
||||
string volume = volumeRegex.Match(searchTerm).Value;
|
||||
if (rangeResultRegex.IsMatch(volume))
|
||||
{
|
||||
string range = rangeResultRegex.Match(volume).Value;
|
||||
int start = Convert.ToInt32(range.Split('-')[0]);
|
||||
int end = Convert.ToInt32(range.Split('-')[1]);
|
||||
return availableChapters.Where(aCh => aCh.volumeNumber is not null &&
|
||||
Convert.ToInt32(aCh.volumeNumber) >= start &&
|
||||
Convert.ToInt32(aCh.volumeNumber) <= end).ToArray();
|
||||
}
|
||||
else if (singleResultRegex.IsMatch(volume))
|
||||
{
|
||||
string volumeNumber = singleResultRegex.Match(volume).Value;
|
||||
return availableChapters.Where(aCh =>
|
||||
aCh.volumeNumber is not null &&
|
||||
aCh.volumeNumber.Equals(volumeNumber, StringComparison.InvariantCultureIgnoreCase)).ToArray();
|
||||
}
|
||||
|
||||
}
|
||||
else if (chapterRegex.IsMatch(searchTerm))
|
||||
{
|
||||
string chapter = chapterRegex.Match(searchTerm).Value;
|
||||
if (rangeResultRegex.IsMatch(chapter))
|
||||
{
|
||||
string range = rangeResultRegex.Match(chapter).Value;
|
||||
int start = Convert.ToInt32(range.Split('-')[0]);
|
||||
int end = Convert.ToInt32(range.Split('-')[1]);
|
||||
return availableChapters.Where(aCh => Convert.ToInt32(aCh.chapterNumber) >= start &&
|
||||
Convert.ToInt32(aCh.chapterNumber) <= end).ToArray();
|
||||
}
|
||||
else if (singleResultRegex.IsMatch(chapter))
|
||||
{
|
||||
string chapterNumber = singleResultRegex.Match(chapter).Value;
|
||||
return availableChapters.Where(aCh =>
|
||||
aCh.chapterNumber.Equals(chapterNumber, StringComparison.InvariantCultureIgnoreCase)).ToArray();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (rangeResultRegex.IsMatch(searchTerm))
|
||||
{
|
||||
int start = Convert.ToInt32(searchTerm.Split('-')[0]);
|
||||
int end = Convert.ToInt32(searchTerm.Split('-')[1]);
|
||||
return availableChapters[start..(end + 1)];
|
||||
}
|
||||
else if(singleResultRegex.IsMatch(searchTerm))
|
||||
return new [] { availableChapters[Convert.ToInt32(searchTerm)] };
|
||||
else if (allRegex.IsMatch(searchTerm))
|
||||
return availableChapters;
|
||||
}
|
||||
|
||||
return Array.Empty<Chapter>();
|
||||
}
|
||||
|
||||
public abstract HttpStatusCode DownloadChapter(Chapter chapter, ProgressToken? progressToken = null);
|
||||
|
||||
/// <summary>
|
||||
/// Copies the already downloaded cover from cache to downloadLocation
|
||||
/// </summary>
|
||||
/// <param name="publication">Publication to retrieve Cover for</param>
|
||||
public void CopyCoverFromCacheToDownloadLocation(Publication publication)
|
||||
{
|
||||
Log($"Copy cover {publication}");
|
||||
//Check if Publication already has a Folder and cover
|
||||
string publicationFolder = publication.CreatePublicationFolder(settings.downloadLocation);
|
||||
DirectoryInfo dirInfo = new (publicationFolder);
|
||||
if (dirInfo.EnumerateFiles().Any(info => info.Name.Contains("cover", StringComparison.InvariantCultureIgnoreCase)))
|
||||
{
|
||||
Log($"Cover exists {publication}");
|
||||
return;
|
||||
}
|
||||
|
||||
string fileInCache = Path.Join(settings.coverImageCache, publication.coverFileNameInCache);
|
||||
string newFilePath = Path.Join(publicationFolder, $"cover.{Path.GetFileName(fileInCache).Split('.')[^1]}" );
|
||||
Log($"Cloning cover {fileInCache} -> {newFilePath}");
|
||||
File.Copy(fileInCache, newFilePath, true);
|
||||
if(RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||
File.SetUnixFileMode(newFilePath, GroupRead | GroupWrite | OtherRead | OtherWrite | UserRead | UserWrite);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Downloads Image from URL and saves it to the given path(incl. fileName)
|
||||
/// </summary>
|
||||
/// <param name="imageUrl"></param>
|
||||
/// <param name="fullPath"></param>
|
||||
/// <param name="requestType">RequestType for Rate-Limit</param>
|
||||
/// <param name="referrer">referrer used in html request header</param>
|
||||
private HttpStatusCode DownloadImage(string imageUrl, string fullPath, byte requestType, string? referrer = null)
|
||||
{
|
||||
DownloadClient.RequestResult requestResult = downloadClient.MakeRequest(imageUrl, requestType, referrer);
|
||||
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300 || requestResult.result == Stream.Null)
|
||||
return requestResult.statusCode;
|
||||
byte[] buffer = new byte[requestResult.result.Length];
|
||||
requestResult.result.ReadExactly(buffer, 0, buffer.Length);
|
||||
File.WriteAllBytes(fullPath, buffer);
|
||||
return requestResult.statusCode;
|
||||
}
|
||||
|
||||
protected HttpStatusCode DownloadChapterImages(string[] imageUrls, string saveArchiveFilePath, byte requestType, string? comicInfoPath = null, string? referrer = null, ProgressToken? progressToken = null)
|
||||
{
|
||||
if (progressToken?.cancellationRequested ?? false)
|
||||
return HttpStatusCode.RequestTimeout;
|
||||
Log($"Downloading Images for {saveArchiveFilePath}");
|
||||
if(progressToken is not null)
|
||||
progressToken.increments = imageUrls.Length;
|
||||
//Check if Publication Directory already exists
|
||||
string directoryPath = Path.GetDirectoryName(saveArchiveFilePath)!;
|
||||
if (!Directory.Exists(directoryPath))
|
||||
Directory.CreateDirectory(directoryPath);
|
||||
|
||||
if (File.Exists(saveArchiveFilePath)) //Don't download twice.
|
||||
return HttpStatusCode.OK;
|
||||
|
||||
//Create a temporary folder to store images
|
||||
string tempFolder = Directory.CreateTempSubdirectory().FullName;
|
||||
|
||||
int chapter = 0;
|
||||
//Download all Images to temporary Folder
|
||||
foreach (string imageUrl in imageUrls)
|
||||
{
|
||||
string[] split = imageUrl.Split('.');
|
||||
string extension = split[^1];
|
||||
Log($"Downloading image {chapter + 1:000}/{imageUrls.Length:000}"); //TODO
|
||||
HttpStatusCode status = DownloadImage(imageUrl, Path.Join(tempFolder, $"{chapter++}.{extension}"), requestType, referrer);
|
||||
if ((int)status < 200 || (int)status >= 300)
|
||||
{
|
||||
progressToken?.Complete();
|
||||
return status;
|
||||
}
|
||||
if (progressToken?.cancellationRequested ?? false)
|
||||
{
|
||||
progressToken?.Complete();
|
||||
return HttpStatusCode.RequestTimeout;
|
||||
}
|
||||
progressToken?.Increment();
|
||||
}
|
||||
|
||||
if(comicInfoPath is not null)
|
||||
File.Copy(comicInfoPath, Path.Join(tempFolder, "ComicInfo.xml"));
|
||||
|
||||
Log($"Creating archive {saveArchiveFilePath}");
|
||||
//ZIP-it and ship-it
|
||||
ZipFile.CreateFromDirectory(tempFolder, saveArchiveFilePath);
|
||||
if(RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||
File.SetUnixFileMode(saveArchiveFilePath, GroupRead | GroupWrite | OtherRead | OtherWrite | UserRead | UserWrite);
|
||||
Directory.Delete(tempFolder, true); //Cleanup
|
||||
|
||||
progressToken?.Complete();
|
||||
return HttpStatusCode.OK;
|
||||
}
|
||||
|
||||
protected string SaveCoverImageToCache(string url, byte requestType)
|
||||
{
|
||||
string[] split = url.Split('/');
|
||||
string filename = split[^1];
|
||||
string saveImagePath = Path.Join(settings.coverImageCache, filename);
|
||||
|
||||
if (File.Exists(saveImagePath))
|
||||
return filename;
|
||||
|
||||
DownloadClient.RequestResult coverResult = downloadClient.MakeRequest(url, requestType);
|
||||
using MemoryStream ms = new();
|
||||
coverResult.result.CopyTo(ms);
|
||||
File.WriteAllBytes(saveImagePath, ms.ToArray());
|
||||
Log($"Saving cover to {saveImagePath}");
|
||||
return filename;
|
||||
}
|
||||
}
|
@ -2,35 +2,50 @@
|
||||
using System.Net;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Nodes;
|
||||
using Tranga.Jobs;
|
||||
|
||||
namespace Tranga.Connectors;
|
||||
public class MangaDex : Connector
|
||||
namespace Tranga.MangaConnectors;
|
||||
public class MangaDex : MangaConnector
|
||||
{
|
||||
public override string name { get; }
|
||||
|
||||
public MangaDex(string downloadLocation, uint downloadDelay) : base(downloadLocation, downloadDelay)
|
||||
private enum RequestType : byte
|
||||
{
|
||||
name = "MangaDex";
|
||||
}
|
||||
|
||||
public MangaDex(string downloadLocation) : base(downloadLocation, 750)
|
||||
{
|
||||
name = "MangaDex";
|
||||
Manga,
|
||||
Feed,
|
||||
AtHomeServer,
|
||||
CoverUrl,
|
||||
Author,
|
||||
}
|
||||
|
||||
public override Publication[] GetPublications(string publicationTitle = "")
|
||||
public MangaDex(GlobalBase clone) : base(clone)
|
||||
{
|
||||
name = "MangaDex";
|
||||
this.downloadClient = new DownloadClient(new Dictionary<byte, int>()
|
||||
{
|
||||
{(byte)RequestType.Manga, 250},
|
||||
{(byte)RequestType.Feed, 250},
|
||||
{(byte)RequestType.AtHomeServer, 40},
|
||||
{(byte)RequestType.CoverUrl, 250},
|
||||
{(byte)RequestType.Author, 250}
|
||||
}, clone);
|
||||
}
|
||||
|
||||
protected override Publication[] GetPublications(string publicationTitle = "")
|
||||
{
|
||||
Log($"Searching Publications. Term=\"{publicationTitle}\"");
|
||||
const int limit = 100; //How many values we want returned at once
|
||||
int offset = 0; //"Page"
|
||||
int total = int.MaxValue; //How many total results are there, is updated on first request
|
||||
HashSet<Publication> publications = new();
|
||||
int loadedPublicationData = 0;
|
||||
while (offset < total) //As long as we haven't requested all "Pages"
|
||||
{
|
||||
//Request next Page
|
||||
DownloadClient.RequestResult requestResult =
|
||||
downloadClient.MakeRequest(
|
||||
$"https://api.mangadex.org/manga?limit={limit}&title={publicationTitle}&offset={offset}");
|
||||
if (requestResult.statusCode != HttpStatusCode.OK)
|
||||
$"https://api.mangadex.org/manga?limit={limit}&title={publicationTitle}&offset={offset}", (byte)RequestType.Manga);
|
||||
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
||||
break;
|
||||
JsonObject? result = JsonSerializer.Deserialize<JsonObject>(requestResult.result);
|
||||
|
||||
@ -44,9 +59,12 @@ public class MangaDex : Connector
|
||||
//Loop each Manga and extract information from JSON
|
||||
foreach (JsonNode? mangeNode in mangaInResult)
|
||||
{
|
||||
Log($"Getting publication data. {++loadedPublicationData}/{total}");
|
||||
JsonObject manga = (JsonObject)mangeNode!;
|
||||
JsonObject attributes = manga["attributes"]!.AsObject();
|
||||
|
||||
string publicationId = manga["id"]!.GetValue<string>();
|
||||
|
||||
string title = attributes["title"]!.AsObject().ContainsKey("en") && attributes["title"]!["en"] is not null
|
||||
? attributes["title"]!["en"]!.GetValue<string>()
|
||||
: attributes["title"]![((IDictionary<string, JsonNode?>)attributes["title"]!.AsObject()).Keys.First()]!.GetValue<string>();
|
||||
@ -56,14 +74,12 @@ public class MangaDex : Connector
|
||||
: null;
|
||||
|
||||
JsonArray altTitlesObject = attributes["altTitles"]!.AsArray();
|
||||
string[,] altTitles = new string[altTitlesObject.Count, 2];
|
||||
int titleIndex = 0;
|
||||
Dictionary<string, string> altTitlesDict = new();
|
||||
foreach (JsonNode? altTitleNode in altTitlesObject)
|
||||
{
|
||||
JsonObject altTitleObject = (JsonObject)altTitleNode!;
|
||||
string key = ((IDictionary<string, JsonNode?>)altTitleObject).Keys.ToArray()[0];
|
||||
altTitles[titleIndex, 0] = key;
|
||||
altTitles[titleIndex++, 1] = altTitleObject[key]!.GetValue<string>();
|
||||
altTitlesDict.TryAdd(key, altTitleObject[key]!.GetValue<string>());
|
||||
}
|
||||
|
||||
JsonArray tagsObject = attributes["tags"]!.AsArray();
|
||||
@ -75,23 +91,30 @@ public class MangaDex : Connector
|
||||
tags.Add(tagObject["attributes"]!["name"]!["en"]!.GetValue<string>());
|
||||
}
|
||||
|
||||
string? poster = null;
|
||||
string? posterId = null;
|
||||
HashSet<string> authorIds = new();
|
||||
if (manga.ContainsKey("relationships") && manga["relationships"] is not null)
|
||||
{
|
||||
JsonArray relationships = manga["relationships"]!.AsArray();
|
||||
poster = relationships.FirstOrDefault(relationship => relationship!["type"]!.GetValue<string>() == "cover_art")!["id"]!.GetValue<string>();
|
||||
posterId = relationships.FirstOrDefault(relationship => relationship!["type"]!.GetValue<string>() == "cover_art")!["id"]!.GetValue<string>();
|
||||
foreach (JsonNode? node in relationships.Where(relationship =>
|
||||
relationship!["type"]!.GetValue<string>() == "author"))
|
||||
authorIds.Add(node!["id"]!.GetValue<string>());
|
||||
}
|
||||
string? coverUrl = GetCoverUrl(publicationId, posterId);
|
||||
string? coverCacheName = null;
|
||||
if (coverUrl is not null)
|
||||
coverCacheName = SaveCoverImageToCache(coverUrl, (byte)RequestType.AtHomeServer);
|
||||
|
||||
string[,]? links = null;
|
||||
List<string> authors = GetAuthors(authorIds);
|
||||
|
||||
Dictionary<string, string> linksDict = new();
|
||||
if (attributes.ContainsKey("links") && attributes["links"] is not null)
|
||||
{
|
||||
JsonObject linksObject = attributes["links"]!.AsObject();
|
||||
links = new string[linksObject.Count, 2];
|
||||
int linkIndex = 0;
|
||||
foreach (string key in ((IDictionary<string, JsonNode?>)linksObject).Keys)
|
||||
{
|
||||
links[linkIndex, 0] = key;
|
||||
links[linkIndex++, 1] = linksObject[key]!.GetValue<string>();
|
||||
linksDict.Add(key, linksObject[key]!.GetValue<string>());
|
||||
}
|
||||
}
|
||||
|
||||
@ -105,27 +128,31 @@ public class MangaDex : Connector
|
||||
|
||||
string status = attributes["status"]!.GetValue<string>();
|
||||
|
||||
Publication pub = new Publication(
|
||||
Publication pub = new (
|
||||
title,
|
||||
authors,
|
||||
description,
|
||||
altTitles,
|
||||
altTitlesDict,
|
||||
tags.ToArray(),
|
||||
poster,
|
||||
links,
|
||||
coverUrl,
|
||||
coverCacheName,
|
||||
linksDict,
|
||||
year,
|
||||
originalLanguage,
|
||||
status,
|
||||
manga["id"]!.GetValue<string>()
|
||||
publicationId
|
||||
);
|
||||
publications.Add(pub); //Add Publication (Manga) to result
|
||||
}
|
||||
}
|
||||
|
||||
Log($"Retrieved {publications.Count} publications.");
|
||||
return publications.ToArray();
|
||||
}
|
||||
|
||||
public override Chapter[] GetChapters(Publication publication, string language = "")
|
||||
{
|
||||
Log($"Getting chapters {publication}");
|
||||
const int limit = 100; //How many values we want returned at once
|
||||
int offset = 0; //"Page"
|
||||
int total = int.MaxValue; //How many total results are there, is updated on first request
|
||||
@ -136,8 +163,8 @@ public class MangaDex : Connector
|
||||
//Request next "Page"
|
||||
DownloadClient.RequestResult requestResult =
|
||||
downloadClient.MakeRequest(
|
||||
$"https://api.mangadex.org/manga/{publication.downloadUrl}/feed?limit={limit}&offset={offset}&translatedLanguage%5B%5D={language}");
|
||||
if (requestResult.statusCode != HttpStatusCode.OK)
|
||||
$"https://api.mangadex.org/manga/{publication.publicationId}/feed?limit={limit}&offset={offset}&translatedLanguage%5B%5D={language}", (byte)RequestType.Feed);
|
||||
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
||||
break;
|
||||
JsonObject? result = JsonSerializer.Deserialize<JsonObject>(requestResult.result);
|
||||
|
||||
@ -162,32 +189,34 @@ public class MangaDex : Connector
|
||||
? attributes["volume"]!.GetValue<string>()
|
||||
: null;
|
||||
|
||||
string? chapterNum = attributes.ContainsKey("chapter") && attributes["chapter"] is not null
|
||||
string chapterNum = attributes.ContainsKey("chapter") && attributes["chapter"] is not null
|
||||
? attributes["chapter"]!.GetValue<string>()
|
||||
: null;
|
||||
: "null";
|
||||
|
||||
chapters.Add(new Chapter(title, volume, chapterNum, chapterId));
|
||||
if(chapterNum is not "null")
|
||||
chapters.Add(new Chapter(publication, title, volume, chapterNum, chapterId));
|
||||
}
|
||||
}
|
||||
|
||||
//Return Chapters ordered by Chapter-Number
|
||||
NumberFormatInfo chapterNumberFormatInfo = new()
|
||||
{
|
||||
NumberDecimalSeparator = "."
|
||||
};
|
||||
NumberFormatInfo chapterNumberFormatInfo = new() { NumberDecimalSeparator = "." };
|
||||
Log($"Got {chapters.Count} chapters. {publication}");
|
||||
return chapters.OrderBy(chapter => Convert.ToSingle(chapter.chapterNumber, chapterNumberFormatInfo)).ToArray();
|
||||
}
|
||||
|
||||
public override void DownloadChapter(Publication publication, Chapter chapter)
|
||||
public override HttpStatusCode DownloadChapter(Chapter chapter, ProgressToken? progressToken = null)
|
||||
{
|
||||
if (progressToken?.cancellationRequested ?? false)
|
||||
return HttpStatusCode.RequestTimeout;
|
||||
Log($"Retrieving chapter-info {chapter} {chapter.parentPublication}");
|
||||
//Request URLs for Chapter-Images
|
||||
DownloadClient.RequestResult requestResult =
|
||||
downloadClient.MakeRequest($"https://api.mangadex.org/at-home/server/{chapter.url}?forcePort443=false'");
|
||||
if (requestResult.statusCode != HttpStatusCode.OK)
|
||||
return;
|
||||
downloadClient.MakeRequest($"https://api.mangadex.org/at-home/server/{chapter.url}?forcePort443=false'", (byte)RequestType.AtHomeServer);
|
||||
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
||||
return requestResult.statusCode;
|
||||
JsonObject? result = JsonSerializer.Deserialize<JsonObject>(requestResult.result);
|
||||
if (result is null)
|
||||
return;
|
||||
return HttpStatusCode.NoContent;
|
||||
|
||||
string baseUrl = result["baseUrl"]!.GetValue<string>();
|
||||
string hash = result["chapter"]!["hash"]!.GetValue<string>();
|
||||
@ -198,44 +227,55 @@ public class MangaDex : Connector
|
||||
imageUrls.Add($"{baseUrl}/data/{hash}/{image!.GetValue<string>()}");
|
||||
|
||||
string comicInfoPath = Path.GetTempFileName();
|
||||
File.WriteAllText(comicInfoPath, CreateComicInfo(publication, chapter));
|
||||
File.WriteAllText(comicInfoPath, chapter.GetComicInfoXmlString());
|
||||
|
||||
//Download Chapter-Images
|
||||
DownloadChapterImages(imageUrls.ToArray(), CreateFullFilepath(publication, chapter), downloadClient, comicInfoPath);
|
||||
return DownloadChapterImages(imageUrls.ToArray(), chapter.GetArchiveFilePath(settings.downloadLocation), (byte)RequestType.AtHomeServer, comicInfoPath, progressToken:progressToken);
|
||||
}
|
||||
|
||||
public override void DownloadCover(Publication publication)
|
||||
private string? GetCoverUrl(string publicationId, string? posterId)
|
||||
{
|
||||
//Check if Publication already has a Folder and cover
|
||||
string publicationFolder = Path.Join(downloadLocation, publication.folderName);
|
||||
if(!Directory.Exists(publicationFolder))
|
||||
Directory.CreateDirectory(publicationFolder);
|
||||
DirectoryInfo dirInfo = new (publicationFolder);
|
||||
foreach(FileInfo fileInfo in dirInfo.EnumerateFiles())
|
||||
if (fileInfo.Name.Contains("cover."))
|
||||
return;
|
||||
|
||||
Log($"Getting CoverUrl for Publication {publicationId}");
|
||||
if (posterId is null)
|
||||
{
|
||||
Log("No cover.");
|
||||
return null;
|
||||
}
|
||||
|
||||
//Request information where to download Cover
|
||||
DownloadClient.RequestResult requestResult =
|
||||
downloadClient.MakeRequest($"https://api.mangadex.org/cover/{publication.posterUrl}");
|
||||
if (requestResult.statusCode != HttpStatusCode.OK)
|
||||
return;
|
||||
downloadClient.MakeRequest($"https://api.mangadex.org/cover/{posterId}", (byte)RequestType.CoverUrl);
|
||||
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
||||
return null;
|
||||
JsonObject? result = JsonSerializer.Deserialize<JsonObject>(requestResult.result);
|
||||
if (result is null)
|
||||
return;
|
||||
return null;
|
||||
|
||||
string fileName = result["data"]!["attributes"]!["fileName"]!.GetValue<string>();
|
||||
|
||||
string coverUrl = $"https://uploads.mangadex.org/covers/{publication.downloadUrl}/{fileName}";
|
||||
|
||||
//Get file-extension (jpg, png)
|
||||
string[] split = coverUrl.Split('.');
|
||||
string extension = split[^1];
|
||||
string coverUrl = $"https://uploads.mangadex.org/covers/{publicationId}/{fileName}";
|
||||
Log($"Cover-Url {publicationId} -> {coverUrl}");
|
||||
return coverUrl;
|
||||
}
|
||||
|
||||
string outFolderPath = Path.Join(downloadLocation, publication.folderName);
|
||||
Directory.CreateDirectory(outFolderPath);
|
||||
|
||||
//Download cover-Image
|
||||
DownloadImage(coverUrl, Path.Join(downloadLocation, publication.folderName, $"cover.{extension}"), this.downloadClient);
|
||||
private List<string> GetAuthors(IEnumerable<string> authorIds)
|
||||
{
|
||||
Log("Retrieving authors.");
|
||||
List<string> ret = new();
|
||||
foreach (string authorId in authorIds)
|
||||
{
|
||||
DownloadClient.RequestResult requestResult =
|
||||
downloadClient.MakeRequest($"https://api.mangadex.org/author/{authorId}", (byte)RequestType.Author);
|
||||
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
||||
return ret;
|
||||
JsonObject? result = JsonSerializer.Deserialize<JsonObject>(requestResult.result);
|
||||
if (result is null)
|
||||
return ret;
|
||||
|
||||
string authorName = result["data"]!["attributes"]!["name"]!.GetValue<string>();
|
||||
ret.Add(authorName);
|
||||
Log($"Got author {authorId} -> {authorName}");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
223
Tranga/MangaConnectors/MangaKatana.cs
Normal file
223
Tranga/MangaConnectors/MangaKatana.cs
Normal file
@ -0,0 +1,223 @@
|
||||
using System.Globalization;
|
||||
using System.Net;
|
||||
using System.Text.RegularExpressions;
|
||||
using HtmlAgilityPack;
|
||||
using Tranga.Jobs;
|
||||
|
||||
namespace Tranga.MangaConnectors;
|
||||
|
||||
public class MangaKatana : MangaConnector
|
||||
{
|
||||
public override string name { get; }
|
||||
|
||||
public MangaKatana(GlobalBase clone) : base(clone)
|
||||
{
|
||||
this.name = "MangaKatana";
|
||||
this.downloadClient = new DownloadClient(new Dictionary<byte, int>()
|
||||
{
|
||||
{1, 60}
|
||||
}, clone);
|
||||
}
|
||||
|
||||
protected override Publication[] GetPublications(string publicationTitle = "")
|
||||
{
|
||||
Log($"Searching Publications. Term=\"{publicationTitle}\"");
|
||||
string sanitizedTitle = string.Join('_', Regex.Matches(publicationTitle, "[A-z]*").Where(m => m.Value.Length > 0)).ToLower();
|
||||
string requestUrl = $"https://mangakatana.com/?search={sanitizedTitle}&search_by=book_name";
|
||||
DownloadClient.RequestResult requestResult =
|
||||
downloadClient.MakeRequest(requestUrl, 1);
|
||||
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
||||
return Array.Empty<Publication>();
|
||||
|
||||
// ReSharper disable once MergeIntoPattern
|
||||
// If a single result is found, the user will be redirected to the results directly instead of a result page
|
||||
if(requestResult.hasBeenRedirected
|
||||
&& requestResult.redirectedToUrl is not null
|
||||
&& requestResult.redirectedToUrl.Contains("mangakatana.com/manga"))
|
||||
{
|
||||
return new [] { ParseSinglePublicationFromHtml(requestResult.result, requestResult.redirectedToUrl.Split('/')[^1]) };
|
||||
}
|
||||
|
||||
Publication[] publications = ParsePublicationsFromHtml(requestResult.result);
|
||||
Log($"Retrieved {publications.Length} publications.");
|
||||
return publications;
|
||||
}
|
||||
|
||||
private Publication[] ParsePublicationsFromHtml(Stream html)
|
||||
{
|
||||
StreamReader reader = new(html);
|
||||
string htmlString = reader.ReadToEnd();
|
||||
HtmlDocument document = new();
|
||||
document.LoadHtml(htmlString);
|
||||
IEnumerable<HtmlNode> searchResults = document.DocumentNode.SelectNodes("//*[@id='book_list']/div");
|
||||
if (searchResults is null || !searchResults.Any())
|
||||
return Array.Empty<Publication>();
|
||||
List<string> urls = new();
|
||||
foreach (HtmlNode mangaResult in searchResults)
|
||||
{
|
||||
urls.Add(mangaResult.Descendants("a").First().GetAttributes()
|
||||
.First(a => a.Name == "href").Value);
|
||||
}
|
||||
|
||||
HashSet<Publication> ret = new();
|
||||
foreach (string url in urls)
|
||||
{
|
||||
DownloadClient.RequestResult requestResult =
|
||||
downloadClient.MakeRequest(url, 1);
|
||||
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
||||
return Array.Empty<Publication>();
|
||||
|
||||
ret.Add(ParseSinglePublicationFromHtml(requestResult.result, url.Split('/')[^1]));
|
||||
}
|
||||
|
||||
return ret.ToArray();
|
||||
}
|
||||
|
||||
private Publication ParseSinglePublicationFromHtml(Stream html, string publicationId)
|
||||
{
|
||||
StreamReader reader = new(html);
|
||||
string htmlString = reader.ReadToEnd();
|
||||
HtmlDocument document = new();
|
||||
document.LoadHtml(htmlString);
|
||||
string status = "";
|
||||
Dictionary<string, string> altTitles = new();
|
||||
Dictionary<string, string>? links = null;
|
||||
HashSet<string> tags = new();
|
||||
string[] authors = Array.Empty<string>();
|
||||
string originalLanguage = "";
|
||||
|
||||
HtmlNode infoNode = document.DocumentNode.SelectSingleNode("//*[@id='single_book']");
|
||||
string sortName = infoNode.Descendants("h1").First(n => n.HasClass("heading")).InnerText;
|
||||
HtmlNode infoTable = infoNode.SelectSingleNode("//*[@id='single_book']/div[2]/div/ul");
|
||||
|
||||
foreach (HtmlNode row in infoTable.Descendants("li"))
|
||||
{
|
||||
string key = row.SelectNodes("div").First().InnerText.ToLower();
|
||||
string value = row.SelectNodes("div").Last().InnerText;
|
||||
string keySanitized = string.Concat(Regex.Matches(key, "[a-z]"));
|
||||
|
||||
switch (keySanitized)
|
||||
{
|
||||
case "altnames":
|
||||
string[] alts = value.Split(" ; ");
|
||||
for (int i = 0; i < alts.Length; i++)
|
||||
altTitles.Add(i.ToString(), alts[i]);
|
||||
break;
|
||||
case "authorsartists":
|
||||
authors = value.Split(',');
|
||||
break;
|
||||
case "status":
|
||||
status = value;
|
||||
break;
|
||||
case "genres":
|
||||
tags = row.SelectNodes("div").Last().Descendants("a").Select(a => a.InnerText).ToHashSet();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
string posterUrl = document.DocumentNode.SelectSingleNode("//*[@id='single_book']/div[1]/div").Descendants("img").First()
|
||||
.GetAttributes().First(a => a.Name == "src").Value;
|
||||
|
||||
string coverFileNameInCache = SaveCoverImageToCache(posterUrl, 1);
|
||||
|
||||
string description = document.DocumentNode.SelectSingleNode("//*[@id='single_book']/div[3]/p").InnerText;
|
||||
while (description.StartsWith('\n'))
|
||||
description = description.Substring(1);
|
||||
|
||||
int year = DateTime.Now.Year;
|
||||
string yearString = infoTable.Descendants("div").First(d => d.HasClass("updateAt"))
|
||||
.InnerText.Split('-')[^1];
|
||||
|
||||
if(yearString.Contains("ago") == false)
|
||||
{
|
||||
year = Convert.ToInt32(yearString);
|
||||
}
|
||||
|
||||
return new Publication(sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl, coverFileNameInCache, links,
|
||||
year, originalLanguage, status, publicationId);
|
||||
}
|
||||
|
||||
public override Chapter[] GetChapters(Publication publication, string language = "")
|
||||
{
|
||||
Log($"Getting chapters {publication}");
|
||||
string requestUrl = $"https://mangakatana.com/manga/{publication.publicationId}";
|
||||
// Leaving this in for verification if the page exists
|
||||
DownloadClient.RequestResult requestResult =
|
||||
downloadClient.MakeRequest(requestUrl, 1);
|
||||
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
||||
return Array.Empty<Chapter>();
|
||||
|
||||
//Return Chapters ordered by Chapter-Number
|
||||
NumberFormatInfo chapterNumberFormatInfo = new()
|
||||
{
|
||||
NumberDecimalSeparator = "."
|
||||
};
|
||||
List<Chapter> chapters = ParseChaptersFromHtml(publication, requestUrl);
|
||||
Log($"Got {chapters.Count} chapters. {publication}");
|
||||
return chapters.OrderBy(chapter => Convert.ToSingle(chapter.chapterNumber, chapterNumberFormatInfo)).ToArray();
|
||||
}
|
||||
|
||||
private List<Chapter> ParseChaptersFromHtml(Publication publication, string mangaUrl)
|
||||
{
|
||||
// Using HtmlWeb will include the chapters since they are loaded with js
|
||||
HtmlWeb web = new();
|
||||
HtmlDocument document = web.Load(mangaUrl);
|
||||
|
||||
List<Chapter> ret = new();
|
||||
|
||||
HtmlNode chapterList = document.DocumentNode.SelectSingleNode("//div[contains(@class, 'chapters')]/table/tbody");
|
||||
|
||||
foreach (HtmlNode chapterInfo in chapterList.Descendants("tr"))
|
||||
{
|
||||
string fullString = chapterInfo.Descendants("a").First().InnerText;
|
||||
|
||||
string? volumeNumber = fullString.Contains("Vol.") ? fullString.Replace("Vol.", "").Split(' ')[0] : null;
|
||||
string chapterNumber = fullString.Split(':')[0].Split("Chapter ")[1].Split(" ")[0].Replace('-', '.');
|
||||
string chapterName = string.Concat(fullString.Split(':')[1..]);
|
||||
string url = chapterInfo.Descendants("a").First()
|
||||
.GetAttributeValue("href", "");
|
||||
ret.Add(new Chapter(publication, chapterName, volumeNumber, chapterNumber, url));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public override HttpStatusCode DownloadChapter(Chapter chapter, ProgressToken? progressToken = null)
|
||||
{
|
||||
if (progressToken?.cancellationRequested ?? false)
|
||||
return HttpStatusCode.RequestTimeout;
|
||||
Log($"Retrieving chapter-info {chapter} {chapter.parentPublication}");
|
||||
string requestUrl = chapter.url;
|
||||
// Leaving this in to check if the page exists
|
||||
DownloadClient.RequestResult requestResult =
|
||||
downloadClient.MakeRequest(requestUrl, 1);
|
||||
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
||||
return requestResult.statusCode;
|
||||
|
||||
string[] imageUrls = ParseImageUrlsFromHtml(requestUrl);
|
||||
|
||||
string comicInfoPath = Path.GetTempFileName();
|
||||
File.WriteAllText(comicInfoPath, chapter.GetComicInfoXmlString());
|
||||
|
||||
return DownloadChapterImages(imageUrls, chapter.GetArchiveFilePath(settings.downloadLocation), 1, comicInfoPath, "https://mangakatana.com/", progressToken:progressToken);
|
||||
}
|
||||
|
||||
private string[] ParseImageUrlsFromHtml(string mangaUrl)
|
||||
{
|
||||
HtmlWeb web = new();
|
||||
HtmlDocument document = web.Load(mangaUrl);
|
||||
|
||||
// Images are loaded dynamically, but the urls are present in a piece of js code on the page
|
||||
string js = document.DocumentNode.SelectSingleNode("//script[contains(., 'data-src')]").InnerText
|
||||
.Replace("\r", "")
|
||||
.Replace("\n", "")
|
||||
.Replace("\t", "");
|
||||
|
||||
// ReSharper disable once StringLiteralTypo
|
||||
string regexPat = @"(var thzq=\[')(.*)(,];function)";
|
||||
var group = Regex.Matches(js, regexPat).First().Groups[2].Value.Replace("'", "");
|
||||
var urls = group.Split(',');
|
||||
|
||||
return urls;
|
||||
}
|
||||
}
|
206
Tranga/MangaConnectors/Manganato.cs
Normal file
206
Tranga/MangaConnectors/Manganato.cs
Normal file
@ -0,0 +1,206 @@
|
||||
using System.Globalization;
|
||||
using System.Net;
|
||||
using System.Text.RegularExpressions;
|
||||
using HtmlAgilityPack;
|
||||
using Tranga.Jobs;
|
||||
|
||||
namespace Tranga.MangaConnectors;
|
||||
|
||||
public class Manganato : MangaConnector
|
||||
{
|
||||
public override string name { get; }
|
||||
|
||||
public Manganato(GlobalBase clone) : base(clone)
|
||||
{
|
||||
this.name = "Manganato";
|
||||
this.downloadClient = new DownloadClient(new Dictionary<byte, int>()
|
||||
{
|
||||
{1, 60}
|
||||
}, clone);
|
||||
}
|
||||
|
||||
protected override Publication[] GetPublications(string publicationTitle = "")
|
||||
{
|
||||
Log($"Searching Publications. Term=\"{publicationTitle}\"");
|
||||
string sanitizedTitle = string.Join('_', Regex.Matches(publicationTitle, "[A-z]*")).ToLower();
|
||||
string requestUrl = $"https://manganato.com/search/story/{sanitizedTitle}";
|
||||
DownloadClient.RequestResult requestResult =
|
||||
downloadClient.MakeRequest(requestUrl, 1);
|
||||
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
||||
return Array.Empty<Publication>();
|
||||
|
||||
Publication[] publications = ParsePublicationsFromHtml(requestResult.result);
|
||||
Log($"Retrieved {publications.Length} publications.");
|
||||
return publications;
|
||||
}
|
||||
|
||||
private Publication[] ParsePublicationsFromHtml(Stream html)
|
||||
{
|
||||
StreamReader reader = new (html);
|
||||
string htmlString = reader.ReadToEnd();
|
||||
HtmlDocument document = new ();
|
||||
document.LoadHtml(htmlString);
|
||||
IEnumerable<HtmlNode> searchResults = document.DocumentNode.Descendants("div").Where(n => n.HasClass("search-story-item"));
|
||||
List<string> urls = new();
|
||||
foreach (HtmlNode mangaResult in searchResults)
|
||||
{
|
||||
urls.Add(mangaResult.Descendants("a").First(n => n.HasClass("item-title")).GetAttributes()
|
||||
.First(a => a.Name == "href").Value);
|
||||
}
|
||||
|
||||
HashSet<Publication> ret = new();
|
||||
foreach (string url in urls)
|
||||
{
|
||||
DownloadClient.RequestResult requestResult =
|
||||
downloadClient.MakeRequest(url, 1);
|
||||
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
||||
return Array.Empty<Publication>();
|
||||
|
||||
ret.Add(ParseSinglePublicationFromHtml(requestResult.result, url.Split('/')[^1]));
|
||||
}
|
||||
|
||||
return ret.ToArray();
|
||||
}
|
||||
|
||||
private Publication ParseSinglePublicationFromHtml(Stream html, string publicationId)
|
||||
{
|
||||
StreamReader reader = new (html);
|
||||
string htmlString = reader.ReadToEnd();
|
||||
HtmlDocument document = new ();
|
||||
document.LoadHtml(htmlString);
|
||||
string status = "";
|
||||
Dictionary<string, string> altTitles = new();
|
||||
Dictionary<string, string>? links = null;
|
||||
HashSet<string> tags = new();
|
||||
string[] authors = Array.Empty<string>();
|
||||
string originalLanguage = "";
|
||||
|
||||
HtmlNode infoNode = document.DocumentNode.Descendants("div").First(d => d.HasClass("story-info-right"));
|
||||
|
||||
string sortName = infoNode.Descendants("h1").First().InnerText;
|
||||
|
||||
HtmlNode infoTable = infoNode.Descendants().First(d => d.Name == "table");
|
||||
|
||||
foreach (HtmlNode row in infoTable.Descendants("tr"))
|
||||
{
|
||||
string key = row.SelectNodes("td").First().InnerText.ToLower();
|
||||
string value = row.SelectNodes("td").Last().InnerText;
|
||||
string keySanitized = string.Concat(Regex.Matches(key, "[a-z]"));
|
||||
|
||||
switch (keySanitized)
|
||||
{
|
||||
case "alternative":
|
||||
string[] alts = value.Split(" ; ");
|
||||
for(int i = 0; i < alts.Length; i++)
|
||||
altTitles.Add(i.ToString(), alts[i]);
|
||||
break;
|
||||
case "authors":
|
||||
authors = value.Split('-');
|
||||
break;
|
||||
case "status":
|
||||
status = value;
|
||||
break;
|
||||
case "genres":
|
||||
string[] genres = value.Split(" - ");
|
||||
tags = genres.ToHashSet();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
string posterUrl = document.DocumentNode.Descendants("span").First(s => s.HasClass("info-image")).Descendants("img").First()
|
||||
.GetAttributes().First(a => a.Name == "src").Value;
|
||||
|
||||
string coverFileNameInCache = SaveCoverImageToCache(posterUrl, 1);
|
||||
|
||||
string description = document.DocumentNode.Descendants("div").First(d => d.HasClass("panel-story-info-description"))
|
||||
.InnerText.Replace("Description :", "");
|
||||
while (description.StartsWith('\n'))
|
||||
description = description.Substring(1);
|
||||
|
||||
string yearString = document.DocumentNode.Descendants("li").Last(li => li.HasClass("a-h")).Descendants("span")
|
||||
.First(s => s.HasClass("chapter-time")).InnerText;
|
||||
int year = Convert.ToInt32(yearString.Split(',')[^1]) + 2000;
|
||||
|
||||
return new Publication(sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl, coverFileNameInCache, links,
|
||||
year, originalLanguage, status, publicationId);
|
||||
}
|
||||
|
||||
public override Chapter[] GetChapters(Publication publication, string language = "")
|
||||
{
|
||||
Log($"Getting chapters {publication}");
|
||||
string requestUrl = $"https://chapmanganato.com/{publication.publicationId}";
|
||||
DownloadClient.RequestResult requestResult =
|
||||
downloadClient.MakeRequest(requestUrl, 1);
|
||||
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
||||
return Array.Empty<Chapter>();
|
||||
|
||||
//Return Chapters ordered by Chapter-Number
|
||||
NumberFormatInfo chapterNumberFormatInfo = new()
|
||||
{
|
||||
NumberDecimalSeparator = "."
|
||||
};
|
||||
List<Chapter> chapters = ParseChaptersFromHtml(publication, requestResult.result);
|
||||
Log($"Got {chapters.Count} chapters. {publication}");
|
||||
return chapters.OrderBy(chapter => Convert.ToSingle(chapter.chapterNumber, chapterNumberFormatInfo)).ToArray();
|
||||
}
|
||||
|
||||
private List<Chapter> ParseChaptersFromHtml(Publication publication, Stream html)
|
||||
{
|
||||
StreamReader reader = new (html);
|
||||
string htmlString = reader.ReadToEnd();
|
||||
HtmlDocument document = new ();
|
||||
document.LoadHtml(htmlString);
|
||||
List<Chapter> ret = new();
|
||||
|
||||
HtmlNode chapterList = document.DocumentNode.Descendants("ul").First(l => l.HasClass("row-content-chapter"));
|
||||
|
||||
foreach (HtmlNode chapterInfo in chapterList.Descendants("li"))
|
||||
{
|
||||
string fullString = chapterInfo.Descendants("a").First(d => d.HasClass("chapter-name")).InnerText;
|
||||
|
||||
string? volumeNumber = fullString.Contains("Vol.") ? fullString.Replace("Vol.", "").Split(' ')[0] : null;
|
||||
string chapterNumber = fullString.Split(':')[0].Split("Chapter ")[1].Replace('-','.');
|
||||
string chapterName = string.Concat(fullString.Split(':')[1..]);
|
||||
string url = chapterInfo.Descendants("a").First(d => d.HasClass("chapter-name"))
|
||||
.GetAttributeValue("href", "");
|
||||
ret.Add(new Chapter(publication, chapterName, volumeNumber, chapterNumber, url));
|
||||
}
|
||||
ret.Reverse();
|
||||
return ret;
|
||||
}
|
||||
|
||||
public override HttpStatusCode DownloadChapter(Chapter chapter, ProgressToken? progressToken = null)
|
||||
{
|
||||
if (progressToken?.cancellationRequested ?? false)
|
||||
return HttpStatusCode.RequestTimeout;
|
||||
Log($"Retrieving chapter-info {chapter} {chapter.parentPublication}");
|
||||
string requestUrl = chapter.url;
|
||||
DownloadClient.RequestResult requestResult =
|
||||
downloadClient.MakeRequest(requestUrl, 1);
|
||||
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
||||
return requestResult.statusCode;
|
||||
|
||||
string[] imageUrls = ParseImageUrlsFromHtml(requestResult.result);
|
||||
|
||||
string comicInfoPath = Path.GetTempFileName();
|
||||
File.WriteAllText(comicInfoPath, chapter.GetComicInfoXmlString());
|
||||
|
||||
return DownloadChapterImages(imageUrls, chapter.GetArchiveFilePath(settings.downloadLocation), 1, comicInfoPath, "https://chapmanganato.com/", progressToken:progressToken);
|
||||
}
|
||||
|
||||
private string[] ParseImageUrlsFromHtml(Stream html)
|
||||
{
|
||||
StreamReader reader = new (html);
|
||||
string htmlString = reader.ReadToEnd();
|
||||
HtmlDocument document = new ();
|
||||
document.LoadHtml(htmlString);
|
||||
List<string> ret = new();
|
||||
|
||||
HtmlNode imageContainer =
|
||||
document.DocumentNode.Descendants("div").First(i => i.HasClass("container-chapter-reader"));
|
||||
foreach(HtmlNode imageNode in imageContainer.Descendants("img"))
|
||||
ret.Add(imageNode.GetAttributeValue("src", ""));
|
||||
|
||||
return ret.ToArray();
|
||||
}
|
||||
}
|
274
Tranga/MangaConnectors/Mangasee.cs
Normal file
274
Tranga/MangaConnectors/Mangasee.cs
Normal file
@ -0,0 +1,274 @@
|
||||
using System.Globalization;
|
||||
using System.Net;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Xml.Linq;
|
||||
using HtmlAgilityPack;
|
||||
using Newtonsoft.Json;
|
||||
using PuppeteerSharp;
|
||||
using Tranga.Jobs;
|
||||
|
||||
namespace Tranga.MangaConnectors;
|
||||
|
||||
public class Mangasee : MangaConnector
|
||||
{
|
||||
public override string name { get; }
|
||||
private IBrowser? _browser;
|
||||
private const string ChromiumVersion = "1154303";
|
||||
|
||||
public Mangasee(GlobalBase clone) : base(clone)
|
||||
{
|
||||
this.name = "Mangasee";
|
||||
this.downloadClient = new DownloadClient(new Dictionary<byte, int>()
|
||||
{
|
||||
{ 1, 60 }
|
||||
}, clone);
|
||||
|
||||
Task d = new Task(DownloadBrowser);
|
||||
d.Start();
|
||||
}
|
||||
|
||||
private async void DownloadBrowser()
|
||||
{
|
||||
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.");
|
||||
this._browser = await Puppeteer.LaunchAsync(new LaunchOptions
|
||||
{
|
||||
Headless = true,
|
||||
ExecutablePath = browserFetcher.GetExecutablePath(ChromiumVersion),
|
||||
Args = new [] {
|
||||
"--disable-gpu",
|
||||
"--disable-dev-shm-usage",
|
||||
"--disable-setuid-sandbox",
|
||||
"--no-sandbox"}
|
||||
});
|
||||
}
|
||||
|
||||
protected override Publication[] GetPublications(string publicationTitle = "")
|
||||
{
|
||||
Log($"Searching Publications. Term=\"{publicationTitle}\"");
|
||||
string requestUrl = $"https://mangasee123.com/_search.php";
|
||||
DownloadClient.RequestResult requestResult =
|
||||
downloadClient.MakeRequest(requestUrl, 1);
|
||||
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
||||
return Array.Empty<Publication>();
|
||||
|
||||
return ParsePublicationsFromHtml(requestResult.result, publicationTitle);
|
||||
}
|
||||
|
||||
private Publication[] ParsePublicationsFromHtml(Stream html, string publicationTitle)
|
||||
{
|
||||
string jsonString = new StreamReader(html).ReadToEnd();
|
||||
List<SearchResultItem> result = JsonConvert.DeserializeObject<List<SearchResultItem>>(jsonString)!;
|
||||
Dictionary<SearchResultItem, int> queryFiltered = new();
|
||||
foreach (SearchResultItem resultItem in result)
|
||||
{
|
||||
int matches = resultItem.GetMatches(publicationTitle);
|
||||
if (matches > 0)
|
||||
queryFiltered.TryAdd(resultItem, matches);
|
||||
}
|
||||
|
||||
queryFiltered = queryFiltered.Where(item => item.Value >= publicationTitle.Split(' ').Length - 1)
|
||||
.ToDictionary(item => item.Key, item => item.Value);
|
||||
|
||||
Log($"Retrieved {queryFiltered.Count} publications.");
|
||||
|
||||
HashSet<Publication> ret = new();
|
||||
List<SearchResultItem> orderedFiltered =
|
||||
queryFiltered.OrderBy(item => item.Value).ToDictionary(item => item.Key, item => item.Value).Keys.ToList();
|
||||
|
||||
uint index = 1;
|
||||
foreach (SearchResultItem orderedItem in orderedFiltered)
|
||||
{
|
||||
DownloadClient.RequestResult requestResult =
|
||||
downloadClient.MakeRequest($"https://mangasee123.com/manga/{orderedItem.i}", 1);
|
||||
if ((int)requestResult.statusCode >= 200 || (int)requestResult.statusCode < 300)
|
||||
{
|
||||
Log($"Retrieving Publication info: {orderedItem.s} {index++}/{orderedFiltered.Count}");
|
||||
ret.Add(ParseSinglePublicationFromHtml(requestResult.result, orderedItem.s, orderedItem.i, orderedItem.a));
|
||||
}
|
||||
}
|
||||
return ret.ToArray();
|
||||
}
|
||||
|
||||
|
||||
private Publication ParseSinglePublicationFromHtml(Stream html, string sortName, string publicationId, string[] a)
|
||||
{
|
||||
StreamReader reader = new (html);
|
||||
HtmlDocument document = new ();
|
||||
document.LoadHtml(reader.ReadToEnd());
|
||||
|
||||
string originalLanguage = "", status = "";
|
||||
Dictionary<string, string> altTitles = new(), links = new();
|
||||
HashSet<string> tags = new();
|
||||
|
||||
HtmlNode posterNode =
|
||||
document.DocumentNode.Descendants("img").First(img => img.HasClass("img-fluid") && img.HasClass("bottom-5"));
|
||||
string posterUrl = posterNode.GetAttributeValue("src", "");
|
||||
string coverFileNameInCache = SaveCoverImageToCache(posterUrl, 1);
|
||||
|
||||
HtmlNode attributes = document.DocumentNode.Descendants("div")
|
||||
.First(div => div.HasClass("col-md-9") && div.HasClass("col-sm-8") && div.HasClass("top-5"))
|
||||
.Descendants("ul").First();
|
||||
|
||||
HtmlNode[] authorsNodes = attributes.Descendants("li")
|
||||
.First(node => node.InnerText.Contains("author(s):", StringComparison.CurrentCultureIgnoreCase))
|
||||
.Descendants("a").ToArray();
|
||||
List<string> authors = new();
|
||||
foreach(HtmlNode authorNode in authorsNodes)
|
||||
authors.Add(authorNode.InnerText);
|
||||
|
||||
HtmlNode[] genreNodes = attributes.Descendants("li")
|
||||
.First(node => node.InnerText.Contains("genre(s):", StringComparison.CurrentCultureIgnoreCase))
|
||||
.Descendants("a").ToArray();
|
||||
foreach (HtmlNode genreNode in genreNodes)
|
||||
tags.Add(genreNode.InnerText);
|
||||
|
||||
HtmlNode yearNode = attributes.Descendants("li")
|
||||
.First(node => node.InnerText.Contains("released:", StringComparison.CurrentCultureIgnoreCase))
|
||||
.Descendants("a").First();
|
||||
int year = Convert.ToInt32(yearNode.InnerText);
|
||||
|
||||
HtmlNode[] statusNodes = attributes.Descendants("li")
|
||||
.First(node => node.InnerText.Contains("status:", StringComparison.CurrentCultureIgnoreCase))
|
||||
.Descendants("a").ToArray();
|
||||
foreach(HtmlNode statusNode in statusNodes)
|
||||
if (statusNode.InnerText.Contains("publish", StringComparison.CurrentCultureIgnoreCase))
|
||||
status = statusNode.InnerText.Split(' ')[0];
|
||||
|
||||
HtmlNode descriptionNode = attributes.Descendants("li").First(node => node.InnerText.Contains("description:", StringComparison.CurrentCultureIgnoreCase)).Descendants("div").First();
|
||||
string description = descriptionNode.InnerText;
|
||||
|
||||
int i = 0;
|
||||
foreach(string at in a)
|
||||
altTitles.Add((i++).ToString(), at);
|
||||
|
||||
return new Publication(sortName, authors, description, altTitles, tags.ToArray(), posterUrl, coverFileNameInCache, links,
|
||||
year, originalLanguage, status, publicationId);
|
||||
}
|
||||
|
||||
// ReSharper disable once ClassNeverInstantiated.Local Will be instantiated during deserialization
|
||||
private class SearchResultItem
|
||||
{
|
||||
public string i { get; init; }
|
||||
public string s { get; init; }
|
||||
public string[] a { get; init; }
|
||||
|
||||
[JsonConstructor]
|
||||
public SearchResultItem(string i, string s, string[] a)
|
||||
{
|
||||
this.i = i;
|
||||
this.s = s;
|
||||
this.a = a;
|
||||
}
|
||||
|
||||
public int GetMatches(string title)
|
||||
{
|
||||
int ret = 0;
|
||||
Regex cleanRex = new("[A-z0-9]*");
|
||||
string[] badWords = { "a", "an", "no", "ni", "so", "as", "and", "the", "of", "that", "in", "is", "for" };
|
||||
|
||||
string[] titleTerms = title.Split(new[] { ' ', '-' }).Where(str => !badWords.Contains(str)).ToArray();
|
||||
|
||||
foreach (Match matchTerm in cleanRex.Matches(this.i))
|
||||
ret += titleTerms.Count(titleTerm =>
|
||||
titleTerm.Equals(matchTerm.Value, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
foreach (Match matchTerm in cleanRex.Matches(this.s))
|
||||
ret += titleTerms.Count(titleTerm =>
|
||||
titleTerm.Equals(matchTerm.Value, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
foreach(string alt in this.a)
|
||||
foreach (Match matchTerm in cleanRex.Matches(alt))
|
||||
ret += titleTerms.Count(titleTerm =>
|
||||
titleTerm.Equals(matchTerm.Value, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
public override Chapter[] GetChapters(Publication publication, string language = "")
|
||||
{
|
||||
Log($"Getting chapters {publication}");
|
||||
XDocument doc = XDocument.Load($"https://mangasee123.com/rss/{publication.publicationId}.xml");
|
||||
XElement[] chapterItems = doc.Descendants("item").ToArray();
|
||||
List<Chapter> chapters = new();
|
||||
foreach (XElement chapter in chapterItems)
|
||||
{
|
||||
string volumeNumber = "1";
|
||||
string chapterName = chapter.Descendants("title").First().Value;
|
||||
string chapterNumber = Regex.Matches(chapterName, "[0-9]+")[^1].ToString();
|
||||
|
||||
string url = chapter.Descendants("link").First().Value;
|
||||
url = url.Replace(Regex.Matches(url,"(-page-[0-9])")[0].ToString(),"");
|
||||
chapters.Add(new Chapter(publication, "", volumeNumber, chapterNumber, url));
|
||||
}
|
||||
|
||||
//Return Chapters ordered by Chapter-Number
|
||||
NumberFormatInfo chapterNumberFormatInfo = new()
|
||||
{
|
||||
NumberDecimalSeparator = "."
|
||||
};
|
||||
Log($"Got {chapters.Count} chapters. {publication}");
|
||||
return chapters.OrderBy(chapter => Convert.ToSingle(chapter.chapterNumber, chapterNumberFormatInfo)).ToArray();
|
||||
}
|
||||
|
||||
public override HttpStatusCode DownloadChapter(Chapter chapter, ProgressToken? progressToken = null)
|
||||
{
|
||||
if (progressToken?.cancellationRequested ?? false)
|
||||
return HttpStatusCode.RequestTimeout;
|
||||
while (this._browser is null && !(progressToken?.cancellationRequested??false))
|
||||
{
|
||||
Log("Waiting for headless browser to download...");
|
||||
Thread.Sleep(1000);
|
||||
}
|
||||
if (progressToken?.cancellationRequested??false)
|
||||
return HttpStatusCode.RequestTimeout;
|
||||
|
||||
Log($"Retrieving chapter-info {chapter} {chapter.parentPublication}");
|
||||
IPage page = _browser!.NewPageAsync().Result;
|
||||
IResponse response = page.GoToAsync(chapter.url).Result;
|
||||
if (response.Ok)
|
||||
{
|
||||
HtmlDocument document = new ();
|
||||
document.LoadHtml(page.GetContentAsync().Result);
|
||||
|
||||
HtmlNode gallery = document.DocumentNode.Descendants("div").First(div => div.HasClass("ImageGallery"));
|
||||
HtmlNode[] images = gallery.Descendants("img").Where(img => img.HasClass("img-fluid")).ToArray();
|
||||
List<string> urls = new();
|
||||
foreach(HtmlNode galleryImage in images)
|
||||
urls.Add(galleryImage.GetAttributeValue("src", ""));
|
||||
|
||||
string comicInfoPath = Path.GetTempFileName();
|
||||
File.WriteAllText(comicInfoPath, chapter.GetComicInfoXmlString());
|
||||
|
||||
return DownloadChapterImages(urls.ToArray(), chapter.GetArchiveFilePath(settings.downloadLocation), 1, comicInfoPath, progressToken:progressToken);
|
||||
}
|
||||
return response.Status;
|
||||
}
|
||||
}
|
51
Tranga/NotificationConnectors/Gotify.cs
Normal file
51
Tranga/NotificationConnectors/Gotify.cs
Normal file
@ -0,0 +1,51 @@
|
||||
using System.Text;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Tranga.NotificationConnectors;
|
||||
|
||||
public class Gotify : NotificationConnector
|
||||
{
|
||||
public string endpoint { get; }
|
||||
// ReSharper disable once MemberCanBePrivate.Global
|
||||
public string appToken { get; }
|
||||
private readonly HttpClient _client = new();
|
||||
|
||||
[JsonConstructor]
|
||||
public Gotify(string endpoint, string appToken, GlobalBase clone) : base(NotificationManagerType.Gotify, clone)
|
||||
{
|
||||
this.endpoint = endpoint;
|
||||
this.appToken = appToken;
|
||||
}
|
||||
|
||||
public override void SendNotification(string title, string notificationText)
|
||||
{
|
||||
Log($"Sending notification: {title} - {notificationText}");
|
||||
MessageData message = new(title, notificationText);
|
||||
HttpRequestMessage request = new(HttpMethod.Post, $"{endpoint}/message");
|
||||
request.Headers.Add("X-Gotify-Key", this.appToken);
|
||||
request.Content = new StringContent(JsonConvert.SerializeObject(message, Formatting.None), Encoding.UTF8, "application/json");
|
||||
HttpResponseMessage response = _client.Send(request);
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
StreamReader sr = new (response.Content.ReadAsStream());
|
||||
logger?.WriteLine(this.GetType().ToString(), $"{response.StatusCode}: {sr.ReadToEnd()}");
|
||||
}
|
||||
}
|
||||
|
||||
private class MessageData
|
||||
{
|
||||
// ReSharper disable four times UnusedAutoPropertyAccessor.Local
|
||||
public string message { get; }
|
||||
public long priority { get; }
|
||||
public string title { get; }
|
||||
public Dictionary<string, object> extras { get; }
|
||||
|
||||
public MessageData(string title, string message)
|
||||
{
|
||||
this.title = title;
|
||||
this.message = message;
|
||||
this.extras = new();
|
||||
this.priority = 4;
|
||||
}
|
||||
}
|
||||
}
|
44
Tranga/NotificationConnectors/LunaSea.cs
Normal file
44
Tranga/NotificationConnectors/LunaSea.cs
Normal file
@ -0,0 +1,44 @@
|
||||
using System.Text;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Tranga.NotificationConnectors;
|
||||
|
||||
public class LunaSea : NotificationConnector
|
||||
{
|
||||
// ReSharper disable once MemberCanBePrivate.Global
|
||||
public string id { get; init; }
|
||||
private readonly HttpClient _client = new();
|
||||
|
||||
[JsonConstructor]
|
||||
public LunaSea(string id, GlobalBase clone) : base(NotificationManagerType.LunaSea, clone)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public override void SendNotification(string title, string notificationText)
|
||||
{
|
||||
Log($"Sending notification: {title} - {notificationText}");
|
||||
MessageData message = new(title, notificationText);
|
||||
HttpRequestMessage request = new(HttpMethod.Post, $"https://notify.lunasea.app/v1/custom/{id}");
|
||||
request.Content = new StringContent(JsonConvert.SerializeObject(message, Formatting.None), Encoding.UTF8, "application/json");
|
||||
HttpResponseMessage response = _client.Send(request);
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
StreamReader sr = new (response.Content.ReadAsStream());
|
||||
Log($"{response.StatusCode}: {sr.ReadToEnd()}");
|
||||
}
|
||||
}
|
||||
|
||||
private class MessageData
|
||||
{
|
||||
// ReSharper disable twice UnusedAutoPropertyAccessor.Local
|
||||
public string title { get; }
|
||||
public string body { get; }
|
||||
|
||||
public MessageData(string title, string body)
|
||||
{
|
||||
this.title = title;
|
||||
this.body = body;
|
||||
}
|
||||
}
|
||||
}
|
15
Tranga/NotificationConnectors/NotificationConnector.cs
Normal file
15
Tranga/NotificationConnectors/NotificationConnector.cs
Normal file
@ -0,0 +1,15 @@
|
||||
namespace Tranga.NotificationConnectors;
|
||||
|
||||
public abstract class NotificationConnector : GlobalBase
|
||||
{
|
||||
public NotificationManagerType notificationManagerType;
|
||||
|
||||
protected NotificationConnector(NotificationManagerType notificationManagerType, GlobalBase clone) : base(clone)
|
||||
{
|
||||
this.notificationManagerType = notificationManagerType;
|
||||
}
|
||||
|
||||
public enum NotificationManagerType : byte { Gotify = 0, LunaSea = 1 }
|
||||
|
||||
public abstract void SendNotification(string title, string notificationText);
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Tranga.NotificationConnectors;
|
||||
|
||||
public class NotificationManagerJsonConverter : JsonConverter
|
||||
{
|
||||
public override bool CanConvert(Type objectType)
|
||||
{
|
||||
return (objectType == typeof(NotificationConnector));
|
||||
}
|
||||
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object? existingValue,
|
||||
JsonSerializer serializer)
|
||||
{
|
||||
JObject jo = JObject.Load(reader);
|
||||
if (jo["notificationManagerType"]!.Value<byte>() == (byte)NotificationConnector.NotificationManagerType.Gotify)
|
||||
return jo.ToObject<Gotify>(serializer)!;
|
||||
else if (jo["notificationManagerType"]!.Value<byte>() == (byte)NotificationConnector.NotificationManagerType.LunaSea)
|
||||
return jo.ToObject<LunaSea>(serializer)!;
|
||||
|
||||
throw new Exception();
|
||||
}
|
||||
|
||||
public override bool CanWrite => false;
|
||||
|
||||
/// <summary>
|
||||
/// Don't call this
|
||||
/// </summary>
|
||||
public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer)
|
||||
{
|
||||
throw new Exception("Dont call this");
|
||||
}
|
||||
}
|
@ -1,43 +1,85 @@
|
||||
using Newtonsoft.Json;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using Newtonsoft.Json;
|
||||
using static System.IO.UnixFileMode;
|
||||
|
||||
namespace Tranga;
|
||||
|
||||
/// <summary>
|
||||
/// Contains information on a Publication (Manga)
|
||||
/// </summary>
|
||||
public readonly struct Publication
|
||||
public struct Publication
|
||||
{
|
||||
public string sortName { get; }
|
||||
// ReSharper disable UnusedAutoPropertyAccessor.Global we need it, trust
|
||||
[JsonIgnore]public string[,] altTitles { get; }
|
||||
// ReSharper disable trice MemberCanBePrivate.Global, trust
|
||||
public List<string> authors { get; }
|
||||
// ReSharper disable once UnusedAutoPropertyAccessor.Global
|
||||
public Dictionary<string,string> altTitles { get; }
|
||||
// ReSharper disable once MemberCanBePrivate.Global
|
||||
public string? description { get; }
|
||||
public string[] tags { get; }
|
||||
// ReSharper disable once UnusedAutoPropertyAccessor.Global
|
||||
public string? posterUrl { get; }
|
||||
[JsonIgnore]public string[,]? links { get; }
|
||||
public string? coverFileNameInCache { get; }
|
||||
// ReSharper disable once UnusedAutoPropertyAccessor.Global
|
||||
public Dictionary<string,string> links { get; }
|
||||
// ReSharper disable once MemberCanBePrivate.Global
|
||||
public int? year { get; }
|
||||
public string? originalLanguage { get; }
|
||||
// ReSharper disable once MemberCanBePrivate.Global
|
||||
public string status { get; }
|
||||
public string folderName { get; }
|
||||
public string downloadUrl { get; }
|
||||
public string publicationId { get; }
|
||||
public string internalId { get; }
|
||||
public float ignoreChaptersBelow { get; set; }
|
||||
|
||||
public Publication(string sortName, string? description, string[,] altTitles, string[] tags, string? posterUrl, string[,]? links, int? year, string? originalLanguage, string status, string downloadUrl)
|
||||
private static readonly Regex LegalCharacters = new (@"[A-Z]*[a-z]*[0-9]* *\.*-*,*'*\'*\)*\(*~*!*");
|
||||
|
||||
[JsonConstructor]
|
||||
public Publication(string sortName, List<string> authors, string? description, Dictionary<string,string> altTitles, string[] tags, string? posterUrl, string? coverFileNameInCache, Dictionary<string,string>? links, int? year, string? originalLanguage, string status, string publicationId, string? folderName = null, float? ignoreChaptersBelow = 0)
|
||||
{
|
||||
this.sortName = sortName;
|
||||
this.authors = authors;
|
||||
this.description = description;
|
||||
this.altTitles = altTitles;
|
||||
this.tags = tags;
|
||||
this.coverFileNameInCache = coverFileNameInCache;
|
||||
this.posterUrl = posterUrl;
|
||||
this.links = links;
|
||||
this.links = links ?? new Dictionary<string, string>();
|
||||
this.year = year;
|
||||
this.originalLanguage = originalLanguage;
|
||||
this.status = status;
|
||||
this.downloadUrl = downloadUrl;
|
||||
this.folderName = string.Concat(sortName.Split(Path.GetInvalidPathChars().Concat(Path.GetInvalidFileNameChars()).ToArray()));
|
||||
this.publicationId = publicationId;
|
||||
this.folderName = folderName ?? string.Concat(LegalCharacters.Matches(sortName));
|
||||
while (this.folderName.EndsWith('.'))
|
||||
this.folderName = this.folderName.Substring(0, this.folderName.Length - 1);
|
||||
string onlyLowerLetters = string.Concat(this.sortName.ToLower().Where(Char.IsLetter));
|
||||
this.internalId = Convert.ToBase64String(Encoding.ASCII.GetBytes($"{onlyLowerLetters}{this.year}"));
|
||||
this.ignoreChaptersBelow = ignoreChaptersBelow ?? 0f;
|
||||
}
|
||||
|
||||
public string CreatePublicationFolder(string downloadDirectory)
|
||||
{
|
||||
string publicationFolder = Path.Join(downloadDirectory, this.folderName);
|
||||
if(!Directory.Exists(publicationFolder))
|
||||
Directory.CreateDirectory(publicationFolder);
|
||||
if(RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||
File.SetUnixFileMode(publicationFolder, GroupRead | GroupWrite | GroupExecute | OtherRead | OtherWrite | OtherExecute | UserRead | UserWrite | UserExecute);
|
||||
return publicationFolder;
|
||||
}
|
||||
|
||||
public void SaveSeriesInfoJson(string downloadDirectory)
|
||||
{
|
||||
string publicationFolder = CreatePublicationFolder(downloadDirectory);
|
||||
string seriesInfoPath = Path.Join(publicationFolder, "series.json");
|
||||
if(!File.Exists(seriesInfoPath))
|
||||
File.WriteAllText(seriesInfoPath,this.GetSeriesInfoJson());
|
||||
if(RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||
File.SetUnixFileMode(seriesInfoPath, GroupRead | GroupWrite | OtherRead | OtherWrite | UserRead | UserWrite);
|
||||
}
|
||||
|
||||
/// <returns>Serialized JSON String for series.json</returns>
|
||||
public string GetSeriesInfoJson()
|
||||
private string GetSeriesInfoJson()
|
||||
{
|
||||
SeriesInfo si = new (new Metadata(this.sortName, this.year.ToString() ?? string.Empty, this.status, this.description ?? ""));
|
||||
return System.Text.Json.JsonSerializer.Serialize(si);
|
||||
@ -73,9 +115,9 @@ public readonly struct Publication
|
||||
{
|
||||
this.name = name;
|
||||
this.year = year;
|
||||
if(status == "ongoing" || status == "hiatus")
|
||||
if(status.ToLower() == "ongoing" || status.ToLower() == "hiatus")
|
||||
this.status = "Continuing";
|
||||
else if (status == "completed" || status == "cancelled")
|
||||
else if (status.ToLower() == "completed" || status.ToLower() == "cancelled" || status.ToLower() == "discontinued")
|
||||
this.status = "Ended";
|
||||
else
|
||||
this.status = status;
|
||||
|
75
Tranga/Server.cs
Normal file
75
Tranga/Server.cs
Normal file
@ -0,0 +1,75 @@
|
||||
using System.Net;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Tranga;
|
||||
|
||||
public class Server : GlobalBase
|
||||
{
|
||||
private readonly HttpListener _listener = new ();
|
||||
private readonly Tranga _parent;
|
||||
|
||||
public Server(Tranga parent) : base(parent)
|
||||
{
|
||||
this._parent = parent;
|
||||
if(RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||
this._listener.Prefixes.Add($"http://*:{settings.apiPortNumber}/");
|
||||
else
|
||||
this._listener.Prefixes.Add($"http://localhost:{settings.apiPortNumber}/");
|
||||
Thread t = new (Listen);
|
||||
t.Start();
|
||||
}
|
||||
|
||||
private void Listen()
|
||||
{
|
||||
this._listener.Start();
|
||||
foreach(string prefix in this._listener.Prefixes)
|
||||
Log($"Listening on {prefix}");
|
||||
while (this._listener.IsListening && _parent.keepRunning)
|
||||
{
|
||||
HttpListenerContext context = this._listener.GetContextAsync().Result;
|
||||
Log($"{context.Request.HttpMethod} {context.Request.Url} {context.Request.UserAgent}");
|
||||
Task t = new(() =>
|
||||
{
|
||||
if(context.Request.HttpMethod == "OPTIONS")
|
||||
SendResponse(HttpStatusCode.OK, context.Response);
|
||||
else
|
||||
HandleRequest(context);
|
||||
});
|
||||
t.Start();
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleRequest(HttpListenerContext context)
|
||||
{
|
||||
HttpListenerRequest request = context.Request;
|
||||
HttpListenerResponse response = context.Response;
|
||||
if(request.Url!.LocalPath.Contains("favicon"))
|
||||
SendResponse(HttpStatusCode.NoContent, response);
|
||||
|
||||
SendResponse(HttpStatusCode.NotFound, response);
|
||||
}
|
||||
|
||||
private void SendResponse(HttpStatusCode statusCode, HttpListenerResponse response, object? content = null)
|
||||
{
|
||||
//logger?.WriteLine(this.GetType().ToString(), $"Sending response: {statusCode}");
|
||||
response.StatusCode = (int)statusCode;
|
||||
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-Max-Age", "1728000");
|
||||
response.AppendHeader("Access-Control-Allow-Origin", "*");
|
||||
response.ContentType = "application/json";
|
||||
try
|
||||
{
|
||||
response.OutputStream.Write(content is not null
|
||||
? Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(content))
|
||||
: Array.Empty<byte>());
|
||||
response.OutputStream.Close();
|
||||
}
|
||||
catch (HttpListenerException)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -1,121 +0,0 @@
|
||||
namespace Tranga;
|
||||
|
||||
/// <summary>
|
||||
/// Executes TrangaTasks
|
||||
/// Based on the TrangaTask.Task a method is called.
|
||||
/// The chapterCollection is updated with new Publications/Chapters.
|
||||
/// </summary>
|
||||
public static class TaskExecutor
|
||||
{
|
||||
/// <summary>
|
||||
/// Executes TrangaTask.
|
||||
/// </summary>
|
||||
/// <param name="taskManager">Parent</param>
|
||||
/// <param name="trangaTask">Task to execute</param>
|
||||
/// <param name="chapterCollection">Current chapterCollection to update</param>
|
||||
/// <exception cref="ArgumentException">Is thrown when there is no Connector available with the name of the TrangaTask.connectorName</exception>
|
||||
public static void Execute(TaskManager taskManager, TrangaTask trangaTask, Dictionary<Publication, List<Chapter>> chapterCollection)
|
||||
{
|
||||
//Only execute task if it is not already being executed.
|
||||
if (trangaTask.state == TrangaTask.ExecutionState.Running)
|
||||
return;
|
||||
trangaTask.state = TrangaTask.ExecutionState.Running;
|
||||
|
||||
//Connector is not needed for all tasks
|
||||
Connector? connector = null;
|
||||
if (trangaTask.task != TrangaTask.Task.UpdateKomgaLibrary)
|
||||
connector = taskManager.GetConnector(trangaTask.connectorName!);
|
||||
|
||||
//Call appropriate Method based on TrangaTask.Task
|
||||
switch (trangaTask.task)
|
||||
{
|
||||
case TrangaTask.Task.DownloadNewChapters:
|
||||
DownloadNewChapters(connector!, (Publication)trangaTask.publication!, trangaTask.language, chapterCollection);
|
||||
break;
|
||||
case TrangaTask.Task.UpdateChapters:
|
||||
UpdateChapters(connector!, (Publication)trangaTask.publication!, trangaTask.language, chapterCollection);
|
||||
break;
|
||||
case TrangaTask.Task.UpdatePublications:
|
||||
UpdatePublications(connector!, chapterCollection);
|
||||
break;
|
||||
case TrangaTask.Task.UpdateKomgaLibrary:
|
||||
UpdateKomgaLibrary(taskManager);
|
||||
break;
|
||||
}
|
||||
|
||||
trangaTask.state = TrangaTask.ExecutionState.Waiting;
|
||||
trangaTask.lastExecuted = DateTime.Now;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates all Komga-Libraries
|
||||
/// </summary>
|
||||
/// <param name="taskManager">Parent</param>
|
||||
private static void UpdateKomgaLibrary(TaskManager taskManager)
|
||||
{
|
||||
if (taskManager.komga is null)
|
||||
return;
|
||||
Komga komga = taskManager.komga;
|
||||
|
||||
Komga.KomgaLibrary[] allLibraries = komga.GetLibraries();
|
||||
foreach (Komga.KomgaLibrary lib in allLibraries)
|
||||
komga.UpdateLibrary(lib.id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the available Publications from a Connector (all of them)
|
||||
/// </summary>
|
||||
/// <param name="connector">Connector to receive Publications from</param>
|
||||
/// <param name="chapterCollection"></param>
|
||||
private static void UpdatePublications(Connector connector, Dictionary<Publication, List<Chapter>> chapterCollection)
|
||||
{
|
||||
Publication[] publications = connector.GetPublications();
|
||||
foreach (Publication publication in publications)
|
||||
chapterCollection.TryAdd(publication, new List<Chapter>());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks for new Chapters and Downloads new ones.
|
||||
/// If no Chapters had been downloaded previously, download also cover and create series.json
|
||||
/// </summary>
|
||||
/// <param name="connector">Connector to use</param>
|
||||
/// <param name="publication">Publication to check</param>
|
||||
/// <param name="language">Language to receive chapters for</param>
|
||||
/// <param name="chapterCollection"></param>
|
||||
private static void DownloadNewChapters(Connector connector, Publication publication, string language, Dictionary<Publication, List<Chapter>> chapterCollection)
|
||||
{
|
||||
List<Chapter> newChapters = UpdateChapters(connector, publication, language, chapterCollection);
|
||||
connector.DownloadCover(publication);
|
||||
|
||||
//Check if Publication already has a Folder and a series.json
|
||||
string publicationFolder = Path.Join(connector.downloadLocation, publication.folderName);
|
||||
if(!Directory.Exists(publicationFolder))
|
||||
Directory.CreateDirectory(publicationFolder);
|
||||
|
||||
string seriesInfoPath = Path.Join(publicationFolder, "series.json");
|
||||
if(!File.Exists(seriesInfoPath))
|
||||
File.WriteAllText(seriesInfoPath,publication.GetSeriesInfoJson());
|
||||
|
||||
foreach(Chapter newChapter in newChapters)
|
||||
connector.DownloadChapter(publication, newChapter);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the available Chapters of a Publication
|
||||
/// </summary>
|
||||
/// <param name="connector">Connector to use</param>
|
||||
/// <param name="publication">Publication to check</param>
|
||||
/// <param name="language">Language to receive chapters for</param>
|
||||
/// <param name="chapterCollection"></param>
|
||||
/// <returns>List of Chapters that were previously not in collection</returns>
|
||||
private static List<Chapter> UpdateChapters(Connector connector, Publication publication, string language, Dictionary<Publication, List<Chapter>> chapterCollection)
|
||||
{
|
||||
List<Chapter> newChaptersList = new();
|
||||
chapterCollection.TryAdd(publication, newChaptersList); //To ensure publication is actually in collection
|
||||
|
||||
Chapter[] newChapters = connector.GetChapters(publication, language);
|
||||
newChaptersList = newChapters.Where(nChapter => !connector.ChapterIsDownloaded(publication, nChapter)).ToList();
|
||||
|
||||
return newChaptersList;
|
||||
}
|
||||
}
|
@ -1,257 +0,0 @@
|
||||
using Newtonsoft.Json;
|
||||
using Tranga.Connectors;
|
||||
|
||||
namespace Tranga;
|
||||
|
||||
/// <summary>
|
||||
/// Manages all TrangaTasks.
|
||||
/// Provides a Threaded environment to execute Tasks, and still manage the Task-Collection
|
||||
/// </summary>
|
||||
public class TaskManager
|
||||
{
|
||||
private readonly Dictionary<Publication, List<Chapter>> _chapterCollection = new();
|
||||
private readonly HashSet<TrangaTask> _allTasks;
|
||||
private bool _continueRunning = true;
|
||||
private readonly Connector[] _connectors;
|
||||
private Dictionary<Connector, List<TrangaTask>> tasksToExecute = new();
|
||||
private string downloadLocation { get; }
|
||||
|
||||
public Komga? komga { get; private set; }
|
||||
|
||||
/// <param name="folderPath">Local path to save data (Manga) to</param>
|
||||
/// <param name="komgaBaseUrl">The Url of the Komga-instance that you want to update</param>
|
||||
/// <param name="komgaUsername">The Komga username</param>
|
||||
/// <param name="komgaPassword">The Komga password</param>
|
||||
public TaskManager(string folderPath, string? komgaBaseUrl = null, string? komgaUsername = null, string? komgaPassword = null)
|
||||
{
|
||||
this.downloadLocation = folderPath;
|
||||
|
||||
if (komgaBaseUrl != null && komgaUsername != null && komgaPassword != null)
|
||||
this.komga = new Komga(komgaBaseUrl, komgaUsername, komgaPassword);
|
||||
this._connectors = new Connector[]{ new MangaDex(folderPath) };
|
||||
foreach(Connector cConnector in this._connectors)
|
||||
tasksToExecute.Add(cConnector, new List<TrangaTask>());
|
||||
_allTasks = new HashSet<TrangaTask>();
|
||||
|
||||
Thread taskChecker = new(TaskCheckerThread);
|
||||
taskChecker.Start();
|
||||
}
|
||||
|
||||
public TaskManager(SettingsData settings)
|
||||
{
|
||||
this._connectors = new Connector[]{ new MangaDex(settings.downloadLocation) };
|
||||
foreach(Connector cConnector in this._connectors)
|
||||
tasksToExecute.Add(cConnector, new List<TrangaTask>());
|
||||
this.downloadLocation = settings.downloadLocation;
|
||||
this.komga = settings.komga;
|
||||
_allTasks = settings.allTasks;
|
||||
Thread taskChecker = new(TaskCheckerThread);
|
||||
taskChecker.Start();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Runs continuously until shutdown.
|
||||
/// Checks if tasks have to be executed (time elapsed)
|
||||
/// </summary>
|
||||
private void TaskCheckerThread()
|
||||
{
|
||||
while (_continueRunning)
|
||||
{
|
||||
//Check if previous tasks have finished and execute new tasks
|
||||
foreach (KeyValuePair<Connector, List<TrangaTask>> connectorTaskQueue in tasksToExecute)
|
||||
{
|
||||
connectorTaskQueue.Value.RemoveAll(task => task.state == TrangaTask.ExecutionState.Waiting);
|
||||
if (connectorTaskQueue.Value.Count > 0 && !connectorTaskQueue.Value.All(task => task.state is TrangaTask.ExecutionState.Running or TrangaTask.ExecutionState.Waiting))
|
||||
ExecuteTaskNow(connectorTaskQueue.Value.First());
|
||||
}
|
||||
|
||||
//Check if task should be executed
|
||||
//Depending on type execute immediately or enqueue
|
||||
foreach (TrangaTask task in _allTasks.Where(aTask => aTask.ShouldExecute()))
|
||||
{
|
||||
task.state = TrangaTask.ExecutionState.Enqueued;
|
||||
if(task.connectorName is null)
|
||||
ExecuteTaskNow(task);
|
||||
else
|
||||
{
|
||||
tasksToExecute[GetConnector(task.connectorName!)].Add(task);
|
||||
}
|
||||
}
|
||||
Thread.Sleep(1000);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Forces the execution of a given task
|
||||
/// </summary>
|
||||
/// <param name="task">Task to execute</param>
|
||||
public void ExecuteTaskNow(TrangaTask task)
|
||||
{
|
||||
if (!this._allTasks.Contains(task))
|
||||
return;
|
||||
|
||||
Task t = new Task(() =>
|
||||
{
|
||||
TaskExecutor.Execute(this, task, this._chapterCollection);
|
||||
});
|
||||
t.Start();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates and adds a new Task to the task-Collection
|
||||
/// </summary>
|
||||
/// <param name="task">TrangaTask.Task to later execute</param>
|
||||
/// <param name="connectorName">Name of the connector to use</param>
|
||||
/// <param name="publication">Publication to execute Task on, can be null in case of unrelated Task</param>
|
||||
/// <param name="reoccurrence">Time-Interval between Executions</param>
|
||||
/// <param name="language">language, should Task require parameter. Can be empty</param>
|
||||
/// <exception cref="ArgumentException">Is thrown when connectorName is not a available Connector</exception>
|
||||
public TrangaTask AddTask(TrangaTask.Task task, string? connectorName, Publication? publication, TimeSpan reoccurrence,
|
||||
string language = "")
|
||||
{
|
||||
if (task != TrangaTask.Task.UpdateKomgaLibrary && connectorName is null)
|
||||
throw new ArgumentException($"connectorName can not be null for task {task}");
|
||||
|
||||
TrangaTask newTask;
|
||||
if (task == TrangaTask.Task.UpdateKomgaLibrary)
|
||||
{
|
||||
newTask = new TrangaTask(task, null, null, reoccurrence, language);
|
||||
|
||||
//Check if same task already exists
|
||||
// ReSharper disable once SimplifyLinqExpressionUseAll readabilty
|
||||
if (!_allTasks.Any(trangaTask => trangaTask.task == task))
|
||||
{
|
||||
_allTasks.Add(newTask);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//Get appropriate Connector from available Connectors for TrangaTask
|
||||
Connector? connector = _connectors.FirstOrDefault(c => c.name == connectorName);
|
||||
if (connector is null)
|
||||
throw new ArgumentException($"Connector {connectorName} is not a known connector.");
|
||||
|
||||
newTask = new TrangaTask(task, connector.name, publication, reoccurrence, language);
|
||||
|
||||
//Check if same task already exists
|
||||
if (!_allTasks.Any(trangaTask => trangaTask.task == task && trangaTask.connectorName == connector.name &&
|
||||
trangaTask.publication?.downloadUrl == publication?.downloadUrl))
|
||||
{
|
||||
if(task != TrangaTask.Task.UpdatePublications)
|
||||
_chapterCollection.Add((Publication)publication!, new List<Chapter>());
|
||||
_allTasks.Add(newTask);
|
||||
}
|
||||
}
|
||||
ExportData(Directory.GetCurrentDirectory());
|
||||
|
||||
return newTask;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes Task from task-collection
|
||||
/// </summary>
|
||||
/// <param name="task">TrangaTask.Task type</param>
|
||||
/// <param name="connectorName">Name of Connector that was used</param>
|
||||
/// <param name="publication">Publication that was used</param>
|
||||
public void RemoveTask(TrangaTask.Task task, string connectorName, Publication? publication)
|
||||
{
|
||||
_allTasks.RemoveWhere(trangaTask =>
|
||||
trangaTask.task == task && trangaTask.connectorName == connectorName &&
|
||||
trangaTask.publication?.downloadUrl == publication?.downloadUrl);
|
||||
ExportData(Directory.GetCurrentDirectory());
|
||||
}
|
||||
|
||||
/// <returns>All available Connectors</returns>
|
||||
public Dictionary<string, Connector> GetAvailableConnectors()
|
||||
{
|
||||
return this._connectors.ToDictionary(connector => connector.name, connector => connector);
|
||||
}
|
||||
|
||||
/// <returns>All TrangaTasks in task-collection</returns>
|
||||
public TrangaTask[] GetAllTasks()
|
||||
{
|
||||
TrangaTask[] ret = new TrangaTask[_allTasks.Count];
|
||||
_allTasks.CopyTo(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <returns>All added Publications</returns>
|
||||
public Publication[] GetAllPublications()
|
||||
{
|
||||
return this._chapterCollection.Keys.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return Connector with given Name
|
||||
/// </summary>
|
||||
/// <param name="connectorName">Connector-name (exact)</param>
|
||||
/// <exception cref="Exception">If Connector is not available</exception>
|
||||
public Connector GetConnector(string connectorName)
|
||||
{
|
||||
Connector? ret = this._connectors.FirstOrDefault(connector => connector.name == connectorName);
|
||||
if (ret is null)
|
||||
throw new Exception($"Connector {connectorName} is not an available Connector.");
|
||||
return (Connector)ret!;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Shuts down the taskManager.
|
||||
/// </summary>
|
||||
/// <param name="force">If force is true, tasks are aborted.</param>
|
||||
public void Shutdown(bool force = false)
|
||||
{
|
||||
_continueRunning = false;
|
||||
ExportData(Directory.GetCurrentDirectory());
|
||||
|
||||
if(force)
|
||||
Environment.Exit(_allTasks.Count(task => task.state is TrangaTask.ExecutionState.Enqueued or TrangaTask.ExecutionState.Running));
|
||||
|
||||
//Wait for tasks to finish
|
||||
while(_allTasks.Any(task => task.state is TrangaTask.ExecutionState.Running or TrangaTask.ExecutionState.Enqueued))
|
||||
Thread.Sleep(10);
|
||||
Environment.Exit(0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads stored data (settings, tasks) from file
|
||||
/// </summary>
|
||||
/// <param name="importFolderPath">working directory, filename has to be data.json</param>
|
||||
public static SettingsData LoadData(string importFolderPath)
|
||||
{
|
||||
string importPath = Path.Join(importFolderPath, "data.json");
|
||||
if (!File.Exists(importPath))
|
||||
return new SettingsData("", null, new HashSet<TrangaTask>());
|
||||
|
||||
string toRead = File.ReadAllText(importPath);
|
||||
SettingsData data = JsonConvert.DeserializeObject<SettingsData>(toRead)!;
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Exports data (settings, tasks) to file
|
||||
/// </summary>
|
||||
/// <param name="exportFolderPath">Folder path, filename will be data.json</param>
|
||||
private void ExportData(string exportFolderPath)
|
||||
{
|
||||
SettingsData data = new SettingsData(this.downloadLocation, this.komga, this._allTasks);
|
||||
|
||||
string exportPath = Path.Join(exportFolderPath, "data.json");
|
||||
string serializedData = JsonConvert.SerializeObject(data);
|
||||
File.WriteAllText(exportPath, serializedData);
|
||||
}
|
||||
|
||||
public class SettingsData
|
||||
{
|
||||
public string downloadLocation { get; set; }
|
||||
public Komga? komga { get; set; }
|
||||
public HashSet<TrangaTask> allTasks { get; }
|
||||
|
||||
public SettingsData(string downloadLocation, Komga? komga, HashSet<TrangaTask> allTasks)
|
||||
{
|
||||
this.downloadLocation = downloadLocation;
|
||||
this.komga = komga;
|
||||
this.allTasks = allTasks;
|
||||
}
|
||||
}
|
||||
}
|
32
Tranga/Tranga.cs
Normal file
32
Tranga/Tranga.cs
Normal file
@ -0,0 +1,32 @@
|
||||
using Logging;
|
||||
using Tranga.Jobs;
|
||||
|
||||
namespace Tranga;
|
||||
|
||||
public partial class Tranga : GlobalBase
|
||||
{
|
||||
public bool keepRunning;
|
||||
private JobBoss _jobBoss;
|
||||
private Server server;
|
||||
|
||||
public Tranga(Logger? logger, TrangaSettings settings) : base(logger, settings)
|
||||
{
|
||||
keepRunning = true;
|
||||
_jobBoss = new(this);
|
||||
StartJobBoss();
|
||||
this.server = new Server(this);
|
||||
}
|
||||
|
||||
private void StartJobBoss()
|
||||
{
|
||||
Thread t = new (() =>
|
||||
{
|
||||
while (keepRunning)
|
||||
{
|
||||
_jobBoss.CheckJobs();
|
||||
Thread.Sleep(1000);
|
||||
}
|
||||
});
|
||||
t.Start();
|
||||
}
|
||||
}
|
@ -4,10 +4,24 @@
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<OutputType>Exe</OutputType>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="HtmlAgilityPack" Version="1.11.46" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="PuppeteerSharp" Version="10.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Logging\Logging.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="..\.dockerignore">
|
||||
<Link>.dockerignore</Link>
|
||||
<DependentUpon>Dockerfile</DependentUpon>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
136
Tranga/TrangaArgs.cs
Normal file
136
Tranga/TrangaArgs.cs
Normal file
@ -0,0 +1,136 @@
|
||||
using Logging;
|
||||
|
||||
namespace Tranga;
|
||||
|
||||
public partial class Tranga : GlobalBase
|
||||
{
|
||||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
string[]? help = GetArg(args, ArgEnum.Help);
|
||||
if (help is not null)
|
||||
{
|
||||
PrintHelp();
|
||||
return;
|
||||
}
|
||||
|
||||
string[]? consoleLogger = GetArg(args, ArgEnum.ConsoleLogger);
|
||||
string[]? fileLogger = GetArg(args, ArgEnum.FileLogger);
|
||||
string? filePath = fileLogger?[0];//TODO validate path
|
||||
|
||||
List<Logger.LoggerType> enabledLoggers = new();
|
||||
if(consoleLogger is not null)
|
||||
enabledLoggers.Add(Logger.LoggerType.ConsoleLogger);
|
||||
if (fileLogger is not null)
|
||||
enabledLoggers.Add(Logger.LoggerType.FileLogger);
|
||||
Logger logger = new(enabledLoggers.ToArray(), Console.Out, Console.OutputEncoding, filePath);
|
||||
|
||||
TrangaSettings? settings = null;
|
||||
string[]? downloadLocationPath = GetArg(args, ArgEnum.DownloadLocation);
|
||||
string[]? workingDirectory = GetArg(args, ArgEnum.WorkingDirectory);
|
||||
|
||||
if (downloadLocationPath is not null && workingDirectory is not null)
|
||||
{
|
||||
settings = new TrangaSettings(downloadLocationPath[0], workingDirectory[0]);
|
||||
}else if (downloadLocationPath is not null)
|
||||
{
|
||||
if (settings is null)
|
||||
settings = new TrangaSettings(downloadLocation: downloadLocationPath[0]);
|
||||
else
|
||||
settings = new TrangaSettings(downloadLocation: downloadLocationPath[0], settings.workingDirectory);
|
||||
}else if (workingDirectory is not null)
|
||||
{
|
||||
if (settings is null)
|
||||
settings = new TrangaSettings(downloadLocation: workingDirectory[0]);
|
||||
else
|
||||
settings = new TrangaSettings(settings.downloadLocation, workingDirectory[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
settings = new TrangaSettings();
|
||||
}
|
||||
|
||||
Directory.CreateDirectory(settings.downloadLocation);//TODO validate path
|
||||
Directory.CreateDirectory(settings.workingDirectory);//TODO validate path
|
||||
|
||||
Tranga _ = new (logger, settings);
|
||||
}
|
||||
|
||||
private static void PrintHelp()
|
||||
{
|
||||
Console.WriteLine("Tranga-Help:");
|
||||
foreach (Argument argument in arguments.Values)
|
||||
{
|
||||
foreach(string name in argument.names)
|
||||
Console.Write("{0} ", name);
|
||||
if(argument.parameterCount > 0)
|
||||
Console.Write($"<{argument.parameterCount}>");
|
||||
Console.Write("\r\n {0}\r\n", argument.helpText);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an array containing the parameters for the argument.
|
||||
/// </summary>
|
||||
/// <param name="args">List of argument-strings</param>
|
||||
/// <param name="arg">Requested parameter</param>
|
||||
/// <returns>
|
||||
/// If there are no parameters for an argument, returns an empty array.
|
||||
/// If the argument is not found returns null.
|
||||
/// </returns>
|
||||
private static string[]? GetArg(string[] args, ArgEnum arg)
|
||||
{
|
||||
List<string> argsList = args.ToList();
|
||||
List<string> ret = new();
|
||||
foreach (string name in arguments[arg].names)
|
||||
{
|
||||
int argIndex = argsList.IndexOf(name);
|
||||
if (argIndex != -1)
|
||||
{
|
||||
if (arguments[arg].parameterCount == 0)
|
||||
return ret.ToArray();
|
||||
for (int parameterIndex = 1; parameterIndex <= arguments[arg].parameterCount; parameterIndex++)
|
||||
{
|
||||
if(argIndex + parameterIndex >= argsList.Count || args[argIndex + parameterIndex].Contains('-'))//End of arguments, or no parameter provided, when one is required
|
||||
Console.WriteLine($"No parameter provided for argument {name}. -h for help.");
|
||||
ret.Add(args[argIndex + parameterIndex]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret.Any() ? ret.ToArray() : null;
|
||||
}
|
||||
|
||||
private static Dictionary<ArgEnum, Argument> arguments = new()
|
||||
{
|
||||
{ ArgEnum.DownloadLocation, new(new []{"-d", "--downloadLocation"}, 1, "Directory to which downloaded Manga are saved") },
|
||||
{ ArgEnum.WorkingDirectory, new(new []{"-w", "--workingDirectory"}, 1, "Directory in which application-data is saved") },
|
||||
{ ArgEnum.ConsoleLogger, new(new []{"-c", "--consoleLogger"}, 0, "Enables the consoleLogger") },
|
||||
{ ArgEnum.FileLogger, new(new []{"-f", "--fileLogger"}, 1, "Enables the fileLogger, Directory where logfiles are saved") },
|
||||
{ ArgEnum.Help, new(new []{"-h", "--help"}, 0, "Print this") }
|
||||
//{ ArgEnum., new(new []{""}, 1, "") }
|
||||
};
|
||||
|
||||
internal enum ArgEnum
|
||||
{
|
||||
TrangaSettings,
|
||||
DownloadLocation,
|
||||
WorkingDirectory,
|
||||
ConsoleLogger,
|
||||
FileLogger,
|
||||
Help
|
||||
}
|
||||
|
||||
private struct Argument
|
||||
{
|
||||
public string[] names { get; }
|
||||
public byte parameterCount { get; }
|
||||
public string helpText { get; }
|
||||
|
||||
public Argument(string[] names, byte parameterCount, string helpText)
|
||||
{
|
||||
this.names = names;
|
||||
this.parameterCount = parameterCount;
|
||||
this.helpText = helpText;
|
||||
}
|
||||
}
|
||||
}
|
88
Tranga/TrangaSettings.cs
Normal file
88
Tranga/TrangaSettings.cs
Normal file
@ -0,0 +1,88 @@
|
||||
using Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Tranga.LibraryConnectors;
|
||||
using Tranga.NotificationConnectors;
|
||||
|
||||
namespace Tranga;
|
||||
|
||||
public class TrangaSettings
|
||||
{
|
||||
public string downloadLocation { get; private set; }
|
||||
public string workingDirectory { get; init; }
|
||||
public int apiPortNumber { get; init; }
|
||||
[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 tasksFilePath => Path.Join(workingDirectory, "tasks.json");
|
||||
[JsonIgnore] public string coverImageCache => Path.Join(workingDirectory, "imageCache");
|
||||
public ushort? version { get; set; }
|
||||
|
||||
public TrangaSettings(string? downloadLocation = null, string? workingDirectory = null, int apiPortNumber = 6531)
|
||||
{
|
||||
this.apiPortNumber = apiPortNumber;
|
||||
downloadLocation ??= Path.Join(Directory.GetCurrentDirectory(), "Downloads");
|
||||
workingDirectory ??= Directory.GetCurrentDirectory();
|
||||
if (downloadLocation.Length < 1 || workingDirectory.Length < 1)
|
||||
throw new ArgumentException("Download-location and working-directory paths can not be empty!");
|
||||
this.workingDirectory = workingDirectory;
|
||||
this.downloadLocation = downloadLocation;
|
||||
|
||||
if (File.Exists(settingsFilePath))
|
||||
{
|
||||
TrangaSettings settings = JsonConvert.DeserializeObject<TrangaSettings>(File.ReadAllText(settingsFilePath))!;
|
||||
this.downloadLocation = settings.downloadLocation;
|
||||
this.workingDirectory = settings.workingDirectory;
|
||||
}
|
||||
}
|
||||
|
||||
public HashSet<LibraryConnector> LoadLibraryConnectors()
|
||||
{
|
||||
if (!File.Exists(libraryConnectorsFilePath))
|
||||
return new HashSet<LibraryConnector>();
|
||||
return JsonConvert.DeserializeObject<HashSet<LibraryConnector>>(File.ReadAllText(libraryConnectorsFilePath),
|
||||
new JsonSerializerSettings()
|
||||
{
|
||||
Converters =
|
||||
{
|
||||
new LibraryManagerJsonConverter()
|
||||
}
|
||||
})!;
|
||||
}
|
||||
|
||||
public HashSet<NotificationConnector> LoadNotificationConnectors()
|
||||
{
|
||||
if (!File.Exists(notificationConnectorsFilePath))
|
||||
return new HashSet<NotificationConnector>();
|
||||
return JsonConvert.DeserializeObject<HashSet<NotificationConnector>>(File.ReadAllText(libraryConnectorsFilePath),
|
||||
new JsonSerializerSettings()
|
||||
{
|
||||
Converters =
|
||||
{
|
||||
new NotificationManagerJsonConverter()
|
||||
}
|
||||
})!;
|
||||
}
|
||||
|
||||
public void ExportSettings()
|
||||
{
|
||||
while (File.Exists(settingsFilePath))
|
||||
{
|
||||
bool inUse = true;
|
||||
while (inUse)
|
||||
{
|
||||
try
|
||||
{
|
||||
using FileStream stream = new (settingsFilePath, FileMode.Open, FileAccess.Read, FileShare.None);
|
||||
stream.Close();
|
||||
inUse = false;
|
||||
}
|
||||
catch (IOException)
|
||||
{
|
||||
Thread.Sleep(100);
|
||||
}
|
||||
}
|
||||
}
|
||||
File.WriteAllText(settingsFilePath, JsonConvert.SerializeObject(this));
|
||||
}
|
||||
}
|
@ -1,61 +0,0 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Tranga;
|
||||
|
||||
/// <summary>
|
||||
/// Stores information on Task
|
||||
/// </summary>
|
||||
public class TrangaTask
|
||||
{
|
||||
// ReSharper disable once CommentTypo ...Tell me why!
|
||||
// ReSharper disable once MemberCanBePrivate.Global I want it thaaat way
|
||||
public TimeSpan reoccurrence { get; }
|
||||
public DateTime lastExecuted { get; set; }
|
||||
public string? connectorName { get; }
|
||||
public Task task { get; }
|
||||
public Publication? publication { get; }
|
||||
public string language { get; }
|
||||
[JsonIgnore]public ExecutionState state { get; set; }
|
||||
|
||||
public enum ExecutionState
|
||||
{
|
||||
Waiting,
|
||||
Enqueued,
|
||||
Running
|
||||
};
|
||||
|
||||
public TrangaTask(Task task, string? connectorName, Publication? publication, TimeSpan reoccurrence, string language = "")
|
||||
{
|
||||
if(task != Task.UpdateKomgaLibrary && connectorName is null)
|
||||
throw new ArgumentException($"connectorName can not be null for task {task}");
|
||||
|
||||
if (publication is null && task != Task.UpdatePublications && task != Task.UpdateKomgaLibrary)
|
||||
throw new ArgumentException($"Publication can not be null for task {task}");
|
||||
|
||||
this.publication = publication;
|
||||
this.reoccurrence = reoccurrence;
|
||||
this.lastExecuted = DateTime.Now.Subtract(reoccurrence);
|
||||
this.connectorName = connectorName;
|
||||
this.task = task;
|
||||
this.language = language;
|
||||
}
|
||||
|
||||
/// <returns>True if elapsed time since last execution is greater than set interval</returns>
|
||||
public bool ShouldExecute()
|
||||
{
|
||||
return DateTime.Now.Subtract(this.lastExecuted) > reoccurrence && state is ExecutionState.Waiting;
|
||||
}
|
||||
|
||||
public enum Task
|
||||
{
|
||||
UpdatePublications,
|
||||
UpdateChapters,
|
||||
DownloadNewChapters,
|
||||
UpdateKomgaLibrary
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{task}\t{lastExecuted}\t{reoccurrence}\t{state}\t{connectorName}\t{publication?.sortName}";
|
||||
}
|
||||
}
|
21
docker-compose.yaml
Normal file
21
docker-compose.yaml
Normal file
@ -0,0 +1,21 @@
|
||||
version: '3'
|
||||
services:
|
||||
tranga-api:
|
||||
image: glax/tranga-api:latest
|
||||
container_name: tranga-api
|
||||
volumes:
|
||||
- ./tranga:/usr/share/Tranga-API #1 when replacing ./tranga replace #2 with same value
|
||||
- ./Manga:/Manga
|
||||
ports:
|
||||
- "6531:6531"
|
||||
restart: unless-stopped
|
||||
tranga-website:
|
||||
image: glax/tranga-website:latest
|
||||
container_name: tranga-website
|
||||
volumes:
|
||||
- ./tranga/imageCache:/usr/share/nginx/html/imageCache:ro #2 when replacing Point to same value as #1/imageCache
|
||||
ports:
|
||||
- "9555:80"
|
||||
depends_on:
|
||||
- tranga-api
|
||||
restart: unless-stopped
|
Reference in New Issue
Block a user