mirror of
https://github.com/C9Glax/tranga.git
synced 2025-06-14 15:27:53 +02:00
Compare commits
83 Commits
Author | SHA1 | Date | |
---|---|---|---|
8b99a98e24 | |||
cf171d5c38 | |||
6d49b4b934 | |||
b55d2a2d06 | |||
737eebf599 | |||
aef01b684c | |||
53bff61174 | |||
431a602a40 | |||
9afb81cee2 | |||
ea69b355b5 | |||
84dbc36bbf | |||
455c87b2e1 | |||
df991e3da6 | |||
13c96fd09a | |||
6f1a6a43ee | |||
e2afc09c4a | |||
e9db7cfacc | |||
755167c39a | |||
1cff93fbac | |||
6c775d6e0c | |||
876b1ab78b | |||
a321ecb1bc | |||
674c8fc37b | |||
e24652b83e | |||
5dee13c402 | |||
942a552c8e | |||
b5bd5d6126 | |||
715cf1f4f3 | |||
168bf5a358 | |||
636d17d287 | |||
294b819ff0 | |||
d763610383 | |||
2910473fec | |||
ca2d13226f | |||
95c65c981e | |||
e72efa3731 | |||
597eedb6d4 | |||
8829132046 | |||
32467191f6 | |||
fe52d2c3b5 | |||
554f6b4acc | |||
9d0fc18051 | |||
e02b00e0ef | |||
06a8e4e895 | |||
a557f8cab5 | |||
e564be08f5 | |||
b8bf7bdf30 | |||
d6af014cb7 | |||
2dcaaf4d66 | |||
e3ec5420c0 | |||
5d66bce5b6 | |||
07ae4af209 | |||
d62b0bdf34 | |||
a367ebb230 | |||
4d3861d31b | |||
497ec74b9a | |||
18b5d17994 | |||
1916018fba | |||
a6a2d20981 | |||
1449292e53 | |||
67f3695be8 | |||
086d72565a | |||
e54e83c2ae | |||
73f19c3989 | |||
2c84688925 | |||
a58f113d14 | |||
fcb1848a93 | |||
337111d833 | |||
bb77e5348f | |||
b1850bf5f3 | |||
f2bd5c5e85 | |||
f396640001 | |||
05763d9f22 | |||
a11830b6b5 | |||
c76f3991d9 | |||
4ee47ed65c | |||
430ee2301f | |||
58de0115d6 | |||
fa44de0c8d | |||
72bd1c56a8 | |||
538cfec619 | |||
ff01bac9d4 | |||
52f357021d |
674
LICENSE.txt
Normal file
674
LICENSE.txt
Normal file
@ -0,0 +1,674 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
32
Logging/FileLogger.cs
Normal file
32
Logging/FileLogger.cs
Normal file
@ -0,0 +1,32 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
17
Logging/FormattedConsoleLogger.cs
Normal file
17
Logging/FormattedConsoleLogger.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System.Text;
|
||||
|
||||
namespace Logging;
|
||||
|
||||
public class FormattedConsoleLogger : LoggerBase
|
||||
{
|
||||
|
||||
public FormattedConsoleLogger(TextWriter? stdOut, Encoding? encoding = null) : base(stdOut, encoding)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected override void Write(LogMessage message)
|
||||
{
|
||||
//Nothing to do yet
|
||||
}
|
||||
}
|
63
Logging/Logger.cs
Normal file
63
Logging/Logger.cs
Normal file
@ -0,0 +1,63 @@
|
||||
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();
|
||||
}
|
||||
}
|
58
Logging/LoggerBase.cs
Normal file
58
Logging/LoggerBase.cs
Normal file
@ -0,0 +1,58 @@
|
||||
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,30} | {value}";
|
||||
}
|
||||
}
|
||||
}
|
9
Logging/Logging.csproj
Normal file
9
Logging/Logging.csproj
Normal file
@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
57
Logging/MemoryLogger.cs
Normal file
57
Logging/MemoryLogger.cs
Normal file
@ -0,0 +1,57 @@
|
||||
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)
|
||||
{
|
||||
_logMessages.Add(value.logTime, value);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
141
README.md
141
README.md
@ -1,5 +1,140 @@
|
||||
Has a interactive CLI-Version as well as API-Version (no documentation of API yet).
|
||||
<!-- PROJECT SHIELDS -->
|
||||
<!--
|
||||
*** I'm using markdown "reference style" links for readability.
|
||||
*** Reference links are enclosed in brackets [ ] instead of parentheses ( ).
|
||||
*** See the bottom of this document for the declaration of the reference variables
|
||||
*** for contributors-url, forks-url, etc. This is an optional, concise syntax you may use.
|
||||
*** https://www.markdownguide.org/basic-syntax/#reference-style-links
|
||||
-->
|
||||
|
||||
Only one Connector so far: MangaDex.org (Timeout between requests 750ms)
|
||||
<!-- PROJECT LOGO -->
|
||||
<br />
|
||||
<div align="center">
|
||||
|
||||
Can automatically download new Chapters every given time-period.
|
||||
<h3 align="center">Tranga</h3>
|
||||
|
||||
<p align="center">
|
||||
Automatic Manga and Metadata downloader
|
||||
</p>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<!-- TABLE OF CONTENTS -->
|
||||
<details>
|
||||
<summary>Table of Contents</summary>
|
||||
<ol>
|
||||
<li>
|
||||
<a href="#about-the-project">About The Project</a>
|
||||
<ul>
|
||||
<li><a href="#built-with">Built With</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
<a href="#getting-started">Getting Started</a>
|
||||
<ul>
|
||||
<li><a href="#prerequisites">Prerequisites</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="#roadmap">Roadmap</a></li>
|
||||
<li><a href="#contributing">Contributing</a></li>
|
||||
<li><a href="#license">License</a></li>
|
||||
<li><a href="#acknowledgments">Acknowledgments</a></li>
|
||||
</ol>
|
||||
</details>
|
||||
|
||||
|
||||
|
||||
<!-- ABOUT THE PROJECT -->
|
||||
## About The Project
|
||||
|
||||
Tranga can download Chapters and Metadata from Scanlation sites such as
|
||||
|
||||
- [MangaDex.org](https://mangadex.org/)
|
||||
|
||||
and automatically start updates in [Komga](https://komga.org/) to import them.
|
||||
|
||||
### Inspiration:
|
||||
|
||||
Because [Kaizoku](https://github.com/oae/kaizoku) was relying on [mangal](https://github.com/metafates/mangal) and mangal
|
||||
hasn't received bugfixes for it's issues with Titles not showing up, or throwing errors because of illegal characters,
|
||||
there were no alternatives for automatic downloads. However [Kaizoku](https://github.com/oae/kaizoku) certainly had a great Web-UI.
|
||||
|
||||
That is why I wanted to create my own project, in a language I understand, and that I am able to maintain myself.
|
||||
|
||||
<p align="right">(<a href="#readme-top">back to top</a>)</p>
|
||||
|
||||
|
||||
|
||||
### Built With
|
||||
|
||||
- .NET-Core
|
||||
- Newtonsoft.JSON
|
||||
- Love <3
|
||||
|
||||
<p align="right">(<a href="#readme-top">back to top</a>)</p>
|
||||
|
||||
|
||||
|
||||
<!-- GETTING STARTED -->
|
||||
## Getting Started
|
||||
|
||||
To use head over to [releases](https://git.bernloehr.eu/glax/Tranga/releases) and download a release.
|
||||
|
||||
A CLI will guide you through setup.
|
||||
|
||||
### Prerequisites
|
||||
|
||||
[.NET-Core 7.0](https://dotnet.microsoft.com/en-us/download/dotnet/7.0)
|
||||
|
||||
<!-- ROADMAP -->
|
||||
## Roadmap
|
||||
|
||||
- [ ] Web-UI #1
|
||||
- [ ] More Connectors
|
||||
- [ ] Manganato #2
|
||||
- [ ] ?
|
||||
|
||||
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>
|
||||
|
||||
|
||||
|
||||
<!-- CONTRIBUTING -->
|
||||
## Contributing
|
||||
|
||||
The following is copy & pasted:
|
||||
|
||||
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**.
|
||||
|
||||
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement".
|
||||
Don't forget to give the project a star! Thanks again!
|
||||
|
||||
1. Fork the Project
|
||||
2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)
|
||||
3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)
|
||||
4. Push to the Branch (`git push origin feature/AmazingFeature`)
|
||||
5. Open a Pull Request
|
||||
|
||||
<p align="right">(<a href="#readme-top">back to top</a>)</p>
|
||||
|
||||
|
||||
|
||||
<!-- LICENSE -->
|
||||
## License
|
||||
|
||||
Distributed under the GNU GPLv3 License. See `LICENSE.txt` for more information.
|
||||
|
||||
<p align="right">(<a href="#readme-top">back to top</a>)</p>
|
||||
|
||||
|
||||
|
||||
<!-- ACKNOWLEDGMENTS -->
|
||||
## Acknowledgments
|
||||
|
||||
* [Choose an Open Source License](https://choosealicense.com)
|
||||
* [Font Awesome](https://fontawesome.com)
|
||||
* [Best-README-Template](https://github.com/othneildrew/Best-README-Template/tree/master)
|
||||
|
||||
<p align="right">(<a href="#readme-top">back to top</a>)</p>
|
||||
|
@ -1,51 +1,122 @@
|
||||
using System.Text.Json;
|
||||
|
||||
using Logging;
|
||||
using Tranga;
|
||||
using Tranga.Connectors;
|
||||
|
||||
TaskManager taskManager = new TaskManager(Directory.GetCurrentDirectory());
|
||||
string applicationFolderPath = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Tranga-API");
|
||||
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, "data.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, null, logFilePath);
|
||||
|
||||
logger.WriteLine("Tranga_CLI", "Loading Taskmanager.");
|
||||
TaskManager.SettingsData settings;
|
||||
if (File.Exists(settingsFilePath))
|
||||
settings = TaskManager.LoadData(settingsFilePath);
|
||||
else
|
||||
settings = new TaskManager.SettingsData(Directory.GetCurrentDirectory(), settingsFilePath, null, new HashSet<TrangaTask>());
|
||||
|
||||
TaskManager taskManager = new (settings, logger);
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen();
|
||||
builder.Services.AddControllers().AddNewtonsoftJson();
|
||||
var app = builder.Build();
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
|
||||
app.MapGet("/GetConnectors", () => JsonSerializer.Serialize(taskManager.GetAvailableConnectors().Values.ToArray()));
|
||||
app.MapGet("/GetAvailableControllers", () => taskManager.GetAvailableConnectors());
|
||||
|
||||
app.MapGet("/GetPublications", (string connectorName, string? title) =>
|
||||
app.MapGet("/GetKnownPublications", () => taskManager.GetAllPublications());
|
||||
|
||||
app.MapGet("/GetPublicationsFromConnector", (string connectorName, string title) =>
|
||||
{
|
||||
Connector? connector = taskManager.GetAvailableConnectors().FirstOrDefault(c => c.Key == connectorName).Value;
|
||||
Connector? connector = taskManager.GetAvailableConnectors().FirstOrDefault(con => con.Key == connectorName).Value;
|
||||
if (connector is null)
|
||||
return JsonSerializer.Serialize($"Connector {connectorName} is not a known connector.");
|
||||
|
||||
Publication[] publications;
|
||||
if (title is not null)
|
||||
publications = connector.GetPublications(title);
|
||||
else
|
||||
publications = connector.GetPublications();
|
||||
|
||||
return JsonSerializer.Serialize(publications);
|
||||
return Array.Empty<Publication>();
|
||||
if(title.Length < 4)
|
||||
return Array.Empty<Publication>();
|
||||
return taskManager.GetPublicationsFromConnector(connector, title);
|
||||
});
|
||||
|
||||
app.MapGet("/ListTasks", () => JsonSerializer.Serialize(taskManager.GetAllTasks()));
|
||||
app.MapGet("/Tasks/GetTaskTypes", () => Enum.GetNames(typeof(TrangaTask.Task)));
|
||||
|
||||
app.MapGet("/CreateTask",
|
||||
(TrangaTask.Task task, string connectorName, string? publicationName, TimeSpan reoccurrence, string language) =>
|
||||
{
|
||||
Publication? publication =
|
||||
taskManager.GetAllPublications().FirstOrDefault(pub => pub.downloadUrl == publicationName);
|
||||
if (publication is null)
|
||||
JsonSerializer.Serialize($"Publication {publicationName} is unknown.");
|
||||
|
||||
taskManager.AddTask(task, connectorName, publication, reoccurrence, language);
|
||||
JsonSerializer.Serialize("Success");
|
||||
});
|
||||
|
||||
app.MapGet("/RemoveTask", (TrangaTask.Task task, string connector, string? publicationName) =>
|
||||
app.MapPost("/Tasks/Create", (string taskType, string? connectorName, string? publicationId, string reoccurrenceTime, string? language) =>
|
||||
{
|
||||
Publication? publication =
|
||||
taskManager.GetAllPublications().FirstOrDefault(pub => pub.downloadUrl == publicationName);
|
||||
if (publication is null)
|
||||
JsonSerializer.Serialize($"Publication {publicationName} is unknown.");
|
||||
|
||||
taskManager.RemoveTask(task, connector, publication);
|
||||
JsonSerializer.Serialize("Success");
|
||||
Publication? publication = taskManager.GetAllPublications().FirstOrDefault(pub => pub.internalId == publicationId);
|
||||
TrangaTask.Task task = Enum.Parse<TrangaTask.Task>(taskType);
|
||||
taskManager.AddTask(task, connectorName, publication, TimeSpan.Parse(reoccurrenceTime), language??"");
|
||||
});
|
||||
|
||||
app.Run();
|
||||
app.MapPost("/Tasks/Delete", (string taskType, string? connectorName, string? publicationId) =>
|
||||
{
|
||||
Publication? publication = taskManager.GetAllPublications().FirstOrDefault(pub => pub.internalId == publicationId);
|
||||
TrangaTask.Task task = Enum.Parse<TrangaTask.Task>(taskType);
|
||||
taskManager.DeleteTask(task, connectorName, publication);
|
||||
});
|
||||
|
||||
app.MapGet("/Tasks/GetList", () => taskManager.GetAllTasks());
|
||||
|
||||
app.MapPost("/Tasks/Start", (string taskType, string? connectorName, string? publicationId) =>
|
||||
{
|
||||
TrangaTask.Task pTask = Enum.Parse<TrangaTask.Task>(taskType);
|
||||
TrangaTask? task = taskManager.GetAllTasks().FirstOrDefault(tTask =>
|
||||
tTask.task == pTask && tTask.publication?.internalId == publicationId && tTask.connectorName == connectorName);
|
||||
if (task is null)
|
||||
return;
|
||||
taskManager.ExecuteTaskNow(task);
|
||||
});
|
||||
|
||||
app.MapGet("/Tasks/GetRunningTasks",
|
||||
() => taskManager.GetAllTasks().Where(task => task.state is TrangaTask.ExecutionState.Running));
|
||||
|
||||
app.MapGet("/Queue/GetList",
|
||||
() => taskManager.GetAllTasks().Where(task => task.state is TrangaTask.ExecutionState.Enqueued));
|
||||
|
||||
app.MapPost("/Queue/Enqueue", (string taskType, string? connectorName, string? publicationId) =>
|
||||
{
|
||||
TrangaTask.Task pTask = Enum.Parse<TrangaTask.Task>(taskType);
|
||||
TrangaTask? task = taskManager.GetAllTasks().FirstOrDefault(tTask =>
|
||||
tTask.task == pTask && tTask.publication?.internalId == publicationId && tTask.connectorName == connectorName);
|
||||
if (task is null)
|
||||
return;
|
||||
taskManager.AddTaskToQueue(task);
|
||||
});
|
||||
|
||||
app.MapPost("/Queue/Dequeue", (string taskType, string? connectorName, string? publicationId) =>
|
||||
{
|
||||
TrangaTask.Task pTask = Enum.Parse<TrangaTask.Task>(taskType);
|
||||
TrangaTask? task = taskManager.GetAllTasks().FirstOrDefault(tTask =>
|
||||
tTask.task == pTask && tTask.publication?.internalId == publicationId && tTask.connectorName == connectorName);
|
||||
if (task is null)
|
||||
return;
|
||||
taskManager.RemoveTaskFromQueue(task);
|
||||
});
|
||||
|
||||
app.MapGet("/Settings/Get", () => new Settings(taskManager.settings));
|
||||
|
||||
app.MapPost("/Settings/Update", (string? downloadLocation, string? komgaUrl, string? komgaAuth) => taskManager.UpdateSettings(downloadLocation, komgaUrl, komgaAuth) );
|
||||
|
||||
app.Run();
|
||||
|
||||
class Settings
|
||||
{
|
||||
public string downloadLocation { get; }
|
||||
public Komga? komga { get; }
|
||||
|
||||
public Settings(TaskManager.SettingsData settings)
|
||||
{
|
||||
this.downloadLocation = settings.downloadLocation;
|
||||
this.komga = settings.komga;
|
||||
}
|
||||
}
|
@ -3,8 +3,8 @@
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:14826",
|
||||
"sslPort": 44333
|
||||
"applicationUrl": "http://localhost:1716",
|
||||
"sslPort": 44391
|
||||
}
|
||||
},
|
||||
"profiles": {
|
||||
@ -12,7 +12,7 @@
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"applicationUrl": "http://localhost:5119",
|
||||
"applicationUrl": "http://localhost:5177",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
@ -21,7 +21,7 @@
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"applicationUrl": "https://localhost:7070;http://localhost:5119",
|
||||
"applicationUrl": "https://localhost:7036;http://localhost:5177",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
|
@ -15,7 +15,14 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Logging\Logging.csproj" />
|
||||
<ProjectReference Include="..\Tranga\Tranga.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="7.0.5" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="7.0.6" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -1 +0,0 @@
|
||||
[{"reoccurrence":"00:00:00","lastExecuted":"2023-05-19T17:34:40.5349215+02:00","connectorName":"MangaDex","task":0,"publication":{"sortName":null,"description":null,"tags":null,"posterUrl":null,"year":null,"originalLanguage":null,"status":null,"folderName":null,"downloadUrl":null},"language":"en"}]
|
@ -1,213 +1,364 @@
|
||||
using System.Globalization;
|
||||
using Logging;
|
||||
using Tranga;
|
||||
using Tranga.Connectors;
|
||||
|
||||
namespace Tranga_CLI;
|
||||
|
||||
/*
|
||||
* This is written with pure hatred for readability.
|
||||
* At some point do this properly.
|
||||
* Read at own risk.
|
||||
*/
|
||||
|
||||
public static class Tranga_Cli
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
string folderPath = Directory.GetCurrentDirectory();
|
||||
string settingsPath = Path.Join(Directory.GetCurrentDirectory(), "lastPath.setting");
|
||||
if (File.Exists(settingsPath))
|
||||
folderPath = File.ReadAllText(settingsPath);
|
||||
string applicationFolderPath = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "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, "data.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, null, logFilePath);
|
||||
|
||||
logger.WriteLine("Tranga_CLI", "Loading Taskmanager.");
|
||||
TaskManager.SettingsData settings;
|
||||
if (File.Exists(settingsFilePath))
|
||||
settings = TaskManager.LoadData(settingsFilePath);
|
||||
else
|
||||
settings = new TaskManager.SettingsData(Directory.GetCurrentDirectory(), settingsFilePath, null, new HashSet<TrangaTask>());
|
||||
|
||||
|
||||
Console.WriteLine($"Output folder path [{folderPath}]:");
|
||||
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)
|
||||
folderPath = tmpPath;
|
||||
File.WriteAllText(settingsPath, folderPath);
|
||||
settings.UpdateSettings(pDownloadLocation: tmpPath, null);
|
||||
|
||||
Console.Write("Mode (D: Interactive only, T: TaskManager):");
|
||||
ConsoleKeyInfo mode = Console.ReadKey();
|
||||
while (mode.Key != ConsoleKey.D && mode.Key != ConsoleKey.T)
|
||||
mode = Console.ReadKey();
|
||||
Console.WriteLine();
|
||||
Console.WriteLine($"Komga BaseURL [{settings.komga?.baseUrl}]:");
|
||||
string? tmpUrl = Console.ReadLine();
|
||||
while (tmpUrl is null)
|
||||
tmpUrl = Console.ReadLine();
|
||||
if (tmpUrl.Length > 0)
|
||||
{
|
||||
Console.WriteLine("Username:");
|
||||
string? tmpUser = Console.ReadLine();
|
||||
while (tmpUser is null || tmpUser.Length < 1)
|
||||
tmpUser = Console.ReadLine();
|
||||
|
||||
Console.WriteLine("Password:");
|
||||
string tmpPass = string.Empty;
|
||||
ConsoleKey key;
|
||||
do
|
||||
{
|
||||
var keyInfo = Console.ReadKey(intercept: true);
|
||||
key = keyInfo.Key;
|
||||
|
||||
if (key == ConsoleKey.Backspace && tmpPass.Length > 0)
|
||||
{
|
||||
Console.Write("\b \b");
|
||||
tmpPass = tmpPass[0..^1];
|
||||
}
|
||||
else if (!char.IsControl(keyInfo.KeyChar))
|
||||
{
|
||||
Console.Write("*");
|
||||
tmpPass += keyInfo.KeyChar;
|
||||
}
|
||||
} while (key != ConsoleKey.Enter);
|
||||
|
||||
settings.UpdateSettings(null, new Komga(tmpUrl, tmpUser, tmpPass, logger));
|
||||
}
|
||||
|
||||
if(mode.Key == ConsoleKey.D)
|
||||
DownloadNow(folderPath);
|
||||
else if (mode.Key == ConsoleKey.T)
|
||||
TaskMode(folderPath);
|
||||
logger.WriteLine("Tranga_CLI", "Loaded.");
|
||||
TaskMode(settings, logger);
|
||||
}
|
||||
|
||||
private static void TaskMode(string folderPath)
|
||||
private static void TaskMode(TaskManager.SettingsData settings, Logger logger)
|
||||
{
|
||||
TaskManager taskManager = new TaskManager(folderPath);
|
||||
ConsoleKey selection = ConsoleKey.NoName;
|
||||
int menu = 0;
|
||||
while (selection != ConsoleKey.Escape && selection != ConsoleKey.Q)
|
||||
TaskManager taskManager = new (settings, logger);
|
||||
ConsoleKey selection = ConsoleKey.EraseEndOfFile;
|
||||
PrintMenu(taskManager, taskManager.settings.downloadLocation, logger);
|
||||
while (selection != ConsoleKey.Q)
|
||||
{
|
||||
switch (menu)
|
||||
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)
|
||||
{
|
||||
case 1:
|
||||
PrintTasks(taskManager.GetAllTasks());
|
||||
Console.WriteLine("Press any key.");
|
||||
Console.ReadKey();
|
||||
menu = 0;
|
||||
break;
|
||||
case 2:
|
||||
Connector connector = SelectConnector(folderPath, taskManager.GetAvailableConnectors().Values.ToArray());
|
||||
TrangaTask.Task task = SelectTask();
|
||||
Publication? publication = null;
|
||||
if(task != TrangaTask.Task.UpdatePublications)
|
||||
publication = SelectPublication(connector);
|
||||
TimeSpan reoccurrence = SelectReoccurrence();
|
||||
TrangaTask newTask = taskManager.AddTask(task, connector.name, publication, reoccurrence, "en");
|
||||
Console.WriteLine(newTask);
|
||||
Console.WriteLine("Press any key.");
|
||||
Console.ReadKey();
|
||||
menu = 0;
|
||||
break;
|
||||
case 3:
|
||||
RemoveTask(taskManager);
|
||||
Console.WriteLine("Press any key.");
|
||||
Console.ReadKey();
|
||||
menu = 0;
|
||||
break;
|
||||
case 4:
|
||||
ExecuteTaskNow(taskManager);
|
||||
Console.WriteLine("Press any key.");
|
||||
Console.ReadKey();
|
||||
menu = 0;
|
||||
break;
|
||||
case 5:
|
||||
Console.WriteLine("Search-Query (Name):");
|
||||
string? query = Console.ReadLine();
|
||||
while (query is null || query.Length < 1)
|
||||
query = Console.ReadLine();
|
||||
PrintTasks(taskManager.GetAllTasks().Where(qTask =>
|
||||
((Publication)qTask.publication!).sortName.ToLower()
|
||||
.Contains(query, StringComparison.OrdinalIgnoreCase)).ToArray());
|
||||
Console.WriteLine("Press any key.");
|
||||
Console.ReadKey();
|
||||
menu = 0;
|
||||
break;
|
||||
case 6:
|
||||
PrintTasks(taskManager.GetAllTasks().Where(eTask => eTask.isBeingExecuted).ToArray());
|
||||
Console.WriteLine("Press any key.");
|
||||
Console.ReadKey();
|
||||
menu = 0;
|
||||
break;
|
||||
default:
|
||||
selection = Menu(taskManager, folderPath);
|
||||
switch (selection)
|
||||
{
|
||||
case ConsoleKey.L:
|
||||
menu = 1;
|
||||
break;
|
||||
case ConsoleKey.C:
|
||||
menu = 2;
|
||||
break;
|
||||
case ConsoleKey.D:
|
||||
menu = 3;
|
||||
break;
|
||||
case ConsoleKey.E:
|
||||
menu = 4;
|
||||
break;
|
||||
case ConsoleKey.U:
|
||||
menu = 0;
|
||||
break;
|
||||
case ConsoleKey.S:
|
||||
menu = 5;
|
||||
break;
|
||||
case ConsoleKey.R:
|
||||
menu = 6;
|
||||
break;
|
||||
default:
|
||||
menu = 0;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
selection = Console.ReadKey().Key;
|
||||
switch (selection)
|
||||
{
|
||||
case ConsoleKey.L:
|
||||
PrintTasks(taskManager.GetAllTasks(), logger);
|
||||
Console.WriteLine("Press any key.");
|
||||
Console.ReadKey();
|
||||
break;
|
||||
case ConsoleKey.C:
|
||||
CreateTask(taskManager, taskManager.settings, 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:
|
||||
PrintTasks(
|
||||
taskManager.GetAllTasks().Where(eTask => eTask.state == TrangaTask.ExecutionState.Running)
|
||||
.ToArray(), logger);
|
||||
Console.WriteLine("Press any key.");
|
||||
Console.ReadKey();
|
||||
break;
|
||||
case ConsoleKey.K:
|
||||
PrintTasks(
|
||||
taskManager.GetAllTasks().Where(qTask => qTask.state is TrangaTask.ExecutionState.Enqueued)
|
||||
.ToArray(), logger);
|
||||
Console.WriteLine("Press any key.");
|
||||
Console.ReadKey();
|
||||
break;
|
||||
case ConsoleKey.F:
|
||||
TailLog(logger);
|
||||
Console.ReadKey();
|
||||
break;
|
||||
case ConsoleKey.M:
|
||||
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;
|
||||
}
|
||||
PrintMenu(taskManager, taskManager.settings.downloadLocation, logger);
|
||||
}
|
||||
Thread.Sleep(200);
|
||||
}
|
||||
|
||||
if (taskManager.GetAllTasks().Any(task => task.isBeingExecuted))
|
||||
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 ConsoleKey Menu(TaskManager taskManager, string folderPath)
|
||||
private static void PrintMenu(TaskManager taskManager, string folderPath, Logger logger)
|
||||
{
|
||||
int taskCount = taskManager.GetAllTasks().Length;
|
||||
int taskRunningCount = taskManager.GetAllTasks().Count(task => task.isBeingExecuted);
|
||||
int taskRunningCount = taskManager.GetAllTasks().Count(task => task.state == TrangaTask.ExecutionState.Running);
|
||||
int taskEnqueuedCount =
|
||||
taskManager.GetAllTasks().Count(task => task.state == TrangaTask.ExecutionState.Enqueued);
|
||||
Console.Clear();
|
||||
Console.WriteLine($"Download Folder: {folderPath} Tasks (Running/Total): {taskRunningCount}/{taskCount}");
|
||||
Console.WriteLine("U: Update this Screen");
|
||||
Console.WriteLine("L: List tasks");
|
||||
Console.WriteLine("C: Create Task");
|
||||
Console.WriteLine("D: Delete Task");
|
||||
Console.WriteLine("E: Execute Task now");
|
||||
Console.WriteLine("S: Search Task");
|
||||
Console.WriteLine("R: Running Tasks");
|
||||
Console.WriteLine("Q: Exit");
|
||||
ConsoleKey selection = Console.ReadKey().Key;
|
||||
Console.WriteLine($"Download Folder: {folderPath}");
|
||||
Console.WriteLine($"Tasks (Running/Queue/Total)): {taskRunningCount}/{taskEnqueuedCount}/{taskCount}");
|
||||
Console.WriteLine();
|
||||
return selection;
|
||||
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}{"M: Remove Task from Queue", -30}");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine($"{"",-30}{"F: Show Log",-30}{"Q: Exit",-30}");
|
||||
}
|
||||
|
||||
private static void PrintTasks(TrangaTask[] tasks)
|
||||
private static void PrintTasks(TrangaTask[] tasks, Logger logger)
|
||||
{
|
||||
logger.WriteLine("Tranga_CLI", "Printing Tasks");
|
||||
int taskCount = tasks.Length;
|
||||
int taskRunningCount = tasks.Count(task => task.isBeingExecuted);
|
||||
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/Total): {taskRunningCount}/{taskCount}");
|
||||
Console.WriteLine($"Tasks (Running/Queue/Total): {taskRunningCount}/{taskEnqueuedCount}/{taskCount}");
|
||||
string header =
|
||||
$"{"",-5}{"Task",-20} | {"Last Executed",-20} | {"Reoccurrence",-12} | {"State",-10} | {"Connector",-15} | Publication/Manga";
|
||||
Console.WriteLine(header);
|
||||
Console.WriteLine(new string('-', header.Length));
|
||||
foreach(TrangaTask trangaTask in tasks)
|
||||
Console.WriteLine($"{tIndex++:000}: {trangaTask}");
|
||||
}
|
||||
|
||||
private static void ExecuteTaskNow(TaskManager taskManager)
|
||||
private static TrangaTask? SelectTask(TrangaTask[] tasks, Logger logger)
|
||||
{
|
||||
TrangaTask[] tasks = taskManager.GetAllTasks();
|
||||
logger.WriteLine("Tranga_CLI", "Menu: Select task");
|
||||
if (tasks.Length < 1)
|
||||
{
|
||||
Console.Clear();
|
||||
Console.WriteLine("There are no available Tasks.");
|
||||
return;
|
||||
logger.WriteLine("Tranga_CLI", "No available Tasks.");
|
||||
return null;
|
||||
}
|
||||
PrintTasks(tasks);
|
||||
PrintTasks(tasks, logger);
|
||||
|
||||
logger.WriteLine("Tranga_CLI", "Selecting Task to Remove (from queue)");
|
||||
Console.WriteLine("Enter q to abort");
|
||||
Console.WriteLine($"Select Task (0-{tasks.Length - 1}):");
|
||||
|
||||
string? selectedTask = Console.ReadLine();
|
||||
while(selectedTask is null || selectedTask.Length < 1)
|
||||
selectedTask = Console.ReadLine();
|
||||
int selectedTaskIndex = Convert.ToInt32(selectedTask);
|
||||
|
||||
taskManager.ExecuteTaskNow(tasks[selectedTaskIndex]);
|
||||
}
|
||||
|
||||
private static void RemoveTask(TaskManager taskManager)
|
||||
{
|
||||
TrangaTask[] tasks = taskManager.GetAllTasks();
|
||||
if (tasks.Length < 1)
|
||||
if (selectedTask.Length == 1 && selectedTask.ToLower() == "q")
|
||||
{
|
||||
Console.Clear();
|
||||
Console.WriteLine("There are no available Tasks.");
|
||||
return;
|
||||
Console.WriteLine("aborted.");
|
||||
logger.WriteLine("Tranga_CLI", "aborted");
|
||||
return null;
|
||||
}
|
||||
PrintTasks(tasks);
|
||||
|
||||
Console.WriteLine($"Select Task (0-{tasks.Length - 1}):");
|
||||
try
|
||||
{
|
||||
int selectedTaskIndex = Convert.ToInt32(selectedTask);
|
||||
logger.WriteLine("Tranga_CLI", "Sending Task to TaskManager");
|
||||
return tasks[selectedTaskIndex];
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine($"Exception: {e.Message}");
|
||||
logger.WriteLine("Tranga_CLI", e.Message);
|
||||
}
|
||||
|
||||
string? selectedTask = Console.ReadLine();
|
||||
while(selectedTask is null || selectedTask.Length < 1)
|
||||
selectedTask = Console.ReadLine();
|
||||
int selectedTaskIndex = Convert.ToInt32(selectedTask);
|
||||
|
||||
taskManager.RemoveTask(tasks[selectedTaskIndex].task, tasks[selectedTaskIndex].connectorName, tasks[selectedTaskIndex].publication);
|
||||
return null;
|
||||
}
|
||||
|
||||
private static TrangaTask.Task SelectTask()
|
||||
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? selectedTask = SelectTask(tasks, logger);
|
||||
if (selectedTask is null)
|
||||
return;
|
||||
|
||||
logger.WriteLine("Tranga_CLI", "Sending Task to TaskManager");
|
||||
taskManager.AddTaskToQueue(selectedTask);
|
||||
}
|
||||
|
||||
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? selectedTask = SelectTask(tasks, logger);
|
||||
if (selectedTask is null)
|
||||
return;
|
||||
|
||||
logger.WriteLine("Tranga_CLI", "Sending Task to TaskManager");
|
||||
taskManager.RemoveTaskFromQueue(selectedTask);
|
||||
}
|
||||
|
||||
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, TaskManager.SettingsData settings, 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.UpdateKomgaLibrary)
|
||||
{
|
||||
connector = SelectConnector(settings.downloadLocation, taskManager.GetAvailableConnectors().Values.ToArray(), logger);
|
||||
if (connector is null)
|
||||
return;
|
||||
}
|
||||
|
||||
Publication? publication = null;
|
||||
if (task != TrangaTask.Task.UpdatePublications && task != TrangaTask.Task.UpdateKomgaLibrary)
|
||||
{
|
||||
publication = SelectPublication(connector!, logger);
|
||||
if (publication is null)
|
||||
return;
|
||||
}
|
||||
|
||||
TimeSpan reoccurrence = SelectReoccurrence(logger);
|
||||
logger.WriteLine("Tranga_CLI", "Sending Task to TaskManager");
|
||||
TrangaTask newTask = taskManager.AddTask(task, connector?.name, publication, reoccurrence, "en");
|
||||
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? selectedTask = SelectTask(tasks, logger);
|
||||
if (selectedTask is null)
|
||||
return;
|
||||
|
||||
logger.WriteLine("Tranga_CLI", "Sending Task to TaskManager");
|
||||
taskManager.ExecuteTaskNow(selectedTask);
|
||||
}
|
||||
|
||||
private static void DeleteTask(TaskManager taskManager, Logger logger)
|
||||
{
|
||||
logger.WriteLine("Tranga_CLI", "Menu: Delete Task");
|
||||
TrangaTask[] tasks = taskManager.GetAllTasks();
|
||||
|
||||
TrangaTask? selectedTask = SelectTask(tasks, logger);
|
||||
if (selectedTask is null)
|
||||
return;
|
||||
|
||||
logger.WriteLine("Tranga_CLI", "Sending Task to TaskManager");
|
||||
taskManager.DeleteTask(selectedTask.task, selectedTask.connectorName, selectedTask.publication);
|
||||
}
|
||||
|
||||
private static TrangaTask.Task? SelectTaskType(Logger logger)
|
||||
{
|
||||
logger.WriteLine("Tranga_CLI", "Menu: Select TaskType");
|
||||
Console.Clear();
|
||||
string[] taskNames = Enum.GetNames<TrangaTask.Task>();
|
||||
|
||||
@ -215,65 +366,87 @@ public static class Tranga_Cli
|
||||
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();
|
||||
int selectedTaskIndex = Convert.ToInt32(selectedTask);
|
||||
|
||||
string selectedTaskName = taskNames[selectedTaskIndex];
|
||||
return Enum.Parse<TrangaTask.Task>(selectedTaskName);
|
||||
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()
|
||||
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 void DownloadNow(string folderPath)
|
||||
{
|
||||
Connector connector = SelectConnector(folderPath);
|
||||
|
||||
Publication publication = SelectPublication(connector);
|
||||
|
||||
Chapter[] downloadChapters = SelectChapters(connector, publication);
|
||||
|
||||
if (downloadChapters.Length > 0)
|
||||
{
|
||||
connector.DownloadCover(publication);
|
||||
connector.SaveSeriesInfo(publication);
|
||||
}
|
||||
|
||||
foreach (Chapter chapter in downloadChapters)
|
||||
{
|
||||
Console.WriteLine($"Downloading {publication.sortName} V{chapter.volumeNumber}C{chapter.chapterNumber}");
|
||||
connector.DownloadChapter(publication, chapter);
|
||||
}
|
||||
}
|
||||
|
||||
private static Connector SelectConnector(string folderPath, Connector[]? availableConnectors = null)
|
||||
private static Connector? SelectConnector(string folderPath, Connector[] connectors, Logger logger)
|
||||
{
|
||||
logger.WriteLine("Tranga_CLI", "Menu: Select Connector");
|
||||
Console.Clear();
|
||||
Connector[] connectors = availableConnectors ?? new Connector[] { new MangaDex(folderPath) };
|
||||
|
||||
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();
|
||||
int selectedConnectorIndex = Convert.ToInt32(selectedConnector);
|
||||
|
||||
if (selectedConnector.Length == 1 && selectedConnector.ToLower() == "q")
|
||||
{
|
||||
Console.Clear();
|
||||
Console.WriteLine("aborted.");
|
||||
logger.WriteLine("Tranga_CLI", "aborted.");
|
||||
return null;
|
||||
}
|
||||
|
||||
return connectors[selectedConnectorIndex];
|
||||
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(Connector connector)
|
||||
private static Publication? SelectPublication(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):");
|
||||
@ -285,52 +458,45 @@ public static class Tranga_Cli
|
||||
Console.WriteLine("Publications:");
|
||||
foreach(Publication publication in publications)
|
||||
Console.WriteLine($"{pIndex++}: {publication.sortName}");
|
||||
Console.WriteLine($"Select publication to Download (0-{publications.Length - 1}):");
|
||||
|
||||
string? selected = Console.ReadLine();
|
||||
while(selected is null || selected.Length < 1)
|
||||
selected = Console.ReadLine();
|
||||
return publications[Convert.ToInt32(selected)];
|
||||
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 Chapter[] SelectChapters(Connector connector, Publication publication)
|
||||
private static void SearchTasks(TaskManager taskManager, Logger logger)
|
||||
{
|
||||
logger.WriteLine("Tranga_CLI", "Menu: Search task");
|
||||
Console.Clear();
|
||||
Console.WriteLine($"Connector: {connector.name} Publication: {publication.sortName}");
|
||||
Chapter[] chapters = connector.GetChapters(publication, "en");
|
||||
|
||||
int cIndex = 0;
|
||||
Console.WriteLine("Chapters:");
|
||||
foreach (Chapter ch in chapters)
|
||||
{
|
||||
string name = cIndex.ToString();
|
||||
if (ch.name is not null && ch.name.Length > 0)
|
||||
name = ch.name;
|
||||
else if (ch.chapterNumber is not null && ch.chapterNumber.Length > 0)
|
||||
name = ch.chapterNumber;
|
||||
Console.WriteLine($"{cIndex++}: {name}");
|
||||
}
|
||||
Console.WriteLine($"Select Chapters to download (0-{chapters.Length - 1}) [range x-y or 'a' for all]: ");
|
||||
string? selected = Console.ReadLine();
|
||||
while(selected is null || selected.Length < 1)
|
||||
selected = Console.ReadLine();
|
||||
|
||||
int start = 0;
|
||||
int end;
|
||||
if (selected == "a")
|
||||
end = chapters.Length - 1;
|
||||
else if (selected.Contains('-'))
|
||||
{
|
||||
string[] split = selected.Split('-');
|
||||
start = Convert.ToInt32(split[0]);
|
||||
end = Convert.ToInt32(split[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
start = Convert.ToInt32(selected);
|
||||
end = Convert.ToInt32(selected);
|
||||
}
|
||||
|
||||
return chapters.Skip(start).Take((end + 1)-start).ToArray();
|
||||
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);
|
||||
}
|
||||
}
|
16
Tranga.sln
16
Tranga.sln
@ -4,7 +4,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tranga", ".\Tranga\Tranga.c
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tranga-CLI", "Tranga-CLI\Tranga-CLI.csproj", "{4899E3B2-B259-479A-B43E-042D043E9501}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tranga-API", "Tranga-API\Tranga-API.csproj", "{6284C936-4E90-486B-BC46-0AFAD85AD8EE}"
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Logging", "Logging\Logging.csproj", "{415BE889-BB7D-426F-976F-8D977876A462}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tranga-API", "Tranga-API\Tranga-API.csproj", "{48F4E495-75BC-4402-8E03-DEC5B79D7E83}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@ -20,9 +22,13 @@ Global
|
||||
{4899E3B2-B259-479A-B43E-042D043E9501}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{4899E3B2-B259-479A-B43E-042D043E9501}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{4899E3B2-B259-479A-B43E-042D043E9501}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{6284C936-4E90-486B-BC46-0AFAD85AD8EE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{6284C936-4E90-486B-BC46-0AFAD85AD8EE}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{6284C936-4E90-486B-BC46-0AFAD85AD8EE}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{6284C936-4E90-486B-BC46-0AFAD85AD8EE}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{415BE889-BB7D-426F-976F-8D977876A462}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{415BE889-BB7D-426F-976F-8D977876A462}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{415BE889-BB7D-426F-976F-8D977876A462}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{415BE889-BB7D-426F-976F-8D977876A462}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{48F4E495-75BC-4402-8E03-DEC5B79D7E83}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{48F4E495-75BC-4402-8E03-DEC5B79D7E83}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{48F4E495-75BC-4402-8E03-DEC5B79D7E83}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{48F4E495-75BC-4402-8E03-DEC5B79D7E83}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
@ -1,2 +1,3 @@
|
||||
<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/=Komga/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Tranga/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
@ -1,6 +1,7 @@
|
||||
using System.IO.Compression;
|
||||
using System.Net;
|
||||
using System.Xml.Linq;
|
||||
using Logging;
|
||||
|
||||
namespace Tranga;
|
||||
|
||||
@ -13,10 +14,13 @@ public abstract class Connector
|
||||
internal string downloadLocation { get; } //Location of local files
|
||||
protected DownloadClient downloadClient { get; }
|
||||
|
||||
protected Connector(string downloadLocation, uint downloadDelay)
|
||||
protected Logger? logger;
|
||||
|
||||
protected Connector(string downloadLocation, uint downloadDelay, Logger? logger)
|
||||
{
|
||||
this.downloadLocation = downloadLocation;
|
||||
this.downloadClient = new DownloadClient(downloadDelay);
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
public abstract string name { get; } //Name of the Connector (e.g. Website)
|
||||
@ -58,6 +62,7 @@ public abstract class Connector
|
||||
/// <param name="publication">Publication to save series.json for</param>
|
||||
public void SaveSeriesInfo(Publication publication)
|
||||
{
|
||||
logger?.WriteLine(this.GetType().ToString(), $"Saving series.json for {publication.sortName}");
|
||||
//Check if Publication already has a Folder and a series.json
|
||||
string publicationFolder = Path.Join(downloadLocation, publication.folderName);
|
||||
if(!Directory.Exists(publicationFolder))
|
||||
@ -68,23 +73,37 @@ public abstract class Connector
|
||||
File.WriteAllText(seriesInfoPath,publication.GetSeriesInfoJson());
|
||||
}
|
||||
|
||||
protected static string CreateComicInfo(Publication publication, Chapter chapter)
|
||||
/// <summary>
|
||||
/// Creates a string containing XML of publication and chapter.
|
||||
/// See ComicInfo.xml
|
||||
/// </summary>
|
||||
/// <returns>XML-string</returns>
|
||||
protected static string CreateComicInfo(Publication publication, Chapter chapter, Logger? logger)
|
||||
{
|
||||
logger?.WriteLine("Connector", $"Creating ComicInfo.Xml for {publication.sortName} Chapter {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("Volume", chapter.volumeNumber),
|
||||
new XElement("Number", chapter.sortNumber)
|
||||
new XElement("Number", chapter.chapterNumber) //TODO check if this is correct at some point
|
||||
);
|
||||
return comicInfo.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a chapter-archive is already present
|
||||
/// </summary>
|
||||
/// <returns>true if chapter is present</returns>
|
||||
public bool ChapterIsDownloaded(Publication publication, Chapter chapter)
|
||||
{
|
||||
return File.Exists(CreateFullFilepath(publication, chapter));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates full file path of chapter-archive
|
||||
/// </summary>
|
||||
/// <returns>Filepath</returns>
|
||||
protected string CreateFullFilepath(Publication publication, Chapter chapter)
|
||||
{
|
||||
return Path.Join(downloadLocation, publication.folderName, chapter.fileName);
|
||||
@ -111,8 +130,9 @@ public abstract class Connector
|
||||
/// <param name="saveArchiveFilePath">Full path to save archive to (without file ending .cbz)</param>
|
||||
/// <param name="downloadClient">DownloadClient of the connector</param>
|
||||
/// <param name="comicInfoPath">Path of the generate Chapter ComicInfo.xml, if it was generated</param>
|
||||
protected static void DownloadChapterImages(string[] imageUrls, string saveArchiveFilePath, DownloadClient downloadClient, string? comicInfoPath = null)
|
||||
protected static void DownloadChapterImages(string[] imageUrls, string saveArchiveFilePath, DownloadClient downloadClient, Logger? logger, string? comicInfoPath = null)
|
||||
{
|
||||
logger?.WriteLine("Connector", "Downloading Images");
|
||||
//Check if Publication Directory already exists
|
||||
string[] splitPath = saveArchiveFilePath.Split(Path.DirectorySeparatorChar);
|
||||
string directoryPath = Path.Combine(splitPath.Take(splitPath.Length - 1).ToArray());
|
||||
@ -138,6 +158,7 @@ public abstract class Connector
|
||||
if(comicInfoPath is not null)
|
||||
File.Copy(comicInfoPath, Path.Join(tempFolder, "ComicInfo.xml"));
|
||||
|
||||
logger?.WriteLine("Connector", "Creating archive");
|
||||
//ZIP-it and ship-it
|
||||
ZipFile.CreateFromDirectory(tempFolder, fullPath);
|
||||
Directory.Delete(tempFolder, true); //Cleanup
|
||||
|
@ -2,24 +2,26 @@
|
||||
using System.Net;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Nodes;
|
||||
using Logging;
|
||||
|
||||
namespace Tranga.Connectors;
|
||||
public class MangaDex : Connector
|
||||
{
|
||||
public override string name { get; }
|
||||
|
||||
public MangaDex(string downloadLocation, uint downloadDelay) : base(downloadLocation, downloadDelay)
|
||||
public MangaDex(string downloadLocation, uint downloadDelay, Logger? logger) : base(downloadLocation, downloadDelay, logger)
|
||||
{
|
||||
name = "MangaDex";
|
||||
}
|
||||
|
||||
public MangaDex(string downloadLocation) : base(downloadLocation, 750)
|
||||
public MangaDex(string downloadLocation, Logger? logger) : base(downloadLocation, 750, logger)
|
||||
{
|
||||
name = "MangaDex";
|
||||
}
|
||||
|
||||
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
|
||||
@ -56,14 +58,12 @@ public class MangaDex : Connector
|
||||
: null;
|
||||
|
||||
JsonArray altTitlesObject = attributes["altTitles"]!.AsArray();
|
||||
string[,] altTitles = new string[altTitlesObject.Count, 2];
|
||||
int titleIndex = 0;
|
||||
Dictionary<string, string> altTitlesDict = new();
|
||||
foreach (JsonNode? altTitleNode in altTitlesObject)
|
||||
{
|
||||
JsonObject altTitleObject = (JsonObject)altTitleNode!;
|
||||
string key = ((IDictionary<string, JsonNode?>)altTitleObject).Keys.ToArray()[0];
|
||||
altTitles[titleIndex, 0] = key;
|
||||
altTitles[titleIndex++, 1] = altTitleObject[key]!.GetValue<string>();
|
||||
altTitlesDict.TryAdd(key, altTitleObject[key]!.GetValue<string>());
|
||||
}
|
||||
|
||||
JsonArray tagsObject = attributes["tags"]!.AsArray();
|
||||
@ -82,16 +82,14 @@ public class MangaDex : Connector
|
||||
poster = relationships.FirstOrDefault(relationship => relationship!["type"]!.GetValue<string>() == "cover_art")!["id"]!.GetValue<string>();
|
||||
}
|
||||
|
||||
Dictionary<string, string> linksDict = new();
|
||||
string[,]? links = null;
|
||||
if (attributes.ContainsKey("links") && attributes["links"] is not null)
|
||||
{
|
||||
JsonObject linksObject = attributes["links"]!.AsObject();
|
||||
links = new string[linksObject.Count, 2];
|
||||
int linkIndex = 0;
|
||||
foreach (string key in ((IDictionary<string, JsonNode?>)linksObject).Keys)
|
||||
{
|
||||
links[linkIndex, 0] = key;
|
||||
links[linkIndex++, 1] = linksObject[key]!.GetValue<string>();
|
||||
linksDict.Add(key, linksObject[key]!.GetValue<string>());
|
||||
}
|
||||
}
|
||||
|
||||
@ -108,10 +106,10 @@ public class MangaDex : Connector
|
||||
Publication pub = new Publication(
|
||||
title,
|
||||
description,
|
||||
altTitles,
|
||||
altTitlesDict,
|
||||
tags.ToArray(),
|
||||
poster,
|
||||
links,
|
||||
linksDict,
|
||||
year,
|
||||
originalLanguage,
|
||||
status,
|
||||
@ -126,6 +124,7 @@ public class MangaDex : Connector
|
||||
|
||||
public override Chapter[] GetChapters(Publication publication, string language = "")
|
||||
{
|
||||
logger?.WriteLine(this.GetType().ToString(), $"Getting Chapters {publication.sortName} (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
|
||||
@ -180,6 +179,7 @@ public class MangaDex : Connector
|
||||
|
||||
public override void DownloadChapter(Publication publication, Chapter chapter)
|
||||
{
|
||||
logger?.WriteLine(this.GetType().ToString(), $"Download Chapter {publication.sortName} {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'");
|
||||
@ -198,14 +198,15 @@ public class MangaDex : Connector
|
||||
imageUrls.Add($"{baseUrl}/data/{hash}/{image!.GetValue<string>()}");
|
||||
|
||||
string comicInfoPath = Path.GetTempFileName();
|
||||
File.WriteAllText(comicInfoPath, CreateComicInfo(publication, chapter));
|
||||
File.WriteAllText(comicInfoPath, CreateComicInfo(publication, chapter, logger));
|
||||
|
||||
//Download Chapter-Images
|
||||
DownloadChapterImages(imageUrls.ToArray(), CreateFullFilepath(publication, chapter), downloadClient, comicInfoPath);
|
||||
DownloadChapterImages(imageUrls.ToArray(), CreateFullFilepath(publication, chapter), downloadClient, logger, comicInfoPath);
|
||||
}
|
||||
|
||||
public override void DownloadCover(Publication publication)
|
||||
{
|
||||
logger?.WriteLine(this.GetType().ToString(), $"Download cover {publication.sortName}");
|
||||
//Check if Publication already has a Folder and cover
|
||||
string publicationFolder = Path.Join(downloadLocation, publication.folderName);
|
||||
if(!Directory.Exists(publicationFolder))
|
||||
|
125
Tranga/Komga.cs
Normal file
125
Tranga/Komga.cs
Normal file
@ -0,0 +1,125 @@
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text.Json.Nodes;
|
||||
using Logging;
|
||||
using Newtonsoft.Json;
|
||||
using JsonSerializer = System.Text.Json.JsonSerializer;
|
||||
|
||||
namespace Tranga;
|
||||
|
||||
/// <summary>
|
||||
/// Provides connectivity to Komga-API
|
||||
/// Can fetch and update libraries
|
||||
/// </summary>
|
||||
public class Komga
|
||||
{
|
||||
public string baseUrl { get; }
|
||||
public string auth { get; } //Base64 encoded, if you use your password everywhere, you have problems
|
||||
|
||||
private Logger? logger;
|
||||
|
||||
/// <param name="baseUrl">Base-URL of Komga instance, no trailing slashes(/)</param>
|
||||
/// <param name="username">Komga Username</param>
|
||||
/// <param name="password">Komga password, will be base64 encoded. yea</param>
|
||||
public Komga(string baseUrl, string username, string password, Logger? logger)
|
||||
{
|
||||
this.baseUrl = baseUrl;
|
||||
this.auth = Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes($"{username}:{password}"));
|
||||
this.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>
|
||||
[JsonConstructor]
|
||||
public Komga(string baseUrl, string auth, Logger? logger)
|
||||
{
|
||||
this.baseUrl = baseUrl;
|
||||
this.auth = auth;
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fetches all libraries available to the user
|
||||
/// </summary>
|
||||
/// <returns>Array of KomgaLibraries</returns>
|
||||
public KomgaLibrary[] GetLibraries()
|
||||
{
|
||||
logger?.WriteLine(this.GetType().ToString(), $"Getting Libraries");
|
||||
Stream data = NetClient.MakeRequest($"{baseUrl}/api/v1/libraries", auth);
|
||||
JsonArray? result = JsonSerializer.Deserialize<JsonArray>(data);
|
||||
if (result is null)
|
||||
return Array.Empty<KomgaLibrary>();
|
||||
|
||||
HashSet<KomgaLibrary> ret = new();
|
||||
|
||||
foreach (JsonNode? jsonNode in result)
|
||||
{
|
||||
var jObject = (JsonObject?)jsonNode;
|
||||
string libraryId = jObject!["id"]!.GetValue<string>();
|
||||
string libraryName = jObject!["name"]!.GetValue<string>();
|
||||
ret.Add(new KomgaLibrary(libraryId, libraryName));
|
||||
}
|
||||
|
||||
return ret.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates library with given id
|
||||
/// </summary>
|
||||
/// <param name="libraryId">Id of the Komga-Library</param>
|
||||
/// <returns>true if successful</returns>
|
||||
public bool UpdateLibrary(string libraryId)
|
||||
{
|
||||
logger?.WriteLine(this.GetType().ToString(), $"Updating Libraries");
|
||||
return NetClient.MakePost($"{baseUrl}/api/v1/libraries/{libraryId}/scan", auth);
|
||||
}
|
||||
|
||||
public struct KomgaLibrary
|
||||
{
|
||||
public string id { get; }
|
||||
public string name { get; }
|
||||
|
||||
public KomgaLibrary(string id, string name)
|
||||
{
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
||||
private static class NetClient
|
||||
{
|
||||
public static Stream MakeRequest(string url, string auth)
|
||||
{
|
||||
HttpClient client = new();
|
||||
HttpRequestMessage requestMessage = new HttpRequestMessage
|
||||
{
|
||||
Method = HttpMethod.Get,
|
||||
RequestUri = new Uri(url),
|
||||
Headers =
|
||||
{
|
||||
{ "Accept", "application/json" },
|
||||
{ "Authorization", new AuthenticationHeaderValue("Basic", auth).ToString() }
|
||||
}
|
||||
};
|
||||
HttpResponseMessage response = client.Send(requestMessage);
|
||||
Stream resultString = response.IsSuccessStatusCode ? response.Content.ReadAsStream() : Stream.Null;
|
||||
return resultString;
|
||||
}
|
||||
|
||||
public static bool MakePost(string url, string auth)
|
||||
{
|
||||
HttpClient client = new();
|
||||
HttpRequestMessage requestMessage = new HttpRequestMessage
|
||||
{
|
||||
Method = HttpMethod.Post,
|
||||
RequestUri = new Uri(url),
|
||||
Headers =
|
||||
{
|
||||
{ "Accept", "application/json" },
|
||||
{ "Authorization", new AuthenticationHeaderValue("Basic", auth).ToString() }
|
||||
}
|
||||
};
|
||||
HttpResponseMessage response = client.Send(requestMessage);
|
||||
return response.IsSuccessStatusCode;
|
||||
}
|
||||
}
|
||||
}
|
@ -9,36 +9,40 @@ public readonly struct Publication
|
||||
{
|
||||
public string sortName { get; }
|
||||
// ReSharper disable UnusedAutoPropertyAccessor.Global we need it, trust
|
||||
[JsonIgnore]public string[,] altTitles { get; }
|
||||
[JsonIgnore]public Dictionary<string,string> altTitles { get; }
|
||||
// ReSharper disable trice MemberCanBePrivate.Global, trust
|
||||
public string? description { get; }
|
||||
public string[] tags { get; }
|
||||
public string? posterUrl { get; }
|
||||
[JsonIgnore]public string[,]? links { get; }
|
||||
[JsonIgnore]public Dictionary<string,string> links { get; }
|
||||
public int? year { get; }
|
||||
public string? originalLanguage { get; }
|
||||
public string status { get; }
|
||||
public string folderName { get; }
|
||||
public string downloadUrl { get; }
|
||||
public string internalId { get; }
|
||||
|
||||
public Publication(string sortName, string? description, string[,] altTitles, string[] tags, string? posterUrl, string[,]? links, int? year, string? originalLanguage, string status, string downloadUrl)
|
||||
public readonly struct ValueTuple
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public Publication(string sortName, string? description, Dictionary<string,string> altTitles, string[] tags, string? posterUrl, Dictionary<string,string>? links, int? year, string? originalLanguage, string status, string downloadUrl)
|
||||
{
|
||||
this.sortName = sortName;
|
||||
this.description = description;
|
||||
this.altTitles = altTitles;
|
||||
this.tags = tags;
|
||||
this.posterUrl = posterUrl;
|
||||
this.links = links;
|
||||
this.links = links ?? new Dictionary<string, string>();
|
||||
this.year = year;
|
||||
this.originalLanguage = originalLanguage;
|
||||
this.status = status;
|
||||
this.downloadUrl = downloadUrl;
|
||||
this.folderName = string.Concat(sortName.Split(Path.GetInvalidPathChars().Concat(Path.GetInvalidFileNameChars()).ToArray()));
|
||||
this.internalId = Guid.NewGuid().ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
|
||||
/// <returns>Serialized JSON String for series.json</returns>
|
||||
public string GetSeriesInfoJson()
|
||||
{
|
||||
@ -57,13 +61,13 @@ public readonly struct Publication
|
||||
//Only for series.json what an abomination, why are all the fields not-null????
|
||||
private struct Metadata
|
||||
{
|
||||
// ReSharper disable UnusedAutoPropertyAccessor.Local we need it, trust
|
||||
// ReSharper disable UnusedAutoPropertyAccessor.Local we need them all, trust me
|
||||
[JsonRequired] public string type { get; }
|
||||
[JsonRequired] public string publisher { get; }
|
||||
// ReSharper disable twice IdentifierTypo
|
||||
[JsonRequired] public int comicid { get; }
|
||||
[JsonRequired] public string booktype { get; }
|
||||
// ReSharper disable InconsistentNaming
|
||||
// ReSharper disable InconsistentNaming This one property is capitalized. Why?
|
||||
[JsonRequired] public string ComicImage { get; }
|
||||
[JsonRequired] public int total_issues { get; }
|
||||
[JsonRequired] public string publication_run { get; }
|
||||
@ -84,7 +88,7 @@ public readonly struct Publication
|
||||
this.status = status;
|
||||
this.description_text = description_text;
|
||||
|
||||
//kill it with fire
|
||||
//kill it with fire, but otherwise Komga will not parse
|
||||
type = "Manga";
|
||||
publisher = "";
|
||||
comicid = 0;
|
||||
|
@ -1,4 +1,6 @@
|
||||
namespace Tranga;
|
||||
using Logging;
|
||||
|
||||
namespace Tranga;
|
||||
|
||||
/// <summary>
|
||||
/// Executes TrangaTasks
|
||||
@ -7,41 +9,65 @@
|
||||
/// </summary>
|
||||
public static class TaskExecutor
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Executes TrangaTask.
|
||||
/// </summary>
|
||||
/// <param name="connectors">List of all available Connectors</param>
|
||||
/// <param name="taskManager">Parent</param>
|
||||
/// <param name="trangaTask">Task to execute</param>
|
||||
/// <param name="chapterCollection">Current chapterCollection to update</param>
|
||||
/// <param name="logger"></param>
|
||||
/// <exception cref="ArgumentException">Is thrown when there is no Connector available with the name of the TrangaTask.connectorName</exception>
|
||||
public static void Execute(Connector[] connectors, TrangaTask trangaTask, Dictionary<Publication, List<Chapter>> chapterCollection)
|
||||
public static void Execute(TaskManager taskManager, TrangaTask trangaTask, Logger? logger)
|
||||
{
|
||||
//Get Connector from list of available Connectors and the required Connector of the TrangaTask
|
||||
Connector? connector = connectors.FirstOrDefault(c => c.name == trangaTask.connectorName);
|
||||
if (connector is null)
|
||||
throw new ArgumentException($"Connector {trangaTask.connectorName} is not a known connector.");
|
||||
|
||||
if (trangaTask.isBeingExecuted)
|
||||
//Only execute task if it is not already being executed.
|
||||
if (trangaTask.state == TrangaTask.ExecutionState.Running)
|
||||
{
|
||||
logger?.WriteLine("TaskExecutor", $"Task already running {trangaTask}");
|
||||
return;
|
||||
trangaTask.isBeingExecuted = true;
|
||||
trangaTask.lastExecuted = DateTime.Now;
|
||||
}
|
||||
trangaTask.state = TrangaTask.ExecutionState.Running;
|
||||
logger?.WriteLine("TaskExecutor", $"Starting Task {trangaTask}");
|
||||
|
||||
//Connector is not needed for all tasks
|
||||
Connector? connector = null;
|
||||
if (trangaTask.task != TrangaTask.Task.UpdateKomgaLibrary)
|
||||
connector = taskManager.GetConnector(trangaTask.connectorName!);
|
||||
|
||||
//Call appropriate Method based on TrangaTask.Task
|
||||
switch (trangaTask.task)
|
||||
{
|
||||
case TrangaTask.Task.DownloadNewChapters:
|
||||
DownloadNewChapters(connector, (Publication)trangaTask.publication!, trangaTask.language, chapterCollection);
|
||||
DownloadNewChapters(connector!, (Publication)trangaTask.publication!, trangaTask.language, ref taskManager._chapterCollection);
|
||||
break;
|
||||
case TrangaTask.Task.UpdateChapters:
|
||||
UpdateChapters(connector, (Publication)trangaTask.publication!, trangaTask.language, chapterCollection);
|
||||
UpdateChapters(connector!, (Publication)trangaTask.publication!, trangaTask.language, ref taskManager._chapterCollection);
|
||||
break;
|
||||
case TrangaTask.Task.UpdatePublications:
|
||||
UpdatePublications(connector, chapterCollection);
|
||||
UpdatePublications(connector!, ref taskManager._chapterCollection);
|
||||
break;
|
||||
case TrangaTask.Task.UpdateKomgaLibrary:
|
||||
UpdateKomgaLibrary(taskManager);
|
||||
break;
|
||||
}
|
||||
|
||||
logger?.WriteLine("TaskExecutor", $"Task finished! {trangaTask}");
|
||||
trangaTask.lastExecuted = DateTime.Now;
|
||||
trangaTask.state = TrangaTask.ExecutionState.Waiting;
|
||||
}
|
||||
|
||||
trangaTask.isBeingExecuted = false;
|
||||
/// <summary>
|
||||
/// Updates all Komga-Libraries
|
||||
/// </summary>
|
||||
/// <param name="taskManager">Parent</param>
|
||||
private static void UpdateKomgaLibrary(TaskManager taskManager)
|
||||
{
|
||||
if (taskManager.komga is null)
|
||||
return;
|
||||
Komga komga = taskManager.komga;
|
||||
|
||||
Komga.KomgaLibrary[] allLibraries = komga.GetLibraries();
|
||||
foreach (Komga.KomgaLibrary lib in allLibraries)
|
||||
komga.UpdateLibrary(lib.id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -49,7 +75,7 @@ public static class TaskExecutor
|
||||
/// </summary>
|
||||
/// <param name="connector">Connector to receive Publications from</param>
|
||||
/// <param name="chapterCollection"></param>
|
||||
private static void UpdatePublications(Connector connector, Dictionary<Publication, List<Chapter>> chapterCollection)
|
||||
private static void UpdatePublications(Connector connector, ref Dictionary<Publication, List<Chapter>> chapterCollection)
|
||||
{
|
||||
Publication[] publications = connector.GetPublications();
|
||||
foreach (Publication publication in publications)
|
||||
@ -64,9 +90,9 @@ public static class TaskExecutor
|
||||
/// <param name="publication">Publication to check</param>
|
||||
/// <param name="language">Language to receive chapters for</param>
|
||||
/// <param name="chapterCollection"></param>
|
||||
private static void DownloadNewChapters(Connector connector, Publication publication, string language, Dictionary<Publication, List<Chapter>> chapterCollection)
|
||||
private static void DownloadNewChapters(Connector connector, Publication publication, string language, ref Dictionary<Publication, List<Chapter>> chapterCollection)
|
||||
{
|
||||
List<Chapter> newChapters = UpdateChapters(connector, publication, language, chapterCollection);
|
||||
List<Chapter> newChapters = UpdateChapters(connector, publication, language, ref chapterCollection);
|
||||
connector.DownloadCover(publication);
|
||||
|
||||
//Check if Publication already has a Folder and a series.json
|
||||
@ -90,7 +116,7 @@ public static class TaskExecutor
|
||||
/// <param name="language">Language to receive chapters for</param>
|
||||
/// <param name="chapterCollection"></param>
|
||||
/// <returns>List of Chapters that were previously not in collection</returns>
|
||||
private static List<Chapter> UpdateChapters(Connector connector, Publication publication, string language, Dictionary<Publication, List<Chapter>> chapterCollection)
|
||||
private static List<Chapter> UpdateChapters(Connector connector, Publication publication, string language, ref Dictionary<Publication, List<Chapter>> chapterCollection)
|
||||
{
|
||||
List<Chapter> newChaptersList = new();
|
||||
chapterCollection.TryAdd(publication, newChaptersList); //To ensure publication is actually in collection
|
||||
|
@ -1,4 +1,5 @@
|
||||
using Newtonsoft.Json;
|
||||
using Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Tranga.Connectors;
|
||||
|
||||
namespace Tranga;
|
||||
@ -9,32 +10,94 @@ namespace Tranga;
|
||||
/// </summary>
|
||||
public class TaskManager
|
||||
{
|
||||
private readonly Dictionary<Publication, List<Chapter>> _chapterCollection;
|
||||
public Dictionary<Publication, List<Chapter>> _chapterCollection = new();
|
||||
private readonly HashSet<TrangaTask> _allTasks;
|
||||
private bool _continueRunning = true;
|
||||
private readonly Connector[] _connectors;
|
||||
private readonly Dictionary<Connector, List<TrangaTask>> _taskQueue = new();
|
||||
public SettingsData settings { get; }
|
||||
private Logger? logger { get; }
|
||||
public Komga? komga { get; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="folderPath">Local path to save data (Manga) to</param>
|
||||
public TaskManager(string folderPath)
|
||||
/// <param name="downloadFolderPath">Local path to save data (Manga) to</param>
|
||||
/// <param name="settingsFilePath">Path to the settings file (data.json)</param>
|
||||
/// <param name="komgaBaseUrl">The Url of the Komga-instance that you want to update</param>
|
||||
/// <param name="komgaUsername">The Komga username</param>
|
||||
/// <param name="komgaPassword">The Komga password</param>
|
||||
/// <param name="logger"></param>
|
||||
public TaskManager(string downloadFolderPath, string? settingsFilePath = null, string? komgaBaseUrl = null, string? komgaUsername = null, string? komgaPassword = null, Logger? logger = null)
|
||||
{
|
||||
this._connectors = new Connector[]{ new MangaDex(folderPath) };
|
||||
_chapterCollection = new();
|
||||
_allTasks = ImportTasks(Directory.GetCurrentDirectory());
|
||||
this.logger = logger;
|
||||
_allTasks = new HashSet<TrangaTask>();
|
||||
if (komgaBaseUrl != null && komgaUsername != null && komgaPassword != null)
|
||||
this.komga = new Komga(komgaBaseUrl, komgaUsername, komgaPassword, logger);
|
||||
|
||||
this.settings = new SettingsData(downloadFolderPath, settingsFilePath, this.komga, this._allTasks);
|
||||
ExportData();
|
||||
|
||||
this._connectors = new Connector[]{ new MangaDex(downloadFolderPath, logger) };
|
||||
foreach(Connector cConnector in this._connectors)
|
||||
_taskQueue.Add(cConnector, new List<TrangaTask>());
|
||||
|
||||
Thread taskChecker = new(TaskCheckerThread);
|
||||
taskChecker.Start();
|
||||
}
|
||||
|
||||
public void UpdateSettings(string? downloadLocation, string? komgaUrl, string? komgaAuth)
|
||||
{
|
||||
Komga? komga = null;
|
||||
if (komgaUrl is not null && komgaAuth is not null)
|
||||
komga = new Komga(komgaUrl, komgaAuth, null);
|
||||
settings.UpdateSettings(downloadLocation, komga);
|
||||
ExportData();
|
||||
}
|
||||
|
||||
public TaskManager(SettingsData settings, Logger? logger = null)
|
||||
{
|
||||
this.logger = logger;
|
||||
this._connectors = new Connector[]{ new MangaDex(settings.downloadLocation, logger) };
|
||||
this.settings = settings;
|
||||
ExportData();
|
||||
|
||||
foreach(Connector cConnector in this._connectors)
|
||||
_taskQueue.Add(cConnector, new List<TrangaTask>());
|
||||
this.komga = settings.komga;
|
||||
_allTasks = settings.allTasks;
|
||||
Thread taskChecker = new(TaskCheckerThread);
|
||||
taskChecker.Start();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Runs continuously until shutdown.
|
||||
/// Checks if tasks have to be executed (time elapsed)
|
||||
/// </summary>
|
||||
private void TaskCheckerThread()
|
||||
{
|
||||
logger?.WriteLine(this.GetType().ToString(), "Starting TaskCheckerThread.");
|
||||
while (_continueRunning)
|
||||
{
|
||||
foreach (TrangaTask task in _allTasks)
|
||||
//Check if previous tasks have finished and execute new tasks
|
||||
foreach (KeyValuePair<Connector, List<TrangaTask>> connectorTaskQueue in _taskQueue)
|
||||
{
|
||||
if(task.ShouldExecute())
|
||||
TaskExecutor.Execute(this._connectors, task, this._chapterCollection); //Might crash here, when adding new Task while another Task is running. Check later
|
||||
if(connectorTaskQueue.Value.RemoveAll(task => task.state == TrangaTask.ExecutionState.Waiting) > 0)
|
||||
ExportData();
|
||||
|
||||
if (connectorTaskQueue.Value.Count > 0 && connectorTaskQueue.Value.All(task => task.state is TrangaTask.ExecutionState.Enqueued))
|
||||
ExecuteTaskNow(connectorTaskQueue.Value.First());
|
||||
}
|
||||
|
||||
//Check if task should be executed
|
||||
//Depending on type execute immediately or enqueue
|
||||
foreach (TrangaTask task in _allTasks.Where(aTask => aTask.ShouldExecute()))
|
||||
{
|
||||
task.state = TrangaTask.ExecutionState.Enqueued;
|
||||
if(task.connectorName is null)
|
||||
ExecuteTaskNow(task);
|
||||
else
|
||||
{
|
||||
logger?.WriteLine(this.GetType().ToString(), $"Task due: {task}");
|
||||
_taskQueue[GetConnector(task.connectorName!)].Add(task);
|
||||
}
|
||||
}
|
||||
Thread.Sleep(1000);
|
||||
}
|
||||
@ -49,9 +112,10 @@ public class TaskManager
|
||||
if (!this._allTasks.Contains(task))
|
||||
return;
|
||||
|
||||
logger?.WriteLine(this.GetType().ToString(), $"Forcing Execution: {task}");
|
||||
Task t = new Task(() =>
|
||||
{
|
||||
TaskExecutor.Execute(this._connectors, task, this._chapterCollection);
|
||||
TaskExecutor.Execute(this, task, logger);
|
||||
});
|
||||
t.Start();
|
||||
}
|
||||
@ -65,24 +129,47 @@ public class TaskManager
|
||||
/// <param name="reoccurrence">Time-Interval between Executions</param>
|
||||
/// <param name="language">language, should Task require parameter. Can be empty</param>
|
||||
/// <exception cref="ArgumentException">Is thrown when connectorName is not a available Connector</exception>
|
||||
public TrangaTask AddTask(TrangaTask.Task task, string connectorName, Publication? publication, TimeSpan reoccurrence,
|
||||
public TrangaTask AddTask(TrangaTask.Task task, string? connectorName, Publication? publication, TimeSpan reoccurrence,
|
||||
string language = "")
|
||||
{
|
||||
//Get appropriate Connector from available Connectors for TrangaTask
|
||||
Connector? connector = _connectors.FirstOrDefault(c => c.name == connectorName);
|
||||
if (connector is null)
|
||||
throw new ArgumentException($"Connector {connectorName} is not a known connector.");
|
||||
|
||||
TrangaTask newTask = new TrangaTask(connector.name, task, publication, reoccurrence, language);
|
||||
//Check if same task already exists
|
||||
if (!_allTasks.Any(trangaTask => trangaTask.task != task && trangaTask.connectorName != connector.name &&
|
||||
trangaTask.publication?.downloadUrl != publication?.downloadUrl))
|
||||
logger?.WriteLine(this.GetType().ToString(), $"Adding new Task {task} {connectorName} {publication?.sortName}");
|
||||
|
||||
TrangaTask newTask;
|
||||
if (task == TrangaTask.Task.UpdateKomgaLibrary)
|
||||
{
|
||||
if(task != TrangaTask.Task.UpdatePublications)
|
||||
_chapterCollection.Add((Publication)publication!, new List<Chapter>());
|
||||
_allTasks.Add(newTask);
|
||||
ExportTasks(Directory.GetCurrentDirectory());
|
||||
newTask = new TrangaTask(task, null, null, reoccurrence, language);
|
||||
|
||||
//Check if same task already exists
|
||||
// ReSharper disable once SimplifyLinqExpressionUseAll readabilty
|
||||
if (!_allTasks.Any(trangaTask => trangaTask.task == task))
|
||||
{
|
||||
_allTasks.Add(newTask);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(connectorName is null)
|
||||
throw new ArgumentException($"connectorName can not be null for task {task}");
|
||||
|
||||
//Get appropriate Connector from available Connectors for TrangaTask
|
||||
Connector? connector = _connectors.FirstOrDefault(c => c.name == connectorName);
|
||||
if (connector is null)
|
||||
throw new ArgumentException($"Connector {connectorName} is not a known connector.");
|
||||
|
||||
newTask = new TrangaTask(task, connector.name, publication, reoccurrence, language);
|
||||
|
||||
//Check if same task already exists
|
||||
if (!_allTasks.Any(trangaTask => trangaTask.task == task && trangaTask.connectorName == connector.name &&
|
||||
trangaTask.publication?.downloadUrl == publication?.downloadUrl))
|
||||
{
|
||||
if(task != TrangaTask.Task.UpdatePublications)
|
||||
_chapterCollection.TryAdd((Publication)publication!, new List<Chapter>());
|
||||
_allTasks.Add(newTask);
|
||||
}
|
||||
}
|
||||
logger?.WriteLine(this.GetType().ToString(), $"Added new Task {newTask.ToString()}");
|
||||
ExportData();
|
||||
|
||||
return newTask;
|
||||
}
|
||||
|
||||
@ -92,26 +179,56 @@ public class TaskManager
|
||||
/// <param name="task">TrangaTask.Task type</param>
|
||||
/// <param name="connectorName">Name of Connector that was used</param>
|
||||
/// <param name="publication">Publication that was used</param>
|
||||
public void RemoveTask(TrangaTask.Task task, string connectorName, Publication? publication)
|
||||
public void DeleteTask(TrangaTask.Task task, string? connectorName, Publication? publication)
|
||||
{
|
||||
_allTasks.RemoveWhere(trangaTask =>
|
||||
trangaTask.task == task && trangaTask.connectorName == connectorName &&
|
||||
trangaTask.publication?.downloadUrl == publication?.downloadUrl);
|
||||
ExportTasks(Directory.GetCurrentDirectory());
|
||||
logger?.WriteLine(this.GetType().ToString(), $"Removing Task {task} {publication?.sortName}");
|
||||
if (task == TrangaTask.Task.UpdateKomgaLibrary)
|
||||
{
|
||||
_allTasks.RemoveWhere(uTask => uTask.task == TrangaTask.Task.UpdateKomgaLibrary);
|
||||
logger?.WriteLine(this.GetType().ToString(), $"Removed Task {task}");
|
||||
}
|
||||
else if (connectorName is null)
|
||||
throw new ArgumentException($"connectorName can not be null for Task {task}");
|
||||
else
|
||||
{
|
||||
if(_allTasks.RemoveWhere(trangaTask =>
|
||||
trangaTask.task == task && trangaTask.connectorName == connectorName &&
|
||||
trangaTask.publication?.downloadUrl == publication?.downloadUrl) > 0)
|
||||
logger?.WriteLine(this.GetType().ToString(), $"Removed Task {task} {publication?.sortName} {publication?.downloadUrl}.");
|
||||
else
|
||||
logger?.WriteLine(this.GetType().ToString(), $"No Task {task} {publication?.sortName} {publication?.downloadUrl} could be found.");
|
||||
}
|
||||
ExportData();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// Removes a Task from the queue
|
||||
/// </summary>
|
||||
/// <param name="task"></param>
|
||||
public void RemoveTaskFromQueue(TrangaTask task)
|
||||
{
|
||||
task.lastExecuted = DateTime.Now;
|
||||
foreach (List<TrangaTask> taskList in this._taskQueue.Values)
|
||||
taskList.Remove(task);
|
||||
task.state = TrangaTask.ExecutionState.Waiting;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets last execution time to start of time
|
||||
/// Let taskManager handle enqueuing
|
||||
/// </summary>
|
||||
/// <param name="task"></param>
|
||||
public void AddTaskToQueue(TrangaTask task)
|
||||
{
|
||||
task.lastExecuted = DateTime.UnixEpoch;
|
||||
}
|
||||
|
||||
/// <returns>All available Connectors</returns>
|
||||
public Dictionary<string, Connector> GetAvailableConnectors()
|
||||
{
|
||||
return this._connectors.ToDictionary(connector => connector.name, connector => connector);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
|
||||
/// <returns>All TrangaTasks in task-collection</returns>
|
||||
public TrangaTask[] GetAllTasks()
|
||||
{
|
||||
@ -120,14 +237,37 @@ public class TaskManager
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public Publication[] GetPublicationsFromConnector(Connector connector, string? title = null)
|
||||
{
|
||||
Publication[] ret = connector.GetPublications(title ?? "");
|
||||
foreach (Publication publication in ret)
|
||||
{
|
||||
if(!_chapterCollection.Any(pub => pub.Key.sortName == publication.sortName))
|
||||
this._chapterCollection.TryAdd(publication, new List<Chapter>());
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <returns>All added Publications</returns>
|
||||
public Publication[] GetAllPublications()
|
||||
{
|
||||
return this._chapterCollection.Keys.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return Connector with given Name
|
||||
/// </summary>
|
||||
/// <param name="connectorName">Connector-name (exact)</param>
|
||||
/// <exception cref="Exception">If Connector is not available</exception>
|
||||
public Connector GetConnector(string? connectorName)
|
||||
{
|
||||
if(connectorName is null)
|
||||
throw new Exception($"connectorName can not be null");
|
||||
Connector? ret = this._connectors.FirstOrDefault(connector => connector.name == connectorName);
|
||||
if (ret is null)
|
||||
throw new Exception($"Connector {connectorName} is not an available Connector.");
|
||||
return (Connector)ret!;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Shuts down the taskManager.
|
||||
@ -135,38 +275,72 @@ public class TaskManager
|
||||
/// <param name="force">If force is true, tasks are aborted.</param>
|
||||
public void Shutdown(bool force = false)
|
||||
{
|
||||
logger?.WriteLine(this.GetType().ToString(), $"Shutting down (forced={force})");
|
||||
_continueRunning = false;
|
||||
ExportTasks(Directory.GetCurrentDirectory());
|
||||
ExportData();
|
||||
|
||||
if(force)
|
||||
Environment.Exit(_allTasks.Count(task => task.isBeingExecuted));
|
||||
Environment.Exit(_allTasks.Count(task => task.state is TrangaTask.ExecutionState.Enqueued or TrangaTask.ExecutionState.Running));
|
||||
|
||||
//Wait for tasks to finish
|
||||
while(_allTasks.Any(task => task.isBeingExecuted))
|
||||
while(_allTasks.Any(task => task.state is TrangaTask.ExecutionState.Running or TrangaTask.ExecutionState.Enqueued))
|
||||
Thread.Sleep(10);
|
||||
logger?.WriteLine(this.GetType().ToString(), "Tasks finished. Bye!");
|
||||
Environment.Exit(0);
|
||||
}
|
||||
|
||||
private HashSet<TrangaTask> ImportTasks(string importFolderPath)
|
||||
/// <summary>
|
||||
/// Loads stored data (settings, tasks) from file
|
||||
/// </summary>
|
||||
/// <param name="importFilePath">working directory, filename has to be data.json</param>
|
||||
public static SettingsData LoadData(string importFilePath)
|
||||
{
|
||||
string filePath = Path.Join(importFolderPath, "tasks.json");
|
||||
if (!File.Exists(filePath))
|
||||
return new HashSet<TrangaTask>();
|
||||
if (!File.Exists(importFilePath))
|
||||
return new SettingsData(Directory.GetCurrentDirectory(), null, null, new HashSet<TrangaTask>());
|
||||
|
||||
string toRead = File.ReadAllText(filePath);
|
||||
string toRead = File.ReadAllText(importFilePath);
|
||||
SettingsData data = JsonConvert.DeserializeObject<SettingsData>(toRead)!;
|
||||
|
||||
TrangaTask[] importTasks = JsonConvert.DeserializeObject<TrangaTask[]>(toRead)!;
|
||||
|
||||
foreach(TrangaTask task in importTasks.Where(task => task.publication is not null))
|
||||
this._chapterCollection.Add((Publication)task.publication!, new List<Chapter>());
|
||||
|
||||
return importTasks.ToHashSet();
|
||||
return data;
|
||||
}
|
||||
|
||||
private void ExportTasks(string exportFolderPath)
|
||||
/// <summary>
|
||||
/// Exports data (settings, tasks) to file
|
||||
/// </summary>
|
||||
private void ExportData()
|
||||
{
|
||||
string filePath = Path.Join(exportFolderPath, "tasks.json");
|
||||
string toWrite = JsonConvert.SerializeObject(_allTasks.ToArray());
|
||||
File.WriteAllText(filePath,toWrite);
|
||||
logger?.WriteLine(this.GetType().ToString(), $"Exporting data to {settings.settingsFilePath}");
|
||||
|
||||
|
||||
|
||||
string serializedData = JsonConvert.SerializeObject(settings);
|
||||
|
||||
File.WriteAllText(settings.settingsFilePath, serializedData);
|
||||
}
|
||||
|
||||
public class SettingsData
|
||||
{
|
||||
public string downloadLocation { get; private set; }
|
||||
public string settingsFilePath { get; }
|
||||
public Komga? komga { get; private set; }
|
||||
public HashSet<TrangaTask> allTasks { get; }
|
||||
|
||||
public SettingsData(string downloadLocation, string? settingsFilePath, Komga? komga, HashSet<TrangaTask> allTasks)
|
||||
{
|
||||
this.settingsFilePath = settingsFilePath ??
|
||||
Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
|
||||
"Tranga", "data.json");
|
||||
this.downloadLocation = downloadLocation;
|
||||
this.komga = komga;
|
||||
this.allTasks = allTasks;
|
||||
}
|
||||
|
||||
public void UpdateSettings(string? pDownloadLocation, Komga? pKomga)
|
||||
{
|
||||
if(pDownloadLocation is not null)
|
||||
this.downloadLocation = pDownloadLocation;
|
||||
if(pKomga is not null)
|
||||
this.komga = pKomga;
|
||||
}
|
||||
}
|
||||
}
|
@ -10,4 +10,8 @@
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Logging\Logging.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -7,20 +7,31 @@ namespace Tranga;
|
||||
/// </summary>
|
||||
public class TrangaTask
|
||||
{
|
||||
// ReSharper disable once CommentTypo ...tell me why!
|
||||
// ReSharper disable once CommentTypo ...Tell me why!
|
||||
// ReSharper disable once MemberCanBePrivate.Global I want it thaaat way
|
||||
public TimeSpan reoccurrence { get; }
|
||||
public DateTime lastExecuted { get; set; }
|
||||
public string connectorName { get; }
|
||||
public string? connectorName { get; }
|
||||
public Task task { get; }
|
||||
public Publication? publication { get; }
|
||||
public string language { get; }
|
||||
[JsonIgnore]public bool isBeingExecuted { get; set; }
|
||||
[JsonIgnore]public ExecutionState state { get; set; }
|
||||
|
||||
public TrangaTask(string connectorName, Task task, Publication? publication, TimeSpan reoccurrence, string language = "")
|
||||
public enum ExecutionState
|
||||
{
|
||||
if (task != Task.UpdatePublications && publication is null)
|
||||
throw new ArgumentException($"Publication has to be not null for task {task}");
|
||||
Waiting,
|
||||
Enqueued,
|
||||
Running
|
||||
};
|
||||
|
||||
public TrangaTask(Task task, string? connectorName, Publication? publication, TimeSpan reoccurrence, string language = "")
|
||||
{
|
||||
if(task != Task.UpdateKomgaLibrary && connectorName is null)
|
||||
throw new ArgumentException($"connectorName can not be null for task {task}");
|
||||
|
||||
if (publication is null && task != Task.UpdatePublications && task != Task.UpdateKomgaLibrary)
|
||||
throw new ArgumentException($"Publication can not be null for task {task}");
|
||||
|
||||
this.publication = publication;
|
||||
this.reoccurrence = reoccurrence;
|
||||
this.lastExecuted = DateTime.Now.Subtract(reoccurrence);
|
||||
@ -29,24 +40,22 @@ public class TrangaTask
|
||||
this.language = language;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns>True if elapsed time since last execution is greater than set interval</returns>
|
||||
public bool ShouldExecute()
|
||||
{
|
||||
return DateTime.Now.Subtract(this.lastExecuted) > reoccurrence;
|
||||
return DateTime.Now.Subtract(this.lastExecuted) > reoccurrence && state is ExecutionState.Waiting;
|
||||
}
|
||||
|
||||
public enum Task
|
||||
{
|
||||
UpdatePublications,
|
||||
UpdateChapters,
|
||||
DownloadNewChapters
|
||||
DownloadNewChapters,
|
||||
UpdateKomgaLibrary
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{task}\t{lastExecuted}\t{reoccurrence}\t{(isBeingExecuted ? "running" : "waiting")}\t{connectorName}\t{publication?.sortName}";
|
||||
return $"{task,-20} | {lastExecuted,-20} | {reoccurrence,-12} | {state,-10} | {connectorName,-15} | {publication?.sortName}";
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user