mirror of
https://github.com/C9Glax/tranga.git
synced 2025-06-14 15:27:53 +02:00
Compare commits
967 Commits
1.5
...
6a8df2f5f8
Author | SHA1 | Date | |
---|---|---|---|
6a8df2f5f8 | |||
524596ad85 | |||
6aa8413c40 | |||
94adefa8e6 | |||
7cf7eb85d2 | |||
55c0e2c4e7 | |||
5494f2b754 | |||
b96ae4a2d2 | |||
80190e1286 | |||
3a25c0b221 | |||
16dd1ffa97 | |||
9cb5f636dd | |||
df319e9afb | |||
84388a469a | |||
d322445550 | |||
81d22bc022 | |||
6b0cefbc7c | |||
519030861d | |||
6940e6c64d | |||
e66ab49e7d | |||
67a15cec7f | |||
ae11c31b9d | |||
60b128fc30 | |||
729f018712 | |||
03e89913e3 | |||
c4fc2f436b | |||
ebc30c85bf | |||
d6b0e3a366 | |||
e1bfdd675b | |||
e6f8853b49 | |||
99ddb06d6d | |||
62876498d0 | |||
1044821147 | |||
7f946da1c3 | |||
79e7941dda | |||
faa235783c | |||
87c5ad001d | |||
3b58e0498b | |||
87274aca19 | |||
77c5903cf1 | |||
0d32f15ee9 | |||
a0774841bc | |||
3ee3a07565 | |||
b9eecd3afd | |||
6534341fd5 | |||
6737be4a20 | |||
84833acdeb | |||
538e6fa60b | |||
8c5bcd2665 | |||
50dfd92c91 | |||
bf9fe517b0 | |||
e1f1a05724 | |||
1008da7ee8 | |||
72d9bda0e8 | |||
a40a9c84df | |||
ec884f888f | |||
57df419d65 | |||
825b945ad1 | |||
b8c624f3ea | |||
93cfdddd19 | |||
4c8d9bfaf2 | |||
dd988658c0 | |||
cf4c84a47f | |||
5d9bfc3adf | |||
5a770c8e9f | |||
395619acd3 | |||
502821c246 | |||
9d6a8ed686 | |||
e3bd7620aa | |||
afcc2cacaf | |||
4040b5845c | |||
428d6e13d1 | |||
1e6a65c0fd | |||
025d43b752 | |||
113c0abba7 | |||
7daebcb1c4 | |||
747df0bde5 | |||
463f360808 | |||
44ff158c66 | |||
85d7c07b13 | |||
b5b45d0801 | |||
553f56ecaf | |||
9cc4f8c090 | |||
29f3f1a16e | |||
204fb7614d | |||
d6e73ffcdf | |||
5a8202f872 | |||
1bd914571c | |||
483dcc41df | |||
55cc2a2e84 | |||
b619109ea1 | |||
72943330c3 | |||
bc44a5333b | |||
38bc1e4d53 | |||
47479f7a0d | |||
b2381be860 | |||
657e1b338b | |||
5018800d09 | |||
ee265a7519 | |||
5b0624654b | |||
a75549c699 | |||
c7dc5e75f2 | |||
3f37eefe72 | |||
b7bc04a045 | |||
f7daacf0d4 | |||
1cb8899195 | |||
f46244cb9c | |||
9db3f1b0da | |||
dc9cd4b1dd | |||
3566ad774d | |||
94b81969c7 | |||
3e581e2ddb | |||
bd8cb86c52 | |||
34c5436b33 | |||
4690394437 | |||
02cf8578c9 | |||
067497ddd0 | |||
4b88cdbd90 | |||
420013f07b | |||
8cee11aa22 | |||
07c6081c03 | |||
585d7e3380 | |||
febce6b92a | |||
fb7ed21d82 | |||
2db85e5070 | |||
198bbdcf94 | |||
c58adf64fa | |||
957debea01 | |||
5186ae66c9 | |||
c35e1ef517 | |||
8f6891142b | |||
b52e6d4908 | |||
96b5921ed6 | |||
9d47445339 | |||
93696fbac1 | |||
582b3af89c | |||
f57667bc8f | |||
f9a30f2587 | |||
240af81fa9 | |||
26b2910000 | |||
a88b85e599 | |||
27f823cfeb | |||
70993a692a | |||
1a631362c9 | |||
00c4f0533f | |||
8670863810 | |||
2c9bd2532e | |||
575fb739cc | |||
d4af068f0e | |||
6a4d454a08 | |||
225db8beda | |||
d80fcd9039 | |||
30c44760e7 | |||
a3ae3c320d | |||
4871bc801d | |||
ea262889e6 | |||
445542b653 | |||
b7718220ef | |||
34c62e8658 | |||
a9fcc93670 | |||
68d7ef258f | |||
fdea4f5ea5 | |||
ac3039e587 | |||
1c5f105a4d | |||
3829a1cf26 | |||
c3daa0b751 | |||
3a072beea3 | |||
8e6f2798a9 | |||
26a07f4a2f | |||
9cbde9a6b4 | |||
0870aa9fdb | |||
172650e644 | |||
48ab44c28d | |||
52ff2e54a8 | |||
61d80a93cf | |||
32ecdcda76 | |||
7be3ee52e9 | |||
981eb0fd9f | |||
a92eba2d14 | |||
47f3044a6d | |||
6d03cc5f8d | |||
290c405f52 | |||
fcdbd32872 | |||
eb6c37cc53 | |||
d922842186 | |||
69323d6d60 | |||
46a0fb8c48 | |||
ec8eb40941 | |||
d2074fae35 | |||
713bbc230f | |||
32ab9a552f | |||
7b6724ad38 | |||
c11c68d6d7 | |||
09fdb6e5f1 | |||
be68ddc9b7 | |||
e86ad03b1e | |||
9dfbe89e87 | |||
96e2845a5b | |||
98e75af486 | |||
e2f5c3badc | |||
cda07bb9aa | |||
7c18466e95 | |||
c36204c7a8 | |||
ce1c4d3f65 | |||
52d0489a1b | |||
18edcef1c3 | |||
73ad881600 | |||
f89aea6ac8 | |||
5f05ba1049 | |||
c6cfd9eb6c | |||
a20ee01cfa | |||
cf5cbba9a8 | |||
600b56033d | |||
fdea3659f1 | |||
7f3754fb64 | |||
2dac5db4da | |||
99df9a9dfd | |||
77bb309dfa | |||
3456fc6564 | |||
35f2625f05 | |||
0b9948e367 | |||
96f3dbce65 | |||
895128a462 | |||
3b9d4a6735 | |||
a94186455b | |||
7d3deee74c | |||
5980b64caa | |||
cbecb257ef | |||
8316ed08a7 | |||
190fa8cba7 | |||
217700d08d | |||
7ff9ac53ee | |||
6faaaf4139 | |||
9b8b80cd24 | |||
15f3e2b8ec | |||
2be29e4019 | |||
e8dbf7a718 | |||
a968f4328d | |||
398b6fff05 | |||
f5da2f8526 | |||
73093ab86c | |||
75eea8c761 | |||
fccaf9fcbe | |||
3122aa32e8 | |||
06cdbbd283 | |||
02fad2dd44 | |||
e0a7d1a187 | |||
054c88712e | |||
d0f9a4102c | |||
9f178821b6 | |||
e95eb0497c | |||
3c3f7bb95a | |||
032ee95716 | |||
682fd0bc2a | |||
dfa8e66f34 | |||
8f51d22303 | |||
d41de84262 | |||
1bd20791b8 | |||
03aeab44cd | |||
6d723b6355 | |||
7b91bb699f | |||
14e33cc496 | |||
6f3bba99b0 | |||
2d848843d0 | |||
63b493fa9c | |||
001a37b8ef | |||
69d6884517 | |||
db73af3bdd | |||
59547efab2 | |||
f4336f9777 | |||
bec3ac52a9 | |||
ea37e81ece | |||
6a20783d48 | |||
21af75f410 | |||
fc884adc9f | |||
960d3f7c62 | |||
6520aebcdf | |||
1ee9b644aa | |||
2f36701fef | |||
b18f8e4059 | |||
8145abb744 | |||
9dd52178b9 | |||
cf242f81e1 | |||
a629792818 | |||
34dd78810d | |||
e1c504226c | |||
200a22228f | |||
bc10136331 | |||
06df6e0767 | |||
ba029b71f5 | |||
082802ddbe | |||
d5f1df0400 | |||
d00881e611 | |||
72bc7ec07b | |||
89b5aa266e | |||
926c0d5833 | |||
80e2568113 | |||
3b6417eff2 | |||
6b9ddca711 | |||
2812a6dff1 | |||
1991862a42 | |||
40e4d5c203 | |||
49e9731184 | |||
a4e85f254f | |||
4f47aeadcf | |||
e0c1356fea | |||
0d9b3d2499 | |||
d73bf70868 | |||
8e5d15ead9 | |||
b8c28e6d21 | |||
9ea5e436fe | |||
b4c310638a | |||
159341ff3c | |||
29338b9b17 | |||
0eda8913b0 | |||
5ca50630e4 | |||
d0bfb262bf | |||
4f14f15ade | |||
d89a24fd11 | |||
a5859e3c82 | |||
dd2fa3fbd7 | |||
33e5d65785 | |||
d60ed77dbe | |||
e15c6816b5 | |||
4a4fe4b40d | |||
d221532e0d | |||
4881789970 | |||
be1e6fe988 | |||
f61e51e506 | |||
eba511749b | |||
5bc2a8909d | |||
de4c57a0cd | |||
e368c3c98a | |||
f3e0959be8 | |||
d17ca1d97a | |||
e9376e3782 | |||
7c217a7e33 | |||
a437fcbca1 | |||
1dcfecd66f | |||
6db4646336 | |||
8a6298e3fd | |||
194705c124 | |||
f4d5969003 | |||
8607bd2c89 | |||
9d92069a4b | |||
5614729eab | |||
fab30dc5a7 | |||
fd20b9febf | |||
ee6de661c8 | |||
d52ec8d36f | |||
790e77b00c | |||
37dfb4df02 | |||
42feea3ad5 | |||
4f14903538 | |||
bbc750d731 | |||
08dd01942f | |||
6ae3918679 | |||
351144e763 | |||
aea4c0c61b | |||
7b9e935db7 | |||
048b165d76 | |||
ebe3012c69 | |||
8ccb6c0cb5 | |||
a5dbed9525 | |||
811ddd903f | |||
beb455308f | |||
f948809bcd | |||
7ceb9cd4cb | |||
57f1e037ef | |||
5c309131ad | |||
6ca8d58e43 | |||
e3211b95e2 | |||
b5e9e03f64 | |||
98bd8a983b | |||
27a559834f | |||
f4996659ef | |||
e05684d5d1 | |||
4a7d23c0d9 | |||
1d44b6d9c6 | |||
2cfc7ac2c5 | |||
811a183af2 | |||
fb0755eb89 | |||
2e8b896f3b | |||
017f31ca83 | |||
4021237888 | |||
7ed3846c5f | |||
4692cc297a | |||
7f95ab9439 | |||
49a9b7ccb0 | |||
0735e2c588 | |||
5b22246c41 | |||
2e1f633f40 | |||
8887cea718 | |||
061da1b4bf | |||
80dc8fbe65 | |||
28a0efe488 | |||
3d08b1f9f2 | |||
3d855020eb | |||
c6d0168d2f | |||
d52213002e | |||
ec9290f41f | |||
6b91796e5a | |||
9f9ea569d5 | |||
4bd1150a0e | |||
8b62e2c467 | |||
7ec262a2e4 | |||
d32d5976ee | |||
58cff6513a | |||
783f229a6a | |||
2651a0c53b | |||
0ced3a7dd9 | |||
a56555eee4 | |||
cee7870aad | |||
aaf06da8e1 | |||
51a26a3cba | |||
bce77180bc | |||
8c66bbc89f | |||
762da4c859 | |||
daba940b45 | |||
79e61a62c7 | |||
06fe98323a | |||
5f820c53f5 | |||
c69f1f6569 | |||
e360037fda | |||
ea866e0136 | |||
c3231327f9 | |||
03e90eccd3 | |||
64482931a3 | |||
cce4901a5d | |||
3adb103fc4 | |||
b6ffb97a04 | |||
5bdbd9e2e4 | |||
49cfff8a2f | |||
6d48a100ca | |||
4104169c19 | |||
4cb7c941a2 | |||
b3fb53f6d8 | |||
f729c44f88 | |||
8b9769b816 | |||
f4966b0348 | |||
9a02859f6b | |||
e96dd07521 | |||
a610eff8f0 | |||
df2fc4a036 | |||
c41f04d92d | |||
5e647099cd | |||
011af9c7a8 | |||
630e507564 | |||
fa2598084f | |||
f79743ee93 | |||
2828fec316 | |||
bd14722791 | |||
d22b49cfa8 | |||
595051b0fe | |||
238395a3da | |||
0313d81204 | |||
f5cecb9e30 | |||
7e5fa6ce41 | |||
0ab2ae03ce | |||
95236daf41 | |||
294ce01bc3 | |||
13565d1c7a | |||
a8aa7d3370 | |||
01bab62190 | |||
2768ab38e6 | |||
54b24ac37f | |||
c67e89f1dd | |||
4ba44d3ac3 | |||
33b8ede492 | |||
dbc1b94124 | |||
8631cf6376 | |||
df4d547e2b | |||
006b71b496 | |||
5f03b0d89c | |||
6dc1ea0030 | |||
ff08754610 | |||
d1a6c0ad3d | |||
0260868968 | |||
b1f72dcb81 | |||
b0f353819b | |||
8f8d019861 | |||
21a7392493 | |||
0d5db15f87 | |||
431fde0d76 | |||
e022bf3081 | |||
c25a4f69ec | |||
82bdb248b9 | |||
b27114eaad | |||
051eb4a417 | |||
482704af2c | |||
af4229920d | |||
6f5fb7e0bb | |||
7628510b87 | |||
dd965d886a | |||
7e54577c54 | |||
537ad3a5f8 | |||
6a8697fc3a | |||
94582496ef | |||
17ef5eae0f | |||
d5b6d4e8ee | |||
05190bc9e2 | |||
d211dd2d01 | |||
590547e407 | |||
2ad04c5c46 | |||
189569ccdf | |||
2872eeea09 | |||
c0cfeaa35d | |||
2fd780996c | |||
b390bb8ea5 | |||
847829e617 | |||
0f29da00de | |||
9b2a6de841 | |||
17a27c9922 | |||
6c9071b22b | |||
abfe42b7c1 | |||
72ae124418 | |||
bee6e7ba37 | |||
8079ffc742 | |||
6d6e33491b | |||
a8697a14a3 | |||
e2adac937a | |||
b4708c5d10 | |||
597abde115 | |||
2a824bbb8d | |||
9691eb0d08 | |||
4888e18fd2 | |||
0aa92a7913 | |||
db53e2156b | |||
1cce0f204e | |||
ce41c49a0e | |||
b8570e5eef | |||
1f24a2349d | |||
ca95460218 | |||
e801cc4cbf | |||
2c4c8de8b5 | |||
0b4461265c | |||
c008d55f26 | |||
9b990aecea | |||
299fa6afda | |||
c03e927565 | |||
bb6c553afa | |||
33d78ed757 | |||
84272ddd1e | |||
2f0fbbd3cb | |||
5bc414fd59 | |||
2eaeadb92c | |||
d8df6eccb1 | |||
db64b717eb | |||
1afe36a525 | |||
aa692f6978 | |||
c706824222 | |||
3ca6245fc2 | |||
2dd82aad13 | |||
3c4867a276 | |||
bae157cdb4 | |||
3b818ff1af | |||
5d12be2983 | |||
31a4e693e0 | |||
e49db9a4cb | |||
54142e61fe | |||
cd5ca0e302 | |||
95da900213 | |||
b5be4e0dd8 | |||
0c135aa89e | |||
e11ee4dafe | |||
05573f65f9 | |||
d986c808e3 | |||
5df63b00c2 | |||
903bb5af5e | |||
cc8453d4a8 | |||
800d4c1ec1 | |||
b4f97eefcf | |||
29f6de2590 | |||
23e5c4a7b1 | |||
e15717cb04 | |||
b995fc568a | |||
442d949371 | |||
263d0e6036 | |||
7c7d43021e | |||
5cdc7d7207 | |||
1bcbd1517f | |||
b72da45ae9 | |||
01041e43ac | |||
4c1a659f16 | |||
2e02f0b237 | |||
77f93d87f9 | |||
45c0f19a9d | |||
7c09deb143 | |||
449d406eab | |||
083ce238d8 | |||
5f9ffb8aad | |||
92bc3d5aa8 | |||
49ab8928b1 | |||
391efcb9bc | |||
963ad375e8 | |||
0a5ded2036 | |||
4843c7f05c | |||
6adbda2359 | |||
425cf7e0d6 | |||
8f5dd5aab5 | |||
733ae285f1 | |||
2e1c8ce34f | |||
c965bc38d1 | |||
37266ea095 | |||
8caac538c9 | |||
7c7f711bb4 | |||
d78897eb74 | |||
438c11af4f | |||
38df54baff | |||
98d187d133 | |||
5352cca058 | |||
3381909afd | |||
7219641859 | |||
f63851d95d | |||
e72301d062 | |||
2302e1009b | |||
40fea6cc7f | |||
5458c43f21 | |||
f78bec43d6 | |||
88876fb8f4 | |||
c71aec8882 | |||
ddfba0d864 | |||
ca9c0b22c1 | |||
6844d0a242 | |||
fd9319de27 | |||
726be70af3 | |||
19c9ecb3e7 | |||
f01a786e59 | |||
59f9bcc7d0 | |||
2796a2adb5 | |||
e07b191293 | |||
9bf650f5fc | |||
334795b263 | |||
51a6f216af | |||
238a2775f4 | |||
fec970d7d6 | |||
e642d50c47 | |||
fafcdac00a | |||
1785aa28ea | |||
f22c332cab | |||
b3bf523e1e | |||
06b2e11164 | |||
7972f07801 | |||
d89af7cc5b | |||
31a0c6ffb2 | |||
668a3b3a96 | |||
3938c61297 | |||
4f3bcd245d | |||
129c95f123 | |||
e2cdf27d40 | |||
4156365b18 | |||
d3ccddd8db | |||
13075a8704 | |||
e7d9f53a93 | |||
dc6dfd4aa1 | |||
0fba09b1e8 | |||
f08b9e85ec | |||
95fcc73c74 | |||
73492d8102 | |||
c69dd22ecf | |||
17b6c523a2 | |||
6c3f7604fe | |||
94f88f08e9 | |||
47327524be | |||
3b96419739 | |||
b7c9b4e9b4 | |||
13adb45444 | |||
b8fbee578e | |||
c1fb42b537 | |||
dcc12ec3ea | |||
8c554076b2 | |||
a10fbdf3a5 | |||
f246209685 | |||
41c561bd1d | |||
fc7d5463c3 | |||
3c2ce266f6 | |||
306cb87d67 | |||
23cda74487 | |||
3ceee63dfc | |||
4e5a6fe97b | |||
b3b1971dad | |||
2699f35b62 | |||
7a14583d6a | |||
660f6a1648 | |||
482fcb7102 | |||
b6cdb07e3f | |||
0875e7ee12 | |||
cb6482ebae | |||
87ea077281 | |||
c1aa4cf6b5 | |||
f5b6b1785f | |||
2553a150d1 | |||
b149d377dc | |||
0209159c5c | |||
e31820eb00 | |||
c4d69c27a4 | |||
3ee53b7436 | |||
64ec0963e1 | |||
27c4ed719c | |||
4f4b0cb3a8 | |||
48d312da0b | |||
1fe4b75ac7 | |||
c580fafc62 | |||
58040ecb10 | |||
2960a9b8f0 | |||
f52bb8eb89 | |||
ae0dc548ae | |||
051b85d08b | |||
d89ca0a2ef | |||
f1f640c1f6 | |||
9319aa7d1f | |||
656e62628e | |||
ba27adf255 | |||
88ca75e883 | |||
67c23b357f | |||
4a5271e2a7 | |||
fec5ad664c | |||
3cea5fb431 | |||
7fa44fba54 | |||
d6b5a29fdc | |||
a4a49d40f0 | |||
28fa85f05c | |||
1066e1ca2e | |||
39307f4313 | |||
a316ee3d48 | |||
569622099d | |||
017701867d | |||
c3d62bd337 | |||
dc9e9e705c | |||
9eee6683fa | |||
1265c7a072 | |||
c601541249 | |||
ae1184320f | |||
384e4c4f43 | |||
76a2b2498a | |||
2ab21b15cf | |||
7acdf7a19b | |||
af8716fcb1 | |||
5f2c66b729 | |||
e030f02431 | |||
bdeb75f4e4 | |||
4ce114986d | |||
8035bf3fcd | |||
85bf3ec7e8 | |||
0f17615b10 | |||
0c8145803e | |||
b2e0c3db97 | |||
ca283fcfff | |||
1d55070daf | |||
32fd75bdae | |||
99ad702163 | |||
6e3a9c2a78 | |||
ad1d4dfe23 | |||
14ba71005f | |||
22c4c0eb2c | |||
44f8d369c3 | |||
c0e6da144e | |||
51a1ae72ca | |||
79bbc92467 | |||
ae5be31c89 | |||
eebe25a378 | |||
0f3da4ec81 | |||
0b77dc1172 | |||
37cf47bc17 | |||
4cce2e04cb | |||
5465ac4e5c | |||
dd4d5a81ee | |||
a05e1914e3 | |||
ed79ee5d0f | |||
28e05e549d | |||
eaab7c5235 | |||
0552b3db82 | |||
c813e1854d | |||
32036df057 | |||
394829ee36 | |||
2a389f1ede | |||
3167f6c3e6 | |||
89c5f4b820 | |||
1c1169e5ce | |||
d5d34c5381 | |||
c0efbb22cc | |||
9f30e52713 | |||
1fd36c91d6 | |||
e663163de8 | |||
4827b90c3d | |||
e274c864f9 | |||
f4bc182954 | |||
3365be219c | |||
10708b3abd | |||
c1e939f1e3 | |||
21d53dabec | |||
a9417dbba6 | |||
4ca7b107eb | |||
61024bcee9 | |||
ea1b8749a6 | |||
2fcab1f1b1 | |||
bbd716383a | |||
6e1a0ab06c | |||
181942153b | |||
fe04af4a2b | |||
4240a1eb6a | |||
32349c1ddf | |||
a94d3d6b40 | |||
f916cda0f1 | |||
a8f0f1af15 | |||
0cf3a95f58 | |||
a89a526fda | |||
4d1e43e7b3 | |||
4f9749d09e | |||
7614f9aad3 | |||
97c0e42512 | |||
565bc0775d | |||
e6a3fa2899 | |||
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 |
@ -1,25 +0,0 @@
|
|||||||
**/.dockerignore
|
|
||||||
**/.env
|
|
||||||
**/.git
|
|
||||||
**/.gitignore
|
|
||||||
**/.project
|
|
||||||
**/.settings
|
|
||||||
**/.toolstarget
|
|
||||||
**/.vs
|
|
||||||
**/.vscode
|
|
||||||
**/.idea
|
|
||||||
**/*.*proj.user
|
|
||||||
**/*.dbmdl
|
|
||||||
**/*.jfm
|
|
||||||
**/azds.yaml
|
|
||||||
**/bin
|
|
||||||
**/charts
|
|
||||||
**/docker-compose*
|
|
||||||
**/Dockerfile*
|
|
||||||
**/node_modules
|
|
||||||
**/npm-debug.log
|
|
||||||
**/obj
|
|
||||||
**/secrets.dev.yaml
|
|
||||||
**/values.dev.yaml
|
|
||||||
LICENSE
|
|
||||||
README.md
|
|
21
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
Normal file
21
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
name: Bug Report
|
||||||
|
description: File a bug report
|
||||||
|
title: "[It broke]: "
|
||||||
|
labels: ["bug"]
|
||||||
|
body:
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: What is broken?
|
||||||
|
description: What happened? How did we get here?
|
||||||
|
placeholder: The place where you tell me what you expected to happen, and what happened instead.
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Log-output
|
||||||
|
description: The output of `docker logs tranga-api`
|
||||||
|
render: C#
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Additional stuff
|
||||||
|
description: Screenshots, anything you think might help
|
23
.github/ISSUE_TEMPLATE/new_connector.yml
vendored
Normal file
23
.github/ISSUE_TEMPLATE/new_connector.yml
vendored
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
name: New Connector Request
|
||||||
|
description: Request a new site to be added
|
||||||
|
title: "[New Connector]: "
|
||||||
|
labels: ["New Connector"]
|
||||||
|
body:
|
||||||
|
- type: input
|
||||||
|
attributes:
|
||||||
|
label: Website-Link
|
||||||
|
placeholder: https://
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: checkboxes
|
||||||
|
attributes:
|
||||||
|
label: Is the Website free to access?
|
||||||
|
description: We can't support pay-to-use sites.
|
||||||
|
options:
|
||||||
|
- label: The Website is freely accessible.
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Anything else?
|
||||||
|
validations:
|
||||||
|
required: false
|
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"
|
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@v4
|
||||||
|
|
||||||
|
# https://github.com/docker/setup-qemu-action#usage
|
||||||
|
- name: Set up QEMU
|
||||||
|
uses: docker/setup-qemu-action@v3.2.0
|
||||||
|
|
||||||
|
# https://github.com/marketplace/actions/docker-setup-buildx
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
id: buildx
|
||||||
|
uses: docker/setup-buildx-action@v3.8.0
|
||||||
|
|
||||||
|
# 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@v6.9.0
|
||||||
|
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,linux/arm64
|
||||||
|
pull: true
|
||||||
|
push: true
|
||||||
|
tags: |
|
||||||
|
glax/tranga-api:cuttingedge
|
45
.github/workflows/docker-image-dev.yml
vendored
Normal file
45
.github/workflows/docker-image-dev.yml
vendored
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
name: Docker Image CI
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ "dev" ]
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
|
||||||
|
build:
|
||||||
|
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
# https://github.com/docker/setup-qemu-action#usage
|
||||||
|
- name: Set up QEMU
|
||||||
|
uses: docker/setup-qemu-action@v3.2.0
|
||||||
|
|
||||||
|
# https://github.com/marketplace/actions/docker-setup-buildx
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
id: buildx
|
||||||
|
uses: docker/setup-buildx-action@v3.8.0
|
||||||
|
|
||||||
|
# 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@v6.9.0
|
||||||
|
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,linux/arm64
|
||||||
|
pull: true
|
||||||
|
push: true
|
||||||
|
tags: |
|
||||||
|
glax/tranga-api:dev
|
45
.github/workflows/docker-image-master.yml
vendored
Normal file
45
.github/workflows/docker-image-master.yml
vendored
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
name: Docker Image CI
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ "master" ]
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
|
||||||
|
build:
|
||||||
|
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
# https://github.com/docker/setup-qemu-action#usage
|
||||||
|
- name: Set up QEMU
|
||||||
|
uses: docker/setup-qemu-action@v3.2.0
|
||||||
|
|
||||||
|
# https://github.com/marketplace/actions/docker-setup-buildx
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
id: buildx
|
||||||
|
uses: docker/setup-buildx-action@v3.8.0
|
||||||
|
|
||||||
|
# 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@v6.9.0
|
||||||
|
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,linux/arm64
|
||||||
|
pull: true
|
||||||
|
push: true
|
||||||
|
tags: |
|
||||||
|
glax/tranga-api:latest
|
45
.github/workflows/docker-image-serverv2.yml
vendored
Normal file
45
.github/workflows/docker-image-serverv2.yml
vendored
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
name: Docker Image CI
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ "Server-V2" ]
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
|
||||||
|
build:
|
||||||
|
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
# https://github.com/docker/setup-qemu-action#usage
|
||||||
|
- name: Set up QEMU
|
||||||
|
uses: docker/setup-qemu-action@v3.2.0
|
||||||
|
|
||||||
|
# https://github.com/marketplace/actions/docker-setup-buildx
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
id: buildx
|
||||||
|
uses: docker/setup-buildx-action@v3.8.0
|
||||||
|
|
||||||
|
# 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@v6.9.0
|
||||||
|
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,linux/arm64
|
||||||
|
pull: true
|
||||||
|
push: true
|
||||||
|
tags: |
|
||||||
|
glax/tranga-api:Server-V2
|
6
.gitignore
vendored
6
.gitignore
vendored
@ -19,3 +19,9 @@ riderModule.iml
|
|||||||
/.idea
|
/.idea
|
||||||
cover.jpg
|
cover.jpg
|
||||||
cover.png
|
cover.png
|
||||||
|
/.vscode
|
||||||
|
/.vs/
|
||||||
|
Tranga/Properties/launchSettings.json
|
||||||
|
/Manga
|
||||||
|
/settings
|
||||||
|
*.DotSettings.user
|
@ -1,21 +1,37 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<TargetFramework>net9.0</TargetFramework>
|
||||||
<TargetFramework>net7.0</TargetFramework>
|
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||||
|
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||||
|
<NoWarn>$(NoWarn);1591</NoWarn>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Include="..\.dockerignore">
|
<PackageReference Include="Asp.Versioning.Mvc.ApiExplorer" Version="8.1.0" />
|
||||||
<Link>.dockerignore</Link>
|
<PackageReference Include="HtmlAgilityPack" Version="1.11.71" />
|
||||||
</Content>
|
<PackageReference Include="log4net" Version="3.0.3" />
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="9.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.0">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
|
<PackageReference Include="Npgsql" Version="9.0.2" />
|
||||||
|
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.2" />
|
||||||
|
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.Design" Version="1.1.0" />
|
||||||
|
<PackageReference Include="PuppeteerSharp" Version="20.0.5" />
|
||||||
|
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.5" />
|
||||||
|
<PackageReference Include="Soenneker.Utils.String.NeedlemanWunsch" Version="3.0.697" />
|
||||||
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="7.2.0" />
|
||||||
|
<PackageReference Include="System.Drawing.Common" Version="9.0.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Tranga\Tranga.csproj" />
|
<Folder Include="Migrations\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
6
API/API.http
Normal file
6
API/API.http
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
@API_HostAddress = http://localhost:5105
|
||||||
|
|
||||||
|
GET {{API_HostAddress}}/weatherforecast/
|
||||||
|
Accept: application/json
|
||||||
|
|
||||||
|
###
|
223
API/Controllers/JobController.cs
Normal file
223
API/Controllers/JobController.cs
Normal file
@ -0,0 +1,223 @@
|
|||||||
|
using API.Schema;
|
||||||
|
using API.Schema.Jobs;
|
||||||
|
using Asp.Versioning;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using static Microsoft.AspNetCore.Http.StatusCodes;
|
||||||
|
|
||||||
|
namespace API.Controllers;
|
||||||
|
|
||||||
|
[ApiVersion(2)]
|
||||||
|
[ApiController]
|
||||||
|
[Produces("application/json")]
|
||||||
|
[Route("v{version:apiVersion}/[controller]")]
|
||||||
|
public class JobController(PgsqlContext context) : Controller
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Returns all Jobs
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Array of Jobs</returns>
|
||||||
|
[HttpGet]
|
||||||
|
[ProducesResponseType<Job[]>(Status200OK)]
|
||||||
|
public IActionResult GetAllJobs()
|
||||||
|
{
|
||||||
|
Job[] ret = context.Jobs.ToArray();
|
||||||
|
return Ok(ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns Jobs with requested Job-IDs
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ids">Array of Job-IDs</param>
|
||||||
|
/// <returns>Array of Jobs</returns>
|
||||||
|
[HttpPost("WithIDs")]
|
||||||
|
[ProducesResponseType<Job[]>(Status200OK)]
|
||||||
|
public IActionResult GetJobs([FromBody]string[] ids)
|
||||||
|
{
|
||||||
|
Job[] ret = context.Jobs.Where(job => ids.Contains(job.JobId)).ToArray();
|
||||||
|
return Ok(ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get all Jobs in requested State
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="state">Requested Job-State</param>
|
||||||
|
/// <returns>Array of Jobs</returns>
|
||||||
|
[HttpGet("State/{state}")]
|
||||||
|
[ProducesResponseType<Job[]>(Status200OK)]
|
||||||
|
public IActionResult GetJobsInState(JobState state)
|
||||||
|
{
|
||||||
|
Job[] jobsInState = context.Jobs.Where(job => job.state == state).ToArray();
|
||||||
|
return Ok(jobsInState);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns all Jobs of requested Type
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="type">Requested Job-Type</param>
|
||||||
|
/// <returns>Array of Jobs</returns>
|
||||||
|
[HttpGet("Type/{type}")]
|
||||||
|
[ProducesResponseType<Job[]>(Status200OK)]
|
||||||
|
public IActionResult GetJobsOfType(JobType type)
|
||||||
|
{
|
||||||
|
Job[] jobsOfType = context.Jobs.Where(job => job.JobType == type).ToArray();
|
||||||
|
return Ok(jobsOfType);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Return Job with ID
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">Job-ID</param>
|
||||||
|
/// <returns>Job</returns>
|
||||||
|
[HttpGet("{id}")]
|
||||||
|
[ProducesResponseType<Job>(Status200OK)]
|
||||||
|
[ProducesResponseType(Status404NotFound)]
|
||||||
|
public IActionResult GetJob(string id)
|
||||||
|
{
|
||||||
|
Job? ret = context.Jobs.Find(id);
|
||||||
|
return (ret is not null) switch
|
||||||
|
{
|
||||||
|
true => Ok(ret),
|
||||||
|
false => NotFound()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create a new CreateNewDownloadChapterJob
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="request">ID of the Manga, and how often we check again</param>
|
||||||
|
/// <returns>Nothing</returns>
|
||||||
|
[HttpPut("NewDownloadChapterJob/{mangaId}")]
|
||||||
|
[ProducesResponseType(Status201Created)]
|
||||||
|
[ProducesResponseType<string>(Status500InternalServerError)]
|
||||||
|
public IActionResult CreateNewDownloadChapterJob(string mangaId, [FromBody]ulong recurrenceTime)
|
||||||
|
{
|
||||||
|
Job job = new DownloadNewChaptersJob(recurrenceTime, mangaId);
|
||||||
|
return AddJob(job);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create a new DownloadSingleChapterJob
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="chapterId">ID of the Chapter</param>
|
||||||
|
/// <returns>Nothing</returns>
|
||||||
|
[HttpPut("DownloadSingleChapterJob/{chapterId}")]
|
||||||
|
[ProducesResponseType(Status201Created)]
|
||||||
|
[ProducesResponseType<string>(Status500InternalServerError)]
|
||||||
|
public IActionResult CreateNewDownloadChapterJob(string chapterId)
|
||||||
|
{
|
||||||
|
Job job = new DownloadSingleChapterJob(chapterId);
|
||||||
|
return AddJob(job);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create a new UpdateMetadataJob
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="mangaId">ID of the Manga</param>
|
||||||
|
/// <returns>Nothing</returns>
|
||||||
|
[HttpPut("UpdateMetadataJob/{mangaId}")]
|
||||||
|
[ProducesResponseType(Status201Created)]
|
||||||
|
[ProducesResponseType<string>(Status500InternalServerError)]
|
||||||
|
public IActionResult CreateUpdateMetadataJob(string mangaId)
|
||||||
|
{
|
||||||
|
Job job = new UpdateMetadataJob(0, mangaId);
|
||||||
|
return AddJob(job);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create a new UpdateMetadataJob for all Manga
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Nothing</returns>
|
||||||
|
[HttpPut("UpdateMetadataJob")]
|
||||||
|
[ProducesResponseType(Status201Created)]
|
||||||
|
[ProducesResponseType<string>(Status500InternalServerError)]
|
||||||
|
public IActionResult CreateUpdateAllMetadataJob()
|
||||||
|
{
|
||||||
|
List<string> ids = context.Manga.Select(m => m.MangaId).ToList();
|
||||||
|
List<UpdateMetadataJob> jobs = ids.Select(id => new UpdateMetadataJob(0, id)).ToList();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
context.Jobs.AddRange(jobs);
|
||||||
|
context.SaveChanges();
|
||||||
|
return Created();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return StatusCode(500, e.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private IActionResult AddJob(Job job)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
context.Jobs.Add(job);
|
||||||
|
context.SaveChanges();
|
||||||
|
return Created();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return StatusCode(500, e.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Delete Job with ID
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">Job-ID</param>
|
||||||
|
/// <returns>Nothing</returns>
|
||||||
|
[HttpDelete("{id}")]
|
||||||
|
[ProducesResponseType(Status200OK)]
|
||||||
|
[ProducesResponseType(Status404NotFound)]
|
||||||
|
[ProducesResponseType(Status500InternalServerError)]
|
||||||
|
public IActionResult DeleteJob(string id)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Job? ret = context.Jobs.Find(id);
|
||||||
|
switch (ret is not null)
|
||||||
|
{
|
||||||
|
case true:
|
||||||
|
context.Remove(ret);
|
||||||
|
context.SaveChanges();
|
||||||
|
return Ok();
|
||||||
|
case false: return NotFound();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return StatusCode(500, e.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Starts the Job with the requested ID
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">Job-ID</param>
|
||||||
|
/// <returns>Nothing</returns>
|
||||||
|
[HttpPost("{id}/Start")]
|
||||||
|
[ProducesResponseType(Status202Accepted)]
|
||||||
|
[ProducesResponseType(Status404NotFound)]
|
||||||
|
[ProducesResponseType(Status500InternalServerError)]
|
||||||
|
public IActionResult StartJob(string id)
|
||||||
|
{
|
||||||
|
Job? ret = context.Jobs.Find(id);
|
||||||
|
if (ret is null)
|
||||||
|
return NotFound();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
context.Update(ret);
|
||||||
|
context.SaveChanges();
|
||||||
|
return Accepted();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return StatusCode(500, e.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost("{id}/Stop")]
|
||||||
|
public IActionResult StopJob(string id)
|
||||||
|
{
|
||||||
|
return NotFound(new ProblemResponse("Not implemented")); //TODO
|
||||||
|
}
|
||||||
|
}
|
95
API/Controllers/LibraryConnectorController.cs
Normal file
95
API/Controllers/LibraryConnectorController.cs
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
using API.Schema;
|
||||||
|
using API.Schema.LibraryConnectors;
|
||||||
|
using Asp.Versioning;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using static Microsoft.AspNetCore.Http.StatusCodes;
|
||||||
|
|
||||||
|
namespace API.Controllers;
|
||||||
|
|
||||||
|
[ApiVersion(2)]
|
||||||
|
[ApiController]
|
||||||
|
[Produces("application/json")]
|
||||||
|
[Route("v{v:apiVersion}/[controller]")]
|
||||||
|
public class LibraryConnectorController(PgsqlContext context) : Controller
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets all configured Library-Connectors
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Array of configured Library-Connectors</returns>
|
||||||
|
[HttpGet]
|
||||||
|
[ProducesResponseType<LibraryConnector[]>(Status200OK)]
|
||||||
|
public IActionResult GetAllConnectors()
|
||||||
|
{
|
||||||
|
LibraryConnector[] connectors = context.LibraryConnectors.ToArray();
|
||||||
|
return Ok(connectors);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns Library-Connector with requested ID
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">Library-Connector-ID</param>
|
||||||
|
/// <returns>Library-Connector</returns>
|
||||||
|
[HttpGet("{id}")]
|
||||||
|
[ProducesResponseType<LibraryConnector>(Status200OK)]
|
||||||
|
[ProducesResponseType(Status404NotFound)]
|
||||||
|
public IActionResult GetConnector(string id)
|
||||||
|
{
|
||||||
|
LibraryConnector? ret = context.LibraryConnectors.Find(id);
|
||||||
|
return (ret is not null) switch
|
||||||
|
{
|
||||||
|
true => Ok(ret),
|
||||||
|
false => NotFound()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a new Library-Connector
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="libraryConnector">Library-Connector</param>
|
||||||
|
/// <returns>Nothing</returns>
|
||||||
|
[HttpPut]
|
||||||
|
[ProducesResponseType(Status200OK)]
|
||||||
|
[ProducesResponseType<string>(Status500InternalServerError)]
|
||||||
|
public IActionResult CreateConnector([FromBody]LibraryConnector libraryConnector)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
context.LibraryConnectors.Add(libraryConnector);
|
||||||
|
context.SaveChanges();
|
||||||
|
return Created();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return StatusCode(500, e.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Deletes the Library-Connector with the requested ID
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">Library-Connector-ID</param>
|
||||||
|
/// <returns>Nothing</returns>
|
||||||
|
[HttpDelete("{id}")]
|
||||||
|
[ProducesResponseType(Status200OK)]
|
||||||
|
[ProducesResponseType(Status404NotFound)]
|
||||||
|
[ProducesResponseType(Status500InternalServerError)]
|
||||||
|
public IActionResult DeleteConnector(string id)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
LibraryConnector? ret = context.LibraryConnectors.Find(id);
|
||||||
|
switch (ret is not null)
|
||||||
|
{
|
||||||
|
case true:
|
||||||
|
context.Remove(ret);
|
||||||
|
context.SaveChanges();
|
||||||
|
return Ok();
|
||||||
|
case false: return NotFound();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return StatusCode(500, e.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
163
API/Controllers/MangaController.cs
Normal file
163
API/Controllers/MangaController.cs
Normal file
@ -0,0 +1,163 @@
|
|||||||
|
using API.Schema;
|
||||||
|
using Asp.Versioning;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using static Microsoft.AspNetCore.Http.StatusCodes;
|
||||||
|
|
||||||
|
namespace API.Controllers;
|
||||||
|
|
||||||
|
[ApiVersion(2)]
|
||||||
|
[ApiController]
|
||||||
|
[Produces("application/json")]
|
||||||
|
[Route("v{v:apiVersion}/[controller]")]
|
||||||
|
public class MangaController(PgsqlContext context) : Controller
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Returns all cached Manga
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Array of Manga</returns>
|
||||||
|
[HttpGet]
|
||||||
|
[ProducesResponseType<Manga[]>(Status200OK)]
|
||||||
|
public IActionResult GetAllManga()
|
||||||
|
{
|
||||||
|
Manga[] ret = context.Manga.ToArray();
|
||||||
|
return Ok(ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns all cached Manga with IDs
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ids">Array of Manga-IDs</param>
|
||||||
|
/// <returns>Array of Manga</returns>
|
||||||
|
[HttpPost("WithIDs")]
|
||||||
|
[ProducesResponseType<Manga[]>(Status200OK)]
|
||||||
|
public IActionResult GetManga([FromBody]string[] ids)
|
||||||
|
{
|
||||||
|
Manga[] ret = context.Manga.Where(m => ids.Contains(m.MangaId)).ToArray();
|
||||||
|
return Ok(ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Return Manga with ID
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">Manga-ID</param>
|
||||||
|
/// <returns>Manga</returns>
|
||||||
|
[HttpGet("{id}")]
|
||||||
|
[ProducesResponseType<Manga>(Status200OK)]
|
||||||
|
[ProducesResponseType(Status404NotFound)]
|
||||||
|
public IActionResult GetManga(string id)
|
||||||
|
{
|
||||||
|
Manga? ret = context.Manga.Find(id);
|
||||||
|
return (ret is not null) switch
|
||||||
|
{
|
||||||
|
true => Ok(ret),
|
||||||
|
false => NotFound()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Delete Manga with ID
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">Manga-ID</param>
|
||||||
|
/// <returns>Nothing</returns>
|
||||||
|
[HttpDelete("{id}")]
|
||||||
|
[ProducesResponseType(Status200OK)]
|
||||||
|
[ProducesResponseType(Status404NotFound)]
|
||||||
|
[ProducesResponseType(Status500InternalServerError)]
|
||||||
|
public IActionResult DeleteManga(string id)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Manga? ret = context.Manga.Find(id);
|
||||||
|
switch (ret is not null)
|
||||||
|
{
|
||||||
|
case true:
|
||||||
|
context.Remove(ret);
|
||||||
|
context.SaveChanges();
|
||||||
|
return Ok();
|
||||||
|
case false: return NotFound();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return StatusCode(500, e.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns URL of Cover of Manga
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">Manga-ID</param>
|
||||||
|
/// <returns>URL of Cover</returns>
|
||||||
|
[HttpGet("{id}/Cover")]
|
||||||
|
[ProducesResponseType<string>(Status500InternalServerError)]
|
||||||
|
public IActionResult GetCover(string id)
|
||||||
|
{
|
||||||
|
return StatusCode(500, "Not implemented"); //TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns all Chapters of Manga
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">Manga-ID</param>
|
||||||
|
/// <returns>Array of Chapters</returns>
|
||||||
|
[HttpGet("{id}/Chapters")]
|
||||||
|
[ProducesResponseType<Chapter[]>(Status200OK)]
|
||||||
|
[ProducesResponseType<string>(Status404NotFound)]
|
||||||
|
public IActionResult GetChapters(string id)
|
||||||
|
{
|
||||||
|
Manga? m = context.Manga.Find(id);
|
||||||
|
if (m is null)
|
||||||
|
return NotFound("Manga could not be found");
|
||||||
|
Chapter[] ret = context.Chapters.Where(c => c.ParentManga.MangaId == m.MangaId).ToArray();
|
||||||
|
return Ok(ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the latest Chapter of requested Manga
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">Manga-ID</param>
|
||||||
|
/// <returns>Latest Chapter</returns>
|
||||||
|
[HttpGet("{id}/Chapter/Latest")]
|
||||||
|
[ProducesResponseType<Chapter>(Status200OK)]
|
||||||
|
[ProducesResponseType<string>(Status404NotFound)]
|
||||||
|
public IActionResult GetLatestChapter(string id)
|
||||||
|
{
|
||||||
|
Manga? m = context.Manga.Find(id);
|
||||||
|
if (m is null)
|
||||||
|
return NotFound("Manga could not be found");
|
||||||
|
List<Chapter> chapters = context.Chapters.Where(c => c.ParentManga.MangaId == m.MangaId).ToList();
|
||||||
|
Chapter? max = chapters.Max();
|
||||||
|
if (max is null)
|
||||||
|
return NotFound("Chapter could not be found");
|
||||||
|
return Ok(max);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Configure the cut-off for Manga
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>This is important for the DownloadNewChapters-Job</remarks>
|
||||||
|
/// <param name="id">Manga-ID</param>
|
||||||
|
/// <returns>Nothing</returns>
|
||||||
|
[HttpPatch("{id}/IgnoreChaptersBefore")]
|
||||||
|
[ProducesResponseType<float>(Status200OK)]
|
||||||
|
public IActionResult IgnoreChaptersBefore(string id)
|
||||||
|
{
|
||||||
|
Manga? m = context.Manga.Find(id);
|
||||||
|
if (m is null)
|
||||||
|
return NotFound("Manga could not be found");
|
||||||
|
return Ok(m.IgnoreChapterBefore);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Move the Directory the .cbz-files are located in
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">Manga-ID</param>
|
||||||
|
/// <param name="folder">New Directory-Path</param>
|
||||||
|
/// <returns>Nothing</returns>
|
||||||
|
[HttpPost("{id}/MoveFolder")]
|
||||||
|
[ProducesResponseType<string>(Status500InternalServerError)]
|
||||||
|
public IActionResult MoveFolder(string id, [FromBody]string folder)
|
||||||
|
{
|
||||||
|
return StatusCode(500, "Not implemented"); //TODO
|
||||||
|
}
|
||||||
|
}
|
26
API/Controllers/MiscController.cs
Normal file
26
API/Controllers/MiscController.cs
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
using API.Schema;
|
||||||
|
using API.Schema.MangaConnectors;
|
||||||
|
using Asp.Versioning;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using static Microsoft.AspNetCore.Http.StatusCodes;
|
||||||
|
|
||||||
|
namespace API.Controllers;
|
||||||
|
|
||||||
|
[ApiVersion(2)]
|
||||||
|
[ApiController]
|
||||||
|
[Produces("application/json")]
|
||||||
|
[Route("v{v:apiVersion}")]
|
||||||
|
public class MiscController(PgsqlContext context) : Controller
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Get all available Connectors (Scanlation-Sites)
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Array of MangaConnector</returns>
|
||||||
|
[HttpGet("GetConnectors")]
|
||||||
|
[ProducesResponseType<MangaConnector[]>(Status200OK)]
|
||||||
|
public IActionResult GetConnectors()
|
||||||
|
{
|
||||||
|
MangaConnector[] connectors = context.MangaConnectors.ToArray();
|
||||||
|
return Ok(connectors);
|
||||||
|
}
|
||||||
|
}
|
95
API/Controllers/NotificationConnectorController.cs
Normal file
95
API/Controllers/NotificationConnectorController.cs
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
using API.Schema;
|
||||||
|
using API.Schema.NotificationConnectors;
|
||||||
|
using Asp.Versioning;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using static Microsoft.AspNetCore.Http.StatusCodes;
|
||||||
|
|
||||||
|
namespace API.Controllers;
|
||||||
|
|
||||||
|
[ApiVersion(2)]
|
||||||
|
[ApiController]
|
||||||
|
[Produces("application/json")]
|
||||||
|
[Route("v{v:apiVersion}/[controller]")]
|
||||||
|
public class NotificationConnectorController(PgsqlContext context) : Controller
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets all configured Notification-Connectors
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Array of configured Notification-Connectors</returns>
|
||||||
|
[HttpGet]
|
||||||
|
[ProducesResponseType<NotificationConnector[]>(Status200OK)]
|
||||||
|
public IActionResult GetAllConnectors()
|
||||||
|
{
|
||||||
|
NotificationConnector[] ret = context.NotificationConnectors.ToArray();
|
||||||
|
return Ok(ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns Notification-Connector with requested ID
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">Notification-Connector-ID</param>
|
||||||
|
/// <returns>Notification-Connector</returns>
|
||||||
|
[HttpGet("{id}")]
|
||||||
|
[ProducesResponseType<NotificationConnector>(Status200OK)]
|
||||||
|
[ProducesResponseType(Status404NotFound)]
|
||||||
|
public IActionResult GetConnector(string id)
|
||||||
|
{
|
||||||
|
NotificationConnector? ret = context.NotificationConnectors.Find(id);
|
||||||
|
return (ret is not null) switch
|
||||||
|
{
|
||||||
|
true => Ok(ret),
|
||||||
|
false => NotFound()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a new Notification-Connector
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="notificationConnector">Notification-Connector</param>
|
||||||
|
/// <returns>Nothing</returns>
|
||||||
|
[HttpPut]
|
||||||
|
[ProducesResponseType<NotificationConnector[]>(Status200OK)]
|
||||||
|
[ProducesResponseType<string>(Status500InternalServerError)]
|
||||||
|
public IActionResult CreateConnector([FromBody]NotificationConnector notificationConnector)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
context.NotificationConnectors.Add(notificationConnector);
|
||||||
|
context.SaveChanges();
|
||||||
|
return Created();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return StatusCode(500, e.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Deletes the Notification-Connector with the requested ID
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">Notification-Connector-ID</param>
|
||||||
|
/// <returns>Nothing</returns>
|
||||||
|
[HttpDelete("{id}")]
|
||||||
|
[ProducesResponseType(Status200OK)]
|
||||||
|
[ProducesResponseType(Status404NotFound)]
|
||||||
|
[ProducesResponseType(Status500InternalServerError)]
|
||||||
|
public IActionResult DeleteConnector(string id)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
NotificationConnector? ret = context.NotificationConnectors.Find(id);
|
||||||
|
switch (ret is not null)
|
||||||
|
{
|
||||||
|
case true:
|
||||||
|
context.Remove(ret);
|
||||||
|
context.SaveChanges();
|
||||||
|
return Ok();
|
||||||
|
case false: return NotFound();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return StatusCode(500, e.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
150
API/Controllers/SearchController.cs
Normal file
150
API/Controllers/SearchController.cs
Normal file
@ -0,0 +1,150 @@
|
|||||||
|
using API.Schema;
|
||||||
|
using API.Schema.MangaConnectors;
|
||||||
|
using Asp.Versioning;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using static Microsoft.AspNetCore.Http.StatusCodes;
|
||||||
|
|
||||||
|
namespace API.Controllers;
|
||||||
|
|
||||||
|
[ApiVersion(2)]
|
||||||
|
[ApiController]
|
||||||
|
[Produces("application/json")]
|
||||||
|
[Route("v{v:apiVersion}/[controller]")]
|
||||||
|
public class SearchController(PgsqlContext context) : Controller
|
||||||
|
{
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initiate a search for a Manga on all Connectors
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">Name/Title of the Manga</param>
|
||||||
|
/// <returns>Array of Manga</returns>
|
||||||
|
[HttpPost("{name}")]
|
||||||
|
[ProducesResponseType<Manga[]>(Status500InternalServerError)]
|
||||||
|
public IActionResult SearchMangaGlobal(string name)
|
||||||
|
{
|
||||||
|
List<(Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)> allManga = new();
|
||||||
|
foreach (MangaConnector contextMangaConnector in context.MangaConnectors)
|
||||||
|
allManga.AddRange(contextMangaConnector.GetManga(name));
|
||||||
|
List<Manga> retMangas = new();
|
||||||
|
foreach ((Manga? manga, List<Author>? authors, List<MangaTag>? tags, List<Link>? links, List<MangaAltTitle>? altTitles) in allManga)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Manga? add = AddMangaToContext(manga, authors, tags, links, altTitles);
|
||||||
|
if(add is not null)
|
||||||
|
retMangas.Add(add);
|
||||||
|
}
|
||||||
|
catch (DbUpdateException)
|
||||||
|
{
|
||||||
|
return StatusCode(500, new ProblemResponse("An error occurred while processing your request."));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Ok(retMangas.ToArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initiate a search for a Manga on a specific Connector
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">Manga-Connector-ID</param>
|
||||||
|
/// <param name="name">Name/Title of the Manga</param>
|
||||||
|
/// <returns>Manga</returns>
|
||||||
|
[HttpPost("{id}/{name}")]
|
||||||
|
[ProducesResponseType<Manga[]>(Status200OK)]
|
||||||
|
[ProducesResponseType<ProblemResponse>(Status404NotFound)]
|
||||||
|
[ProducesResponseType<ProblemResponse>(Status500InternalServerError)]
|
||||||
|
public IActionResult SearchManga(string id, string name)
|
||||||
|
{
|
||||||
|
MangaConnector? connector = context.MangaConnectors.Find(id);
|
||||||
|
if (connector is null)
|
||||||
|
return NotFound(new ProblemResponse("Connector not found."));
|
||||||
|
(Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)[] mangas = connector.GetManga(name);
|
||||||
|
List<Manga> retMangas = new();
|
||||||
|
foreach ((Manga? manga, List<Author>? authors, List<MangaTag>? tags, List<Link>? links, List<MangaAltTitle>? altTitles) in mangas)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Manga? add = AddMangaToContext(manga, authors, tags, links, altTitles);
|
||||||
|
if(add is not null)
|
||||||
|
retMangas.Add(add);
|
||||||
|
}
|
||||||
|
catch (DbUpdateException e)
|
||||||
|
{
|
||||||
|
return StatusCode(500, new ProblemResponse("An error occurred while processing your request.", e.Message));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Ok(retMangas.ToArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
private Manga? AddMangaToContext(Manga? manga, List<Author>? authors, List<MangaTag>? tags, List<Link>? links,
|
||||||
|
List<MangaAltTitle>? altTitles)
|
||||||
|
{
|
||||||
|
if (manga is null)
|
||||||
|
return null;
|
||||||
|
Manga? existing = context.Manga.FirstOrDefault(m =>
|
||||||
|
m.MangaConnector == manga.MangaConnector && m.ConnectorId == manga.ConnectorId);
|
||||||
|
|
||||||
|
if (tags is not null)
|
||||||
|
{
|
||||||
|
IEnumerable<MangaTag> mergedTags = tags.Select(mt =>
|
||||||
|
{
|
||||||
|
MangaTag? inDb = context.Tags.FirstOrDefault(t => t.Equals(mt));
|
||||||
|
return inDb ?? mt;
|
||||||
|
});
|
||||||
|
manga.Tags = mergedTags.ToList();
|
||||||
|
IEnumerable<MangaTag> newTags = manga.Tags.Where(mt => !context.Tags.Any(t => t.Tag.Equals(mt.Tag)));
|
||||||
|
context.Tags.AddRange(newTags);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (authors is not null)
|
||||||
|
{
|
||||||
|
IEnumerable<Author> mergedAuthors = authors.Select(ma =>
|
||||||
|
{
|
||||||
|
Author? inDb = context.Authors.FirstOrDefault(a => a.AuthorName == ma.AuthorName);
|
||||||
|
return inDb ?? ma;
|
||||||
|
});
|
||||||
|
manga.Authors = mergedAuthors.ToList();
|
||||||
|
IEnumerable<Author> newAuthors = manga.Authors.Where(ma => !context.Authors.Any(a =>
|
||||||
|
a.AuthorName == ma.AuthorName));
|
||||||
|
context.Authors.AddRange(newAuthors);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (links is not null)
|
||||||
|
{
|
||||||
|
IEnumerable<Link> mergedLinks = links.Select(ml =>
|
||||||
|
{
|
||||||
|
Link? inDb = context.Link.FirstOrDefault(l =>
|
||||||
|
l.LinkProvider == ml.LinkProvider && l.LinkUrl == ml.LinkUrl);
|
||||||
|
return inDb ?? ml;
|
||||||
|
});
|
||||||
|
manga.Links = mergedLinks.ToList();
|
||||||
|
IEnumerable<Link> newLinks = manga.Links.Where(ml => !context.Link.Any(l =>
|
||||||
|
l.LinkProvider == ml.LinkProvider && l.LinkUrl == ml.LinkUrl));
|
||||||
|
context.Link.AddRange(newLinks);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (altTitles is not null)
|
||||||
|
{
|
||||||
|
IEnumerable<MangaAltTitle> mergedAltTitles = altTitles.Select(mat =>
|
||||||
|
{
|
||||||
|
MangaAltTitle? inDb = context.AltTitles.FirstOrDefault(at =>
|
||||||
|
at.Language == mat.Language && at.Title == mat.Title);
|
||||||
|
return inDb ?? mat;
|
||||||
|
});
|
||||||
|
manga.AltTitles = mergedAltTitles.ToList();
|
||||||
|
IEnumerable<MangaAltTitle> newAltTitles = manga.AltTitles.Where(mat =>
|
||||||
|
!context.AltTitles.Any(at => at.Language == mat.Language && at.Title == mat.Title));
|
||||||
|
context.AltTitles.AddRange(newAltTitles);
|
||||||
|
}
|
||||||
|
|
||||||
|
existing?.UpdateWithInfo(manga);
|
||||||
|
if(existing is not null)
|
||||||
|
context.Manga.Update(existing);
|
||||||
|
else
|
||||||
|
context.Manga.Add(manga);
|
||||||
|
|
||||||
|
context.SaveChanges();
|
||||||
|
return existing ?? manga;
|
||||||
|
}
|
||||||
|
}
|
161
API/Controllers/SettingsController.cs
Normal file
161
API/Controllers/SettingsController.cs
Normal file
@ -0,0 +1,161 @@
|
|||||||
|
using API.Schema;
|
||||||
|
using Asp.Versioning;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using static Microsoft.AspNetCore.Http.StatusCodes;
|
||||||
|
|
||||||
|
namespace API.Controllers;
|
||||||
|
|
||||||
|
[ApiVersion(2)]
|
||||||
|
[ApiController]
|
||||||
|
[Produces("application/json")]
|
||||||
|
[Route("v{v:apiVersion}/[controller]")]
|
||||||
|
public class SettingsController(PgsqlContext context) : Controller
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Get all Settings
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet]
|
||||||
|
[ProducesResponseType<string>(Status500InternalServerError)]
|
||||||
|
public IActionResult GetSettings()
|
||||||
|
{
|
||||||
|
return StatusCode(500, "Not implemented"); //TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get the current UserAgent used by Tranga
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>UserAgent as string</returns>
|
||||||
|
[HttpGet("UserAgent")]
|
||||||
|
[ProducesResponseType<string>(Status500InternalServerError)]
|
||||||
|
public IActionResult GetUserAgent()
|
||||||
|
{
|
||||||
|
return StatusCode(500, "Not implemented"); //TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Set a new UserAgent
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Nothing</returns>
|
||||||
|
[HttpPatch("UserAgent")]
|
||||||
|
[ProducesResponseType<string>(Status500InternalServerError)]
|
||||||
|
public IActionResult SetUserAgent()
|
||||||
|
{
|
||||||
|
return StatusCode(500, "Not implemented"); //TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reset the UserAgent to default
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Nothing</returns>
|
||||||
|
[HttpDelete("UserAgent")]
|
||||||
|
[ProducesResponseType<string>(Status500InternalServerError)]
|
||||||
|
public IActionResult ResetUserAgent()
|
||||||
|
{
|
||||||
|
return StatusCode(500, "Not implemented"); //TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get all Request-Limits
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet("RequestLimits")]
|
||||||
|
[ProducesResponseType<string>(Status500InternalServerError)]
|
||||||
|
public IActionResult GetRequestLimits()
|
||||||
|
{
|
||||||
|
return StatusCode(500, "Not implemented"); //TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Update all Request-Limits to new values
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Nothing</returns>
|
||||||
|
[HttpPatch("RequestLimits")]
|
||||||
|
[ProducesResponseType<string>(Status500InternalServerError)]
|
||||||
|
public IActionResult SetRequestLimits()
|
||||||
|
{
|
||||||
|
return StatusCode(500, "Not implemented"); //TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reset all Request-Limits
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Nothing</returns>
|
||||||
|
[HttpDelete("RequestLimits")]
|
||||||
|
[ProducesResponseType<string>(Status500InternalServerError)]
|
||||||
|
public IActionResult ResetRequestLimits()
|
||||||
|
{
|
||||||
|
return StatusCode(500, "Not implemented"); //TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns Level of Image-Compression for Images
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet("ImageCompression")]
|
||||||
|
[ProducesResponseType<string>(Status500InternalServerError)]
|
||||||
|
public IActionResult GetImageCompression()
|
||||||
|
{
|
||||||
|
return StatusCode(500, "Not implemented"); //TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Set the Image-Compression-Level for Images
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="percentage">100 to disable, 0-99 for JPEG compression-Level</param>
|
||||||
|
/// <returns>Nothing</returns>
|
||||||
|
[HttpPatch("ImageCompression")]
|
||||||
|
[ProducesResponseType<string>(Status500InternalServerError)]
|
||||||
|
public IActionResult SetImageCompression(int percentage)
|
||||||
|
{
|
||||||
|
return StatusCode(500, "Not implemented"); //TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get state of Black/White-Image setting
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>True if enabled</returns>
|
||||||
|
[HttpGet("BWImages")]
|
||||||
|
[ProducesResponseType<string>(Status500InternalServerError)]
|
||||||
|
public IActionResult GetBwImagesToggle()
|
||||||
|
{
|
||||||
|
return StatusCode(500, "Not implemented"); //TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Enable/Disable conversion of Images to Black and White
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="enabled">true to enable</param>
|
||||||
|
/// <returns>Nothing</returns>
|
||||||
|
[HttpPatch("BWImages")]
|
||||||
|
[ProducesResponseType<string>(Status500InternalServerError)]
|
||||||
|
public IActionResult SetBwImagesToggle(bool enabled)
|
||||||
|
{
|
||||||
|
return StatusCode(500, "Not implemented"); //TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get state of April Fools Mode
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>April Fools Mode disables all downloads on April 1st</remarks>
|
||||||
|
/// <returns>True if enabled</returns>
|
||||||
|
[HttpGet("AprilFoolsMode")]
|
||||||
|
[ProducesResponseType<string>(Status500InternalServerError)]
|
||||||
|
public IActionResult GetAprilFoolsMode()
|
||||||
|
{
|
||||||
|
return StatusCode(500, "Not implemented"); //TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Enable/Disable April Fools Mode
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>April Fools Mode disables all downloads on April 1st</remarks>
|
||||||
|
/// <param name="enabled">true to enable</param>
|
||||||
|
/// <returns>Nothing</returns>
|
||||||
|
[HttpPatch("AprilFoolsMode")]
|
||||||
|
[ProducesResponseType<string>(Status500InternalServerError)]
|
||||||
|
public IActionResult SetAprilFoolsMode(bool enabled)
|
||||||
|
{
|
||||||
|
return StatusCode(500, "Not implemented"); //TODO
|
||||||
|
}
|
||||||
|
}
|
@ -1,13 +0,0 @@
|
|||||||
# syntax=docker/dockerfile:1
|
|
||||||
|
|
||||||
FROM mcr.microsoft.com/dotnet/sdk:7.0 as build-env
|
|
||||||
WORKDIR /src
|
|
||||||
COPY . /src/
|
|
||||||
RUN dotnet restore API/API.csproj
|
|
||||||
RUN dotnet publish -c Release -o /publish
|
|
||||||
|
|
||||||
FROM glax/tranga-base:dev as runtime
|
|
||||||
WORKDIR /publish
|
|
||||||
COPY --from=build-env /publish .
|
|
||||||
EXPOSE 6531
|
|
||||||
ENTRYPOINT ["dotnet", "/publish/API.dll"]
|
|
110
API/MangaDownloadClients/ChromiumDownloadClient.cs
Normal file
110
API/MangaDownloadClients/ChromiumDownloadClient.cs
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
using System.Net;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using HtmlAgilityPack;
|
||||||
|
using PuppeteerSharp;
|
||||||
|
|
||||||
|
namespace API.MangaDownloadClients;
|
||||||
|
|
||||||
|
internal class ChromiumDownloadClient : DownloadClient
|
||||||
|
{
|
||||||
|
private static IBrowser? _browser;
|
||||||
|
private const int StartTimeoutMs = 10000;
|
||||||
|
private readonly HttpDownloadClient _httpDownloadClient;
|
||||||
|
|
||||||
|
private static async Task<IBrowser> StartBrowser()
|
||||||
|
{
|
||||||
|
return await Puppeteer.LaunchAsync(new LaunchOptions
|
||||||
|
{
|
||||||
|
Headless = true,
|
||||||
|
Args = new [] {
|
||||||
|
"--disable-gpu",
|
||||||
|
"--disable-dev-shm-usage",
|
||||||
|
"--disable-setuid-sandbox",
|
||||||
|
"--no-sandbox"},
|
||||||
|
Timeout = StartTimeoutMs
|
||||||
|
}, new LoggerFactory([new LogProvider()])); //TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
private class LogProvider : ILoggerProvider
|
||||||
|
{
|
||||||
|
//TODO
|
||||||
|
public void Dispose() { }
|
||||||
|
|
||||||
|
public ILogger CreateLogger(string categoryName) => new Logger();
|
||||||
|
}
|
||||||
|
|
||||||
|
private class Logger : ILogger
|
||||||
|
{
|
||||||
|
public Logger() : base() { }
|
||||||
|
|
||||||
|
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter)
|
||||||
|
{
|
||||||
|
if (logLevel <= LogLevel.Information)
|
||||||
|
return;
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsEnabled(LogLevel logLevel) => true;
|
||||||
|
|
||||||
|
public IDisposable? BeginScope<TState>(TState state) where TState : notnull => null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ChromiumDownloadClient()
|
||||||
|
{
|
||||||
|
_httpDownloadClient = new();
|
||||||
|
if(_browser is null)
|
||||||
|
_browser = StartBrowser().Result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly Regex _imageUrlRex = new(@"https?:\/\/.*\.(?:p?jpe?g|gif|a?png|bmp|avif|webp)(\?.*)?");
|
||||||
|
internal override RequestResult MakeRequestInternal(string url, string? referrer = null, string? clickButton = null)
|
||||||
|
{
|
||||||
|
return _imageUrlRex.IsMatch(url)
|
||||||
|
? _httpDownloadClient.MakeRequestInternal(url, referrer)
|
||||||
|
: MakeRequestBrowser(url, referrer, clickButton);
|
||||||
|
}
|
||||||
|
|
||||||
|
private RequestResult MakeRequestBrowser(string url, string? referrer = null, string? clickButton = null)
|
||||||
|
{
|
||||||
|
IPage page = _browser.NewPageAsync().Result;
|
||||||
|
page.DefaultTimeout = 10000;
|
||||||
|
IResponse response;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
response = page.GoToAsync(url, WaitUntilNavigation.Networkidle0).Result;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
page.CloseAsync();
|
||||||
|
return new RequestResult(HttpStatusCode.InternalServerError, null, Stream.Null);
|
||||||
|
}
|
||||||
|
|
||||||
|
Stream stream = Stream.Null;
|
||||||
|
HtmlDocument? document = null;
|
||||||
|
|
||||||
|
if (response.Headers.TryGetValue("Content-Type", out string? content))
|
||||||
|
{
|
||||||
|
if (content.Contains("text/html"))
|
||||||
|
{
|
||||||
|
if (clickButton is not null && page.QuerySelectorAsync(clickButton).Result is not null)
|
||||||
|
page.ClickAsync(clickButton).Wait();
|
||||||
|
string htmlString = page.GetContentAsync().Result;
|
||||||
|
stream = new MemoryStream(Encoding.Default.GetBytes(htmlString));
|
||||||
|
document = new ();
|
||||||
|
document.LoadHtml(htmlString);
|
||||||
|
}else if (content.Contains("image"))
|
||||||
|
{
|
||||||
|
stream = new MemoryStream(response.BufferAsync().Result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
page.CloseAsync();
|
||||||
|
return new RequestResult(HttpStatusCode.InternalServerError, null, Stream.Null);
|
||||||
|
}
|
||||||
|
|
||||||
|
page.CloseAsync();
|
||||||
|
return new RequestResult(response.Status, document, stream, false, "");
|
||||||
|
}
|
||||||
|
}
|
42
API/MangaDownloadClients/DownloadClient.cs
Normal file
42
API/MangaDownloadClients/DownloadClient.cs
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
using System.Net;
|
||||||
|
using API.Schema;
|
||||||
|
|
||||||
|
namespace API.MangaDownloadClients;
|
||||||
|
|
||||||
|
internal abstract class DownloadClient
|
||||||
|
{
|
||||||
|
private readonly Dictionary<RequestType, DateTime> _lastExecutedRateLimit;
|
||||||
|
|
||||||
|
protected DownloadClient()
|
||||||
|
{
|
||||||
|
this._lastExecutedRateLimit = new();
|
||||||
|
}
|
||||||
|
|
||||||
|
public RequestResult MakeRequest(string url, RequestType requestType, string? referrer = null, string? clickButton = null)
|
||||||
|
{
|
||||||
|
if (!TrangaSettings.requestLimits.ContainsKey(requestType))
|
||||||
|
{
|
||||||
|
return new RequestResult(HttpStatusCode.NotAcceptable, null, Stream.Null);
|
||||||
|
}
|
||||||
|
|
||||||
|
int rateLimit = TrangaSettings.userAgent == TrangaSettings.DefaultUserAgent
|
||||||
|
? TrangaSettings.DefaultRequestLimits[requestType]
|
||||||
|
: TrangaSettings.requestLimits[requestType];
|
||||||
|
|
||||||
|
TimeSpan timeBetweenRequests = TimeSpan.FromMinutes(1).Divide(rateLimit);
|
||||||
|
_lastExecutedRateLimit.TryAdd(requestType, DateTime.Now.Subtract(timeBetweenRequests));
|
||||||
|
|
||||||
|
TimeSpan rateLimitTimeout = timeBetweenRequests.Subtract(DateTime.Now.Subtract(_lastExecutedRateLimit[requestType]));
|
||||||
|
|
||||||
|
if (rateLimitTimeout > TimeSpan.Zero)
|
||||||
|
{
|
||||||
|
Thread.Sleep(rateLimitTimeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
RequestResult result = MakeRequestInternal(url, referrer, clickButton);
|
||||||
|
_lastExecutedRateLimit[requestType] = DateTime.Now;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal abstract RequestResult MakeRequestInternal(string url, string? referrer = null, string? clickButton = null);
|
||||||
|
}
|
73
API/MangaDownloadClients/HttpDownloadClient.cs
Normal file
73
API/MangaDownloadClients/HttpDownloadClient.cs
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
using System.Net;
|
||||||
|
using API.Schema;
|
||||||
|
using HtmlAgilityPack;
|
||||||
|
|
||||||
|
namespace API.MangaDownloadClients;
|
||||||
|
|
||||||
|
internal class HttpDownloadClient : DownloadClient
|
||||||
|
{
|
||||||
|
private static readonly HttpClient Client = new()
|
||||||
|
{
|
||||||
|
Timeout = TimeSpan.FromSeconds(10)
|
||||||
|
};
|
||||||
|
|
||||||
|
public HttpDownloadClient()
|
||||||
|
{
|
||||||
|
Client.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", TrangaSettings.userAgent);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal override RequestResult MakeRequestInternal(string url, string? referrer = null, string? clickButton = null)
|
||||||
|
{
|
||||||
|
//TODO
|
||||||
|
//if (clickButton is not null)
|
||||||
|
//Log("Can not click button on static site.");
|
||||||
|
HttpResponseMessage? response = null;
|
||||||
|
while (response is null)
|
||||||
|
{
|
||||||
|
HttpRequestMessage requestMessage = new(HttpMethod.Get, url);
|
||||||
|
if (referrer is not null)
|
||||||
|
requestMessage.Headers.Referrer = new Uri(referrer);
|
||||||
|
//Log($"Requesting {requestType} {url}");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
response = Client.Send(requestMessage);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
switch (e)
|
||||||
|
{
|
||||||
|
case TaskCanceledException:
|
||||||
|
return new RequestResult(HttpStatusCode.RequestTimeout, null, Stream.Null);
|
||||||
|
case HttpRequestException:
|
||||||
|
return new RequestResult(HttpStatusCode.BadRequest, null, Stream.Null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!response.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
return new RequestResult(response.StatusCode, null, Stream.Null);
|
||||||
|
}
|
||||||
|
|
||||||
|
Stream stream = response.Content.ReadAsStream();
|
||||||
|
|
||||||
|
HtmlDocument? document = null;
|
||||||
|
|
||||||
|
if (response.Content.Headers.ContentType?.MediaType == "text/html")
|
||||||
|
{
|
||||||
|
StreamReader reader = new (stream);
|
||||||
|
document = new ();
|
||||||
|
document.LoadHtml(reader.ReadToEnd());
|
||||||
|
stream.Position = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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, document, stream, true,
|
||||||
|
response.RequestMessage.RequestUri.AbsoluteUri);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new RequestResult(response.StatusCode, document, stream);
|
||||||
|
}
|
||||||
|
}
|
27
API/MangaDownloadClients/RequestResult.cs
Normal file
27
API/MangaDownloadClients/RequestResult.cs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
using System.Net;
|
||||||
|
using HtmlAgilityPack;
|
||||||
|
|
||||||
|
namespace API.MangaDownloadClients;
|
||||||
|
|
||||||
|
public struct RequestResult
|
||||||
|
{
|
||||||
|
public HttpStatusCode statusCode { get; }
|
||||||
|
public Stream result { get; }
|
||||||
|
public bool hasBeenRedirected { get; }
|
||||||
|
public string? redirectedToUrl { get; }
|
||||||
|
public HtmlDocument? htmlDocument { get; }
|
||||||
|
|
||||||
|
public RequestResult(HttpStatusCode statusCode, HtmlDocument? htmlDocument, Stream result)
|
||||||
|
{
|
||||||
|
this.statusCode = statusCode;
|
||||||
|
this.htmlDocument = htmlDocument;
|
||||||
|
this.result = result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RequestResult(HttpStatusCode statusCode, HtmlDocument? htmlDocument, Stream result, bool hasBeenRedirected, string redirectedTo)
|
||||||
|
: this(statusCode, htmlDocument, result)
|
||||||
|
{
|
||||||
|
this.hasBeenRedirected = hasBeenRedirected;
|
||||||
|
redirectedToUrl = redirectedTo;
|
||||||
|
}
|
||||||
|
}
|
11
API/MangaDownloadClients/RequestType.cs
Normal file
11
API/MangaDownloadClients/RequestType.cs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
namespace API.MangaDownloadClients;
|
||||||
|
|
||||||
|
public enum RequestType : byte
|
||||||
|
{
|
||||||
|
Default = 0,
|
||||||
|
MangaDexFeed = 1,
|
||||||
|
MangaImage = 2,
|
||||||
|
MangaCover = 3,
|
||||||
|
MangaDexImage = 5,
|
||||||
|
MangaInfo = 6
|
||||||
|
}
|
781
API/Migrations/20241201235443_Initial.Designer.cs
generated
Normal file
781
API/Migrations/20241201235443_Initial.Designer.cs
generated
Normal file
@ -0,0 +1,781 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using API.Schema;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace API.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(PgsqlContext))]
|
||||||
|
[Migration("20241201235443_Initial")]
|
||||||
|
partial class Initial
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasAnnotation("ProductVersion", "9.0.0")
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||||
|
|
||||||
|
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.Author", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("AuthorId")
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<string>("AuthorName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("AuthorId");
|
||||||
|
|
||||||
|
b.ToTable("Authors");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.Chapter", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("ChapterId")
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<string>("ArchiveFileName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("ChapterIds")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<float>("ChapterNumber")
|
||||||
|
.HasColumnType("real");
|
||||||
|
|
||||||
|
b.Property<bool>("Downloaded")
|
||||||
|
.HasColumnType("boolean");
|
||||||
|
|
||||||
|
b.Property<string>("ParentMangaId")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<string>("Title")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("Url")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<float?>("VolumeNumber")
|
||||||
|
.HasColumnType("real");
|
||||||
|
|
||||||
|
b.HasKey("ChapterId");
|
||||||
|
|
||||||
|
b.HasIndex("ParentMangaId");
|
||||||
|
|
||||||
|
b.ToTable("Chapters");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.Jobs.Job", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("JobId")
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.PrimitiveCollection<string[]>("DependsOnJobIds")
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("text[]");
|
||||||
|
|
||||||
|
b.Property<string>("JobId1")
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<byte>("JobType")
|
||||||
|
.HasColumnType("smallint");
|
||||||
|
|
||||||
|
b.Property<DateTime>("LastExecution")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<DateTime>("NextExecution")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("ParentJobId")
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<decimal>("RecurrenceMs")
|
||||||
|
.HasColumnType("numeric(20,0)");
|
||||||
|
|
||||||
|
b.Property<int>("state")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.HasKey("JobId");
|
||||||
|
|
||||||
|
b.HasIndex("JobId1");
|
||||||
|
|
||||||
|
b.ToTable("Jobs");
|
||||||
|
|
||||||
|
b.HasDiscriminator<byte>("JobType");
|
||||||
|
|
||||||
|
b.UseTphMappingStrategy();
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.LibraryConnectors.LibraryConnector", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("LibraryConnectorId")
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<string>("Auth")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("BaseUrl")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<byte>("LibraryType")
|
||||||
|
.HasColumnType("smallint");
|
||||||
|
|
||||||
|
b.HasKey("LibraryConnectorId");
|
||||||
|
|
||||||
|
b.ToTable("LibraryConnectors");
|
||||||
|
|
||||||
|
b.HasDiscriminator<byte>("LibraryType");
|
||||||
|
|
||||||
|
b.UseTphMappingStrategy();
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.Link", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("LinkId")
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<string>("LinkIds")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("LinkProvider")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("LinkUrl")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("MangaId")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.HasKey("LinkId");
|
||||||
|
|
||||||
|
b.HasIndex("MangaId");
|
||||||
|
|
||||||
|
b.ToTable("Link");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.Manga", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("MangaId")
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.PrimitiveCollection<string[]>("AltTitleIds")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text[]");
|
||||||
|
|
||||||
|
b.PrimitiveCollection<string[]>("AuthorIds")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text[]");
|
||||||
|
|
||||||
|
b.Property<string>("ConnectorId")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<string>("CoverFileNameInCache")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("CoverUrl")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("Description")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("FolderName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<float>("IgnoreChapterBefore")
|
||||||
|
.HasColumnType("real");
|
||||||
|
|
||||||
|
b.Property<string>("LatestChapterAvailableId")
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<string>("LatestChapterDownloadedId")
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.PrimitiveCollection<string[]>("LinkIds")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text[]");
|
||||||
|
|
||||||
|
b.Property<string>("MangaConnectorName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("character varying(32)");
|
||||||
|
|
||||||
|
b.Property<string>("MangaIds")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("OriginalLanguage")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<byte>("ReleaseStatus")
|
||||||
|
.HasColumnType("smallint");
|
||||||
|
|
||||||
|
b.PrimitiveCollection<string[]>("TagIds")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text[]");
|
||||||
|
|
||||||
|
b.Property<long>("year")
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b.HasKey("MangaId");
|
||||||
|
|
||||||
|
b.HasIndex("LatestChapterAvailableId")
|
||||||
|
.IsUnique();
|
||||||
|
|
||||||
|
b.HasIndex("LatestChapterDownloadedId")
|
||||||
|
.IsUnique();
|
||||||
|
|
||||||
|
b.HasIndex("MangaConnectorName");
|
||||||
|
|
||||||
|
b.ToTable("Manga");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.MangaAltTitle", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("AltTitleId")
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<string>("AltTitleIds")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("Language")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(8)
|
||||||
|
.HasColumnType("character varying(8)");
|
||||||
|
|
||||||
|
b.Property<string>("MangaId")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<string>("Title")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("AltTitleId");
|
||||||
|
|
||||||
|
b.HasIndex("MangaId");
|
||||||
|
|
||||||
|
b.ToTable("AltTitles");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.MangaConnector", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.HasMaxLength(32)
|
||||||
|
.HasColumnType("character varying(32)");
|
||||||
|
|
||||||
|
b.PrimitiveCollection<string[]>("BaseUris")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text[]");
|
||||||
|
|
||||||
|
b.PrimitiveCollection<string[]>("SupportedLanguages")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text[]");
|
||||||
|
|
||||||
|
b.HasKey("Name");
|
||||||
|
|
||||||
|
b.ToTable("MangaConnectors");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.MangaTag", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("Tag")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Tag");
|
||||||
|
|
||||||
|
b.ToTable("Tags");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.NotificationConnectors.NotificationConnector", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("NotificationConnectorId")
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<byte>("NotificationConnectorType")
|
||||||
|
.HasColumnType("smallint");
|
||||||
|
|
||||||
|
b.HasKey("NotificationConnectorId");
|
||||||
|
|
||||||
|
b.ToTable("NotificationConnectors");
|
||||||
|
|
||||||
|
b.HasDiscriminator<byte>("NotificationConnectorType");
|
||||||
|
|
||||||
|
b.UseTphMappingStrategy();
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("MangaAuthor", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("MangaId")
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<string>("AuthorId")
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<string>("AuthorIds")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("MangaIds")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("MangaId", "AuthorId");
|
||||||
|
|
||||||
|
b.HasIndex("AuthorId");
|
||||||
|
|
||||||
|
b.ToTable("MangaAuthor");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("MangaTag", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("MangaId")
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<string>("Tag")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("MangaIds")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("TagIds")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("MangaId", "Tag");
|
||||||
|
|
||||||
|
b.HasIndex("MangaIds");
|
||||||
|
|
||||||
|
b.HasIndex("Tag");
|
||||||
|
|
||||||
|
b.ToTable("MangaTag");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.Jobs.CreateArchiveJob", b =>
|
||||||
|
{
|
||||||
|
b.HasBaseType("API.Schema.Jobs.Job");
|
||||||
|
|
||||||
|
b.Property<string>("ChapterId")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<string>("ComicInfoLocation")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("ImagesLocation")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasIndex("ChapterId");
|
||||||
|
|
||||||
|
b.ToTable("Jobs", t =>
|
||||||
|
{
|
||||||
|
t.Property("ChapterId")
|
||||||
|
.HasColumnName("CreateArchiveJob_ChapterId");
|
||||||
|
});
|
||||||
|
|
||||||
|
b.HasDiscriminator().HasValue((byte)4);
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.Jobs.CreateComicInfoXmlJob", b =>
|
||||||
|
{
|
||||||
|
b.HasBaseType("API.Schema.Jobs.Job");
|
||||||
|
|
||||||
|
b.Property<string>("ChapterId")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<string>("Path")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasIndex("ChapterId");
|
||||||
|
|
||||||
|
b.ToTable("Jobs", t =>
|
||||||
|
{
|
||||||
|
t.Property("ChapterId")
|
||||||
|
.HasColumnName("CreateComicInfoXmlJob_ChapterId");
|
||||||
|
});
|
||||||
|
|
||||||
|
b.HasDiscriminator().HasValue((byte)6);
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.Jobs.DownloadNewChaptersJob", b =>
|
||||||
|
{
|
||||||
|
b.HasBaseType("API.Schema.Jobs.Job");
|
||||||
|
|
||||||
|
b.Property<string>("MangaId")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.HasIndex("MangaId");
|
||||||
|
|
||||||
|
b.HasDiscriminator().HasValue((byte)1);
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.Jobs.DownloadSingleChapterJob", b =>
|
||||||
|
{
|
||||||
|
b.HasBaseType("API.Schema.Jobs.Job");
|
||||||
|
|
||||||
|
b.Property<string>("ChapterId")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.HasIndex("ChapterId");
|
||||||
|
|
||||||
|
b.HasDiscriminator().HasValue((byte)0);
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.Jobs.MoveFileOrFolderJob", b =>
|
||||||
|
{
|
||||||
|
b.HasBaseType("API.Schema.Jobs.Job");
|
||||||
|
|
||||||
|
b.Property<string>("FromLocation")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("ToLocation")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasDiscriminator().HasValue((byte)3);
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.Jobs.ProcessImagesJob", b =>
|
||||||
|
{
|
||||||
|
b.HasBaseType("API.Schema.Jobs.Job");
|
||||||
|
|
||||||
|
b.Property<bool>("Bw")
|
||||||
|
.HasColumnType("boolean");
|
||||||
|
|
||||||
|
b.Property<int>("Compression")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<string>("Path")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.ToTable("Jobs", t =>
|
||||||
|
{
|
||||||
|
t.Property("Path")
|
||||||
|
.HasColumnName("ProcessImagesJob_Path");
|
||||||
|
});
|
||||||
|
|
||||||
|
b.HasDiscriminator().HasValue((byte)5);
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.Jobs.SearchMangaJob", b =>
|
||||||
|
{
|
||||||
|
b.HasBaseType("API.Schema.Jobs.Job");
|
||||||
|
|
||||||
|
b.Property<string>("MangaConnectorName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("SearchString")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasDiscriminator().HasValue((byte)7);
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.Jobs.UpdateMetadataJob", b =>
|
||||||
|
{
|
||||||
|
b.HasBaseType("API.Schema.Jobs.Job");
|
||||||
|
|
||||||
|
b.Property<string>("MangaId")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.HasIndex("MangaId");
|
||||||
|
|
||||||
|
b.ToTable("Jobs", t =>
|
||||||
|
{
|
||||||
|
t.Property("MangaId")
|
||||||
|
.HasColumnName("UpdateMetadataJob_MangaId");
|
||||||
|
});
|
||||||
|
|
||||||
|
b.HasDiscriminator().HasValue((byte)2);
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.LibraryConnectors.Kavita", b =>
|
||||||
|
{
|
||||||
|
b.HasBaseType("API.Schema.LibraryConnectors.LibraryConnector");
|
||||||
|
|
||||||
|
b.HasDiscriminator().HasValue((byte)1);
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.LibraryConnectors.Komga", b =>
|
||||||
|
{
|
||||||
|
b.HasBaseType("API.Schema.LibraryConnectors.LibraryConnector");
|
||||||
|
|
||||||
|
b.HasDiscriminator().HasValue((byte)0);
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.NotificationConnectors.Gotify", b =>
|
||||||
|
{
|
||||||
|
b.HasBaseType("API.Schema.NotificationConnectors.NotificationConnector");
|
||||||
|
|
||||||
|
b.Property<string>("AppToken")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("Endpoint")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasDiscriminator().HasValue((byte)0);
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.NotificationConnectors.Lunasea", b =>
|
||||||
|
{
|
||||||
|
b.HasBaseType("API.Schema.NotificationConnectors.NotificationConnector");
|
||||||
|
|
||||||
|
b.Property<string>("Id")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasDiscriminator().HasValue((byte)1);
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.NotificationConnectors.Ntfy", b =>
|
||||||
|
{
|
||||||
|
b.HasBaseType("API.Schema.NotificationConnectors.NotificationConnector");
|
||||||
|
|
||||||
|
b.Property<string>("Auth")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("Endpoint")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("Topic")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.ToTable("NotificationConnectors", t =>
|
||||||
|
{
|
||||||
|
t.Property("Endpoint")
|
||||||
|
.HasColumnName("Ntfy_Endpoint");
|
||||||
|
});
|
||||||
|
|
||||||
|
b.HasDiscriminator().HasValue((byte)2);
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.Chapter", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("API.Schema.Manga", "ParentManga")
|
||||||
|
.WithMany("Chapters")
|
||||||
|
.HasForeignKey("ParentMangaId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("ParentManga");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.Jobs.Job", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("API.Schema.Jobs.Job", null)
|
||||||
|
.WithMany("DependsOnJobs")
|
||||||
|
.HasForeignKey("JobId1");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.Link", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("API.Schema.Manga", "Manga")
|
||||||
|
.WithMany("Links")
|
||||||
|
.HasForeignKey("MangaId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Manga");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.Manga", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("API.Schema.Chapter", "LatestChapterAvailable")
|
||||||
|
.WithOne()
|
||||||
|
.HasForeignKey("API.Schema.Manga", "LatestChapterAvailableId");
|
||||||
|
|
||||||
|
b.HasOne("API.Schema.Chapter", "LatestChapterDownloaded")
|
||||||
|
.WithOne()
|
||||||
|
.HasForeignKey("API.Schema.Manga", "LatestChapterDownloadedId");
|
||||||
|
|
||||||
|
b.HasOne("API.Schema.MangaConnector", "MangaConnector")
|
||||||
|
.WithMany("Mangas")
|
||||||
|
.HasForeignKey("MangaConnectorName")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("LatestChapterAvailable");
|
||||||
|
|
||||||
|
b.Navigation("LatestChapterDownloaded");
|
||||||
|
|
||||||
|
b.Navigation("MangaConnector");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.MangaAltTitle", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("API.Schema.Manga", "Manga")
|
||||||
|
.WithMany("AltTitles")
|
||||||
|
.HasForeignKey("MangaId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Manga");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("MangaAuthor", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("API.Schema.Author", null)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("AuthorId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("API.Schema.Manga", null)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("MangaId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("MangaTag", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("API.Schema.Manga", null)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("MangaId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("API.Schema.MangaTag", null)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("MangaIds")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("API.Schema.MangaTag", null)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("Tag")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.Jobs.CreateArchiveJob", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("API.Schema.Chapter", "Chapter")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("ChapterId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Chapter");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.Jobs.CreateComicInfoXmlJob", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("API.Schema.Chapter", "Chapter")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("ChapterId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Chapter");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.Jobs.DownloadNewChaptersJob", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("API.Schema.Manga", "Manga")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("MangaId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Manga");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.Jobs.DownloadSingleChapterJob", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("API.Schema.Chapter", "Chapter")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("ChapterId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Chapter");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.Jobs.UpdateMetadataJob", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("API.Schema.Manga", "Manga")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("MangaId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Manga");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.Jobs.Job", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("DependsOnJobs");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.Manga", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("AltTitles");
|
||||||
|
|
||||||
|
b.Navigation("Chapters");
|
||||||
|
|
||||||
|
b.Navigation("Links");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.MangaConnector", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Mangas");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
447
API/Migrations/20241201235443_Initial.cs
Normal file
447
API/Migrations/20241201235443_Initial.cs
Normal file
@ -0,0 +1,447 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace API.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class Initial : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Authors",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
AuthorId = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false),
|
||||||
|
AuthorName = table.Column<string>(type: "text", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Authors", x => x.AuthorId);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "LibraryConnectors",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
LibraryConnectorId = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false),
|
||||||
|
LibraryType = table.Column<byte>(type: "smallint", nullable: false),
|
||||||
|
BaseUrl = table.Column<string>(type: "text", nullable: false),
|
||||||
|
Auth = table.Column<string>(type: "text", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_LibraryConnectors", x => x.LibraryConnectorId);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "MangaConnectors",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Name = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
|
||||||
|
SupportedLanguages = table.Column<string[]>(type: "text[]", nullable: false),
|
||||||
|
BaseUris = table.Column<string[]>(type: "text[]", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_MangaConnectors", x => x.Name);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "NotificationConnectors",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
NotificationConnectorId = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false),
|
||||||
|
NotificationConnectorType = table.Column<byte>(type: "smallint", nullable: false),
|
||||||
|
Endpoint = table.Column<string>(type: "text", nullable: true),
|
||||||
|
AppToken = table.Column<string>(type: "text", nullable: true),
|
||||||
|
Id = table.Column<string>(type: "text", nullable: true),
|
||||||
|
Ntfy_Endpoint = table.Column<string>(type: "text", nullable: true),
|
||||||
|
Auth = table.Column<string>(type: "text", nullable: true),
|
||||||
|
Topic = table.Column<string>(type: "text", nullable: true)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_NotificationConnectors", x => x.NotificationConnectorId);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Tags",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Tag = table.Column<string>(type: "text", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Tags", x => x.Tag);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "AltTitles",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
AltTitleId = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false),
|
||||||
|
Language = table.Column<string>(type: "character varying(8)", maxLength: 8, nullable: false),
|
||||||
|
Title = table.Column<string>(type: "text", nullable: false),
|
||||||
|
MangaId = table.Column<string>(type: "character varying(64)", nullable: false),
|
||||||
|
AltTitleIds = table.Column<string>(type: "text", nullable: true)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_AltTitles", x => x.AltTitleId);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Chapters",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
ChapterId = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false),
|
||||||
|
VolumeNumber = table.Column<float>(type: "real", nullable: true),
|
||||||
|
ChapterNumber = table.Column<float>(type: "real", nullable: false),
|
||||||
|
Url = table.Column<string>(type: "text", nullable: false),
|
||||||
|
Title = table.Column<string>(type: "text", nullable: true),
|
||||||
|
ArchiveFileName = table.Column<string>(type: "text", nullable: false),
|
||||||
|
Downloaded = table.Column<bool>(type: "boolean", nullable: false),
|
||||||
|
ParentMangaId = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false),
|
||||||
|
ChapterIds = table.Column<string>(type: "text", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Chapters", x => x.ChapterId);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Manga",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
MangaId = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false),
|
||||||
|
ConnectorId = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false),
|
||||||
|
Name = table.Column<string>(type: "text", nullable: false),
|
||||||
|
Description = table.Column<string>(type: "text", nullable: false),
|
||||||
|
CoverUrl = table.Column<string>(type: "text", nullable: false),
|
||||||
|
CoverFileNameInCache = table.Column<string>(type: "text", nullable: true),
|
||||||
|
year = table.Column<long>(type: "bigint", nullable: false),
|
||||||
|
OriginalLanguage = table.Column<string>(type: "text", nullable: true),
|
||||||
|
ReleaseStatus = table.Column<byte>(type: "smallint", nullable: false),
|
||||||
|
FolderName = table.Column<string>(type: "text", nullable: false),
|
||||||
|
IgnoreChapterBefore = table.Column<float>(type: "real", nullable: false),
|
||||||
|
LatestChapterDownloadedId = table.Column<string>(type: "character varying(64)", nullable: true),
|
||||||
|
LatestChapterAvailableId = table.Column<string>(type: "character varying(64)", nullable: true),
|
||||||
|
MangaConnectorName = table.Column<string>(type: "character varying(32)", nullable: false),
|
||||||
|
AuthorIds = table.Column<string[]>(type: "text[]", nullable: false),
|
||||||
|
TagIds = table.Column<string[]>(type: "text[]", nullable: false),
|
||||||
|
LinkIds = table.Column<string[]>(type: "text[]", nullable: false),
|
||||||
|
AltTitleIds = table.Column<string[]>(type: "text[]", nullable: false),
|
||||||
|
MangaIds = table.Column<string>(type: "text", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Manga", x => x.MangaId);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_Manga_Chapters_LatestChapterAvailableId",
|
||||||
|
column: x => x.LatestChapterAvailableId,
|
||||||
|
principalTable: "Chapters",
|
||||||
|
principalColumn: "ChapterId");
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_Manga_Chapters_LatestChapterDownloadedId",
|
||||||
|
column: x => x.LatestChapterDownloadedId,
|
||||||
|
principalTable: "Chapters",
|
||||||
|
principalColumn: "ChapterId");
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_Manga_MangaConnectors_MangaConnectorName",
|
||||||
|
column: x => x.MangaConnectorName,
|
||||||
|
principalTable: "MangaConnectors",
|
||||||
|
principalColumn: "Name",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Jobs",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
JobId = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false),
|
||||||
|
ParentJobId = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
|
||||||
|
DependsOnJobIds = table.Column<string[]>(type: "text[]", maxLength: 64, nullable: true),
|
||||||
|
JobType = table.Column<byte>(type: "smallint", nullable: false),
|
||||||
|
RecurrenceMs = table.Column<decimal>(type: "numeric(20,0)", nullable: false),
|
||||||
|
LastExecution = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||||
|
NextExecution = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||||
|
state = table.Column<int>(type: "integer", nullable: false),
|
||||||
|
JobId1 = table.Column<string>(type: "character varying(64)", nullable: true),
|
||||||
|
ImagesLocation = table.Column<string>(type: "text", nullable: true),
|
||||||
|
ComicInfoLocation = table.Column<string>(type: "text", nullable: true),
|
||||||
|
CreateArchiveJob_ChapterId = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
|
||||||
|
Path = table.Column<string>(type: "text", nullable: true),
|
||||||
|
CreateComicInfoXmlJob_ChapterId = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
|
||||||
|
MangaId = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
|
||||||
|
ChapterId = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
|
||||||
|
FromLocation = table.Column<string>(type: "text", nullable: true),
|
||||||
|
ToLocation = table.Column<string>(type: "text", nullable: true),
|
||||||
|
ProcessImagesJob_Path = table.Column<string>(type: "text", nullable: true),
|
||||||
|
Bw = table.Column<bool>(type: "boolean", nullable: true),
|
||||||
|
Compression = table.Column<int>(type: "integer", nullable: true),
|
||||||
|
SearchString = table.Column<string>(type: "text", nullable: true),
|
||||||
|
MangaConnectorName = table.Column<string>(type: "text", nullable: true),
|
||||||
|
UpdateMetadataJob_MangaId = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Jobs", x => x.JobId);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_Jobs_Chapters_ChapterId",
|
||||||
|
column: x => x.ChapterId,
|
||||||
|
principalTable: "Chapters",
|
||||||
|
principalColumn: "ChapterId",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_Jobs_Chapters_CreateArchiveJob_ChapterId",
|
||||||
|
column: x => x.CreateArchiveJob_ChapterId,
|
||||||
|
principalTable: "Chapters",
|
||||||
|
principalColumn: "ChapterId",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_Jobs_Chapters_CreateComicInfoXmlJob_ChapterId",
|
||||||
|
column: x => x.CreateComicInfoXmlJob_ChapterId,
|
||||||
|
principalTable: "Chapters",
|
||||||
|
principalColumn: "ChapterId",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_Jobs_Jobs_JobId1",
|
||||||
|
column: x => x.JobId1,
|
||||||
|
principalTable: "Jobs",
|
||||||
|
principalColumn: "JobId");
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_Jobs_Manga_MangaId",
|
||||||
|
column: x => x.MangaId,
|
||||||
|
principalTable: "Manga",
|
||||||
|
principalColumn: "MangaId",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_Jobs_Manga_UpdateMetadataJob_MangaId",
|
||||||
|
column: x => x.UpdateMetadataJob_MangaId,
|
||||||
|
principalTable: "Manga",
|
||||||
|
principalColumn: "MangaId",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Link",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
LinkId = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false),
|
||||||
|
LinkProvider = table.Column<string>(type: "text", nullable: false),
|
||||||
|
LinkUrl = table.Column<string>(type: "text", nullable: false),
|
||||||
|
MangaId = table.Column<string>(type: "character varying(64)", nullable: false),
|
||||||
|
LinkIds = table.Column<string>(type: "text", nullable: true)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Link", x => x.LinkId);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_Link_Manga_MangaId",
|
||||||
|
column: x => x.MangaId,
|
||||||
|
principalTable: "Manga",
|
||||||
|
principalColumn: "MangaId",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "MangaAuthor",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
MangaId = table.Column<string>(type: "character varying(64)", nullable: false),
|
||||||
|
AuthorId = table.Column<string>(type: "character varying(64)", nullable: false),
|
||||||
|
AuthorIds = table.Column<string>(type: "text", nullable: true),
|
||||||
|
MangaIds = table.Column<string>(type: "text", nullable: true)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_MangaAuthor", x => new { x.MangaId, x.AuthorId });
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_MangaAuthor_Authors_AuthorId",
|
||||||
|
column: x => x.AuthorId,
|
||||||
|
principalTable: "Authors",
|
||||||
|
principalColumn: "AuthorId",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_MangaAuthor_Manga_MangaId",
|
||||||
|
column: x => x.MangaId,
|
||||||
|
principalTable: "Manga",
|
||||||
|
principalColumn: "MangaId",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "MangaTag",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
MangaId = table.Column<string>(type: "character varying(64)", nullable: false),
|
||||||
|
Tag = table.Column<string>(type: "text", nullable: false),
|
||||||
|
MangaIds = table.Column<string>(type: "text", nullable: false),
|
||||||
|
TagIds = table.Column<string>(type: "text", nullable: true)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_MangaTag", x => new { x.MangaId, x.Tag });
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_MangaTag_Manga_MangaId",
|
||||||
|
column: x => x.MangaId,
|
||||||
|
principalTable: "Manga",
|
||||||
|
principalColumn: "MangaId",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_MangaTag_Tags_MangaIds",
|
||||||
|
column: x => x.MangaIds,
|
||||||
|
principalTable: "Tags",
|
||||||
|
principalColumn: "Tag",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_MangaTag_Tags_Tag",
|
||||||
|
column: x => x.Tag,
|
||||||
|
principalTable: "Tags",
|
||||||
|
principalColumn: "Tag",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_AltTitles_MangaId",
|
||||||
|
table: "AltTitles",
|
||||||
|
column: "MangaId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_Chapters_ParentMangaId",
|
||||||
|
table: "Chapters",
|
||||||
|
column: "ParentMangaId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_Jobs_ChapterId",
|
||||||
|
table: "Jobs",
|
||||||
|
column: "ChapterId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_Jobs_CreateArchiveJob_ChapterId",
|
||||||
|
table: "Jobs",
|
||||||
|
column: "CreateArchiveJob_ChapterId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_Jobs_CreateComicInfoXmlJob_ChapterId",
|
||||||
|
table: "Jobs",
|
||||||
|
column: "CreateComicInfoXmlJob_ChapterId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_Jobs_JobId1",
|
||||||
|
table: "Jobs",
|
||||||
|
column: "JobId1");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_Jobs_MangaId",
|
||||||
|
table: "Jobs",
|
||||||
|
column: "MangaId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_Jobs_UpdateMetadataJob_MangaId",
|
||||||
|
table: "Jobs",
|
||||||
|
column: "UpdateMetadataJob_MangaId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_Link_MangaId",
|
||||||
|
table: "Link",
|
||||||
|
column: "MangaId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_Manga_LatestChapterAvailableId",
|
||||||
|
table: "Manga",
|
||||||
|
column: "LatestChapterAvailableId",
|
||||||
|
unique: true);
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_Manga_LatestChapterDownloadedId",
|
||||||
|
table: "Manga",
|
||||||
|
column: "LatestChapterDownloadedId",
|
||||||
|
unique: true);
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_Manga_MangaConnectorName",
|
||||||
|
table: "Manga",
|
||||||
|
column: "MangaConnectorName");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_MangaAuthor_AuthorId",
|
||||||
|
table: "MangaAuthor",
|
||||||
|
column: "AuthorId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_MangaTag_MangaIds",
|
||||||
|
table: "MangaTag",
|
||||||
|
column: "MangaIds");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_MangaTag_Tag",
|
||||||
|
table: "MangaTag",
|
||||||
|
column: "Tag");
|
||||||
|
|
||||||
|
migrationBuilder.AddForeignKey(
|
||||||
|
name: "FK_AltTitles_Manga_MangaId",
|
||||||
|
table: "AltTitles",
|
||||||
|
column: "MangaId",
|
||||||
|
principalTable: "Manga",
|
||||||
|
principalColumn: "MangaId",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
|
||||||
|
migrationBuilder.AddForeignKey(
|
||||||
|
name: "FK_Chapters_Manga_ParentMangaId",
|
||||||
|
table: "Chapters",
|
||||||
|
column: "ParentMangaId",
|
||||||
|
principalTable: "Manga",
|
||||||
|
principalColumn: "MangaId",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropForeignKey(
|
||||||
|
name: "FK_Chapters_Manga_ParentMangaId",
|
||||||
|
table: "Chapters");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "AltTitles");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Jobs");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "LibraryConnectors");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Link");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "MangaAuthor");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "MangaTag");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "NotificationConnectors");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Authors");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Tags");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Manga");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Chapters");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "MangaConnectors");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
688
API/Migrations/PgsqlContextModelSnapshot.cs
Normal file
688
API/Migrations/PgsqlContextModelSnapshot.cs
Normal file
@ -0,0 +1,688 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using API.Schema;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace API.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(PgsqlContext))]
|
||||||
|
partial class PgsqlContextModelSnapshot : ModelSnapshot
|
||||||
|
{
|
||||||
|
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasAnnotation("ProductVersion", "9.0.0")
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||||
|
|
||||||
|
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.Author", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("AuthorId")
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<string>("AuthorName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("AuthorId");
|
||||||
|
|
||||||
|
b.ToTable("Authors");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.Chapter", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("ChapterId")
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<string>("ArchiveFileName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<float>("ChapterNumber")
|
||||||
|
.HasColumnType("real");
|
||||||
|
|
||||||
|
b.Property<bool>("Downloaded")
|
||||||
|
.HasColumnType("boolean");
|
||||||
|
|
||||||
|
b.Property<string>("ParentMangaId")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<string>("Title")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("Url")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<float?>("VolumeNumber")
|
||||||
|
.HasColumnType("real");
|
||||||
|
|
||||||
|
b.HasKey("ChapterId");
|
||||||
|
|
||||||
|
b.HasIndex("ParentMangaId");
|
||||||
|
|
||||||
|
b.ToTable("Chapters");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.Jobs.Job", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("JobId")
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.PrimitiveCollection<string[]>("DependsOnJobsIds")
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("text[]");
|
||||||
|
|
||||||
|
b.Property<string>("JobId1")
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<byte>("JobType")
|
||||||
|
.HasColumnType("smallint");
|
||||||
|
|
||||||
|
b.Property<DateTime>("LastExecution")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("ParentJobId")
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<decimal>("RecurrenceMs")
|
||||||
|
.HasColumnType("numeric(20,0)");
|
||||||
|
|
||||||
|
b.Property<int>("state")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.HasKey("JobId");
|
||||||
|
|
||||||
|
b.HasIndex("JobId1");
|
||||||
|
|
||||||
|
b.HasIndex("ParentJobId");
|
||||||
|
|
||||||
|
b.ToTable("Jobs");
|
||||||
|
|
||||||
|
b.HasDiscriminator<byte>("JobType");
|
||||||
|
|
||||||
|
b.UseTphMappingStrategy();
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.LibraryConnectors.LibraryConnector", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("LibraryConnectorId")
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<string>("Auth")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("BaseUrl")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<byte>("LibraryType")
|
||||||
|
.HasColumnType("smallint");
|
||||||
|
|
||||||
|
b.HasKey("LibraryConnectorId");
|
||||||
|
|
||||||
|
b.ToTable("LibraryConnectors");
|
||||||
|
|
||||||
|
b.HasDiscriminator<byte>("LibraryType");
|
||||||
|
|
||||||
|
b.UseTphMappingStrategy();
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.Link", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("LinkId")
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<string>("LinkProvider")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("LinkUrl")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("MangaId")
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.HasKey("LinkId");
|
||||||
|
|
||||||
|
b.HasIndex("MangaId");
|
||||||
|
|
||||||
|
b.ToTable("Link");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.Manga", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("MangaId")
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<string>("ConnectorId")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<string>("CoverFileNameInCache")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("CoverUrl")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("Description")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("FolderName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<float>("IgnoreChapterBefore")
|
||||||
|
.HasColumnType("real");
|
||||||
|
|
||||||
|
b.Property<string>("MangaConnectorId")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("character varying(32)");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("OriginalLanguage")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<byte>("ReleaseStatus")
|
||||||
|
.HasColumnType("smallint");
|
||||||
|
|
||||||
|
b.Property<string>("WebsiteUrl")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<long>("Year")
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b.HasKey("MangaId");
|
||||||
|
|
||||||
|
b.HasIndex("MangaConnectorId");
|
||||||
|
|
||||||
|
b.ToTable("Manga");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.MangaAltTitle", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("AltTitleId")
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<string>("Language")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(8)
|
||||||
|
.HasColumnType("character varying(8)");
|
||||||
|
|
||||||
|
b.Property<string>("MangaId")
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<string>("Title")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("AltTitleId");
|
||||||
|
|
||||||
|
b.HasIndex("MangaId");
|
||||||
|
|
||||||
|
b.ToTable("AltTitles");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.MangaConnectors.MangaConnector", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.HasMaxLength(32)
|
||||||
|
.HasColumnType("character varying(32)");
|
||||||
|
|
||||||
|
b.PrimitiveCollection<string[]>("BaseUris")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text[]");
|
||||||
|
|
||||||
|
b.PrimitiveCollection<string[]>("SupportedLanguages")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text[]");
|
||||||
|
|
||||||
|
b.HasKey("Name");
|
||||||
|
|
||||||
|
b.ToTable("MangaConnectors");
|
||||||
|
|
||||||
|
b.HasDiscriminator<string>("Name").HasValue("MangaConnector");
|
||||||
|
|
||||||
|
b.UseTphMappingStrategy();
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.MangaTag", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("Tag")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Tag");
|
||||||
|
|
||||||
|
b.ToTable("Tags");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.Notification", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("NotificationId")
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<DateTime>("Date")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("Message")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("Title")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<byte>("Urgency")
|
||||||
|
.HasColumnType("smallint");
|
||||||
|
|
||||||
|
b.HasKey("NotificationId");
|
||||||
|
|
||||||
|
b.ToTable("Notifications");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.NotificationConnectors.NotificationConnector", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("NotificationConnectorId")
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<byte>("NotificationConnectorType")
|
||||||
|
.HasColumnType("smallint");
|
||||||
|
|
||||||
|
b.HasKey("NotificationConnectorId");
|
||||||
|
|
||||||
|
b.ToTable("NotificationConnectors");
|
||||||
|
|
||||||
|
b.HasDiscriminator<byte>("NotificationConnectorType");
|
||||||
|
|
||||||
|
b.UseTphMappingStrategy();
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("AuthorManga", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("AuthorsAuthorId")
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<string>("MangaId")
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.HasKey("AuthorsAuthorId", "MangaId");
|
||||||
|
|
||||||
|
b.HasIndex("MangaId");
|
||||||
|
|
||||||
|
b.ToTable("AuthorManga");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("MangaMangaTag", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("MangaId")
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.Property<string>("TagsTag")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("MangaId", "TagsTag");
|
||||||
|
|
||||||
|
b.HasIndex("TagsTag");
|
||||||
|
|
||||||
|
b.ToTable("MangaMangaTag");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.Jobs.DownloadNewChaptersJob", b =>
|
||||||
|
{
|
||||||
|
b.HasBaseType("API.Schema.Jobs.Job");
|
||||||
|
|
||||||
|
b.Property<string>("MangaId")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.HasIndex("MangaId");
|
||||||
|
|
||||||
|
b.HasDiscriminator().HasValue((byte)1);
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.Jobs.DownloadSingleChapterJob", b =>
|
||||||
|
{
|
||||||
|
b.HasBaseType("API.Schema.Jobs.Job");
|
||||||
|
|
||||||
|
b.Property<string>("ChapterId")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.HasIndex("ChapterId");
|
||||||
|
|
||||||
|
b.HasDiscriminator().HasValue((byte)0);
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.Jobs.MoveFileOrFolderJob", b =>
|
||||||
|
{
|
||||||
|
b.HasBaseType("API.Schema.Jobs.Job");
|
||||||
|
|
||||||
|
b.Property<string>("FromLocation")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("ToLocation")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasDiscriminator().HasValue((byte)3);
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.Jobs.UpdateMetadataJob", b =>
|
||||||
|
{
|
||||||
|
b.HasBaseType("API.Schema.Jobs.Job");
|
||||||
|
|
||||||
|
b.Property<string>("MangaId")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(64)
|
||||||
|
.HasColumnType("character varying(64)");
|
||||||
|
|
||||||
|
b.HasIndex("MangaId");
|
||||||
|
|
||||||
|
b.ToTable("Jobs", t =>
|
||||||
|
{
|
||||||
|
t.Property("MangaId")
|
||||||
|
.HasColumnName("UpdateMetadataJob_MangaId");
|
||||||
|
});
|
||||||
|
|
||||||
|
b.HasDiscriminator().HasValue((byte)2);
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.LibraryConnectors.Kavita", b =>
|
||||||
|
{
|
||||||
|
b.HasBaseType("API.Schema.LibraryConnectors.LibraryConnector");
|
||||||
|
|
||||||
|
b.HasDiscriminator().HasValue((byte)1);
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.LibraryConnectors.Komga", b =>
|
||||||
|
{
|
||||||
|
b.HasBaseType("API.Schema.LibraryConnectors.LibraryConnector");
|
||||||
|
|
||||||
|
b.HasDiscriminator().HasValue((byte)0);
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.MangaConnectors.AsuraToon", b =>
|
||||||
|
{
|
||||||
|
b.HasBaseType("API.Schema.MangaConnectors.MangaConnector");
|
||||||
|
|
||||||
|
b.HasDiscriminator().HasValue("AsuraToon");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.MangaConnectors.Bato", b =>
|
||||||
|
{
|
||||||
|
b.HasBaseType("API.Schema.MangaConnectors.MangaConnector");
|
||||||
|
|
||||||
|
b.HasDiscriminator().HasValue("Bato");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.MangaConnectors.MangaDex", b =>
|
||||||
|
{
|
||||||
|
b.HasBaseType("API.Schema.MangaConnectors.MangaConnector");
|
||||||
|
|
||||||
|
b.HasDiscriminator().HasValue("MangaDex");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.MangaConnectors.MangaHere", b =>
|
||||||
|
{
|
||||||
|
b.HasBaseType("API.Schema.MangaConnectors.MangaConnector");
|
||||||
|
|
||||||
|
b.HasDiscriminator().HasValue("MangaHere");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.MangaConnectors.MangaKatana", b =>
|
||||||
|
{
|
||||||
|
b.HasBaseType("API.Schema.MangaConnectors.MangaConnector");
|
||||||
|
|
||||||
|
b.HasDiscriminator().HasValue("MangaKatana");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.MangaConnectors.MangaLife", b =>
|
||||||
|
{
|
||||||
|
b.HasBaseType("API.Schema.MangaConnectors.MangaConnector");
|
||||||
|
|
||||||
|
b.HasDiscriminator().HasValue("Manga4Life");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.MangaConnectors.Manganato", b =>
|
||||||
|
{
|
||||||
|
b.HasBaseType("API.Schema.MangaConnectors.MangaConnector");
|
||||||
|
|
||||||
|
b.HasDiscriminator().HasValue("Manganato");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.MangaConnectors.Mangasee", b =>
|
||||||
|
{
|
||||||
|
b.HasBaseType("API.Schema.MangaConnectors.MangaConnector");
|
||||||
|
|
||||||
|
b.HasDiscriminator().HasValue("Mangasee");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.MangaConnectors.Mangaworld", b =>
|
||||||
|
{
|
||||||
|
b.HasBaseType("API.Schema.MangaConnectors.MangaConnector");
|
||||||
|
|
||||||
|
b.HasDiscriminator().HasValue("Mangaworld");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.MangaConnectors.ManhuaPlus", b =>
|
||||||
|
{
|
||||||
|
b.HasBaseType("API.Schema.MangaConnectors.MangaConnector");
|
||||||
|
|
||||||
|
b.HasDiscriminator().HasValue("ManhuaPlus");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.MangaConnectors.Weebcentral", b =>
|
||||||
|
{
|
||||||
|
b.HasBaseType("API.Schema.MangaConnectors.MangaConnector");
|
||||||
|
|
||||||
|
b.HasDiscriminator().HasValue("Weebcentral");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.NotificationConnectors.Gotify", b =>
|
||||||
|
{
|
||||||
|
b.HasBaseType("API.Schema.NotificationConnectors.NotificationConnector");
|
||||||
|
|
||||||
|
b.Property<string>("AppToken")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("Endpoint")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasDiscriminator().HasValue((byte)0);
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.NotificationConnectors.Lunasea", b =>
|
||||||
|
{
|
||||||
|
b.HasBaseType("API.Schema.NotificationConnectors.NotificationConnector");
|
||||||
|
|
||||||
|
b.Property<string>("Id")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasDiscriminator().HasValue((byte)1);
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.NotificationConnectors.Ntfy", b =>
|
||||||
|
{
|
||||||
|
b.HasBaseType("API.Schema.NotificationConnectors.NotificationConnector");
|
||||||
|
|
||||||
|
b.Property<string>("Auth")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("Endpoint")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("Topic")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.ToTable("NotificationConnectors", t =>
|
||||||
|
{
|
||||||
|
t.Property("Endpoint")
|
||||||
|
.HasColumnName("Ntfy_Endpoint");
|
||||||
|
});
|
||||||
|
|
||||||
|
b.HasDiscriminator().HasValue((byte)2);
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.Chapter", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("API.Schema.Manga", "ParentManga")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("ParentMangaId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("ParentManga");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.Jobs.Job", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("API.Schema.Jobs.Job", null)
|
||||||
|
.WithMany("DependsOnJobs")
|
||||||
|
.HasForeignKey("JobId1");
|
||||||
|
|
||||||
|
b.HasOne("API.Schema.Jobs.Job", "ParentJob")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("ParentJobId");
|
||||||
|
|
||||||
|
b.Navigation("ParentJob");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.Link", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("API.Schema.Manga", null)
|
||||||
|
.WithMany("Links")
|
||||||
|
.HasForeignKey("MangaId");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.Manga", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("API.Schema.MangaConnectors.MangaConnector", "MangaConnector")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("MangaConnectorId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("MangaConnector");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.MangaAltTitle", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("API.Schema.Manga", null)
|
||||||
|
.WithMany("AltTitles")
|
||||||
|
.HasForeignKey("MangaId");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("AuthorManga", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("API.Schema.Author", null)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("AuthorsAuthorId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("API.Schema.Manga", null)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("MangaId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("MangaMangaTag", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("API.Schema.Manga", null)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("MangaId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("API.Schema.MangaTag", null)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("TagsTag")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.Jobs.DownloadNewChaptersJob", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("API.Schema.Manga", "Manga")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("MangaId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Manga");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.Jobs.DownloadSingleChapterJob", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("API.Schema.Chapter", "Chapter")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("ChapterId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Chapter");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.Jobs.UpdateMetadataJob", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("API.Schema.Manga", "Manga")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("MangaId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Manga");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.Jobs.Job", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("DependsOnJobs");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("API.Schema.Manga", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("AltTitles");
|
||||||
|
|
||||||
|
b.Navigation("Links");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
46
API/NamedSwaggerGenOptions.cs
Normal file
46
API/NamedSwaggerGenOptions.cs
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
using Asp.Versioning.ApiExplorer;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
using Microsoft.OpenApi.Models;
|
||||||
|
using Swashbuckle.AspNetCore.SwaggerGen;
|
||||||
|
|
||||||
|
namespace API;
|
||||||
|
|
||||||
|
public class NamedSwaggerGenOptions : IConfigureNamedOptions<SwaggerGenOptions>
|
||||||
|
{
|
||||||
|
private readonly IApiVersionDescriptionProvider provider;
|
||||||
|
public NamedSwaggerGenOptions(IApiVersionDescriptionProvider provider)
|
||||||
|
{
|
||||||
|
this.provider = provider;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Configure(string? name, SwaggerGenOptions options)
|
||||||
|
{
|
||||||
|
Configure(options);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Configure(SwaggerGenOptions options)
|
||||||
|
{
|
||||||
|
// add swagger document for every API version discovered
|
||||||
|
foreach (var description in provider.ApiVersionDescriptions)
|
||||||
|
{
|
||||||
|
options.SwaggerDoc(
|
||||||
|
description.GroupName,
|
||||||
|
CreateVersionInfo(description));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private OpenApiInfo CreateVersionInfo(
|
||||||
|
ApiVersionDescription description)
|
||||||
|
{
|
||||||
|
var info = new OpenApiInfo()
|
||||||
|
{
|
||||||
|
Title = "Test API " + description.GroupName,
|
||||||
|
Version = description.ApiVersion.ToString()
|
||||||
|
};
|
||||||
|
if (description.IsDeprecated)
|
||||||
|
{
|
||||||
|
info.Description += " This API version has been deprecated.";
|
||||||
|
}
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
}
|
3
API/ProblemResponse.cs
Normal file
3
API/ProblemResponse.cs
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
namespace API;
|
||||||
|
|
||||||
|
public record ProblemResponse(string title, string? message = null);
|
155
API/Program.cs
155
API/Program.cs
@ -1,46 +1,133 @@
|
|||||||
using System.Runtime.InteropServices;
|
using System.Reflection;
|
||||||
using Logging;
|
using System.Text.Json.Serialization;
|
||||||
using Tranga;
|
using API;
|
||||||
|
using API.Schema;
|
||||||
|
using API.Schema.Jobs;
|
||||||
|
using API.Schema.MangaConnectors;
|
||||||
|
using Asp.Versioning;
|
||||||
|
using Asp.Versioning.Builder;
|
||||||
|
using Asp.Versioning.Conventions;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Newtonsoft.Json.Converters;
|
||||||
|
|
||||||
namespace API;
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
public class Program
|
builder.Services.AddCors(options =>
|
||||||
{
|
{
|
||||||
public static void Main(string[] args)
|
options.AddPolicy("AllowAll",
|
||||||
{
|
policy =>
|
||||||
string applicationFolderPath = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Tranga-API");
|
{
|
||||||
string downloadFolderPath = RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? "/Manga" : Path.Join(applicationFolderPath, "Manga");
|
policy
|
||||||
string logsFolderPath = RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? "/var/logs/Tranga" : Path.Join(applicationFolderPath, "logs");
|
.AllowAnyOrigin()
|
||||||
string logFilePath = Path.Join(logsFolderPath, $"log-{DateTime.Now:dd-M-yyyy-HH-mm-ss}.txt");
|
.AllowAnyMethod()
|
||||||
string settingsFilePath = Path.Join(applicationFolderPath, "settings.json");
|
.AllowAnyHeader();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
Directory.CreateDirectory(logsFolderPath);
|
builder.Services.AddApiVersioning(option =>
|
||||||
Logger logger = new(new[] { Logger.LoggerType.FileLogger, Logger.LoggerType.ConsoleLogger }, Console.Out, Console.Out.Encoding, logFilePath);
|
{
|
||||||
|
option.AssumeDefaultVersionWhenUnspecified = true;
|
||||||
|
option.DefaultApiVersion = new ApiVersion(2);
|
||||||
|
option.ReportApiVersions = true;
|
||||||
|
option.ApiVersionReader = ApiVersionReader.Combine(
|
||||||
|
new UrlSegmentApiVersionReader(),
|
||||||
|
new QueryStringApiVersionReader("api-version"),
|
||||||
|
new HeaderApiVersionReader("X-Version"),
|
||||||
|
new MediaTypeApiVersionReader("x-version"));
|
||||||
|
})
|
||||||
|
.AddMvc(options =>
|
||||||
|
{
|
||||||
|
options.Conventions.Add(new VersionByNamespaceConvention());
|
||||||
|
})
|
||||||
|
.AddApiExplorer(options => {
|
||||||
|
options.GroupNameFormat = "'v'V";
|
||||||
|
options.SubstituteApiVersionInUrl = true;
|
||||||
|
});
|
||||||
|
builder.Services.AddEndpointsApiExplorer();
|
||||||
|
builder.Services.AddSwaggerGen(opt =>
|
||||||
|
{
|
||||||
|
var xmlFilename = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
|
||||||
|
opt.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, xmlFilename));
|
||||||
|
});
|
||||||
|
builder.Services.ConfigureOptions<NamedSwaggerGenOptions>();
|
||||||
|
|
||||||
logger.WriteLine("Tranga", "Loading settings.");
|
builder.Services.AddDbContext<PgsqlContext>(options =>
|
||||||
|
options.UseNpgsql($"Host={Environment.GetEnvironmentVariable("POSTGRES_HOST")??"localhost:5432"}; " +
|
||||||
|
$"Database={Environment.GetEnvironmentVariable("POSTGRES_DB")??"postgres"}; " +
|
||||||
|
$"Username={Environment.GetEnvironmentVariable("POSTGRES_USER")??"postgres"}; " +
|
||||||
|
$"Password={Environment.GetEnvironmentVariable("POSTGRES_PASSWORD")??"postgres"}"));
|
||||||
|
|
||||||
TrangaSettings settings;
|
builder.Services.AddControllers().AddNewtonsoftJson(opts =>
|
||||||
if (File.Exists(settingsFilePath))
|
{
|
||||||
settings = TrangaSettings.LoadSettings(settingsFilePath, logger);
|
opts.SerializerSettings.Converters.Add(new StringEnumConverter());
|
||||||
else
|
});
|
||||||
settings = new TrangaSettings(downloadFolderPath, applicationFolderPath, new HashSet<LibraryManager>(), new HashSet<NotificationManager>());
|
|
||||||
|
|
||||||
Directory.CreateDirectory(settings.workingDirectory);
|
builder.WebHost.UseUrls("http://*:6531");
|
||||||
Directory.CreateDirectory(settings.downloadLocation);
|
|
||||||
Directory.CreateDirectory(settings.coverImageCache);
|
|
||||||
|
|
||||||
logger.WriteLine("Tranga",$"Application-Folder: {settings.workingDirectory}");
|
var app = builder.Build();
|
||||||
logger.WriteLine("Tranga",$"Settings-File-Path: {settings.settingsFilePath}");
|
|
||||||
logger.WriteLine("Tranga",$"Download-Folder-Path: {settings.downloadLocation}");
|
|
||||||
logger.WriteLine("Tranga",$"Logfile-Path: {logFilePath}");
|
|
||||||
logger.WriteLine("Tranga",$"Image-Cache-Path: {settings.coverImageCache}");
|
|
||||||
|
|
||||||
logger.WriteLine("Tranga", "Loading Taskmanager.");
|
ApiVersionSet apiVersionSet = app.NewApiVersionSet()
|
||||||
TaskManager taskManager = new (settings, logger);
|
.HasApiVersion(new ApiVersion(2))
|
||||||
|
.ReportApiVersions()
|
||||||
|
.Build();
|
||||||
|
|
||||||
Server server = new (6531, taskManager, logger);
|
|
||||||
foreach(NotificationManager nm in taskManager.settings.notificationManagers)
|
app.UseCors("AllowAll");
|
||||||
nm.SendNotification("Tranga-API", "Started Tranga-API");
|
|
||||||
}
|
app.MapControllers()
|
||||||
|
.WithApiVersionSet(apiVersionSet)
|
||||||
|
.MapToApiVersion(2);
|
||||||
|
|
||||||
|
app.UseSwagger();
|
||||||
|
app.UseSwaggerUI(options =>
|
||||||
|
{
|
||||||
|
options.SwaggerEndpoint(
|
||||||
|
$"/swagger/v2/swagger.json", "v2");
|
||||||
|
});
|
||||||
|
|
||||||
|
app.UseHttpsRedirection();
|
||||||
|
|
||||||
|
using (var scope = app.Services.CreateScope())
|
||||||
|
{
|
||||||
|
var db = scope.ServiceProvider.GetRequiredService<PgsqlContext>();
|
||||||
|
db.Database.Migrate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
using (var scope = app.Services.CreateScope())
|
||||||
|
{
|
||||||
|
PgsqlContext context = scope.ServiceProvider.GetService<PgsqlContext>()!;
|
||||||
|
|
||||||
|
MangaConnector[] connectors =
|
||||||
|
[
|
||||||
|
new AsuraToon(),
|
||||||
|
new Bato(),
|
||||||
|
new MangaDex(),
|
||||||
|
new MangaHere(),
|
||||||
|
new MangaKatana(),
|
||||||
|
new MangaLife(),
|
||||||
|
new Manganato(),
|
||||||
|
new Mangasee(),
|
||||||
|
new Mangaworld(),
|
||||||
|
new ManhuaPlus(),
|
||||||
|
new Weebcentral()
|
||||||
|
];
|
||||||
|
MangaConnector[] newConnectors = connectors.Where(c => !context.MangaConnectors.Contains(c)).ToArray();
|
||||||
|
context.MangaConnectors.AddRange(newConnectors);
|
||||||
|
|
||||||
|
context.Jobs.RemoveRange(context.Jobs.Where(j => j.state == JobState.Completed && j.RecurrenceMs < 1));
|
||||||
|
|
||||||
|
string[] emojis = { "(•‿•)", "(づ \u25d5‿\u25d5 )づ", "( \u02d8\u25bd\u02d8)っ\u2668", "=\uff3e\u25cf \u22cf \u25cf\uff3e=", "(ΦωΦ)", "(\u272a\u3268\u272a)", "( ノ・o・ )ノ", "(〜^\u2207^ )〜", "~(\u2267ω\u2266)~","૮ \u00b4• ﻌ \u00b4• ა", "(\u02c3ᆺ\u02c2)", "(=\ud83d\udf66 \u0f1d \ud83d\udf66=)"};
|
||||||
|
context.Notifications.Add(new Notification("Tranga Started", emojis[Random.Shared.Next(0, emojis.Length - 1)], NotificationUrgency.High));
|
||||||
|
|
||||||
|
context.SaveChanges();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TrangaSettings.Load();
|
||||||
|
Tranga.StartLogger();
|
||||||
|
Tranga.JobStarterThread.Start(app.Services.CreateScope().ServiceProvider.GetService<PgsqlContext>());
|
||||||
|
Tranga.NotificationSenderThread.Start(app.Services.CreateScope().ServiceProvider.GetService<PgsqlContext>());
|
||||||
|
|
||||||
|
app.UseCors("AllowAll");
|
||||||
|
|
||||||
|
app.Run();
|
47
API/Properties/launchSettings.json
Normal file
47
API/Properties/launchSettings.json
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
{
|
||||||
|
"$schema": "http://json.schemastore.org/launchsettings.json",
|
||||||
|
"iisSettings": {
|
||||||
|
"windowsAuthentication": false,
|
||||||
|
"anonymousAuthentication": true,
|
||||||
|
"iisExpress": {
|
||||||
|
"applicationUrl": "http://localhost:5976",
|
||||||
|
"sslPort": 44332,
|
||||||
|
"environmentVariables": {
|
||||||
|
"POSTGRES_Host": "localhost:5432"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"profiles": {
|
||||||
|
"http": {
|
||||||
|
"commandName": "Project",
|
||||||
|
"dotnetRunMessages": true,
|
||||||
|
"launchBrowser": true,
|
||||||
|
"launchUrl": "swagger",
|
||||||
|
"applicationUrl": "http://localhost:5287",
|
||||||
|
"environmentVariables": {
|
||||||
|
"ASPNETCORE_ENVIRONMENT": "Development",
|
||||||
|
"POSTGRES_Host": "localhost:5432"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"https": {
|
||||||
|
"commandName": "Project",
|
||||||
|
"dotnetRunMessages": true,
|
||||||
|
"launchBrowser": true,
|
||||||
|
"launchUrl": "swagger",
|
||||||
|
"applicationUrl": "https://localhost:7206;http://localhost:5287",
|
||||||
|
"environmentVariables": {
|
||||||
|
"ASPNETCORE_ENVIRONMENT": "Development",
|
||||||
|
"POSTGRES_Host": "localhost:5432"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"IIS Express": {
|
||||||
|
"commandName": "IISExpress",
|
||||||
|
"launchBrowser": true,
|
||||||
|
"launchUrl": "swagger",
|
||||||
|
"environmentVariables": {
|
||||||
|
"ASPNETCORE_ENVIRONMENT": "Development",
|
||||||
|
"POSTGRES_Host": "localhost:5432"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,361 +0,0 @@
|
|||||||
using System.Net;
|
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
using Tranga;
|
|
||||||
using Tranga.TrangaTasks;
|
|
||||||
|
|
||||||
namespace API;
|
|
||||||
|
|
||||||
public class RequestHandler
|
|
||||||
{
|
|
||||||
private TaskManager _taskManager;
|
|
||||||
private Server _parent;
|
|
||||||
|
|
||||||
private List<ValueTuple<HttpMethod, string, string[]>> _validRequestPaths = new()
|
|
||||||
{
|
|
||||||
new(HttpMethod.Get, "/", Array.Empty<string>()),
|
|
||||||
new(HttpMethod.Get, "/Connectors", Array.Empty<string>()),
|
|
||||||
new(HttpMethod.Get, "/Publications/Known", new[] { "internalId?" }),
|
|
||||||
new(HttpMethod.Get, "/Publications/FromConnector", new[] { "connectorName", "title" }),
|
|
||||||
new(HttpMethod.Get, "/Publications/Chapters",
|
|
||||||
new[] { "connectorName", "internalId", "onlyNew?", "onlyExisting?", "language?" }),
|
|
||||||
new(HttpMethod.Get, "/Tasks/Types", Array.Empty<string>()),
|
|
||||||
new(HttpMethod.Post, "/Tasks/CreateMonitorTask",
|
|
||||||
new[] { "connectorName", "internalId", "reoccurrenceTime", "language?" }),
|
|
||||||
new(HttpMethod.Post, "/Tasks/CreateUpdateLibraryTask", new[] { "reoccurrenceTime" }),
|
|
||||||
new(HttpMethod.Post, "/Tasks/CreateDownloadChaptersTask",
|
|
||||||
new[] { "connectorName", "internalId", "chapters", "language?" }),
|
|
||||||
new(HttpMethod.Get, "/Tasks", new[] { "taskType", "connectorName?", "publicationId?" }),
|
|
||||||
new(HttpMethod.Delete, "/Tasks", new[] { "taskType", "connectorName?", "searchString?" }),
|
|
||||||
new(HttpMethod.Get, "/Tasks/Progress",
|
|
||||||
new[] { "taskType", "connectorName", "publicationId", "chapterSortNumber?" }),
|
|
||||||
new(HttpMethod.Post, "/Tasks/Start", new[] { "taskType", "connectorName?", "internalId?" }),
|
|
||||||
new(HttpMethod.Get, "/Tasks/RunningTasks", Array.Empty<string>()),
|
|
||||||
new(HttpMethod.Get, "/Queue/List", Array.Empty<string>()),
|
|
||||||
new(HttpMethod.Post, "/Queue/Enqueue", new[] { "taskType", "connectorName?", "publicationId?" }),
|
|
||||||
new(HttpMethod.Delete, "/Queue/Dequeue", new[] { "taskType", "connectorName?", "publicationId?" }),
|
|
||||||
new(HttpMethod.Get, "/Settings", Array.Empty<string>()),
|
|
||||||
new(HttpMethod.Post, "/Settings/Update", new[]
|
|
||||||
{
|
|
||||||
"downloadLocation?", "komgaUrl?", "komgaAuth?", "kavitaUrl?", "kavitaUsername?",
|
|
||||||
"kavitaPassword?", "gotifyUrl?", "gotifyAppToken?", "lunaseaWebhook?"
|
|
||||||
})
|
|
||||||
};
|
|
||||||
|
|
||||||
public RequestHandler(TaskManager taskManager, Server parent)
|
|
||||||
{
|
|
||||||
this._taskManager = taskManager;
|
|
||||||
this._parent = parent;
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void HandleRequest(HttpListenerRequest request, HttpListenerResponse response)
|
|
||||||
{
|
|
||||||
string requestPath = request.Url!.LocalPath;
|
|
||||||
if (requestPath.Contains("favicon"))
|
|
||||||
{
|
|
||||||
_parent.SendResponse(HttpStatusCode.NoContent, response);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!this._validRequestPaths.Any(path => path.Item1.Method == request.HttpMethod && path.Item2 == requestPath))
|
|
||||||
{
|
|
||||||
_parent.SendResponse(HttpStatusCode.BadRequest, response);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Dictionary<string, string> variables = GetRequestVariables(request.Url!.Query);
|
|
||||||
object? responseObject = null;
|
|
||||||
switch (request.HttpMethod)
|
|
||||||
{
|
|
||||||
case "GET":
|
|
||||||
responseObject = this.HandleGet(requestPath, variables);
|
|
||||||
break;
|
|
||||||
case "POST":
|
|
||||||
this.HandlePost(requestPath, variables);
|
|
||||||
break;
|
|
||||||
case "DELETE":
|
|
||||||
this.HandleDelete(requestPath, variables);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
_parent.SendResponse(HttpStatusCode.OK, response, responseObject);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Dictionary<string, string> GetRequestVariables(string query)
|
|
||||||
{
|
|
||||||
Dictionary<string, string> ret = new();
|
|
||||||
Regex queryRex = new (@"\?{1}([A-z]+=[A-z]+)+(&[A-z]+=[A-z]+)*");
|
|
||||||
if (!queryRex.IsMatch(query))
|
|
||||||
return ret;
|
|
||||||
query = query.Substring(1);
|
|
||||||
foreach(string kvpair in query.Split('&'))
|
|
||||||
ret.Add(kvpair.Split('=')[0], kvpair.Split('=')[1]);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void HandleDelete(string requestPath, Dictionary<string, string> variables)
|
|
||||||
{
|
|
||||||
switch (requestPath)
|
|
||||||
{
|
|
||||||
case "/Tasks":
|
|
||||||
variables.TryGetValue("taskType", out string? taskType1);
|
|
||||||
variables.TryGetValue("connectorName", out string? connectorName1);
|
|
||||||
variables.TryGetValue("publicationId", out string? publicationId1);
|
|
||||||
if(taskType1 is null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
TrangaTask.Task task = Enum.Parse<TrangaTask.Task>(taskType1);
|
|
||||||
foreach(TrangaTask tTask in _taskManager.GetTasksMatching(task, connectorName1, internalId: publicationId1))
|
|
||||||
_taskManager.DeleteTask(tTask);
|
|
||||||
}
|
|
||||||
catch (ArgumentException)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "/Queue/Dequeue":
|
|
||||||
variables.TryGetValue("taskType", out string? taskType2);
|
|
||||||
variables.TryGetValue("connectorName", out string? connectorName2);
|
|
||||||
variables.TryGetValue("publicationId", out string? publicationId2);
|
|
||||||
if(taskType2 is null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
TrangaTask.Task pTask = Enum.Parse<TrangaTask.Task>(taskType2);
|
|
||||||
TrangaTask? task = _taskManager
|
|
||||||
.GetTasksMatching(pTask, connectorName: connectorName2, internalId: publicationId2).FirstOrDefault();
|
|
||||||
|
|
||||||
if (task is null)
|
|
||||||
return;
|
|
||||||
_taskManager.RemoveTaskFromQueue(task);
|
|
||||||
}
|
|
||||||
catch (ArgumentException)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void HandlePost(string requestPath, Dictionary<string, string> variables)
|
|
||||||
{
|
|
||||||
switch (requestPath)
|
|
||||||
{
|
|
||||||
|
|
||||||
case "/Tasks/CreateMonitorTask":
|
|
||||||
variables.TryGetValue("connectorName", out string? connectorName1);
|
|
||||||
variables.TryGetValue("internalId", out string? internalId1);
|
|
||||||
variables.TryGetValue("reoccurrenceTime", out string? reoccurrenceTime1);
|
|
||||||
variables.TryGetValue("language", out string? language1);
|
|
||||||
if (connectorName1 is null || internalId1 is null || reoccurrenceTime1 is null)
|
|
||||||
return;
|
|
||||||
Connector? connector1 =
|
|
||||||
_taskManager.GetAvailableConnectors().FirstOrDefault(con => con.Key == connectorName1).Value;
|
|
||||||
if (connector1 is null)
|
|
||||||
return;
|
|
||||||
Publication? publication1 = _taskManager.GetAllPublications().FirstOrDefault(pub => pub.internalId == internalId1);
|
|
||||||
if (publication1 is null)
|
|
||||||
return;
|
|
||||||
_taskManager.AddTask(new MonitorPublicationTask(connectorName1, (Publication)publication1, TimeSpan.Parse(reoccurrenceTime1), language1 ?? "en"));
|
|
||||||
break;
|
|
||||||
case "/Tasks/CreateUpdateLibraryTask":
|
|
||||||
variables.TryGetValue("reoccurrenceTime", out string? reoccurrenceTime2);
|
|
||||||
if (reoccurrenceTime2 is null)
|
|
||||||
return;
|
|
||||||
_taskManager.AddTask(new UpdateLibrariesTask(TimeSpan.Parse(reoccurrenceTime2)));
|
|
||||||
break;
|
|
||||||
case "/Tasks/CreateDownloadChaptersTask":
|
|
||||||
variables.TryGetValue("connectorName", out string? connectorName2);
|
|
||||||
variables.TryGetValue("internalId", out string? internalId2);
|
|
||||||
variables.TryGetValue("chapters", out string? chapters);
|
|
||||||
variables.TryGetValue("language", out string? language2);
|
|
||||||
if (connectorName2 is null || internalId2 is null || chapters is null)
|
|
||||||
return;
|
|
||||||
Connector? connector2 =
|
|
||||||
_taskManager.GetAvailableConnectors().FirstOrDefault(con => con.Key == connectorName2).Value;
|
|
||||||
if (connector2 is null)
|
|
||||||
return;
|
|
||||||
Publication? publication2 = _taskManager.GetAllPublications().FirstOrDefault(pub => pub.internalId == internalId2);
|
|
||||||
if (publication2 is null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
IEnumerable<Chapter> toDownload = connector2.SearchChapters((Publication)publication2, chapters, language2 ?? "en");
|
|
||||||
foreach(Chapter chapter in toDownload)
|
|
||||||
_taskManager.AddTask(new DownloadChapterTask(connectorName2, (Publication)publication2, chapter, "en"));
|
|
||||||
break;
|
|
||||||
case "/Tasks/Start":
|
|
||||||
variables.TryGetValue("taskType", out string? taskType1);
|
|
||||||
variables.TryGetValue("connectorName", out string? connectorName3);
|
|
||||||
variables.TryGetValue("internalId", out string? internalId3);
|
|
||||||
if (taskType1 is null)
|
|
||||||
return;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
TrangaTask.Task pTask = Enum.Parse<TrangaTask.Task>(taskType1);
|
|
||||||
TrangaTask? task = _taskManager
|
|
||||||
.GetTasksMatching(pTask, connectorName: connectorName3, internalId: internalId3).FirstOrDefault();
|
|
||||||
|
|
||||||
if (task is null)
|
|
||||||
return;
|
|
||||||
_taskManager.ExecuteTaskNow(task);
|
|
||||||
}
|
|
||||||
catch (ArgumentException)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "/Queue/Enqueue":
|
|
||||||
variables.TryGetValue("taskType", out string? taskType2);
|
|
||||||
variables.TryGetValue("connectorName", out string? connectorName4);
|
|
||||||
variables.TryGetValue("publicationId", out string? publicationId);
|
|
||||||
if (taskType2 is null)
|
|
||||||
return;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
TrangaTask.Task pTask = Enum.Parse<TrangaTask.Task>(taskType2);
|
|
||||||
TrangaTask? task = _taskManager
|
|
||||||
.GetTasksMatching(pTask, connectorName: connectorName4, internalId: publicationId).FirstOrDefault();
|
|
||||||
|
|
||||||
if (task is null)
|
|
||||||
return;
|
|
||||||
_taskManager.AddTaskToQueue(task);
|
|
||||||
}
|
|
||||||
catch (ArgumentException)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "/Settings/Update":
|
|
||||||
variables.TryGetValue("downloadLocation", out string? downloadLocation);
|
|
||||||
variables.TryGetValue("komgaUrl", out string? komgaUrl);
|
|
||||||
variables.TryGetValue("komgaAuth", out string? komgaAuth);
|
|
||||||
variables.TryGetValue("kavitaUrl", out string? kavitaUrl);
|
|
||||||
variables.TryGetValue("kavitaUsername", out string? kavitaUsername);
|
|
||||||
variables.TryGetValue("kavitaPassword", out string? kavitaPassword);
|
|
||||||
variables.TryGetValue("gotifyUrl", out string? gotifyUrl);
|
|
||||||
variables.TryGetValue("gotifyAppToken", out string? gotifyAppToken);
|
|
||||||
variables.TryGetValue("lunaseaWebhook", out string? lunaseaWebhook);
|
|
||||||
|
|
||||||
if (downloadLocation is not null && downloadLocation.Length > 0)
|
|
||||||
_taskManager.settings.UpdateSettings(TrangaSettings.UpdateField.DownloadLocation, _parent.logger, downloadLocation);
|
|
||||||
if (komgaUrl is not null && komgaAuth is not null && komgaUrl.Length > 5 && komgaAuth.Length > 0)
|
|
||||||
_taskManager.settings.UpdateSettings(TrangaSettings.UpdateField.Komga, _parent.logger, komgaUrl, komgaAuth);
|
|
||||||
if (kavitaUrl is not null && kavitaPassword is not null && kavitaUsername is not null && kavitaUrl.Length > 5 &&
|
|
||||||
kavitaUsername.Length > 0 && kavitaPassword.Length > 0)
|
|
||||||
_taskManager.settings.UpdateSettings(TrangaSettings.UpdateField.Kavita, _parent.logger, kavitaUrl, kavitaUsername,
|
|
||||||
kavitaPassword);
|
|
||||||
if (gotifyUrl is not null && gotifyAppToken is not null && gotifyUrl.Length > 5 && gotifyAppToken.Length > 0)
|
|
||||||
_taskManager.settings.UpdateSettings(TrangaSettings.UpdateField.Gotify, _parent.logger, gotifyUrl, gotifyAppToken);
|
|
||||||
if(lunaseaWebhook is not null && lunaseaWebhook.Length > 5)
|
|
||||||
_taskManager.settings.UpdateSettings(TrangaSettings.UpdateField.LunaSea, _parent.logger, lunaseaWebhook);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private object? HandleGet(string requestPath, Dictionary<string, string> variables)
|
|
||||||
{
|
|
||||||
switch (requestPath)
|
|
||||||
{
|
|
||||||
case "/Connectors":
|
|
||||||
return this._taskManager.GetAvailableConnectors().Keys.ToArray();
|
|
||||||
case "/Publications/Known":
|
|
||||||
variables.TryGetValue("internalId", out string? internalId1);
|
|
||||||
if(internalId1 is null)
|
|
||||||
return _taskManager.GetAllPublications();
|
|
||||||
return new [] { _taskManager.GetAllPublications().FirstOrDefault(pub => pub.internalId == internalId1) };
|
|
||||||
case "/Publications/FromConnector":
|
|
||||||
variables.TryGetValue("connectorName", out string? connectorName1);
|
|
||||||
variables.TryGetValue("title", out string? title);
|
|
||||||
if (connectorName1 is null || title is null)
|
|
||||||
return null;
|
|
||||||
Connector? connector1 = _taskManager.GetAvailableConnectors().FirstOrDefault(con => con.Key == connectorName1).Value;
|
|
||||||
if (connector1 is null)
|
|
||||||
return null;
|
|
||||||
if(title.Length < 4)
|
|
||||||
return null;
|
|
||||||
return _taskManager.GetPublicationsFromConnector(connector1, title);
|
|
||||||
case "/Publications/Chapters":
|
|
||||||
string[] yes = { "true", "yes", "1", "y" };
|
|
||||||
variables.TryGetValue("connectorName", out string? connectorName2);
|
|
||||||
variables.TryGetValue("internalId", out string? internalId2);
|
|
||||||
variables.TryGetValue("onlyNew", out string? onlyNew);
|
|
||||||
variables.TryGetValue("onlyExisting", out string? onlyExisting);
|
|
||||||
variables.TryGetValue("language", out string? language);
|
|
||||||
if (connectorName2 is null || internalId2 is null)
|
|
||||||
return null;
|
|
||||||
bool newOnly = onlyNew is not null && yes.Contains(onlyNew);
|
|
||||||
bool existingOnly = onlyExisting is not null && yes.Contains(onlyExisting);
|
|
||||||
|
|
||||||
Connector? connector2 = _taskManager.GetAvailableConnectors().FirstOrDefault(con => con.Key == connectorName2).Value;
|
|
||||||
if (connector2 is null)
|
|
||||||
return null;
|
|
||||||
Publication? publication = _taskManager.GetAllPublications().FirstOrDefault(pub => pub.internalId == internalId2);
|
|
||||||
if (publication is null)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
if(newOnly)
|
|
||||||
return _taskManager.GetNewChaptersList(connector2, (Publication)publication, language??"en").ToArray();
|
|
||||||
else if (existingOnly)
|
|
||||||
return _taskManager.GetExistingChaptersList(connector2, (Publication)publication, language ?? "en").ToArray();
|
|
||||||
else
|
|
||||||
return connector2.GetChapters((Publication)publication, language??"en");
|
|
||||||
case "/Tasks/Types":
|
|
||||||
return Enum.GetNames(typeof(TrangaTask.Task));
|
|
||||||
case "/Tasks":
|
|
||||||
variables.TryGetValue("taskType", out string? taskType1);
|
|
||||||
variables.TryGetValue("connectorName", out string? connectorName3);
|
|
||||||
variables.TryGetValue("searchString", out string? searchString);
|
|
||||||
if (taskType1 is null)
|
|
||||||
return null;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
TrangaTask.Task task = Enum.Parse<TrangaTask.Task>(taskType1);
|
|
||||||
return _taskManager.GetTasksMatching(task, connectorName:connectorName3, searchString:searchString);
|
|
||||||
}
|
|
||||||
catch (ArgumentException)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
case "/Tasks/Progress":
|
|
||||||
variables.TryGetValue("taskType", out string? taskType2);
|
|
||||||
variables.TryGetValue("connectorName", out string? connectorName4);
|
|
||||||
variables.TryGetValue("publicationId", out string? publicationId);
|
|
||||||
variables.TryGetValue("chapterSortNumber", out string? chapterSortNumber);
|
|
||||||
if (taskType2 is null || connectorName4 is null || publicationId is null)
|
|
||||||
return null;
|
|
||||||
Connector? connector =
|
|
||||||
_taskManager.GetAvailableConnectors().FirstOrDefault(con => con.Key == connectorName4).Value;
|
|
||||||
if (connector is null)
|
|
||||||
return null;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
TrangaTask? task = null;
|
|
||||||
TrangaTask.Task pTask = Enum.Parse<TrangaTask.Task>(taskType2);
|
|
||||||
if (pTask is TrangaTask.Task.MonitorPublication)
|
|
||||||
{
|
|
||||||
task = _taskManager.GetTasksMatching(pTask, connectorName: connectorName4, internalId: publicationId).FirstOrDefault();
|
|
||||||
}else if (pTask is TrangaTask.Task.DownloadChapter && chapterSortNumber is not null)
|
|
||||||
{
|
|
||||||
task = _taskManager.GetTasksMatching(pTask, connectorName: connectorName4, internalId: publicationId,
|
|
||||||
chapterSortNumber: chapterSortNumber).FirstOrDefault();
|
|
||||||
}
|
|
||||||
if (task is null)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
return task.progress;
|
|
||||||
}
|
|
||||||
catch (ArgumentException)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
case "/Tasks/RunningTasks":
|
|
||||||
return _taskManager.GetAllTasks().Where(task => task.state is TrangaTask.ExecutionState.Running);
|
|
||||||
case "/Queue/List":
|
|
||||||
return _taskManager.GetAllTasks().Where(task => task.state is TrangaTask.ExecutionState.Enqueued).OrderBy(task => task.nextExecution);
|
|
||||||
case "/Settings":
|
|
||||||
return _taskManager.settings;
|
|
||||||
case "/":
|
|
||||||
default:
|
|
||||||
return this._validRequestPaths;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
12
API/Schema/Author.cs
Normal file
12
API/Schema/Author.cs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace API.Schema;
|
||||||
|
|
||||||
|
[PrimaryKey("AuthorId")]
|
||||||
|
public class Author(string authorName)
|
||||||
|
{
|
||||||
|
[MaxLength(64)]
|
||||||
|
public string AuthorId { get; init; } = TokenGen.CreateToken(typeof(Author), 64);
|
||||||
|
public string AuthorName { get; init; } = authorName;
|
||||||
|
}
|
113
API/Schema/Chapter.cs
Normal file
113
API/Schema/Chapter.cs
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
using API.Schema.Jobs;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace API.Schema;
|
||||||
|
|
||||||
|
[PrimaryKey("ChapterId")]
|
||||||
|
public class Chapter : IComparable<Chapter>
|
||||||
|
{
|
||||||
|
[MaxLength(64)]
|
||||||
|
public string ChapterId { get; init; } = TokenGen.CreateToken(typeof(Chapter), 64);
|
||||||
|
public int? VolumeNumber { get; private set; }
|
||||||
|
public ChapterNumber ChapterNumber { get; private set; }
|
||||||
|
public string Url { get; internal set; }
|
||||||
|
public string? Title { get; private set; }
|
||||||
|
public string ArchiveFileName { get; private set; }
|
||||||
|
public bool Downloaded { get; internal set; } = false;
|
||||||
|
|
||||||
|
public string ParentMangaId { get; internal set; }
|
||||||
|
public Manga? ParentManga { get; init; }
|
||||||
|
|
||||||
|
public Chapter(Manga parentManga, string url, ChapterNumber chapterNumber, int? volumeNumber = null, string? title = null)
|
||||||
|
: this(parentManga.MangaId, url, chapterNumber, volumeNumber, title)
|
||||||
|
{
|
||||||
|
this.ParentManga = parentManga;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Chapter(string parentMangaId, string url, ChapterNumber chapterNumber,
|
||||||
|
int? volumeNumber = null, string? title = null)
|
||||||
|
{
|
||||||
|
this.ParentMangaId = parentMangaId;
|
||||||
|
this.Url = url;
|
||||||
|
this.ChapterNumber = chapterNumber;
|
||||||
|
this.VolumeNumber = volumeNumber;
|
||||||
|
this.Title = title;
|
||||||
|
this.ArchiveFileName = BuildArchiveFileName();
|
||||||
|
}
|
||||||
|
|
||||||
|
public MoveFileOrFolderJob? UpdateChapterNumber(ChapterNumber chapterNumber)
|
||||||
|
{
|
||||||
|
this.ChapterNumber = chapterNumber;
|
||||||
|
return UpdateArchiveFileName();
|
||||||
|
}
|
||||||
|
|
||||||
|
public MoveFileOrFolderJob? UpdateVolumeNumber(int? volumeNumber)
|
||||||
|
{
|
||||||
|
this.VolumeNumber = volumeNumber;
|
||||||
|
return UpdateArchiveFileName();
|
||||||
|
}
|
||||||
|
|
||||||
|
public MoveFileOrFolderJob? UpdateTitle(string? title)
|
||||||
|
{
|
||||||
|
this.Title = title;
|
||||||
|
return UpdateArchiveFileName();
|
||||||
|
}
|
||||||
|
|
||||||
|
private string BuildArchiveFileName()
|
||||||
|
{
|
||||||
|
return $"{this.ParentManga.Name} - Vol.{this.VolumeNumber ?? 0} Ch.{this.ChapterNumber}{(this.Title is null ? "" : $" - {this.Title}")}.cbz";
|
||||||
|
}
|
||||||
|
|
||||||
|
private MoveFileOrFolderJob? UpdateArchiveFileName()
|
||||||
|
{
|
||||||
|
string oldPath = GetArchiveFilePath();
|
||||||
|
this.ArchiveFileName = BuildArchiveFileName();
|
||||||
|
if (Downloaded)
|
||||||
|
{
|
||||||
|
return new MoveFileOrFolderJob(oldPath, GetArchiveFilePath());
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates full file path of chapter-archive
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Filepath</returns>
|
||||||
|
internal string GetArchiveFilePath()
|
||||||
|
{
|
||||||
|
return Path.Join(TrangaSettings.downloadLocation, ParentManga.FolderName, ArchiveFileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsDownloaded()
|
||||||
|
{
|
||||||
|
string path = GetArchiveFilePath();
|
||||||
|
return File.Exists(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int CompareTo(Chapter? other)
|
||||||
|
{
|
||||||
|
if(other is not { } otherChapter)
|
||||||
|
throw new ArgumentException($"{other} can not be compared to {this}");
|
||||||
|
return this.VolumeNumber?.CompareTo(otherChapter.VolumeNumber) switch
|
||||||
|
{
|
||||||
|
<0 => -1,
|
||||||
|
>0 => 1,
|
||||||
|
_ => this.ChapterNumber.CompareTo(otherChapter.ChapterNumber)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
internal string GetComicInfoXmlString()
|
||||||
|
{
|
||||||
|
XElement comicInfo = new XElement("ComicInfo",
|
||||||
|
new XElement("Tags", string.Join(',', ParentManga.Tags.Select(tag => tag.Tag))),
|
||||||
|
new XElement("LanguageISO", ParentManga.OriginalLanguage),
|
||||||
|
new XElement("Title", this.Title),
|
||||||
|
new XElement("Writer", string.Join(',', ParentManga.Authors.Select(author => author.AuthorName))),
|
||||||
|
new XElement("Volume", this.VolumeNumber),
|
||||||
|
new XElement("Number", this.ChapterNumber)
|
||||||
|
);
|
||||||
|
return comicInfo.ToString();
|
||||||
|
}
|
||||||
|
}
|
305
API/Schema/ChapterNumber.cs
Normal file
305
API/Schema/ChapterNumber.cs
Normal file
@ -0,0 +1,305 @@
|
|||||||
|
using System.Diagnostics;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Numerics;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
|
namespace API.Schema;
|
||||||
|
|
||||||
|
public readonly struct ChapterNumber : INumber<ChapterNumber>
|
||||||
|
{
|
||||||
|
private readonly uint[] _numbers;
|
||||||
|
private readonly bool _naN;
|
||||||
|
|
||||||
|
private ChapterNumber(uint[] numbers, bool naN = false)
|
||||||
|
{
|
||||||
|
this._numbers = numbers;
|
||||||
|
this._naN = naN;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ChapterNumber(string number)
|
||||||
|
{
|
||||||
|
if (!CanParse(number))
|
||||||
|
{
|
||||||
|
this._numbers = [];
|
||||||
|
this._naN = true;
|
||||||
|
}
|
||||||
|
this._numbers = number.Split('.').Select(uint.Parse).ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ChapterNumber(float number) : this(number.ToString("F")) {}
|
||||||
|
|
||||||
|
public ChapterNumber(double number) : this((float)number) {}
|
||||||
|
|
||||||
|
public ChapterNumber(uint number)
|
||||||
|
{
|
||||||
|
this._numbers = [number];
|
||||||
|
this._naN = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ChapterNumber(int number)
|
||||||
|
{
|
||||||
|
if (int.IsNegative(number))
|
||||||
|
{
|
||||||
|
this._numbers = [];
|
||||||
|
this._naN = true;
|
||||||
|
}
|
||||||
|
this._numbers = [(uint)number];
|
||||||
|
this._naN = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int CompareTo(ChapterNumber other)
|
||||||
|
{
|
||||||
|
byte index = 0;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
if (this._numbers[index] < other._numbers[index])
|
||||||
|
return -1;
|
||||||
|
else if (this._numbers[index] > other._numbers[index])
|
||||||
|
return 1;
|
||||||
|
}while(index < this._numbers.Length && index < other._numbers.Length);
|
||||||
|
|
||||||
|
if (index >= this._numbers.Length && index >= other._numbers.Length)
|
||||||
|
return 0;
|
||||||
|
else if (index >= this._numbers.Length)
|
||||||
|
return -1;
|
||||||
|
else if (index >= other._numbers.Length)
|
||||||
|
return 1;
|
||||||
|
throw new UnreachableException();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static readonly Regex Pattern = new(@"[0-9]+(?:\.[0-9]+)*");
|
||||||
|
public static bool CanParse(string? number) => number is not null && Pattern.Match(number).Length == number.Length && number.Length > 0;
|
||||||
|
|
||||||
|
public bool Equals(ChapterNumber other) => CompareTo(other) == 0;
|
||||||
|
|
||||||
|
public string ToString(string? format, IFormatProvider? formatProvider)
|
||||||
|
{
|
||||||
|
return string.Join('.', _numbers);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool Equals(object? obj)
|
||||||
|
{
|
||||||
|
return obj is ChapterNumber other && Equals(other);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int GetHashCode()
|
||||||
|
{
|
||||||
|
return HashCode.Combine(_numbers, _naN);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider? provider)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int CompareTo(object? obj)
|
||||||
|
{
|
||||||
|
if(obj is ChapterNumber other)
|
||||||
|
return CompareTo(other);
|
||||||
|
throw new ArgumentException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ChapterNumber Parse(string s, IFormatProvider? provider)
|
||||||
|
{
|
||||||
|
if(!CanParse(s))
|
||||||
|
throw new FormatException($"Invalid ChapterNumber-String: {s}");
|
||||||
|
return new ChapterNumber(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool TryParse([NotNullWhen(true)] string? s, IFormatProvider? provider, out ChapterNumber result)
|
||||||
|
{
|
||||||
|
result = new ChapterNumber([], true);;
|
||||||
|
if (!CanParse(s))
|
||||||
|
return false;
|
||||||
|
if (s is null)
|
||||||
|
return false;
|
||||||
|
result = new ChapterNumber(s);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ChapterNumber Parse(ReadOnlySpan<char> s, IFormatProvider? provider) => Parse(s.ToString(), provider);
|
||||||
|
|
||||||
|
public static bool TryParse(ReadOnlySpan<char> s, IFormatProvider? provider, out ChapterNumber result) => TryParse(s.ToString(), provider, out result);
|
||||||
|
|
||||||
|
public static ChapterNumber operator +(ChapterNumber left, ChapterNumber right)
|
||||||
|
{
|
||||||
|
if (IsNaN(left) || IsNaN(right))
|
||||||
|
return new ChapterNumber([], true);
|
||||||
|
int size = left._numbers.Length > right._numbers.Length ? left._numbers.Length : right._numbers.Length;
|
||||||
|
uint[] numbers = new uint[size];
|
||||||
|
for (int i = 0; i < size; i++)
|
||||||
|
{
|
||||||
|
if(left._numbers.Length < i)
|
||||||
|
numbers[i] = right._numbers[i];
|
||||||
|
else if(right._numbers.Length < i)
|
||||||
|
numbers[i] = left._numbers[i];
|
||||||
|
else
|
||||||
|
numbers[i] = left._numbers[i] + right._numbers[i];
|
||||||
|
}
|
||||||
|
return new ChapterNumber(numbers);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool BothNotNaN(ChapterNumber left, ChapterNumber right) => !IsNaN(left) && !IsNaN(right);
|
||||||
|
|
||||||
|
public static ChapterNumber AdditiveIdentity => Zero;
|
||||||
|
|
||||||
|
public static bool operator ==(ChapterNumber left, ChapterNumber right) => BothNotNaN(left, right) && left.Equals(right);
|
||||||
|
|
||||||
|
public static bool operator !=(ChapterNumber left, ChapterNumber right) => !(left == right);
|
||||||
|
|
||||||
|
public static bool operator >(ChapterNumber left, ChapterNumber right) => BothNotNaN(left, right) && left.CompareTo(right) > 0;
|
||||||
|
|
||||||
|
public static bool operator >=(ChapterNumber left, ChapterNumber right) => BothNotNaN(left, right) && left.CompareTo(right) >= 0;
|
||||||
|
|
||||||
|
public static bool operator <(ChapterNumber left, ChapterNumber right) => BothNotNaN(left, right) && left.CompareTo(right) < 0;
|
||||||
|
|
||||||
|
public static bool operator <=(ChapterNumber left, ChapterNumber right) => BothNotNaN(left, right) && left.CompareTo(right) <= 0;
|
||||||
|
|
||||||
|
public static ChapterNumber operator %(ChapterNumber left, ChapterNumber right) => throw new ArithmeticException();
|
||||||
|
|
||||||
|
public static ChapterNumber operator +(ChapterNumber value) => throw new InvalidOperationException();
|
||||||
|
|
||||||
|
public static ChapterNumber operator --(ChapterNumber value)
|
||||||
|
{
|
||||||
|
if (IsNaN(value))
|
||||||
|
return value;
|
||||||
|
uint[] numbers = value._numbers;
|
||||||
|
numbers[0]--;
|
||||||
|
return new ChapterNumber(numbers);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ChapterNumber operator /(ChapterNumber left, ChapterNumber right) => throw new InvalidOperationException();
|
||||||
|
|
||||||
|
public static ChapterNumber operator ++(ChapterNumber value)
|
||||||
|
{
|
||||||
|
if (IsNaN(value))
|
||||||
|
return value;
|
||||||
|
uint[] numbers = value._numbers;
|
||||||
|
numbers[0]++;
|
||||||
|
return new ChapterNumber(numbers);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ChapterNumber MultiplicativeIdentity => One;
|
||||||
|
public static ChapterNumber operator *(ChapterNumber left, ChapterNumber right) => throw new InvalidOperationException();
|
||||||
|
|
||||||
|
public static ChapterNumber operator -(ChapterNumber left, ChapterNumber right) => throw new InvalidOperationException();
|
||||||
|
|
||||||
|
public static ChapterNumber operator -(ChapterNumber value) => throw new InvalidOperationException();
|
||||||
|
|
||||||
|
public static ChapterNumber Abs(ChapterNumber value) => value;
|
||||||
|
|
||||||
|
public static bool IsCanonical(ChapterNumber value) => true;
|
||||||
|
|
||||||
|
public static bool IsComplexNumber(ChapterNumber value) => false;
|
||||||
|
|
||||||
|
public static bool IsEvenInteger(ChapterNumber value) => IsInteger(value) && uint.IsEvenInteger(value._numbers[0]);
|
||||||
|
|
||||||
|
public static bool IsFinite(ChapterNumber value) => true;
|
||||||
|
|
||||||
|
public static bool IsImaginaryNumber(ChapterNumber value) => false;
|
||||||
|
|
||||||
|
public static bool IsInfinity(ChapterNumber value) => false;
|
||||||
|
|
||||||
|
public static bool IsInteger(ChapterNumber value) => !IsNaN(value) && value._numbers.Length == 1;
|
||||||
|
|
||||||
|
public static bool IsNaN(ChapterNumber value) => value._naN;
|
||||||
|
|
||||||
|
public static bool IsNegative(ChapterNumber value) => false;
|
||||||
|
|
||||||
|
public static bool IsNegativeInfinity(ChapterNumber value) => false;
|
||||||
|
|
||||||
|
public static bool IsNormal(ChapterNumber value) => true;
|
||||||
|
|
||||||
|
public static bool IsOddInteger(ChapterNumber value) => false;
|
||||||
|
|
||||||
|
public static bool IsPositive(ChapterNumber value) => true;
|
||||||
|
|
||||||
|
public static bool IsPositiveInfinity(ChapterNumber value) => false;
|
||||||
|
|
||||||
|
public static bool IsRealNumber(ChapterNumber value) => false;
|
||||||
|
|
||||||
|
public static bool IsSubnormal(ChapterNumber value) => false;
|
||||||
|
|
||||||
|
public static bool IsZero(ChapterNumber value) => value._numbers.All(n => n == 0);
|
||||||
|
|
||||||
|
public static ChapterNumber MaxMagnitude(ChapterNumber x, ChapterNumber y)
|
||||||
|
{
|
||||||
|
if(IsNaN(x))
|
||||||
|
return new ChapterNumber([], true);
|
||||||
|
if (IsNaN(y))
|
||||||
|
return new ChapterNumber([], true);
|
||||||
|
return x >= y ? x : y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ChapterNumber MaxMagnitudeNumber(ChapterNumber x, ChapterNumber y)
|
||||||
|
{
|
||||||
|
if (IsNaN(x))
|
||||||
|
return y;
|
||||||
|
if (IsNaN(y))
|
||||||
|
return x;
|
||||||
|
return x >= y ? x : y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ChapterNumber MinMagnitude(ChapterNumber x, ChapterNumber y)
|
||||||
|
{
|
||||||
|
if(IsNaN(x))
|
||||||
|
return new ChapterNumber([], true);
|
||||||
|
if (IsNaN(y))
|
||||||
|
return new ChapterNumber([], true);
|
||||||
|
return x <= y ? x : y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ChapterNumber MinMagnitudeNumber(ChapterNumber x, ChapterNumber y)
|
||||||
|
{
|
||||||
|
if (IsNaN(x))
|
||||||
|
return y;
|
||||||
|
if (IsNaN(y))
|
||||||
|
return x;
|
||||||
|
return x <= y ? x : y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ChapterNumber Parse(ReadOnlySpan<char> s, NumberStyles style, IFormatProvider? provider) => throw new NotImplementedException();
|
||||||
|
|
||||||
|
public static ChapterNumber Parse(string s, NumberStyles style, IFormatProvider? provider) => throw new NotImplementedException();
|
||||||
|
|
||||||
|
public static bool TryConvertFromChecked<TOther>(TOther value, out ChapterNumber result) where TOther : INumberBase<TOther>
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool TryConvertFromSaturating<TOther>(TOther value, out ChapterNumber result) where TOther : INumberBase<TOther>
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool TryConvertFromTruncating<TOther>(TOther value, out ChapterNumber result) where TOther : INumberBase<TOther>
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool TryConvertToChecked<TOther>(ChapterNumber value, [MaybeNullWhen(false)] out TOther result) where TOther : INumberBase<TOther>
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool TryConvertToSaturating<TOther>(ChapterNumber value, [MaybeNullWhen(false)] out TOther result) where TOther : INumberBase<TOther>
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool TryConvertToTruncating<TOther>(ChapterNumber value, [MaybeNullWhen(false)] out TOther result) where TOther : INumberBase<TOther>
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool TryParse(ReadOnlySpan<char> s, NumberStyles style, IFormatProvider? provider, out ChapterNumber result)
|
||||||
|
=> TryParse(s.ToString(), style, provider, out result);
|
||||||
|
|
||||||
|
public static bool TryParse([NotNullWhen(true)] string? s, NumberStyles style, IFormatProvider? provider, out ChapterNumber result)
|
||||||
|
=> TryParse(s, provider, out result);
|
||||||
|
|
||||||
|
public static ChapterNumber One => new(1);
|
||||||
|
public static int Radix => 10;
|
||||||
|
public static ChapterNumber Zero => new(0);
|
||||||
|
}
|
136
API/Schema/Jobs/DownloadMangaCoverJob.cs
Normal file
136
API/Schema/Jobs/DownloadMangaCoverJob.cs
Normal file
@ -0,0 +1,136 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.IO.Compression;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using API.MangaDownloadClients;
|
||||||
|
using API.Schema.MangaConnectors;
|
||||||
|
using SixLabors.ImageSharp;
|
||||||
|
using SixLabors.ImageSharp.Formats.Jpeg;
|
||||||
|
using SixLabors.ImageSharp.Processing;
|
||||||
|
using SixLabors.ImageSharp.Processing.Processors.Binarization;
|
||||||
|
using static System.IO.UnixFileMode;
|
||||||
|
|
||||||
|
namespace API.Schema.Jobs;
|
||||||
|
|
||||||
|
public class DownloadMangaCoverJob(string chapterId, string? parentJobId = null, ICollection<string>? dependsOnJobsIds = null)
|
||||||
|
: Job(TokenGen.CreateToken(typeof(DownloadMangaCoverJob), 64), JobType.DownloadMangaCoverJob, 0, parentJobId, dependsOnJobsIds)
|
||||||
|
{
|
||||||
|
[MaxLength(64)]
|
||||||
|
public string ChapterId { get; init; } = chapterId;
|
||||||
|
public Chapter? Chapter { get; init; }
|
||||||
|
|
||||||
|
protected override IEnumerable<Job> RunInternal(PgsqlContext context)
|
||||||
|
{
|
||||||
|
MangaConnector connector = Chapter.ParentManga?.MangaConnector ?? context.MangaConnectors.Find(context.Manga.Find(Chapter.ParentMangaId)?.MangaId)!;
|
||||||
|
DownloadChapterImages(Chapter, connector);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool DownloadChapterImages(Chapter chapter, MangaConnector connector)
|
||||||
|
{
|
||||||
|
string[] imageUrls = connector.GetChapterImageUrls(Chapter);
|
||||||
|
string saveArchiveFilePath = chapter.GetArchiveFilePath();
|
||||||
|
|
||||||
|
//Check if Publication Directory already exists
|
||||||
|
string directoryPath = Path.GetDirectoryName(saveArchiveFilePath)!;
|
||||||
|
if (!Directory.Exists(directoryPath))
|
||||||
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||||
|
Directory.CreateDirectory(directoryPath,
|
||||||
|
UserRead | UserWrite | UserExecute | GroupRead | GroupWrite | GroupExecute );
|
||||||
|
else
|
||||||
|
Directory.CreateDirectory(directoryPath);
|
||||||
|
|
||||||
|
if (File.Exists(saveArchiveFilePath)) //Don't download twice. Redownload
|
||||||
|
File.Delete(saveArchiveFilePath);
|
||||||
|
|
||||||
|
//Create a temporary folder to store images
|
||||||
|
string tempFolder = Directory.CreateTempSubdirectory("trangatemp").FullName;
|
||||||
|
|
||||||
|
int chapterNum = 0;
|
||||||
|
//Download all Images to temporary Folder
|
||||||
|
if (imageUrls.Length == 0)
|
||||||
|
{
|
||||||
|
Directory.Delete(tempFolder, true);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (string imageUrl in imageUrls)
|
||||||
|
{
|
||||||
|
string extension = imageUrl.Split('.')[^1].Split('?')[0];
|
||||||
|
string imagePath = Path.Join(tempFolder, $"{chapterNum++}.{extension}");
|
||||||
|
bool status = DownloadImage(imageUrl, imagePath);
|
||||||
|
if (status is false)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
CopyCoverFromCacheToDownloadLocation();
|
||||||
|
|
||||||
|
File.WriteAllText(Path.Join(tempFolder, "ComicInfo.xml"), chapter.GetComicInfoXmlString());
|
||||||
|
|
||||||
|
//ZIP-it and ship-it
|
||||||
|
ZipFile.CreateFromDirectory(tempFolder, saveArchiveFilePath);
|
||||||
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||||
|
File.SetUnixFileMode(saveArchiveFilePath, UserRead | UserWrite | UserExecute | GroupRead | GroupWrite | GroupExecute | OtherRead | OtherExecute);
|
||||||
|
Directory.Delete(tempFolder, true); //Cleanup
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ProcessImage(string imagePath)
|
||||||
|
{
|
||||||
|
if (!TrangaSettings.bwImages && TrangaSettings.compression == 100)
|
||||||
|
return;
|
||||||
|
DateTime start = DateTime.Now;
|
||||||
|
using Image image = Image.Load(imagePath);
|
||||||
|
File.Delete(imagePath);
|
||||||
|
if(TrangaSettings.bwImages)
|
||||||
|
image.Mutate(i => i.ApplyProcessor(new AdaptiveThresholdProcessor()));
|
||||||
|
image.SaveAsJpeg(imagePath, new JpegEncoder()
|
||||||
|
{
|
||||||
|
Quality = TrangaSettings.compression
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CopyCoverFromCacheToDownloadLocation(int? retries = 1)
|
||||||
|
{
|
||||||
|
//Check if Publication already has a Folder and cover
|
||||||
|
string publicationFolder = Chapter.ParentManga.CreatePublicationFolder();
|
||||||
|
DirectoryInfo dirInfo = new (publicationFolder);
|
||||||
|
if (dirInfo.EnumerateFiles().Any(info => info.Name.Contains("cover", StringComparison.InvariantCultureIgnoreCase)))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
string? fileInCache = Chapter.ParentManga.CoverFileNameInCache;
|
||||||
|
if (fileInCache is null || !File.Exists(fileInCache))
|
||||||
|
{
|
||||||
|
if (retries > 0 && Chapter.ParentManga.CoverUrl is not null)
|
||||||
|
{
|
||||||
|
Chapter.ParentManga.SaveCoverImageToCache();
|
||||||
|
CopyCoverFromCacheToDownloadLocation(--retries);
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
string newFilePath = Path.Join(publicationFolder, $"cover.{Path.GetFileName(fileInCache).Split('.')[^1]}" );
|
||||||
|
File.Copy(fileInCache, newFilePath, true);
|
||||||
|
if(RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||||
|
File.SetUnixFileMode(newFilePath, GroupRead | GroupWrite | UserRead | UserWrite);
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool DownloadImage(string imageUrl, string savePath)
|
||||||
|
{
|
||||||
|
HttpDownloadClient downloadClient = new();
|
||||||
|
RequestResult requestResult = downloadClient.MakeRequest(imageUrl, RequestType.MangaImage);
|
||||||
|
|
||||||
|
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
||||||
|
return false;
|
||||||
|
if (requestResult.result == Stream.Null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
FileStream fs = new (savePath, FileMode.Create);
|
||||||
|
requestResult.result.CopyTo(fs);
|
||||||
|
fs.Close();
|
||||||
|
ProcessImage(savePath);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
22
API/Schema/Jobs/DownloadNewChaptersJob.cs
Normal file
22
API/Schema/Jobs/DownloadNewChaptersJob.cs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using API.Schema.MangaConnectors;
|
||||||
|
|
||||||
|
namespace API.Schema.Jobs;
|
||||||
|
|
||||||
|
public class DownloadNewChaptersJob(ulong recurrenceMs, string mangaId, string? parentJobId = null, ICollection<string>? dependsOnJobsIds = null)
|
||||||
|
: Job(TokenGen.CreateToken(typeof(DownloadNewChaptersJob), 64), JobType.DownloadNewChaptersJob, recurrenceMs, parentJobId, dependsOnJobsIds)
|
||||||
|
{
|
||||||
|
[MaxLength(64)]
|
||||||
|
public string MangaId { get; init; } = mangaId;
|
||||||
|
public Manga? Manga { get; init; }
|
||||||
|
|
||||||
|
protected override IEnumerable<Job> RunInternal(PgsqlContext context)
|
||||||
|
{
|
||||||
|
Manga m = Manga ?? context.Manga.Find(MangaId)!;
|
||||||
|
MangaConnector connector = m.MangaConnector ?? context.MangaConnectors.Find(m.MangaConnectorId)!;
|
||||||
|
Chapter[] newChapters = connector.GetNewChapters(m);
|
||||||
|
context.Chapters.AddRangeAsync(newChapters).Wait();
|
||||||
|
context.SaveChangesAsync().Wait();
|
||||||
|
return newChapters.Select(chapter => new DownloadSingleChapterJob(chapter.ChapterId, this.JobId));
|
||||||
|
}
|
||||||
|
}
|
138
API/Schema/Jobs/DownloadSingleChapterJob.cs
Normal file
138
API/Schema/Jobs/DownloadSingleChapterJob.cs
Normal file
@ -0,0 +1,138 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.IO.Compression;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using API.MangaDownloadClients;
|
||||||
|
using API.Schema.MangaConnectors;
|
||||||
|
using SixLabors.ImageSharp;
|
||||||
|
using SixLabors.ImageSharp.Formats.Jpeg;
|
||||||
|
using SixLabors.ImageSharp.Processing;
|
||||||
|
using SixLabors.ImageSharp.Processing.Processors.Binarization;
|
||||||
|
using static System.IO.UnixFileMode;
|
||||||
|
|
||||||
|
namespace API.Schema.Jobs;
|
||||||
|
|
||||||
|
public class DownloadSingleChapterJob(string chapterId, string? parentJobId = null, ICollection<string>? dependsOnJobsIds = null)
|
||||||
|
: Job(TokenGen.CreateToken(typeof(DownloadSingleChapterJob), 64), JobType.DownloadSingleChapterJob, 0, parentJobId, dependsOnJobsIds)
|
||||||
|
{
|
||||||
|
[MaxLength(64)]
|
||||||
|
public string ChapterId { get; init; } = chapterId;
|
||||||
|
public Chapter? Chapter { get; init; }
|
||||||
|
|
||||||
|
protected override IEnumerable<Job> RunInternal(PgsqlContext context)
|
||||||
|
{
|
||||||
|
Chapter c = Chapter ?? context.Chapters.Find(ChapterId)!;
|
||||||
|
Manga m = c.ParentManga ?? context.Manga.Find(c.ParentMangaId)!;
|
||||||
|
MangaConnector connector = m.MangaConnector ?? context.MangaConnectors.Find(m.MangaConnectorId)!;
|
||||||
|
DownloadChapterImages(c, connector, m);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool DownloadChapterImages(Chapter chapter, MangaConnector connector, Manga manga)
|
||||||
|
{
|
||||||
|
string[] imageUrls = connector.GetChapterImageUrls(chapter);
|
||||||
|
string saveArchiveFilePath = chapter.GetArchiveFilePath();
|
||||||
|
|
||||||
|
//Check if Publication Directory already exists
|
||||||
|
string directoryPath = Path.GetDirectoryName(saveArchiveFilePath)!;
|
||||||
|
if (!Directory.Exists(directoryPath))
|
||||||
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||||
|
Directory.CreateDirectory(directoryPath,
|
||||||
|
UserRead | UserWrite | UserExecute | GroupRead | GroupWrite | GroupExecute );
|
||||||
|
else
|
||||||
|
Directory.CreateDirectory(directoryPath);
|
||||||
|
|
||||||
|
if (File.Exists(saveArchiveFilePath)) //Don't download twice. Redownload
|
||||||
|
File.Delete(saveArchiveFilePath);
|
||||||
|
|
||||||
|
//Create a temporary folder to store images
|
||||||
|
string tempFolder = Directory.CreateTempSubdirectory("trangatemp").FullName;
|
||||||
|
|
||||||
|
int chapterNum = 0;
|
||||||
|
//Download all Images to temporary Folder
|
||||||
|
if (imageUrls.Length == 0)
|
||||||
|
{
|
||||||
|
Directory.Delete(tempFolder, true);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (string imageUrl in imageUrls)
|
||||||
|
{
|
||||||
|
string extension = imageUrl.Split('.')[^1].Split('?')[0];
|
||||||
|
string imagePath = Path.Join(tempFolder, $"{chapterNum++}.{extension}");
|
||||||
|
bool status = DownloadImage(imageUrl, imagePath);
|
||||||
|
if (status is false)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
CopyCoverFromCacheToDownloadLocation(manga);
|
||||||
|
|
||||||
|
File.WriteAllText(Path.Join(tempFolder, "ComicInfo.xml"), chapter.GetComicInfoXmlString());
|
||||||
|
|
||||||
|
//ZIP-it and ship-it
|
||||||
|
ZipFile.CreateFromDirectory(tempFolder, saveArchiveFilePath);
|
||||||
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||||
|
File.SetUnixFileMode(saveArchiveFilePath, UserRead | UserWrite | UserExecute | GroupRead | GroupWrite | GroupExecute | OtherRead | OtherExecute);
|
||||||
|
Directory.Delete(tempFolder, true); //Cleanup
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ProcessImage(string imagePath)
|
||||||
|
{
|
||||||
|
if (!TrangaSettings.bwImages && TrangaSettings.compression == 100)
|
||||||
|
return;
|
||||||
|
DateTime start = DateTime.Now;
|
||||||
|
using Image image = Image.Load(imagePath);
|
||||||
|
File.Delete(imagePath);
|
||||||
|
if(TrangaSettings.bwImages)
|
||||||
|
image.Mutate(i => i.ApplyProcessor(new AdaptiveThresholdProcessor()));
|
||||||
|
image.SaveAsJpeg(imagePath, new JpegEncoder()
|
||||||
|
{
|
||||||
|
Quality = TrangaSettings.compression
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CopyCoverFromCacheToDownloadLocation(Manga manga, int? retries = 1)
|
||||||
|
{
|
||||||
|
//Check if Publication already has a Folder and cover
|
||||||
|
string publicationFolder = manga.CreatePublicationFolder();
|
||||||
|
DirectoryInfo dirInfo = new (publicationFolder);
|
||||||
|
if (dirInfo.EnumerateFiles().Any(info => info.Name.Contains("cover", StringComparison.InvariantCultureIgnoreCase)))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
string? fileInCache = manga.CoverFileNameInCache;
|
||||||
|
if (fileInCache is null || !File.Exists(fileInCache))
|
||||||
|
{
|
||||||
|
if (retries > 0)
|
||||||
|
{
|
||||||
|
manga.SaveCoverImageToCache();
|
||||||
|
CopyCoverFromCacheToDownloadLocation(manga, --retries);
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
string newFilePath = Path.Join(publicationFolder, $"cover.{Path.GetFileName(fileInCache).Split('.')[^1]}" );
|
||||||
|
File.Copy(fileInCache, newFilePath, true);
|
||||||
|
if(RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||||
|
File.SetUnixFileMode(newFilePath, GroupRead | GroupWrite | UserRead | UserWrite);
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool DownloadImage(string imageUrl, string savePath)
|
||||||
|
{
|
||||||
|
HttpDownloadClient downloadClient = new();
|
||||||
|
RequestResult requestResult = downloadClient.MakeRequest(imageUrl, RequestType.MangaImage);
|
||||||
|
|
||||||
|
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
||||||
|
return false;
|
||||||
|
if (requestResult.result == Stream.Null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
FileStream fs = new (savePath, FileMode.Create);
|
||||||
|
requestResult.result.CopyTo(fs);
|
||||||
|
fs.Close();
|
||||||
|
ProcessImage(savePath);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
55
API/Schema/Jobs/Job.cs
Normal file
55
API/Schema/Jobs/Job.cs
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace API.Schema.Jobs;
|
||||||
|
|
||||||
|
[PrimaryKey("JobId")]
|
||||||
|
public abstract class Job
|
||||||
|
{
|
||||||
|
[MaxLength(64)]
|
||||||
|
public string JobId { get; init; }
|
||||||
|
|
||||||
|
[MaxLength(64)]
|
||||||
|
public string? ParentJobId { get; init; }
|
||||||
|
public Job? ParentJob { get; init; }
|
||||||
|
|
||||||
|
[MaxLength(64)]
|
||||||
|
public ICollection<string>? DependsOnJobsIds { get; init; }
|
||||||
|
public ICollection<Job>? DependsOnJobs { get; init; }
|
||||||
|
|
||||||
|
public JobType JobType { get; init; }
|
||||||
|
public ulong RecurrenceMs { get; set; }
|
||||||
|
public DateTime LastExecution { get; internal set; } = DateTime.UnixEpoch;
|
||||||
|
|
||||||
|
[NotMapped]
|
||||||
|
public DateTime NextExecution => LastExecution.AddMilliseconds(RecurrenceMs);
|
||||||
|
public JobState state { get; internal set; } = JobState.Waiting;
|
||||||
|
|
||||||
|
public Job(string jobId, JobType jobType, ulong recurrenceMs, Job? parentJob = null, ICollection<Job>? dependsOnJobs = null)
|
||||||
|
: this(jobId, jobType, recurrenceMs, parentJob?.JobId, dependsOnJobs?.Select(j => j.JobId).ToList())
|
||||||
|
{
|
||||||
|
this.ParentJob = parentJob;
|
||||||
|
this.DependsOnJobs = dependsOnJobs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Job(string jobId, JobType jobType, ulong recurrenceMs, string? parentJobId = null, ICollection<string>? dependsOnJobsIds = null)
|
||||||
|
{
|
||||||
|
JobId = jobId;
|
||||||
|
ParentJobId = parentJobId;
|
||||||
|
DependsOnJobsIds = dependsOnJobsIds;
|
||||||
|
JobType = jobType;
|
||||||
|
RecurrenceMs = recurrenceMs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<Job> Run(PgsqlContext context)
|
||||||
|
{
|
||||||
|
this.state = JobState.Running;
|
||||||
|
IEnumerable<Job> newJobs = RunInternal(context);
|
||||||
|
this.state = JobState.Completed;
|
||||||
|
return newJobs;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract IEnumerable<Job> RunInternal(PgsqlContext context);
|
||||||
|
}
|
29
API/Schema/Jobs/JobJsonDeserializer.cs
Normal file
29
API/Schema/Jobs/JobJsonDeserializer.cs
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
using JsonSerializer = Newtonsoft.Json.JsonSerializer;
|
||||||
|
|
||||||
|
namespace API.Schema.Jobs;
|
||||||
|
|
||||||
|
public class JobJsonDeserializer : JsonConverter<Job>
|
||||||
|
{
|
||||||
|
public override bool CanWrite { get; } = false;
|
||||||
|
|
||||||
|
public override void WriteJson(JsonWriter writer, Job? value, JsonSerializer serializer)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override Job? ReadJson(JsonReader reader, Type objectType, Job? existingValue, bool hasExistingValue, JsonSerializer serializer)
|
||||||
|
{
|
||||||
|
JObject j = JObject.Load(reader);
|
||||||
|
JobType? type = Enum.Parse<JobType>(j.GetValue("jobType")!.Value<string>()!);
|
||||||
|
return type switch
|
||||||
|
{
|
||||||
|
JobType.DownloadSingleChapterJob => j.ToObject<DownloadSingleChapterJob>(),
|
||||||
|
JobType.DownloadNewChaptersJob => j.ToObject<DownloadNewChaptersJob>(),
|
||||||
|
JobType.UpdateMetaDataJob => j.ToObject<UpdateMetadataJob>(),
|
||||||
|
JobType.MoveFileOrFolderJob => j.ToObject<MoveFileOrFolderJob>(),
|
||||||
|
_ => null
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
8
API/Schema/Jobs/JobState.cs
Normal file
8
API/Schema/Jobs/JobState.cs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
namespace API.Schema.Jobs;
|
||||||
|
|
||||||
|
public enum JobState
|
||||||
|
{
|
||||||
|
Waiting,
|
||||||
|
Running,
|
||||||
|
Completed
|
||||||
|
}
|
11
API/Schema/Jobs/JobType.cs
Normal file
11
API/Schema/Jobs/JobType.cs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
namespace API.Schema.Jobs;
|
||||||
|
|
||||||
|
|
||||||
|
public enum JobType : byte
|
||||||
|
{
|
||||||
|
DownloadSingleChapterJob = 0,
|
||||||
|
DownloadNewChaptersJob = 1,
|
||||||
|
UpdateMetaDataJob = 2,
|
||||||
|
MoveFileOrFolderJob = 3,
|
||||||
|
DownloadMangaCoverJob = 4
|
||||||
|
}
|
13
API/Schema/Jobs/MoveFileOrFolderJob.cs
Normal file
13
API/Schema/Jobs/MoveFileOrFolderJob.cs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
namespace API.Schema.Jobs;
|
||||||
|
|
||||||
|
public class MoveFileOrFolderJob(string fromLocation, string toLocation, string? parentJobId = null, ICollection<string>? dependsOnJobsIds = null)
|
||||||
|
: Job(TokenGen.CreateToken(typeof(MoveFileOrFolderJob), 64), JobType.MoveFileOrFolderJob, 0, parentJobId, dependsOnJobsIds)
|
||||||
|
{
|
||||||
|
public string FromLocation { get; init; } = fromLocation;
|
||||||
|
public string ToLocation { get; init; } = toLocation;
|
||||||
|
|
||||||
|
protected override IEnumerable<Job> RunInternal(PgsqlContext context)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
16
API/Schema/Jobs/UpdateMetadataJob.cs
Normal file
16
API/Schema/Jobs/UpdateMetadataJob.cs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace API.Schema.Jobs;
|
||||||
|
|
||||||
|
public class UpdateMetadataJob(ulong recurrenceMs, string mangaId, string? parentJobId = null, ICollection<string>? dependsOnJobsIds = null)
|
||||||
|
: Job(TokenGen.CreateToken(typeof(UpdateMetadataJob), 64), JobType.UpdateMetaDataJob, recurrenceMs, parentJobId, dependsOnJobsIds)
|
||||||
|
{
|
||||||
|
[MaxLength(64)]
|
||||||
|
public string MangaId { get; init; } = mangaId;
|
||||||
|
public virtual Manga Manga { get; init; }
|
||||||
|
|
||||||
|
protected override IEnumerable<Job> RunInternal(PgsqlContext context)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
@ -1,22 +1,21 @@
|
|||||||
using System.Text.Json.Nodes;
|
using System.Text.Json;
|
||||||
using Logging;
|
using System.Text.Json.Nodes;
|
||||||
using Newtonsoft.Json;
|
|
||||||
using JsonSerializer = System.Text.Json.JsonSerializer;
|
|
||||||
|
|
||||||
namespace Tranga.LibraryManagers;
|
namespace API.Schema.LibraryConnectors;
|
||||||
|
|
||||||
public class Kavita : LibraryManager
|
public class Kavita : LibraryConnector
|
||||||
{
|
{
|
||||||
|
|
||||||
public Kavita(string baseUrl, string username, string password, Logger? logger) : base(baseUrl, GetToken(baseUrl, username, password), logger, LibraryType.Kavita)
|
public Kavita(string baseUrl, string auth) : base(TokenGen.CreateToken(typeof(Kavita), 64), LibraryType.Kavita, baseUrl, auth)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
[JsonConstructor]
|
public Kavita(string baseUrl, string username, string password) :
|
||||||
public Kavita(string baseUrl, string auth, Logger? logger) : base(baseUrl, auth, logger, LibraryType.Kavita)
|
this(baseUrl, GetToken(baseUrl, username, password))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static string GetToken(string baseUrl, string username, string password)
|
private static string GetToken(string baseUrl, string username, string password)
|
||||||
{
|
{
|
||||||
HttpClient client = new()
|
HttpClient client = new()
|
||||||
@ -32,19 +31,37 @@ public class Kavita : LibraryManager
|
|||||||
RequestUri = new Uri($"{baseUrl}/api/Account/login"),
|
RequestUri = new Uri($"{baseUrl}/api/Account/login"),
|
||||||
Content = new StringContent($"{{\"username\":\"{username}\",\"password\":\"{password}\"}}", System.Text.Encoding.UTF8, "application/json")
|
Content = new StringContent($"{{\"username\":\"{username}\",\"password\":\"{password}\"}}", System.Text.Encoding.UTF8, "application/json")
|
||||||
};
|
};
|
||||||
|
try
|
||||||
HttpResponseMessage response = client.Send(requestMessage);
|
{
|
||||||
JsonObject? result = JsonSerializer.Deserialize<JsonObject>(response.Content.ReadAsStream());
|
HttpResponseMessage response = client.Send(requestMessage);
|
||||||
if (result is not null)
|
if (response.IsSuccessStatusCode)
|
||||||
return result!["token"]!.GetValue<string>();
|
{
|
||||||
else return "";
|
JsonObject? result = JsonSerializer.Deserialize<JsonObject>(response.Content.ReadAsStream());
|
||||||
|
if (result is not null)
|
||||||
|
return result["token"]!.GetValue<string>();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (HttpRequestException e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void UpdateLibrary()
|
protected override void UpdateLibraryInternal()
|
||||||
{
|
{
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Updating Libraries");
|
|
||||||
foreach (KavitaLibrary lib in GetLibraries())
|
foreach (KavitaLibrary lib in GetLibraries())
|
||||||
NetClient.MakePost($"{baseUrl}/api/Library/scan?libraryId={lib.id}", "Bearer", auth, logger);
|
NetClient.MakePost($"{BaseUrl}/api/Library/scan?libraryId={lib.id}", "Bearer", Auth);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal override bool Test()
|
||||||
|
{
|
||||||
|
foreach (KavitaLibrary lib in GetLibraries())
|
||||||
|
if (NetClient.MakePost($"{BaseUrl}/api/Library/scan?libraryId={lib.id}", "Bearer", Auth))
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -53,27 +70,26 @@ public class Kavita : LibraryManager
|
|||||||
/// <returns>Array of KavitaLibrary</returns>
|
/// <returns>Array of KavitaLibrary</returns>
|
||||||
private IEnumerable<KavitaLibrary> GetLibraries()
|
private IEnumerable<KavitaLibrary> GetLibraries()
|
||||||
{
|
{
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Getting Libraries");
|
Stream data = NetClient.MakeRequest($"{BaseUrl}/api/Library/libraries", "Bearer", Auth);
|
||||||
Stream data = NetClient.MakeRequest($"{baseUrl}/api/Library", "Bearer", auth, logger);
|
|
||||||
if (data == Stream.Null)
|
if (data == Stream.Null)
|
||||||
{
|
{
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"No libraries returned");
|
|
||||||
return Array.Empty<KavitaLibrary>();
|
return Array.Empty<KavitaLibrary>();
|
||||||
}
|
}
|
||||||
JsonArray? result = JsonSerializer.Deserialize<JsonArray>(data);
|
JsonArray? result = JsonSerializer.Deserialize<JsonArray>(data);
|
||||||
if (result is null)
|
if (result is null)
|
||||||
{
|
{
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"No libraries returned");
|
|
||||||
return Array.Empty<KavitaLibrary>();
|
return Array.Empty<KavitaLibrary>();
|
||||||
}
|
}
|
||||||
|
|
||||||
HashSet<KavitaLibrary> ret = new();
|
List<KavitaLibrary> ret = new();
|
||||||
|
|
||||||
foreach (JsonNode? jsonNode in result)
|
foreach (JsonNode? jsonNode in result)
|
||||||
{
|
{
|
||||||
var jObject = (JsonObject?)jsonNode;
|
JsonObject? jObject = (JsonObject?)jsonNode;
|
||||||
|
if(jObject is null)
|
||||||
|
continue;
|
||||||
int libraryId = jObject!["id"]!.GetValue<int>();
|
int libraryId = jObject!["id"]!.GetValue<int>();
|
||||||
string libraryName = jObject!["name"]!.GetValue<string>();
|
string libraryName = jObject["name"]!.GetValue<string>();
|
||||||
ret.Add(new KavitaLibrary(libraryId, libraryName));
|
ret.Add(new KavitaLibrary(libraryId, libraryName));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,6 +99,7 @@ public class Kavita : LibraryManager
|
|||||||
private struct KavitaLibrary
|
private struct KavitaLibrary
|
||||||
{
|
{
|
||||||
public int id { get; }
|
public int id { get; }
|
||||||
|
// ReSharper disable once UnusedAutoPropertyAccessor.Local
|
||||||
public string name { get; }
|
public string name { get; }
|
||||||
|
|
||||||
public KavitaLibrary(int id, string name)
|
public KavitaLibrary(int id, string name)
|
74
API/Schema/LibraryConnectors/Komga.cs
Normal file
74
API/Schema/LibraryConnectors/Komga.cs
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Nodes;
|
||||||
|
|
||||||
|
namespace API.Schema.LibraryConnectors;
|
||||||
|
|
||||||
|
public class Komga : LibraryConnector
|
||||||
|
{
|
||||||
|
public Komga(string baseUrl, string auth) : base(TokenGen.CreateToken(typeof(Komga), 64), LibraryType.Komga,
|
||||||
|
baseUrl, auth)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public Komga(string baseUrl, string username, string password)
|
||||||
|
: this(baseUrl, Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes($"{username}:{password}")))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void UpdateLibraryInternal()
|
||||||
|
{
|
||||||
|
foreach (KomgaLibrary lib in GetLibraries())
|
||||||
|
NetClient.MakePost($"{BaseUrl}/api/v1/libraries/{lib.id}/scan", "Basic", Auth);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal override bool Test()
|
||||||
|
{
|
||||||
|
foreach (KomgaLibrary lib in GetLibraries())
|
||||||
|
if (NetClient.MakePost($"{BaseUrl}/api/v1/libraries/{lib.id}/scan", "Basic", Auth))
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Fetches all libraries available to the user
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Array of KomgaLibraries</returns>
|
||||||
|
private IEnumerable<KomgaLibrary> GetLibraries()
|
||||||
|
{
|
||||||
|
Stream data = NetClient.MakeRequest($"{BaseUrl}/api/v1/libraries", "Basic", Auth);
|
||||||
|
if (data == Stream.Null)
|
||||||
|
{
|
||||||
|
return Array.Empty<KomgaLibrary>();
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
18
API/Schema/LibraryConnectors/LibraryConnector.cs
Normal file
18
API/Schema/LibraryConnectors/LibraryConnector.cs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace API.Schema.LibraryConnectors;
|
||||||
|
|
||||||
|
[PrimaryKey("LibraryConnectorId")]
|
||||||
|
public abstract class LibraryConnector(string libraryConnectorId, LibraryType libraryType, string baseUrl, string auth)
|
||||||
|
{
|
||||||
|
[MaxLength(64)]
|
||||||
|
public string LibraryConnectorId { get; } = libraryConnectorId;
|
||||||
|
|
||||||
|
public LibraryType LibraryType { get; init; } = libraryType;
|
||||||
|
public string BaseUrl { get; init; } = baseUrl;
|
||||||
|
public string Auth { get; init; } = auth;
|
||||||
|
|
||||||
|
protected abstract void UpdateLibraryInternal();
|
||||||
|
internal abstract bool Test();
|
||||||
|
}
|
7
API/Schema/LibraryConnectors/LibraryType.cs
Normal file
7
API/Schema/LibraryConnectors/LibraryType.cs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
namespace API.Schema.LibraryConnectors;
|
||||||
|
|
||||||
|
public enum LibraryType : byte
|
||||||
|
{
|
||||||
|
Komga = 0,
|
||||||
|
Kavita = 1
|
||||||
|
}
|
69
API/Schema/LibraryConnectors/NetClient.cs
Normal file
69
API/Schema/LibraryConnectors/NetClient.cs
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
using System.Net;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
|
|
||||||
|
namespace API.Schema.LibraryConnectors;
|
||||||
|
|
||||||
|
public class NetClient
|
||||||
|
{
|
||||||
|
public static Stream MakeRequest(string url, string authScheme, string auth)
|
||||||
|
{
|
||||||
|
HttpClient client = new();
|
||||||
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(authScheme, auth);
|
||||||
|
|
||||||
|
HttpRequestMessage requestMessage = new ()
|
||||||
|
{
|
||||||
|
Method = HttpMethod.Get,
|
||||||
|
RequestUri = new Uri(url)
|
||||||
|
};
|
||||||
|
try
|
||||||
|
{
|
||||||
|
|
||||||
|
HttpResponseMessage response = client.Send(requestMessage);
|
||||||
|
|
||||||
|
if (response.StatusCode is HttpStatusCode.Unauthorized &&
|
||||||
|
response.RequestMessage!.RequestUri!.AbsoluteUri != url)
|
||||||
|
return MakeRequest(response.RequestMessage!.RequestUri!.AbsoluteUri, authScheme, auth);
|
||||||
|
else if (response.IsSuccessStatusCode)
|
||||||
|
return response.Content.ReadAsStream();
|
||||||
|
else
|
||||||
|
return Stream.Null;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
switch (e)
|
||||||
|
{
|
||||||
|
case HttpRequestException:
|
||||||
|
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
return Stream.Null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool MakePost(string url, string authScheme, string auth)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
|
||||||
|
if(response.StatusCode is HttpStatusCode.Unauthorized && response.RequestMessage!.RequestUri!.AbsoluteUri != url)
|
||||||
|
return MakePost(response.RequestMessage!.RequestUri!.AbsoluteUri, authScheme, auth);
|
||||||
|
else if (response.IsSuccessStatusCode)
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
20
API/Schema/Link.cs
Normal file
20
API/Schema/Link.cs
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace API.Schema;
|
||||||
|
|
||||||
|
[PrimaryKey("LinkId")]
|
||||||
|
public class Link(string linkProvider, string linkUrl)
|
||||||
|
{
|
||||||
|
[MaxLength(64)]
|
||||||
|
public string LinkId { get; init; } = TokenGen.CreateToken(typeof(Link), 64);
|
||||||
|
public string LinkProvider { get; init; } = linkProvider;
|
||||||
|
public string LinkUrl { get; init; } = linkUrl;
|
||||||
|
|
||||||
|
public override bool Equals(object? obj)
|
||||||
|
{
|
||||||
|
if (obj is not Link other)
|
||||||
|
return false;
|
||||||
|
return other.LinkProvider == LinkProvider && other.LinkUrl == LinkUrl;
|
||||||
|
}
|
||||||
|
}
|
130
API/Schema/Manga.cs
Normal file
130
API/Schema/Manga.cs
Normal file
@ -0,0 +1,130 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using API.MangaDownloadClients;
|
||||||
|
using API.Schema.Jobs;
|
||||||
|
using API.Schema.MangaConnectors;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using static System.IO.UnixFileMode;
|
||||||
|
|
||||||
|
namespace API.Schema;
|
||||||
|
|
||||||
|
[PrimaryKey("MangaId")]
|
||||||
|
public class Manga
|
||||||
|
{
|
||||||
|
[MaxLength(64)]
|
||||||
|
public string MangaId { get; init; } = TokenGen.CreateToken(typeof(Manga), 64);
|
||||||
|
[MaxLength(64)]
|
||||||
|
public string ConnectorId { get; init; }
|
||||||
|
|
||||||
|
public string Name { get; internal set; }
|
||||||
|
public string Description { get; internal set; }
|
||||||
|
public string WebsiteUrl { get; internal set; }
|
||||||
|
public string CoverUrl { get; internal set; }
|
||||||
|
public string? CoverFileNameInCache { get; internal set; }
|
||||||
|
public uint Year { get; internal set; }
|
||||||
|
public string? OriginalLanguage { get; internal set; }
|
||||||
|
public MangaReleaseStatus ReleaseStatus { get; internal set; }
|
||||||
|
public string FolderName { get; private set; }
|
||||||
|
public float IgnoreChapterBefore { get; internal set; }
|
||||||
|
|
||||||
|
public string MangaConnectorId { get; private set; }
|
||||||
|
public MangaConnector? MangaConnector { get; private set; }
|
||||||
|
|
||||||
|
public ICollection<Author>? Authors { get; internal set; }
|
||||||
|
|
||||||
|
public ICollection<MangaTag>? Tags { get; internal set; }
|
||||||
|
|
||||||
|
public ICollection<Link>? Links { get; internal set; }
|
||||||
|
|
||||||
|
public ICollection<MangaAltTitle>? AltTitles { get; internal set; }
|
||||||
|
|
||||||
|
public Manga(string connectorId, string name, string description, string websiteUrl, string coverUrl,
|
||||||
|
string? coverFileNameInCache, uint year, string? originalLanguage, MangaReleaseStatus releaseStatus,
|
||||||
|
float ignoreChapterBefore, MangaConnector mangaConnector, ICollection<Author> authors,
|
||||||
|
ICollection<MangaTag> tags, ICollection<Link> links, ICollection<MangaAltTitle> altTitles)
|
||||||
|
: this(connectorId, name, description, websiteUrl, coverUrl, coverFileNameInCache, year, originalLanguage,
|
||||||
|
releaseStatus, ignoreChapterBefore, mangaConnector.Name)
|
||||||
|
{
|
||||||
|
this.Authors = authors;
|
||||||
|
this.Tags = tags;
|
||||||
|
this.Links = links;
|
||||||
|
this.AltTitles = altTitles;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Manga(string connectorId, string name, string description, string websiteUrl, string coverUrl,
|
||||||
|
string? coverFileNameInCache, uint year, string? originalLanguage, MangaReleaseStatus releaseStatus,
|
||||||
|
float ignoreChapterBefore, string mangaConnectorId)
|
||||||
|
{
|
||||||
|
ConnectorId = connectorId;
|
||||||
|
Name = name;
|
||||||
|
Description = description;
|
||||||
|
WebsiteUrl = websiteUrl;
|
||||||
|
CoverUrl = coverUrl;
|
||||||
|
CoverFileNameInCache = coverFileNameInCache;
|
||||||
|
Year = year;
|
||||||
|
OriginalLanguage = originalLanguage;
|
||||||
|
ReleaseStatus = releaseStatus;
|
||||||
|
IgnoreChapterBefore = ignoreChapterBefore;
|
||||||
|
MangaConnectorId = mangaConnectorId;
|
||||||
|
FolderName = BuildFolderName(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MoveFileOrFolderJob UpdateFolderName(string downloadLocation, string newName)
|
||||||
|
{
|
||||||
|
string oldName = this.FolderName;
|
||||||
|
this.FolderName = newName;
|
||||||
|
return new MoveFileOrFolderJob(Path.Join(downloadLocation, oldName), Path.Join(downloadLocation, this.FolderName));
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void UpdateWithInfo(Manga other)
|
||||||
|
{
|
||||||
|
this.Name = other.Name;
|
||||||
|
this.Year = other.Year;
|
||||||
|
this.Description = other.Description;
|
||||||
|
this.CoverUrl = other.CoverUrl;
|
||||||
|
this.OriginalLanguage = other.OriginalLanguage;
|
||||||
|
this.Authors = other.Authors;
|
||||||
|
this.Links = other.Links;
|
||||||
|
this.Tags = other.Tags;
|
||||||
|
this.AltTitles = other.AltTitles;
|
||||||
|
this.ReleaseStatus = other.ReleaseStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string BuildFolderName(string mangaName)
|
||||||
|
{
|
||||||
|
return mangaName;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal string SaveCoverImageToCache()
|
||||||
|
{
|
||||||
|
Regex urlRex = new (@"https?:\/\/((?:[a-zA-Z0-9-]+\.)+[a-zA-Z0-9]+)\/(?:.+\/)*(.+\.([a-zA-Z]+))");
|
||||||
|
//https?:\/\/[a-zA-Z0-9-]+\.([a-zA-Z0-9-]+\.[a-zA-Z0-9]+)\/(?:.+\/)*(.+\.([a-zA-Z]+)) for only second level domains
|
||||||
|
Match match = urlRex.Match(CoverUrl);
|
||||||
|
string filename = $"{match.Groups[1].Value}-{MangaId}.{match.Groups[3].Value}";
|
||||||
|
string saveImagePath = Path.Join(TrangaSettings.coverImageCache, filename);
|
||||||
|
|
||||||
|
if (File.Exists(saveImagePath))
|
||||||
|
return saveImagePath;
|
||||||
|
|
||||||
|
RequestResult coverResult = new HttpDownloadClient().MakeRequest(CoverUrl, RequestType.MangaCover);
|
||||||
|
using MemoryStream ms = new();
|
||||||
|
coverResult.result.CopyTo(ms);
|
||||||
|
Directory.CreateDirectory(TrangaSettings.coverImageCache);
|
||||||
|
File.WriteAllBytes(saveImagePath, ms.ToArray());
|
||||||
|
return saveImagePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string CreatePublicationFolder()
|
||||||
|
{
|
||||||
|
string publicationFolder = Path.Join(TrangaSettings.downloadLocation, 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO onchanges create job to update metadata files in archives, etc.
|
||||||
|
}
|
15
API/Schema/MangaAltTitle.cs
Normal file
15
API/Schema/MangaAltTitle.cs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace API.Schema;
|
||||||
|
|
||||||
|
[PrimaryKey("AltTitleId")]
|
||||||
|
public class MangaAltTitle(string language, string title)
|
||||||
|
{
|
||||||
|
[MaxLength(64)]
|
||||||
|
public string AltTitleId { get; init; } = TokenGen.CreateToken("AltTitle", 64);
|
||||||
|
[MaxLength(8)]
|
||||||
|
public string Language { get; init; } = language;
|
||||||
|
public string Title { get; set; } = title;
|
||||||
|
}
|
192
API/Schema/MangaConnectors/AsuraToon.cs
Normal file
192
API/Schema/MangaConnectors/AsuraToon.cs
Normal file
@ -0,0 +1,192 @@
|
|||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using API.MangaDownloadClients;
|
||||||
|
using HtmlAgilityPack;
|
||||||
|
|
||||||
|
namespace API.Schema.MangaConnectors;
|
||||||
|
|
||||||
|
public class AsuraToon : MangaConnector
|
||||||
|
{
|
||||||
|
|
||||||
|
public AsuraToon() : base("AsuraToon", ["en"], ["https://asuracomic.net"])
|
||||||
|
{
|
||||||
|
this.downloadClient = new ChromiumDownloadClient();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override (Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)[] GetManga(string publicationTitle = "")
|
||||||
|
{
|
||||||
|
string sanitizedTitle = string.Join(' ', Regex.Matches(publicationTitle, "[A-z]*").Where(m => m.Value.Length > 0)).ToLower();
|
||||||
|
string requestUrl = $"https://asuracomic.net/series?name={sanitizedTitle}";
|
||||||
|
RequestResult requestResult =
|
||||||
|
downloadClient.MakeRequest(requestUrl, RequestType.Default);
|
||||||
|
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
||||||
|
return [];
|
||||||
|
|
||||||
|
if (requestResult.htmlDocument is null)
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
(Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)[] publications = ParsePublicationsFromHtml(requestResult.htmlDocument);
|
||||||
|
return publications;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override (Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)? GetMangaFromId(string publicationId)
|
||||||
|
{
|
||||||
|
return GetMangaFromUrl($"https://asuracomic.net/series/{publicationId}");
|
||||||
|
}
|
||||||
|
|
||||||
|
public override (Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)? GetMangaFromUrl(string url)
|
||||||
|
{
|
||||||
|
RequestResult requestResult = downloadClient.MakeRequest(url, RequestType.MangaInfo);
|
||||||
|
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
||||||
|
return null;
|
||||||
|
if (requestResult.htmlDocument is null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return ParseSinglePublicationFromHtml(requestResult.htmlDocument, url.Split('/')[^1], url);
|
||||||
|
}
|
||||||
|
|
||||||
|
private (Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)[] ParsePublicationsFromHtml(HtmlDocument document)
|
||||||
|
{
|
||||||
|
HtmlNodeCollection mangaList = document.DocumentNode.SelectNodes("//a[starts-with(@href,'series')]");
|
||||||
|
if (mangaList is null || mangaList.Count < 1)
|
||||||
|
return [];
|
||||||
|
|
||||||
|
IEnumerable<string> urls = mangaList.Select(a => $"https://asuracomic.net/{a.GetAttributeValue("href", "")}");
|
||||||
|
|
||||||
|
List<(Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)> ret = new();
|
||||||
|
foreach (string url in urls)
|
||||||
|
{
|
||||||
|
(Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)? manga = GetMangaFromUrl(url);
|
||||||
|
if (manga is { } x)
|
||||||
|
ret.Add(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
private (Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?) ParseSinglePublicationFromHtml(HtmlDocument document, string publicationId, string websiteUrl)
|
||||||
|
{
|
||||||
|
string? originalLanguage = null;
|
||||||
|
Dictionary<string, string> altTitles = new(), links = new();
|
||||||
|
|
||||||
|
HtmlNodeCollection genreNodes = document.DocumentNode.SelectNodes("//h3[text()='Genres']/../div/button");
|
||||||
|
string[] tags = genreNodes.Select(b => b.InnerText).ToArray();
|
||||||
|
List<MangaTag> mangaTags = tags.Select(t => new MangaTag(t)).ToList();
|
||||||
|
|
||||||
|
HtmlNode statusNode = document.DocumentNode.SelectSingleNode("//h3[text()='Status']/../h3[2]");
|
||||||
|
MangaReleaseStatus releaseStatus = statusNode.InnerText.ToLower() switch
|
||||||
|
{
|
||||||
|
"ongoing" => MangaReleaseStatus.Continuing,
|
||||||
|
"hiatus" => MangaReleaseStatus.OnHiatus,
|
||||||
|
"completed" => MangaReleaseStatus.Completed,
|
||||||
|
"dropped" => MangaReleaseStatus.Cancelled,
|
||||||
|
"season end" => MangaReleaseStatus.Continuing,
|
||||||
|
"coming soon" => MangaReleaseStatus.Unreleased,
|
||||||
|
_ => MangaReleaseStatus.Unreleased
|
||||||
|
};
|
||||||
|
|
||||||
|
HtmlNode coverNode =
|
||||||
|
document.DocumentNode.SelectSingleNode("//img[@alt='poster']");
|
||||||
|
string coverUrl = coverNode.GetAttributeValue("src", "");
|
||||||
|
|
||||||
|
HtmlNode titleNode =
|
||||||
|
document.DocumentNode.SelectSingleNode("//title");
|
||||||
|
string sortName = Regex.Match(titleNode.InnerText, @"(.*) - Asura Scans").Groups[1].Value;
|
||||||
|
|
||||||
|
HtmlNode descriptionNode =
|
||||||
|
document.DocumentNode.SelectSingleNode("//h3[starts-with(text(),'Synopsis')]/../span");
|
||||||
|
string description = descriptionNode?.InnerText??"";
|
||||||
|
|
||||||
|
HtmlNodeCollection authorNodes = document.DocumentNode.SelectNodes("//h3[text()='Author']/../h3[not(text()='Author' or text()='_')]");
|
||||||
|
HtmlNodeCollection artistNodes = document.DocumentNode.SelectNodes("//h3[text()='Artist']/../h3[not(text()='Artist' or text()='_')]");
|
||||||
|
IEnumerable<string> authorNames = authorNodes is null ? [] : authorNodes.Select(a => a.InnerText);
|
||||||
|
IEnumerable<string> artistNames = artistNodes is null ? [] : artistNodes.Select(a => a.InnerText);
|
||||||
|
List<string> authorStrings = authorNames.Concat(artistNames).ToList();
|
||||||
|
List<Author> authors = authorStrings.Select(author => new Author(author)).ToList();
|
||||||
|
|
||||||
|
HtmlNode? firstChapterNode = document.DocumentNode.SelectSingleNode("//a[contains(@href, 'chapter/1')]/../following-sibling::h3");
|
||||||
|
uint year = uint.Parse(firstChapterNode?.InnerText.Split(' ')[^1] ?? "2000");
|
||||||
|
|
||||||
|
Manga manga = new (publicationId, sortName, description, websiteUrl, coverUrl, null, year,
|
||||||
|
originalLanguage, releaseStatus, -1,
|
||||||
|
this,
|
||||||
|
authors,
|
||||||
|
mangaTags,
|
||||||
|
[],
|
||||||
|
[]);
|
||||||
|
|
||||||
|
return (manga, authors, mangaTags, [], []);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override Chapter[] GetChapters(Manga manga, string language="en")
|
||||||
|
{
|
||||||
|
string requestUrl = $"https://asuracomic.net/series/{manga.MangaId}";
|
||||||
|
// Leaving this in for verification if the page exists
|
||||||
|
RequestResult requestResult =
|
||||||
|
downloadClient.MakeRequest(requestUrl, RequestType.Default);
|
||||||
|
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
||||||
|
return [];
|
||||||
|
|
||||||
|
//Return Chapters ordered by Chapter-Number
|
||||||
|
List<Chapter> chapters = ParseChaptersFromHtml(manga, requestUrl);
|
||||||
|
return chapters.Order().ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Chapter> ParseChaptersFromHtml(Manga manga, string mangaUrl)
|
||||||
|
{
|
||||||
|
RequestResult result = downloadClient.MakeRequest(mangaUrl, RequestType.Default);
|
||||||
|
if ((int)result.statusCode < 200 || (int)result.statusCode >= 300 || result.htmlDocument is null)
|
||||||
|
{
|
||||||
|
return new List<Chapter>();
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Chapter> ret = new();
|
||||||
|
|
||||||
|
HtmlNodeCollection chapterURLNodes = result.htmlDocument.DocumentNode.SelectNodes("//a[contains(@href, '/chapter/')]");
|
||||||
|
Regex infoRex = new(@"Chapter ([0-9]+)(.*)?");
|
||||||
|
|
||||||
|
foreach (HtmlNode chapterInfo in chapterURLNodes)
|
||||||
|
{
|
||||||
|
string chapterUrl = chapterInfo.GetAttributeValue("href", "");
|
||||||
|
|
||||||
|
Match match = infoRex.Match(chapterInfo.InnerText);
|
||||||
|
if(!ChapterNumber.CanParse(match.Groups[1].Value))
|
||||||
|
continue;
|
||||||
|
ChapterNumber chapterNumber = new(match.Groups[1].Value);
|
||||||
|
string? chapterName = match.Groups[2].Success && match.Groups[2].Length > 1 ? match.Groups[2].Value : null;
|
||||||
|
string url = $"https://asuracomic.net/series/{chapterUrl}";
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ret.Add(new Chapter(manga, url, chapterNumber, null, chapterName));
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal override string[] GetChapterImageUrls(Chapter chapter)
|
||||||
|
{
|
||||||
|
string requestUrl = chapter.Url;
|
||||||
|
// Leaving this in to check if the page exists
|
||||||
|
RequestResult requestResult =
|
||||||
|
downloadClient.MakeRequest(requestUrl, RequestType.Default);
|
||||||
|
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300 || requestResult.htmlDocument is null)
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
string[] imageUrls = ParseImageUrlsFromHtml(requestResult.htmlDocument);
|
||||||
|
return imageUrls;
|
||||||
|
}
|
||||||
|
|
||||||
|
private string[] ParseImageUrlsFromHtml(HtmlDocument document)
|
||||||
|
{
|
||||||
|
HtmlNodeCollection images = document.DocumentNode.SelectNodes("//img[contains(@alt, 'chapter page')]");
|
||||||
|
|
||||||
|
return images.Select(i => i.GetAttributeValue("src", "")).ToArray();
|
||||||
|
}
|
||||||
|
}
|
205
API/Schema/MangaConnectors/Bato.cs
Normal file
205
API/Schema/MangaConnectors/Bato.cs
Normal file
@ -0,0 +1,205 @@
|
|||||||
|
using System.Net;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using API.MangaDownloadClients;
|
||||||
|
using HtmlAgilityPack;
|
||||||
|
|
||||||
|
namespace API.Schema.MangaConnectors;
|
||||||
|
|
||||||
|
public class Bato : MangaConnector
|
||||||
|
{
|
||||||
|
|
||||||
|
public Bato() : base("Bato", ["en"], ["bato.to"])
|
||||||
|
{
|
||||||
|
this.downloadClient = new HttpDownloadClient();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override (Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)[] GetManga(string publicationTitle = "")
|
||||||
|
{
|
||||||
|
string sanitizedTitle = string.Join(' ', Regex.Matches(publicationTitle, "[A-z]*").Where(m => m.Value.Length > 0)).ToLower();
|
||||||
|
string requestUrl = $"https://bato.to/v3x-search?word={sanitizedTitle}&lang=en";
|
||||||
|
RequestResult requestResult =
|
||||||
|
downloadClient.MakeRequest(requestUrl, RequestType.Default);
|
||||||
|
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
||||||
|
return [];
|
||||||
|
|
||||||
|
if (requestResult.htmlDocument is null)
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
(Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)[] publications = ParsePublicationsFromHtml(requestResult.htmlDocument);
|
||||||
|
return publications;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override (Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)? GetMangaFromId(string publicationId)
|
||||||
|
{
|
||||||
|
return GetMangaFromUrl($"https://bato.to/title/{publicationId}");
|
||||||
|
}
|
||||||
|
|
||||||
|
public override (Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)? GetMangaFromUrl(string url)
|
||||||
|
{
|
||||||
|
RequestResult requestResult = downloadClient.MakeRequest(url, RequestType.MangaInfo);
|
||||||
|
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
||||||
|
return null;
|
||||||
|
if (requestResult.htmlDocument is null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return ParseSinglePublicationFromHtml(requestResult.htmlDocument, url.Split('/')[^1], url);
|
||||||
|
}
|
||||||
|
|
||||||
|
private (Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)[] ParsePublicationsFromHtml(HtmlDocument document)
|
||||||
|
{
|
||||||
|
HtmlNode mangaList = document.DocumentNode.SelectSingleNode("//div[@data-hk='0-0-2']");
|
||||||
|
if (!mangaList.ChildNodes.Any(node => node.Name == "div"))
|
||||||
|
return [];
|
||||||
|
|
||||||
|
List<string> urls = mangaList.ChildNodes
|
||||||
|
.Select(node => $"https://bato.to{node.Descendants("div").First().FirstChild.GetAttributeValue("href", "")}").ToList();
|
||||||
|
|
||||||
|
HashSet<(Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)> ret = new();
|
||||||
|
foreach (string url in urls)
|
||||||
|
{
|
||||||
|
(Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)? manga = GetMangaFromUrl(url);
|
||||||
|
if (manga is { } x)
|
||||||
|
ret.Add(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
private (Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?) ParseSinglePublicationFromHtml(HtmlDocument document, string publicationId, string websiteUrl)
|
||||||
|
{
|
||||||
|
HtmlNode infoNode = document.DocumentNode.SelectSingleNode("/html/body/div/main/div[1]/div[2]");
|
||||||
|
|
||||||
|
string sortName = infoNode.Descendants("h3").First().InnerText;
|
||||||
|
string description = document.DocumentNode
|
||||||
|
.SelectSingleNode("//div[contains(concat(' ',normalize-space(@class),' '),'prose')]").InnerText;
|
||||||
|
|
||||||
|
string[] altTitlesList = infoNode.ChildNodes[1].ChildNodes[2].InnerText.Split('/');
|
||||||
|
int i = 0;
|
||||||
|
List<MangaAltTitle> altTitles = altTitlesList.Select(a => new MangaAltTitle(i++.ToString(), a)).ToList();
|
||||||
|
|
||||||
|
string coverUrl = document.DocumentNode.SelectNodes("//img")
|
||||||
|
.First(child => child.GetAttributeValue("data-hk", "") == "0-1-0").GetAttributeValue("src", "").Replace("&", "&");
|
||||||
|
|
||||||
|
List<HtmlNode> genreNodes = document.DocumentNode.SelectSingleNode("//b[text()='Genres:']/..").SelectNodes("span").ToList();
|
||||||
|
string[] tags = genreNodes.Select(node => node.FirstChild.InnerText).ToArray();
|
||||||
|
List<MangaTag> mangaTags = tags.Select(s => new MangaTag(s)).ToList();
|
||||||
|
|
||||||
|
List<HtmlNode> authorsNodes = infoNode.ChildNodes[1].ChildNodes[3].Descendants("a").ToList();
|
||||||
|
List<string> authorNames = authorsNodes.Select(node => node.InnerText.Replace("amp;", "")).ToList();
|
||||||
|
List<Author> authors = authorNames.Select(n => new Author(n)).ToList();
|
||||||
|
|
||||||
|
HtmlNode? originalLanguageNode = document.DocumentNode.SelectSingleNode("//span[text()='Tr From']/..");
|
||||||
|
string originalLanguage = originalLanguageNode is not null ? originalLanguageNode.LastChild.InnerText : "";
|
||||||
|
|
||||||
|
if (!uint.TryParse(
|
||||||
|
document.DocumentNode.SelectSingleNode("//span[text()='Original Publication:']/..").LastChild.InnerText.Split('-')[0],
|
||||||
|
out uint year))
|
||||||
|
year = (uint)DateTime.Now.Year;
|
||||||
|
|
||||||
|
string status = document.DocumentNode.SelectSingleNode("//span[text()='Original Publication:']/..")
|
||||||
|
.ChildNodes[2].InnerText;
|
||||||
|
MangaReleaseStatus releaseStatus = MangaReleaseStatus.Unreleased;
|
||||||
|
switch (status.ToLower())
|
||||||
|
{
|
||||||
|
case "ongoing": releaseStatus = MangaReleaseStatus.Continuing; break;
|
||||||
|
case "completed": releaseStatus = MangaReleaseStatus.Completed; break;
|
||||||
|
case "hiatus": releaseStatus = MangaReleaseStatus.OnHiatus; break;
|
||||||
|
case "cancelled": releaseStatus = MangaReleaseStatus.Cancelled; break;
|
||||||
|
case "pending": releaseStatus = MangaReleaseStatus.Unreleased; break;
|
||||||
|
}
|
||||||
|
|
||||||
|
Manga manga = new (publicationId, sortName, description, websiteUrl, coverUrl, null, year,
|
||||||
|
originalLanguage, releaseStatus, -1,
|
||||||
|
this,
|
||||||
|
authors,
|
||||||
|
mangaTags,
|
||||||
|
[],
|
||||||
|
altTitles);
|
||||||
|
|
||||||
|
return (manga, authors, mangaTags, [], altTitles);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override Chapter[] GetChapters(Manga manga, string language="en")
|
||||||
|
{
|
||||||
|
string requestUrl = $"https://bato.to/title/{manga.MangaId}";
|
||||||
|
// Leaving this in for verification if the page exists
|
||||||
|
RequestResult requestResult =
|
||||||
|
downloadClient.MakeRequest(requestUrl, RequestType.Default);
|
||||||
|
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
||||||
|
return [];
|
||||||
|
|
||||||
|
//Return Chapters ordered by Chapter-Number
|
||||||
|
List<Chapter> chapters = ParseChaptersFromHtml(manga, requestUrl);
|
||||||
|
return chapters.Order().ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Chapter> ParseChaptersFromHtml(Manga manga, string mangaUrl)
|
||||||
|
{
|
||||||
|
RequestResult result = downloadClient.MakeRequest(mangaUrl, RequestType.Default);
|
||||||
|
if ((int)result.statusCode < 200 || (int)result.statusCode >= 300 || result.htmlDocument is null)
|
||||||
|
{
|
||||||
|
return new List<Chapter>();
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Chapter> ret = new();
|
||||||
|
|
||||||
|
HtmlNode chapterList =
|
||||||
|
result.htmlDocument.DocumentNode.SelectSingleNode("/html/body/div/main/div[3]/astro-island/div/div[2]/div/div/astro-slot");
|
||||||
|
|
||||||
|
Regex numberRex = new(@"\/title\/.+\/([0-9])+(?:-vol_([0-9]+))?-ch_([0-9\.]+)");
|
||||||
|
|
||||||
|
foreach (HtmlNode chapterInfo in chapterList.SelectNodes("div"))
|
||||||
|
{
|
||||||
|
HtmlNode infoNode = chapterInfo.FirstChild.FirstChild;
|
||||||
|
string chapterUrl = infoNode.GetAttributeValue("href", "");
|
||||||
|
|
||||||
|
Match match = numberRex.Match(chapterUrl);
|
||||||
|
string id = match.Groups[1].Value;
|
||||||
|
int? volumeNumber = match.Groups[2].Success ? int.Parse(match.Groups[2].Value) : null;
|
||||||
|
if(ChapterNumber.CanParse(match.Groups[3].Value))
|
||||||
|
continue;
|
||||||
|
ChapterNumber chapterNumber = new(match.Groups[3].Value);
|
||||||
|
string url = $"https://bato.to{chapterUrl}?load=2";
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ret.Add(new Chapter(manga, url, chapterNumber, volumeNumber, null));
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal override string[] GetChapterImageUrls(Chapter chapter)
|
||||||
|
{
|
||||||
|
string requestUrl = chapter.Url;
|
||||||
|
// Leaving this in to check if the page exists
|
||||||
|
RequestResult requestResult =
|
||||||
|
downloadClient.MakeRequest(requestUrl, RequestType.Default);
|
||||||
|
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300 || requestResult.htmlDocument is null)
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
string[] imageUrls = ParseImageUrlsFromHtml(requestResult.htmlDocument);
|
||||||
|
return imageUrls;
|
||||||
|
}
|
||||||
|
|
||||||
|
private string[] ParseImageUrlsFromHtml(HtmlDocument document)
|
||||||
|
{
|
||||||
|
HtmlNode images = document.DocumentNode.SelectNodes("//astro-island").First(node =>
|
||||||
|
node.GetAttributeValue("component-url", "").Contains("/_astro/ImageList."));
|
||||||
|
|
||||||
|
string weirdString = images.OuterHtml;
|
||||||
|
string weirdString2 = Regex.Match(weirdString, @"props=\""(.*)}\""").Groups[1].Value;
|
||||||
|
string[] urls = Regex.Matches(weirdString2, @"(https:\/\/[A-z\-0-9\.\?\&\;\=\/]+)\\")
|
||||||
|
.Select(match => match.Groups[1].Value.Replace("&", "&")).ToArray();
|
||||||
|
|
||||||
|
return urls;
|
||||||
|
}
|
||||||
|
}
|
39
API/Schema/MangaConnectors/MangaConnector.cs
Normal file
39
API/Schema/MangaConnectors/MangaConnector.cs
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using API.MangaDownloadClients;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace API.Schema.MangaConnectors;
|
||||||
|
|
||||||
|
[PrimaryKey("Name")]
|
||||||
|
public abstract class MangaConnector(string name, string[] supportedLanguages, string[] baseUris)
|
||||||
|
{
|
||||||
|
[MaxLength(32)]
|
||||||
|
public string Name { get; init; } = name;
|
||||||
|
public string[] SupportedLanguages { get; init; } = supportedLanguages;
|
||||||
|
public string[] BaseUris { get; init; } = baseUris;
|
||||||
|
|
||||||
|
public abstract (Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)[] GetManga(string publicationTitle = "");
|
||||||
|
|
||||||
|
public abstract (Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)? GetMangaFromUrl(string url);
|
||||||
|
|
||||||
|
public abstract (Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)? GetMangaFromId(string publicationId);
|
||||||
|
|
||||||
|
public abstract Chapter[] GetChapters(Manga manga, string language="en");
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
|
[NotMapped]
|
||||||
|
internal DownloadClient downloadClient { get; init; } = null!;
|
||||||
|
|
||||||
|
public Chapter[] GetNewChapters(Manga manga)
|
||||||
|
{
|
||||||
|
Chapter[] allChapters = GetChapters(manga);
|
||||||
|
if (allChapters.Length < 1)
|
||||||
|
return [];
|
||||||
|
|
||||||
|
return allChapters.Where(chapter => !chapter.IsDownloaded()).ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
internal abstract string[] GetChapterImageUrls(Chapter chapter);
|
||||||
|
}
|
281
API/Schema/MangaConnectors/MangaDex.cs
Normal file
281
API/Schema/MangaConnectors/MangaDex.cs
Normal file
@ -0,0 +1,281 @@
|
|||||||
|
using System.Net;
|
||||||
|
using System.Text.Json.Nodes;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using API.MangaDownloadClients;
|
||||||
|
using JsonSerializer = System.Text.Json.JsonSerializer;
|
||||||
|
|
||||||
|
namespace API.Schema.MangaConnectors;
|
||||||
|
|
||||||
|
public class MangaDex : MangaConnector
|
||||||
|
{
|
||||||
|
//https://api.mangadex.org/docs/3-enumerations/#language-codes--localization
|
||||||
|
//https://en.wikipedia.org/wiki/List_of_ISO_639_language_codes
|
||||||
|
//https://gist.github.com/Josantonius/b455e315bc7f790d14b136d61d9ae469
|
||||||
|
public MangaDex() : base("MangaDex", ["en","pt","pt-br","it","de","ru","aa","ab","ae","af","ak","am","an","ar-ae","ar-bh","ar-dz","ar-eg","ar-iq","ar-jo","ar-kw","ar-lb","ar-ly","ar-ma","ar-om","ar-qa","ar-sa","ar-sy","ar-tn","ar-ye","ar","as","av","ay","az","ba","be","bg","bh","bi","bm","bn","bo","br","bs","ca","ce","ch","co","cr","cs","cu","cv","cy","da","de-at","de-ch","de-de","de-li","de-lu","div","dv","dz","ee","el","en-au","en-bz","en-ca","en-cb","en-gb","en-ie","en-jm","en-nz","en-ph","en-tt","en-us","en-za","en-zw","eo","es-ar","es-bo","es-cl","es-co","es-cr","es-do","es-ec","es-es","es-gt","es-hn","es-la","es-mx","es-ni","es-pa","es-pe","es-pr","es-py","es-sv","es-us","es-uy","es-ve","es","et","eu","fa","ff","fi","fj","fo","fr-be","fr-ca","fr-ch","fr-fr","fr-lu","fr-mc","fr","fy","ga","gd","gl","gn","gu","gv","ha","he","hi","ho","hr-ba","hr-hr","hr","ht","hu","hy","hz","ia","id","ie","ig","ii","ik","in","io","is","it-ch","it-it","iu","iw","ja","ja-ro","ji","jv","jw","ka","kg","ki","kj","kk","kl","km","kn","ko","ko-ro","kr","ks","ku","kv","kw","ky","kz","la","lb","lg","li","ln","lo","ls","lt","lu","lv","mg","mh","mi","mk","ml","mn","mo","mr","ms-bn","ms-my","ms","mt","my","na","nb","nd","ne","ng","nl-be","nl-nl","nl","nn","no","nr","ns","nv","ny","oc","oj","om","or","os","pa","pi","pl","ps","pt-pt","qu-bo","qu-ec","qu-pe","qu","rm","rn","ro","rw","sa","sb","sc","sd","se-fi","se-no","se-se","se","sg","sh","si","sk","sl","sm","sn","so","sq","sr-ba","sr-sp","sr","ss","st","su","sv-fi","sv-se","sv","sw","sx","syr","ta","te","tg","th","ti","tk","tl","tn","to","tr","ts","tt","tw","ty","ug","uk","ur","us","uz","ve","vi","vo","wa","wo","xh","yi","yo","za","zh-cn","zh-hk","zh-mo","zh-ro","zh-sg","zh-tw","zh","zu"], ["mangadex.org"])
|
||||||
|
{
|
||||||
|
this.downloadClient = new HttpDownloadClient();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override (Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)[] GetManga(string 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<(Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)> retManga = new();
|
||||||
|
int loadedPublicationData = 0;
|
||||||
|
List<JsonNode> results = new();
|
||||||
|
|
||||||
|
//Request all search-results
|
||||||
|
while (offset < total) //As long as we haven't requested all "Pages"
|
||||||
|
{
|
||||||
|
//Request next Page
|
||||||
|
RequestResult requestResult = downloadClient.MakeRequest(
|
||||||
|
$"https://api.mangadex.org/manga?limit={limit}&title={publicationTitle}&offset={offset}" +
|
||||||
|
$"&contentRating%5B%5D=safe&contentRating%5B%5D=suggestive&contentRating%5B%5D=erotica" +
|
||||||
|
$"&contentRating%5B%5D=pornographic" +
|
||||||
|
$"&includes%5B%5D=manga&includes%5B%5D=cover_art&includes%5B%5D=author" +
|
||||||
|
$"&includes%5B%5D=artist&includes%5B%5D=tag", RequestType.MangaInfo);
|
||||||
|
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
||||||
|
break;
|
||||||
|
JsonObject? result = JsonSerializer.Deserialize<JsonObject>(requestResult.result);
|
||||||
|
|
||||||
|
offset += limit;
|
||||||
|
if (result is null)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if(result.ContainsKey("total"))
|
||||||
|
total = result["total"]!.GetValue<int>(); //Update the total number of Publications
|
||||||
|
else continue;
|
||||||
|
|
||||||
|
if (result.ContainsKey("data"))
|
||||||
|
results.AddRange(result["data"]!.AsArray()!);//Manga-data-Array
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (JsonNode mangaNode in results)
|
||||||
|
{
|
||||||
|
if(MangaFromJsonObject(mangaNode.AsObject()) is { } manga)
|
||||||
|
retManga.Add(manga); //Add Publication (Manga) to result
|
||||||
|
}
|
||||||
|
return retManga.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override (Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)? GetMangaFromId(string publicationId)
|
||||||
|
{
|
||||||
|
RequestResult requestResult =
|
||||||
|
downloadClient.MakeRequest($"https://api.mangadex.org/manga/{publicationId}?includes%5B%5D=manga&includes%5B%5D=cover_art&includes%5B%5D=author&includes%5B%5D=artist&includes%5B%5D=tag", RequestType.MangaInfo);
|
||||||
|
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
||||||
|
return null;
|
||||||
|
JsonObject? result = JsonSerializer.Deserialize<JsonObject>(requestResult.result);
|
||||||
|
if(result is not null)
|
||||||
|
return MangaFromJsonObject(result["data"]!.AsObject());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override (Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)? GetMangaFromUrl(string url)
|
||||||
|
{
|
||||||
|
Regex idRex = new (@"https:\/\/mangadex.org\/title\/([A-z0-9-]*)\/.*");
|
||||||
|
string id = idRex.Match(url).Groups[1].Value;
|
||||||
|
return GetMangaFromId(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
private (Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)? MangaFromJsonObject(JsonObject manga)
|
||||||
|
{
|
||||||
|
if (!manga.TryGetPropertyValue("id", out JsonNode? idNode))
|
||||||
|
return null;
|
||||||
|
string publicationId = idNode!.GetValue<string>();
|
||||||
|
|
||||||
|
if (!manga.TryGetPropertyValue("attributes", out JsonNode? attributesNode))
|
||||||
|
return null;
|
||||||
|
JsonObject attributes = attributesNode!.AsObject();
|
||||||
|
|
||||||
|
if (!attributes.TryGetPropertyValue("title", out JsonNode? titleNode))
|
||||||
|
return null;
|
||||||
|
string sortName = titleNode!.AsObject().ContainsKey("en") switch
|
||||||
|
{
|
||||||
|
true => titleNode.AsObject()["en"]!.GetValue<string>(),
|
||||||
|
false => titleNode.AsObject().First().Value!.GetValue<string>()
|
||||||
|
};
|
||||||
|
|
||||||
|
Dictionary<string, string> altTitlesDict = new();
|
||||||
|
if (attributes.TryGetPropertyValue("altTitles", out JsonNode? altTitlesNode))
|
||||||
|
{
|
||||||
|
foreach (JsonNode? altTitleNode in altTitlesNode!.AsArray())
|
||||||
|
{
|
||||||
|
JsonObject altTitleNodeObject = altTitleNode!.AsObject();
|
||||||
|
altTitlesDict.TryAdd(altTitleNodeObject.First().Key, altTitleNodeObject.First().Value!.GetValue<string>());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
List<MangaAltTitle> altTitles = altTitlesDict.Select(t => new MangaAltTitle(t.Key, t.Value)).ToList();
|
||||||
|
|
||||||
|
if (!attributes.TryGetPropertyValue("description", out JsonNode? descriptionNode))
|
||||||
|
return null;
|
||||||
|
string description = descriptionNode!.AsObject().ContainsKey("en") switch
|
||||||
|
{
|
||||||
|
true => descriptionNode.AsObject()["en"]!.GetValue<string>(),
|
||||||
|
false => descriptionNode.AsObject().FirstOrDefault().Value?.GetValue<string>() ?? ""
|
||||||
|
};
|
||||||
|
|
||||||
|
Dictionary<string, string> linksDict = new();
|
||||||
|
if (attributes.TryGetPropertyValue("links", out JsonNode? linksNode) && linksNode is not null)
|
||||||
|
foreach (KeyValuePair<string, JsonNode?> linkKv in linksNode!.AsObject())
|
||||||
|
linksDict.TryAdd(linkKv.Key, linkKv.Value.GetValue<string>());
|
||||||
|
List<Link> links = linksDict.Select(x => new Link(x.Key, x.Value)).ToList();
|
||||||
|
|
||||||
|
string? originalLanguage =
|
||||||
|
attributes.TryGetPropertyValue("originalLanguage", out JsonNode? originalLanguageNode) switch
|
||||||
|
{
|
||||||
|
true => originalLanguageNode?.GetValue<string>(),
|
||||||
|
false => null
|
||||||
|
};
|
||||||
|
|
||||||
|
MangaReleaseStatus releaseStatus = MangaReleaseStatus.Unreleased;
|
||||||
|
if (attributes.TryGetPropertyValue("status", out JsonNode? statusNode))
|
||||||
|
{
|
||||||
|
releaseStatus = statusNode?.GetValue<string>().ToLower() switch
|
||||||
|
{
|
||||||
|
"ongoing" => MangaReleaseStatus.Continuing,
|
||||||
|
"completed" => MangaReleaseStatus.Completed,
|
||||||
|
"hiatus" => MangaReleaseStatus.OnHiatus,
|
||||||
|
"cancelled" => MangaReleaseStatus.Cancelled,
|
||||||
|
_ => MangaReleaseStatus.Unreleased
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
uint year = attributes.TryGetPropertyValue("year", out JsonNode? yearNode) switch
|
||||||
|
{
|
||||||
|
true => yearNode?.GetValue<uint>()??0,
|
||||||
|
false => 0
|
||||||
|
};
|
||||||
|
|
||||||
|
HashSet<string> tags = new(128);
|
||||||
|
if (attributes.TryGetPropertyValue("tags", out JsonNode? tagsNode))
|
||||||
|
foreach (JsonNode? tagNode in tagsNode!.AsArray())
|
||||||
|
tags.Add(tagNode!["attributes"]!["name"]!["en"]!.GetValue<string>());
|
||||||
|
List<MangaTag> mangaTags = tags.Select(t => new MangaTag(t)).ToList();
|
||||||
|
|
||||||
|
if (!manga.TryGetPropertyValue("relationships", out JsonNode? relationshipsNode))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
JsonNode? coverNode = relationshipsNode!.AsArray()
|
||||||
|
.FirstOrDefault(rel => rel!["type"]!.GetValue<string>().Equals("cover_art"));
|
||||||
|
if (coverNode is null)
|
||||||
|
return null;
|
||||||
|
string fileName = coverNode["attributes"]!["fileName"]!.GetValue<string>();
|
||||||
|
string coverUrl = $"https://uploads.mangadex.org/covers/{publicationId}/{fileName}";
|
||||||
|
|
||||||
|
List<string> authorNames = new();
|
||||||
|
JsonNode?[] authorNodes = relationshipsNode.AsArray()
|
||||||
|
.Where(rel => rel!["type"]!.GetValue<string>().Equals("author") || rel!["type"]!.GetValue<string>().Equals("artist")).ToArray();
|
||||||
|
foreach (JsonNode? authorNode in authorNodes)
|
||||||
|
{
|
||||||
|
string authorName = authorNode!["attributes"]!["name"]!.GetValue<string>();
|
||||||
|
if(!authorNames.Contains(authorName))
|
||||||
|
authorNames.Add(authorName);
|
||||||
|
}
|
||||||
|
List<Author> authors = authorNames.Select(a => new Author(a)).ToList();
|
||||||
|
|
||||||
|
Manga pub = new (publicationId, sortName, description, $"https://mangadex.org/title/{publicationId}", coverUrl, null, year,
|
||||||
|
originalLanguage, releaseStatus, -1,
|
||||||
|
this,
|
||||||
|
authors,
|
||||||
|
mangaTags,
|
||||||
|
links,
|
||||||
|
altTitles);
|
||||||
|
|
||||||
|
return (pub, authors, mangaTags, links, altTitles);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override Chapter[] GetChapters(Manga manga, string language="en")
|
||||||
|
{
|
||||||
|
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
|
||||||
|
List<Chapter> chapters = new();
|
||||||
|
//As long as we haven't requested all "Pages"
|
||||||
|
while (offset < total)
|
||||||
|
{
|
||||||
|
//Request next "Page"
|
||||||
|
RequestResult requestResult =
|
||||||
|
downloadClient.MakeRequest(
|
||||||
|
$"https://api.mangadex.org/manga/{manga.ConnectorId}/feed?limit={limit}&offset={offset}&translatedLanguage%5B%5D={language}&contentRating%5B%5D=safe&contentRating%5B%5D=suggestive&contentRating%5B%5D=erotica&contentRating%5B%5D=pornographic", RequestType.MangaDexFeed);
|
||||||
|
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
||||||
|
break;
|
||||||
|
JsonObject? result = JsonSerializer.Deserialize<JsonObject>(requestResult.result);
|
||||||
|
|
||||||
|
offset += limit;
|
||||||
|
if (result is null)
|
||||||
|
break;
|
||||||
|
|
||||||
|
total = result["total"]!.GetValue<int>();
|
||||||
|
JsonArray chaptersInResult = result["data"]!.AsArray();
|
||||||
|
//Loop through all Chapters in result and extract information from JSON
|
||||||
|
foreach (JsonNode? jsonNode in chaptersInResult)
|
||||||
|
{
|
||||||
|
JsonObject chapter = (JsonObject)jsonNode!;
|
||||||
|
JsonObject attributes = chapter["attributes"]!.AsObject();
|
||||||
|
|
||||||
|
string chapterId = chapter["id"]!.GetValue<string>();
|
||||||
|
string url = $"https://mangadex.org/chapter/{chapterId}";
|
||||||
|
|
||||||
|
string? title = attributes.ContainsKey("title") && attributes["title"] is not null
|
||||||
|
? attributes["title"]!.GetValue<string>()
|
||||||
|
: null;
|
||||||
|
|
||||||
|
int? volume = attributes.ContainsKey("volume") && attributes["volume"] is not null
|
||||||
|
? int.Parse(attributes["volume"]!.GetValue<string>())
|
||||||
|
: null;
|
||||||
|
|
||||||
|
string? chapterNumStr = attributes.ContainsKey("chapter") && attributes["chapter"] is not null
|
||||||
|
? attributes["chapter"]!.GetValue<string>()
|
||||||
|
: null;
|
||||||
|
|
||||||
|
if(chapterNumStr is null || ChapterNumber.CanParse(chapterNumStr))
|
||||||
|
continue;
|
||||||
|
ChapterNumber chapterNumber = new(chapterNumStr);
|
||||||
|
|
||||||
|
|
||||||
|
if (attributes.ContainsKey("pages") && attributes["pages"] is not null &&
|
||||||
|
attributes["pages"]!.GetValue<int>() < 1)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Chapter newChapter = new Chapter(manga, url, chapterNumber, volume, title);
|
||||||
|
if(!chapters.Contains(newChapter))
|
||||||
|
chapters.Add(newChapter);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Return Chapters ordered by Chapter-Number
|
||||||
|
return chapters.Order().ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
internal override string[] GetChapterImageUrls(Chapter chapter)
|
||||||
|
{//Request URLs for Chapter-Images
|
||||||
|
RequestResult requestResult =
|
||||||
|
downloadClient.MakeRequest($"https://api.mangadex.org/at-home/server/{chapter.ChapterId}?forcePort443=false", RequestType.MangaDexImage);
|
||||||
|
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
JsonObject? result = JsonSerializer.Deserialize<JsonObject>(requestResult.result);
|
||||||
|
if (result is null)
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
string baseUrl = result["baseUrl"]!.GetValue<string>();
|
||||||
|
string hash = result["chapter"]!["hash"]!.GetValue<string>();
|
||||||
|
JsonArray imageFileNames = result["chapter"]!["data"]!.AsArray();
|
||||||
|
//Loop through all imageNames and construct urls (imageUrl)
|
||||||
|
List<string> imageUrls = new();
|
||||||
|
foreach (JsonNode? image in imageFileNames)
|
||||||
|
imageUrls.Add($"{baseUrl}/data/{hash}/{image!.GetValue<string>()}");
|
||||||
|
return imageUrls.ToArray();
|
||||||
|
}
|
||||||
|
}
|
185
API/Schema/MangaConnectors/MangaHere.cs
Normal file
185
API/Schema/MangaConnectors/MangaHere.cs
Normal file
@ -0,0 +1,185 @@
|
|||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using API.MangaDownloadClients;
|
||||||
|
using HtmlAgilityPack;
|
||||||
|
|
||||||
|
namespace API.Schema.MangaConnectors;
|
||||||
|
|
||||||
|
public class MangaHere : MangaConnector
|
||||||
|
{
|
||||||
|
public MangaHere() : base("MangaHere", ["en"], ["www.mangahere.cc"])
|
||||||
|
{
|
||||||
|
this.downloadClient = new ChromiumDownloadClient();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override (Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)[] GetManga(string publicationTitle = "")
|
||||||
|
{
|
||||||
|
string sanitizedTitle = string.Join('+', Regex.Matches(publicationTitle, "[A-z]*").Where(str => str.Length > 0)).ToLower();
|
||||||
|
string requestUrl = $"https://www.mangahere.cc/search?title={sanitizedTitle}";
|
||||||
|
RequestResult requestResult =
|
||||||
|
downloadClient.MakeRequest(requestUrl, RequestType.Default);
|
||||||
|
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300 || requestResult.htmlDocument is null)
|
||||||
|
return [];
|
||||||
|
|
||||||
|
(Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)[] publications = ParsePublicationsFromHtml(requestResult.htmlDocument);
|
||||||
|
return publications;
|
||||||
|
}
|
||||||
|
|
||||||
|
private (Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)[] ParsePublicationsFromHtml(HtmlDocument document)
|
||||||
|
{
|
||||||
|
if (document.DocumentNode.SelectNodes("//div[contains(concat(' ',normalize-space(@class),' '),' container ')]").Any(node => node.ChildNodes.Any(cNode => cNode.HasClass("search-keywords"))))
|
||||||
|
return [];
|
||||||
|
|
||||||
|
List<string> urls = document.DocumentNode
|
||||||
|
.SelectNodes("//a[contains(@href, '/manga/') and not(contains(@href, '.html'))]")
|
||||||
|
.Select(thumb => $"https://www.mangahere.cc{thumb.GetAttributeValue("href", "")}").Distinct().ToList();
|
||||||
|
|
||||||
|
HashSet<(Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)> ret = new();
|
||||||
|
foreach (string url in urls)
|
||||||
|
{
|
||||||
|
(Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)? manga = GetMangaFromUrl(url);
|
||||||
|
if (manga is { } x)
|
||||||
|
ret.Add(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override (Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)? GetMangaFromId(string publicationId)
|
||||||
|
{
|
||||||
|
return GetMangaFromUrl($"https://www.mangahere.cc/manga/{publicationId}");
|
||||||
|
}
|
||||||
|
|
||||||
|
public override (Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)? GetMangaFromUrl(string url)
|
||||||
|
{
|
||||||
|
RequestResult requestResult =
|
||||||
|
downloadClient.MakeRequest(url, RequestType.MangaInfo);
|
||||||
|
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300 || requestResult.htmlDocument is null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
Regex idRex = new (@"https:\/\/www\.mangahere\.[a-z]{0,63}\/manga\/([0-9A-z\-]+).*");
|
||||||
|
string id = idRex.Match(url).Groups[1].Value;
|
||||||
|
return ParseSinglePublicationFromHtml(requestResult.htmlDocument, id, url);
|
||||||
|
}
|
||||||
|
|
||||||
|
private (Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?) ParseSinglePublicationFromHtml(HtmlDocument document, string publicationId, string websiteUrl)
|
||||||
|
{
|
||||||
|
string originalLanguage = "", status = "";
|
||||||
|
Dictionary<string, string> altTitles = new(), links = new();
|
||||||
|
MangaReleaseStatus releaseStatus = MangaReleaseStatus.Unreleased;
|
||||||
|
|
||||||
|
//We dont get posters, because same origin bs HtmlNode posterNode = document.DocumentNode.SelectSingleNode("//img[contains(concat(' ',normalize-space(@class),' '),' detail-info-cover-img ')]");
|
||||||
|
string coverUrl = "http://static.mangahere.cc/v20230914/mangahere/images/nopicture.jpg";
|
||||||
|
|
||||||
|
HtmlNode titleNode = document.DocumentNode.SelectSingleNode("//span[contains(concat(' ',normalize-space(@class),' '),' detail-info-right-title-font ')]");
|
||||||
|
string sortName = titleNode.InnerText;
|
||||||
|
|
||||||
|
List<string> authorNames = document.DocumentNode
|
||||||
|
.SelectNodes("//p[contains(concat(' ',normalize-space(@class),' '),' detail-info-right-say ')]/a")
|
||||||
|
.Select(node => node.InnerText)
|
||||||
|
.ToList();
|
||||||
|
List<Author> authors = authorNames.Select(n => new Author(n)).ToList();
|
||||||
|
|
||||||
|
HashSet<string> tags = document.DocumentNode
|
||||||
|
.SelectNodes("//p[contains(concat(' ',normalize-space(@class),' '),' detail-info-right-tag-list ')]/a")
|
||||||
|
.Select(node => node.InnerText)
|
||||||
|
.ToHashSet();
|
||||||
|
List<MangaTag> mangaTags = tags.Select(n => new MangaTag(n)).ToList();
|
||||||
|
|
||||||
|
status = document.DocumentNode.SelectSingleNode("//span[contains(concat(' ',normalize-space(@class),' '),' detail-info-right-title-tip ')]").InnerText;
|
||||||
|
switch (status.ToLower())
|
||||||
|
{
|
||||||
|
case "cancelled": releaseStatus = MangaReleaseStatus.Cancelled; break;
|
||||||
|
case "hiatus": releaseStatus = MangaReleaseStatus.OnHiatus; break;
|
||||||
|
case "discontinued": releaseStatus = MangaReleaseStatus.Cancelled; break;
|
||||||
|
case "complete": releaseStatus = MangaReleaseStatus.Completed; break;
|
||||||
|
case "ongoing": releaseStatus = MangaReleaseStatus.Continuing; break;
|
||||||
|
}
|
||||||
|
|
||||||
|
HtmlNode descriptionNode = document.DocumentNode
|
||||||
|
.SelectSingleNode("//p[contains(concat(' ',normalize-space(@class),' '),' fullcontent ')]");
|
||||||
|
string description = descriptionNode.InnerText;
|
||||||
|
|
||||||
|
Manga manga = new (publicationId, sortName, description, websiteUrl, coverUrl, null, 0,
|
||||||
|
originalLanguage, releaseStatus, -1,
|
||||||
|
this,
|
||||||
|
authors,
|
||||||
|
mangaTags,
|
||||||
|
[],
|
||||||
|
[]);
|
||||||
|
|
||||||
|
return (manga, authors, mangaTags, [], []);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override Chapter[] GetChapters(Manga manga, string language="en")
|
||||||
|
{
|
||||||
|
string requestUrl = $"https://www.mangahere.cc/manga/{manga.MangaId}";
|
||||||
|
RequestResult requestResult =
|
||||||
|
downloadClient.MakeRequest(requestUrl, RequestType.Default);
|
||||||
|
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300 || requestResult.htmlDocument is null)
|
||||||
|
return Array.Empty<Chapter>();
|
||||||
|
|
||||||
|
List<string> urls = requestResult.htmlDocument.DocumentNode.SelectNodes("//div[@id='list-1']/ul//li//a[contains(@href, '/manga/')]")
|
||||||
|
.Select(node => node.GetAttributeValue("href", "")).ToList();
|
||||||
|
Regex chapterRex = new(@".*\/manga\/[a-zA-Z0-9\-\._\~\!\$\&\'\(\)\*\+\,\;\=\:\@]+\/v([0-9(TBD)]+)\/c([0-9\.]+)\/.*");
|
||||||
|
|
||||||
|
List<Chapter> chapters = new();
|
||||||
|
foreach (string url in urls)
|
||||||
|
{
|
||||||
|
Match rexMatch = chapterRex.Match(url);
|
||||||
|
|
||||||
|
int? volumeNumber = rexMatch.Groups[1].Value == "TBD" ? null : int.Parse(rexMatch.Groups[1].Value);
|
||||||
|
if(!ChapterNumber.CanParse(rexMatch.Groups[2].Value))
|
||||||
|
continue;
|
||||||
|
ChapterNumber chapterNumber = new(rexMatch.Groups[2].Value);
|
||||||
|
string fullUrl = $"https://www.mangahere.cc{url}";
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
chapters.Add(new Chapter(manga, fullUrl, chapterNumber, volumeNumber, null));
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//Return Chapters ordered by Chapter-Number
|
||||||
|
return chapters.Order().ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
internal override string[] GetChapterImageUrls(Chapter chapter)
|
||||||
|
{
|
||||||
|
List<string> imageUrls = new();
|
||||||
|
|
||||||
|
int downloaded = 1;
|
||||||
|
int images = 1;
|
||||||
|
string url = string.Join('/', chapter.Url.Split('/')[..^1]);
|
||||||
|
do
|
||||||
|
{
|
||||||
|
RequestResult requestResult =
|
||||||
|
downloadClient.MakeRequest($"{url}/{downloaded}.html", RequestType.Default);
|
||||||
|
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300 || requestResult.htmlDocument is null)
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
imageUrls.AddRange(ParseImageUrlsFromHtml(requestResult.htmlDocument));
|
||||||
|
|
||||||
|
images = requestResult.htmlDocument.DocumentNode
|
||||||
|
.SelectNodes("//a[contains(@href, '/manga/')]")
|
||||||
|
.MaxBy(node => node.GetAttributeValue("data-page", 0))!.GetAttributeValue("data-page", 0);
|
||||||
|
} while (downloaded++ <= images);
|
||||||
|
|
||||||
|
return imageUrls.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
private string[] ParseImageUrlsFromHtml(HtmlDocument document)
|
||||||
|
{
|
||||||
|
return document.DocumentNode
|
||||||
|
.SelectNodes("//img[contains(concat(' ',normalize-space(@class),' '),' reader-main-img ')]")
|
||||||
|
.Select(node =>
|
||||||
|
{
|
||||||
|
string url = node.GetAttributeValue("src", "");
|
||||||
|
return url.StartsWith("//") ? $"https:{url}" : url;
|
||||||
|
})
|
||||||
|
.ToArray();
|
||||||
|
}
|
||||||
|
}
|
234
API/Schema/MangaConnectors/MangaKatana.cs
Normal file
234
API/Schema/MangaConnectors/MangaKatana.cs
Normal file
@ -0,0 +1,234 @@
|
|||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using API.MangaDownloadClients;
|
||||||
|
using HtmlAgilityPack;
|
||||||
|
|
||||||
|
namespace API.Schema.MangaConnectors;
|
||||||
|
|
||||||
|
public class MangaKatana : MangaConnector
|
||||||
|
{
|
||||||
|
public MangaKatana() : base("MangaKatana", ["en"], ["mangakatana.com"])
|
||||||
|
{
|
||||||
|
this.downloadClient = new HttpDownloadClient();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override (Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)[] GetManga(string publicationTitle = "")
|
||||||
|
{
|
||||||
|
string sanitizedTitle = string.Join("%20", Regex.Matches(publicationTitle, "[A-z]*").Where(m => m.Value.Length > 0)).ToLower();
|
||||||
|
string requestUrl = $"https://mangakatana.com/?search={sanitizedTitle}&search_by=book_name";
|
||||||
|
RequestResult requestResult =
|
||||||
|
downloadClient.MakeRequest(requestUrl, RequestType.Default);
|
||||||
|
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
||||||
|
return [];
|
||||||
|
|
||||||
|
// 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], requestResult.redirectedToUrl) };
|
||||||
|
}
|
||||||
|
|
||||||
|
(Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)[] publications = ParsePublicationsFromHtml(requestResult.result);
|
||||||
|
return publications;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override (Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)? GetMangaFromId(string publicationId)
|
||||||
|
{
|
||||||
|
return GetMangaFromUrl($"https://mangakatana.com/manga/{publicationId}");
|
||||||
|
}
|
||||||
|
|
||||||
|
public override (Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)? GetMangaFromUrl(string url)
|
||||||
|
{
|
||||||
|
RequestResult requestResult =
|
||||||
|
downloadClient.MakeRequest(url, RequestType.MangaInfo);
|
||||||
|
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
||||||
|
return null;
|
||||||
|
return ParseSinglePublicationFromHtml(requestResult.result, url.Split('/')[^1], url);
|
||||||
|
}
|
||||||
|
|
||||||
|
private (Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)[] 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 [];
|
||||||
|
List<string> urls = new();
|
||||||
|
foreach (HtmlNode mangaResult in searchResults)
|
||||||
|
{
|
||||||
|
urls.Add(mangaResult.Descendants("a").First().GetAttributes()
|
||||||
|
.First(a => a.Name == "href").Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
HashSet<(Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)> ret = new();
|
||||||
|
foreach (string url in urls)
|
||||||
|
{
|
||||||
|
(Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)? manga = GetMangaFromUrl(url);
|
||||||
|
if (manga is { } x)
|
||||||
|
ret.Add(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
private (Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?) ParseSinglePublicationFromHtml(Stream html, string publicationId, string websiteUrl)
|
||||||
|
{
|
||||||
|
StreamReader reader = new(html);
|
||||||
|
string htmlString = reader.ReadToEnd();
|
||||||
|
HtmlDocument document = new();
|
||||||
|
document.LoadHtml(htmlString);
|
||||||
|
Dictionary<string, string> altTitlesDict = new();
|
||||||
|
Dictionary<string, string>? links = null;
|
||||||
|
HashSet<string> tags = new();
|
||||||
|
string[] authorNames = [];
|
||||||
|
string originalLanguage = "";
|
||||||
|
MangaReleaseStatus releaseStatus = MangaReleaseStatus.Unreleased;
|
||||||
|
|
||||||
|
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++)
|
||||||
|
altTitlesDict.Add(i.ToString(), alts[i]);
|
||||||
|
break;
|
||||||
|
case "authorsartists":
|
||||||
|
authorNames = value.Split(',');
|
||||||
|
break;
|
||||||
|
case "status":
|
||||||
|
switch (value.ToLower())
|
||||||
|
{
|
||||||
|
case "ongoing": releaseStatus = MangaReleaseStatus.Continuing; break;
|
||||||
|
case "completed": releaseStatus = MangaReleaseStatus.Completed; break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "genres":
|
||||||
|
tags = row.SelectNodes("div").Last().Descendants("a").Select(a => a.InnerText).ToHashSet();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
string coverUrl = document.DocumentNode.SelectSingleNode("//*[@id='single_book']/div[1]/div").Descendants("img").First()
|
||||||
|
.GetAttributes().First(a => a.Name == "src").Value;
|
||||||
|
|
||||||
|
string description = document.DocumentNode.SelectSingleNode("//*[@id='single_book']/div[3]/p").InnerText;
|
||||||
|
while (description.StartsWith('\n'))
|
||||||
|
description = description.Substring(1);
|
||||||
|
|
||||||
|
uint year = (uint)DateTime.Now.Year;
|
||||||
|
string yearString = infoTable.Descendants("div").First(d => d.HasClass("updateAt"))
|
||||||
|
.InnerText.Split('-')[^1];
|
||||||
|
|
||||||
|
if(yearString.Contains("ago") == false)
|
||||||
|
{
|
||||||
|
year = uint.Parse(yearString);
|
||||||
|
}
|
||||||
|
List<Author> authors = authorNames.Select(n => new Author(n)).ToList();
|
||||||
|
List<MangaTag> mangaTags = tags.Select(n => new MangaTag(n)).ToList();
|
||||||
|
List<MangaAltTitle> altTitles = altTitlesDict.Select(x => new MangaAltTitle(x.Key, x.Value)).ToList();
|
||||||
|
|
||||||
|
Manga manga = new (publicationId, sortName, description, websiteUrl, coverUrl, null, year,
|
||||||
|
originalLanguage, releaseStatus, -1,
|
||||||
|
this,
|
||||||
|
authors,
|
||||||
|
mangaTags,
|
||||||
|
[],
|
||||||
|
altTitles);
|
||||||
|
|
||||||
|
return (manga, authors, mangaTags, [], altTitles);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override Chapter[] GetChapters(Manga manga, string language="en")
|
||||||
|
{
|
||||||
|
string requestUrl = $"https://mangakatana.com/manga/{manga.MangaId}";
|
||||||
|
// Leaving this in for verification if the page exists
|
||||||
|
RequestResult requestResult =
|
||||||
|
downloadClient.MakeRequest(requestUrl, RequestType.Default);
|
||||||
|
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
||||||
|
return Array.Empty<Chapter>();
|
||||||
|
|
||||||
|
//Return Chapters ordered by Chapter-Number
|
||||||
|
List<Chapter> chapters = ParseChaptersFromHtml(manga, requestUrl);
|
||||||
|
return chapters.Order().ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Chapter> ParseChaptersFromHtml(Manga manga, 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");
|
||||||
|
|
||||||
|
Regex volumeRex = new(@"[0-9a-z\-\.]+\/[0-9a-z\-]*v([0-9\.]+)");
|
||||||
|
Regex chapterNumRex = new(@"[0-9a-z\-\.]+\/[0-9a-z\-]*c([0-9\.]+)");
|
||||||
|
Regex chapterNameRex = new(@"Chapter [0-9\.]+:? (.*)");
|
||||||
|
|
||||||
|
foreach (HtmlNode chapterInfo in chapterList.Descendants("tr"))
|
||||||
|
{
|
||||||
|
string fullString = chapterInfo.Descendants("a").First().InnerText;
|
||||||
|
string url = chapterInfo.Descendants("a").First()
|
||||||
|
.GetAttributeValue("href", "");
|
||||||
|
|
||||||
|
int? volumeNumber = volumeRex.IsMatch(url) ? int.Parse(volumeRex.Match(url).Groups[1].Value) : null;
|
||||||
|
if(!ChapterNumber.CanParse(chapterNumRex.Match(url).Groups[1].Value))
|
||||||
|
continue;
|
||||||
|
ChapterNumber chapterNumber = new(chapterNumRex.Match(url).Groups[1].Value);
|
||||||
|
string chapterName = chapterNameRex.Match(fullString).Groups[1].Value;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ret.Add(new Chapter(manga, url, chapterNumber, volumeNumber, chapterName));
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal override string[] GetChapterImageUrls(Chapter chapter)
|
||||||
|
{
|
||||||
|
string requestUrl = chapter.Url;
|
||||||
|
// Leaving this in to check if the page exists
|
||||||
|
RequestResult requestResult =
|
||||||
|
downloadClient.MakeRequest(requestUrl, RequestType.Default);
|
||||||
|
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300 || requestResult.htmlDocument is null)
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
string[] imageUrls = ParseImageUrlsFromHtml(requestResult.htmlDocument);
|
||||||
|
return imageUrls;
|
||||||
|
}
|
||||||
|
|
||||||
|
private string[] ParseImageUrlsFromHtml(HtmlDocument document)
|
||||||
|
{
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
}
|
188
API/Schema/MangaConnectors/MangaLife.cs
Normal file
188
API/Schema/MangaConnectors/MangaLife.cs
Normal file
@ -0,0 +1,188 @@
|
|||||||
|
using System.Net;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using API.MangaDownloadClients;
|
||||||
|
using HtmlAgilityPack;
|
||||||
|
|
||||||
|
namespace API.Schema.MangaConnectors;
|
||||||
|
|
||||||
|
public class MangaLife : MangaConnector
|
||||||
|
{
|
||||||
|
public MangaLife() : base("Manga4Life", ["en"], ["manga4life.com"])
|
||||||
|
{
|
||||||
|
this.downloadClient = new ChromiumDownloadClient();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override (Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)[] GetManga(string publicationTitle = "")
|
||||||
|
{
|
||||||
|
string sanitizedTitle = WebUtility.UrlEncode(publicationTitle);
|
||||||
|
string requestUrl = $"https://manga4life.com/search/?name={sanitizedTitle}";
|
||||||
|
RequestResult requestResult =
|
||||||
|
downloadClient.MakeRequest(requestUrl, RequestType.Default);
|
||||||
|
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
||||||
|
return [];
|
||||||
|
|
||||||
|
if (requestResult.htmlDocument is null)
|
||||||
|
return [];
|
||||||
|
(Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)[] publications = ParsePublicationsFromHtml(requestResult.htmlDocument);
|
||||||
|
return publications;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override (Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)? GetMangaFromId(string publicationId)
|
||||||
|
{
|
||||||
|
return GetMangaFromUrl($"https://manga4life.com/manga/{publicationId}");
|
||||||
|
}
|
||||||
|
|
||||||
|
public override (Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)? GetMangaFromUrl(string url)
|
||||||
|
{
|
||||||
|
Regex publicationIdRex = new(@"https:\/\/(www\.)?manga4life.com\/manga\/(.*)(\/.*)*");
|
||||||
|
string publicationId = publicationIdRex.Match(url).Groups[2].Value;
|
||||||
|
|
||||||
|
RequestResult requestResult = this.downloadClient.MakeRequest(url, RequestType.MangaInfo);
|
||||||
|
if(requestResult.htmlDocument is not null)
|
||||||
|
return ParseSinglePublicationFromHtml(requestResult.htmlDocument, publicationId, url);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private (Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)[] ParsePublicationsFromHtml(HtmlDocument document)
|
||||||
|
{
|
||||||
|
HtmlNode resultsNode = document.DocumentNode.SelectSingleNode("//div[@class='BoxBody']/div[last()]/div[1]/div");
|
||||||
|
if (resultsNode.Descendants("div").Count() == 1 && resultsNode.Descendants("div").First().HasClass("NoResults"))
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
List<(Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)> ret = new();
|
||||||
|
|
||||||
|
foreach (HtmlNode resultNode in resultsNode.SelectNodes("div"))
|
||||||
|
{
|
||||||
|
string url = resultNode.Descendants().First(d => d.HasClass("SeriesName")).GetAttributeValue("href", "");
|
||||||
|
(Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)? manga = GetMangaFromUrl($"https://manga4life.com{url}");
|
||||||
|
if (manga is { } x)
|
||||||
|
ret.Add(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private (Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?) ParseSinglePublicationFromHtml(HtmlDocument document, string publicationId, string websiteUrl)
|
||||||
|
{
|
||||||
|
string originalLanguage = "", status = "";
|
||||||
|
Dictionary<string, string> altTitles = new(), links = new();
|
||||||
|
HashSet<string> tags = new();
|
||||||
|
MangaReleaseStatus releaseStatus = MangaReleaseStatus.Unreleased;
|
||||||
|
|
||||||
|
HtmlNode posterNode = document.DocumentNode.SelectSingleNode("//div[@class='BoxBody']//div[@class='row']//img");
|
||||||
|
string coverUrl = posterNode.GetAttributeValue("src", "");
|
||||||
|
|
||||||
|
HtmlNode titleNode = document.DocumentNode.SelectSingleNode("//div[@class='BoxBody']//div[@class='row']//h1");
|
||||||
|
string sortName = titleNode.InnerText;
|
||||||
|
|
||||||
|
HtmlNode[] authorsNodes = document.DocumentNode
|
||||||
|
.SelectNodes("//div[@class='BoxBody']//div[@class='row']//span[text()='Author(s):']/..").Descendants("a")
|
||||||
|
.ToArray();
|
||||||
|
List<string> authorNames = new();
|
||||||
|
foreach (HtmlNode authorNode in authorsNodes)
|
||||||
|
authorNames.Add(authorNode.InnerText);
|
||||||
|
List<Author> authors = authorNames.Select(a => new Author(a)).ToList();
|
||||||
|
|
||||||
|
HtmlNode[] genreNodes = document.DocumentNode
|
||||||
|
.SelectNodes("//div[@class='BoxBody']//div[@class='row']//span[text()='Genre(s):']/..").Descendants("a")
|
||||||
|
.ToArray();
|
||||||
|
foreach (HtmlNode genreNode in genreNodes)
|
||||||
|
tags.Add(genreNode.InnerText);
|
||||||
|
List<MangaTag> mangaTags = tags.Select(t => new MangaTag(t)).ToList();
|
||||||
|
|
||||||
|
HtmlNode yearNode = document.DocumentNode
|
||||||
|
.SelectNodes("//div[@class='BoxBody']//div[@class='row']//span[text()='Released:']/..").Descendants("a")
|
||||||
|
.First();
|
||||||
|
uint year = uint.Parse(yearNode.InnerText);
|
||||||
|
|
||||||
|
HtmlNode[] statusNodes = document.DocumentNode
|
||||||
|
.SelectNodes("//div[@class='BoxBody']//div[@class='row']//span[text()='Status:']/..").Descendants("a")
|
||||||
|
.ToArray();
|
||||||
|
foreach (HtmlNode statusNode in statusNodes)
|
||||||
|
if (statusNode.InnerText.Contains("publish", StringComparison.CurrentCultureIgnoreCase))
|
||||||
|
status = statusNode.InnerText.Split(' ')[0];
|
||||||
|
switch (status.ToLower())
|
||||||
|
{
|
||||||
|
case "cancelled": releaseStatus = MangaReleaseStatus.Cancelled; break;
|
||||||
|
case "hiatus": releaseStatus = MangaReleaseStatus.OnHiatus; break;
|
||||||
|
case "discontinued": releaseStatus = MangaReleaseStatus.Cancelled; break;
|
||||||
|
case "complete": releaseStatus = MangaReleaseStatus.Completed; break;
|
||||||
|
case "ongoing": releaseStatus = MangaReleaseStatus.Continuing; break;
|
||||||
|
}
|
||||||
|
|
||||||
|
HtmlNode descriptionNode = document.DocumentNode
|
||||||
|
.SelectNodes("//div[@class='BoxBody']//div[@class='row']//span[text()='Description:']/..")
|
||||||
|
.Descendants("div").First();
|
||||||
|
string description = descriptionNode.InnerText;
|
||||||
|
|
||||||
|
Manga manga = new (publicationId, sortName, description, websiteUrl, coverUrl, null, year,
|
||||||
|
originalLanguage, releaseStatus, -1,
|
||||||
|
this,
|
||||||
|
authors,
|
||||||
|
mangaTags,
|
||||||
|
[],
|
||||||
|
[]);
|
||||||
|
|
||||||
|
return (manga, authors, mangaTags, [], []);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override Chapter[] GetChapters(Manga manga, string language="en")
|
||||||
|
{
|
||||||
|
RequestResult result = downloadClient.MakeRequest($"https://manga4life.com/manga/{manga.MangaId}", RequestType.Default, clickButton:"[class*='ShowAllChapters']");
|
||||||
|
if ((int)result.statusCode < 200 || (int)result.statusCode >= 300 || result.htmlDocument is null)
|
||||||
|
{
|
||||||
|
return Array.Empty<Chapter>();
|
||||||
|
}
|
||||||
|
|
||||||
|
HtmlNodeCollection chapterNodes = result.htmlDocument.DocumentNode.SelectNodes(
|
||||||
|
"//a[contains(concat(' ',normalize-space(@class),' '),' ChapterLink ')]");
|
||||||
|
string[] urls = chapterNodes.Select(node => node.GetAttributeValue("href", "")).ToArray();
|
||||||
|
Regex urlRex = new (@"-chapter-([0-9\\.]+)(-index-([0-9\\.]+))?");
|
||||||
|
|
||||||
|
List<Chapter> chapters = new();
|
||||||
|
foreach (string url in urls)
|
||||||
|
{
|
||||||
|
Match rexMatch = urlRex.Match(url);
|
||||||
|
|
||||||
|
int? volumeNumber = rexMatch.Groups[3].Success && rexMatch.Groups[3].Value.Length > 0
|
||||||
|
? int.Parse(rexMatch.Groups[3].Value)
|
||||||
|
: null;
|
||||||
|
|
||||||
|
if(!ChapterNumber.CanParse(rexMatch.Groups[1].Value))
|
||||||
|
continue;
|
||||||
|
ChapterNumber chapterNumber = new(rexMatch.Groups[1].Value);
|
||||||
|
string fullUrl = $"https://manga4life.com{url}";
|
||||||
|
fullUrl = fullUrl.Replace(Regex.Match(url,"(-page-[0-9])").Value,"");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
chapters.Add(new Chapter(manga, fullUrl, chapterNumber, volumeNumber, null));
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//Return Chapters ordered by Chapter-Number
|
||||||
|
return chapters.Order().ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
internal override string[] GetChapterImageUrls(Chapter chapter)
|
||||||
|
{
|
||||||
|
RequestResult requestResult = this.downloadClient.MakeRequest(chapter.Url, RequestType.Default);
|
||||||
|
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300 || requestResult.htmlDocument is null)
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
HtmlDocument document = requestResult.htmlDocument;
|
||||||
|
|
||||||
|
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", ""));
|
||||||
|
return urls.ToArray();
|
||||||
|
}
|
||||||
|
}
|
226
API/Schema/MangaConnectors/Manganato.cs
Normal file
226
API/Schema/MangaConnectors/Manganato.cs
Normal file
@ -0,0 +1,226 @@
|
|||||||
|
using System.Globalization;
|
||||||
|
using System.Net;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using API.MangaDownloadClients;
|
||||||
|
using HtmlAgilityPack;
|
||||||
|
|
||||||
|
namespace API.Schema.MangaConnectors;
|
||||||
|
|
||||||
|
public class Manganato : MangaConnector
|
||||||
|
{
|
||||||
|
public Manganato() : base("Manganato", ["en"], ["manganato.com"])
|
||||||
|
{
|
||||||
|
this.downloadClient = new HttpDownloadClient();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override (Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)[] GetManga(string publicationTitle = "")
|
||||||
|
{
|
||||||
|
string sanitizedTitle = string.Join('_', Regex.Matches(publicationTitle, "[A-z]*").Where(str => str.Length > 0)).ToLower();
|
||||||
|
string requestUrl = $"https://manganato.com/search/story/{sanitizedTitle}";
|
||||||
|
RequestResult requestResult =
|
||||||
|
downloadClient.MakeRequest(requestUrl, RequestType.Default);
|
||||||
|
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300 ||requestResult.htmlDocument is null)
|
||||||
|
return [];
|
||||||
|
(Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)[] publications = ParsePublicationsFromHtml(requestResult.htmlDocument);
|
||||||
|
return publications;
|
||||||
|
}
|
||||||
|
|
||||||
|
private (Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)[] ParsePublicationsFromHtml(HtmlDocument document)
|
||||||
|
{
|
||||||
|
List<HtmlNode> searchResults = document.DocumentNode.Descendants("div").Where(n => n.HasClass("search-story-item")).ToList();
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<(Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)> ret = new();
|
||||||
|
foreach (string url in urls)
|
||||||
|
{
|
||||||
|
(Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)? manga = GetMangaFromUrl(url);
|
||||||
|
if (manga is { } x)
|
||||||
|
ret.Add(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override (Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)? GetMangaFromId(string publicationId)
|
||||||
|
{
|
||||||
|
return GetMangaFromUrl($"https://chapmanganato.com/{publicationId}");
|
||||||
|
}
|
||||||
|
|
||||||
|
public override (Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)? GetMangaFromUrl(string url)
|
||||||
|
{
|
||||||
|
RequestResult requestResult =
|
||||||
|
downloadClient.MakeRequest(url, RequestType.MangaInfo);
|
||||||
|
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
if (requestResult.htmlDocument is null)
|
||||||
|
return null;
|
||||||
|
return ParseSinglePublicationFromHtml(requestResult.htmlDocument, url.Split('/')[^1], url);
|
||||||
|
}
|
||||||
|
|
||||||
|
private (Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?) ParseSinglePublicationFromHtml(HtmlDocument document, string publicationId, string websiteUrl)
|
||||||
|
{
|
||||||
|
Dictionary<string, string> altTitlesDict = new();
|
||||||
|
Dictionary<string, string>? links = null;
|
||||||
|
HashSet<string> tags = new();
|
||||||
|
string[] authorNames = [];
|
||||||
|
string originalLanguage = "";
|
||||||
|
MangaReleaseStatus releaseStatus = MangaReleaseStatus.Unreleased;
|
||||||
|
|
||||||
|
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++)
|
||||||
|
altTitlesDict.Add(i.ToString(), alts[i]);
|
||||||
|
break;
|
||||||
|
case "authors":
|
||||||
|
authorNames = value.Split('-');
|
||||||
|
for (int i = 0; i < authorNames.Length; i++)
|
||||||
|
authorNames[i] = authorNames[i].Replace("\r\n", "");
|
||||||
|
break;
|
||||||
|
case "status":
|
||||||
|
switch (value.ToLower())
|
||||||
|
{
|
||||||
|
case "ongoing": releaseStatus = MangaReleaseStatus.Continuing; break;
|
||||||
|
case "completed": releaseStatus = MangaReleaseStatus.Completed; break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "genres":
|
||||||
|
string[] genres = value.Split(" - ");
|
||||||
|
for (int i = 0; i < genres.Length; i++)
|
||||||
|
genres[i] = genres[i].Replace("\r\n", "");
|
||||||
|
tags = genres.ToHashSet();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
List<Author> authors = authorNames.Select(n => new Author(n)).ToList();
|
||||||
|
List<MangaTag> mangaTags = tags.Select(n => new MangaTag(n)).ToList();
|
||||||
|
List<MangaAltTitle> mangaAltTitles = altTitlesDict.Select(a => new MangaAltTitle(a.Key, a.Value)).ToList();
|
||||||
|
|
||||||
|
string coverUrl = document.DocumentNode.Descendants("span").First(s => s.HasClass("info-image")).Descendants("img").First()
|
||||||
|
.GetAttributes().First(a => a.Name == "src").Value;
|
||||||
|
|
||||||
|
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 pattern = "MMM dd,yyyy HH:mm";
|
||||||
|
|
||||||
|
HtmlNode? oldestChapter = document.DocumentNode
|
||||||
|
.SelectNodes("//span[contains(concat(' ',normalize-space(@class),' '),' chapter-time ')]").MaxBy(
|
||||||
|
node => DateTime.ParseExact(node.GetAttributeValue("title", "Dec 31 2400, 23:59"), pattern,
|
||||||
|
CultureInfo.InvariantCulture).Millisecond);
|
||||||
|
|
||||||
|
|
||||||
|
uint year = (uint)DateTime.ParseExact(oldestChapter?.GetAttributeValue("title", "Dec 31 2400, 23:59")??"Dec 31 2400, 23:59", pattern,
|
||||||
|
CultureInfo.InvariantCulture).Year;
|
||||||
|
|
||||||
|
Manga manga = new (publicationId, sortName, description, websiteUrl, coverUrl, null, year,
|
||||||
|
originalLanguage, releaseStatus, -1,
|
||||||
|
this,
|
||||||
|
authors,
|
||||||
|
mangaTags,
|
||||||
|
[],
|
||||||
|
mangaAltTitles);
|
||||||
|
|
||||||
|
return (manga, authors, mangaTags, [], mangaAltTitles);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override Chapter[] GetChapters(Manga manga, string language="en")
|
||||||
|
{
|
||||||
|
string requestUrl = $"https://chapmanganato.com/{manga.MangaId}";
|
||||||
|
RequestResult requestResult =
|
||||||
|
downloadClient.MakeRequest(requestUrl, RequestType.Default);
|
||||||
|
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
||||||
|
return [];
|
||||||
|
|
||||||
|
//Return Chapters ordered by Chapter-Number
|
||||||
|
if (requestResult.htmlDocument is null)
|
||||||
|
return [];
|
||||||
|
List<Chapter> chapters = ParseChaptersFromHtml(manga, requestResult.htmlDocument);
|
||||||
|
return chapters.Order().ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private List<Chapter> ParseChaptersFromHtml(Manga manga, HtmlDocument document)
|
||||||
|
{
|
||||||
|
List<Chapter> ret = new();
|
||||||
|
|
||||||
|
HtmlNode chapterList = document.DocumentNode.Descendants("ul").First(l => l.HasClass("row-content-chapter"));
|
||||||
|
|
||||||
|
Regex volRex = new(@"Vol\.([0-9]+).*");
|
||||||
|
Regex chapterRex = new(@"https:\/\/chapmanganato.[A-z]+\/manga-[A-z0-9]+\/chapter-([0-9\.]+)");
|
||||||
|
Regex nameRex = new(@"Chapter ([0-9]+(\.[0-9]+)*){1}:? (.*)");
|
||||||
|
|
||||||
|
foreach (HtmlNode chapterInfo in chapterList.Descendants("li"))
|
||||||
|
{
|
||||||
|
string fullString = chapterInfo.Descendants("a").First(d => d.HasClass("chapter-name")).InnerText;
|
||||||
|
|
||||||
|
string url = chapterInfo.Descendants("a").First(d => d.HasClass("chapter-name"))
|
||||||
|
.GetAttributeValue("href", "");
|
||||||
|
|
||||||
|
int? volumeNumber = volRex.IsMatch(fullString)
|
||||||
|
? int.Parse(volRex.Match(fullString).Groups[1].Value)
|
||||||
|
: null;
|
||||||
|
if(!ChapterNumber.CanParse(chapterRex.Match(url).Groups[1].Value))
|
||||||
|
continue;
|
||||||
|
ChapterNumber chapterNumber = new(chapterRex.Match(url).Groups[1].Value);
|
||||||
|
string chapterName = nameRex.Match(fullString).Groups[3].Value;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ret.Add(new Chapter(manga, url, chapterNumber, volumeNumber, chapterName));
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ret.Reverse();
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal override string[] GetChapterImageUrls(Chapter chapter)
|
||||||
|
{
|
||||||
|
string requestUrl = chapter.Url;
|
||||||
|
RequestResult requestResult =
|
||||||
|
downloadClient.MakeRequest(requestUrl, RequestType.Default);
|
||||||
|
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300 ||
|
||||||
|
requestResult.htmlDocument is null)
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
string[] imageUrls = ParseImageUrlsFromHtml(requestResult.htmlDocument);
|
||||||
|
return imageUrls;
|
||||||
|
}
|
||||||
|
|
||||||
|
private string[] ParseImageUrlsFromHtml(HtmlDocument document)
|
||||||
|
{
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
215
API/Schema/MangaConnectors/Mangasee.cs
Normal file
215
API/Schema/MangaConnectors/Mangasee.cs
Normal file
@ -0,0 +1,215 @@
|
|||||||
|
using System.Data;
|
||||||
|
using System.Net;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
using API.MangaDownloadClients;
|
||||||
|
using HtmlAgilityPack;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Soenneker.Utils.String.NeedlemanWunsch;
|
||||||
|
|
||||||
|
namespace API.Schema.MangaConnectors;
|
||||||
|
|
||||||
|
public class Mangasee : MangaConnector
|
||||||
|
{
|
||||||
|
public Mangasee() : base("Mangasee", ["en"], ["mangasee123.com"])
|
||||||
|
{
|
||||||
|
this.downloadClient = new ChromiumDownloadClient();
|
||||||
|
}
|
||||||
|
|
||||||
|
private struct SearchResult
|
||||||
|
{
|
||||||
|
public string i { get; set; }
|
||||||
|
public string s { get; set; }
|
||||||
|
public string[] a { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public override (Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)[] GetManga(string publicationTitle = "")
|
||||||
|
{
|
||||||
|
string requestUrl = "https://mangasee123.com/_search.php";
|
||||||
|
RequestResult requestResult =
|
||||||
|
downloadClient.MakeRequest(requestUrl, RequestType.Default);
|
||||||
|
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300 || requestResult.htmlDocument is null)
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
SearchResult[] searchResults = JsonConvert.DeserializeObject<SearchResult[]>(requestResult.htmlDocument!.DocumentNode.InnerText) ??
|
||||||
|
throw new NoNullAllowedException();
|
||||||
|
SearchResult[] filteredResults = FilteredResults(publicationTitle, searchResults);
|
||||||
|
|
||||||
|
|
||||||
|
string[] urls = filteredResults.Select(result => $"https://mangasee123.com/manga/{result.i}").ToArray();
|
||||||
|
List<(Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)> searchResultManga = new();
|
||||||
|
foreach (string url in urls)
|
||||||
|
{
|
||||||
|
(Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)? newManga = GetMangaFromUrl(url);
|
||||||
|
if(newManga is { } manga)
|
||||||
|
searchResultManga.Add(manga);
|
||||||
|
}
|
||||||
|
return searchResultManga.ToArray();
|
||||||
|
}
|
||||||
|
catch (NoNullAllowedException)
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly string[] _filterWords = {"a", "the", "of", "as", "to", "no", "for", "on", "with", "be", "and", "in", "wa", "at", "be", "ni"};
|
||||||
|
private string ToFilteredString(string input) => string.Join(' ', input.ToLower().Split(' ').Where(word => _filterWords.Contains(word) == false));
|
||||||
|
private SearchResult[] FilteredResults(string publicationTitle, SearchResult[] unfilteredSearchResults)
|
||||||
|
{
|
||||||
|
Dictionary<SearchResult, int> similarity = new();
|
||||||
|
foreach (SearchResult sr in unfilteredSearchResults)
|
||||||
|
{
|
||||||
|
List<int> scores = new();
|
||||||
|
string filteredPublicationString = ToFilteredString(publicationTitle);
|
||||||
|
string filteredSString = ToFilteredString(sr.s);
|
||||||
|
scores.Add(NeedlemanWunschStringUtil.CalculateSimilarity(filteredSString, filteredPublicationString));
|
||||||
|
foreach (string srA in sr.a)
|
||||||
|
{
|
||||||
|
string filteredAString = ToFilteredString(srA);
|
||||||
|
scores.Add(NeedlemanWunschStringUtil.CalculateSimilarity(filteredAString, filteredPublicationString));
|
||||||
|
}
|
||||||
|
similarity.Add(sr, scores.Sum() / scores.Count);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<SearchResult> ret = similarity.OrderBy(s => s.Value).Take(10).Select(s => s.Key).ToList();
|
||||||
|
return ret.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override (Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)? GetMangaFromId(string publicationId)
|
||||||
|
{
|
||||||
|
return GetMangaFromUrl($"https://mangasee123.com/manga/{publicationId}");
|
||||||
|
}
|
||||||
|
|
||||||
|
public override (Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)? GetMangaFromUrl(string url)
|
||||||
|
{
|
||||||
|
Regex publicationIdRex = new(@"https:\/\/mangasee123.com\/manga\/(.*)(\/.*)*");
|
||||||
|
string publicationId = publicationIdRex.Match(url).Groups[1].Value;
|
||||||
|
|
||||||
|
RequestResult requestResult = this.downloadClient.MakeRequest(url, RequestType.MangaInfo);
|
||||||
|
if((int)requestResult.statusCode < 300 && (int)requestResult.statusCode >= 200 && requestResult.htmlDocument is not null)
|
||||||
|
return ParseSinglePublicationFromHtml(requestResult.htmlDocument, publicationId, url);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private (Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?) ParseSinglePublicationFromHtml(HtmlDocument document, string publicationId, string websiteUrl)
|
||||||
|
{
|
||||||
|
string originalLanguage = "", status = "";
|
||||||
|
Dictionary<string, string> altTitles = new(), links = new();
|
||||||
|
HashSet<string> tags = new();
|
||||||
|
MangaReleaseStatus releaseStatus = MangaReleaseStatus.Unreleased;
|
||||||
|
|
||||||
|
HtmlNode posterNode = document.DocumentNode.SelectSingleNode("//div[@class='BoxBody']//div[@class='row']//img");
|
||||||
|
string coverUrl = posterNode.GetAttributeValue("src", "");
|
||||||
|
|
||||||
|
HtmlNode titleNode = document.DocumentNode.SelectSingleNode("//div[@class='BoxBody']//div[@class='row']//h1");
|
||||||
|
string sortName = titleNode.InnerText;
|
||||||
|
|
||||||
|
HtmlNode[] authorsNodes = document.DocumentNode
|
||||||
|
.SelectNodes("//div[@class='BoxBody']//div[@class='row']//span[text()='Author(s):']/..").Descendants("a")
|
||||||
|
.ToArray();
|
||||||
|
List<string> authorNames = new();
|
||||||
|
foreach (HtmlNode authorNode in authorsNodes)
|
||||||
|
authorNames.Add(authorNode.InnerText);
|
||||||
|
List<Author> authors = authorNames.Select(a => new Author(a)).ToList();
|
||||||
|
|
||||||
|
HtmlNode[] genreNodes = document.DocumentNode
|
||||||
|
.SelectNodes("//div[@class='BoxBody']//div[@class='row']//span[text()='Genre(s):']/..").Descendants("a")
|
||||||
|
.ToArray();
|
||||||
|
foreach (HtmlNode genreNode in genreNodes)
|
||||||
|
tags.Add(genreNode.InnerText);
|
||||||
|
List<MangaTag> mangaTags = tags.Select(t => new MangaTag(t)).ToList();
|
||||||
|
|
||||||
|
HtmlNode yearNode = document.DocumentNode
|
||||||
|
.SelectNodes("//div[@class='BoxBody']//div[@class='row']//span[text()='Released:']/..").Descendants("a")
|
||||||
|
.First();
|
||||||
|
uint year = uint.Parse(yearNode.InnerText);
|
||||||
|
|
||||||
|
HtmlNode[] statusNodes = document.DocumentNode
|
||||||
|
.SelectNodes("//div[@class='BoxBody']//div[@class='row']//span[text()='Status:']/..").Descendants("a")
|
||||||
|
.ToArray();
|
||||||
|
foreach (HtmlNode statusNode in statusNodes)
|
||||||
|
if (statusNode.InnerText.Contains("publish", StringComparison.CurrentCultureIgnoreCase))
|
||||||
|
status = statusNode.InnerText.Split(' ')[0];
|
||||||
|
switch (status.ToLower())
|
||||||
|
{
|
||||||
|
case "cancelled": releaseStatus = MangaReleaseStatus.Cancelled; break;
|
||||||
|
case "hiatus": releaseStatus = MangaReleaseStatus.OnHiatus; break;
|
||||||
|
case "discontinued": releaseStatus = MangaReleaseStatus.Cancelled; break;
|
||||||
|
case "complete": releaseStatus = MangaReleaseStatus.Completed; break;
|
||||||
|
case "ongoing": releaseStatus = MangaReleaseStatus.Continuing; break;
|
||||||
|
}
|
||||||
|
|
||||||
|
HtmlNode descriptionNode = document.DocumentNode
|
||||||
|
.SelectNodes("//div[@class='BoxBody']//div[@class='row']//span[text()='Description:']/..")
|
||||||
|
.Descendants("div").First();
|
||||||
|
string description = descriptionNode.InnerText;
|
||||||
|
|
||||||
|
Manga manga = new (publicationId, sortName, description, websiteUrl, coverUrl, null, year,
|
||||||
|
originalLanguage, releaseStatus, -1,
|
||||||
|
this,
|
||||||
|
authors,
|
||||||
|
mangaTags,
|
||||||
|
[],
|
||||||
|
[]);
|
||||||
|
|
||||||
|
return (manga, authors, mangaTags, [], []);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override Chapter[] GetChapters(Manga manga, string language="en")
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
XDocument doc = XDocument.Load($"https://mangasee123.com/rss/{manga.MangaId}.xml");
|
||||||
|
XElement[] chapterItems = doc.Descendants("item").ToArray();
|
||||||
|
List<Chapter> chapters = new();
|
||||||
|
Regex chVolRex = new(@".*chapter-([0-9\.]+)(?:-index-([0-9\.]+))?.*");
|
||||||
|
foreach (XElement chapter in chapterItems)
|
||||||
|
{
|
||||||
|
string url = chapter.Descendants("link").First().Value;
|
||||||
|
Match m = chVolRex.Match(url);
|
||||||
|
int? volumeNumber = m.Groups[2].Success ? int.Parse(m.Groups[2].Value) : null;
|
||||||
|
if(!ChapterNumber.CanParse(m.Groups[1].Value))
|
||||||
|
continue;
|
||||||
|
ChapterNumber chapterNumber = new(m.Groups[1].Value);
|
||||||
|
|
||||||
|
string chapterUrl = Regex.Replace(url, @"-page-[0-9]+(\.html)", ".html");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
chapters.Add(new Chapter(manga, chapterUrl,chapterNumber, volumeNumber, null));
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Return Chapters ordered by Chapter-Number
|
||||||
|
return chapters.Order().ToArray();
|
||||||
|
}
|
||||||
|
catch (HttpRequestException e)
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal override string[] GetChapterImageUrls(Chapter chapter)
|
||||||
|
{
|
||||||
|
RequestResult requestResult = this.downloadClient.MakeRequest(chapter.Url, RequestType.Default);
|
||||||
|
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300 || requestResult.htmlDocument is null)
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
HtmlDocument document = requestResult.htmlDocument;
|
||||||
|
|
||||||
|
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", ""));
|
||||||
|
return urls.ToArray();
|
||||||
|
}
|
||||||
|
}
|
225
API/Schema/MangaConnectors/Mangaworld.cs
Normal file
225
API/Schema/MangaConnectors/Mangaworld.cs
Normal file
@ -0,0 +1,225 @@
|
|||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using API.MangaDownloadClients;
|
||||||
|
using HtmlAgilityPack;
|
||||||
|
|
||||||
|
namespace API.Schema.MangaConnectors;
|
||||||
|
|
||||||
|
public class Mangaworld : MangaConnector
|
||||||
|
{
|
||||||
|
public Mangaworld() : base("Mangaworld", ["it"], ["www.mangaworld.ac"])
|
||||||
|
{
|
||||||
|
this.downloadClient = new ChromiumDownloadClient();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override (Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)[] GetManga(string publicationTitle = "")
|
||||||
|
{
|
||||||
|
string sanitizedTitle = string.Join(' ', Regex.Matches(publicationTitle, "[A-z]*").Where(str => str.Length > 0)).ToLower();
|
||||||
|
string requestUrl = $"https://www.mangaworld.ac/archive?keyword={sanitizedTitle}";
|
||||||
|
RequestResult requestResult =
|
||||||
|
downloadClient.MakeRequest(requestUrl, RequestType.Default);
|
||||||
|
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
||||||
|
return [];
|
||||||
|
|
||||||
|
if (requestResult.htmlDocument is null)
|
||||||
|
return [];
|
||||||
|
(Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)[] publications = ParsePublicationsFromHtml(requestResult.htmlDocument);
|
||||||
|
return publications;
|
||||||
|
}
|
||||||
|
|
||||||
|
private (Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)[] ParsePublicationsFromHtml(HtmlDocument document)
|
||||||
|
{
|
||||||
|
if (!document.DocumentNode.SelectSingleNode("//div[@class='comics-grid']").ChildNodes
|
||||||
|
.Any(node => node.HasClass("entry")))
|
||||||
|
return [];
|
||||||
|
|
||||||
|
List<string> urls = document.DocumentNode
|
||||||
|
.SelectNodes(
|
||||||
|
"//div[@class='comics-grid']//div[@class='entry']//a[contains(concat(' ',normalize-space(@class),' '),'thumb')]")
|
||||||
|
.Select(thumb => thumb.GetAttributeValue("href", "")).ToList();
|
||||||
|
|
||||||
|
List<(Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)> ret = new();
|
||||||
|
foreach (string url in urls)
|
||||||
|
{
|
||||||
|
(Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)? manga = GetMangaFromUrl(url);
|
||||||
|
if (manga is { } x)
|
||||||
|
ret.Add(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override (Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)? GetMangaFromId(string publicationId)
|
||||||
|
{
|
||||||
|
return GetMangaFromUrl($"https://www.mangaworld.ac/manga/{publicationId}");
|
||||||
|
}
|
||||||
|
|
||||||
|
public override (Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)? GetMangaFromUrl(string url)
|
||||||
|
{
|
||||||
|
RequestResult requestResult =
|
||||||
|
downloadClient.MakeRequest(url, RequestType.MangaInfo);
|
||||||
|
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
if (requestResult.htmlDocument is null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
Regex idRex = new (@"https:\/\/www\.mangaworld\.[a-z]{0,63}\/manga\/([0-9]+\/[0-9A-z\-]+).*");
|
||||||
|
string id = idRex.Match(url).Groups[1].Value;
|
||||||
|
return ParseSinglePublicationFromHtml(requestResult.htmlDocument, id, url);
|
||||||
|
}
|
||||||
|
|
||||||
|
private (Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?) ParseSinglePublicationFromHtml(HtmlDocument document, string publicationId, string websiteUrl)
|
||||||
|
{
|
||||||
|
Dictionary<string, string> altTitlesDict = new();
|
||||||
|
string originalLanguage = "";
|
||||||
|
MangaReleaseStatus releaseStatus = MangaReleaseStatus.Unreleased;
|
||||||
|
|
||||||
|
HtmlNode infoNode = document.DocumentNode.Descendants("div").First(d => d.HasClass("info"));
|
||||||
|
|
||||||
|
string sortName = infoNode.Descendants("h1").First().InnerText;
|
||||||
|
|
||||||
|
HtmlNode metadata = infoNode.Descendants().First(d => d.HasClass("meta-data"));
|
||||||
|
|
||||||
|
HtmlNode altTitlesNode = metadata.SelectSingleNode("//span[text()='Titoli alternativi: ' or text()='Titolo alternativo: ']/..").ChildNodes[1];
|
||||||
|
string[] alts = altTitlesNode.InnerText.Split(", ");
|
||||||
|
for(int i = 0; i < alts.Length; i++)
|
||||||
|
altTitlesDict.Add(i.ToString(), alts[i]);
|
||||||
|
List<MangaAltTitle> altTitles = altTitlesDict.Select(a => new MangaAltTitle(a.Key, a.Value)).ToList();
|
||||||
|
|
||||||
|
HtmlNode genresNode =
|
||||||
|
metadata.SelectSingleNode("//span[text()='Generi: ' or text()='Genero: ']/..");
|
||||||
|
HashSet<string> tags = genresNode.SelectNodes("a").Select(node => node.InnerText).ToHashSet();
|
||||||
|
List<MangaTag> mangaTags = tags.Select(t => new MangaTag(t)).ToList();
|
||||||
|
|
||||||
|
HtmlNode authorsNode =
|
||||||
|
metadata.SelectSingleNode("//span[text()='Autore: ' or text()='Autori: ']/..");
|
||||||
|
string[] authorNames = authorsNode.SelectNodes("a").Select(node => node.InnerText).ToArray();
|
||||||
|
List<Author> authors = authorNames.Select(n => new Author(n)).ToList();
|
||||||
|
|
||||||
|
string status = metadata.SelectSingleNode("//span[text()='Stato: ']/..").SelectNodes("a").First().InnerText;
|
||||||
|
// ReSharper disable 5 times StringLiteralTypo
|
||||||
|
switch (status.ToLower())
|
||||||
|
{
|
||||||
|
case "cancellato": releaseStatus = MangaReleaseStatus.Cancelled; break;
|
||||||
|
case "in pausa": releaseStatus = MangaReleaseStatus.OnHiatus; break;
|
||||||
|
case "droppato": releaseStatus = MangaReleaseStatus.Cancelled; break;
|
||||||
|
case "finito": releaseStatus = MangaReleaseStatus.Completed; break;
|
||||||
|
case "in corso": releaseStatus = MangaReleaseStatus.Continuing; break;
|
||||||
|
}
|
||||||
|
|
||||||
|
string coverUrl = document.DocumentNode.SelectSingleNode("//img[@class='rounded']").GetAttributeValue("src", "");
|
||||||
|
|
||||||
|
string description = document.DocumentNode.SelectSingleNode("//div[@id='noidungm']").InnerText;
|
||||||
|
|
||||||
|
string yearString = metadata.SelectSingleNode("//span[text()='Anno di uscita: ']/..").SelectNodes("a").First().InnerText;
|
||||||
|
uint year = uint.Parse(yearString);
|
||||||
|
|
||||||
|
Manga manga = new (publicationId, sortName, description, websiteUrl, coverUrl, null, year,
|
||||||
|
originalLanguage, releaseStatus, -1,
|
||||||
|
this,
|
||||||
|
authors,
|
||||||
|
mangaTags,
|
||||||
|
[],
|
||||||
|
altTitles);
|
||||||
|
|
||||||
|
return (manga, authors, mangaTags, [], altTitles);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override Chapter[] GetChapters(Manga manga, string language="en")
|
||||||
|
{
|
||||||
|
string requestUrl = $"https://www.mangaworld.ac/manga/{manga.MangaId}";
|
||||||
|
RequestResult requestResult =
|
||||||
|
downloadClient.MakeRequest(requestUrl, RequestType.Default);
|
||||||
|
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300 || requestResult.htmlDocument is null)
|
||||||
|
return [];
|
||||||
|
|
||||||
|
List<Chapter> chapters = ParseChaptersFromHtml(manga, requestResult.htmlDocument);
|
||||||
|
return chapters.Order().ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Chapter> ParseChaptersFromHtml(Manga manga, HtmlDocument document)
|
||||||
|
{
|
||||||
|
List<Chapter> ret = new();
|
||||||
|
|
||||||
|
HtmlNode chaptersWrapper =
|
||||||
|
document.DocumentNode.SelectSingleNode(
|
||||||
|
"//div[contains(concat(' ',normalize-space(@class),' '),'chapters-wrapper')]");
|
||||||
|
|
||||||
|
Regex volumeRex = new(@"[Vv]olume ([0-9]+).*");
|
||||||
|
Regex chapterRex = new(@"[Cc]apitolo ([0-9]+(?:\.[0-9]+)?).*");
|
||||||
|
Regex idRex = new(@".*\/read\/([a-z0-9]+)(?:[?\/].*)?");
|
||||||
|
if (chaptersWrapper.Descendants("div").Any(descendant => descendant.HasClass("volume-element")))
|
||||||
|
{
|
||||||
|
foreach (HtmlNode volNode in document.DocumentNode.SelectNodes("//div[contains(concat(' ',normalize-space(@class),' '),'volume-element')]"))
|
||||||
|
{
|
||||||
|
string volumeStr = volumeRex.Match(volNode.SelectNodes("div").First(node => node.HasClass("volume")).SelectSingleNode("p").InnerText).Groups[1].Value;
|
||||||
|
int volume = int.Parse(volumeStr);
|
||||||
|
foreach (HtmlNode chNode in volNode.SelectNodes("div").First(node => node.HasClass("volume-chapters")).SelectNodes("div"))
|
||||||
|
{
|
||||||
|
|
||||||
|
string numberStr = chapterRex.Match(chNode.SelectSingleNode("a").SelectSingleNode("span").InnerText).Groups[1].Value;
|
||||||
|
if(!ChapterNumber.CanParse(numberStr))
|
||||||
|
continue;
|
||||||
|
ChapterNumber chapterNumber = new(numberStr);
|
||||||
|
string url = chNode.SelectSingleNode("a").GetAttributeValue("href", "");
|
||||||
|
string id = idRex.Match(chNode.SelectSingleNode("a").GetAttributeValue("href", "")).Groups[1].Value;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ret.Add(new Chapter(manga, url, chapterNumber, volume, null));
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
foreach (HtmlNode chNode in chaptersWrapper.SelectNodes("div").Where(node => node.HasClass("chapter")))
|
||||||
|
{
|
||||||
|
string numberStr = chapterRex.Match(chNode.SelectSingleNode("a").SelectSingleNode("span").InnerText).Groups[1].Value;
|
||||||
|
if(!ChapterNumber.CanParse(numberStr))
|
||||||
|
continue;
|
||||||
|
ChapterNumber chapterNumber = new(numberStr);
|
||||||
|
string url = chNode.SelectSingleNode("a").GetAttributeValue("href", "");
|
||||||
|
string id = idRex.Match(chNode.SelectSingleNode("a").GetAttributeValue("href", "")).Groups[1].Value;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ret.Add(new Chapter(manga, url, chapterNumber, null, null));
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ret.Reverse();
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal override string[] GetChapterImageUrls(Chapter chapter)
|
||||||
|
{
|
||||||
|
string requestUrl = $"{chapter.Url}?style=list";
|
||||||
|
RequestResult requestResult =
|
||||||
|
downloadClient.MakeRequest(requestUrl, RequestType.Default);
|
||||||
|
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300 || requestResult.htmlDocument is null)
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
string[] imageUrls = ParseImageUrlsFromHtml(requestResult.htmlDocument);
|
||||||
|
return imageUrls;
|
||||||
|
}
|
||||||
|
|
||||||
|
private string[] ParseImageUrlsFromHtml(HtmlDocument document)
|
||||||
|
{
|
||||||
|
List<string> ret = new();
|
||||||
|
|
||||||
|
HtmlNode imageContainer =
|
||||||
|
document.DocumentNode.SelectSingleNode("//div[@id='page']");
|
||||||
|
foreach(HtmlNode imageNode in imageContainer.Descendants("img"))
|
||||||
|
ret.Add(imageNode.GetAttributeValue("src", ""));
|
||||||
|
|
||||||
|
return ret.ToArray();
|
||||||
|
}
|
||||||
|
}
|
181
API/Schema/MangaConnectors/ManhuaPlus.cs
Normal file
181
API/Schema/MangaConnectors/ManhuaPlus.cs
Normal file
@ -0,0 +1,181 @@
|
|||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using API.MangaDownloadClients;
|
||||||
|
using HtmlAgilityPack;
|
||||||
|
|
||||||
|
namespace API.Schema.MangaConnectors;
|
||||||
|
|
||||||
|
public class ManhuaPlus : MangaConnector
|
||||||
|
{
|
||||||
|
public ManhuaPlus() : base("ManhuaPlus", ["en"], ["manhuaplus.org"])
|
||||||
|
{
|
||||||
|
this.downloadClient = new ChromiumDownloadClient();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override (Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)[] GetManga(string publicationTitle = "")
|
||||||
|
{
|
||||||
|
string sanitizedTitle = string.Join(' ', Regex.Matches(publicationTitle, "[A-z]*").Where(str => str.Length > 0)).ToLower();
|
||||||
|
string requestUrl = $"https://manhuaplus.org/search?keyword={sanitizedTitle}";
|
||||||
|
RequestResult requestResult =
|
||||||
|
downloadClient.MakeRequest(requestUrl, RequestType.Default);
|
||||||
|
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300 || requestResult.htmlDocument is null)
|
||||||
|
return [];
|
||||||
|
|
||||||
|
(Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)[] publications = ParsePublicationsFromHtml(requestResult.htmlDocument);
|
||||||
|
return publications;
|
||||||
|
}
|
||||||
|
|
||||||
|
private (Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)[] ParsePublicationsFromHtml(HtmlDocument document)
|
||||||
|
{
|
||||||
|
if (document.DocumentNode.SelectSingleNode("//h1/../..").ChildNodes//I already want to not.
|
||||||
|
.Any(node => node.InnerText.Contains("No manga found")))
|
||||||
|
return [];
|
||||||
|
|
||||||
|
List<string> urls = document.DocumentNode
|
||||||
|
.SelectNodes("//h1/../..//a[contains(@href, 'https://manhuaplus.org/manga/') and contains(concat(' ',normalize-space(@class),' '),' clamp ') and not(contains(@href, '/chapter'))]")
|
||||||
|
.Select(mangaNode => mangaNode.GetAttributeValue("href", "")).ToList();
|
||||||
|
|
||||||
|
List<(Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)> ret = new();
|
||||||
|
foreach (string url in urls)
|
||||||
|
{
|
||||||
|
(Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)? manga = GetMangaFromUrl(url);
|
||||||
|
if (manga is { } x)
|
||||||
|
ret.Add(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override (Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)? GetMangaFromId(string publicationId)
|
||||||
|
{
|
||||||
|
return GetMangaFromUrl($"https://manhuaplus.org/manga/{publicationId}");
|
||||||
|
}
|
||||||
|
|
||||||
|
public override (Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)? GetMangaFromUrl(string url)
|
||||||
|
{
|
||||||
|
Regex publicationIdRex = new(@"https:\/\/manhuaplus.org\/manga\/(.*)(\/.*)*");
|
||||||
|
string publicationId = publicationIdRex.Match(url).Groups[1].Value;
|
||||||
|
|
||||||
|
RequestResult requestResult = this.downloadClient.MakeRequest(url, RequestType.MangaInfo);
|
||||||
|
if((int)requestResult.statusCode < 300 && (int)requestResult.statusCode >= 200 && requestResult.htmlDocument is not null && requestResult.redirectedToUrl != "https://manhuaplus.org/home") //When manga doesnt exists it redirects to home
|
||||||
|
return ParseSinglePublicationFromHtml(requestResult.htmlDocument, publicationId, url);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private (Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?) ParseSinglePublicationFromHtml(HtmlDocument document, string publicationId, string websiteUrl)
|
||||||
|
{
|
||||||
|
string originalLanguage = "", status = "";
|
||||||
|
Dictionary<string, string> altTitles = new(), links = new();
|
||||||
|
HashSet<string> tags = new();
|
||||||
|
MangaReleaseStatus releaseStatus = MangaReleaseStatus.Unreleased;
|
||||||
|
|
||||||
|
HtmlNode posterNode = document.DocumentNode.SelectSingleNode("/html/body/main/div/div/div[2]/div[1]/figure/a/img");//BRUH
|
||||||
|
Regex posterRex = new(@".*(\/uploads/covers/[a-zA-Z0-9\-\._\~\!\$\&\'\(\)\*\+\,\;\=\:\@]+).*");
|
||||||
|
string coverUrl = $"https://manhuaplus.org/{posterRex.Match(posterNode.GetAttributeValue("src", "")).Groups[1].Value}";
|
||||||
|
|
||||||
|
HtmlNode titleNode = document.DocumentNode.SelectSingleNode("//h1");
|
||||||
|
string sortName = titleNode.InnerText.Replace("\n", "");
|
||||||
|
|
||||||
|
List<string> authorNames = new();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
HtmlNode[] authorsNodes = document.DocumentNode
|
||||||
|
.SelectNodes("//a[contains(@href, 'https://manhuaplus.org/authors/')]")
|
||||||
|
.ToArray();
|
||||||
|
foreach (HtmlNode authorNode in authorsNodes)
|
||||||
|
authorNames.Add(authorNode.InnerText);
|
||||||
|
}
|
||||||
|
catch (ArgumentNullException e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
List<Author> authors = authorNames.Select(a => new Author(a)).ToList();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
HtmlNode[] genreNodes = document.DocumentNode
|
||||||
|
.SelectNodes("//a[contains(@href, 'https://manhuaplus.org/genres/')]").ToArray();
|
||||||
|
foreach (HtmlNode genreNode in genreNodes)
|
||||||
|
tags.Add(genreNode.InnerText.Replace("\n", ""));
|
||||||
|
}
|
||||||
|
catch (ArgumentNullException e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
List<MangaTag> mangaTags = tags.Select(t => new MangaTag(t)).ToList();
|
||||||
|
|
||||||
|
Regex yearRex = new(@"(?:[0-9]{1,2}\/){2}([0-9]{2,4}) [0-9]{1,2}:[0-9]{1,2}");
|
||||||
|
HtmlNode yearNode = document.DocumentNode.SelectSingleNode("//aside//i[contains(concat(' ',normalize-space(@class),' '),' fa-clock ')]/../span");
|
||||||
|
Match match = yearRex.Match(yearNode.InnerText);
|
||||||
|
uint year = match.Success && match.Groups[1].Success ? uint.Parse(match.Groups[1].Value) : 0;
|
||||||
|
|
||||||
|
status = document.DocumentNode.SelectSingleNode("//aside//i[contains(concat(' ',normalize-space(@class),' '),' fa-rss ')]/../span").InnerText.Replace("\n", "");
|
||||||
|
switch (status.ToLower())
|
||||||
|
{
|
||||||
|
case "cancelled": releaseStatus = MangaReleaseStatus.Cancelled; break;
|
||||||
|
case "hiatus": releaseStatus = MangaReleaseStatus.OnHiatus; break;
|
||||||
|
case "discontinued": releaseStatus = MangaReleaseStatus.Cancelled; break;
|
||||||
|
case "complete": releaseStatus = MangaReleaseStatus.Completed; break;
|
||||||
|
case "ongoing": releaseStatus = MangaReleaseStatus.Continuing; break;
|
||||||
|
}
|
||||||
|
|
||||||
|
HtmlNode descriptionNode = document.DocumentNode
|
||||||
|
.SelectSingleNode("//div[@id='syn-target']");
|
||||||
|
string description = descriptionNode.InnerText;
|
||||||
|
|
||||||
|
Manga manga = new (publicationId, sortName, description, websiteUrl, coverUrl, null, year,
|
||||||
|
originalLanguage, releaseStatus, -1,
|
||||||
|
this,
|
||||||
|
authors,
|
||||||
|
mangaTags,
|
||||||
|
[],
|
||||||
|
[]);
|
||||||
|
|
||||||
|
return (manga, authors, mangaTags, [], []);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override Chapter[] GetChapters(Manga manga, string language="en")
|
||||||
|
{
|
||||||
|
RequestResult result = downloadClient.MakeRequest($"https://manhuaplus.org/manga/{manga.MangaId}", RequestType.Default);
|
||||||
|
if ((int)result.statusCode < 200 || (int)result.statusCode >= 300 || result.htmlDocument is null)
|
||||||
|
{
|
||||||
|
return Array.Empty<Chapter>();
|
||||||
|
}
|
||||||
|
|
||||||
|
HtmlNodeCollection chapterNodes = result.htmlDocument.DocumentNode.SelectNodes("//li[contains(concat(' ',normalize-space(@class),' '),' chapter ')]//a");
|
||||||
|
string[] urls = chapterNodes.Select(node => node.GetAttributeValue("href", "")).ToArray();
|
||||||
|
Regex urlRex = new (@".*\/chapter-([0-9\-]+).*");
|
||||||
|
|
||||||
|
List<Chapter> chapters = new();
|
||||||
|
foreach (string url in urls)
|
||||||
|
{
|
||||||
|
Match rexMatch = urlRex.Match(url);
|
||||||
|
|
||||||
|
if(!ChapterNumber.CanParse(rexMatch.Groups[1].Value))
|
||||||
|
continue;
|
||||||
|
ChapterNumber chapterNumber = new(rexMatch.Groups[1].Value);
|
||||||
|
string fullUrl = url;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
chapters.Add(new Chapter(manga, fullUrl, chapterNumber, null, null));
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//Return Chapters ordered by Chapter-Number
|
||||||
|
return chapters.Order().ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
internal override string[] GetChapterImageUrls(Chapter chapter)
|
||||||
|
{
|
||||||
|
RequestResult requestResult = this.downloadClient.MakeRequest(chapter.Url, RequestType.Default);
|
||||||
|
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300 || requestResult.htmlDocument is null)
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
HtmlDocument document = requestResult.htmlDocument;
|
||||||
|
|
||||||
|
HtmlNode[] images = document.DocumentNode.SelectNodes("//a[contains(concat(' ',normalize-space(@class),' '),' readImg ')]/img").ToArray();
|
||||||
|
List<string> urls = images.Select(node => node.GetAttributeValue("src", "")).ToList();
|
||||||
|
return urls.ToArray();
|
||||||
|
}
|
||||||
|
}
|
228
API/Schema/MangaConnectors/WeebCentral.cs
Normal file
228
API/Schema/MangaConnectors/WeebCentral.cs
Normal file
@ -0,0 +1,228 @@
|
|||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using API.MangaDownloadClients;
|
||||||
|
using HtmlAgilityPack;
|
||||||
|
using Soenneker.Utils.String.NeedlemanWunsch;
|
||||||
|
|
||||||
|
namespace API.Schema.MangaConnectors;
|
||||||
|
|
||||||
|
public class Weebcentral : MangaConnector
|
||||||
|
{
|
||||||
|
private readonly string _baseUrl = "https://weebcentral.com";
|
||||||
|
|
||||||
|
private readonly string[] _filterWords =
|
||||||
|
{ "a", "the", "of", "as", "to", "no", "for", "on", "with", "be", "and", "in", "wa", "at", "be", "ni" };
|
||||||
|
|
||||||
|
public Weebcentral() : base("Weebcentral", ["en"], ["https://weebcentral.com"])
|
||||||
|
{
|
||||||
|
downloadClient = new ChromiumDownloadClient();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override (Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)[] GetManga(string publicationTitle = "")
|
||||||
|
{
|
||||||
|
const int limit = 32; //How many values we want returned at once
|
||||||
|
var offset = 0; //"Page"
|
||||||
|
var requestUrl =
|
||||||
|
$"{_baseUrl}/search/data?limit={limit}&offset={offset}&text={publicationTitle}&sort=Best+Match&order=Ascending&official=Any&display_mode=Minimal%20Display";
|
||||||
|
var requestResult =
|
||||||
|
downloadClient.MakeRequest(requestUrl, RequestType.Default);
|
||||||
|
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300 ||
|
||||||
|
requestResult.htmlDocument == null)
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
var publications = ParsePublicationsFromHtml(requestResult.htmlDocument);
|
||||||
|
|
||||||
|
return publications;
|
||||||
|
}
|
||||||
|
|
||||||
|
private (Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)[] ParsePublicationsFromHtml(HtmlDocument document)
|
||||||
|
{
|
||||||
|
if (document.DocumentNode.SelectNodes("//article") == null)
|
||||||
|
return [];
|
||||||
|
|
||||||
|
var urls = document.DocumentNode.SelectNodes("/html/body/article/a[@class='link link-hover']")
|
||||||
|
.Select(elem => elem.GetAttributeValue("href", "")).ToList();
|
||||||
|
|
||||||
|
List<(Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)> ret = new();
|
||||||
|
foreach (var url in urls)
|
||||||
|
{
|
||||||
|
var manga = GetMangaFromUrl(url);
|
||||||
|
if (manga is { } x)
|
||||||
|
ret.Add(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override (Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)? GetMangaFromUrl(string url)
|
||||||
|
{
|
||||||
|
Regex publicationIdRex = new(@"https:\/\/weebcentral\.com\/series\/(\w*)\/(.*)");
|
||||||
|
var publicationId = publicationIdRex.Match(url).Groups[1].Value;
|
||||||
|
|
||||||
|
var requestResult = downloadClient.MakeRequest(url, RequestType.MangaInfo);
|
||||||
|
if ((int)requestResult.statusCode < 300 && (int)requestResult.statusCode >= 200 &&
|
||||||
|
requestResult.htmlDocument is not null)
|
||||||
|
return ParseSinglePublicationFromHtml(requestResult.htmlDocument, publicationId, url);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private (Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?) ParseSinglePublicationFromHtml(HtmlDocument document, string publicationId, string websiteUrl)
|
||||||
|
{
|
||||||
|
var posterNode =
|
||||||
|
document.DocumentNode.SelectSingleNode("//section[@class='flex items-center justify-center']/picture/img");
|
||||||
|
var coverUrl = posterNode?.GetAttributeValue("src", "") ?? "";
|
||||||
|
|
||||||
|
var titleNode = document.DocumentNode.SelectSingleNode("//section/h1");
|
||||||
|
var sortName = titleNode?.InnerText ?? "Undefined";
|
||||||
|
|
||||||
|
HtmlNode[] authorsNodes =
|
||||||
|
document.DocumentNode.SelectNodes("//ul/li[strong/text() = 'Author(s): ']/span")?.ToArray() ?? [];
|
||||||
|
var authorNames = authorsNodes.Select(n => n.InnerText).ToList();
|
||||||
|
List<Author> authors = authorNames.Select(n => new Author(n)).ToList();
|
||||||
|
|
||||||
|
HtmlNode[] genreNodes =
|
||||||
|
document.DocumentNode.SelectNodes("//ul/li[strong/text() = 'Tags(s): ']/span")?.ToArray() ?? [];
|
||||||
|
HashSet<string> tags = genreNodes.Select(n => n.InnerText).ToHashSet();
|
||||||
|
List<MangaTag> mangaTags = tags.Select(t => new MangaTag(t)).ToList();
|
||||||
|
|
||||||
|
var statusNode = document.DocumentNode.SelectSingleNode("//ul/li[strong/text() = 'Status: ']/a");
|
||||||
|
var status = statusNode?.InnerText ?? "";
|
||||||
|
var releaseStatus = MangaReleaseStatus.Unreleased;
|
||||||
|
switch (status.ToLower())
|
||||||
|
{
|
||||||
|
case "cancelled": releaseStatus = MangaReleaseStatus.Cancelled; break;
|
||||||
|
case "hiatus": releaseStatus = MangaReleaseStatus.OnHiatus; break;
|
||||||
|
case "complete": releaseStatus = MangaReleaseStatus.Completed; break;
|
||||||
|
case "ongoing": releaseStatus = MangaReleaseStatus.Continuing; break;
|
||||||
|
}
|
||||||
|
|
||||||
|
var yearNode = document.DocumentNode.SelectSingleNode("//ul/li[strong/text() = 'Released: ']/span");
|
||||||
|
var year = uint.Parse(yearNode?.InnerText ?? "0");
|
||||||
|
|
||||||
|
var descriptionNode = document.DocumentNode.SelectSingleNode("//ul/li[strong/text() = 'Description']/p");
|
||||||
|
var description = descriptionNode?.InnerText ?? "Undefined";
|
||||||
|
|
||||||
|
HtmlNode[] altTitleNodes = document.DocumentNode
|
||||||
|
.SelectNodes("//ul/li[strong/text() = 'Associated Name(s)']/ul/li")?.ToArray() ?? [];
|
||||||
|
Dictionary<string, string> altTitlesDict = new(), links = new();
|
||||||
|
for (var i = 0; i < altTitleNodes.Length; i++)
|
||||||
|
altTitlesDict.Add(i.ToString(), altTitleNodes[i].InnerText);
|
||||||
|
List<MangaAltTitle> altTitles = altTitlesDict.Select(a => new MangaAltTitle(a.Key, a.Value)).ToList();
|
||||||
|
|
||||||
|
var originalLanguage = "";
|
||||||
|
|
||||||
|
Manga manga = new (publicationId, sortName, description, websiteUrl, coverUrl, null, year,
|
||||||
|
originalLanguage, releaseStatus, -1,
|
||||||
|
this,
|
||||||
|
authors,
|
||||||
|
mangaTags,
|
||||||
|
[],
|
||||||
|
altTitles);
|
||||||
|
|
||||||
|
return (manga, authors, mangaTags, [], altTitles);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override (Manga, List<Author>?, List<MangaTag>?, List<Link>?, List<MangaAltTitle>?)? GetMangaFromId(string publicationId)
|
||||||
|
{
|
||||||
|
return GetMangaFromUrl($"https://weebcentral.com/series/{publicationId}");
|
||||||
|
}
|
||||||
|
|
||||||
|
private string ToFilteredString(string input)
|
||||||
|
{
|
||||||
|
return string.Join(' ', input.ToLower().Split(' ').Where(word => _filterWords.Contains(word) == false));
|
||||||
|
}
|
||||||
|
|
||||||
|
private SearchResult[] FilteredResults(string publicationTitle, SearchResult[] unfilteredSearchResults)
|
||||||
|
{
|
||||||
|
Dictionary<SearchResult, int> similarity = new();
|
||||||
|
foreach (var sr in unfilteredSearchResults)
|
||||||
|
{
|
||||||
|
List<int> scores = new();
|
||||||
|
var filteredPublicationString = ToFilteredString(publicationTitle);
|
||||||
|
var filteredSString = ToFilteredString(sr.s);
|
||||||
|
scores.Add(NeedlemanWunschStringUtil.CalculateSimilarity(filteredSString, filteredPublicationString));
|
||||||
|
foreach (var srA in sr.a)
|
||||||
|
{
|
||||||
|
var filteredAString = ToFilteredString(srA);
|
||||||
|
scores.Add(NeedlemanWunschStringUtil.CalculateSimilarity(filteredAString, filteredPublicationString));
|
||||||
|
}
|
||||||
|
|
||||||
|
similarity.Add(sr, scores.Sum() / scores.Count);
|
||||||
|
}
|
||||||
|
|
||||||
|
var ret = similarity.OrderBy(s => s.Value).Take(10).Select(s => s.Key).ToList();
|
||||||
|
return ret.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override Chapter[] GetChapters(Manga manga, string language = "en")
|
||||||
|
{
|
||||||
|
var requestUrl = $"{_baseUrl}/series/{manga.MangaId}/full-chapter-list";
|
||||||
|
var requestResult =
|
||||||
|
downloadClient.MakeRequest(requestUrl, RequestType.Default);
|
||||||
|
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
||||||
|
return Array.Empty<Chapter>();
|
||||||
|
|
||||||
|
//Return Chapters ordered by Chapter-Number
|
||||||
|
if (requestResult.htmlDocument is null)
|
||||||
|
return Array.Empty<Chapter>();
|
||||||
|
var chapters = ParseChaptersFromHtml(manga, requestResult.htmlDocument);
|
||||||
|
return chapters.Order().ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Chapter> ParseChaptersFromHtml(Manga manga, HtmlDocument document)
|
||||||
|
{
|
||||||
|
var chaptersWrapper = document.DocumentNode.SelectSingleNode("/html/body");
|
||||||
|
|
||||||
|
Regex chapterRex = new(@".* (\d+)");
|
||||||
|
Regex idRex = new(@"https:\/\/weebcentral\.com\/chapters\/(\w*)");
|
||||||
|
|
||||||
|
var ret = chaptersWrapper.Descendants("a").Select(elem =>
|
||||||
|
{
|
||||||
|
var url = elem.GetAttributeValue("href", "") ?? "Undefined";
|
||||||
|
|
||||||
|
if (!url.StartsWith("https://") && !url.StartsWith("http://"))
|
||||||
|
return new Chapter(manga, "undefined", new ChapterNumber(-1), null, null);
|
||||||
|
|
||||||
|
var idMatch = idRex.Match(url);
|
||||||
|
var id = idMatch.Success ? idMatch.Groups[1].Value : null;
|
||||||
|
|
||||||
|
var chapterNode = elem.SelectSingleNode("span[@class='grow flex items-center gap-2']/span")?.InnerText ??
|
||||||
|
"Undefined";
|
||||||
|
|
||||||
|
var chapterNumberMatch = chapterRex.Match(chapterNode);
|
||||||
|
|
||||||
|
if(!chapterNumberMatch.Success || !ChapterNumber.CanParse(chapterNumberMatch.Groups[1].Value))
|
||||||
|
return new Chapter(manga, "undefined", new ChapterNumber(-1), null, null);
|
||||||
|
ChapterNumber chapterNumber = new(chapterNumberMatch.Groups[1].Value);
|
||||||
|
|
||||||
|
return new Chapter(manga, url, chapterNumber, null, null);
|
||||||
|
}).Where(elem => elem.ChapterNumber < ChapterNumber.Zero && elem.Url != "undefined").ToList();
|
||||||
|
|
||||||
|
ret.Reverse();
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal override string[] GetChapterImageUrls(Chapter chapter)
|
||||||
|
{
|
||||||
|
var requestResult = downloadClient.MakeRequest(chapter.Url, RequestType.Default);
|
||||||
|
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300 ||requestResult.htmlDocument is null)
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
var document = requestResult.htmlDocument;
|
||||||
|
|
||||||
|
var imageNodes =
|
||||||
|
document.DocumentNode.SelectNodes($"//section[@hx-get='{chapter.Url}/images']/img")?.ToArray() ?? [];
|
||||||
|
var urls = imageNodes.Select(imgNode => imgNode.GetAttributeValue("src", "")).ToArray();
|
||||||
|
return urls;
|
||||||
|
}
|
||||||
|
|
||||||
|
private struct SearchResult
|
||||||
|
{
|
||||||
|
public string i { get; set; }
|
||||||
|
public string s { get; set; }
|
||||||
|
public string[] a { get; set; }
|
||||||
|
}
|
||||||
|
}
|
10
API/Schema/MangaReleaseStatus.cs
Normal file
10
API/Schema/MangaReleaseStatus.cs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
namespace API.Schema;
|
||||||
|
|
||||||
|
public enum MangaReleaseStatus : byte
|
||||||
|
{
|
||||||
|
Continuing = 0,
|
||||||
|
Completed = 1,
|
||||||
|
OnHiatus = 2,
|
||||||
|
Cancelled = 3,
|
||||||
|
Unreleased = 4
|
||||||
|
}
|
9
API/Schema/MangaTag.cs
Normal file
9
API/Schema/MangaTag.cs
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace API.Schema;
|
||||||
|
|
||||||
|
[PrimaryKey("Tag")]
|
||||||
|
public class MangaTag(string tag)
|
||||||
|
{
|
||||||
|
public string Tag { get; init; } = tag;
|
||||||
|
}
|
21
API/Schema/Notification.cs
Normal file
21
API/Schema/Notification.cs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace API.Schema;
|
||||||
|
|
||||||
|
[PrimaryKey("NotificationId")]
|
||||||
|
public class Notification(string title, string message = "", NotificationUrgency urgency = NotificationUrgency.Normal, DateTime? date = null)
|
||||||
|
{
|
||||||
|
[MaxLength(64)]
|
||||||
|
public string NotificationId { get; init; } = TokenGen.CreateToken("Notification", 64);
|
||||||
|
|
||||||
|
public NotificationUrgency Urgency { get; init; } = urgency;
|
||||||
|
|
||||||
|
public string Title { get; init; } = title;
|
||||||
|
|
||||||
|
public string Message { get; init; } = message;
|
||||||
|
|
||||||
|
public DateTime Date { get; init; } = date ?? DateTime.UtcNow;
|
||||||
|
|
||||||
|
public Notification() : this("") { }
|
||||||
|
}
|
@ -1,38 +1,31 @@
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using Logging;
|
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace Tranga.NotificationManagers;
|
namespace API.Schema.NotificationConnectors;
|
||||||
|
|
||||||
public class Gotify : NotificationManager
|
public class Gotify(string endpoint, string appToken)
|
||||||
|
: NotificationConnector(TokenGen.CreateToken(typeof(Gotify), 64), NotificationConnectorType.Gotify)
|
||||||
{
|
{
|
||||||
public string endpoint { get; }
|
public string Endpoint { get; init; } = endpoint;
|
||||||
public string appToken { get; }
|
public string AppToken { get; init; } = appToken;
|
||||||
private readonly HttpClient _client = new();
|
|
||||||
|
|
||||||
public Gotify(string endpoint, string appToken, Logger? logger = null) : base(NotificationManagerType.Gotify, logger)
|
|
||||||
{
|
|
||||||
this.endpoint = endpoint;
|
|
||||||
this.appToken = appToken;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void SendNotification(string title, string notificationText)
|
public override void SendNotification(string title, string notificationText)
|
||||||
{
|
{
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Sending notification: {title} - {notificationText}");
|
|
||||||
MessageData message = new(title, notificationText);
|
MessageData message = new(title, notificationText);
|
||||||
HttpRequestMessage request = new(HttpMethod.Post, $"{endpoint}/message");
|
HttpRequestMessage request = new(HttpMethod.Post, $"{endpoint}/message");
|
||||||
request.Headers.Add("X-Gotify-Key", this.appToken);
|
request.Headers.Add("X-Gotify-Key", this.AppToken);
|
||||||
request.Content = new StringContent(JsonConvert.SerializeObject(message, Formatting.None), Encoding.UTF8, "application/json");
|
request.Content = new StringContent(JsonConvert.SerializeObject(message, Formatting.None), Encoding.UTF8, "application/json");
|
||||||
HttpResponseMessage response = _client.Send(request);
|
HttpResponseMessage response = _client.Send(request);
|
||||||
if (!response.IsSuccessStatusCode)
|
if (!response.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
StreamReader sr = new (response.Content.ReadAsStream());
|
StreamReader sr = new (response.Content.ReadAsStream());
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"{response.StatusCode}: {sr.ReadToEnd()}");
|
//TODO
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class MessageData
|
private class MessageData
|
||||||
{
|
{
|
||||||
|
// ReSharper disable four times UnusedAutoPropertyAccessor.Local
|
||||||
public string message { get; }
|
public string message { get; }
|
||||||
public long priority { get; }
|
public long priority { get; }
|
||||||
public string title { get; }
|
public string title { get; }
|
@ -1,43 +1,35 @@
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using Logging;
|
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace Tranga.NotificationManagers;
|
namespace API.Schema.NotificationConnectors;
|
||||||
|
|
||||||
public class LunaSea : NotificationManager
|
public class Lunasea(string id)
|
||||||
|
: NotificationConnector(TokenGen.CreateToken(typeof(Lunasea), 64), NotificationConnectorType.LunaSea)
|
||||||
{
|
{
|
||||||
public string webhook { get; }
|
public string Id { get; init; } = id;
|
||||||
private readonly HttpClient _client = new();
|
|
||||||
public LunaSea(string webhook, Logger? logger = null) : base(NotificationManagerType.LunaSea, logger)
|
|
||||||
{
|
|
||||||
this.webhook = webhook;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void SendNotification(string title, string notificationText)
|
public override void SendNotification(string title, string notificationText)
|
||||||
{
|
{
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Sending notification: {title} - {notificationText}");
|
|
||||||
MessageData message = new(title, notificationText);
|
MessageData message = new(title, notificationText);
|
||||||
HttpRequestMessage request = new(HttpMethod.Post, webhook);
|
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");
|
request.Content = new StringContent(JsonConvert.SerializeObject(message, Formatting.None), Encoding.UTF8, "application/json");
|
||||||
HttpResponseMessage response = _client.Send(request);
|
HttpResponseMessage response = _client.Send(request);
|
||||||
if (!response.IsSuccessStatusCode)
|
if (!response.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
StreamReader sr = new (response.Content.ReadAsStream());
|
StreamReader sr = new (response.Content.ReadAsStream());
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"{response.StatusCode}: {sr.ReadToEnd()}");
|
//TODO
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class MessageData
|
private class MessageData
|
||||||
{
|
{
|
||||||
|
// ReSharper disable twice UnusedAutoPropertyAccessor.Local
|
||||||
public string title { get; }
|
public string title { get; }
|
||||||
public string body { get; }
|
public string body { get; }
|
||||||
public string image { get; }
|
|
||||||
|
|
||||||
public MessageData(string title, string body)
|
public MessageData(string title, string body)
|
||||||
{
|
{
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.body = body;
|
this.body = body;
|
||||||
this.image = "";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
20
API/Schema/NotificationConnectors/NotificationConnector.cs
Normal file
20
API/Schema/NotificationConnectors/NotificationConnector.cs
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace API.Schema.NotificationConnectors;
|
||||||
|
|
||||||
|
[PrimaryKey("NotificationConnectorId")]
|
||||||
|
public abstract class NotificationConnector(string notificationConnectorId, NotificationConnectorType notificationConnectorType)
|
||||||
|
{
|
||||||
|
[MaxLength(64)]
|
||||||
|
public string NotificationConnectorId { get; } = notificationConnectorId;
|
||||||
|
public NotificationConnectorType NotificationConnectorType { get; init; } = notificationConnectorType;
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
|
[NotMapped]
|
||||||
|
protected readonly HttpClient _client = new();
|
||||||
|
|
||||||
|
public abstract void SendNotification(string title, string notificationText);
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
namespace API.Schema.NotificationConnectors;
|
||||||
|
|
||||||
|
|
||||||
|
public enum NotificationConnectorType : byte
|
||||||
|
{
|
||||||
|
Gotify = 0,
|
||||||
|
LunaSea = 1,
|
||||||
|
Ntfy = 2
|
||||||
|
}
|
77
API/Schema/NotificationConnectors/Ntfy.cs
Normal file
77
API/Schema/NotificationConnectors/Ntfy.cs
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace API.Schema.NotificationConnectors;
|
||||||
|
|
||||||
|
public class Ntfy : NotificationConnector
|
||||||
|
{
|
||||||
|
private NotificationConnector _notificationConnectorImplementation;
|
||||||
|
public string Endpoint { get; init; }
|
||||||
|
public string Auth { get; init; }
|
||||||
|
public string Topic { get; init; }
|
||||||
|
|
||||||
|
public Ntfy(string endpoint, string auth, string topic): base(TokenGen.CreateToken(typeof(Ntfy), 64), NotificationConnectorType.Ntfy)
|
||||||
|
{
|
||||||
|
Endpoint = endpoint;
|
||||||
|
Auth = auth;
|
||||||
|
Topic = topic;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Ntfy(string endpoint, string username, string password, string? topic = null) :
|
||||||
|
this(EndpointAndTopicFromUrl(endpoint)[0], topic??EndpointAndTopicFromUrl(endpoint)[1], AuthFromUsernamePassword(username, password))
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string AuthFromUsernamePassword(string username, string password)
|
||||||
|
{
|
||||||
|
string authHeader = "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes($"{username}:{password}"));
|
||||||
|
string authParam = Convert.ToBase64String(Encoding.UTF8.GetBytes(authHeader)).Replace("=","");
|
||||||
|
return authParam;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string[] EndpointAndTopicFromUrl(string url)
|
||||||
|
{
|
||||||
|
string[] ret = new string[2];
|
||||||
|
Regex rootUriRex = new(@"(https?:\/\/[a-zA-Z0-9-\.]+\.[a-zA-Z0-9]+)(?:\/([a-zA-Z0-9-\.]+))?.*");
|
||||||
|
Match match = rootUriRex.Match(url);
|
||||||
|
if(!match.Success)
|
||||||
|
throw new ArgumentException($"Error getting URI from provided endpoint-URI: {url}");
|
||||||
|
|
||||||
|
ret[0] = match.Groups[1].Value;
|
||||||
|
ret[1] = match.Groups[2].Success && match.Groups[2].Value.Length > 0 ? match.Groups[2].Value : "tranga";
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void SendNotification(string title, string notificationText)
|
||||||
|
{
|
||||||
|
MessageData message = new(title, Topic, notificationText);
|
||||||
|
HttpRequestMessage request = new(HttpMethod.Post, $"{this.Endpoint}?auth={this.Auth}");
|
||||||
|
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());
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class MessageData
|
||||||
|
{
|
||||||
|
// ReSharper disable UnusedAutoPropertyAccessor.Local
|
||||||
|
public string topic { get; }
|
||||||
|
public string title { get; }
|
||||||
|
public string message { get; }
|
||||||
|
public int priority { get; }
|
||||||
|
|
||||||
|
public MessageData(string title, string topic, string message)
|
||||||
|
{
|
||||||
|
this.topic = topic;
|
||||||
|
this.title = title;
|
||||||
|
this.message = message;
|
||||||
|
this.priority = 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
8
API/Schema/NotificationUrgency.cs
Normal file
8
API/Schema/NotificationUrgency.cs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
namespace API.Schema;
|
||||||
|
|
||||||
|
public enum NotificationUrgency : byte
|
||||||
|
{
|
||||||
|
Low = 1,
|
||||||
|
Normal = 3,
|
||||||
|
High = 5
|
||||||
|
}
|
109
API/Schema/PgsqlContext.cs
Normal file
109
API/Schema/PgsqlContext.cs
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
using API.Schema.Jobs;
|
||||||
|
using API.Schema.LibraryConnectors;
|
||||||
|
using API.Schema.MangaConnectors;
|
||||||
|
using API.Schema.NotificationConnectors;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace API.Schema;
|
||||||
|
|
||||||
|
public class PgsqlContext(DbContextOptions<PgsqlContext> options) : DbContext(options)
|
||||||
|
{
|
||||||
|
public DbSet<Job> Jobs { get; set; }
|
||||||
|
public DbSet<MangaConnector> MangaConnectors { get; set; }
|
||||||
|
public DbSet<Manga> Manga { get; set; }
|
||||||
|
public DbSet<Chapter> Chapters { get; set; }
|
||||||
|
public DbSet<Author> Authors { get; set; }
|
||||||
|
public DbSet<Link> Link { get; set; }
|
||||||
|
public DbSet<MangaTag> Tags { get; set; }
|
||||||
|
public DbSet<MangaAltTitle> AltTitles { get; set; }
|
||||||
|
public DbSet<LibraryConnector> LibraryConnectors { get; set; }
|
||||||
|
public DbSet<NotificationConnector> NotificationConnectors { get; set; }
|
||||||
|
public DbSet<Notification> Notifications { get; set; }
|
||||||
|
|
||||||
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
modelBuilder.Entity<MangaConnector>()
|
||||||
|
.HasDiscriminator(c => c.Name)
|
||||||
|
.HasValue<AsuraToon>("AsuraToon")
|
||||||
|
.HasValue<Bato>("Bato")
|
||||||
|
.HasValue<MangaHere>("MangaHere")
|
||||||
|
.HasValue<MangaKatana>("MangaKatana")
|
||||||
|
.HasValue<MangaLife>("Manga4Life")
|
||||||
|
.HasValue<Manganato>("Manganato")
|
||||||
|
.HasValue<Mangasee>("Mangasee")
|
||||||
|
.HasValue<Mangaworld>("Mangaworld")
|
||||||
|
.HasValue<ManhuaPlus>("ManhuaPlus")
|
||||||
|
.HasValue<Weebcentral>("Weebcentral")
|
||||||
|
.HasValue<MangaDex>("MangaDex");
|
||||||
|
modelBuilder.Entity<LibraryConnector>()
|
||||||
|
.HasDiscriminator<LibraryType>(l => l.LibraryType)
|
||||||
|
.HasValue<Komga>(LibraryType.Komga)
|
||||||
|
.HasValue<Kavita>(LibraryType.Kavita);
|
||||||
|
modelBuilder.Entity<NotificationConnector>()
|
||||||
|
.HasDiscriminator<NotificationConnectorType>(n => n.NotificationConnectorType)
|
||||||
|
.HasValue<Gotify>(NotificationConnectorType.Gotify)
|
||||||
|
.HasValue<Ntfy>(NotificationConnectorType.Ntfy)
|
||||||
|
.HasValue<Lunasea>(NotificationConnectorType.LunaSea);
|
||||||
|
|
||||||
|
modelBuilder.Entity<Job>()
|
||||||
|
.HasDiscriminator<JobType>(j => j.JobType)
|
||||||
|
.HasValue<MoveFileOrFolderJob>(JobType.MoveFileOrFolderJob)
|
||||||
|
.HasValue<DownloadNewChaptersJob>(JobType.DownloadNewChaptersJob)
|
||||||
|
.HasValue<DownloadSingleChapterJob>(JobType.DownloadSingleChapterJob)
|
||||||
|
.HasValue<UpdateMetadataJob>(JobType.UpdateMetaDataJob);
|
||||||
|
modelBuilder.Entity<Job>()
|
||||||
|
.HasOne<Job>(j => j.ParentJob)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey(j => j.ParentJobId);
|
||||||
|
modelBuilder.Entity<Job>()
|
||||||
|
.HasMany<Job>(j => j.DependsOnJobs);
|
||||||
|
modelBuilder.Entity<DownloadNewChaptersJob>()
|
||||||
|
.Navigation(dncj => dncj.Manga)
|
||||||
|
.AutoInclude();
|
||||||
|
modelBuilder.Entity<DownloadSingleChapterJob>()
|
||||||
|
.Navigation(dscj => dscj.Chapter)
|
||||||
|
.AutoInclude();
|
||||||
|
modelBuilder.Entity<UpdateMetadataJob>()
|
||||||
|
.Navigation(umj => umj.Manga)
|
||||||
|
.AutoInclude();
|
||||||
|
|
||||||
|
modelBuilder.Entity<Manga>()
|
||||||
|
.HasOne<MangaConnector>(m => m.MangaConnector)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey(m => m.MangaConnectorId);
|
||||||
|
modelBuilder.Entity<Manga>()
|
||||||
|
.Navigation(m => m.MangaConnector)
|
||||||
|
.AutoInclude();
|
||||||
|
modelBuilder.Entity<Manga>()
|
||||||
|
.HasMany<Author>(m => m.Authors)
|
||||||
|
.WithMany();
|
||||||
|
modelBuilder.Entity<Manga>()
|
||||||
|
.Navigation(m => m.Authors)
|
||||||
|
.AutoInclude();
|
||||||
|
modelBuilder.Entity<Manga>()
|
||||||
|
.HasMany<MangaTag>(m => m.Tags)
|
||||||
|
.WithMany();
|
||||||
|
modelBuilder.Entity<Manga>()
|
||||||
|
.Navigation(m => m.Tags)
|
||||||
|
.AutoInclude();
|
||||||
|
modelBuilder.Entity<Manga>()
|
||||||
|
.HasMany<Link>(m => m.Links)
|
||||||
|
.WithOne();
|
||||||
|
modelBuilder.Entity<Manga>()
|
||||||
|
.Navigation(m => m.Links)
|
||||||
|
.AutoInclude();
|
||||||
|
modelBuilder.Entity<Manga>()
|
||||||
|
.HasMany<MangaAltTitle>(m => m.AltTitles)
|
||||||
|
.WithOne();
|
||||||
|
modelBuilder.Entity<Manga>()
|
||||||
|
.Navigation(m => m.AltTitles)
|
||||||
|
.AutoInclude();
|
||||||
|
modelBuilder.Entity<Chapter>()
|
||||||
|
.HasOne<Manga>(c => c.ParentManga)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey(c => c.ParentMangaId);
|
||||||
|
modelBuilder.Entity<Chapter>()
|
||||||
|
.Navigation(c => c.ParentManga)
|
||||||
|
.AutoInclude();
|
||||||
|
}
|
||||||
|
}
|
@ -1,72 +0,0 @@
|
|||||||
using System.Net;
|
|
||||||
using System.Text;
|
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
using Logging;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
using Tranga;
|
|
||||||
|
|
||||||
namespace API;
|
|
||||||
|
|
||||||
public class Server
|
|
||||||
{
|
|
||||||
private readonly HttpListener _listener = new ();
|
|
||||||
private readonly RequestHandler _requestHandler;
|
|
||||||
internal readonly Logger? logger;
|
|
||||||
|
|
||||||
private readonly Regex _validUrl =
|
|
||||||
new (@"https?:\/\/(www\.)?[-A-z0-9]{1,256}(\.[-a-zA-Z0-9]{1,6})?(:[0-9]{1,5})?(\/{1}[A-z0-9()@:%_\+.~#?&=]+)*\/?");
|
|
||||||
public Server(int port, TaskManager taskManager, Logger? logger = null)
|
|
||||||
{
|
|
||||||
this.logger = logger;
|
|
||||||
this._listener.Prefixes.Add($"http://*:{port}/");
|
|
||||||
this._requestHandler = new RequestHandler(taskManager, this);
|
|
||||||
Listen();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Listen()
|
|
||||||
{
|
|
||||||
this._listener.Start();
|
|
||||||
foreach (string prefix in this._listener.Prefixes)
|
|
||||||
this.logger?.WriteLine(this.GetType().ToString(), $"Listening on {prefix}");
|
|
||||||
while (this._listener.IsListening)
|
|
||||||
{
|
|
||||||
HttpListenerContext context = this._listener.GetContextAsync().Result;
|
|
||||||
Task t = new (() =>
|
|
||||||
{
|
|
||||||
HandleContext(context);
|
|
||||||
});
|
|
||||||
t.Start();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void HandleContext(HttpListenerContext context)
|
|
||||||
{
|
|
||||||
HttpListenerRequest request = context.Request;
|
|
||||||
HttpListenerResponse response = context.Response;
|
|
||||||
//logger?.WriteLine(this.GetType().ToString(), $"New request: {request.HttpMethod} {request.Url}");
|
|
||||||
|
|
||||||
if (!_validUrl.IsMatch(request.Url!.ToString()))
|
|
||||||
{
|
|
||||||
SendResponse(HttpStatusCode.BadRequest, response);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
_requestHandler.HandleRequest(request, response);
|
|
||||||
}
|
|
||||||
|
|
||||||
internal 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";
|
|
||||||
response.OutputStream.Write(content is not null
|
|
||||||
? Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(content))
|
|
||||||
: Array.Empty<byte>());
|
|
||||||
response.OutputStream.Close();
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
40
API/TokenGen.cs
Normal file
40
API/TokenGen.cs
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
using System.Security.Cryptography;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace API;
|
||||||
|
|
||||||
|
public static class TokenGen
|
||||||
|
{
|
||||||
|
private const uint MinimumLength = 8;
|
||||||
|
private const string Chars = "abcdefghijklmnopqrstuvwxyz0123456789";
|
||||||
|
|
||||||
|
public static string CreateToken(Type t, uint fullLength) => CreateToken(t.Name, fullLength);
|
||||||
|
|
||||||
|
public static string CreateToken(string prefix, uint fullLength)
|
||||||
|
{
|
||||||
|
if (prefix.Length + 1 >= fullLength - MinimumLength)
|
||||||
|
throw new ArgumentException("Prefix to long to create Token of meaningful length.");
|
||||||
|
long l = fullLength - prefix.Length - 1;
|
||||||
|
byte[] rng = new byte[l];
|
||||||
|
RandomNumberGenerator.Create().GetBytes(rng);
|
||||||
|
string key = new (rng.Select(b => Chars[b % Chars.Length]).ToArray());
|
||||||
|
key = string.Join('-', prefix, key);
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string CreateTokenHash(string prefix, uint fullLength, string[] keys)
|
||||||
|
{
|
||||||
|
if (prefix.Length + 1 >= fullLength - MinimumLength)
|
||||||
|
throw new ArgumentException("Prefix to long to create Token of meaningful length.");
|
||||||
|
int l = (int)(fullLength - prefix.Length - 1);
|
||||||
|
MD5 md5 = MD5.Create();
|
||||||
|
byte[][] hashes = keys.Select(key => md5.ComputeHash(Encoding.UTF8.GetBytes(key))).ToArray();
|
||||||
|
byte[] xOrHash = new byte[l];
|
||||||
|
foreach (byte[] hash in hashes)
|
||||||
|
for(int i = 0; i < hash.Length; i++)
|
||||||
|
xOrHash[i] = (byte)(xOrHash[i] ^ (i >= hash.Length ? 0 : hash[i]));
|
||||||
|
string key = new (xOrHash.Select(b => Chars[b % Chars.Length]).ToArray());
|
||||||
|
key = string.Join('-', prefix, key);
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
}
|
104
API/Tranga.cs
Normal file
104
API/Tranga.cs
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
using API.Schema;
|
||||||
|
using API.Schema.Jobs;
|
||||||
|
using API.Schema.NotificationConnectors;
|
||||||
|
using log4net;
|
||||||
|
using log4net.Config;
|
||||||
|
|
||||||
|
namespace API;
|
||||||
|
|
||||||
|
public static class Tranga
|
||||||
|
{
|
||||||
|
public static Thread NotificationSenderThread { get; } = new (NotificationSender);
|
||||||
|
public static Thread JobStarterThread { get; } = new (JobStarter);
|
||||||
|
private static readonly Dictionary<Thread, Job> RunningJobs = new();
|
||||||
|
private static readonly ILog Log = LogManager.GetLogger(typeof(Tranga));
|
||||||
|
|
||||||
|
internal static void StartLogger()
|
||||||
|
{
|
||||||
|
BasicConfigurator.Configure();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void NotificationSender(object? pgsqlContext)
|
||||||
|
{
|
||||||
|
if(pgsqlContext is null) return;
|
||||||
|
PgsqlContext context = (PgsqlContext)pgsqlContext;
|
||||||
|
|
||||||
|
IQueryable<Notification> staleNotifications = context.Notifications.Where(n => n.Urgency < NotificationUrgency.Normal);
|
||||||
|
context.Notifications.RemoveRange(staleNotifications);
|
||||||
|
context.SaveChanges();
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
SendNotifications(context, NotificationUrgency.High);
|
||||||
|
SendNotifications(context, NotificationUrgency.Normal);
|
||||||
|
SendNotifications(context, NotificationUrgency.Low);
|
||||||
|
|
||||||
|
context.SaveChanges();
|
||||||
|
Thread.Sleep(2000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void SendNotifications(PgsqlContext context, NotificationUrgency urgency)
|
||||||
|
{
|
||||||
|
List<Notification> notifications = context.Notifications.Where(n => n.Urgency == urgency).ToList();
|
||||||
|
if (notifications.Any())
|
||||||
|
{
|
||||||
|
DateTime max = notifications.MaxBy(n => n.Date)!.Date;
|
||||||
|
if (DateTime.Now.Subtract(max) > TrangaSettings.NotificationUrgencyDelay(urgency))
|
||||||
|
{
|
||||||
|
foreach (NotificationConnector notificationConnector in context.NotificationConnectors)
|
||||||
|
{
|
||||||
|
foreach (Notification notification in notifications)
|
||||||
|
notificationConnector.SendNotification(notification.Title, notification.Message);
|
||||||
|
}
|
||||||
|
context.Notifications.RemoveRange(notifications);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
context.SaveChanges();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void JobStarter(object? pgsqlContext)
|
||||||
|
{
|
||||||
|
if(pgsqlContext is null) return;
|
||||||
|
PgsqlContext context = (PgsqlContext)pgsqlContext;
|
||||||
|
|
||||||
|
string TRANGA = "\n\n _______ \n|_ _|.----..---.-..-----..-----..---.-.\n | | | _|| _ || || _ || _ |\n |___| |__| |___._||__|__||___ ||___._|\n |_____| \n\n";
|
||||||
|
Log.Info(TRANGA);
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
List<Job> completedJobs = context.Jobs.Where(j => j.state == JobState.Completed).ToList();
|
||||||
|
foreach (Job job in completedJobs)
|
||||||
|
if(job.RecurrenceMs <= 0)
|
||||||
|
context.Jobs.Remove(job);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
job.LastExecution = DateTime.UtcNow;
|
||||||
|
job.state = JobState.Waiting;
|
||||||
|
context.Jobs.Update(job);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Job> runJobs = context.Jobs.Where(j => j.state <= JobState.Running).ToList().Where(j => j.NextExecution < DateTime.UtcNow).ToList();
|
||||||
|
foreach (Job job in runJobs)
|
||||||
|
{
|
||||||
|
Thread t = new (() =>
|
||||||
|
{
|
||||||
|
IEnumerable<Job> newJobs = job.Run(context);
|
||||||
|
context.Jobs.AddRange(newJobs);
|
||||||
|
});
|
||||||
|
RunningJobs.Add(t, job);
|
||||||
|
t.Start();
|
||||||
|
context.Jobs.Update(job);
|
||||||
|
}
|
||||||
|
|
||||||
|
(Thread, Job)[] removeFromThreadsList = RunningJobs.Where(t => !t.Key.IsAlive)
|
||||||
|
.Select(t => (t.Key, t.Value)).ToArray();
|
||||||
|
foreach ((Thread thread, Job job) thread in removeFromThreadsList)
|
||||||
|
{
|
||||||
|
RunningJobs.Remove(thread.thread);
|
||||||
|
context.Jobs.Update(thread.job);
|
||||||
|
}
|
||||||
|
|
||||||
|
context.SaveChanges();
|
||||||
|
Thread.Sleep(2000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
191
API/TrangaSettings.cs
Normal file
191
API/TrangaSettings.cs
Normal file
@ -0,0 +1,191 @@
|
|||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using API.MangaDownloadClients;
|
||||||
|
using API.Schema;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
using static System.IO.UnixFileMode;
|
||||||
|
|
||||||
|
namespace API;
|
||||||
|
|
||||||
|
public static class TrangaSettings
|
||||||
|
{
|
||||||
|
public static string downloadLocation { get; private set; } = (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? "/Manga" : Path.Join(Directory.GetCurrentDirectory(), "Downloads"));
|
||||||
|
public static string workingDirectory { get; private set; } = Path.Join(RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? "/usr/share" : Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "tranga-api");
|
||||||
|
public static int apiPortNumber { get; private set; } = 6531;
|
||||||
|
[JsonIgnore]
|
||||||
|
internal static readonly string DefaultUserAgent = $"Tranga ({Enum.GetName(Environment.OSVersion.Platform)}; {(Environment.Is64BitOperatingSystem ? "x64" : "")}) / 1.0";
|
||||||
|
public static string userAgent { get; private set; } = DefaultUserAgent;
|
||||||
|
public static int compression{ get; private set; } = 40;
|
||||||
|
public static bool bwImages { get; private set; } = false;
|
||||||
|
[JsonIgnore]
|
||||||
|
public static string settingsFilePath => Path.Join(workingDirectory, "settings.json");
|
||||||
|
[JsonIgnore]
|
||||||
|
public static string coverImageCache => Path.Join(workingDirectory, "imageCache");
|
||||||
|
public static bool aprilFoolsMode { get; private set; } = true;
|
||||||
|
[JsonIgnore]
|
||||||
|
internal static readonly Dictionary<RequestType, int> DefaultRequestLimits = new ()
|
||||||
|
{
|
||||||
|
{RequestType.MangaInfo, 250},
|
||||||
|
{RequestType.MangaDexFeed, 250},
|
||||||
|
{RequestType.MangaDexImage, 40},
|
||||||
|
{RequestType.MangaImage, 60},
|
||||||
|
{RequestType.MangaCover, 250},
|
||||||
|
{RequestType.Default, 60}
|
||||||
|
};
|
||||||
|
public static Dictionary<RequestType, int> requestLimits { get; set; } = DefaultRequestLimits;
|
||||||
|
|
||||||
|
public static TimeSpan NotificationUrgencyDelay(NotificationUrgency urgency) => urgency switch
|
||||||
|
{
|
||||||
|
NotificationUrgency.High => TimeSpan.Zero,
|
||||||
|
NotificationUrgency.Normal => TimeSpan.FromMinutes(5),
|
||||||
|
NotificationUrgency.Low => TimeSpan.FromMinutes(10),
|
||||||
|
_ => TimeSpan.FromHours(1)
|
||||||
|
};
|
||||||
|
|
||||||
|
public static void Load()
|
||||||
|
{
|
||||||
|
if(File.Exists(settingsFilePath))
|
||||||
|
Deserialize(File.ReadAllText(settingsFilePath));
|
||||||
|
else return;
|
||||||
|
|
||||||
|
Directory.CreateDirectory(downloadLocation);
|
||||||
|
ExportSettings();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void UpdateAprilFoolsMode(bool enabled)
|
||||||
|
{
|
||||||
|
aprilFoolsMode = enabled;
|
||||||
|
ExportSettings();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void UpdateCompressImages(int value)
|
||||||
|
{
|
||||||
|
compression = int.Clamp(value, 1, 100);
|
||||||
|
ExportSettings();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void UpdateBwImages(bool enabled)
|
||||||
|
{
|
||||||
|
bwImages = enabled;
|
||||||
|
ExportSettings();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void UpdateDownloadLocation(string newPath, bool moveFiles = true)
|
||||||
|
{
|
||||||
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||||
|
Directory.CreateDirectory(newPath, GroupRead | GroupWrite | None | OtherRead | OtherWrite | UserRead | UserWrite);
|
||||||
|
else
|
||||||
|
Directory.CreateDirectory(newPath);
|
||||||
|
|
||||||
|
if (moveFiles)
|
||||||
|
MoveContentsOfDirectoryTo(TrangaSettings.downloadLocation, newPath);
|
||||||
|
|
||||||
|
TrangaSettings.downloadLocation = newPath;
|
||||||
|
ExportSettings();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void MoveContentsOfDirectoryTo(string oldDir, string newDir)
|
||||||
|
{
|
||||||
|
string[] directoryPaths = Directory.GetDirectories(oldDir);
|
||||||
|
string[] filePaths = Directory.GetFiles(oldDir);
|
||||||
|
foreach (string file in filePaths)
|
||||||
|
{
|
||||||
|
string newPath = Path.Join(newDir, Path.GetFileName(file));
|
||||||
|
File.Move(file, newPath, true);
|
||||||
|
}
|
||||||
|
foreach(string directory in directoryPaths)
|
||||||
|
{
|
||||||
|
string? dirName = Path.GetDirectoryName(directory);
|
||||||
|
if(dirName is null)
|
||||||
|
continue;
|
||||||
|
string newPath = Path.Join(newDir, dirName);
|
||||||
|
if(Directory.Exists(newPath))
|
||||||
|
MoveContentsOfDirectoryTo(directory, newPath);
|
||||||
|
else
|
||||||
|
Directory.Move(directory, newPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void UpdateUserAgent(string? customUserAgent)
|
||||||
|
{
|
||||||
|
userAgent = customUserAgent ?? DefaultUserAgent;
|
||||||
|
ExportSettings();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void UpdateRateLimit(RequestType requestType, int newLimit)
|
||||||
|
{
|
||||||
|
requestLimits[requestType] = newLimit;
|
||||||
|
ExportSettings();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void ResetRateLimits()
|
||||||
|
{
|
||||||
|
requestLimits = DefaultRequestLimits;
|
||||||
|
ExportSettings();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void ExportSettings()
|
||||||
|
{
|
||||||
|
if (File.Exists(settingsFilePath))
|
||||||
|
{
|
||||||
|
while(IsFileInUse(settingsFilePath))
|
||||||
|
Thread.Sleep(100);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
Directory.CreateDirectory(new FileInfo(settingsFilePath).DirectoryName!);
|
||||||
|
File.WriteAllText(settingsFilePath, Serialize());
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static 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)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static JObject AsJObject()
|
||||||
|
{
|
||||||
|
JObject jobj = new JObject();
|
||||||
|
jobj.Add("downloadLocation", JToken.FromObject(downloadLocation));
|
||||||
|
jobj.Add("workingDirectory", JToken.FromObject(workingDirectory));
|
||||||
|
jobj.Add("apiPortNumber", JToken.FromObject(apiPortNumber));
|
||||||
|
jobj.Add("userAgent", JToken.FromObject(userAgent));
|
||||||
|
jobj.Add("aprilFoolsMode", JToken.FromObject(aprilFoolsMode));
|
||||||
|
jobj.Add("requestLimits", JToken.FromObject(requestLimits));
|
||||||
|
jobj.Add("compression", JToken.FromObject(compression));
|
||||||
|
jobj.Add("bwImages", JToken.FromObject(bwImages));
|
||||||
|
return jobj;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string Serialize() => AsJObject().ToString();
|
||||||
|
|
||||||
|
public static void Deserialize(string serialized)
|
||||||
|
{
|
||||||
|
JObject jobj = JObject.Parse(serialized);
|
||||||
|
if (jobj.TryGetValue("downloadLocation", out JToken? dl))
|
||||||
|
downloadLocation = dl.Value<string>()!;
|
||||||
|
if (jobj.TryGetValue("workingDirectory", out JToken? wd))
|
||||||
|
workingDirectory = wd.Value<string>()!;
|
||||||
|
if (jobj.TryGetValue("apiPortNumber", out JToken? apn))
|
||||||
|
apiPortNumber = apn.Value<int>();
|
||||||
|
if (jobj.TryGetValue("userAgent", out JToken? ua))
|
||||||
|
userAgent = ua.Value<string>()!;
|
||||||
|
if (jobj.TryGetValue("aprilFoolsMode", out JToken? afm))
|
||||||
|
aprilFoolsMode = afm.Value<bool>()!;
|
||||||
|
if (jobj.TryGetValue("requestLimits", out JToken? rl))
|
||||||
|
requestLimits = rl.ToObject<Dictionary<RequestType, int>>()!;
|
||||||
|
if (jobj.TryGetValue("compression", out JToken? ci))
|
||||||
|
compression = ci.Value<int>()!;
|
||||||
|
if (jobj.TryGetValue("bwImages", out JToken? bwi))
|
||||||
|
bwImages = bwi.Value<bool>()!;
|
||||||
|
}
|
||||||
|
}
|
8
API/appsettings.Development.json
Normal file
8
API/appsettings.Development.json
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.AspNetCore": "Warning"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
9
API/appsettings.json
Normal file
9
API/appsettings.json
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.AspNetCore": "Warning"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"AllowedHosts": "*"
|
||||||
|
}
|
50
Dockerfile
50
Dockerfile
@ -1,14 +1,42 @@
|
|||||||
# syntax=docker/dockerfile:1
|
# syntax=docker/dockerfile:1
|
||||||
|
ARG DOTNET=9.0
|
||||||
|
|
||||||
FROM mcr.microsoft.com/dotnet/sdk:7.0 as build-env
|
FROM --platform=$TARGETPLATFORM mcr.microsoft.com/dotnet/aspnet:$DOTNET AS base
|
||||||
WORKDIR /src
|
|
||||||
COPY . /src/
|
|
||||||
RUN dotnet restore Tranga-API/Tranga-API.csproj
|
|
||||||
RUN dotnet publish -c Release -o /publish
|
|
||||||
|
|
||||||
#FROM mcr.microsoft.com/dotnet/aspnet:7.0 as runtime
|
|
||||||
FROM glax/tranga-base:latest as runtime
|
|
||||||
WORKDIR /publish
|
WORKDIR /publish
|
||||||
COPY --from=build-env /publish .
|
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
|
||||||
EXPOSE 80
|
ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium
|
||||||
ENTRYPOINT ["dotnet", "/publish/Tranga-API.dll"]
|
ENV XDG_CONFIG_HOME=/tmp/.chromium
|
||||||
|
ENV XDG_CACHE_HOME=/tmp/.chromium
|
||||||
|
RUN apt-get update \
|
||||||
|
&& apt-get install -y libx11-6 libx11-xcb1 libatk1.0-0 libgtk-3-0 libcups2 libdrm2 libxkbcommon0 libxcomposite1 libxdamage1 libxrandr2 libgbm1 libpango-1.0-0 libcairo2 libasound2 libxshmfence1 libnss3 chromium \
|
||||||
|
&& apt-get autopurge -y \
|
||||||
|
&& apt-get autoclean -y
|
||||||
|
|
||||||
|
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:$DOTNET AS build-env
|
||||||
|
WORKDIR /src
|
||||||
|
|
||||||
|
COPY Tranga.sln /src
|
||||||
|
COPY API/API.csproj /src/API/API.csproj
|
||||||
|
RUN dotnet restore /src/Tranga.sln
|
||||||
|
|
||||||
|
COPY . /src/
|
||||||
|
RUN dotnet publish -c Release --property:OutputPath=/publish -maxcpucount:1
|
||||||
|
|
||||||
|
FROM --platform=$TARGETPLATFORM base AS runtime
|
||||||
|
EXPOSE 6531
|
||||||
|
ARG UNAME=tranga
|
||||||
|
ARG UID=1000
|
||||||
|
ARG GID=1000
|
||||||
|
RUN groupadd -g $GID -o $UNAME \
|
||||||
|
&& useradd -m -u $UID -g $GID -o -s /bin/bash $UNAME \
|
||||||
|
&& mkdir /usr/share/tranga-api \
|
||||||
|
&& mkdir /Manga \
|
||||||
|
&& chown 1000:1000 /usr/share/tranga-api \
|
||||||
|
&& chown 1000:1000 /Manga
|
||||||
|
USER $UNAME
|
||||||
|
|
||||||
|
WORKDIR /publish
|
||||||
|
COPY --chown=1000:1000 --from=build-env /publish .
|
||||||
|
USER 0
|
||||||
|
ENTRYPOINT ["dotnet", "/publish/API.dll"]
|
||||||
|
CMD ["-f", "-c", "-l", "/usr/share/tranga-api/logs"]
|
@ -1,8 +0,0 @@
|
|||||||
# syntax=docker/dockerfile:1
|
|
||||||
#FROM mcr.microsoft.com/dotnet/aspnet:7.0 as runtime
|
|
||||||
FROM mcr.microsoft.com/dotnet/runtime:7.0 as runtime
|
|
||||||
WORKDIR /publish
|
|
||||||
RUN apt-get update
|
|
||||||
RUN apt-get install -y libx11-6 libx11-xcb1 libatk1.0-0 libgtk-3-0 libcups2 libdrm2 libxkbcommon0 libxcomposite1 libxdamage1 libxrandr2 libgbm1 libpango-1.0-0 libcairo2 libasound2 libxshmfence1 libnss3
|
|
||||||
RUN apt-get autopurge -y
|
|
||||||
RUN apt-get autoclean -y
|
|
@ -1,32 +0,0 @@
|
|||||||
using System.Text;
|
|
||||||
using System.Text.Json.Serialization;
|
|
||||||
|
|
||||||
namespace Logging;
|
|
||||||
|
|
||||||
public class FileLogger : LoggerBase
|
|
||||||
{
|
|
||||||
private string logFilePath { get; }
|
|
||||||
private const int MaxNumberOfLogFiles = 5;
|
|
||||||
|
|
||||||
public FileLogger(string logFilePath, TextWriter? stdOut, Encoding? encoding = null) : base (stdOut, 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.ToString());
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
stdOut?.WriteLine(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,17 +0,0 @@
|
|||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace Logging;
|
|
||||||
|
|
||||||
public class FormattedConsoleLogger : LoggerBase
|
|
||||||
{
|
|
||||||
|
|
||||||
public FormattedConsoleLogger(TextWriter? stdOut, Encoding? encoding = null) : base(stdOut, encoding)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Write(LogMessage message)
|
|
||||||
{
|
|
||||||
//Nothing to do yet
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,63 +0,0 @@
|
|||||||
using System.Net.Mime;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace Logging;
|
|
||||||
|
|
||||||
public class Logger : TextWriter
|
|
||||||
{
|
|
||||||
public override Encoding Encoding { get; }
|
|
||||||
public enum LoggerType
|
|
||||||
{
|
|
||||||
FileLogger,
|
|
||||||
ConsoleLogger
|
|
||||||
}
|
|
||||||
|
|
||||||
private FileLogger? _fileLogger;
|
|
||||||
private FormattedConsoleLogger? _formattedConsoleLogger;
|
|
||||||
private MemoryLogger _memoryLogger;
|
|
||||||
private TextWriter? stdOut;
|
|
||||||
|
|
||||||
public Logger(LoggerType[] enabledLoggers, TextWriter? stdOut, Encoding? encoding, string? logFilePath)
|
|
||||||
{
|
|
||||||
this.Encoding = encoding ?? Encoding.ASCII;
|
|
||||||
this.stdOut = stdOut ?? null;
|
|
||||||
if (enabledLoggers.Contains(LoggerType.FileLogger) && logFilePath is not null)
|
|
||||||
_fileLogger = new FileLogger(logFilePath, null, encoding);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_fileLogger = null;
|
|
||||||
throw new ArgumentException($"logFilePath can not be null for LoggerType {LoggerType.FileLogger}");
|
|
||||||
}
|
|
||||||
_formattedConsoleLogger = enabledLoggers.Contains(LoggerType.ConsoleLogger) ? new FormattedConsoleLogger(null, encoding) : null;
|
|
||||||
_memoryLogger = new MemoryLogger(null, 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);
|
|
||||||
stdOut?.Write(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public string[] Tail(uint? lines)
|
|
||||||
{
|
|
||||||
return _memoryLogger.Tail(lines);
|
|
||||||
}
|
|
||||||
|
|
||||||
public string[] GetNewLines()
|
|
||||||
{
|
|
||||||
return _memoryLogger.GetNewLines();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,58 +0,0 @@
|
|||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace Logging;
|
|
||||||
|
|
||||||
public abstract class LoggerBase : TextWriter
|
|
||||||
{
|
|
||||||
public override Encoding Encoding { get; }
|
|
||||||
protected TextWriter? stdOut { get; }
|
|
||||||
|
|
||||||
public LoggerBase(TextWriter? stdOut, Encoding? encoding = null)
|
|
||||||
{
|
|
||||||
this.Encoding = encoding ?? Encoding.ASCII;
|
|
||||||
this.stdOut = stdOut;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void WriteLine(string caller, string? value)
|
|
||||||
{
|
|
||||||
value = value is null ? Environment.NewLine : string.Join(value, Environment.NewLine);
|
|
||||||
|
|
||||||
LogMessage message = new LogMessage(DateTime.Now, caller, value);
|
|
||||||
|
|
||||||
Write(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Write(string caller, string? value)
|
|
||||||
{
|
|
||||||
if (value is null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
LogMessage message = new LogMessage(DateTime.Now, caller, value);
|
|
||||||
|
|
||||||
stdOut?.Write(message.ToString());
|
|
||||||
|
|
||||||
Write(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract void Write(LogMessage message);
|
|
||||||
|
|
||||||
public class LogMessage
|
|
||||||
{
|
|
||||||
public DateTime logTime { get; }
|
|
||||||
public string caller { get; }
|
|
||||||
public string value { get; }
|
|
||||||
|
|
||||||
public LogMessage(DateTime now, string caller, string value)
|
|
||||||
{
|
|
||||||
this.logTime = now;
|
|
||||||
this.caller = caller;
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string ToString()
|
|
||||||
{
|
|
||||||
string dateTimeString = $"{logTime.ToShortDateString()} {logTime.ToLongTimeString()}";
|
|
||||||
return $"[{dateTimeString}] {caller.Split(new char[]{'.','+'}).Last(),15} | {value}";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<TargetFramework>net7.0</TargetFramework>
|
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
|
||||||
<Nullable>enable</Nullable>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
@ -1,58 +0,0 @@
|
|||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace Logging;
|
|
||||||
|
|
||||||
public class MemoryLogger : LoggerBase
|
|
||||||
{
|
|
||||||
private readonly SortedList<DateTime, LogMessage> _logMessages = new();
|
|
||||||
private int _lastLogMessageIndex = 0;
|
|
||||||
|
|
||||||
public MemoryLogger(TextWriter? stdOut, Encoding? encoding = null) : base(stdOut, 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;
|
|
||||||
}
|
|
||||||
}
|
|
130
README.md
130
README.md
@ -1,25 +1,17 @@
|
|||||||
<!-- 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
|
|
||||||
-->
|
|
||||||
|
|
||||||
<!-- PROJECT LOGO -->
|
<!-- PROJECT LOGO -->
|
||||||
<br />
|
<br />
|
||||||
<div align="center">
|
<div align="center">
|
||||||
|
|
||||||
<h3 align="center">Tranga</h3>
|
<h3 align="center">Tranga v2</h3>
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
Automatic Manga and Metadata downloader
|
Automatic Manga and Metadata downloader
|
||||||
</p>
|
</p>
|
||||||
|
<p align="center">
|
||||||
|
This is the API for <a href="https://github.com/C9Glax/tranga-website">Tranga-Website</a>
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- TABLE OF CONTENTS -->
|
<!-- TABLE OF CONTENTS -->
|
||||||
<details>
|
<details>
|
||||||
<summary>Table of Contents</summary>
|
<summary>Table of Contents</summary>
|
||||||
@ -30,9 +22,6 @@
|
|||||||
<li><a href="#built-with">Built With</a></li>
|
<li><a href="#built-with">Built With</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
|
||||||
<a href="#screenshots">Screenshots</a>
|
|
||||||
</li>
|
|
||||||
<li>
|
<li>
|
||||||
<a href="#getting-started">Getting Started</a>
|
<a href="#getting-started">Getting Started</a>
|
||||||
<ul>
|
<ul>
|
||||||
@ -52,19 +41,44 @@
|
|||||||
<!-- ABOUT THE PROJECT -->
|
<!-- ABOUT THE PROJECT -->
|
||||||
## About The Project
|
## About The Project
|
||||||
|
|
||||||
Tranga can download Chapters and Metadata from Scanlation sites such as
|
Tranga can download Chapters and Metadata from "Scanlation" sites such as
|
||||||
|
|
||||||
- [MangaDex.org](https://mangadex.org/)
|
- [MangaDex.org](https://mangadex.org/) (Multilingual)
|
||||||
- [Manganato.com](https://manganato.com/)
|
- [Manganato.com](https://manganato.com/) (en)
|
||||||
- [Mangasee](https://mangasee123.com/)
|
- [Mangasee.com](https://mangasee123.com/) (en)
|
||||||
|
- [MangaKatana.com](https://mangakatana.com) (en)
|
||||||
|
- [Mangaworld.bz](https://www.mangaworld.bz/) (it)
|
||||||
|
- [Bato.to](https://bato.to/v3x) (en)
|
||||||
|
- [Manga4Life](https://manga4life.com) (en)
|
||||||
|
- [ManhuaPlus](https://manhuaplus.org/) (en)
|
||||||
|
- [MangaHere](https://www.mangahere.cc/) (en) (Their covers aren't scrapeable.)
|
||||||
|
- [Weebcentral](https://weebcentral.com) (en)
|
||||||
|
- ❓ Open an [issue](https://github.com/C9Glax/tranga/issues/new?assignees=&labels=New+Connector&projects=&template=new_connector.yml&title=%5BNew+Connector%5D%3A+)
|
||||||
|
|
||||||
|
and trigger a library-scan with [Komga](https://komga.org/) and [Kavita](https://www.kavitareader.com/).
|
||||||
|
Notifications can be sent to your devices using [Gotify](https://gotify.net/), [LunaSea](https://www.lunasea.app/) or [Ntfy](https://ntfy.sh/
|
||||||
|
).
|
||||||
|
|
||||||
|
### What this does and doesn't do
|
||||||
|
|
||||||
|
Tranga (this git-repo) will open a port (standard 6531) and listen for requests to add Jobs to Monitor and/or download specific Manga.
|
||||||
|
The configuration is all done through HTTP-Requests. [Documentation](docs/API_Calls_v2.md)
|
||||||
|
|
||||||
|
_**For a web-frontend use [tranga-website](https://github.com/C9Glax/tranga-website).**_
|
||||||
|
|
||||||
|
This project downloads the images for a Manga from the specified Scanlation-Website and packages them with some metadata - from that same website - in a .cbz-archive (per chapter).
|
||||||
|
It does this on an interval, and checks for any Chapters (.cbz-Archive) not already existing in your specified Download-Location. (If you rename or move files, it will download those again)
|
||||||
|
Tranga can (if configured) trigger a scan in Komga or Kavita, however the directory in which the Manga reside has to be available to both Tranga and Komga/Kavita.
|
||||||
|
|
||||||
|
The project doesn't manage metadata, and doesn't curate, change or enhance any information that isn't available on the selected Scanlation-Site.
|
||||||
|
It will blindly use whatever is scrapes (yes this is a glorified Web-scraper).
|
||||||
|
|
||||||
and automatically start updates in [Komga](https://komga.org/) and [Kavita](https://www.kavitareader.com/) to import them.
|
|
||||||
|
|
||||||
### Inspiration:
|
### Inspiration:
|
||||||
|
|
||||||
Because [Kaizoku](https://github.com/oae/kaizoku) was relying on [mangal](https://github.com/metafates/mangal) and mangal
|
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,
|
hasn't received bugfixes for its 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.
|
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.
|
That is why I wanted to create my own project, in a language I understand, and that I am able to maintain myself.
|
||||||
|
|
||||||
@ -76,73 +90,43 @@ That is why I wanted to create my own project, in a language I understand, and t
|
|||||||
- Newtonsoft.JSON
|
- Newtonsoft.JSON
|
||||||
- [PuppeteerSharp](https://www.puppeteersharp.com/)
|
- [PuppeteerSharp](https://www.puppeteersharp.com/)
|
||||||
- [Html Agility Pack (HAP)](https://html-agility-pack.net/)
|
- [Html Agility Pack (HAP)](https://html-agility-pack.net/)
|
||||||
- Love <3 Blåhaj 🦈
|
- [Soenneker.Utils.String.NeedlemanWunsch](https://github.com/soenneker/soenneker.utils.string.needlemanwunsch)
|
||||||
|
- [Sixlabors.ImageSharp](https://docs-v2.sixlabors.com/articles/imagesharp/index.html#license)
|
||||||
|
- [zstd-wrapper](https://github.com/oleg-st/ZstdSharp) [zstd](https://github.com/facebook/zstd)
|
||||||
|
- 💙 Blåhaj 🦈
|
||||||
|
|
||||||
<p align="right">(<a href="#readme-top">back to top</a>)</p>
|
<p align="right">(<a href="#readme-top">back to top</a>)</p>
|
||||||
|
|
||||||
|
## Star History
|
||||||
|
|
||||||
## Screenshots
|
<a href="https://star-history.com/#c9glax/tranga&Date">
|
||||||
|
<picture>
|
||||||

|
<source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/svg?repos=c9glax/tranga&type=Date&theme=dark" />
|
||||||
|
<source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/svg?repos=c9glax/tranga&type=Date" />
|
||||||

|
<img alt="Star History Chart" src="https://api.star-history.com/svg?repos=c9glax/tranga&type=Date" />
|
||||||
|
</picture>
|
||||||
|  |  |
|
</a>
|
||||||
|-----------------------------------:|:-------------------------------------------------:|
|
|
||||||
|
|
||||||
<p align="right">(<a href="#readme-top">back to top</a>)</p>
|
|
||||||
|
|
||||||
<!-- GETTING STARTED -->
|
<!-- GETTING STARTED -->
|
||||||
## 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
|
### Docker
|
||||||
|
|
||||||
Download [docker-compose.yaml](https://git.bernloehr.eu/glax/Tranga/src/branch/master/docker-compose.yaml) and configure to your needs.
|
Download [docker-compose.yaml](https://git.bernloehr.eu/glax/Tranga/src/branch/master/docker-compose.yaml) and configure to your needs.
|
||||||
|
Mount `/Manga` to wherever you want your chapters (`.cbz`-Archives) downloaded (where Komga/Kavita can access them).
|
||||||
|
The `docker-compose` also includes [tranga-website](https://github.com/C9Glax/tranga-website) as frontend. For its configuration refer to the repo README.
|
||||||
|
|
||||||
Wherever you are mounting `/usr/share/Tranga-API` you also need to mount that same path + `/imageCache` in the webserver container.
|
For compatibility do not execute the compose as root (which you should not do anyways...) but as user that can
|
||||||
|
access the folder.
|
||||||
### 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 pressing 'Search', the results will be presented below - this might, depending on the result-size, take a while.
|
|
||||||
Next select the publication 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.
|
|
||||||
When selecting `Download Chapter` a list will open with all available chapters from which you can then select a range.
|
|
||||||
|
|
||||||
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 syntax).
|
|
||||||
|
|
||||||
### Prerequisites
|
### Prerequisites
|
||||||
|
|
||||||
[.NET-Core 7.0 SDK](https://dotnet.microsoft.com/en-us/download/dotnet/7.0)
|
#### To Build
|
||||||
|
[.NET-Core 8.0 SDK](https://dotnet.microsoft.com/en-us/download/dotnet/8.0)
|
||||||
|
#### To Run
|
||||||
|
[.NET-Core 8.0 Runtime](https://dotnet.microsoft.com/en-us/download/dotnet/8.0) scroll down a bit, should be on the right the second item.
|
||||||
|
|
||||||
<!-- ROADMAP -->
|
See the [open issues](https://github.com/C9Glax/tranga/issues) for a full list of proposed features (and known issues).
|
||||||
## Roadmap
|
|
||||||
|
|
||||||
- [ ] Docker ARM support
|
|
||||||
- [ ] ?
|
|
||||||
|
|
||||||
See the [open issues](https://git.bernloehr.eu/glax/Tranga/issues) for a full list of proposed features (and known issues).
|
|
||||||
|
|
||||||
<p align="right">(<a href="#readme-top">back to top</a>)</p>
|
<p align="right">(<a href="#readme-top">back to top</a>)</p>
|
||||||
|
|
||||||
|
@ -1,16 +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>
|
|
||||||
<ProjectReference Include="..\Tranga\Tranga.csproj" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
@ -1,622 +0,0 @@
|
|||||||
using System.Globalization;
|
|
||||||
using Logging;
|
|
||||||
using Tranga;
|
|
||||||
using Tranga.LibraryManagers;
|
|
||||||
using Tranga.NotificationManagers;
|
|
||||||
using Tranga.TrangaTasks;
|
|
||||||
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
string applicationFolderPath = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Tranga");
|
|
||||||
string logsFolderPath = Path.Join(applicationFolderPath, "logs");
|
|
||||||
string logFilePath = Path.Join(logsFolderPath, $"log-{DateTime.Now:dd-M-yyyy-HH-mm-ss}.txt");
|
|
||||||
string settingsFilePath = Path.Join(applicationFolderPath, "settings.json");
|
|
||||||
|
|
||||||
Directory.CreateDirectory(applicationFolderPath);
|
|
||||||
Directory.CreateDirectory(logsFolderPath);
|
|
||||||
|
|
||||||
Console.WriteLine($"Logfile-Path: {logFilePath}");
|
|
||||||
Console.WriteLine($"Settings-File-Path: {settingsFilePath}");
|
|
||||||
|
|
||||||
Logger logger = new(new[] { Logger.LoggerType.FileLogger }, null, Console.Out.Encoding, logFilePath);
|
|
||||||
|
|
||||||
logger.WriteLine("Tranga_CLI", "Loading Taskmanager.");
|
|
||||||
TrangaSettings settings = File.Exists(settingsFilePath) ? TrangaSettings.LoadSettings(settingsFilePath, logger) : new TrangaSettings(Directory.GetCurrentDirectory(), applicationFolderPath, new HashSet<LibraryManager>(), new HashSet<NotificationManager>());
|
|
||||||
|
|
||||||
|
|
||||||
logger.WriteLine("Tranga_CLI", "User Input");
|
|
||||||
Console.WriteLine($"Output folder path [{settings.downloadLocation}]:");
|
|
||||||
string? tmpPath = Console.ReadLine();
|
|
||||||
while(tmpPath is null)
|
|
||||||
tmpPath = Console.ReadLine();
|
|
||||||
if (tmpPath.Length > 0)
|
|
||||||
settings.UpdateSettings(TrangaSettings.UpdateField.DownloadLocation, logger, tmpPath);
|
|
||||||
|
|
||||||
Console.WriteLine($"Komga BaseURL [{settings.libraryManagers.FirstOrDefault(lm => lm.GetType() == typeof(Komga))?.baseUrl}]:");
|
|
||||||
string? tmpUrlKomga = Console.ReadLine();
|
|
||||||
while (tmpUrlKomga is null)
|
|
||||||
tmpUrlKomga = Console.ReadLine();
|
|
||||||
if (tmpUrlKomga.Length > 0)
|
|
||||||
{
|
|
||||||
Console.WriteLine("Username:");
|
|
||||||
string? tmpKomgaUser = Console.ReadLine();
|
|
||||||
while (tmpKomgaUser is null || tmpKomgaUser.Length < 1)
|
|
||||||
tmpKomgaUser = Console.ReadLine();
|
|
||||||
|
|
||||||
Console.WriteLine("Password:");
|
|
||||||
string tmpKomgaPass = string.Empty;
|
|
||||||
ConsoleKey key;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
var keyInfo = Console.ReadKey(intercept: true);
|
|
||||||
key = keyInfo.Key;
|
|
||||||
|
|
||||||
if (key == ConsoleKey.Backspace && tmpKomgaPass.Length > 0)
|
|
||||||
{
|
|
||||||
Console.Write("\b \b");
|
|
||||||
tmpKomgaPass = tmpKomgaPass[0..^1];
|
|
||||||
}
|
|
||||||
else if (!char.IsControl(keyInfo.KeyChar))
|
|
||||||
{
|
|
||||||
Console.Write("*");
|
|
||||||
tmpKomgaPass += keyInfo.KeyChar;
|
|
||||||
}
|
|
||||||
} while (key != ConsoleKey.Enter);
|
|
||||||
|
|
||||||
settings.UpdateSettings(TrangaSettings.UpdateField.Komga, logger, tmpUrlKomga, tmpKomgaUser, tmpKomgaPass);
|
|
||||||
}
|
|
||||||
|
|
||||||
Console.WriteLine($"Kavita BaseURL [{settings.libraryManagers.FirstOrDefault(lm => lm.GetType() == typeof(Kavita))?.baseUrl}]:");
|
|
||||||
string? tmpUrlKavita = Console.ReadLine();
|
|
||||||
while (tmpUrlKavita is null)
|
|
||||||
tmpUrlKavita = Console.ReadLine();
|
|
||||||
if (tmpUrlKavita.Length > 0)
|
|
||||||
{
|
|
||||||
Console.WriteLine("Username:");
|
|
||||||
string? tmpKavitaUser = Console.ReadLine();
|
|
||||||
while (tmpKavitaUser is null || tmpKavitaUser.Length < 1)
|
|
||||||
tmpKavitaUser = Console.ReadLine();
|
|
||||||
|
|
||||||
Console.WriteLine("Password:");
|
|
||||||
string tmpKavitaPass = string.Empty;
|
|
||||||
ConsoleKey key;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
var keyInfo = Console.ReadKey(intercept: true);
|
|
||||||
key = keyInfo.Key;
|
|
||||||
|
|
||||||
if (key == ConsoleKey.Backspace && tmpKavitaPass.Length > 0)
|
|
||||||
{
|
|
||||||
Console.Write("\b \b");
|
|
||||||
tmpKavitaPass = tmpKavitaPass[0..^1];
|
|
||||||
}
|
|
||||||
else if (!char.IsControl(keyInfo.KeyChar))
|
|
||||||
{
|
|
||||||
Console.Write("*");
|
|
||||||
tmpKavitaPass += keyInfo.KeyChar;
|
|
||||||
}
|
|
||||||
} while (key != ConsoleKey.Enter);
|
|
||||||
|
|
||||||
settings.UpdateSettings(TrangaSettings.UpdateField.Kavita, logger, tmpUrlKavita, tmpKavitaUser, tmpKavitaPass);
|
|
||||||
}
|
|
||||||
|
|
||||||
Console.WriteLine($"Gotify BaseURL [{((Gotify?)settings.notificationManagers.FirstOrDefault(lm => lm.GetType() == typeof(Gotify)))?.endpoint}]:");
|
|
||||||
string? tmpGotifyUrl = Console.ReadLine();
|
|
||||||
while (tmpGotifyUrl is null)
|
|
||||||
tmpGotifyUrl = Console.ReadLine();
|
|
||||||
if (tmpGotifyUrl.Length > 0)
|
|
||||||
{
|
|
||||||
Console.WriteLine("AppToken:");
|
|
||||||
string? tmpGotifyAppToken = Console.ReadLine();
|
|
||||||
while (tmpGotifyAppToken is null || tmpGotifyAppToken.Length < 1)
|
|
||||||
tmpGotifyAppToken = Console.ReadLine();
|
|
||||||
|
|
||||||
settings.UpdateSettings(TrangaSettings.UpdateField.Gotify, logger, tmpGotifyUrl, tmpGotifyAppToken);
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.WriteLine("Tranga_CLI", "Loaded.");
|
|
||||||
foreach(NotificationManager nm in settings.notificationManagers)
|
|
||||||
nm.SendNotification("Tranga", "Loaded.");
|
|
||||||
TaskMode(settings, logger);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void TaskMode(TrangaSettings settings, Logger logger)
|
|
||||||
{
|
|
||||||
TaskManager taskManager = new (settings, logger);
|
|
||||||
ConsoleKey selection = ConsoleKey.EraseEndOfFile;
|
|
||||||
PrintMenu(taskManager, taskManager.settings.downloadLocation);
|
|
||||||
while (selection != ConsoleKey.Q)
|
|
||||||
{
|
|
||||||
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.SetCursorPosition(0,1);
|
|
||||||
Console.WriteLine($"Tasks (Running/Queue/Total)): {taskRunningCount}/{taskEnqueuedCount}/{taskCount}");
|
|
||||||
|
|
||||||
if (Console.KeyAvailable)
|
|
||||||
{
|
|
||||||
selection = Console.ReadKey().Key;
|
|
||||||
switch (selection)
|
|
||||||
{
|
|
||||||
case ConsoleKey.L:
|
|
||||||
while (!Console.KeyAvailable)
|
|
||||||
{
|
|
||||||
PrintTasks(taskManager.GetAllTasks(), logger);
|
|
||||||
Console.WriteLine("Press any key.");
|
|
||||||
Thread.Sleep(500);
|
|
||||||
}
|
|
||||||
Console.ReadKey();
|
|
||||||
break;
|
|
||||||
case ConsoleKey.C:
|
|
||||||
CreateTask(taskManager, logger);
|
|
||||||
Console.WriteLine("Press any key.");
|
|
||||||
Console.ReadKey();
|
|
||||||
break;
|
|
||||||
case ConsoleKey.D:
|
|
||||||
DeleteTask(taskManager, logger);
|
|
||||||
Console.WriteLine("Press any key.");
|
|
||||||
Console.ReadKey();
|
|
||||||
break;
|
|
||||||
case ConsoleKey.E:
|
|
||||||
ExecuteTaskNow(taskManager, logger);
|
|
||||||
Console.WriteLine("Press any key.");
|
|
||||||
Console.ReadKey();
|
|
||||||
break;
|
|
||||||
case ConsoleKey.S:
|
|
||||||
SearchTasks(taskManager, logger);
|
|
||||||
Console.WriteLine("Press any key.");
|
|
||||||
Console.ReadKey();
|
|
||||||
break;
|
|
||||||
case ConsoleKey.R:
|
|
||||||
while (!Console.KeyAvailable)
|
|
||||||
{
|
|
||||||
PrintTasks(
|
|
||||||
taskManager.GetAllTasks().Where(eTask => eTask.state == TrangaTask.ExecutionState.Running)
|
|
||||||
.ToArray(), logger);
|
|
||||||
Console.WriteLine("Press any key.");
|
|
||||||
Thread.Sleep(500);
|
|
||||||
}
|
|
||||||
Console.ReadKey();
|
|
||||||
break;
|
|
||||||
case ConsoleKey.K:
|
|
||||||
while (!Console.KeyAvailable)
|
|
||||||
{
|
|
||||||
PrintTasks(
|
|
||||||
taskManager.GetAllTasks()
|
|
||||||
.Where(qTask => qTask.state is TrangaTask.ExecutionState.Enqueued)
|
|
||||||
.ToArray(), logger);
|
|
||||||
Console.WriteLine("Press any key.");
|
|
||||||
Thread.Sleep(500);
|
|
||||||
}
|
|
||||||
Console.ReadKey();
|
|
||||||
break;
|
|
||||||
case ConsoleKey.F:
|
|
||||||
TailLog(logger);
|
|
||||||
Console.ReadKey();
|
|
||||||
break;
|
|
||||||
case ConsoleKey.G:
|
|
||||||
RemoveTaskFromQueue(taskManager, logger);
|
|
||||||
Console.WriteLine("Press any key.");
|
|
||||||
Console.ReadKey();
|
|
||||||
break;
|
|
||||||
case ConsoleKey.B:
|
|
||||||
AddTaskToQueue(taskManager, logger);
|
|
||||||
Console.WriteLine("Press any key.");
|
|
||||||
Console.ReadKey();
|
|
||||||
break;
|
|
||||||
case ConsoleKey.M:
|
|
||||||
AddMangaTaskToQueue(taskManager, logger);
|
|
||||||
Console.WriteLine("Press any key.");
|
|
||||||
Console.ReadKey();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
PrintMenu(taskManager, taskManager.settings.downloadLocation);
|
|
||||||
}
|
|
||||||
Thread.Sleep(200);
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.WriteLine("Tranga_CLI", "Exiting.");
|
|
||||||
Console.Clear();
|
|
||||||
Console.WriteLine("Exiting.");
|
|
||||||
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 void PrintMenu(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}");
|
|
||||||
Console.WriteLine($"Tasks (Running/Queue/Total)): {taskRunningCount}/{taskEnqueuedCount}/{taskCount}");
|
|
||||||
Console.WriteLine();
|
|
||||||
Console.WriteLine($"{"C: Create Task",-30}{"L: List tasks",-30}{"B: Enqueue Task", -30}");
|
|
||||||
Console.WriteLine($"{"D: Delete Task",-30}{"S: Search Tasks", -30}{"K: List Task Queue", -30}");
|
|
||||||
Console.WriteLine($"{"E: Execute Task now",-30}{"R: List Running Tasks", -30}{"G: Remove Task from Queue", -30}");
|
|
||||||
Console.WriteLine($"{"M: New Download Manga Task",-30}{"", -30}{"", -30}");
|
|
||||||
Console.WriteLine($"{"",-30}{"F: Show Log",-30}{"Q: Exit",-30}");
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void PrintTasks(TrangaTask[] tasks, Logger logger)
|
|
||||||
{
|
|
||||||
logger.WriteLine("Tranga_CLI", "Printing 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}");
|
|
||||||
string header =
|
|
||||||
$"{"",-5}{"Task",-20} | {"Last Executed",-20} | {"Reoccurrence",-12} | {"State",-10} | {"Progress",-9} | {"Finished",-20} | {"Remaining",-12} | {"Connector",-15} | Publication/Manga ";
|
|
||||||
Console.WriteLine(header);
|
|
||||||
Console.WriteLine(new string('-', header.Length));
|
|
||||||
foreach (TrangaTask trangaTask in tasks)
|
|
||||||
{
|
|
||||||
string[] taskSplit = trangaTask.ToString().Split(", ");
|
|
||||||
Console.WriteLine($"{tIndex++:000}: {taskSplit[0],-20} | {taskSplit[1],-20} | {taskSplit[2],-12} | {taskSplit[3],-10} | {taskSplit[4],-9} | {taskSplit[5],-20} | {taskSplit[6][..12],-12} | {(taskSplit.Length > 7 ? taskSplit[7] : ""),-15} | {(taskSplit.Length > 8 ? taskSplit[8] : "")} {(taskSplit.Length > 9 ? taskSplit[9] : "")} {(taskSplit.Length > 10 ? taskSplit[10] : "")}");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private static TrangaTask[] SelectTasks(TrangaTask[] tasks, Logger logger)
|
|
||||||
{
|
|
||||||
logger.WriteLine("Tranga_CLI", "Menu: Select task");
|
|
||||||
if (tasks.Length < 1)
|
|
||||||
{
|
|
||||||
Console.Clear();
|
|
||||||
Console.WriteLine("There are no available Tasks.");
|
|
||||||
logger.WriteLine("Tranga_CLI", "No available Tasks.");
|
|
||||||
return Array.Empty<TrangaTask>();
|
|
||||||
}
|
|
||||||
PrintTasks(tasks, logger);
|
|
||||||
|
|
||||||
logger.WriteLine("Tranga_CLI", "Selecting Task to Remove (from queue)");
|
|
||||||
Console.WriteLine("Enter q to abort");
|
|
||||||
Console.WriteLine($"Select Task(s) (0-{tasks.Length - 1}):");
|
|
||||||
|
|
||||||
string? selectedTask = Console.ReadLine();
|
|
||||||
while(selectedTask is null || selectedTask.Length < 1)
|
|
||||||
selectedTask = Console.ReadLine();
|
|
||||||
|
|
||||||
if (selectedTask.Length == 1 && selectedTask.ToLower() == "q")
|
|
||||||
{
|
|
||||||
Console.Clear();
|
|
||||||
Console.WriteLine("aborted.");
|
|
||||||
logger.WriteLine("Tranga_CLI", "aborted");
|
|
||||||
return Array.Empty<TrangaTask>();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (selectedTask.Contains('-'))
|
|
||||||
{
|
|
||||||
int start = Convert.ToInt32(selectedTask.Split('-')[0]);
|
|
||||||
int end = Convert.ToInt32(selectedTask.Split('-')[1]);
|
|
||||||
return tasks[start..end];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
int selectedTaskIndex = Convert.ToInt32(selectedTask);
|
|
||||||
return new[] { tasks[selectedTaskIndex] };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void AddMangaTaskToQueue(TaskManager taskManager, Logger logger)
|
|
||||||
{
|
|
||||||
Console.Clear();
|
|
||||||
logger.WriteLine("Tranga_CLI", "Menu: Add Manga Download to queue");
|
|
||||||
|
|
||||||
Connector? connector = SelectConnector(taskManager.GetAvailableConnectors().Values.ToArray(), logger);
|
|
||||||
if (connector is null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
Publication? publication = SelectPublication(taskManager, connector, logger);
|
|
||||||
if (publication is null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
TimeSpan reoccurrence = SelectReoccurrence(logger);
|
|
||||||
logger.WriteLine("Tranga_CLI", "Sending Task to TaskManager");
|
|
||||||
TrangaTask nTask = new MonitorPublicationTask(connector.name, (Publication)publication, reoccurrence, "en");
|
|
||||||
taskManager.AddTask(nTask);
|
|
||||||
Console.WriteLine(nTask);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void AddTaskToQueue(TaskManager taskManager, Logger logger)
|
|
||||||
{
|
|
||||||
Console.Clear();
|
|
||||||
logger.WriteLine("Tranga_CLI", "Menu: Add Task to queue");
|
|
||||||
|
|
||||||
TrangaTask[] tasks = taskManager.GetAllTasks().Where(rTask =>
|
|
||||||
rTask.state is not TrangaTask.ExecutionState.Enqueued and not TrangaTask.ExecutionState.Running).ToArray();
|
|
||||||
|
|
||||||
TrangaTask[] selectedTasks = SelectTasks(tasks, logger);
|
|
||||||
logger.WriteLine("Tranga_CLI", $"Sending {selectedTasks.Length} Tasks to TaskManager");
|
|
||||||
foreach(TrangaTask task in selectedTasks)
|
|
||||||
taskManager.AddTaskToQueue(task);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void RemoveTaskFromQueue(TaskManager taskManager, Logger logger)
|
|
||||||
{
|
|
||||||
Console.Clear();
|
|
||||||
logger.WriteLine("Tranga_CLI", "Menu: Remove Task from queue");
|
|
||||||
|
|
||||||
TrangaTask[] tasks = taskManager.GetAllTasks().Where(rTask => rTask.state is TrangaTask.ExecutionState.Enqueued).ToArray();
|
|
||||||
|
|
||||||
TrangaTask[] selectedTasks = SelectTasks(tasks, logger);
|
|
||||||
logger.WriteLine("Tranga_CLI", $"Sending {selectedTasks.Length} Tasks to TaskManager");
|
|
||||||
foreach(TrangaTask task in selectedTasks)
|
|
||||||
taskManager.RemoveTaskFromQueue(task);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void TailLog(Logger logger)
|
|
||||||
{
|
|
||||||
logger.WriteLine("Tranga_CLI", "Menu: Show Log-lines");
|
|
||||||
Console.Clear();
|
|
||||||
|
|
||||||
string[] lines = logger.Tail(20);
|
|
||||||
foreach (string message in lines)
|
|
||||||
Console.Write(message);
|
|
||||||
|
|
||||||
while (!Console.KeyAvailable)
|
|
||||||
{
|
|
||||||
string[] newLines = logger.GetNewLines();
|
|
||||||
foreach(string message in newLines)
|
|
||||||
Console.Write(message);
|
|
||||||
Thread.Sleep(40);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void CreateTask(TaskManager taskManager, Logger logger)
|
|
||||||
{
|
|
||||||
logger.WriteLine("Tranga_CLI", "Menu: Creating Task");
|
|
||||||
TrangaTask.Task? tmpTask = SelectTaskType(logger);
|
|
||||||
if (tmpTask is null)
|
|
||||||
return;
|
|
||||||
TrangaTask.Task task = (TrangaTask.Task)tmpTask;
|
|
||||||
|
|
||||||
Connector? connector = null;
|
|
||||||
if (task != TrangaTask.Task.UpdateLibraries)
|
|
||||||
{
|
|
||||||
connector = SelectConnector(taskManager.GetAvailableConnectors().Values.ToArray(), logger);
|
|
||||||
if (connector is null)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Publication? publication = null;
|
|
||||||
if (task != TrangaTask.Task.UpdateLibraries)
|
|
||||||
{
|
|
||||||
publication = SelectPublication(taskManager, connector!, logger);
|
|
||||||
if (publication is null)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (task is TrangaTask.Task.MonitorPublication)
|
|
||||||
{
|
|
||||||
TimeSpan reoccurrence = SelectReoccurrence(logger);
|
|
||||||
logger.WriteLine("Tranga_CLI", "Sending Task to TaskManager");
|
|
||||||
|
|
||||||
TrangaTask newTask = new MonitorPublicationTask(connector!.name, (Publication)publication!, reoccurrence, "en");
|
|
||||||
taskManager.AddTask(newTask);
|
|
||||||
Console.WriteLine(newTask);
|
|
||||||
}else if (task is TrangaTask.Task.DownloadChapter)
|
|
||||||
{
|
|
||||||
foreach (Chapter chapter in SelectChapters(connector!, (Publication)publication!, logger))
|
|
||||||
{
|
|
||||||
TrangaTask newTask = new DownloadChapterTask(connector!.name, (Publication)publication, chapter, "en");
|
|
||||||
taskManager.AddTask(newTask);
|
|
||||||
Console.WriteLine(newTask);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void ExecuteTaskNow(TaskManager taskManager, Logger logger)
|
|
||||||
{
|
|
||||||
logger.WriteLine("Tranga_CLI", "Menu: Executing Task");
|
|
||||||
TrangaTask[] tasks = taskManager.GetAllTasks().Where(nTask => nTask.state is not TrangaTask.ExecutionState.Running).ToArray();
|
|
||||||
|
|
||||||
TrangaTask[] selectedTasks = SelectTasks(tasks, logger);
|
|
||||||
logger.WriteLine("Tranga_CLI", $"Sending {selectedTasks.Length} Tasks to TaskManager");
|
|
||||||
foreach(TrangaTask task in selectedTasks)
|
|
||||||
taskManager.ExecuteTaskNow(task);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void DeleteTask(TaskManager taskManager, Logger logger)
|
|
||||||
{
|
|
||||||
logger.WriteLine("Tranga_CLI", "Menu: Delete Task");
|
|
||||||
TrangaTask[] tasks = taskManager.GetAllTasks();
|
|
||||||
|
|
||||||
TrangaTask[] selectedTasks = SelectTasks(tasks, logger);
|
|
||||||
logger.WriteLine("Tranga_CLI", $"Sending {selectedTasks.Length} Tasks to TaskManager");
|
|
||||||
foreach(TrangaTask task in selectedTasks)
|
|
||||||
taskManager.DeleteTask(task);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static TrangaTask.Task? SelectTaskType(Logger logger)
|
|
||||||
{
|
|
||||||
logger.WriteLine("Tranga_CLI", "Menu: Select TaskType");
|
|
||||||
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("Enter q to abort");
|
|
||||||
Console.WriteLine($"Select Task (0-{taskNames.Length - 1}):");
|
|
||||||
|
|
||||||
string? selectedTask = Console.ReadLine();
|
|
||||||
while(selectedTask is null || selectedTask.Length < 1)
|
|
||||||
selectedTask = Console.ReadLine();
|
|
||||||
|
|
||||||
if (selectedTask.Length == 1 && selectedTask.ToLower() == "q")
|
|
||||||
{
|
|
||||||
Console.Clear();
|
|
||||||
Console.WriteLine("aborted.");
|
|
||||||
logger.WriteLine("Tranga_CLI", "aborted.");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
int selectedTaskIndex = Convert.ToInt32(selectedTask);
|
|
||||||
string selectedTaskName = taskNames[selectedTaskIndex];
|
|
||||||
return Enum.Parse<TrangaTask.Task>(selectedTaskName);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"Exception: {e.Message}");
|
|
||||||
logger.WriteLine("Tranga_CLI", e.Message);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static TimeSpan SelectReoccurrence(Logger logger)
|
|
||||||
{
|
|
||||||
logger.WriteLine("Tranga_CLI", "Menu: Select Reoccurrence");
|
|
||||||
Console.WriteLine("Select reoccurrence Timer (Format hh:mm:ss):");
|
|
||||||
return TimeSpan.Parse(Console.ReadLine()!, new CultureInfo("en-US"));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Chapter[] SelectChapters(Connector connector, Publication publication, Logger logger)
|
|
||||||
{
|
|
||||||
logger.WriteLine("Tranga_CLI", "Menu: Select Chapters");
|
|
||||||
Chapter[] availableChapters = connector.GetChapters(publication, "en");
|
|
||||||
int cIndex = 0;
|
|
||||||
Console.WriteLine("Chapters:");
|
|
||||||
foreach(Chapter chapter in availableChapters)
|
|
||||||
Console.WriteLine($"{cIndex++}: Vol.{chapter.volumeNumber} Ch.{chapter.chapterNumber} - {chapter.name}");
|
|
||||||
|
|
||||||
Console.WriteLine("Enter q to abort");
|
|
||||||
Console.WriteLine($"Select Chapter(s):");
|
|
||||||
|
|
||||||
string? selectedChapters = Console.ReadLine();
|
|
||||||
while(selectedChapters is null || selectedChapters.Length < 1)
|
|
||||||
selectedChapters = Console.ReadLine();
|
|
||||||
|
|
||||||
return connector.SearchChapters(publication, selectedChapters);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Connector? SelectConnector(Connector[] connectors, Logger logger)
|
|
||||||
{
|
|
||||||
logger.WriteLine("Tranga_CLI", "Menu: Select Connector");
|
|
||||||
Console.Clear();
|
|
||||||
|
|
||||||
int cIndex = 0;
|
|
||||||
Console.WriteLine("Connectors:");
|
|
||||||
foreach (Connector connector in connectors)
|
|
||||||
Console.WriteLine($"{cIndex++}: {connector.name}");
|
|
||||||
|
|
||||||
Console.WriteLine("Enter q to abort");
|
|
||||||
Console.WriteLine($"Select Connector (0-{connectors.Length - 1}):");
|
|
||||||
|
|
||||||
string? selectedConnector = Console.ReadLine();
|
|
||||||
while(selectedConnector is null || selectedConnector.Length < 1)
|
|
||||||
selectedConnector = Console.ReadLine();
|
|
||||||
|
|
||||||
if (selectedConnector.Length == 1 && selectedConnector.ToLower() == "q")
|
|
||||||
{
|
|
||||||
Console.Clear();
|
|
||||||
Console.WriteLine("aborted.");
|
|
||||||
logger.WriteLine("Tranga_CLI", "aborted.");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
int selectedConnectorIndex = Convert.ToInt32(selectedConnector);
|
|
||||||
return connectors[selectedConnectorIndex];
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"Exception: {e.Message}");
|
|
||||||
logger.WriteLine("Tranga_CLI", e.Message);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Publication? SelectPublication(TaskManager taskManager, Connector connector, Logger logger)
|
|
||||||
{
|
|
||||||
logger.WriteLine("Tranga_CLI", "Menu: Select Publication");
|
|
||||||
|
|
||||||
Console.Clear();
|
|
||||||
Console.WriteLine($"Connector: {connector.name}");
|
|
||||||
Console.WriteLine("Publication search query (leave empty for all):");
|
|
||||||
string? query = Console.ReadLine();
|
|
||||||
|
|
||||||
Publication[] publications = taskManager.GetPublicationsFromConnector(connector, query ?? "");
|
|
||||||
|
|
||||||
if (publications.Length < 1)
|
|
||||||
{
|
|
||||||
logger.WriteLine("Tranga_CLI", "No publications returned");
|
|
||||||
Console.WriteLine($"No publications for query '{query}' returned;");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
int pIndex = 0;
|
|
||||||
Console.WriteLine("Publications:");
|
|
||||||
foreach(Publication publication in publications)
|
|
||||||
Console.WriteLine($"{pIndex++}: {publication.sortName}");
|
|
||||||
|
|
||||||
Console.WriteLine("Enter q to abort");
|
|
||||||
Console.WriteLine($"Select publication to Download (0-{publications.Length - 1}):");
|
|
||||||
|
|
||||||
string? selectedPublication = Console.ReadLine();
|
|
||||||
while(selectedPublication is null || selectedPublication.Length < 1)
|
|
||||||
selectedPublication = Console.ReadLine();
|
|
||||||
|
|
||||||
if (selectedPublication.Length == 1 && selectedPublication.ToLower() == "q")
|
|
||||||
{
|
|
||||||
Console.Clear();
|
|
||||||
Console.WriteLine("aborted.");
|
|
||||||
logger.WriteLine("Tranga_CLI", "aborted.");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
int selectedPublicationIndex = Convert.ToInt32(selectedPublication);
|
|
||||||
return publications[selectedPublicationIndex];
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"Exception: {e.Message}");
|
|
||||||
logger.WriteLine("Tranga_CLI", e.Message);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void SearchTasks(TaskManager taskManager, Logger logger)
|
|
||||||
{
|
|
||||||
logger.WriteLine("Tranga_CLI", "Menu: Search task");
|
|
||||||
Console.Clear();
|
|
||||||
Console.WriteLine("Enter search query:");
|
|
||||||
string? query = Console.ReadLine();
|
|
||||||
while (query is null || query.Length < 4)
|
|
||||||
query = Console.ReadLine();
|
|
||||||
PrintTasks(taskManager.GetAllTasks().Where(qTask =>
|
|
||||||
qTask.ToString().ToLower().Contains(query, StringComparison.OrdinalIgnoreCase)).ToArray(), logger);
|
|
||||||
}
|
|
||||||
}
|
|
28
Tranga.sln
28
Tranga.sln
@ -1,12 +1,6 @@
|
|||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tranga", ".\Tranga\Tranga.csproj", "{545E81B9-D96B-4C8F-A97F-2C02414DE566}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "API", "API\API.csproj", "{EDB07E7B-351F-4FCC-9AEF-777838E5551E}"
|
||||||
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}") = "Logging", "Logging\Logging.csproj", "{415BE889-BB7D-426F-976F-8D977876A462}"
|
|
||||||
EndProject
|
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "API", "API\API.csproj", "{A8AB1F5F-D174-49DC-AED2-0909B93BA7B6}"
|
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@ -14,21 +8,9 @@ Global
|
|||||||
Release|Any CPU = Release|Any CPU
|
Release|Any CPU = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
{545E81B9-D96B-4C8F-A97F-2C02414DE566}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{EDB07E7B-351F-4FCC-9AEF-777838E5551E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{545E81B9-D96B-4C8F-A97F-2C02414DE566}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{EDB07E7B-351F-4FCC-9AEF-777838E5551E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{545E81B9-D96B-4C8F-A97F-2C02414DE566}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{EDB07E7B-351F-4FCC-9AEF-777838E5551E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{545E81B9-D96B-4C8F-A97F-2C02414DE566}.Release|Any CPU.Build.0 = Release|Any CPU
|
{EDB07E7B-351F-4FCC-9AEF-777838E5551E}.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
|
|
||||||
{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
|
|
||||||
{A8AB1F5F-D174-49DC-AED2-0909B93BA7B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{A8AB1F5F-D174-49DC-AED2-0909B93BA7B6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{A8AB1F5F-D174-49DC-AED2-0909B93BA7B6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{A8AB1F5F-D174-49DC-AED2-0909B93BA7B6}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
@ -1,7 +1,14 @@
|
|||||||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||||
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=altnames/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=authorsartists/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Gotify/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Gotify/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=jjob/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Komga/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Komga/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=lunasea/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=mangakatana/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Manganato/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Manganato/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Mangasee/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Mangasee/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Mangaworld/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Ntfy/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Taskmanager/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Taskmanager/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Tranga/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Tranga/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
@ -1,40 +0,0 @@
|
|||||||
using System.Globalization;
|
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
|
|
||||||
namespace Tranga;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 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 string? name { get; }
|
|
||||||
public string? volumeNumber { get; }
|
|
||||||
public string? chapterNumber { get; }
|
|
||||||
public string url { get; }
|
|
||||||
public string fileName { get; }
|
|
||||||
public string sortNumber { get; }
|
|
||||||
|
|
||||||
private static readonly Regex LegalCharacters = new Regex(@"([A-z]*[0-9]* *\.*-*,*\]*\[*'*\'*\)*\(*~*!*)*");
|
|
||||||
public Chapter(string? name, string? volumeNumber, string? chapterNumber, string url)
|
|
||||||
{
|
|
||||||
this.name = name;
|
|
||||||
this.volumeNumber = volumeNumber;
|
|
||||||
this.chapterNumber = chapterNumber;
|
|
||||||
this.url = url;
|
|
||||||
NumberFormatInfo nfi = new NumberFormatInfo()
|
|
||||||
{
|
|
||||||
NumberDecimalSeparator = "."
|
|
||||||
};
|
|
||||||
sortNumber = decimal.Round(Convert.ToDecimal(this.volumeNumber ?? "1") * Convert.ToDecimal(this.chapterNumber, nfi), 1)
|
|
||||||
.ToString(nfi);
|
|
||||||
|
|
||||||
string chapterName = string.Concat(LegalCharacters.Matches(name ?? ""));
|
|
||||||
string volStr = this.volumeNumber is not null ? $"Vol.{this.volumeNumber} " : "";
|
|
||||||
string chNumberStr = this.chapterNumber is not null ? $"Ch.{chapterNumber} " : "";
|
|
||||||
string chNameStr = chapterName.Length > 0 ? $"- {chapterName}" : "";
|
|
||||||
chNameStr = chNameStr.Replace("Volume", "").Replace("volume", "");
|
|
||||||
this.fileName = $"{volStr}{chNumberStr}{chNameStr}";
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,384 +0,0 @@
|
|||||||
using System.IO.Compression;
|
|
||||||
using System.Net;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
using System.Xml.Linq;
|
|
||||||
using Logging;
|
|
||||||
using Tranga.TrangaTasks;
|
|
||||||
using static System.IO.UnixFileMode;
|
|
||||||
|
|
||||||
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; init; }
|
|
||||||
|
|
||||||
protected readonly Logger? logger;
|
|
||||||
|
|
||||||
private readonly string _imageCachePath;
|
|
||||||
|
|
||||||
protected Connector(string downloadLocation, string imageCachePath, Logger? logger)
|
|
||||||
{
|
|
||||||
this.downloadLocation = downloadLocation;
|
|
||||||
this.logger = logger;
|
|
||||||
this.downloadClient = new DownloadClient(new Dictionary<byte, int>()
|
|
||||||
{
|
|
||||||
//RequestTypes for RateLimits
|
|
||||||
}, logger);
|
|
||||||
this._imageCachePath = imageCachePath;
|
|
||||||
if (!Directory.Exists(imageCachePath))
|
|
||||||
Directory.CreateDirectory(this._imageCachePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
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 = "");
|
|
||||||
|
|
||||||
public Chapter[] SearchChapters(Publication publication, string searchTerm, string? language = null)
|
|
||||||
{
|
|
||||||
Chapter[] availableChapters = this.GetChapters(publication, language??"en");
|
|
||||||
Regex volumeRegex = new ("((v(ol)*(olume)*)+ *([0-9]+(-[0-9]+)?){1})", RegexOptions.IgnoreCase);
|
|
||||||
Regex chapterRegex = new ("((c(h)*(hapter)*)+ *([0-9]+(-[0-9]+)?){1})", RegexOptions.IgnoreCase);
|
|
||||||
Regex singleResultRegex = new("([0-9]+)", RegexOptions.IgnoreCase);
|
|
||||||
Regex rangeResultRegex = new("([0-9]+(-[0-9]+))", 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.chapterNumber 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 = volumeRegex.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 => aCh.chapterNumber is not null &&
|
|
||||||
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 is not null &&
|
|
||||||
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)] };
|
|
||||||
}
|
|
||||||
|
|
||||||
return Array.Empty<Chapter>();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Retrieves the Chapter (+Images) from the website.
|
|
||||||
/// Should later call DownloadChapterImages to retrieve the individual Images of the Chapter and create .cbz archive.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="publication">Publication that contains Chapter</param>
|
|
||||||
/// <param name="chapter">Chapter with Images to retrieve</param>
|
|
||||||
/// <param name="parentTask">Will be used for progress-tracking</param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
public abstract HttpStatusCode DownloadChapter(Publication publication, Chapter chapter, DownloadChapterTask parentTask, CancellationToken? cancellationToken = null);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Copies the already downloaded cover from cache to downloadLocation
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="publication">Publication to retrieve Cover for</param>
|
|
||||||
/// <param name="settings">TrangaSettings</param>
|
|
||||||
public void CopyCoverFromCacheToDownloadLocation(Publication publication, TrangaSettings settings)
|
|
||||||
{
|
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Cloning cover {publication.sortName} -> {publication.internalId}");
|
|
||||||
//Check if Publication already has a Folder and cover
|
|
||||||
string publicationFolder = publication.CreatePublicationFolder(downloadLocation);
|
|
||||||
DirectoryInfo dirInfo = new (publicationFolder);
|
|
||||||
if (dirInfo.EnumerateFiles().Any(info => info.Name.Contains("cover", StringComparison.InvariantCultureIgnoreCase)))
|
|
||||||
{
|
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Cover exists {publication.sortName}");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
string fileInCache = Path.Join(settings.coverImageCache, publication.coverFileNameInCache);
|
|
||||||
string newFilePath = Path.Join(publicationFolder, $"cover.{Path.GetFileName(fileInCache).Split('.')[^1]}" );
|
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Cloning cover {fileInCache} -> {newFilePath}");
|
|
||||||
File.Copy(fileInCache, newFilePath, true);
|
|
||||||
if(RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
|
||||||
File.SetUnixFileMode(newFilePath, GroupRead | GroupWrite | OtherRead | OtherWrite | UserRead | UserWrite);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates a string containing XML of publication and chapter.
|
|
||||||
/// See ComicInfo.xml
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>XML-string</returns>
|
|
||||||
protected static string GetComicInfoXmlString(Publication publication, Chapter chapter, Logger? logger)
|
|
||||||
{
|
|
||||||
logger?.WriteLine("Connector", $"Creating ComicInfo.Xml for {publication.sortName} {publication.internalId} {chapter.volumeNumber}-{chapter.chapterNumber}");
|
|
||||||
XElement comicInfo = new XElement("ComicInfo",
|
|
||||||
new XElement("Tags", string.Join(',',publication.tags)),
|
|
||||||
new XElement("LanguageISO", publication.originalLanguage),
|
|
||||||
new XElement("Title", chapter.name),
|
|
||||||
new XElement("Writer", string.Join(',', publication.authors)),
|
|
||||||
new XElement("Volume", chapter.volumeNumber),
|
|
||||||
new XElement("Number", chapter.chapterNumber)
|
|
||||||
);
|
|
||||||
return comicInfo.ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Checks if a chapter-archive is already present
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>true if chapter is present</returns>
|
|
||||||
public bool CheckChapterIsDownloaded(Publication publication, Chapter chapter)
|
|
||||||
{
|
|
||||||
Regex legalCharacters = new Regex(@"([A-z]*[0-9]* *\.*-*,*\]*\[*'*\'*\)*\(*~*!*)*");
|
|
||||||
string oldFilePath = Path.Join(downloadLocation, publication.folderName, $"{string.Concat(legalCharacters.Matches(chapter.name ?? ""))} - V{chapter.volumeNumber}C{chapter.chapterNumber} - {chapter.sortNumber}.cbz");
|
|
||||||
string oldFilePath2 = Path.Join(downloadLocation, publication.folderName, $"{string.Concat(legalCharacters.Matches(chapter.name ?? ""))} - VC{chapter.chapterNumber} - {chapter.chapterNumber}.cbz");
|
|
||||||
string newFilePath = GetArchiveFilePath(publication, chapter);
|
|
||||||
if (File.Exists(oldFilePath))
|
|
||||||
File.Move(oldFilePath, newFilePath);
|
|
||||||
else if (File.Exists(oldFilePath2))
|
|
||||||
File.Move(oldFilePath2, newFilePath);
|
|
||||||
return File.Exists(newFilePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates full file path of chapter-archive
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>Filepath</returns>
|
|
||||||
protected string GetArchiveFilePath(Publication publication, Chapter chapter)
|
|
||||||
{
|
|
||||||
return Path.Join(downloadLocation, publication.folderName, $"{publication.folderName} - {chapter.fileName}.cbz");
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <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="parentTask">Used for progress tracking</param>
|
|
||||||
/// <param name="comicInfoPath">Path of the generate Chapter ComicInfo.xml, if it was generated</param>
|
|
||||||
/// <param name="requestType">RequestType for RateLimits</param>
|
|
||||||
/// <param name="referrer">Used in http request header</param>
|
|
||||||
/// <param name="cancellationToken"></param>
|
|
||||||
protected HttpStatusCode DownloadChapterImages(string[] imageUrls, string saveArchiveFilePath, byte requestType, DownloadChapterTask parentTask, string? comicInfoPath = null, string? referrer = null, CancellationToken? cancellationToken = null)
|
|
||||||
{
|
|
||||||
if (cancellationToken?.IsCancellationRequested ?? false)
|
|
||||||
return HttpStatusCode.RequestTimeout;
|
|
||||||
logger?.WriteLine("Connector", $"Downloading Images for {saveArchiveFilePath}");
|
|
||||||
//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];
|
|
||||||
logger?.WriteLine("Connector", $"Downloading Image {chapter + 1:000}/{imageUrls.Length:000} {parentTask.publication.sortName} {parentTask.publication.internalId} Vol.{parentTask.chapter.volumeNumber} Ch.{parentTask.chapter.chapterNumber} {parentTask.progress:P2}");
|
|
||||||
HttpStatusCode status = DownloadImage(imageUrl, Path.Join(tempFolder, $"{chapter++}.{extension}"), requestType, referrer);
|
|
||||||
if ((int)status < 200 || (int)status >= 300)
|
|
||||||
return status;
|
|
||||||
parentTask.IncrementProgress(1.0 / imageUrls.Length);
|
|
||||||
if (cancellationToken?.IsCancellationRequested ?? false)
|
|
||||||
return HttpStatusCode.RequestTimeout;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(comicInfoPath is not null)
|
|
||||||
File.Copy(comicInfoPath, Path.Join(tempFolder, "ComicInfo.xml"));
|
|
||||||
|
|
||||||
logger?.WriteLine("Connector", $"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
|
|
||||||
return HttpStatusCode.OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected string SaveCoverImageToCache(string url, byte requestType)
|
|
||||||
{
|
|
||||||
string[] split = url.Split('/');
|
|
||||||
string filename = split[^1];
|
|
||||||
string saveImagePath = Path.Join(_imageCachePath, 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());
|
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Saving image to {saveImagePath}");
|
|
||||||
return filename;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected class DownloadClient
|
|
||||||
{
|
|
||||||
private static readonly HttpClient Client = new()
|
|
||||||
{
|
|
||||||
Timeout = TimeSpan.FromSeconds(60)
|
|
||||||
};
|
|
||||||
|
|
||||||
private readonly Dictionary<byte, DateTime> _lastExecutedRateLimit;
|
|
||||||
private readonly Dictionary<byte, TimeSpan> _rateLimit;
|
|
||||||
// ReSharper disable once InconsistentNaming
|
|
||||||
private readonly Logger? logger;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates a httpClient
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="rateLimitRequestsPerMinute">Rate limits for requests. byte is RequestType, int maximum requests per minute for RequestType</param>
|
|
||||||
/// <param name="logger"></param>
|
|
||||||
public DownloadClient(Dictionary<byte, int> rateLimitRequestsPerMinute, Logger? logger)
|
|
||||||
{
|
|
||||||
this.logger = logger;
|
|
||||||
_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
|
|
||||||
{
|
|
||||||
logger?.WriteLine(this.GetType().ToString(), "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)
|
|
||||||
{
|
|
||||||
logger?.WriteLine(this.GetType().ToString(), e.Message);
|
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Waiting {_rateLimit[requestType] * 2}... Retrying.");
|
|
||||||
Thread.Sleep(_rateLimit[requestType] * 2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!response.IsSuccessStatusCode)
|
|
||||||
{
|
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Request-Error {response.StatusCode}: {response.ReasonPhrase}");
|
|
||||||
return new RequestResult(response.StatusCode, Stream.Null);
|
|
||||||
}
|
|
||||||
return new RequestResult(response.StatusCode, response.Content.ReadAsStream());
|
|
||||||
}
|
|
||||||
|
|
||||||
public struct RequestResult
|
|
||||||
{
|
|
||||||
public HttpStatusCode statusCode { get; }
|
|
||||||
public Stream result { get; }
|
|
||||||
|
|
||||||
public RequestResult(HttpStatusCode statusCode, Stream result)
|
|
||||||
{
|
|
||||||
this.statusCode = statusCode;
|
|
||||||
this.result = result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,283 +0,0 @@
|
|||||||
using System.Globalization;
|
|
||||||
using System.Net;
|
|
||||||
using System.Text.Json;
|
|
||||||
using System.Text.Json.Nodes;
|
|
||||||
using Logging;
|
|
||||||
using Tranga.TrangaTasks;
|
|
||||||
|
|
||||||
namespace Tranga.Connectors;
|
|
||||||
public class MangaDex : Connector
|
|
||||||
{
|
|
||||||
public override string name { get; }
|
|
||||||
|
|
||||||
private enum RequestType : byte
|
|
||||||
{
|
|
||||||
Manga,
|
|
||||||
Feed,
|
|
||||||
AtHomeServer,
|
|
||||||
CoverUrl,
|
|
||||||
Author,
|
|
||||||
}
|
|
||||||
|
|
||||||
public MangaDex(string downloadLocation, string imageCachePath, Logger? logger) : base(downloadLocation, imageCachePath, logger)
|
|
||||||
{
|
|
||||||
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}
|
|
||||||
}, logger);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override Publication[] GetPublications(string publicationTitle = "")
|
|
||||||
{
|
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Getting Publications (title={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}", (byte)RequestType.Manga);
|
|
||||||
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
|
||||||
break;
|
|
||||||
JsonObject? result = JsonSerializer.Deserialize<JsonObject>(requestResult.result);
|
|
||||||
|
|
||||||
offset += limit;
|
|
||||||
if (result is null)
|
|
||||||
break;
|
|
||||||
|
|
||||||
total = result["total"]!.GetValue<int>(); //Update the total number of Publications
|
|
||||||
|
|
||||||
JsonArray mangaInResult = result["data"]!.AsArray(); //Manga-data-Array
|
|
||||||
//Loop each Manga and extract information from JSON
|
|
||||||
foreach (JsonNode? mangeNode in mangaInResult)
|
|
||||||
{
|
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"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>();
|
|
||||||
|
|
||||||
string? description = attributes["description"]!.AsObject().ContainsKey("en") && attributes["description"]!["en"] is not null
|
|
||||||
? attributes["description"]!["en"]!.GetValue<string?>()
|
|
||||||
: null;
|
|
||||||
|
|
||||||
JsonArray altTitlesObject = attributes["altTitles"]!.AsArray();
|
|
||||||
Dictionary<string, string> altTitlesDict = new();
|
|
||||||
foreach (JsonNode? altTitleNode in altTitlesObject)
|
|
||||||
{
|
|
||||||
JsonObject altTitleObject = (JsonObject)altTitleNode!;
|
|
||||||
string key = ((IDictionary<string, JsonNode?>)altTitleObject).Keys.ToArray()[0];
|
|
||||||
altTitlesDict.TryAdd(key, altTitleObject[key]!.GetValue<string>());
|
|
||||||
}
|
|
||||||
|
|
||||||
JsonArray tagsObject = attributes["tags"]!.AsArray();
|
|
||||||
HashSet<string> tags = new();
|
|
||||||
foreach (JsonNode? tagNode in tagsObject)
|
|
||||||
{
|
|
||||||
JsonObject tagObject = (JsonObject)tagNode!;
|
|
||||||
if(tagObject["attributes"]!["name"]!.AsObject().ContainsKey("en"))
|
|
||||||
tags.Add(tagObject["attributes"]!["name"]!["en"]!.GetValue<string>());
|
|
||||||
}
|
|
||||||
|
|
||||||
string? posterId = null;
|
|
||||||
HashSet<string> authorIds = new();
|
|
||||||
if (manga.ContainsKey("relationships") && manga["relationships"] is not null)
|
|
||||||
{
|
|
||||||
JsonArray relationships = manga["relationships"]!.AsArray();
|
|
||||||
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);
|
|
||||||
|
|
||||||
List<string> authors = GetAuthors(authorIds);
|
|
||||||
|
|
||||||
Dictionary<string, string> linksDict = new();
|
|
||||||
if (attributes.ContainsKey("links") && attributes["links"] is not null)
|
|
||||||
{
|
|
||||||
JsonObject linksObject = attributes["links"]!.AsObject();
|
|
||||||
foreach (string key in ((IDictionary<string, JsonNode?>)linksObject).Keys)
|
|
||||||
{
|
|
||||||
linksDict.Add(key, linksObject[key]!.GetValue<string>());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int? year = attributes.ContainsKey("year") && attributes["year"] is not null
|
|
||||||
? attributes["year"]!.GetValue<int?>()
|
|
||||||
: null;
|
|
||||||
|
|
||||||
string? originalLanguage = attributes.ContainsKey("originalLanguage") && attributes["originalLanguage"] is not null
|
|
||||||
? attributes["originalLanguage"]!.GetValue<string?>()
|
|
||||||
: null;
|
|
||||||
|
|
||||||
string status = attributes["status"]!.GetValue<string>();
|
|
||||||
|
|
||||||
Publication pub = new (
|
|
||||||
title,
|
|
||||||
authors,
|
|
||||||
description,
|
|
||||||
altTitlesDict,
|
|
||||||
tags.ToArray(),
|
|
||||||
coverUrl,
|
|
||||||
coverCacheName,
|
|
||||||
linksDict,
|
|
||||||
year,
|
|
||||||
originalLanguage,
|
|
||||||
status,
|
|
||||||
publicationId
|
|
||||||
);
|
|
||||||
publications.Add(pub); //Add Publication (Manga) to result
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Done getting publications (title={publicationTitle})");
|
|
||||||
return publications.ToArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override Chapter[] GetChapters(Publication publication, string language = "")
|
|
||||||
{
|
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Getting Chapters for {publication.sortName} {publication.internalId} (language={language})");
|
|
||||||
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
|
|
||||||
List<Chapter> chapters = new();
|
|
||||||
//As long as we haven't requested all "Pages"
|
|
||||||
while (offset < total)
|
|
||||||
{
|
|
||||||
//Request next "Page"
|
|
||||||
DownloadClient.RequestResult requestResult =
|
|
||||||
downloadClient.MakeRequest(
|
|
||||||
$"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);
|
|
||||||
|
|
||||||
offset += limit;
|
|
||||||
if (result is null)
|
|
||||||
break;
|
|
||||||
|
|
||||||
total = result["total"]!.GetValue<int>();
|
|
||||||
JsonArray chaptersInResult = result["data"]!.AsArray();
|
|
||||||
//Loop through all Chapters in result and extract information from JSON
|
|
||||||
foreach (JsonNode? jsonNode in chaptersInResult)
|
|
||||||
{
|
|
||||||
JsonObject chapter = (JsonObject)jsonNode!;
|
|
||||||
JsonObject attributes = chapter["attributes"]!.AsObject();
|
|
||||||
string chapterId = chapter["id"]!.GetValue<string>();
|
|
||||||
|
|
||||||
string? title = attributes.ContainsKey("title") && attributes["title"] is not null
|
|
||||||
? attributes["title"]!.GetValue<string>()
|
|
||||||
: null;
|
|
||||||
|
|
||||||
string? volume = attributes.ContainsKey("volume") && attributes["volume"] is not null
|
|
||||||
? attributes["volume"]!.GetValue<string>()
|
|
||||||
: null;
|
|
||||||
|
|
||||||
string? chapterNum = attributes.ContainsKey("chapter") && attributes["chapter"] is not null
|
|
||||||
? attributes["chapter"]!.GetValue<string>()
|
|
||||||
: null;
|
|
||||||
|
|
||||||
chapters.Add(new Chapter(title, volume, chapterNum, chapterId));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Return Chapters ordered by Chapter-Number
|
|
||||||
NumberFormatInfo chapterNumberFormatInfo = new()
|
|
||||||
{
|
|
||||||
NumberDecimalSeparator = "."
|
|
||||||
};
|
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Done getting Chapters for {publication.internalId}");
|
|
||||||
return chapters.OrderBy(chapter => Convert.ToSingle(chapter.chapterNumber, chapterNumberFormatInfo)).ToArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override HttpStatusCode DownloadChapter(Publication publication, Chapter chapter, DownloadChapterTask parentTask, CancellationToken? cancellationToken = null)
|
|
||||||
{
|
|
||||||
if (cancellationToken?.IsCancellationRequested ?? false)
|
|
||||||
return HttpStatusCode.RequestTimeout;
|
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Downloading Chapter-Info {publication.sortName} {publication.internalId} {chapter.volumeNumber}-{chapter.chapterNumber}");
|
|
||||||
//Request URLs for Chapter-Images
|
|
||||||
DownloadClient.RequestResult requestResult =
|
|
||||||
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 HttpStatusCode.NoContent;
|
|
||||||
|
|
||||||
string baseUrl = result["baseUrl"]!.GetValue<string>();
|
|
||||||
string hash = result["chapter"]!["hash"]!.GetValue<string>();
|
|
||||||
JsonArray imageFileNames = result["chapter"]!["data"]!.AsArray();
|
|
||||||
//Loop through all imageNames and construct urls (imageUrl)
|
|
||||||
HashSet<string> imageUrls = new();
|
|
||||||
foreach (JsonNode? image in imageFileNames)
|
|
||||||
imageUrls.Add($"{baseUrl}/data/{hash}/{image!.GetValue<string>()}");
|
|
||||||
|
|
||||||
string comicInfoPath = Path.GetTempFileName();
|
|
||||||
File.WriteAllText(comicInfoPath, GetComicInfoXmlString(publication, chapter, logger));
|
|
||||||
|
|
||||||
//Download Chapter-Images
|
|
||||||
return DownloadChapterImages(imageUrls.ToArray(), GetArchiveFilePath(publication, chapter), (byte)RequestType.AtHomeServer, parentTask, comicInfoPath, cancellationToken:cancellationToken);
|
|
||||||
}
|
|
||||||
|
|
||||||
private string? GetCoverUrl(string publicationId, string? posterId)
|
|
||||||
{
|
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Getting CoverUrl for {publicationId}");
|
|
||||||
if (posterId is null)
|
|
||||||
{
|
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"No posterId, aborting");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Request information where to download Cover
|
|
||||||
DownloadClient.RequestResult requestResult =
|
|
||||||
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 null;
|
|
||||||
|
|
||||||
string fileName = result["data"]!["attributes"]!["fileName"]!.GetValue<string>();
|
|
||||||
|
|
||||||
string coverUrl = $"https://uploads.mangadex.org/covers/{publicationId}/{fileName}";
|
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Got Cover-Url for {publicationId} -> {coverUrl}");
|
|
||||||
return coverUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<string> GetAuthors(IEnumerable<string> authorIds)
|
|
||||||
{
|
|
||||||
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);
|
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Got author {authorId} -> {authorName}");
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,206 +0,0 @@
|
|||||||
using System.Globalization;
|
|
||||||
using System.Net;
|
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
using HtmlAgilityPack;
|
|
||||||
using Logging;
|
|
||||||
using Tranga.TrangaTasks;
|
|
||||||
|
|
||||||
namespace Tranga.Connectors;
|
|
||||||
|
|
||||||
public class Manganato : Connector
|
|
||||||
{
|
|
||||||
public override string name { get; }
|
|
||||||
|
|
||||||
public Manganato(string downloadLocation, string imageCachePath, Logger? logger) : base(downloadLocation, imageCachePath, logger)
|
|
||||||
{
|
|
||||||
this.name = "Manganato";
|
|
||||||
this.downloadClient = new DownloadClient(new Dictionary<byte, int>()
|
|
||||||
{
|
|
||||||
{(byte)1, 60}
|
|
||||||
}, logger);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override Publication[] GetPublications(string publicationTitle = "")
|
|
||||||
{
|
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Getting Publications (title={publicationTitle})");
|
|
||||||
string sanitizedTitle = string.Concat(Regex.Matches(publicationTitle, "[A-z]* *")).ToLower().Replace(' ', '_');
|
|
||||||
string requestUrl = $"https://manganato.com/search/story/{sanitizedTitle}";
|
|
||||||
DownloadClient.RequestResult requestResult =
|
|
||||||
downloadClient.MakeRequest(requestUrl, (byte)1);
|
|
||||||
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
|
||||||
return Array.Empty<Publication>();
|
|
||||||
|
|
||||||
return ParsePublicationsFromHtml(requestResult.result);
|
|
||||||
}
|
|
||||||
|
|
||||||
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, (byte)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;
|
|
||||||
default: 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 = "")
|
|
||||||
{
|
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Getting Chapters for {publication.sortName} {publication.internalId} (language={language})");
|
|
||||||
string requestUrl = $"https://chapmanganato.com/{publication.publicationId}";
|
|
||||||
DownloadClient.RequestResult requestResult =
|
|
||||||
downloadClient.MakeRequest(requestUrl, (byte)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(requestResult.result);
|
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Done getting Chapters for {publication.internalId}");
|
|
||||||
return chapters.OrderBy(chapter => Convert.ToSingle(chapter.chapterNumber, chapterNumberFormatInfo)).ToArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<Chapter> ParseChaptersFromHtml(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(chapterName, volumeNumber, chapterNumber, url));
|
|
||||||
}
|
|
||||||
ret.Reverse();
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override HttpStatusCode DownloadChapter(Publication publication, Chapter chapter, DownloadChapterTask parentTask, CancellationToken? cancellationToken = null)
|
|
||||||
{
|
|
||||||
if (cancellationToken?.IsCancellationRequested ?? false)
|
|
||||||
return HttpStatusCode.RequestTimeout;
|
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Downloading Chapter-Info {publication.sortName} {publication.internalId} {chapter.volumeNumber}-{chapter.chapterNumber}");
|
|
||||||
string requestUrl = chapter.url;
|
|
||||||
DownloadClient.RequestResult requestResult =
|
|
||||||
downloadClient.MakeRequest(requestUrl, (byte)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, GetComicInfoXmlString(publication, chapter, logger));
|
|
||||||
|
|
||||||
return DownloadChapterImages(imageUrls, GetArchiveFilePath(publication, chapter), (byte)1, parentTask, comicInfoPath, "https://chapmanganato.com/", cancellationToken);
|
|
||||||
}
|
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,245 +0,0 @@
|
|||||||
using System.Globalization;
|
|
||||||
using System.Net;
|
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
using System.Xml.Linq;
|
|
||||||
using HtmlAgilityPack;
|
|
||||||
using Logging;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
using PuppeteerSharp;
|
|
||||||
using Tranga.TrangaTasks;
|
|
||||||
|
|
||||||
namespace Tranga.Connectors;
|
|
||||||
|
|
||||||
public class Mangasee : Connector
|
|
||||||
{
|
|
||||||
public override string name { get; }
|
|
||||||
private IBrowser? _browser = null;
|
|
||||||
private const string ChromiumVersion = "1154303";
|
|
||||||
|
|
||||||
public Mangasee(string downloadLocation, string imageCachePath, Logger? logger) : base(downloadLocation,
|
|
||||||
imageCachePath, logger)
|
|
||||||
{
|
|
||||||
this.name = "Mangasee";
|
|
||||||
this.downloadClient = new DownloadClient(new Dictionary<byte, int>()
|
|
||||||
{
|
|
||||||
{ (byte)1, 60 }
|
|
||||||
}, logger);
|
|
||||||
|
|
||||||
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))
|
|
||||||
{
|
|
||||||
logger?.WriteLine(this.GetType().ToString(), "Downloading headless browser");
|
|
||||||
DateTime last = DateTime.Now.Subtract(TimeSpan.FromSeconds(5));
|
|
||||||
browserFetcher.DownloadProgressChanged += (sender, args) =>
|
|
||||||
{
|
|
||||||
double currentBytes = Convert.ToDouble(args.BytesReceived) / Convert.ToDouble(args.TotalBytesToReceive);
|
|
||||||
if (args.TotalBytesToReceive == args.BytesReceived)
|
|
||||||
{
|
|
||||||
logger?.WriteLine(this.GetType().ToString(), "Browser downloaded.");
|
|
||||||
}
|
|
||||||
else if (DateTime.Now > last.AddSeconds(5))
|
|
||||||
{
|
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Browser download progress: {currentBytes:P2}");
|
|
||||||
last = DateTime.Now;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
if (!browserFetcher.CanDownloadAsync(ChromiumVersion).Result)
|
|
||||||
{
|
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Can't download browser version {ChromiumVersion}");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
await browserFetcher.DownloadAsync(ChromiumVersion);
|
|
||||||
}
|
|
||||||
|
|
||||||
logger?.WriteLine(this.GetType().ToString(), "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"}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public override Publication[] GetPublications(string publicationTitle = "")
|
|
||||||
{
|
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Getting Publications (title={publicationTitle})");
|
|
||||||
string sanitizedTitle = string.Concat(Regex.Matches(publicationTitle, "[A-z]* *")).ToLower().Replace(' ', '+');
|
|
||||||
string requestUrl = $"https://mangasee123.com/_search.php";
|
|
||||||
DownloadClient.RequestResult requestResult =
|
|
||||||
downloadClient.MakeRequest(requestUrl, (byte)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)
|
|
||||||
{
|
|
||||||
foreach (string term in publicationTitle.Split(' '))
|
|
||||||
if (resultItem.i.Contains(term, StringComparison.CurrentCultureIgnoreCase))
|
|
||||||
if (!queryFiltered.TryAdd(resultItem, 0))
|
|
||||||
queryFiltered[resultItem]++;
|
|
||||||
}
|
|
||||||
|
|
||||||
queryFiltered = queryFiltered.Where(item => item.Value >= publicationTitle.Split(' ').Length - 1)
|
|
||||||
.ToDictionary(item => item.Key, item => item.Value);
|
|
||||||
|
|
||||||
HashSet<Publication> ret = new();
|
|
||||||
List<SearchResultItem> orderedFiltered =
|
|
||||||
queryFiltered.OrderBy(item => item.Value).ToDictionary(item => item.Key, item => item.Value).Keys.ToList();
|
|
||||||
|
|
||||||
foreach (SearchResultItem orderedItem in orderedFiltered)
|
|
||||||
{
|
|
||||||
DownloadClient.RequestResult requestResult =
|
|
||||||
downloadClient.MakeRequest($"https://mangasee123.com/manga/{orderedItem.i}", (byte)1);
|
|
||||||
if ((int)requestResult.statusCode < 200 || (int)requestResult.statusCode >= 300)
|
|
||||||
return Array.Empty<Publication>();
|
|
||||||
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);
|
|
||||||
string htmlString = reader.ReadToEnd();
|
|
||||||
HtmlDocument document = new ();
|
|
||||||
document.LoadHtml(htmlString);
|
|
||||||
|
|
||||||
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
|
|
||||||
{
|
|
||||||
#pragma warning disable CS8618 //Will always be set
|
|
||||||
public string i { get; set; }
|
|
||||||
public string s { get; set; }
|
|
||||||
public string[] a { get; set; }
|
|
||||||
#pragma warning restore CS8618
|
|
||||||
}
|
|
||||||
|
|
||||||
public override Chapter[] GetChapters(Publication publication, string language = "")
|
|
||||||
{
|
|
||||||
XDocument doc = XDocument.Load($"https://mangasee123.com/rss/{publication.publicationId}.xml");
|
|
||||||
XElement[] chapterItems = doc.Descendants("item").ToArray();
|
|
||||||
List<Chapter> ret = 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(),"");
|
|
||||||
ret.Add(new Chapter("", volumeNumber, chapterNumber, url));
|
|
||||||
}
|
|
||||||
|
|
||||||
//Return Chapters ordered by Chapter-Number
|
|
||||||
NumberFormatInfo chapterNumberFormatInfo = new()
|
|
||||||
{
|
|
||||||
NumberDecimalSeparator = "."
|
|
||||||
};
|
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Done getting Chapters for {publication.internalId}");
|
|
||||||
return ret.OrderBy(chapter => Convert.ToSingle(chapter.chapterNumber, chapterNumberFormatInfo)).ToArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override HttpStatusCode DownloadChapter(Publication publication, Chapter chapter, DownloadChapterTask parentTask, CancellationToken? cancellationToken = null)
|
|
||||||
{
|
|
||||||
if (cancellationToken?.IsCancellationRequested ?? false)
|
|
||||||
return HttpStatusCode.RequestTimeout;
|
|
||||||
while (this._browser is null && !(cancellationToken?.IsCancellationRequested??false))
|
|
||||||
{
|
|
||||||
logger?.WriteLine(this.GetType().ToString(), "Waiting for headless browser to download...");
|
|
||||||
Thread.Sleep(1000);
|
|
||||||
}
|
|
||||||
if (cancellationToken?.IsCancellationRequested??false)
|
|
||||||
return HttpStatusCode.RequestTimeout;
|
|
||||||
|
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Downloading Chapter-Info {publication.sortName} {publication.internalId} {chapter.volumeNumber}-{chapter.chapterNumber}");
|
|
||||||
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, GetComicInfoXmlString(publication, chapter, logger));
|
|
||||||
|
|
||||||
return DownloadChapterImages(urls.ToArray(), GetArchiveFilePath(publication, chapter), (byte)1, parentTask, comicInfoPath, cancellationToken:cancellationToken);
|
|
||||||
}
|
|
||||||
return response.Status;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,120 +0,0 @@
|
|||||||
using System.Net;
|
|
||||||
using System.Net.Http.Headers;
|
|
||||||
using Logging;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
using Newtonsoft.Json.Linq;
|
|
||||||
using Tranga.LibraryManagers;
|
|
||||||
|
|
||||||
namespace Tranga;
|
|
||||||
|
|
||||||
public abstract class LibraryManager
|
|
||||||
{
|
|
||||||
public enum LibraryType : byte
|
|
||||||
{
|
|
||||||
Komga = 0,
|
|
||||||
Kavita = 1
|
|
||||||
}
|
|
||||||
|
|
||||||
public LibraryType libraryType { get; }
|
|
||||||
public string baseUrl { get; }
|
|
||||||
public string auth { get; } //Base64 encoded, if you use your password everywhere, you have problems
|
|
||||||
protected Logger? logger;
|
|
||||||
|
|
||||||
/// <param name="baseUrl">Base-URL of Komga instance, no trailing slashes(/)</param>
|
|
||||||
/// <param name="auth">Base64 string of username and password (username):(password)</param>
|
|
||||||
/// <param name="logger"></param>
|
|
||||||
/// <param name="libraryType"></param>
|
|
||||||
protected LibraryManager(string baseUrl, string auth, Logger? logger, LibraryType libraryType)
|
|
||||||
{
|
|
||||||
this.baseUrl = baseUrl;
|
|
||||||
this.auth = auth;
|
|
||||||
this.logger = logger;
|
|
||||||
this.libraryType = libraryType;
|
|
||||||
}
|
|
||||||
public abstract void UpdateLibrary();
|
|
||||||
|
|
||||||
public void AddLogger(Logger newLogger)
|
|
||||||
{
|
|
||||||
this.logger = newLogger;
|
|
||||||
}
|
|
||||||
|
|
||||||
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", $"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", $"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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class LibraryManagerJsonConverter : JsonConverter
|
|
||||||
{
|
|
||||||
public override bool CanConvert(Type objectType)
|
|
||||||
{
|
|
||||||
return (objectType == typeof(LibraryManager));
|
|
||||||
}
|
|
||||||
|
|
||||||
public override object ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer)
|
|
||||||
{
|
|
||||||
JObject jo = JObject.Load(reader);
|
|
||||||
if (jo["libraryType"]!.Value<Int64>() == (Int64)LibraryType.Komga)
|
|
||||||
return jo.ToObject<Komga>(serializer)!;
|
|
||||||
|
|
||||||
if (jo["libraryType"]!.Value<Int64>() == (Int64)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");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,75 +0,0 @@
|
|||||||
using System.Text.Json.Nodes;
|
|
||||||
using Logging;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
using JsonSerializer = System.Text.Json.JsonSerializer;
|
|
||||||
|
|
||||||
namespace Tranga.LibraryManagers;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Provides connectivity to Komga-API
|
|
||||||
/// Can fetch and update libraries
|
|
||||||
/// </summary>
|
|
||||||
public class Komga : LibraryManager
|
|
||||||
{
|
|
||||||
public Komga(string baseUrl, string username, string password, Logger? logger)
|
|
||||||
: base(baseUrl, Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes($"{username}:{password}")), logger, LibraryType.Komga)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
[JsonConstructor]
|
|
||||||
public Komga(string baseUrl, string auth, Logger? logger) : base(baseUrl, auth, logger, LibraryType.Komga)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void UpdateLibrary()
|
|
||||||
{
|
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"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()
|
|
||||||
{
|
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"Getting Libraries");
|
|
||||||
Stream data = NetClient.MakeRequest($"{baseUrl}/api/v1/libraries", "Basic", auth, logger);
|
|
||||||
if (data == Stream.Null)
|
|
||||||
{
|
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"No libraries returned");
|
|
||||||
return Array.Empty<KomgaLibrary>();
|
|
||||||
}
|
|
||||||
JsonArray? result = JsonSerializer.Deserialize<JsonArray>(data);
|
|
||||||
if (result is null)
|
|
||||||
{
|
|
||||||
logger?.WriteLine(this.GetType().ToString(), $"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; }
|
|
||||||
public string name { get; }
|
|
||||||
|
|
||||||
public KomgaLibrary(string id, string name)
|
|
||||||
{
|
|
||||||
this.id = id;
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user