├── .github └── workflows │ ├── package.yml │ └── shipper.ps1 ├── .gitignore ├── LICENSE ├── README.md └── suckless-cut.lua /.github/workflows/package.yml: -------------------------------------------------------------------------------- 1 | name: Rust 2 | 3 | on: 4 | push: 5 | branches: [ "main" ] 6 | 7 | jobs: 8 | release-win: 9 | runs-on: ${{ matrix.os }} 10 | 11 | strategy: 12 | matrix: 13 | os: [windows-2022] 14 | 15 | steps: 16 | 17 | - uses: actions/checkout@v3 18 | with: 19 | submodules: recursive 20 | 21 | - name: Ship 22 | shell: pwsh 23 | run: ./.github/workflows/shipper.ps1 24 | 25 | - name: Generate release tag 26 | id: tag 27 | run: echo "::set-output name=release_tag::Nightly_$(date +"%Y.%m.%d_%H-%M")" 28 | 29 | - uses: softprops/action-gh-release@v1 30 | with: 31 | tag_name: ${{ steps.tag.outputs.release_tag }} 32 | fail_on_unmatched_files: true 33 | files: | 34 | ./suckless-cut.lua 35 | ./suckless-cut_with-recommended-scripts.zip -------------------------------------------------------------------------------- /.github/workflows/shipper.ps1: -------------------------------------------------------------------------------- 1 | param( 2 | [switch]$clean 3 | ) 4 | 5 | set-location $psscriptroot/../.. 6 | 7 | if(-not(test-path ./slc-out/)){ 8 | mkdir ./slc-out/ 9 | } 10 | 11 | $curl = (Get-Command curl -CommandType Application -ErrorAction Stop).Source | Select-Object -Last 1 12 | 13 | & $curl --location ` 14 | https://raw.githubusercontent.com/po5/thumbfast/master/thumbfast.lua -o "thumbfast.lua" ` 15 | https://github.com/tomasklaen/uosc/releases/latest/download/uosc.zip -o "uosc.zip" 16 | 17 | Expand-Archive ./uosc.zip ./slc-out 18 | 19 | Move-Item ./thumbfast.lua ./slc-out/scripts/ 20 | 21 | Copy-Item ./suckless-cut.lua ./slc-out/scripts/ 22 | 23 | Compress-Archive ./slc-out/* -DestinationPath ./suckless-cut_with-recommended-scripts.zip 24 | 25 | if ($clean){ 26 | remove-item ./uosc.zip 27 | remove-item ./slc-out/ -Recurse -Force 28 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Lua sources 2 | luac.out 3 | 4 | # luarocks build files 5 | *.src.rock 6 | *.zip 7 | *.tar.gz 8 | 9 | # Object files 10 | *.o 11 | *.os 12 | *.ko 13 | *.obj 14 | *.elf 15 | 16 | # Precompiled Headers 17 | *.gch 18 | *.pch 19 | 20 | # Libraries 21 | *.lib 22 | *.a 23 | *.la 24 | *.lo 25 | *.def 26 | *.exp 27 | 28 | # Shared objects (inc. Windows DLLs) 29 | *.dll 30 | *.so 31 | *.so.* 32 | *.dylib 33 | 34 | # Executables 35 | *.exe 36 | *.out 37 | *.app 38 | *.i*86 39 | *.x86_64 40 | *.hex 41 | 42 | -------------------------------------------------------------------------------- /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 | # suckless-cut 2 | 3 | I recreated the features I liked from [losslesscut](https://github.com/mifi/lossless-cut) in the [mpv](https://mpv.io) (not [mpv.net](https://github.com/mpvnet-player/mpv.net)) video player via a lua script 4 | 5 |
6 | Why? 7 | 8 | LosslessCut is a great and intuitive user interface for cutting videos, but I dislike all the loading times you need to wait through at each step and much prefer a CLI / keyboard based workflow. 9 | 10 | mpv is a much snappier video player, so I made a lua script with keybinds to gather in and out points of videos, and run an external process (smoothie or ffmpeg) to read that video and make a cut copy of them. 11 |
12 | 13 | # Features 14 | 15 | * supports cutting multiple segments (called 'indexes') 16 | * entirely controllable by [keyboard](#keybinds) 17 | * snappy, no chromium or javascript around here 18 | * supports playlists (having multiple files open at once) 19 | * segments are displayed by making fake chapters 20 | 21 | ![chapters](https://github.com/couleur-tweak-tips/suckless-cut/releases/download/readme-assets/chapters.webp) 22 | 23 | # Installation 24 | 25 | Place [`suckless-cut.lua`](https://github.com/couleur-tweak-tips/suckless-cut/releases/latest/download/suckless-cut.lua) in your mpv `scripts` folder 26 | 27 |
28 | What? what even is is my "scripts folder?" 29 | 30 | 31 | ### mpv config folder location 32 | 33 | * https://mpv.io/manual/master/#files (on linux) 34 | 35 | * https://mpv.io/manual/master/#files-on-windows 36 | 37 | Tip: if you installed mpv on Windows with Scoop it's at `%USERPROFILE%\scoop\apps\mpv\current\portable_config` 38 |
39 | 40 | You may also run mpv with `--script="/path/to/suckless-cut.lua"` 41 | ## Keybinds 42 | 43 | ### Setting in & out point(s) 44 | 45 | * g and h sets in and out points at current player position 46 | 47 | * G and H sets in point at `00:00:00`, and out the end of the video 48 | 49 | ### Rendering 50 | 51 | * Ctrl+r takes your indexes and executes your default export program with them 52 | 53 | ### Navigating indexes 54 | 55 | Each cut you make is stored in an index, which contains the `start`, `fin` (end) and file `path` 56 | 57 | After setting a start and end point, setting another start point will automatically set it to index #2 58 | 59 | * c and C lets you go down (uncapped), and up (with capitalized) your **indexes**, which is what each `start`-`end` combo is called 60 | 61 | * Ctrl-p prints all indexes to console & OSD 62 | 63 | * Ctrl+t (requires [uosc](https://github.com/tomasklaen/uosc) installed) graphical index selector 64 | 65 | ![image](https://github.com/couleur-tweak-tips/suckless-cut/releases/download/readme-assets/selector.webp) 66 | 67 | * K cycles export modes, available: 68 | * [smoothie](https://github.com/couleur-tweak-tips/smoothie-rs) 69 | * [ffmpeg](https://ffmpeg.org) 70 | 71 | > [!WARNING] 72 | > smoothie export don't contain audio, to circumvent this cut with ffmpeg first then run it manually through smoothie 73 | 74 | * k cycles cutting modes: 75 | * `split` separates every single cut into separate files 76 | * `trim` merges and joins the multiple cuts you have per video 77 | 78 | ### Debugging 79 | 80 | * Ctrl+v toggles on/off verbose 81 | 82 | ## How to cut at each keyframe (for better results while cutting with ffmpeg) 83 | 84 | Keyframes are arbitrary timestamps in a video that are preferable to cut at, if not you may experience desync or your video not embedding. 85 | 86 | To seek through each keyframes: move your cursor over to the seekbar and use your mouse scroll wheel on it to seek across keyframes, then set your start/end points with `g` `h` there. todo: find/add keybinds to easily do this via the keyboard 87 | 88 | 89 | # Alternatives 90 | 91 | * https://github.com/stax76/awesome-mpv#video-editing 92 | * https://github.com/f0e/mpv-cut -------------------------------------------------------------------------------- /suckless-cut.lua: -------------------------------------------------------------------------------- 1 | local config = { 2 | export_mode = "ffmpeg" 3 | --[[ 4 | supported: 5 | 6 | - smoothie 7 | - ffmpeg 8 | 9 | cycle by pressing K 10 | ]] 11 | ,smoothie_path = "smoothie-rs" 12 | ,ffmpeg_path = "ffmpeg" 13 | --[[ 14 | 15 | defaults to checking in PATH 16 | 17 | Windows users: DO NOT FORGET TO ESCAPE \ BY DOUBLING THEM, i.e.: 18 | 19 | "D:\\This\\is\\OKAY\\smoothie-rs.exe" 20 | 21 | "D:\This\is NOT\OKAY\smoothie-rs.exe" 22 | 23 | ]] -- 24 | 25 | 26 | ,cut_mode = 'trim' 27 | --[[ 28 | 29 | supported: 30 | 31 | - trim: merge each file's own cut to a single file 32 | - split: each cut is exported in it's own file 33 | 34 | cycle by pressing k 35 | 36 | ]] -- 37 | ,switch_above = 119 38 | 39 | ,output_directory = "" 40 | --[[ 41 | 42 | folder where videos get outputted, there's 3 possible settings: 43 | 44 | - "" will output files in the same directory as the input file 45 | - "." for working directory 46 | - "D:\\Videos\\", do not forget to duplicate back slashes \ 47 | 48 | ]] -- 49 | 50 | ,dur = 2500 51 | -- Duration of OSC (top left) messages, in milliseconds 52 | 53 | ,verbose = false 54 | -- Off by default, can be toggled by pressing Ctrl+v 55 | } 56 | require "mp.options".read_options(config, "suckless-cut") 57 | local mp = require 'mp' 58 | local msg = require 'mp.msg' 59 | local utils = require 'mp.utils' 60 | local switchExportRan = false 61 | 62 | mp.register_event("file-loaded", function() 63 | local container_fps = mp.get_property('container-fps') 64 | if container_fps == nil then return end 65 | local vid_fps = tonumber(container_fps) 66 | 67 | if vid_fps == 0 or switchExportRan then 68 | -- disabled by user / already ran 69 | return 70 | elseif config.switch_above > vid_fps then 71 | print("FPS is above trigger limit, switching export mode to smoothie") 72 | config.export_mode = "smoothie" 73 | end 74 | switchExportRan = true 75 | end) 76 | 77 | Osdwarn = false -- Used when user made too many trimming points 78 | Trs = {} -- Creates a fresh empty table, will be appended start/fin timecodes 79 | Index = 1 -- Selects the trim 1, for it to be increased/decreased later 80 | 81 | local function verb(...) 82 | local args = { ... } 83 | local text = "" 84 | 85 | for i, v in ipairs(args) do 86 | text = text .. tostring(v) 87 | end 88 | if config.verbose == true then 89 | print("VERB", text) 90 | end 91 | end 92 | 93 | 94 | 95 | local function notify(duration, ...) 96 | local args = { ... } 97 | local text = "" 98 | 99 | for i, v in ipairs(args) do 100 | text = text .. tostring(v) 101 | end 102 | 103 | if text == nil or text == "" then 104 | return 105 | end 106 | 107 | print("", text) 108 | mp.command(string.format("show-text \"%s\" %d 1", text, duration)) 109 | end 110 | 111 | 112 | 113 | local function dump() 114 | local vals = { 115 | 'container-fps', 'time-pos', 116 | 'playback-time/full', 'stream-open-filename', 117 | 'estimated-frame-number', 'duration' 118 | } 119 | for _, val in ipairs(vals) do 120 | print(val, ": ", mp.get_property(val)) 121 | end 122 | end; mp.add_key_binding("Ctrl+d", "dump", dump) 123 | 124 | 125 | 126 | local function setindex(index) 127 | notify(config.dur, ("Setting index to [" .. index .. "]")) 128 | Index = index 129 | end 130 | mp.register_script_message('setindex', setindex) 131 | 132 | 133 | 134 | local function round(int) 135 | return (math.floor(int * 100)) / 100 136 | end 137 | 138 | local function get_fn() -- fn for File Name 139 | local fn = utils.join_path(mp.get_property("working-directory", ""), (mp.get_property("path", ""))) 140 | 141 | assert(io.open(fn, "r"), "\nFailed to get path " .. fn .. " insufficient permissions?") 142 | 143 | -- -- additional path checking 144 | -- if (io.open(fn, "r") == nil) then 145 | -- fn = utils.join_path(utils.getcwd(), fn) 146 | -- else 147 | -- print("Failed getting path " .. fn) 148 | -- end 149 | 150 | verb("PATH: " .. fn) 151 | 152 | return fn 153 | end 154 | 155 | 156 | 157 | local function get_basename(path) 158 | local _, basename = utils.split_path(path) 159 | assert(basename, "Failed to get basename from " .. path) 160 | return basename 161 | end 162 | 163 | 164 | 165 | 166 | local function selectindex() 167 | -- local fps = mp.get_property('container-fps') 168 | 169 | local menu = { 170 | type = 'menu_type', 171 | title = 'Select an index to switch back to', 172 | items = {} 173 | } 174 | 175 | for i, cur in ipairs(Trs) do 176 | if cur['start'] or cur['end'] then 177 | menu['items'][i] = {} 178 | menu['items'][i]['title'] = (round(cur['start']) or '') .. ' - ' .. (round(cur['fin']) or '') 179 | menu['items'][i]['value'] = "script-message setindex " .. i 180 | menu['items'][i]['hint'] = get_basename(cur['path']) 181 | end 182 | end 183 | mp.commandv('script-message-to', 'uosc', 'open-menu', (utils.format_json(menu))) 184 | end; mp.add_key_binding("Ctrl+t", "selectindex", selectindex) 185 | 186 | 187 | 188 | 189 | local function create_chapter(time_pos) 190 | if not time_pos then 191 | time_pos = mp.get_property_number("time-pos") 192 | end 193 | verb("Creating chapter at ", time_pos) 194 | local time_pos_osd = mp.get_property_osd("playback-time/full") 195 | local curr_chapter = mp.get_property_number("chapter") 196 | local chapter_count = mp.get_property_number("chapter-list/count") 197 | local all_chapters = mp.get_property_native("chapter-list") 198 | 199 | if chapter_count == 0 then 200 | all_chapters[1] = { 201 | title = "", 202 | time = time_pos 203 | } 204 | curr_chapter = 0 205 | else 206 | for i = chapter_count, curr_chapter + 2, -1 do 207 | all_chapters[i + 1] = all_chapters[i] 208 | end 209 | all_chapters[curr_chapter + 2] = { 210 | title = "", 211 | time = time_pos 212 | } 213 | end 214 | mp.set_property_native("chapter-list", all_chapters) 215 | --mp.set_property_number("chapter", curr_chapter+1) 216 | time_pos = nil 217 | end; mp.add_key_binding("n", "createChapter", create_chapter) 218 | 219 | 220 | 221 | 222 | local function deletechapters() 223 | mp.set_property_native("chapter-list", {}) 224 | end; mp.add_key_binding("Ctrl+D", "deletechapters", deletechapters) 225 | 226 | 227 | 228 | 229 | local function reloadTrs() 230 | -- rebuilds chapters from Trs 231 | 232 | mp.set_property_native("chapter-list", {}) 233 | -- Delete all chapters 234 | 235 | for i, val in pairs(Trs) do 236 | if val['path'] == get_fn() then 237 | if Trs[i]['start'] then 238 | create_chapter(Trs[i]['start']) 239 | else 240 | verb("not creating start chapter for index ", i) 241 | end 242 | 243 | if Trs[i]['fin'] then 244 | create_chapter(Trs[i]['fin']) 245 | else 246 | verb("Not creating fin chapter for index ", i) 247 | end 248 | end 249 | end 250 | end; 251 | mp.add_key_binding("R", "reloadTrs", reloadTrs) 252 | mp.register_event("file-loaded", reloadTrs) 253 | 254 | 255 | 256 | 257 | local function incrIndex() 258 | if #Trs < 2 and Trs[Index + 1] == nil then 259 | notify(config.dur, "You only have one starter index,\nstart making a second index before cycling through them.") 260 | return 261 | end 262 | 263 | if Trs[Index + 1] == nil then 264 | Index = 1 -- Looping through 265 | notify(config.dur, "[c] (Looping) Increased index back down to " .. Index) 266 | else 267 | Index = Index + 1 268 | notify(config.dur, "[C] Increased index to " .. Index) 269 | end 270 | end; mp.add_key_binding("C", "increaseIndex", incrIndex) 271 | 272 | 273 | 274 | 275 | local function decrIndex() 276 | if #Trs < 2 then 277 | notify(config.dur, "You only have one starter index,\nstart making a second index before cycling through them.") 278 | return 279 | end 280 | 281 | if Trs[Index - 1] == nil then 282 | Index = #Trs -- Looping through 283 | notify(config.dur, "[c] (Looping) Lowered index back up to " .. Index) 284 | else 285 | Index = Index - 1 286 | notify(config.dur, "[c] Lowered index to " .. Index) 287 | end 288 | end; mp.add_key_binding("c", "decreaseIndex", decrIndex) 289 | 290 | 291 | 292 | 293 | local function showPoints() 294 | if config.verbose then 295 | print(utils.format_json(Trs)) 296 | end 297 | 298 | print("export mode: " .. config.export_mode) 299 | print("cut mode: " .. config.cut_mode) 300 | 301 | if #Trs == 0 then 302 | notify(config.dur, 303 | "cut mode: " .. config.cut_mode .. " | export mode: " .. config.export_mode .. "\nNo trimming points yet") 304 | return 305 | end 306 | 307 | msg = "cut mode: " .. config.cut_mode .. " | export mode: " .. config.export_mode .. "\n" 308 | if #Trs > 11 and Osdwarn == false then 309 | notify(config.dur, "You have too much trimming points\nfor it to fit on the OSD, check the console.") 310 | Osdwarn = true 311 | return 312 | end 313 | 314 | for ind, _ in ipairs(Trs) do 315 | if Trs[ind]['path'] ~= nil then 316 | msg = msg .. "\n" .. "[" .. ind .. "] " .. get_basename(Trs[ind]['path']) 317 | end 318 | if Trs[ind].start ~= nil then --/fps 319 | msg = msg .. " : " .. string.sub(string.format(Trs[ind].start), 1, 4) 320 | end 321 | if Trs[ind].fin ~= nil then --/fps 322 | msg = msg .. " - " .. string.sub(string.format(Trs[ind].fin), 1, 4) 323 | end 324 | end 325 | print(msg) 326 | mp.osd_message(msg, config.dur / 500) -- 2x longer than normal dur, divide by / 1000 for same length 327 | end; mp.add_key_binding("Ctrl+p", "showPoints", showPoints) 328 | 329 | 330 | 331 | 332 | local function getIndex() 333 | notify(config.dur, "[g] Selected index is " .. Index) 334 | end; mp.add_key_binding("Ctrl+g", "getCurrentIndex", getIndex) 335 | 336 | 337 | local function initIndex() 338 | if Trs[Index] == nil then 339 | Trs[Index] = {} 340 | end 341 | end 342 | 343 | 344 | 345 | local function start(sof) 346 | initIndex() 347 | local pos = mp.get_property_number('playback-time/full') 348 | local fn = get_fn() 349 | local curframe = "unfilled start" 350 | if sof == true then 351 | curframe = "0" 352 | else 353 | curframe = mp.get_property_number('time-pos') 354 | end 355 | 356 | if Trs[Index] == nil then Trs[Index] = {} end 357 | Trs[Index]['start'] = curframe 358 | Trs[Index]['path'] = fn 359 | 360 | notify(config.dur, "[g] Set start point of index [" .. Index .. "] at " .. round(pos)) 361 | 362 | create_chapter(); reloadTrs() 363 | end; mp.add_key_binding("g", "set-start", start) 364 | 365 | local function sof() 366 | start(true) 367 | 368 | -- will probably remove the rest of this function later 369 | 370 | 371 | -- local fn = get_fn() 372 | -- notify(dur, "[G] Setting index " .. Index .. " to 00:00:00 (start of file)") 373 | -- if Trs[Index] == nil then Trs[Index] = {} end 374 | -- Trs[Index]['start'] = "0" 375 | -- Trs[Index]['path'] = fn 376 | end; mp.add_key_binding("G", "set-sof", sof) 377 | 378 | 379 | local function fin(eof) 380 | initIndex() 381 | local pos = mp.get_property_number('playback-time/full') 382 | local fn = get_fn() 383 | local curframe = "unfilled fin" 384 | if eof == true then 385 | curframe = string.format(mp.get_property('duration')) 386 | else 387 | curframe = mp.get_property_number('time-pos') 388 | end 389 | if Trs[Index] == nil then Trs[Index] = {} end 390 | Trs[Index]['fin'] = curframe 391 | 392 | if Trs[Index]['start'] == nil and Trs[Index - 1] and Trs[Index - 1]['start'] ~= nil then 393 | notify(config.dur, "[g] You need to set a start point first.") 394 | return nil 395 | -- Trs[Index-1]['fin'] = curframe 396 | end 397 | 398 | Trs[Index]['path'] = fn 399 | 400 | notify(config.dur, "[h] Set end point of index [" .. Index .. "] at " .. round(pos)) 401 | 402 | if Trs[Index + 1] == nil then 403 | Trs[Index + 1] = {} 404 | end 405 | 406 | if Trs[Index + 1]['start'] == nil and Trs[Index + 1]['fin'] == nil then -- Only step up if it's the last index 407 | Index = Index + 408 | 1 -- Else it means the user has went back down on an older index 409 | end 410 | 411 | create_chapter(); reloadTrs() 412 | end; mp.add_key_binding("h", "set-fin", fin) 413 | 414 | 415 | local function eof() 416 | fin(true) 417 | 418 | -- same as sof 419 | 420 | -- local fn = get_fn() 421 | -- print("", utils.format_json(Trs)) 422 | -- if Trs[Index]['start'] == nil then 423 | -- notify(dur, "[g] You need to set a start point first.") 424 | -- return 425 | -- end 426 | 427 | -- local framecount = mp.get_property('duration') 428 | -- notify(dur, "[H] Set end point of index [" .. Index .. "] to " .. framecount .. " (End of file)") 429 | -- Trs[Index]['fin'] = string.format(framecount) 430 | -- Trs[Index]['path'] = fn 431 | end; mp.add_key_binding("H", "set-eof", eof) 432 | 433 | 434 | --------------------------------------------------- 435 | -- the following functions are used by render() --- 436 | --------------------------------------------------- 437 | 438 | local function sanitizeFilepath(filepath) 439 | local sanitized = filepath 440 | if package.config:sub(1,1) == '\\' then -- Check if the system is Windows 441 | sanitized = filepath:gsub("/", "\\") -- Replace forward slashes with backslashes 442 | end 443 | return sanitized 444 | end 445 | 446 | local function checkTrs(tbl) 447 | -- Check if the table is empty 448 | if next(tbl) == nil then 449 | print("next is nil ") 450 | return false 451 | end 452 | 453 | -- Get the last element of the table 454 | local lastObject = tbl[#tbl] 455 | 456 | -- Check if the last object contains all required keys 457 | if lastObject.path and lastObject.fin and lastObject.start then 458 | print("contains all keys") 459 | return true 460 | else 461 | print("insuficient keys") 462 | print(utils.format_json(tbl[#tbl])) 463 | print(utils.format_json(tbl)) 464 | return false 465 | end 466 | end 467 | 468 | local function appendSuffix(path, suffix) 469 | local basename = path:match("^.+[\\/](.+)$") 470 | if basename then 471 | local dotIndex = basename:find("%.") 472 | if dotIndex then 473 | local namePart = basename:sub(1, dotIndex - 1) 474 | local extension = basename:sub(dotIndex) 475 | return path:sub(1, -(#basename + 1)) .. namePart .. suffix .. extension 476 | else 477 | return path .. suffix 478 | end 479 | else 480 | error("Failed adding suffix '" .. suffix .. "' to video file path " .. path, 1) 481 | end 482 | end 483 | 484 | -- https://docs.python.org/3/library/tempfile.html#tempfile.gettempdir 485 | local tempfolder = os.getenv("TEMP") 486 | if utils.readdir(tempfolder) == nil then 487 | tempfolder = os.getenv("TMPDIR") 488 | if utils.readdir(tempfolder) == nil then 489 | if package.config:sub(1, 1) == '\\' then 490 | tempfolder = "C:\\Temp" 491 | else 492 | tempfolder = "/tmp" 493 | end 494 | if utils.readdir(tempfolder) == nil then 495 | error("failed to find temp folder") 496 | end 497 | end 498 | end 499 | 500 | local function table_to_args(args) 501 | for index, object in ipairs(args) do 502 | if string.find(object, "%s") then 503 | args[index] = '"' .. object .. '"' 504 | end 505 | end 506 | 507 | return table.concat(args, " ") 508 | end 509 | 510 | local function render() 511 | -- hides https://mpv.io/manual/master/#terminal-status-line 512 | mp.set_property_bool("quiet", true) 513 | 514 | Commands = {} 515 | if checkTrs(Trs) == false then 516 | Trs[#Trs] = nil 517 | end 518 | -- this fixed something at some point 519 | -- Trs[#Trs] = nil -- remove last object 520 | 521 | local ffi = require("ffi") 522 | ffi.cdef [[ 523 | int system(const char *command); 524 | ]] 525 | 526 | if config.cut_mode == 'split' then 527 | if config.export_mode == "smoothie" then 528 | for _, val in pairs(Trs) do 529 | Cmd = { 530 | args = { 531 | "-i", val['path'], 532 | "--override", "runtime;cut type;trim", 533 | "--stripaudio", 534 | "--override", "runtime;timecodes;" .. val['start'] .. '-' .. val['fin'] 535 | } 536 | } 537 | end 538 | Commands[#Commands + 1] = Cmd 539 | elseif config.export_mode == 'ffmpeg' then 540 | for _, val in pairs(Trs) do 541 | local outPath = appendSuffix( 542 | val['path'], 543 | round(val['start']) .. '-' .. round(val['fin']) 544 | ) 545 | Cmd = { 546 | args = { 547 | "-loglevel", "error", 548 | "-stats", 549 | "-ss", val['start'], 550 | "-i", val['path'], 551 | "-map", "0", 552 | "-to", val['fin'], 553 | "-c", "copy", 554 | outPath 555 | } 556 | } 557 | Commands[#Commands + 1] = Cmd 558 | end 559 | end 560 | elseif config.cut_mode == 'trim' then 561 | local unique = {} 562 | 563 | for _, value in pairs(Trs) do 564 | if not unique[value.path] then 565 | unique[value.path] = {} 566 | end 567 | unique[value.path][#unique[value.path] + 1] = { start = value['start'], fin = value['fin'] } 568 | end 569 | 570 | if config.export_mode == "smoothie" then 571 | for key, value in pairs(unique) do 572 | Cmd = { 573 | args = { 574 | "-i", key, 575 | "--override", "runtime;cut type;trim", 576 | "--stripaudio", 577 | "--override" 578 | } 579 | } 580 | local arg = "runtime;timecodes" 581 | for index, timecodes in ipairs(value) do 582 | -- print(index, utils.format_json(timecodes)) 583 | 584 | arg = arg .. ';' .. timecodes['start'] .. '-' .. timecodes['fin'] 585 | end 586 | arg = '"' .. arg .. '"' 587 | table.insert(Cmd.args, arg) 588 | Commands[#Commands + 1] = Cmd 589 | end 590 | elseif config.export_mode == "ffmpeg" then 591 | print("unique: " .. utils.format_json(unique)) 592 | for in_path, cuts in pairs(unique) do 593 | local cutted_paths = {} 594 | for _, cut in pairs(cuts) do 595 | local outPath = sanitizeFilepath(utils.join_path( 596 | tempfolder, 597 | get_basename(in_path) .. '-' .. cut.start .. '-' .. cut.fin .. "-cut.mkv" 598 | )) 599 | 600 | local args = table_to_args({ 601 | "-loglevel", "error", 602 | "-stats", 603 | "-ss", cut.start, 604 | "-i", in_path, 605 | "-map", "0", 606 | "-to", cut.fin, 607 | "-c", "copy", 608 | outPath 609 | 610 | }) 611 | cutted_paths[#cutted_paths + 1] = outPath 612 | verb("temp cut: " .. args) 613 | 614 | ffi.C.system(config.ffmpeg_path .. " " .. args) 615 | end 616 | 617 | local concat_path = utils.join_path(tempfolder, "slc-concat-temp.txt") 618 | local file = io.open(concat_path, "w") 619 | 620 | -- print("cutted paths: " .. utils.to_string(cutted_paths)) 621 | 622 | if not file then 623 | error("Unable to open file '" .. concat_path .. "' for writing.") 624 | end 625 | 626 | for index, path in ipairs(cutted_paths) do 627 | verb("writing " .. index .. " line '" .. path .. "'") 628 | file:write("file '" .. path .. "'\n") 629 | end 630 | file:close() 631 | 632 | local args = table_to_args({ 633 | "-hide_banner", 634 | "-loglevel", "error", 635 | "-stats", 636 | 637 | "-f", "concat", 638 | "-safe", "0", 639 | "-i", concat_path, 640 | "-c", "copy", 641 | 642 | "-default_mode", "infer_no_subs", 643 | "-ignore_unknown", 644 | "-strict", "experimental", 645 | 646 | appendSuffix(in_path, "-trim") 647 | }) 648 | 649 | verb("final concat :" .. args) 650 | 651 | ffi.C.system(config.ffmpeg_path .. " " .. args) 652 | end 653 | else 654 | error("Unknown export mode '" .. config.export_mode .. "'") 655 | end 656 | end 657 | 658 | --[[ 659 | if config.cut_mode == 'split' then 660 | for key, val in pairs(Trs) do 661 | if config.export_mode == 'smoothie' then 662 | verb('setting smoothie split args') 663 | 664 | Cmd = { 665 | args = { 666 | "-i", val['path'], 667 | "--override", "runtime;cut type;trim", 668 | "--override", "runtime;timecodes;" .. val['start'] .. '-' .. val['fin'] 669 | } 670 | } 671 | elseif config.export_mode == 'ffmpeg' then 672 | verb('setting ffmpeg split args') 673 | local outPath = appendSuffix( 674 | val['path'], 675 | round(val['start']) .. '-' .. round(val['fin']) 676 | ) 677 | Cmd = { 678 | args = { 679 | "-loglevel", "error", 680 | "-stats", 681 | "-i", val['path'], 682 | "-ss", val['start'], 683 | "-to", val['fin'], 684 | "-c", "copy", 685 | outPath 686 | } 687 | } 688 | end 689 | Commands[#Commands + 1] = Cmd 690 | end 691 | elseif config.cut_mode == 'trim' then 692 | local unique = {} 693 | 694 | for key, value in pairs(Trs) do 695 | if not unique[value.path] then 696 | unique[value.path] = {} 697 | end 698 | unique[value.path][#unique[value.path] + 1] = { start = value['start'], fin = value['fin'] } 699 | end 700 | 701 | for key, value in pairs(unique) do 702 | if config.export_mode == "smoothie" then 703 | Cmd = { 704 | args = { 705 | "-i", key, 706 | "--override", "runtime;cut type;trim", 707 | "--override" 708 | } 709 | } 710 | local arg = "runtime;timecodes" 711 | for index, timecodes in ipairs(value) do 712 | -- print(index, utils.format_json(timecodes)) 713 | 714 | arg = arg .. ';' .. timecodes['start'] .. '-' .. timecodes['fin'] 715 | end 716 | arg = '"' .. arg .. '"' 717 | table.insert(Cmd.args, arg) 718 | Commands[#Commands + 1] = Cmd 719 | else 720 | print("\27[31mffmpeg yet\27[0m") 721 | end 722 | end 723 | end 724 | ]] 725 | 726 | if not config.verbose then 727 | mp.set_property("vo", "null") 728 | mp.commandv('quit') 729 | end 730 | 731 | for _, Cmd in pairs(Commands) do 732 | local command = '' 733 | verb("what even is args: " .. utils.format_json(Cmd.args)) 734 | 735 | for i, element in ipairs(Cmd.args) do 736 | if string.find(element, "%s") then 737 | Cmd.args[i] = '"' .. element .. '"' 738 | end 739 | end 740 | 741 | command = table.concat(Cmd.args, " ") 742 | 743 | if config.verbose == true and config.export_mode == "smoothie" then 744 | command = command .. ' --verbose' 745 | print('COMMAND: ' .. command) 746 | end 747 | 748 | -- -- another way 749 | -- mp.command_native({ 750 | -- name = "subprocess", 751 | -- playback_only = false, 752 | -- capture_stdout = true, 753 | -- args = Cmd.args, 754 | -- detach = true 755 | -- }) 756 | 757 | if config.export_mode == "smoothie" then 758 | ffi.C.system(config.smoothie_path .. " " .. command) 759 | elseif config.export_mode == "ffmpeg" and config.cut_mode == "split" then 760 | ffi.C.system(config.ffmpeg_path .. " " .. command) 761 | end 762 | 763 | 764 | -- print(utils.to_string(config.export_mode ~= "smoothie") .. " AND " .. utils.to_string(config.cut_mode ~= "trim")) 765 | -- if config.export_mode ~= "smoothie" and config.cut_mode ~= "trim" then 766 | -- print("we gud :3") 767 | -- if config.export_mode == "smoothie" then 768 | -- print("haha!") 769 | -- ffi.C.system(config.smoothie_path .. " " .. command) 770 | -- elseif config.export_mode == "ffmpeg" then 771 | -- ffi.C.system(config.ffmpeg_path .. " " .. command) 772 | -- else 773 | -- error("Unknown export mode \"" .. config.export_mode .. "\"") 774 | -- end 775 | -- end 776 | end 777 | 778 | if not config.verbose then 779 | mp.commandv('quit') 780 | end 781 | 782 | mp.set_property_bool("quiet", false) 783 | end; mp.add_key_binding("Ctrl+r", "exportSLC", render) 784 | 785 | 786 | 787 | 788 | local function cycleCutModes() 789 | if config.cut_mode == 'trim' then 790 | notify(config.dur, "[k] SPLIT MODE: Separating cuts into separate files") 791 | config.cut_mode = 'split' 792 | elseif config.cut_mode == 'split' then 793 | notify(config.dur, "[k] TRIM MODE: Joining each videos' cuts") 794 | config.cut_mode = 'trim' 795 | end 796 | end; mp.add_key_binding("k", "toggleCutModes", cycleCutModes) 797 | 798 | local function cycleExportModes() 799 | if config.export_mode == 'ffmpeg' then 800 | notify(config.dur, "[K] EXPORT MODE: smoothie") 801 | config.export_mode = 'smoothie' 802 | elseif config.export_mode == 'smoothie' then 803 | notify(config.dur, "[K] EXPORT MODE: ffmpeg") 804 | config.export_mode = 'ffmpeg' 805 | else 806 | notify(config.dur, "unknown export mode '" .. config.export_mode .. "' falling back to ffmpeg") 807 | config.export_mode = 'ffmpeg' 808 | end 809 | end; mp.add_key_binding("K", "toggleExportModes", cycleExportModes) 810 | 811 | 812 | local function toggleVerb() 813 | if config.verbose == true then 814 | notify(config.dur, "[Ctrl+v] toggled off Verbose") 815 | config.verbose = false 816 | elseif config.verbose == false then 817 | notify(config.dur, "[Ctrl+v] toggled on Verbose") 818 | config.verbose = true 819 | end 820 | end; mp.add_key_binding("Ctrl+v", "toggleSLCverbose", toggleVerb) 821 | --------------------------------------------------------------------------------