├── .github └── workflows │ └── executable-compile.yml ├── .gitignore ├── LICENSE ├── README.md ├── classis ├── Course │ └── __init__.py ├── Media │ ├── Book.py │ ├── Document.py │ ├── Live.py │ ├── Read.py │ ├── Video.py │ └── __init__.py ├── SelfException │ └── __init__.py ├── User │ └── __init__.py └── UserLogger │ └── __init__.py ├── config.py ├── config.yml ├── functions ├── deal_mission │ ├── __init__.py │ └── deal_course.py ├── media_download │ ├── __init__.py │ └── deal_media.py ├── set_log │ └── __init__.py └── set_time │ ├── __init__.py │ └── deal_time.py ├── main.py ├── requirements.txt ├── static ├── func_deal_mission.jpg ├── func_media_download.jpg ├── func_set_log.jpg └── func_set_time.jpg └── utils.py /.github/workflows/executable-compile.yml: -------------------------------------------------------------------------------- 1 | name: Compile executable file 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | 7 | jobs: 8 | build: 9 | runs-on: ubuntu-latest 10 | 11 | steps: 12 | - uses: actions/checkout@v3 13 | - name: Set up Python 14 | uses: actions/setup-python@v2 15 | with: 16 | python-version: '3.x' 17 | - name: Install Dependencies 18 | run: | 19 | python -m pip install --upgrade pip 20 | pip install requests 21 | - name: Get the latest release tag and increment 22 | id: get_version 23 | run: | 24 | python -c " 25 | import requests 26 | response = requests.get('https://api.github.com/repos/liuyunfz/chaoxing_tool/releases') 27 | latest_tag = response.json()[0]['tag_name'][1:] 28 | version_parts = list(map(int, latest_tag.split('.'))) 29 | if len(version_parts) == 2: 30 | version_parts.append(1) 31 | elif len(version_parts) == 3: 32 | version_parts[2] += 1 33 | new_tag = '.'.join(map(str, version_parts)) 34 | print(f'::set-output name=VERSION::{new_tag}') 35 | " 36 | - name: Use docker to compile 37 | run: | 38 | docker run -v $GITHUB_WORKSPACE:/src batonogov/pyinstaller-windows:latest 'pyinstaller -D --clean -y --distpath ./ --workpath /tmp ./main.py' 39 | - name: Fix permissions 40 | run: | 41 | sudo chmod -R 777 ${{ github.workspace }} 42 | - name: Move some necessary files 43 | run: | 44 | mv ${{ github.workspace }}/functions ${{ github.workspace }}/main/ 45 | mv ${{ github.workspace }}/classis ${{ github.workspace }}/main/_internal/ 46 | mv ${{ github.workspace }}/config.yml ${{ github.workspace }}/main/ 47 | - name: Zip the directory 48 | run: | 49 | cd ${{ github.workspace }} 50 | zip -r chaoxing_tool.zip main 51 | - name: Create Release 52 | id: create_release 53 | uses: actions/create-release@v1 54 | env: 55 | GITHUB_TOKEN: ${{ secrets.UPLOAD_TOKEN }} 56 | with: 57 | tag_name: v${{ steps.get_version.outputs.VERSION }} 58 | release_name: ${{ steps.get_version.outputs.VERSION }} Beta Release 59 | draft: false 60 | prerelease: true 61 | - name: Upload Release Asset 62 | id: upload-release-asset 63 | uses: actions/upload-release-asset@v1 64 | env: 65 | GITHUB_TOKEN: ${{ secrets.UPLOAD_TOKEN }} 66 | with: 67 | upload_url: ${{ steps.create_release.outputs.upload_url }} 68 | asset_path: ${{ github.workspace }}/chaoxing_tool.zip 69 | asset_name: chaoxing_tool.zip 70 | asset_content_type: application/zip 71 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | __pycache__ 2 | build 3 | dist 4 | chaoxing.spec 5 | .vs 6 | .idea 7 | downloads -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # chaoxing_tool 2 | 3 | 超星/学习通/尔雅 助手,帮助用户一键完成任务点、下载课程资源等。基于 Python 语言和 requests 包。 4 | 5 | 本分支是基于原项目的重构,拥有更高的可扩展性和功能的低耦合性,方便更多开发者参与贡献。 6 | 7 | 项目拥有的Log输出,方便开发者更好的还原用户使用出错时的场景。 8 | 9 | ## 功能 10 | 11 | 基础功能如下: 12 | 13 | - 用户登录 14 | - 手机号登录 15 | - Cookie 登录 16 | - 获取 用户/课程/章节 等数据 17 | - 日志输出 18 | - 程序配置读取与保存 19 | 20 | 扩展功能如下: 21 | 22 | - 一键完成课程中的任务点 23 | 24 |
25 | 26 | ![deal_mission](./static/func_deal_mission.jpg) 27 | 28 |
29 | 30 | - 下载课程中的资源 31 | 32 |
33 | 34 | ![media_download](./static/func_media_download.jpg) 35 | 36 |
37 | 38 | - 刷取课程学习次数 39 | 40 |
41 | 42 | ![media_download](./static/func_set_log.jpg) 43 | 44 |
45 | 46 | - 刷取课程视频观看时长 47 | 48 |
49 | 50 | ![media_download](./static/func_set_time.jpg) 51 | 52 |
53 | 54 | ## 运行 55 | 56 | 以下有两种使用方式,请根据您个人的实际情况与需求选择 57 | 58 | ### 可执行文件运行 59 | 60 | **如果您此前未接触过Python或其他编程语言,且只想直接快捷的使用本工具,请优先选择本方法。** 61 | 62 | **但需要注意本方法的文件只能在Windows上运行,不支持Mac** 63 | 64 | 1. 打开本项目的 [Release](https://github.com/liuyunfz/chaoxing_tool/releases/latest) 页面 65 | 2. 下载其中的`chaoxing_tool.zip`压缩包 66 | 3. 选择一个储存位置对压缩包进行解压 67 | 4. 找到`main.exe`文件双击运行 68 | 69 | ### 源文件运行 70 | 71 | 请确保您的电脑拥有`Python3`环境,以及本项目所需要用的package。 72 | 73 | 首先下载本项目的代码源文件,您可以使用Github自带的Zip download或者使用Git命令`git clone git@github.com:liuyunfz/graph-project.git` 74 | 75 | 然后对项目需要的第三方包进行安装,您可以直接用pip进行安装`pip install -r requirements.txt`,亦或是使用诸如`virtualenv`的虚拟环境进行安装。 76 | 77 | 最后通过`python main.py`运行`mian.py`文件即可 78 | 79 | ### 程序配置 80 | 81 | 详见项目根目录下的`config.yml`而不是`config.py` 82 | 83 | 后者是对配置文件进行读取的Python文件,一般不需要进行修改 84 | 85 | 以下是对`config.yml`文件中一些内容的解释 86 | 87 | ```yaml 88 | GloConfig: 89 | timeout: 3 # 全局requests模块的超时时长,即发送http请求后三秒仍未响应则会引起超时报错 90 | headers: 91 | User-Agent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36 Edg/85.0.564.51' #全局Http请求中协议头的UA设置 92 | debug: 93 | enable: True # 是否开启debug模式,即显示更加详细的软件日志 94 | level: 8 # Loggru日志输出的等级门槛 95 | 96 | FunConfig: 97 | deal-mission: 98 | video-mode: 0 # 视频任务点刷取的模式,0为立即完成,1为等时长刷取 99 | set-log: 100 | delay: 30 # 刷取学习次数的延迟,单位s 101 | 102 | UserData: 103 | cookie: '' # 里面填写账号Cookie,程序可以自动识别直接登录,免去每次输入账号密码。但Cookie经过一段时间会过期,预计3-30天 104 | auto-sign: True # 是否开启自动登录,如果为False则即使上述cookie有内容也不会自动登录 105 | ``` 106 | 107 | 如果您不太清楚以上的内容,可以不进行任何修改 108 | 109 | ## 已知问题 110 | 111 | 详见 [本项目的Bug](https://github.com/liuyunfz/chaoxing_tool/labels/bug) 112 | 113 | ## Contribute 114 | 115 | 如果您也想参与到本项目的开发中,包括但不限于新功能的添加、文档的优化。 116 | 117 | 请阅读本项目的规范文档(还没写),Fork之后提交Pr即可。 118 | 119 | ## 免责声明 120 | 121 | 本项目遵循 [GPL-3.0 License](https://github.com/liuyunfz/chaoxing_tool/blob/master/LICENSE) ,仅作为学习途径使用,请勿用于商业用途或破坏他人的知识产权 122 | 123 | -------------------------------------------------------------------------------- /classis/Course/__init__.py: -------------------------------------------------------------------------------- 1 | # _*_ coding:utf-8 _*_ 2 | # author: liuyunfz 3 | import json 4 | import re 5 | import time 6 | from urllib import parse 7 | from loguru import logger 8 | from lxml import etree 9 | 10 | from utils import doGet, xpath_first, doPost 11 | 12 | 13 | class Course: 14 | def __init__(self, course_id: str, class_id: str, url: str, course_name: str, course_author: str, cpi: str = "", headers: dict = {}, ifOpen: bool = True): 15 | self.course_id = course_id 16 | self.class_id = class_id 17 | self.url = url 18 | self.course_name = course_name 19 | self.course_author = course_author 20 | if cpi == "": 21 | self.cpi = parse.parse_qs(parse.urlparse(self.url).query).get("cpi")[0] 22 | self.chapter_list = [] 23 | self.mission_all = 0 24 | self.mission_fn = 0 25 | self._child_chapter_list = [] 26 | self.url_log = "" 27 | self.headers = headers 28 | self.ifOpen = ifOpen 29 | self._jobEnc = None 30 | 31 | def __str__(self) -> str: 32 | return "\n".join([f"CourseName: {self.course_name}", 33 | f"Author: {self.course_author}", 34 | f"Url: {self.url}", 35 | f"CourseId: {self.course_id}", 36 | f"ClazzId: {self.class_id}", 37 | f"Cpi: {self.cpi}"]) 38 | 39 | def get_chapter(self): 40 | self.chapter_list.clear() 41 | html_text = doGet(url=f"https://mooc2-ans.chaoxing.com/mooc2-ans/mycourse/studentcourse?courseid={self.course_id}&clazzid={self.class_id}&cpi={self.cpi}&ut=s&t={int(time.time())}", headers=self.headers) 42 | ele = etree.HTML(html_text) 43 | ele_root = xpath_first(ele, "//div[@class='fanyaChapterWhite']") 44 | self.mission_all = 0 45 | self.mission_fn = xpath_first(ele_root, "./div[1]/h2/span/text()") 46 | logger.info(f"mission_finished/mission_all: {self.mission_fn}/{self.mission_all}") 47 | ele_units = ele_root.xpath("./div[2]/div[@class='chapter_td']/div[@class='chapter_unit']") 48 | for unit in ele_units: 49 | unit_catalog_name = xpath_first(unit, "./div[1]/div[1]/div[@class='catalog_name newCatalog_name']/a/span/text()").strip() 50 | """ 51 | { 52 | 1计算机系统概论 53 | 1.1 计算机系统简介 1 54 | 1.1.1 计算机的软硬件概念 2 55 | 1.1.2 计算机系统的层次结构 2 56 | 1.2 计算机的基本组成 1 57 | 1.2.1 冯·诺依曼计算机的特点 2 58 | 59 | },{ 60 | 2计算机的发展及应用 61 | 2.1 计算机的发展史 1 62 | 2.1.1 计算机的产生和发展 2 63 | 2.1.2 微型计算机的出现和发展 2 64 | 2.1.3 软件技术的兴起和发展 2 65 | 2.2 计算机的应用 1 66 | } 67 | """ 68 | for item_li in unit.xpath("./div[2]/ul/li"): 69 | self.__recursion_chapter_item(item_li, 0) 70 | logger.debug(self._child_chapter_list) 71 | self.chapter_list.append({ 72 | "catalog_name": unit_catalog_name, 73 | "child_chapter": self._child_chapter_list.copy() 74 | }) 75 | self._child_chapter_list.clear() 76 | 77 | def __recursion_chapter_item(self, element, depth: int): 78 | if (click_data := xpath_first(element, "./div/@onclick")) != "": 79 | knowledge_id = click_data.split("'")[3] 80 | else: 81 | knowledge_id = '' 82 | self._child_chapter_list.append({ 83 | "name": ("🔒 " if knowledge_id == '' else '') + xpath_first(xpath_first(element, "./div/div/div[@class='catalog_name newCatalog_name']/a[@class='clicktitle']"), "string(.)").strip(), 84 | "depth": depth, 85 | "knowledge_id": knowledge_id, 86 | "job_count": int(xpath_first(element, "./div[1]/div[1]/div[@class='catalog_task']/input/@value") or "0"), 87 | "available": knowledge_id != '' 88 | }) 89 | chapter_list = element.xpath("./ul/li") 90 | if chapter_list: 91 | for chapter_item in chapter_list: 92 | self.__recursion_chapter_item(chapter_item, depth + 1) 93 | 94 | def get_url_log(self) -> str: 95 | """ 96 | 获得课程记录学习的链接,同时更新课程的URL 97 | :return: 课程学习记录的URL 98 | """ 99 | if not self.url_log: 100 | self.url = f"https://mooc2-ans.chaoxing.com/mooc2-ans/mycourse/studentcourse?courseid={self.course_id}&clazzid={self.class_id}&cpi={self.cpi}&ut=s&t=1678608658539" 101 | _rsp = doGet(url=self.url, headers=self.headers) 102 | self.url_log = re.findall("(https://fystat-ans.chaoxing.com/log/setlog(.)+)\">", _rsp)[0][0] 103 | return self.url_log 104 | 105 | def get_count_log(self) -> int: 106 | """ 107 | 108 | :return: 课程学习总的次数 109 | """ 110 | _headers = { 111 | 'Accept': 'application/json, text/javascript, */*; q=0.01', 112 | 'Accept-Encoding': 'gzip, deflate, br', 113 | 'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6', 114 | 'Connection': 'keep-alive', 115 | 'Content-Length': '73', 116 | 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', 117 | 'Host': 'stat2-ans.chaoxing.com' 118 | } 119 | _headers.update(self.headers) 120 | _rsp = doPost(url="https://stat2-ans.chaoxing.com/stat2/study-pv/chart", headers=_headers, data=f"clazzid={self.class_id}&courseid={self.course_id}&cpi={self.cpi}&ut=s&year=2023&month=03") 121 | return json.loads(_rsp).get("total") 122 | 123 | def get_time_log(self): 124 | """ 125 | 126 | :param headers: 访问的请求头 127 | :return: 课程视频的累计观看时间与总时长 128 | """ 129 | _url = f"https://stat2-ans.chaoxing.com/stat2/task/s/index?courseid={self.course_id}&cpi={self.cpi}&clazzid={self.class_id}&ut=s&pEnc={self.jobEnc}&" 130 | _rsp = doGet(url=_url, headers=self.headers) 131 | _ele = etree.HTML(_rsp) 132 | _acc = xpath_first(_ele, "//div[@class='fl min']/span/text()") 133 | _all = re.findall(r'总时长 (\d+)', _rsp)[0] 134 | return [float(_acc), float(_all)] 135 | 136 | def get_progress_data(self): 137 | """ 138 | 139 | :return: 140 | """ 141 | 142 | _url_data = f"https://stat2-ans.chaoxing.com/stat2/task/s/progress/detail?clazzid={self.class_id}&courseid={self.course_id}&cpi={self.cpi}&ut=s&pEnc={self.jobEnc}&page=1&pageSize=16&status=0" 143 | _rsp = doGet(url=_url_data, headers=self.headers) 144 | return json.loads(_rsp).get("data").get("results") 145 | 146 | @property 147 | def jobEnc(self): 148 | if self._jobEnc is None: 149 | _url = f"https://stat2-ans.chaoxing.com/study-data/index?courseid={self.course_id}&clazzid={self.class_id}&cpi={self.cpi}&ut=s&t=1683984845824" 150 | _data = doGet(url=_url, headers=self.headers) 151 | self._jobEnc = re.findall(r"jobEnc = '(.*)';", _data)[0] 152 | return self._jobEnc 153 | -------------------------------------------------------------------------------- /classis/Media/Book.py: -------------------------------------------------------------------------------- 1 | # _*_ coding:utf-8 _*_ 2 | # author: liuyunfz 3 | import json 4 | import time 5 | 6 | import loguru 7 | 8 | from classis.Media import Media 9 | from utils import doGet 10 | 11 | 12 | class Book(Media): 13 | def __init__(self, attachment: dict, headers, defaults: dict, courseId: str): 14 | super().__init__(attachment, headers) 15 | self.defaults = defaults 16 | self.courseId = courseId 17 | 18 | def do_finish(self): 19 | _headers = { 20 | 'Accept': '*/*', 21 | 'Accept-Encoding': 'gzip, deflate, br', 22 | 'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6', 23 | 'Connection': 'keep-alive', 24 | 'Host': 'mooc1-2.chaoxing.com', 25 | 'Referer': 'https://mooc1-2.chaoxing.com/ananas/modules/innerbook/index.html?v=2018-0126-1905', 26 | 'Sec-Fetch-Dest': 'empty', 27 | 'Sec-Fetch-Mode': 'cors', 28 | 'Sec-Fetch-Site': 'same-origin', 29 | 'X-Requested-With': 'XMLHttpRequest' 30 | } 31 | _headers.update(self.headers) 32 | _url = 'https://mooc1-2.chaoxing.com/ananas/job?jobid={0}&knowledgeid={1}&courseid={2}&clazzid={3}&jtoken={4}&_dc={5}'.format( 33 | self.jobid, self.defaults.get("knowledgeid"), self.courseId, self.defaults.get("clazzId"), self.attachment.get("jtoken"), int(time.time() * 1000)) 34 | _rsp = doGet(url=_url, headers=_headers) 35 | loguru.logger.debug(_rsp) 36 | if json.loads(_rsp).get("status"): 37 | return True 38 | else: 39 | return False 40 | -------------------------------------------------------------------------------- /classis/Media/Document.py: -------------------------------------------------------------------------------- 1 | # _*_ coding:utf-8 _*_ 2 | # author: liuyunfz 3 | import json 4 | import time 5 | 6 | import loguru 7 | 8 | from classis.Media import Media 9 | from utils import doGet 10 | 11 | 12 | class Document(Media): 13 | def __init__(self, attachment: dict, headers, defaults: dict, courseId: str): 14 | super().__init__(attachment, headers) 15 | self.defaults = defaults 16 | self.courseId = courseId 17 | 18 | def do_finish(self): 19 | _headers = { 20 | 'Accept': '*/*', 21 | 'Accept-Encoding': 'gzip, deflate, br', 22 | 'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6', 23 | 'Connection': 'keep-alive', 24 | 'Host': 'mooc1-2.chaoxing.com', 25 | 'Referer': 'https://mooc1-2.chaoxing.com/ananas/modules/pdf/index.html?v=2020-1103-1706', 26 | 'Sec-Fetch-Dest': 'empty', 27 | 'Sec-Fetch-Mode': 'cors', 28 | 'Sec-Fetch-Site': 'same-origin', 29 | 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.67 Safari/537.36 Edg/87.0.664.52', 30 | 'X-Requested-With': 'XMLHttpRequest' 31 | } 32 | _headers.update(self.headers) 33 | _url = 'https://mooc1-2.chaoxing.com/ananas/job/document?jobid={0}&knowledgeid={1}&courseid={2}&clazzid={3}&jtoken={4}&_dc={5}'.format( 34 | self.jobid, self.defaults.get("knowledgeid"), self.courseId, self.defaults.get("clazzId"), self.attachment.get("jtoken"), int(time.time() * 1000)) 35 | _rsp = doGet(url=_url, headers=_headers) 36 | loguru.logger.debug(_rsp) 37 | if json.loads(_rsp).get("status"): 38 | return True 39 | else: 40 | return False -------------------------------------------------------------------------------- /classis/Media/Live.py: -------------------------------------------------------------------------------- 1 | # _*_ coding:utf-8 _*_ 2 | # author: liuyunfz 3 | import json 4 | import time 5 | from urllib import parse 6 | 7 | import loguru 8 | from lxml import etree 9 | 10 | from classis.Media import Media 11 | from utils import doGet, xpath_first 12 | 13 | 14 | class Live(Media): 15 | def __init__(self, attachment: dict, headers, defaults: dict, courseId: str): 16 | super().__init__(attachment, headers) 17 | self.defaults = defaults 18 | self.courseId = courseId 19 | self.name = self.attachment.get("property").get("title") 20 | 21 | def do_finish(self): 22 | _stream_name = self.attachment.get("property").get("streamName") 23 | _vdoid = self.attachment.get("property").get("vdoid") 24 | _url = "https://zhibo.chaoxing.com/saveTimePc?streamName={0}&vdoid={1}&userId={2}&isStart=0&t=1680790434506&courseId={3}".format( 25 | _stream_name, _vdoid, self.defaults.get("userid"), self.courseId) 26 | _rsp = doGet(url=_url, headers=self.headers) 27 | loguru.logger.debug(_rsp) 28 | if _rsp == "@success": 29 | return True 30 | else: 31 | return False 32 | 33 | def get_status(self) -> 'dict|None': 34 | status_url = f"https://mooc1.chaoxing.com/ananas/live/liveinfo?liveid={self.attachment.get('property').get('liveId')}&userid={self.defaults.get('userid')}&clazzid={self.defaults.get('clazzId')}&knowledgeid={self.defaults.get('knowledgeid')}&courseid={self.courseId}&jobid={self.attachment.get('property').get('_jobid')}&ut=s" 35 | mission_headers = { 36 | "Referer": "https://mooc1.chaoxing.com/ananas/modules/live/index.html?v=2022-1214-1139" 37 | } 38 | mission_headers.update(self.headers) 39 | status_text = doGet(url=status_url, headers=mission_headers) 40 | try: 41 | status_json = json.loads(status_text) 42 | return status_json 43 | except Exception as e: 44 | loguru.logger.error(e) 45 | return -------------------------------------------------------------------------------- /classis/Media/Read.py: -------------------------------------------------------------------------------- 1 | # _*_ coding:utf-8 _*_ 2 | # author: liuyunfz 3 | import json 4 | import time 5 | 6 | import loguru 7 | 8 | from classis.Media import Media 9 | from utils import doGet 10 | 11 | 12 | class Read(Media): 13 | def __init__(self, attachment: dict, headers, defaults: dict, courseId: str): 14 | super().__init__(attachment, headers) 15 | self.defaults = defaults 16 | self.courseId = courseId 17 | 18 | def do_finish(self): 19 | _headers = { 20 | 'Accept': '*/*', 21 | 'Accept-Encoding': 'gzip, deflate, br', 22 | 'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6', 23 | 'Connection': 'keep-alive', 24 | 'Host': 'mooc1-2.chaoxing.com', 25 | 'Referer': 'https://mooc1-2.chaoxing.com/ananas/modules/innerbook/index.html?v=2018-0126-1905', 26 | 'Sec-Fetch-Dest': 'empty', 27 | 'Sec-Fetch-Mode': 'cors', 28 | 'Sec-Fetch-Site': 'same-origin', 29 | 'X-Requested-With': 'XMLHttpRequest' 30 | } 31 | _headers.update(self.headers) 32 | _url = 'https://mooc1-2.chaoxing.com/ananas/job/readv2?jobid={0}&knowledgeid={1}&courseid={2}&clazzid={3}&jtoken={4}&_dc={5}'.format( 33 | self.jobid, self.defaults.get("knowledgeid"), self.courseId, self.defaults.get("clazzId"), self.attachment.get("jtoken"), int(time.time() * 1000)) 34 | _rsp = doGet(url=_url, headers=_headers) 35 | loguru.logger.debug(_rsp) 36 | if json.loads(_rsp).get("status"): 37 | return True 38 | else: 39 | return False 40 | -------------------------------------------------------------------------------- /classis/Media/Video.py: -------------------------------------------------------------------------------- 1 | # _*_ coding:utf-8 _*_ 2 | # author: liuyunfz 3 | import json 4 | 5 | import loguru 6 | 7 | from classis.Media import Media 8 | from utils import doGet 9 | 10 | 11 | class Video(Media): 12 | def __init__(self, attachment: dict, headers, defaults: dict, dtype: str = "Video", name: str = ""): 13 | super().__init__(attachment, headers) 14 | self.objectId = attachment.get("objectId") 15 | self.reportUrl = defaults.get("reportUrl") 16 | self.defaults = defaults 17 | self.dtype = dtype 18 | self.name = name 19 | self.rt = attachment.get("property").get("rt") or 0.9 20 | 21 | def get_status(self) -> 'dict|None': 22 | status_url = "https://mooc1-1.chaoxing.com/ananas/status/{}?k=&flag=normal&_dc=1600850935908".format(self.objectId) 23 | mission_headers = { 24 | "Referer": "https://mooc1.chaoxing.com/ananas/modules/video/index.html?v=2022-0329-1945" 25 | } 26 | mission_headers.update(self.headers) 27 | status_text = doGet(url=status_url, headers=mission_headers) 28 | try: 29 | status_json = json.loads(status_text) 30 | return status_json 31 | except Exception as e: 32 | loguru.logger.error(e) 33 | return 34 | 35 | def do_finish(self): 36 | video_status = self.get_status() 37 | if video_status: 38 | duration = video_status.get('duration') 39 | dtoken = video_status.get('dtoken') 40 | _url = self.get_url(duration, duration, dtoken, 4) 41 | _headers = { 42 | 'Accept': '*/*', 43 | 'Accept-Encoding': 'gzip, deflate, br', 44 | 'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6', 45 | 'Connection': 'keep-alive', 46 | 'Content-Type': 'application/json', 47 | 'Sec-Fetch-Dest': 'empty', 48 | 'Host': 'mooc1.chaoxing.com', 49 | 'Sec-Fetch-Mode': 'cors', 50 | 'Sec-Fetch-Site': 'same-origin', 51 | 'Referer': 'https://mooc1-2.chaoxing.com/ananas/modules/video/index.html?v=2023-0512-1953' 52 | } 53 | _headers.update(self.headers) 54 | _rsp = doGet(url=_url, headers=_headers) 55 | loguru.logger.debug(_rsp) 56 | if json.loads(_rsp).get("isPassed"): 57 | return True 58 | else: 59 | return False 60 | 61 | def get_url(self, time_end: int, duration: int, dtoken: str, play_type: int) -> str: 62 | """ 63 | 获得视频记录提交的链接 64 | 65 | :param time_end: 结束的时间,默认为duration,即总时长 66 | :param duration: 总时长 67 | :param dtoken: 视频的dtoken参数 68 | :param play_type: 视频的播放状态 69 | :return: 提交地址 70 | """ 71 | import hashlib 72 | import time 73 | enc_raw = "[{0}][{1}][{2}][{3}][{4}][{5}][{6}][0_{7}]". \ 74 | format(self.defaults.get("clazzId"), self.defaults.get("userid"), self.jobid, self.objectId, int(time_end) * 1000, "d_yHJ!$pdA~5", duration * 1000, duration) 75 | enc = hashlib.md5(enc_raw.encode()).hexdigest() 76 | url_former = self.reportUrl 77 | url_later = "/{0}?clazzId={1}&playingTime={2}&duration={10}&clipTime=0_{10}&objectId={3}&otherInfo={4}&jobid={5}&userid={6}&isdrag={9}&view=pc&enc={7}&rt={12}&dtype={11}&_t={8}". \ 78 | format(dtoken, self.defaults.get("clazzId"), time_end, self.objectId, self.attachment.get("otherInfo"), self.jobid, self.defaults.get("userid"), enc, int(time.time() * 1000), play_type, duration, self.dtype, self.rt) 79 | return url_former + url_later 80 | -------------------------------------------------------------------------------- /classis/Media/__init__.py: -------------------------------------------------------------------------------- 1 | # _*_ coding:utf-8 _*_ 2 | # author: liuyunfz 3 | from abc import abstractmethod 4 | 5 | 6 | class Media: 7 | def __init__(self, attachment: dict, headers): 8 | self.name = "" 9 | self.attachment = attachment 10 | self.type = attachment.get("type") 11 | self.jobid = attachment.get("jobid") 12 | self.headers = { 13 | # "Cookie": headers.get("Cookie"), 14 | "User-Agent": headers.get("User-Agent") 15 | } 16 | 17 | @abstractmethod 18 | def do_finish(self): 19 | pass 20 | -------------------------------------------------------------------------------- /classis/SelfException/__init__.py: -------------------------------------------------------------------------------- 1 | # _*_ coding:utf-8 _*_ 2 | # author: liuyunfz 3 | import requests 4 | 5 | 6 | class LoginException(Exception): 7 | def __init__(self, msg): 8 | self.msg = msg 9 | 10 | def __str__(self): 11 | return self.msg 12 | 13 | 14 | class RequestException(Exception): 15 | def __init__(self, html: requests.Response, method: int = 0): 16 | self.html = html 17 | self.method = method 18 | self.text = html.text 19 | 20 | def __str__(self): 21 | return "\n".join([f"Url: {self.html.url}", 22 | f"Method: {['Get', 'Post'][self.method]}", 23 | f"Status: {self.html.status_code}"]) 24 | # + f"Html: {self.html.text}" 25 | -------------------------------------------------------------------------------- /classis/User/__init__.py: -------------------------------------------------------------------------------- 1 | # _*_ coding:utf-8 _*_ 2 | # author: liuyunfz 3 | import json 4 | import re 5 | import requests 6 | import sys 7 | 8 | from ..SelfException import LoginException, RequestException 9 | from ..Course import Course 10 | from lxml import etree 11 | from loguru import logger 12 | 13 | from utils import doGet, doPost, encrypt_des, xpath_first, direct_url 14 | 15 | from config import GloConfig 16 | 17 | 18 | class User: 19 | def __init__(self, username: str = "", password: str = "", cookieStr: str = ""): 20 | self.course_list = [] 21 | self.headers = { 22 | 'Accept': 'application/json, text/javascript, */*; q=0.01', 23 | 'Accept-Encoding': 'gzip, deflate, br', 24 | 'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6', 25 | 'Connection': 'keep-alive', 26 | 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', 27 | 'Host': 'passport2.chaoxing.com', 28 | 'Origin': 'https://passport2.chaoxing.com', 29 | 'Referer': 'https://passport2.chaoxing.com/login?loginType=4&fid=314&newversion=true&refer=http://i.mooc.chaoxing.com', 30 | 'Sec-Fetch-Dest': 'empty', 31 | 'Sec-Fetch-Mode': 'cors', 32 | 'Sec-Fetch-Site': 'same-origin', 33 | 'User-Agent': GloConfig.data.get("GloConfig").get("headers").get("User-Agent"), 34 | 'X-Requested-With': 'XMLHttpRequest' 35 | } 36 | if cookieStr == "": 37 | self.username = username 38 | rsp = doPost("https://passport2.chaoxing.com/fanyalogin", 39 | headers=self.headers, 40 | data="fid=314&uname={0}&password={1}&refer=http%253A%252F%252Fi.mooc.chaoxing.com&t=true" 41 | .format(username, encrypt_des(password, "u2oh6Vu^").decode('utf-8')), 42 | ifFullBack=True) 43 | if rsp.status_code == 200: 44 | rsp_json = json.loads(rsp.text) 45 | if rsp_json.get("status"): 46 | self.name = rsp_json.get("name") 47 | self.uid = rsp.cookies.get('_uid') 48 | for item in rsp.cookies: 49 | cookieStr = cookieStr + item.name + '=' + item.value + ';' 50 | self.cookieStr = cookieStr 51 | self.headers = { 52 | 'User-Agent': GloConfig.data.get("GloConfig").get("headers").get("User-Agent"), 53 | # "Cookie": cookieStr 54 | } 55 | else: 56 | raise LoginException(rsp_json.get("msg2")) 57 | else: 58 | raise RequestException(rsp, 1) 59 | else: 60 | self.cookieStr = cookieStr 61 | self.headers = { 62 | 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36 Edg/85.0.564.51', 63 | "Cookie": cookieStr 64 | } 65 | if self.__checkLogin(): 66 | self.uid = re.findall(r"_uid=(\d+);", self.cookieStr)[0] if re.findall(r"_uid=(\d+);", self.cookieStr) else "" 67 | self.name = self.uid # 获取意义不大,暂不添加 68 | self.username = self.uid 69 | else: 70 | raise LoginException("Cookie失效,请重新获取") 71 | 72 | def __checkLogin(self) -> bool: 73 | _url = "https://i.chaoxing.com/base/settings?t=1677930825027" 74 | _headers = { 75 | 'Refer': 'https://i.chaoxing.com/base?t=1677930160468' 76 | } 77 | _headers.update(self.headers) 78 | _rsp = requests.get(url=_url, headers=_headers, allow_redirects=False) 79 | if _rsp.status_code == 200: 80 | return True 81 | else: 82 | return False 83 | 84 | def __str__(self): 85 | return "\n".join([f"Uid: {self.uid}", 86 | f"Username: {self.username}", 87 | f"Cookie: {self.cookieStr}"]) 88 | 89 | def getCourse(self): 90 | self.course_list.clear() 91 | html = doGet(url="https://mooc2-ans.chaoxing.com/mooc2-ans/visit/courses/list?v=1675234609566&rss=1&start=0&size=500&catalogId=0&superstarClass=0&searchname=", headers=self.headers) 92 | ele = etree.HTML(html) 93 | course_ele = ele.xpath("//ul[@id='courseList']/li") 94 | for item in course_ele: 95 | tmp_url = xpath_first(item, "./div[2]/h3/a/@href") 96 | if tmp_url.startswith("http"): 97 | # 如果为自己教授的课则无协议头 98 | course = Course(xpath_first(item, "./div[1]/input[@class='courseId']/@value"), 99 | xpath_first(item, "./div[1]/input[@class='clazzId']/@value"), 100 | # direct_url(tmp_url, self.headers), 具体调用课程后再更新URL,避免多余的HTTP操作 101 | tmp_url, 102 | xpath_first(item, "./div[2]/h3/a/span/@title"), 103 | xpath_first(item, "./div[2]/p[@class='line2 color3']/@title"), 104 | headers=self.headers, 105 | ifOpen=(xpath_first(item, "./div[1]/a[@class='not-open-tip']") == "") 106 | ) 107 | logger.debug("Add course:\n" + str(course)) 108 | self.course_list.append(course) 109 | -------------------------------------------------------------------------------- /classis/UserLogger/__init__.py: -------------------------------------------------------------------------------- 1 | # _*_ coding:utf-8 _*_ 2 | # author: liuyunfz 3 | from loguru import logger 4 | import sys 5 | 6 | 7 | class UserLogger: 8 | def __init__(self): 9 | logger.add(sys.stdout, format="{time:HH:mm:ss} | {level} | {message}", 10 | filter=lambda record: record["extra"].get("name") == "a") 11 | self.log_self = logger.bind(name="a") 12 | 13 | def info(self, message: str): 14 | self.log_self.info(message) 15 | 16 | def error(self, message: str): 17 | self.log_self.error(message) 18 | 19 | def success(self, message: str): 20 | self.log_self.success(message) 21 | 22 | def warning(self, message: str): 23 | self.log_self.warning(message) 24 | -------------------------------------------------------------------------------- /config.py: -------------------------------------------------------------------------------- 1 | # _*_ coding:utf-8 _*_ 2 | # author: liuyunfz 3 | 4 | import yaml 5 | 6 | 7 | class GloConfig: 8 | data: dict = None 9 | 10 | @staticmethod 11 | def init_yaml_data(): 12 | with open("config.yml", "r", encoding="utf-8") as f: 13 | GloConfig.data = yaml.safe_load(f) 14 | 15 | @staticmethod 16 | def release_yaml_data(): 17 | with open("config.yml", "w", encoding="utf-8") as f: 18 | GloConfig.data = yaml.safe_dump(GloConfig.data, f, encoding='utf-8', allow_unicode=True, sort_keys=False) 19 | -------------------------------------------------------------------------------- /config.yml: -------------------------------------------------------------------------------- 1 | InfoStr: 2 | instructions: |- 3 | 欢迎您使用 chaoxing_tool , 本工具是针对超星(学习通)所编写的Python脚本工具 4 | 本工具完全免费且开源,项目地址: https://github.com/liuyunfz/chaoxing_tool 5 | 使用前请确认您使用的是最新版,防止因为超星系统更新导致的功能失效 6 | 7 | 且确认以下须知与功能介绍: 8 | 1.本项目支持一键完成的任务点不包括考试与测试 9 | 2.输入密码时会被自动隐藏,防止您的密码被偷窥 10 | 3.项目不能完全保证不被系统识别异常,请理性使用 11 | 4.所有功能均采用发送GET/POST请求包完成,效率更高且占用资源低 12 | 5.如果您在使用中有疑问或者遇到了BUG,请前往提交Issue: https://github.com/liuyunfz/chaoxing_tool/issues 13 | signStr: |- 14 | 1.使用用户名(手机号)与密码进行登录 15 | 2.使用Cookie进行登录 16 | 请选择您的登录方式: 17 | errSignMode: 请输入正确的序号,如果您不清楚怎么选,请默认选择1 18 | 19 | GloConfig: 20 | timeout: 3 # 全局requests模块的超时时长 21 | delay: # 全局request请求的延迟时间,防止过快访问导致触发反爬 22 | enable: True 23 | time: 0.5 # 支持小数,单位为秒 24 | headers: 25 | User-Agent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36 Edg/85.0.564.51' 26 | debug: 27 | enable: True # 是否开启debug模式,即显示更加详细的软件日志 28 | level: 8 29 | 30 | FunConfig: 31 | deal-mission: 32 | video-mode: 1 # 0为立即完成,1为等时长刷取 33 | single-thread: false #是否为单线程刷取,如果为false则会同时启动所有待完成视频节点的线程 34 | set-log: 35 | delay: 30 # 刷取学习次数的延迟,单位s 36 | 37 | UserData: 38 | cookie: '' 39 | auto-sign: True -------------------------------------------------------------------------------- /functions/deal_mission/__init__.py: -------------------------------------------------------------------------------- 1 | # _*_ coding:utf-8 _*_ 2 | 3 | __name__ = "deal_mission" 4 | __author__ = "liuyunfz" 5 | __disName__ = " ✅ 一键完成课程中的任务节点" 6 | __description__ = """一键完成所有课程或所选课程中需要完成的任务点 7 | 包括视频、阅读、PPT、音频等 8 | 但不包括测验与考试 9 | 10 | 注:视频节点将根据配置文件中的设置,自动选择立刻完成还是等时长速刷取 11 | """ 12 | 13 | import os 14 | import re 15 | import time 16 | 17 | import loguru 18 | 19 | from .deal_course import DealCourse 20 | from utils import clear_console 21 | import classis.User 22 | 23 | 24 | def run(user: classis.User.User, log): 25 | clear_console() 26 | for i in range(len(user.course_list)): 27 | print("%d.%s" % (i + 1, user.course_list[i].course_name)) 28 | 29 | course_choice = [] 30 | while not course_choice: 31 | choice = input("请选择您要完成的课程序号,并用逗号分割。\n如果需要全部完成全部课程则直接回车即可。或者输入q退出本功能\n序号:") 32 | if choice == "": 33 | course_choice = user.course_list 34 | elif choice == "q": 35 | return 36 | else: 37 | try: 38 | for i in re.split("[,,]", choice): 39 | course_choice.append(user.course_list[int(i) - 1]) 40 | except Exception as e: 41 | log.error("序号输入错误,请尝试重新输入") 42 | loguru.logger.error(e) 43 | course_choice.clear() 44 | pass 45 | 46 | log.info("开始处理课程中....\n") 47 | video_url_list = [] 48 | for course_item in course_choice: 49 | log.info("开始处理'%s'..." % course_item.course_name) 50 | _deal_course = DealCourse(user, course_item, log) 51 | _deal_course.do_finish() 52 | for item in _deal_course.thread_pool: 53 | item.join() 54 | log.success("'%s' 课程处理完成\n" % course_item.course_name) 55 | time.sleep(0.4) 56 | if len(video_url_list) == 0: 57 | log.success("任务已完成,回车返回主菜单") 58 | input() 59 | -------------------------------------------------------------------------------- /functions/deal_mission/deal_course.py: -------------------------------------------------------------------------------- 1 | # _*_ coding:utf-8 _*_ 2 | # author: liuyunfz 3 | import json 4 | import random 5 | import re 6 | import threading 7 | import time 8 | 9 | import loguru 10 | from lxml import etree 11 | 12 | from config import GloConfig 13 | from classis.Media.Book import Book 14 | from classis.Media.Document import Document 15 | from classis.Media.Live import Live 16 | from classis.Media.Read import Read 17 | from classis.Media.Video import Video 18 | from utils import doGet, doPost, xpath_first 19 | import classis.User 20 | 21 | 22 | class DealCourse: 23 | def __init__(self, user: classis.User.User, course: classis.User.Course, log): 24 | self.user = user 25 | self.course = course 26 | self.log = log 27 | self.course_name = course.course_name 28 | self.class_id = course.class_id 29 | self.course_id = course.course_id 30 | self.cpi = course.cpi 31 | self.mission_list = [] 32 | self.video_mode = GloConfig.data.get("FunConfig").get("deal-mission").get("video-mode") 33 | self.single_thread = GloConfig.data.get("FunConfig").get("deal-mission").get("single-thread") 34 | self.thread_pool = [] 35 | 36 | def do_finish(self): 37 | if not self.course.ifOpen: 38 | self.log.warning("本课程已结课或锁定,将自动跳过") 39 | return 40 | from functions.set_time import DealVideo 41 | self.deal_course() 42 | self.thread_pool.clear() 43 | if self.mission_list: 44 | self.log.info(f"共读取到 {len(self.mission_list)} 个章节待完成") 45 | for mission_item in self.mission_list: 46 | self.log.info(f"开始处理章节'{mission_item.get('name')}'") 47 | attach_list = self.deal_chapter(mission_item) 48 | if attach_list: 49 | for attach_item in attach_list: 50 | medias = attach_item.get("attachments") 51 | defaults = attach_item.get("defaults") 52 | for media in medias: 53 | if media.get("job") is None: 54 | continue 55 | media_type = media.get("type") 56 | media_module = media.get('property').get('module') 57 | media_name = media.get('property').get('name') 58 | finish_status = False 59 | if media_type == "video": 60 | if media_module == "insertaudio": 61 | self.log.info(f"开始处理音頻任务点:{media_name}") 62 | finish_status = Video(media, self.user.headers, defaults, "Audio").do_finish() 63 | else: 64 | self.log.info(f"开始处理视频任务点:{media_name}") 65 | _video = Video(media, self.user.headers, defaults, name=media_name) 66 | if self.video_mode == 0: 67 | finish_status = _video.do_finish() 68 | else: 69 | _thread = threading.Thread(target=DealVideo.run_video, args=(_video, self.user, self.log)) 70 | if self.single_thread: 71 | self.log.info(f"检测到您启动了单线程模式") 72 | self.log.info(f"开始刷取视频任务点'{media_name}',每分钟更新进度") 73 | _thread.start() 74 | _thread.join() 75 | else: 76 | 77 | self.thread_pool.append(_thread) 78 | self.log.info(f"视频任务点'{media_name}',已根据您的配置启动等时长刷取线程") 79 | _thread.start() 80 | time.sleep(random.random() + 0.5) 81 | 82 | continue 83 | 84 | elif media_type == "read": 85 | self.log.info(f"开始处理阅读任务点:{media_name}") 86 | finish_status = Read(media, self.user.headers, defaults, self.course_id).do_finish() 87 | elif media_type == "document": 88 | self.log.info(f"开始处理Doc文件任务点:{media_name}") 89 | finish_status = Document(media, self.user.headers, defaults, self.course_id).do_finish() 90 | elif media_type == "live": 91 | _live = Live(media, self.user.headers, defaults, self.course_id) 92 | _thread = threading.Thread(target=DealVideo.run_live, args=(_live, self.user, self.log)) 93 | self.thread_pool.append(_thread) 94 | self.log.info(f"直播任务点'{_live.name}',已自动启动等时长刷取线程") 95 | _thread.start() 96 | continue 97 | 98 | elif "bookname" in media.get("property"): 99 | self.log.info(f"开始处理图书任务点:{media_name}") 100 | finish_status = Book(media, self.user.headers, defaults, self.course_id).do_finish() 101 | else: 102 | self.log.error(f"检测到不支持的任务点类型:{media_type}") 103 | loguru.logger.info(media) 104 | continue 105 | 106 | if finish_status: 107 | self.log.success(f"任务点'{media_name}'完成成功") 108 | else: 109 | self.log.error(f"任务点'{media_name}'完成失败") 110 | 111 | def deal_course(self): 112 | self.mission_list.clear() 113 | self.log.info(f"获取'{self.course_name}'课程的章节中...") 114 | self.course.get_chapter() 115 | if self.course.chapter_list: 116 | self.log.success(f"获取'{self.course_name}'课程章节成功,即将展示") 117 | time.sleep(0.4) 118 | for catalog_item in self.course.chapter_list: 119 | print(catalog_item.get("catalog_name")) 120 | for chapter_item in catalog_item.get("child_chapter"): 121 | print("----" * (chapter_item.get("depth") + 1), chapter_item.get("name"), self.mission_list.append(chapter_item) or f" ✍待完成任务点 {chapter_item.get('job_count')}" if chapter_item.get("job_count") else "") 122 | print("🔷" * 35) 123 | self.log.success(f"'{self.course_name}'课程章节展示完毕") 124 | else: 125 | self.log.warning(f"'{self.course_name}'课程章节数为零,请核实或检查网络问题。如有出入请反馈issue") 126 | 127 | def deal_chapter(self, chapter_item: dict): 128 | """ 129 | 处理章节内容,获得章节的具体任务点 130 | 131 | :param chapter_item: 章节dict 132 | :return: 返回媒体list 133 | """ 134 | page_count = self.read_card_count(chapter_item.get("knowledge_id")) 135 | attach_list = [] 136 | for page in range(page_count): 137 | try: 138 | medias_url = "https://mooc1.chaoxing.com/knowledge/cards?clazzid={0}&courseid={1}&knowledgeid={2}&num={4}&ut=s&cpi={3}&v=20160407-1".format(self.class_id, self.course_id, chapter_item.get("knowledge_id"), self.cpi, page) 139 | medias_rsp = doGet(url=medias_url, headers=self.user.headers) 140 | medias_HTML = etree.HTML(medias_rsp) 141 | medias_text = xpath_first(medias_HTML, "//body/script[1]/text()") 142 | datas_raw = re.findall(r"mArg = ({[\s\S]*)}catch", medias_text).pop() 143 | datas = json.loads(datas_raw.strip()[:-1]) 144 | attach_list.append(datas) 145 | except: 146 | continue 147 | return attach_list 148 | 149 | def read_card_count(self, knowledge_id) -> int: 150 | """ 151 | 获取章节总页码数 152 | 153 | :param knowledge_id: 章节id 154 | :return: 返回该章节的页数 155 | """ 156 | _url = 'https://mooc1.chaoxing.com/mycourse/studentstudyAjax?' 157 | data = "courseId={0}&clazzid={1}&chapterId={2}&cpi={3}&verificationcode=&mooc2=1".format(self.course_id, self.class_id, knowledge_id, self.cpi) 158 | rsp = doGet(url=_url + data, headers=self.user.headers) 159 | rsp_HTML = etree.HTML(rsp) 160 | return int(xpath_first(rsp_HTML, "//input[@id='cardcount']/@value")) 161 | -------------------------------------------------------------------------------- /functions/media_download/__init__.py: -------------------------------------------------------------------------------- 1 | # _*_ coding:utf-8 _*_ 2 | # author: liuyunfz 3 | 4 | __name__ = "media_download" 5 | __author__ = "liuyunfz" 6 | __disName__ = " 📂 下载课程中的资源" 7 | __description__ = """下载课程章节中的媒体资源 8 | 包括视频、Word、PPT、音频等文件 9 | """ 10 | 11 | import os 12 | import re 13 | import time 14 | 15 | import loguru 16 | import classis.User 17 | from functions.media_download.deal_media import MediaDownload 18 | from utils import clear_console 19 | 20 | 21 | def run(user: classis.User.User, log): 22 | clear_console() 23 | for i in range(len(user.course_list)): 24 | print("%d.%s" % (i + 1, user.course_list[i].course_name)) 25 | 26 | course_choice = [] 27 | while not course_choice: 28 | choice = input("请选择您下载媒体的课程序号,或者输入q退出本功能\n序号:") 29 | if choice == "q": 30 | return 31 | else: 32 | try: 33 | course_choice.append(user.course_list[int(choice) - 1]) 34 | except Exception as e: 35 | log.error("序号输入错误,请尝试重新输入") 36 | loguru.logger.error(e) 37 | course_choice.clear() 38 | pass 39 | 40 | chapter_media = MediaDownload(user, course_choice[0], log) 41 | chapter_media.deal_course() 42 | chapter_choice = [] 43 | while not chapter_choice: 44 | choice = input("请选择将下载资源所在的课程序号,并用逗号分割。\n如果需要读取所有资源则直接回车即可。或者输入q退出本功能\n序号:") 45 | if not choice: 46 | chapter_choice = chapter_media.chapter_all 47 | elif choice == "q": 48 | return 49 | else: 50 | try: 51 | for i in re.split("[,,]", choice): 52 | if (chapter_item := chapter_media.chapter_all[int(i) - 1])['available']: 53 | chapter_choice.append(chapter_item) 54 | else: 55 | log.info(f"您所选的课程序号'{i}'对应的课程'{chapter_item['name'][2:]}'被锁定,已为您跳过") 56 | except Exception as e: 57 | log.error("序号输入错误,请尝试重新输入") 58 | loguru.logger.error(e) 59 | chapter_choice.clear() 60 | pass 61 | 62 | media_all = [] 63 | for chapter_item in chapter_choice: 64 | log.info(f"开始读取章节'{chapter_item.get('name')}'") 65 | chapter_medias = chapter_media.deal_chapter(chapter_item) 66 | count = 0 67 | for _ in chapter_medias: 68 | _att = _.get("attachments") 69 | count += len(_att) 70 | media_all += _att 71 | log.info(f"章节'{chapter_item.get('name')}'读取完成,共{count}个资源") 72 | 73 | log.success(f"读取完毕,共计{len(media_all)}个资源,即将展示..") 74 | time.sleep(0.4) 75 | for media in media_all: 76 | print(media_all.index(media) + 1, ".", media.get("property").get("name") if media.get("property").get("name") else media.get("property").get("bookname")) 77 | log.success("资源展示完成") 78 | while True: 79 | choice = input("请选择您要下载媒体的序号,用逗号分割,直接回车则全选,或者输入q退出本功能\n序号:") 80 | try: 81 | if choice == "q": 82 | return 83 | elif choice == '': 84 | for item in media_all: 85 | chapter_media.do_download("./downloads", attachment=item) 86 | else: 87 | for i in re.split("[,,]", choice): 88 | chapter_media.do_download("./downloads", attachment=media_all[int(i) - 1]) 89 | except Exception as e: 90 | log.error("序号输入错误,请尝试重新输入") 91 | loguru.logger.error(e) 92 | pass 93 | log.success("下载功能执行完毕,回车返回主菜单") 94 | input() 95 | -------------------------------------------------------------------------------- /functions/media_download/deal_media.py: -------------------------------------------------------------------------------- 1 | # _*_ coding:utf-8 _*_ 2 | # author: liuyunfz 3 | import json 4 | import os.path 5 | import re 6 | import time 7 | 8 | import requests 9 | 10 | import classis.User 11 | from functions.deal_mission import DealCourse 12 | from utils import doGet 13 | 14 | 15 | class MediaDownload(DealCourse): 16 | def __init__(self, user: classis.User.User, course: classis.User.Course, log): 17 | super().__init__(user, course, log) 18 | self.chapter_all = [] 19 | 20 | def deal_course(self): 21 | self.log.info(f"获取'{self.course_name}'课程的章节中...") 22 | self.course.get_chapter() if not self.course.chapter_list else None 23 | if self.course.chapter_list: 24 | self.log.success(f"获取'{self.course_name}'课程章节成功,即将展示") 25 | time.sleep(0.4) 26 | self.chapter_all = [] 27 | ind = 1 28 | for catalog_item in self.course.chapter_list: 29 | print(catalog_item.get("catalog_name")) 30 | for chapter_item in catalog_item.get("child_chapter"): 31 | print(str(ind) + ". ", "----" * (chapter_item.get("depth") + 1), chapter_item.get("name")) 32 | self.chapter_all.append(chapter_item) 33 | ind += 1 34 | print("🔷" * 35) 35 | self.log.success(f"'{self.course_name}'课程章节展示完毕") 36 | else: 37 | self.log.warning(f"'{self.course_name}'课程章节数为零,请核实或检查网络问题。如有出入请反馈issue") 38 | 39 | def deal_chapter(self, chapter_item: dict): 40 | return super().deal_chapter(chapter_item) 41 | 42 | def read_card_count(self, knowledge_id) -> int: 43 | return super().read_card_count(knowledge_id) 44 | 45 | def do_download(self, path="", attachment: dict = {}): 46 | objectid = attachment.get("property").get("objectid") 47 | name = attachment.get("property").get("name") if attachment.get("property").get("name") else attachment.get("property").get("bookname") 48 | if objectid is None: 49 | self.log.error(name + "文件ID获取失败,将跳过该文件") 50 | return 51 | _headers = { 52 | 'Accept': '*/*', 53 | 'Accept-Encoding': 'gzip, deflate, br', 54 | 'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6', 55 | 'Host': 'mooc1-2.chaoxing.com', 56 | 'Referer': 'https://mooc1-2.chaoxing.com/ananas/modules/audio/index.html?v=2022-1028-1705', 57 | 'X-Requested-With': 'XMLHttpRequest' 58 | } 59 | download_headers = { 60 | "referer": "https://mooc1-2.chaoxing.com/ananas/modules/video/index.html?v=2021-0924-1446", 61 | "Host": "s1.ananas.chaoxing.com" 62 | } 63 | download_headers.update(self.user.headers) 64 | _headers.update(self.user.headers) 65 | child_path = path + "/" + self.course_name 66 | if not os.path.exists(path): 67 | os.mkdir(path) 68 | os.mkdir(child_path) 69 | elif not os.path.exists(child_path): 70 | os.mkdir(child_path) 71 | _status = doGet(url="https://mooc1-2.chaoxing.com/ananas/status/{}?_dc={}".format(objectid, int(time.time() * 1000)), headers=_headers) 72 | _status_json = json.loads(_status) 73 | filename = _status_json.get('filename') 74 | if _status_json.get("httphd"): 75 | _url = _status_json.get('httphd') 76 | elif _status_json.get("pagenum") is not None: 77 | _url = _status_json.get('pdf') 78 | else: 79 | _url = _status_json.get('http') 80 | with open(path + "/" + self.course_name + '/' + self._get_save_name(name, filename), "wb") as f: 81 | rsp = requests.get(url=_url, headers=download_headers, stream=True) 82 | length_already = 0 83 | length_all = int(rsp.headers['content-length']) 84 | self.log.info(f"开始下载文件'{name}'") 85 | for chunk in rsp.iter_content(chunk_size=5242880): 86 | if chunk: 87 | length_already += len(chunk) 88 | print("\r下载进度:%d%%" % int(length_already / length_all * 100), end="", flush=True) 89 | f.write(chunk) 90 | print('\n') 91 | self.log.success(f"'{name}'下载完成") 92 | 93 | def _get_save_name(self, name: str, filename: str): 94 | """ 95 | 96 | :param name: 97 | :param filename: 98 | :return: 99 | """ 100 | _end = '.' + filename.split('.')[-1] 101 | name = re.sub('([\/:*?"<>|])*','',name) 102 | _l = name.split(".") 103 | if len(_l) == 1: 104 | return name + _end 105 | else: 106 | if re.fullmatch('([a-z0-9]{1,7})', _l[-1]): 107 | return ''.join(_l[:-1]) + _end 108 | else: 109 | return name + _end 110 | -------------------------------------------------------------------------------- /functions/set_log/__init__.py: -------------------------------------------------------------------------------- 1 | # _*_ coding:utf-8 _*_ 2 | 3 | __name__ = "set_log" 4 | __author__ = "liuyunfz" 5 | __disName__ = " 📜 刷取课程学习次数" 6 | __description__ = """刷取课程的学习次数,但请注意 7 | 由于程序的高速访问,可能会造成预期次数与实际次数的较大误差 8 | 请自行检验并多次刷取以达到最终效果 9 | """ 10 | 11 | import os 12 | import time 13 | 14 | import loguru 15 | from config import GloConfig 16 | import classis.User 17 | from utils import doGet, clear_console 18 | 19 | def run(user: classis.User.User, log): 20 | clear_console() 21 | for i in range(len(user.course_list)): 22 | print("%d.%s" % (i + 1, user.course_list[i].course_name)) 23 | delay = GloConfig.data.get("FunConfig").get("set-log").get("delay") 24 | while True: 25 | choice = input("请选择您要刷取学习次数的课程序号,或者输入q退出本功能\n序号:") 26 | if choice == 'q': 27 | return 28 | elif choice == '': 29 | continue 30 | try: 31 | course = user.course_list[int(choice) - 1] 32 | log.info(f"当前课程'{course.course_name}'学习次数共{course.get_count_log()}次") 33 | times = int(input("请输入要刷取的学习次数:")) 34 | _url = course.get_url_log() 35 | for i in range(1, times + 1): 36 | log.info(f"正在刷取'{course.course_name}'课程第{i}次") 37 | _rsp = doGet(url=_url, headers=user.headers) 38 | loguru.logger.info(_rsp) 39 | time.sleep(delay) 40 | log.success("课程学习次数刷取完毕") 41 | log.info(f"当前课程'{course.course_name}'学习次数共{course.get_count_log()}次") 42 | input("回车返回主菜单") 43 | return 44 | except Exception as e: 45 | loguru.logger.error(e) 46 | log.error("课程序号输入错误,请重新尝试\n") 47 | continue 48 | -------------------------------------------------------------------------------- /functions/set_time/__init__.py: -------------------------------------------------------------------------------- 1 | # _*_ coding:utf-8 _*_ 2 | 3 | __name__ = "set_time" 4 | __author__ = "liuyunfz" 5 | __disName__ = " ⏳ 刷取课程视频观看时长" 6 | __description__ = """刷取课程中视频的观看时长 7 | 首先读取课程中的所有视频资源 8 | 然后由用户选择要通过哪个视频进行时长刷取 9 | 默认针对第一个视频文件进行观看时长的刷取 10 | """ 11 | 12 | import os 13 | import re 14 | import threading 15 | 16 | import loguru 17 | import classis.User 18 | from .deal_time import DealVideo 19 | from utils import clear_console 20 | 21 | 22 | def run(user: classis.User.User, log): 23 | clear_console() 24 | for i in range(len(user.course_list)): 25 | print("%d.%s" % (i + 1, user.course_list[i].course_name)) 26 | while True: 27 | choice = input("请选择您要刷取视频时长的课程序号,或者输入q退出本功能\n序号:") 28 | try: 29 | if choice == 'q': 30 | return 31 | else: 32 | course = user.course_list[int(choice) - 1] 33 | time_list = course.get_time_log() 34 | log.info(f"当前课程'{course.course_name}'视频总时长共{time_list[1]}分钟,已学习{time_list[0]}分钟") 35 | if time_list[0] < time_list[1]: 36 | _dis = time_list[1] - time_list[0] 37 | log.info(f"目标刷取时长:{_dis}分钟,即将开始...") 38 | else: 39 | log.info(f"课程时长已充足,请选择其他课程") 40 | continue 41 | _videos = DealVideo(user, course, log).get_videos() 42 | if len(_videos) == 0: 43 | log.error("未获取到有效的课程视频,请手动检查章节是否被锁") 44 | continue 45 | for item in _videos: 46 | print(f"{_videos.index(item)}.{item.name}") 47 | _video_choice = re.split("[,,]", input("请选择要刷取时长的视频序号并以逗号分隔,直接回车默认选择第一个,-1则全部选择\n序号:")) 48 | thread_pool = [] 49 | if len(_video_choice) == 1: 50 | if _video_choice[0] == "-1": 51 | for item in _videos: 52 | _thread = threading.Thread(target=DealVideo.run_video, args=(item, user, log)) 53 | thread_pool.append(_thread) 54 | _thread.start() 55 | elif _video_choice[0] == "": 56 | _thread = threading.Thread(target=DealVideo.run_video, args=(_videos[0], user, log, _dis)) 57 | thread_pool.append(_thread) 58 | _thread.start() 59 | else: 60 | _thread = threading.Thread(target=DealVideo.run_video, args=(_videos[int(_video_choice[0])], user, log, _dis)) 61 | thread_pool.append(_thread) 62 | _thread.start() 63 | else: 64 | for i in _video_choice: 65 | _thread = threading.Thread(target=DealVideo.run_video, args=(_videos[int(i)], user, log)) 66 | thread_pool.append(_thread) 67 | _thread.start() 68 | for _t in thread_pool: 69 | _t.join() 70 | log.success("课程学习时长刷取完毕") 71 | log.info(f"当前课程'{course.course_name}'学习时长共{course.get_time_log()[0]}分支") 72 | input("回车返回主菜单") 73 | except Exception as e: 74 | loguru.logger.error(e) 75 | log.error("课程序号输入错误,请重新尝试\n") 76 | continue 77 | -------------------------------------------------------------------------------- /functions/set_time/deal_time.py: -------------------------------------------------------------------------------- 1 | # _*_ coding:utf-8 _*_ 2 | # author: liuyunfz 3 | import time 4 | 5 | import loguru 6 | 7 | import classis.User 8 | from classis.Media.Live import Live 9 | from classis.Media.Video import Video 10 | from classis.SelfException import RequestException 11 | from functions.deal_mission import DealCourse 12 | from utils import doGet 13 | 14 | 15 | class DealVideo: 16 | 17 | def __init__(self, user: classis.User.User, course: classis.User.Course, log): 18 | self.user = user 19 | self.course = course 20 | self.log = log 21 | 22 | @staticmethod 23 | def run_video(video: Video, user, log, all_time: int = 0): 24 | video_status = video.get_status() 25 | if video_status: 26 | duration = video_status.get('duration') 27 | dtoken = video_status.get('dtoken') 28 | _headers = { 29 | 'Accept': '*/*', 30 | 'Accept-Encoding': 'gzip, deflate, br', 31 | 'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6', 32 | 'Connection': 'keep-alive', 33 | 'Content-Type': 'application/json', 34 | 'Sec-Fetch-Dest': 'empty', 35 | 'Host': 'mooc1.chaoxing.com', 36 | 'Sec-Fetch-Mode': 'cors', 37 | 'Sec-Fetch-Site': 'same-origin', 38 | 'Referer': 'https://mooc1.chaoxing.com/ananas/modules/video/index.html?v=2023-0519-2354' 39 | } 40 | _headers.update(user.headers) 41 | else: 42 | raise RequestException("视频状态获取失败") 43 | return 44 | 45 | _url = video.get_url(0, duration, dtoken, 3) 46 | _rsp = doGet(_url, _headers) 47 | loguru.logger.debug(_rsp) 48 | time_all = round(duration / 60, 2) 49 | time_m = duration // 60 if all_time == 0 else int(all_time) 50 | time_s = duration - time_m * 60 51 | for i in range(time_m): 52 | time.sleep(59.8) 53 | _url = video.get_url(i * 60 + 59, duration, dtoken, 0) 54 | log.info(f"'{video.name}'当前刷取时长{i + 1}分钟,总时长{time_all}分钟") 55 | _rsp = doGet(_url, _headers) 56 | loguru.logger.debug(_rsp) 57 | if time_s: 58 | time.sleep(time_s) 59 | _url = video.get_url(duration, duration, dtoken, 4) 60 | log.info(f"'{video.name}'当前刷取时长{time_all}分钟,总时长{time_all}分钟") 61 | _rsp = doGet(_url, _headers) 62 | loguru.logger.debug(_rsp) 63 | 64 | @staticmethod 65 | def run_live(live: Live, user, log): 66 | live_status = live.get_status() 67 | if live_status: 68 | duration = live_status.get("temp").get("data").get('duration') 69 | _headers = { 70 | 'Accept': '*/*', 71 | 'Accept-Encoding': 'gzip, deflate, br', 72 | 'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6', 73 | 'Connection': 'keep-alive', 74 | 'Content-Type': 'application/json', 75 | 'Sec-Fetch-Dest': 'empty', 76 | 'Host': 'mooc1.chaoxing.com', 77 | 'Sec-Fetch-Mode': 'cors', 78 | 'Sec-Fetch-Site': 'same-origin', 79 | 'Referer': 'https://mooc1.chaoxing.com/ananas/modules/video/index.html?v=2023-0203-1904' 80 | } 81 | _headers.update(user.headers) 82 | else: 83 | raise RequestException("直播状态获取失败") 84 | return 85 | _dis = (duration + 59) // 60 86 | for i in range(int(_dis)): 87 | log.info(f"'{live.name}'当前刷取时长{i + 1}分钟,总时长{_dis}分钟") 88 | live.do_finish() 89 | time.sleep(59) 90 | 91 | def get_videos(self): 92 | """ 93 | 获得该课程的所有视频对象 94 | :return: 95 | """ 96 | _data = self.course.get_progress_data() 97 | _video_list = [] 98 | for i in _data: 99 | for j in i['list']: 100 | if j['type'] == '视频': 101 | _dc = DealCourse(self.user, self.course, self.log) 102 | attachments = _dc.deal_chapter({'knowledge_id': j.get("chapterId")}) 103 | for attach_item in attachments: 104 | medias = attach_item.get("attachments") 105 | defaults = attach_item.get("defaults") 106 | for media in medias: 107 | media_type = media.get("type") 108 | media_module = media.get('property').get('module') 109 | media_name = media.get('property').get('name') 110 | if media_type == "video": 111 | if media_module == "insertaudio": 112 | pass 113 | else: 114 | _video_list.append(Video(media, self.user.headers, defaults, name=media_name)) 115 | return _video_list 116 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | # _*_ coding:utf-8 _*_ 2 | # author: liuyunfz 3 | import yaml 4 | import os 5 | from loguru import logger 6 | import sys 7 | import importlib 8 | 9 | from classis.SelfException import LoginException 10 | from config import GloConfig 11 | from classis.User import User 12 | from classis.UserLogger import UserLogger 13 | from utils import * 14 | 15 | logger.remove() 16 | log = UserLogger() 17 | 18 | 19 | def sign_in(infoStr: dict, auto_login: bool = True) -> User: 20 | sign_status = False 21 | sign_mode = '' 22 | clear_console() 23 | if auto_login and GloConfig.data.get("UserData").get("auto-sign") and GloConfig.data.get("UserData").get("cookie"): 24 | log.info("您已开启自动登录模式且本地已检测到账号Cookie,即将校验登录...") 25 | try: 26 | _user = User(cookieStr=GloConfig.data.get("UserData").get("cookie")) 27 | sign_status = True 28 | except LoginException: 29 | log.error("本地Cookie错误,即将进入常规登录...") 30 | else: 31 | sign_mode = input(infoStr.get("signStr")) 32 | while sign_mode not in ["1", "2", ""]: 33 | print("\n" + infoStr.get("errSignMode")) 34 | sign_mode = input(infoStr.get("signStr")) 35 | while not sign_status: 36 | try: 37 | if sign_mode == '' or sign_mode == "1": 38 | username = input("\n请输入您的用户名(手机号):") 39 | password = input("请输入您的密码:") 40 | _user = User(username, password) 41 | else: 42 | cookie = input("请输入账号的Cookie:") 43 | _user = User(cookieStr=cookie) 44 | sign_status = True 45 | except Exception as e: 46 | log.error(e) 47 | logger.debug(_user) 48 | log.success("恭喜你 %s,登录成功" % _user.name) 49 | return _user 50 | 51 | 52 | def get_course(_user: User): 53 | log.info("运行读取课程任务") 54 | _user.getCourse() 55 | log.success("课程读取成功") 56 | if not _user.course_list: 57 | log.info("读取到您没有可执行的课程,如果与您的实际情况不符请提交issue") 58 | exit() 59 | 60 | 61 | def get_config(): 62 | sys.path.append(".") 63 | GloConfig.init_yaml_data() 64 | _config = GloConfig.data 65 | config_debug = _config.get("GloConfig").get("debug") 66 | if config_debug.get("enable"): 67 | logger.add(sys.stdout, format="{time:YYYY-MM-DD HH:mm:ss.SSS} | {level} | {name}:{function}:{line} - {message}", 68 | filter=lambda record: record["extra"].get("name") != "a", 69 | level=config_debug.get("level")) 70 | return _config 71 | 72 | 73 | if __name__ == '__main__': 74 | config = get_config() 75 | clear_console() 76 | print(config.get("InfoStr").get("instructions")) 77 | input("\n回车确认后正式使用本软件:") 78 | user = sign_in(config.get("InfoStr")) 79 | get_course(user) 80 | 81 | functions = [] 82 | path_list = os.listdir('./functions') 83 | for module_path in path_list: 84 | logger.debug("Loading function %s" % module_path) 85 | functions.append(importlib.import_module("functions.%s" % module_path)) 86 | logger.success("Loaded %s successfully" % module_path) 87 | 88 | menu_str = "菜单" 89 | for fun_ind in range(len(functions)): 90 | menu_str += f"\n{fun_ind + 1}.{functions[fun_ind].__disName__}" 91 | 92 | # additional menu 93 | menu_str += f"\n{len(functions) + 1}. 🔃 退出当前已登录账号" + \ 94 | f"\n{len(functions) + 2}. 💾 保存设置并退出本程序" 95 | 96 | while True: 97 | try: 98 | print(menu_str) 99 | fun_i = int(input("\n请输入您要使用功能的序号:")) 100 | if fun_i == len(functions) + 1: 101 | clear_console() 102 | user = sign_in(config.get("InfoStr"), False) 103 | get_course(user) 104 | continue 105 | elif fun_i == len(functions) + 2: 106 | if config['UserData']['auto-sign']: 107 | config['UserData']['cookie'] = user.cookieStr 108 | GloConfig.release_yaml_data() 109 | exit(0) 110 | else: 111 | func = functions[fun_i - 1] 112 | clear_console() 113 | print("\n".join([f"功能名称: {func.__disName__}", 114 | f"作者: {func.__author__}", 115 | f"使用须知: {func.__description__}"]) 116 | ) 117 | if input("\n回车确认使用本功能,其他输入则会退回主菜单:") == "": 118 | func.run(user, log) 119 | else: 120 | clear_console() 121 | continue 122 | 123 | except Exception as e: 124 | log.error("功能调用失败,请检查输入的功能序号") 125 | logger.error(e) 126 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | loguru >= 0.6.0 2 | pyDes >= 2.0.1 3 | requests >= 2.27.1 4 | lxml 5 | PyYAML -------------------------------------------------------------------------------- /static/func_deal_mission.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuyunfz/chaoxing_tool/40a8262310208c4e6598514b1bb54a57ecb5b29b/static/func_deal_mission.jpg -------------------------------------------------------------------------------- /static/func_media_download.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuyunfz/chaoxing_tool/40a8262310208c4e6598514b1bb54a57ecb5b29b/static/func_media_download.jpg -------------------------------------------------------------------------------- /static/func_set_log.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuyunfz/chaoxing_tool/40a8262310208c4e6598514b1bb54a57ecb5b29b/static/func_set_log.jpg -------------------------------------------------------------------------------- /static/func_set_time.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuyunfz/chaoxing_tool/40a8262310208c4e6598514b1bb54a57ecb5b29b/static/func_set_time.jpg -------------------------------------------------------------------------------- /utils.py: -------------------------------------------------------------------------------- 1 | # _*_ coding:utf-8 _*_ 2 | # author: liuyunfz 3 | import requests 4 | from loguru import logger 5 | from requests import post, get 6 | import yaml 7 | import pyDes 8 | import binascii 9 | import os 10 | from time import sleep 11 | from classis.SelfException import RequestException 12 | from lxml.etree import _ElementUnicodeResult 13 | with open("config.yml", "r", encoding="utf-8") as f: 14 | config = yaml.safe_load(f) 15 | glo_headers = config.get("GloConfig").get("headers") 16 | glo_timeout = config.get("GloConfig").get("timeout") 17 | logger.success("Loaded config successfully") 18 | if_delay = config.get("GloConfig").get("delay").get("enable") 19 | time_delay = config.get("GloConfig").get("delay").get("time") 20 | 21 | ses = requests.session() 22 | 23 | 24 | def doGet(url: str, headers: 'dict|str' = glo_headers, ifFullBack: bool = False) -> 'str|requests.Response': 25 | """ 26 | 调用requests进行Get请求,并输出日志 27 | 28 | :param url: 欲访问的链接地址 29 | :param headers: 请求携带的headers,默认为config文件中GloConfig.headers 30 | :param ifFullBack 是否返回完整的Response信息 31 | :return: 返回网页文本信息,即html.text 32 | """ 33 | try: 34 | logger.debug("Do Get to Url %s" % url) 35 | ses.headers.clear() 36 | ses.headers.update(headers) 37 | sleep(time_delay) if if_delay else None 38 | html = ses.get(url=url, timeout=glo_timeout) 39 | if ifFullBack: 40 | return html 41 | if html.status_code == 200: 42 | return html.text 43 | else: 44 | raise RequestException(html, 0) 45 | 46 | except Exception as e: 47 | logger.error(f"Get Url {url} Error\n {e}") 48 | 49 | 50 | def doPost(url: str, headers: 'dict|str' = glo_headers, data: 'dict|str' = "", ifFullBack: bool = False) -> 'str|requests.Response': 51 | """ 52 | 调用requests进行Post请求,并输出日志 53 | 54 | :param url: 欲访问的链接地址 55 | :param headers: 请求携带的headers,默认为config文件中GloConfig.headers 56 | :param data: 请求携带的data数据,默认为空 57 | :param ifFullBack 是否返回完整的Response信息 58 | :return: 返回网页文本信息,即html.text 59 | """ 60 | try: 61 | logger.debug("Do Post to Url %s" % url) 62 | logger.debug("With data: %s" % data) 63 | ses.headers.clear() 64 | ses.headers.update(headers) 65 | sleep(time_delay) if if_delay else None 66 | html = ses.post(url=url, data=data, timeout=glo_timeout) 67 | if ifFullBack: 68 | return html 69 | if html.status_code == 200: 70 | return html.text 71 | else: 72 | raise RequestException(html, 1) 73 | 74 | except Exception as e: 75 | logger.error(f"Post Url {url} Error\n {e}") 76 | 77 | 78 | def xpath_first(element, path): 79 | """ 80 | 返回xpath获取到的第一个元素,如果没有则返回空字符串 81 | 由于 lxml.etree._Element._Element 为私有类,所以不予设置返回值类型 82 | 83 | :param element: etree.HTML实例 84 | :param path: xpath路径 85 | :return: 第一个元素或空字符串 86 | """ 87 | if type(element) in (str, int): 88 | return element 89 | res = element.xpath(path) 90 | if type(res) == _ElementUnicodeResult: 91 | return res 92 | if len(res) == 1: 93 | return res[0] 94 | else: 95 | return "" 96 | 97 | 98 | def direct_url(old_url: str, headers: dict, ifLoop: bool = False) -> str: 99 | """ 100 | 返回重定向后的真实Url 101 | 102 | :param old_url: 待重定向的链接地址 103 | :param headers: 附带的请求头 104 | :param ifLoop: 是否迭代查询直至无跳转 105 | :return: 最终的Url 106 | """ 107 | logger.debug("Redirect old url: %s" % old_url) 108 | location_new = None 109 | try: 110 | while location_new is None: 111 | rsp = requests.get(url=old_url, headers=headers, allow_redirects=False) 112 | location_new = rsp.headers.get("Location") 113 | if ifLoop: 114 | return location_new | old_url 115 | if location_new is None: 116 | logger.debug("Final url: %s" % old_url) 117 | return old_url 118 | else: 119 | old_url = location_new 120 | location_new = None 121 | except Exception as e: 122 | logger.error(e) 123 | return "" 124 | 125 | 126 | def encrypt_des(msg, key): 127 | des_obj = pyDes.des(key, key, pad=None, padmode=pyDes.PAD_PKCS5) 128 | secret_bytes = des_obj.encrypt(msg, padmode=pyDes.PAD_PKCS5) 129 | return binascii.b2a_hex(secret_bytes) 130 | 131 | 132 | def clear_console(): 133 | if os.name == "nt": 134 | os.system("cls") 135 | else: 136 | os.system("clear") 137 | 138 | 139 | if __name__ == '__main__': 140 | doGet("https://www.6yfz.cn/") 141 | --------------------------------------------------------------------------------