diff --git a/COPYING.txt b/COPYING.txt
new file mode 100644
index 0000000..f288702
--- /dev/null
+++ b/COPYING.txt
@@ -0,0 +1,674 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc.
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The GNU General Public License is a free, copyleft license for
+software and other kinds of works.
+
+ The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works. By contrast,
+the GNU General Public License is intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users. We, the Free Software Foundation, use the
+GNU General Public License for most of our software; it applies also to
+any other work released this way by its authors. You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+ To protect your rights, we need to prevent others from denying you
+these rights or asking you to surrender the rights. Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received. You must make sure that they, too, receive
+or can get the source code. And you must show them these terms so they
+know their rights.
+
+ Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
+
+ For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software. For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
+
+ Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so. This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software. The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable. Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products. If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+ Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary. To prevent this, the GPL assures that
+patents cannot be used to render the program non-free.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ TERMS AND CONDITIONS
+
+ 0. Definitions.
+
+ "This License" refers to version 3 of the GNU General Public License.
+
+ "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+ "The Program" refers to any copyrightable work licensed under this
+License. Each licensee is addressed as "you". "Licensees" and
+"recipients" may be individuals or organizations.
+
+ To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy. The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+ A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+ To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy. Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+ To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies. Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+ An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License. If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+ 1. Source Code.
+
+ The "source code" for a work means the preferred form of the work
+for making modifications to it. "Object code" means any non-source
+form of a work.
+
+ A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+ The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form. A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+ The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities. However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work. For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+ The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+ The Corresponding Source for a work in source code form is that
+same work.
+
+ 2. Basic Permissions.
+
+ All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met. This License explicitly affirms your unlimited
+permission to run the unmodified Program. The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work. This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+ You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force. You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright. Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+ Conveying under any other circumstances is permitted solely under
+the conditions stated below. Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+ No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+ When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+ 4. Conveying Verbatim Copies.
+
+ You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+ You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+ 5. Conveying Modified Source Versions.
+
+ You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+ a) The work must carry prominent notices stating that you modified
+ it, and giving a relevant date.
+
+ b) The work must carry prominent notices stating that it is
+ released under this License and any conditions added under section
+ 7. This requirement modifies the requirement in section 4 to
+ "keep intact all notices".
+
+ c) You must license the entire work, as a whole, under this
+ License to anyone who comes into possession of a copy. This
+ License will therefore apply, along with any applicable section 7
+ additional terms, to the whole of the work, and all its parts,
+ regardless of how they are packaged. This License gives no
+ permission to license the work in any other way, but it does not
+ invalidate such permission if you have separately received it.
+
+ d) If the work has interactive user interfaces, each must display
+ Appropriate Legal Notices; however, if the Program has interactive
+ interfaces that do not display Appropriate Legal Notices, your
+ work need not make them do so.
+
+ A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit. Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+ 6. Conveying Non-Source Forms.
+
+ You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+ a) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by the
+ Corresponding Source fixed on a durable physical medium
+ customarily used for software interchange.
+
+ b) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by a
+ written offer, valid for at least three years and valid for as
+ long as you offer spare parts or customer support for that product
+ model, to give anyone who possesses the object code either (1) a
+ copy of the Corresponding Source for all the software in the
+ product that is covered by this License, on a durable physical
+ medium customarily used for software interchange, for a price no
+ more than your reasonable cost of physically performing this
+ conveying of source, or (2) access to copy the
+ Corresponding Source from a network server at no charge.
+
+ c) Convey individual copies of the object code with a copy of the
+ written offer to provide the Corresponding Source. This
+ alternative is allowed only occasionally and noncommercially, and
+ only if you received the object code with such an offer, in accord
+ with subsection 6b.
+
+ d) Convey the object code by offering access from a designated
+ place (gratis or for a charge), and offer equivalent access to the
+ Corresponding Source in the same way through the same place at no
+ further charge. You need not require recipients to copy the
+ Corresponding Source along with the object code. If the place to
+ copy the object code is a network server, the Corresponding Source
+ may be on a different server (operated by you or a third party)
+ that supports equivalent copying facilities, provided you maintain
+ clear directions next to the object code saying where to find the
+ Corresponding Source. Regardless of what server hosts the
+ Corresponding Source, you remain obligated to ensure that it is
+ available for as long as needed to satisfy these requirements.
+
+ e) Convey the object code using peer-to-peer transmission, provided
+ you inform other peers where the object code and Corresponding
+ Source of the work are being offered to the general public at no
+ charge under subsection 6d.
+
+ A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+ A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling. In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage. For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product. A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+ "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source. The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+ If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information. But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+ The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed. Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+ Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+ 7. Additional Terms.
+
+ "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law. If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+ When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it. (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.) You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+ Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+ a) Disclaiming warranty or limiting liability differently from the
+ terms of sections 15 and 16 of this License; or
+
+ b) Requiring preservation of specified reasonable legal notices or
+ author attributions in that material or in the Appropriate Legal
+ Notices displayed by works containing it; or
+
+ c) Prohibiting misrepresentation of the origin of that material, or
+ requiring that modified versions of such material be marked in
+ reasonable ways as different from the original version; or
+
+ d) Limiting the use for publicity purposes of names of licensors or
+ authors of the material; or
+
+ e) Declining to grant rights under trademark law for use of some
+ trade names, trademarks, or service marks; or
+
+ f) Requiring indemnification of licensors and authors of that
+ material by anyone who conveys the material (or modified versions of
+ it) with contractual assumptions of liability to the recipient, for
+ any liability that these contractual assumptions directly impose on
+ those licensors and authors.
+
+ All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10. If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term. If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+ If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+ Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+ 8. Termination.
+
+ You may not propagate or modify a covered work except as expressly
+provided under this License. Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+ However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+ Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+ Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License. If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+ 9. Acceptance Not Required for Having Copies.
+
+ You are not required to accept this License in order to receive or
+run a copy of the Program. Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance. However,
+nothing other than this License grants you permission to propagate or
+modify any covered work. These actions infringe copyright if you do
+not accept this License. Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+ 10. Automatic Licensing of Downstream Recipients.
+
+ Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License. You are not responsible
+for enforcing compliance by third parties with this License.
+
+ An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations. If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+ You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License. For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+ 11. Patents.
+
+ A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based. The
+work thus licensed is called the contributor's "contributor version".
+
+ A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version. For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+ In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement). To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+ If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients. "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+ If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+ A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License. You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+ Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+ 12. No Surrender of Others' Freedom.
+
+ If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all. For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+ 13. Use with the GNU Affero General Public License.
+
+ Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU Affero General Public License into a single
+combined work, and to convey the resulting work. The terms of this
+License will continue to apply to the part which is the covered work,
+but the special requirements of the GNU Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
+
+ 14. Revised Versions of this License.
+
+ The Free Software Foundation may publish revised and/or new versions of
+the GNU General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Program specifies that a certain numbered version of the GNU General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation. If the Program does not specify a version number of the
+GNU General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+ If the Program specifies that a proxy can decide which future
+versions of the GNU General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+ Later license versions may give you additional or different
+permissions. However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+ 15. Disclaimer of Warranty.
+
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. Limitation of Liability.
+
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+ 17. Interpretation of Sections 15 and 16.
+
+ If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+
+ Copyright (C)
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+
+Also add information on how to contact you by electronic and paper mail.
+
+ If the program does terminal interaction, make it output a short
+notice like this when it starts in an interactive mode:
+
+ Copyright (C)
+ This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, your program's commands
+might be different; for a GUI interface, you would use an "about box".
+
+ You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU GPL, see
+.
+
+ The GNU General Public License does not permit incorporating your program
+into proprietary programs. If your program is a subroutine library, you
+may consider it more useful to permit linking proprietary applications with
+the library. If this is what you want to do, use the GNU Lesser General
+Public License instead of this License. But first, please read
+.
diff --git a/INSTALL.md b/INSTALL.md
deleted file mode 100644
index 3df433c..0000000
--- a/INSTALL.md
+++ /dev/null
@@ -1,4 +0,0 @@
-Simple. Just move the "shelltube" script along with
-the scripts in lib/ into your PATH.
-Then-- boom, installed.
-Groovy.
diff --git a/LICENSE b/LICENSE
deleted file mode 100644
index 1a18582..0000000
--- a/LICENSE
+++ /dev/null
@@ -1,13 +0,0 @@
-Copyright (c) 2017, Jade Levesque
-
-Permission to use, copy, modify, and/or distribute this software for any
-purpose with or without fee is hereby granted, provided that the above
-copyright notice and this permission notice appear in all copies.
-
-THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
diff --git a/Makefile b/Makefile
deleted file mode 100644
index 93e4443..0000000
--- a/Makefile
+++ /dev/null
@@ -1,3 +0,0 @@
-PREFIX=/usr/local
-install:
- install -m 0755 shelltube lib/* $(PREFIX)/bin/
diff --git a/README.md b/README.md
deleted file mode 100644
index 6d9c34b..0000000
--- a/README.md
+++ /dev/null
@@ -1,102 +0,0 @@
-![Shelltube](https://cloud.githubusercontent.com/assets/7250745/21452795/52fcd6ea-c901-11e6-871b-bd646f2d7c49.png)
-
-shellTube is a collection of (pretty POSIX) shell scripts to
-browse YouTube quickly, efficiently, and without the bloat
-most command-line clients require.
-
-shellTube is written in pure shell; its only dependencies
-are any modern shell (pdksh, bash, zsh), curl/wget, and
-vlc/mplayer/kaffeine.
-
-Even these dependencies, though, can easily be changed. If,
-for example, you don't have vlc, you can just modify a
-single line and be good-to-go using another player.
-
-Also, shellTube doesn't use the YouTube API at all. This
-avoids the annoying red-tapey stuff that goes with it -- IDs,
-registration, quotas -- but has some disadvantages. We'll
-power through the downsides, though! :)
-
-
-Usage
--------
-shellTube is quite simple to use; this tutorial will go over
-the usage of the wrapper script, `shelltube`.
-When running the script, you'll see a prompt:
-
-```
- >>
-```
-
-In this prompt you can type any of the following commands:
-
-| (short) command syntax | description |
-| --- | --- |
-| (`!`) `about` | View the about page. |
-| (`cls`) `clear` | Clear the screen. |
-| (`dl`) `download [URL] ` | Download the selected/specified video. |
-| `exit` | Exit Shelltube. |
-| (`?`) `help` | Display this message. |
-| (`md`) `metadata [URL]` | Display selected/specified video's metadata. |
-| (`//`) `playlist URL` `playlist ID` | View playlist based on `URL` or `ID`. |
-| (`/`) `search TERM` | Perform a search for `TERM`. |
-| (`str`) `stream [URL]` | Stream the selected/specified video. |
-| (`sel`) `video URL` `video ID` | Select video based on `URL` or `ID`. |
-| (`lq`) `queue` | Lists all videos in the queue. |
-| (`sq`) `squeue` | Streams all videos in the queue. |
-| (`dq`) `dqueue` | Downloads all videos in the queue. |
-
-In [brackets], optional arguments are written.
-
-You can use shellTube in one of two ways (or both):
-
-1. By selecting a video and then doing something with it
-2. By doing something and specifying the video
-
-Method A entails using either the `video` or `search`
-command to select a video, which will then be displayed
-before the prompt like so:
-
-```
-$VIDEO-ID-HERE >>
-```
-
-When a video is selected, you use the `download`, `stream`,
-or `metadata` commands without arguments to act on the
-video.
-
-Method B entails just using the `download`, `stream`, or
-`metadata` commands while using a URL or video ID as an
-argument.
-
-For example:
-
-```
- >> download $VIDEO-ID-HERE
-```
-
-You can also download or stream multiple videos in a row
-without user input with the queue.
-The queue is a list of video IDs in the file `/tmp/yt-queue`
-You can add to the queue manually or while looking at
-search results, playlist videos, or channel videos by inputting
-`*` rather than a number when prompted. This adds every video
-listed to the queue.
-When you're back at the main prompt, you can enter `lq`, `dq`,
-or `sq` to list, download, or stream the queued videos.
-
-You could opt to not use this interactive wrapper script and
-instead just use the `yt-down`, `yt-search`, and
-`yt-metadata` scripts on their own.
-
-They are each pretty simple, and you can read their USAGE
-messages at the top of each script.
-
-
-Licensing
------------
-All of ST is released under the
-[ISC](https://opensource.org/licenses/ISC) license.
-
-Except for the `y-down` script, which is released under the
-[GPLv2](https://www.gnu.org/licenses/gpl-2.0.html).
diff --git a/README.txt b/README.txt
new file mode 100644
index 0000000..7c4efda
--- /dev/null
+++ b/README.txt
@@ -0,0 +1,64 @@
+===============================================================================
+SHELLTUBE Shell scripts for easy YT-browsing
+===============================================================================
+shelltube will be a collection of (pretty POSIX) shell scripts to
+browse YouTube quickly, and entirely without captive UIs.
+Right now, there's only one script, yt-search
+
+shelltube is written in pure shell; its only dependencies
+are any modern shell (pdksh, bash, zsh) and curl/wget/ftp.
+Your terminal should accept ANSI color-codes, too~
+
+Before, shelltube was a set of scripts that culimated in a wrapper
+script for browsing Youtube (like mpsyt). You could even download
+videos from YT in pure shell! But, now, all videos require JS execution
+to download (as far as I can tell), so it stopped working.
+
+Now I'm refocusing a bit, ditching the wrapper script (begone, captive UIs,
+ye spectre of ole!), and starting from scratch. :)
+
+
+
+----------------------------------------
+USAGE
+----------------------------------------
+There is one script that makes up shelltube:
+ * yt-search
+
+yt-search lists videos matching a certain search query.
+ USAGE: yt-search [-csmb] query
+
+Each option [-csmb] represents a different format-method.
+ -b big TITLE \n DURATION | VIEWS | URL
+ -m medium TITLE | DURATION | URL
+ -s small TITLE | URL
+ -c compact TITLE | ID
+
+Big takes up two lines, while the rest only use one.
+If you're piping output, you might wanna usa -m, -s, or -c.
+
+
+
+There is another script that comes with shelltube (which it uses
+extensively:
+ * gendl
+
+gendl can download files on a system that has at least one of these:
+ * ftp
+ * wget
+ * curl
+
+... to stdout or to a file.
+
+yt-search uses gendl--
+so make sure they're both in the same directory (or, at least, that
+gendl is in your $PATH)
+
+
+
+----------------------------------------
+BORING STUFF
+----------------------------------------
+License is in COPYING.txt (GNU GPLv3~! <3)
+Author is Jenga Phoenix
+Sauce is at https://git.eunichx.us/shelltube
diff --git a/TODO.txt b/TODO.txt
new file mode 100644
index 0000000..6057ea2
--- /dev/null
+++ b/TODO.txt
@@ -0,0 +1,44 @@
+At some point in time, this SHOULD be the readme. It isn't right now, obviously.
+
+===============================================================================
+SHELLTUBE Shell scripts for easy YT-browsing
+===============================================================================
+shelltube is a collection of (pretty POSIX) shell scripts to
+browse YouTube quickly, and entirely without captive UIs.
+
+shellTube is written in pure shell; its only dependencies
+are any modern shell (pdksh, bash, zsh) and curl/wget/ftp.
+Your terminal should accept ANSI color-codes, too~
+
+
+
+----------------------------------------
+USAGE
+----------------------------------------
+There are three different scripts that make up shelltube:
+ * yt-search
+ * yt-channel
+ * yt-meta
+
+In all three scripts:
+ 'index' means what page of results you're on--
+ 'results' means how many of them will be displayed.
+
+yt-search lists videos matching a certain search query.
+ USAGE: yt-search [-i index] [-r results] query
+
+
+yt-channel lists the videos of a given channel.
+ USAGE: yt-channel [-i index] [-r results] URL/ID/name
+
+yt-meta lists the metadata of a given video
+ USAGE: yt-meta URL/ID
+
+
+
+----------------------------------------
+BORING STUFF
+----------------------------------------
+License is in COPYING.txt (GNU GPLv3~! <3)
+Author is Jenga Phoenix
+Sauce is at https://git.eunichx.us/shelltube
diff --git a/gendl b/gendl
new file mode 100755
index 0000000..0aa0043
--- /dev/null
+++ b/gendl
@@ -0,0 +1,155 @@
+#!/bin/sh
+##############################
+# name: gendl
+# lisc: gnu gplv3
+# desc: download to stdout or
+# file, independent of
+# a specific downloader.
+# ftp/wget/curl support.
+# main: jadedctrl
+##############################
+
+# usage: gendl [-o output] url
+
+
+
+#---------------------------------------
+# backend bits
+
+# NIL --> STRING
+# return the download program you're using
+function download_program
+{
+ programs="ftp curl wget"
+ current=""
+
+ for program in $programs
+ do
+ if whereis $program > /dev/null
+ then
+ current=$program
+ fi
+ done
+
+ if uname -s | grep -e "LibertyBSD" -e "OpenBSD" > /dev/null
+ then
+ current="ftp"
+ fi
+
+ echo "$current"
+}
+
+# STRING PATH --> NIL
+# download URL $1 to stdout
+function download_stdout
+{
+ program=$(download_program)
+ url=$1
+
+ case "$program" in
+ "ftp")
+ output="$(ftp -VMo- $url)"
+ ;;
+ "curl")
+ output="$(curl $url)"
+ ;;
+ "wget")
+ output="$(wget --quiet -O $url)"
+ ;;
+ esac
+
+ return_code=$?
+
+ echo "$output"
+ return $return_code
+}
+
+# STRING PATH --> NIL
+# download URL $1 to path $2
+function download_file
+{
+ program=$(download_program)
+ url=$1
+ path=$2
+
+ case "$program" in
+ "ftp")
+ ftp -VMU "." -o $path $url
+ ;;
+ "curl")
+ curl -o $path $url
+ ;;
+ "wget")
+ wget --quiet -O $path $url
+ ;;
+ esac
+
+ return_code=$?
+
+ if test $return_code -ne 0
+ then
+ rm $path 2> /dev/null
+ # for consistency in behavior; wget saves 404s anyway, whereas
+ # ftp doesn't save anything from 404s, etc.
+ fi
+
+ return $return_code
+}
+
+
+
+# --------------------------------------
+# front-end string-manip
+
+# STRING --> STRING
+# return the last word in a string
+function last_word
+{
+ string="$1"
+
+ echo "$string" \
+ | rev \
+ | sed 's% .*%%' \
+ | rev
+}
+
+function usage
+{
+ echo "usage: gendl [-o output] URL"
+}
+
+
+
+# --------------------------------------
+# invocation
+
+args="$(getopt o: $*)"
+if test $? -ne 0 || test -z "$@"
+then
+ usage
+ exit 2
+fi
+
+
+set -- $args
+while test $# -ne 0
+do
+ case "$1"
+ in
+ -o)
+ download_path="$2"; shift; shift;;
+ --)
+ shift; break;;
+ esac
+done
+
+
+url="$(last_word "$@")"
+
+
+if test -n "$download_path"
+then
+ download_file $url $download_path
+else
+ download_stdout "$url"
+fi
diff --git a/lib/st-download b/lib/st-download
deleted file mode 100755
index fe4a98e..0000000
--- a/lib/st-download
+++ /dev/null
@@ -1,23 +0,0 @@
-#!/bin/sh
-#####################
-# Name: st-download.sh
-# Lisc: ISC
-# Main: jadedctrl
-# Desc: No beer and no TV
-# make Homer go
-# something-something
-# Cxu ne?
-#####################
-
-if test -z "$download_cmd"
-then
- if command -v wget > /dev/null
- then
- wget -q "$1" -O "$2"
- elif command -v curl > /dev/null
- then
- curl -s "$1" -o "$2"
- fi
-else
- $download_cmd
-fi
diff --git a/lib/st-video b/lib/st-video
deleted file mode 100755
index f7933d2..0000000
--- a/lib/st-video
+++ /dev/null
@@ -1,28 +0,0 @@
-#!/bin/sh
-#####################
-# Name: st-video.sh
-# Date: 2016-12-22
-# Lisc: ISC
-# Main: jadedctrl
-# Desc: Does a thing with
-# a video-thingy thing
-# dsfgbvesrht fd
-#####################
-
-if [ -e "$HOME/.config/shelltube" ]
-then
- . "$HOME/.config/shelltube"
-fi
-
-if test -z "$player_cmd"
-then
- if command -v vlc > /dev/null
- then
- vlc --play-and-exit "${1}"
- elif command -v mplayer > /dev/null
- then
- mplayer --quiet "${1}"
- fi
-else
- $player_cmd "${1}"
-fi
diff --git a/lib/yt-channel b/lib/yt-channel
deleted file mode 100755
index 7a36b59..0000000
--- a/lib/yt-channel
+++ /dev/null
@@ -1,191 +0,0 @@
-#!/bin/sh
-#####################
-# Name: yt-channel.sh
-# Lisc: ISC
-# Main: jadedctrl
-# Desc: Display a channel's videos
-# or details in easy-to-read
-# and easy-to-parse results.
-#####################
-
-# Usage: yt-channel.sh [-uci] userid||channel
-
-if [ -e "$HOME/.config/shelltube" ]
-then
- . "$HOME/.config/shelltube"
-else
- results=21
-fi
-
-if [ -e "./lib/yt-meta" ]
-then
- alias yt-channel="./lib/yt-channel"
- alias yt-search="./lib/yt-down"
- alias yt-meta="./lib/yt-meta"
- alias yt-search="./lib/yt-search"
- alias yt-down="./lib/yt-channel"
- alias st-download="./lib/st-download"
- alias st-video="./lib/st-video"
-fi
-
-interactive_mode=0
-channel_file="/tmp/$(mktemp -u yt-channel_XXXXXX)"
-
-# I really need to work out a better way to take flags.
-# This is just awful.
-# ... I'll cross that bridge later.
-
-
-if [ "$1" = "-u" ]
-then
- type="user"
- st-download "https://youtube.com/user/$2/videos" "$channel_file"
-elif [ "$1" = "-iu" ]
-then
- output="$3"
- interactive_mode=1
- type="user"
- st-download "https://youtube.com/user/$2/videos" "$channel_file"
-elif [ "$1" = "-c" ]
-then
- type="channel"
- st-download "https://youtube.com/channel/$2/videos" "$channel_file"
-elif [ "$1" = "-ic" ]
-then
- output="$3"
- interactive_mode=1
- type="channel"
- st-download "https://youtube.com/channel/$2/videos" "$channel_file"
-elif [ "$1" = "-uc" ] || [ -k "$2" ]
-then
- echo "Usage: yt-channel.sh [-uci] userid||channel [output]"
- echo "Make sure to use either the -u flag or the -c flag--"
- echo "*not* both! Also, specify a userid or channel name."
- exit 1
-else
- echo "Usage: yt-channel.sh [-uc] userid||channel"
- exit 1
-fi
-
-get_input() {
- printf '\033[0;32m>>>\033[0m '
- read -r n
-
- if [ "$n" = "exit" ]
- then
- exit
- fi
- if [ "$n" == "*" ]
- then
- cat $temp_file | while IFS='' read -r CUR_LINE
- do
- echo "$CUR_LINE" | sed 's/.*href="\/watch?v=//' | sed 's/".*//' >> $output
- done
- cp $output /tmp/yt-queue
-# test $n -ge 0
- elif [ $? -gt 1 ]
- then
- echo "Bad input, mate. Type in a valid number or 'exit'."
- get_input
- elif [ $n -gt 20 ]
- then
- echo "Out of range. Type in a valid number or 'exit'."
- get_input
- elif [ $n -gt 0 ] && [ $n -lt 20 ]
- then
- sed -n "${n}p" "$temp_file" | sed 's/.*href="\/watch?v=//' | sed 's/".*//' > "$output"
- else
- echo "Bad input, mate. Type in a valid number or 'exit'."
- get_input
- fi
-}
-
-
-row=0
-
-# Now for displaying the search results
-temp_file="/tmp/$(mktemp -u yt-channel_XXXXXX)"
-
-grep "href=\"\/watch?v=" "$channel_file" | grep "title=" | grep -v \
- " "$temp_file"
-item_num=0
-cat "$temp_file" | while IFS='' read -r CUR_LINE
-do
- item_num=$((item_num+1))
- LINE="$(echo "$CUR_LINE" | sed 's/.*//')"
- LINE="$(echo "$LINE" | sed 's/views<\/li>.*//')"
- LINE="$(echo "$LINE" | sed 's/title="Verified"//')"
-
- if [ $row -eq 1 ]
- then
- #color='\033[1;34m'
- #color2='\033[1;34m'
- printf '\033[1;34m'
- row=0
- elif [ $row -eq 0 ]
- then
- #color='\033[1;31m'
- #color2='\033[1;31m'
- printf '\033[1;31m'
- row=1
- fi
-
- if echo "$LINE" | grep "View full playlist" > /dev/null
- then
- type="Playlist"
- title=$(echo "$LINE" | sed 's/.*title="//' | sed 's/".*//')
- items=$(echo "$LINE" | sed 's/.*View full playlist (//' | sed 's/).*//')
- if [ $item_num -ge $((results+1)) ]
- then
- break
- elif [ $item_num -lt 10 ]
- then
- printf '%s. ' "$item_num"
- else
- printf '%s. ' "$item_num"
- fi
- printf '%s' "$title"
- printf ' '
- printf '%s | %s' "$type" "$items"
- printf ' '
- else
- type="Video"
- duration=$(echo "$LINE" | sed 's/.*Duration: //' | sed 's/\..*//')
- itemid=$(echo "$LINE" | sed 's/.*href="\/watch?v=//' | sed 's/".*//')
- title=$(echo "$LINE" | sed 's/.* title="//' | sed 's/".*//')
-
- if [ $item_num -ge $((results+1)) ]
- then
- break
- elif [ $item_num -lt 10 ]
- then
- printf '%s. ' "$item_num"
- else
- printf '%s. ' "$item_num"
- fi
- echo "$title"
- printf ' '
- i=0
- while [ $i -lt 9 ]
- do
- i=$((i+1))
- char=$(echo "$duration" | cut -c$i)
- if [ -z "$char" ]
- then
- printf ' '
- else
- printf '%s' "$char"
- fi
- done
- printf ' | %s\n' "$itemid"
- fi
-done
-
-if [ $interactive_mode -eq 1 ]
-then
- get_input
-fi
-
-printf '\033[0m'
-
-rm "$temp_file"
diff --git a/lib/yt-down b/lib/yt-down
deleted file mode 100755
index b1fb632..0000000
--- a/lib/yt-down
+++ /dev/null
@@ -1,140 +0,0 @@
-#!/bin/sh
-#####################
-# Name: yt-down
-# Lisc: GPLv2
-# Auth: iluaster
-# Main: jadedctrl
-# Desc: Fetches YT videos.
-#####################
-
-# Based on https://github.com/iluaster/Youtube_downloader
-
-# Usage: yt-down -[sSD] $video_id
-# -s for stream; -S for stream and skip prompt;
-# -D for download and skip prompt; No arg for download.
-
-
-if [ "$1" = "-s" ]
-then
- stream_mode=1
- id=$2
-elif [ "$1" = "-S" ]
-then
- stream_mode=1
- skip_prompt=1
- id=$2
-elif [ "$1" = "-D" ]
-then
- stream_mode=0
- skip_prompt=1
- id=$2
-else
- stream_mode=0
- id=$1
-fi
-
-if [ -e "./lib/yt-meta" ]
-then
- alias yt-channel="./lib/yt-channel"
- alias yt-search="./lib/yt-down"
- alias yt-meta="./lib/yt-meta"
- alias yt-search="./lib/yt-search"
- alias yt-down="./lib/yt-channel"
- alias st-download="./lib/st-download"
- alias st-video="./lib/st-video"
-fi
-
-
-if echo "$id" | grep "youtube.com"
-then
- id="$(echo "$id" | sed 's/.*video_id=//')"
-elif [ -z "$id" ]
-then
- echo "No video specified."
- exit 1
-else
- id="$id"
-fi
-
-name="http://www.youtube.com/get_video_info?video_id=$id"
-
-declare -i line=0 2> /dev/null
-
-if $? 2> /dev/null
-then
- echo > /dev/null
-else
- line=0
-fi
-
-select_option ()
-{
- echo "Formats:"
- cat /tmp/video_type_option.txt | while IFS='' read -r i
- do
- line=$((line+1))
- # Replace this pipe method so $line isn't lost
- echo "${line}. $i"
- done
- if [ $skip_prompt -eq 0 ]
- then
- printf '\033[0;32m>>>\033[0m '
- IFS=''
- read -r n
- else
- n=1
- fi
-
- if [ $n -le 5 ];
- then
- head -n "$n" /tmp/tmp3.txt | tail -n 1 > /tmp/tmp4.txt
- else
- echo "$line $n"
- echo "Input Error!"
- line=0
- select_option
- fi
-}
-
-
-st-download "$name" "/tmp/${id}_url.txt"
-
-# Cut and filter mp4 url
-
-cp "/tmp/${id}_url.txt" /tmp/tmp2.txt
-sed -e 's/&/\n/g' /tmp/tmp2.txt| grep 'url_encoded_fmt_stream_map'> /tmp/tmp3.txt
-sed -i -e 's/%2C/,/g' /tmp/tmp3.txt
-sed -i -e 's/,/\n/g' /tmp/tmp3.txt
-
-# Print out total video format name and quality
-perl -ne 'print "$2,$1\n" if /quality%3D(.*?)%.*video%252F(.*?)(%|\n)/' /tmp/tmp3.txt > /tmp/video_type_option.txt
-
-# If video format name is prior to quality
-perl -ne 'print "$1,$2\n" if /video%252F(.*?)%.*quality%3D(.*?)(%|\n)/' /tmp/tmp3.txt >> /tmp/video_type_option.txt
-sed -i -e 's/x-flv/flv/g' /tmp/video_type_option.txt
-
-select_option
-
-# Set file extension name variable and video quality variable
-extension_name=$(head -n "$n" /tmp/video_type_option.txt | tail -n 1 | cut -d "," -f 1)
-quality_name=$(head -n "$n" /tmp/video_type_option.txt | tail -n 1 | cut -d "," -f 2)
-
-sed -i -e 's/%26/\&/g' /tmp/tmp4.txt
-sed -i -e 's/&/\n/g' /tmp/tmp4.txt
-grep 'http' /tmp/tmp4.txt > /tmp/tmp5.txt
-grep 'sig%3D' /tmp/tmp4.txt >> /tmp/tmp5.txt
-perl -pe 's/\n//g' /tmp/tmp5.txt | sed -e 's/sig%3D/\&signature%3D/g' > /tmp/tmp6.txt
-sed -i -e 's/url%3D//g' /tmp/tmp6.txt
-# url decoding
-cat /tmp/tmp6.txt | sed -e 's/%25/%/g' -e 's/%25/%/g' -e 's/%3A/:/g' -e 's/%2F/\//g' -e 's/%3F/\?/g' -e 's/%3D/=/g' -e 's/%26/\&/g' > /tmp/tmp7.txt
-
-
-if [ $stream_mode -eq 1 ]
-then
- st-video "$(cat /tmp/tmp7.txt)"
-else
- st-download "$(cat /tmp/tmp7.txt)" "${id}_${quality_name}.${extension_name}"
-fi
-
-
-rm -f /tmp/tmp[2-7].txt "/tmp/${id}_url.txt" /tmp/video_type_option.txt
diff --git a/lib/yt-meta b/lib/yt-meta
deleted file mode 100755
index 9f4d9fd..0000000
--- a/lib/yt-meta
+++ /dev/null
@@ -1,117 +0,0 @@
-#!/bin/sh
-
-#####################
-# Name: yt-meta.sh
-# Date: 2016-12-10
-# Lisc: ISC
-# Main: jadedctrl
-# Desc: Fetches metadata about
-# a specific YT video.
-#####################
-
-# Usage: yt-meta.sh $video_id
-
-optnum=0
-
-for argument in $@
-do
- if echo $argument | grep "^-" > /dev/null
- then
- charcount=$(echo "$argument" | echo "$(wc -c) - 1" | bc)
- while [ $charcount -gt 0 ]
- do
- character=$(echo "$argument" | head -c1)
- argument=$(echo "$argument" | sed 's/^.//')
- case $character in
- c)
- options="$options c"
- optnum=$((optnum+1)) ;;
- d) # duration
- options="$options d"
- optnum=$((optnum+1)) ;;
- D) # date
- options="$options D"
- optnum=$((optnum+1)) ;;
- v)
- options="$options v"
- optnum=$((optnum+1)) ;;
- t)
- options="$options t"
- optnum=$((optnum+1)) ;;
- i)
- options="$options i"
- optnum=$((optnum+1)) ;;
- -) ;;
- esac
- charcount=$((charcount-1))
- done
- else
- preid="$argument"
- fi
-done
-
-
-if echo "$preid" | grep "youtube.com" > /dev/null
-then
- id="$(echo $preid | sed 's/.*v=//')"
-elif [ -z $preid ]
-then
- echo "No video specified."
- exit 1
-else
- id="$preid"
-fi
-
-if [ -e "./lib/yt-meta" ]
-then
- alias yt-channel="./lib/yt-channel"
- alias yt-search="./lib/yt-down"
- alias yt-meta="./lib/yt-meta"
- alias yt-search="./lib/yt-search"
- alias yt-down="./lib/yt-channel"
- alias st-download="./lib/st-download"
- alias st-video="./lib/st-video"
-fi
-
-
-video_file="/tmp/$(mktemp -u yt-video_XXXXXX)"
-if type "wget" &> /dev/null
-then
- wget -q https://youtube.com/watch?v=$id -O $video_file
- wget -q https://youtube.com/results?search_query=$id -O $video_file.1
-elif type "curl" &> /dev/null
-then
- curl -s https://youtube.com/watch?v=$id -o $video_file
- curl -s https://youtube.com/results?search_query=$id -o $video_file.1
-fi
-
-# Now for displaying the metadata
-title="$(grep "\"title\":\"" $video_file | sed 's/.*"title":"//' | sed 's/".*//')"
-author="$(grep "\"author\":\"" $video_file | sed 's/.*"author":"//' | sed 's/".*//')"
-views="$(grep "\"view_count\":\"" $video_file | sed 's/.*"view_count":"//' | sed 's/".*//')"
-duration="$(grep ">>\033[0m '
- read -r n
-
- if [ "$n" == "exit" ]
- then
- exit
- fi
-
- if [ "$n" == "*" ]
- then
- cat $temp_file | while IFS='' read -r CUR_LINE
- do
- echo $CUR_LINE | sed 's/.*data-video-id="//' | sed 's/".*//' >> $output
- cp $output /tmp/yt-queue
- done
-# test $n -ge 0 &> /dev/null
- elif [ $? -gt 1 ]
- then
- echo "Bad input, mate. Type in a valid number or 'exit'."
- get_input
- elif [ $n -gt 20 ]
- then
- echo "Out of range. Type in a valid number or 'exit'."
- get_input
- elif [ $n -gt 0 ] && [ $n -lt 20 ]
- then
- sed -n ${n}p $temp_file | sed 's/.*data-video-id="//' | sed 's/".*//' > $output
- else
- echo "Bad input, mate. Type in a valid number or 'exit'."
- get_input
- fi
-}
-
-# If Google adds any extra features or changes the webpage
-# layout, this script'll break immediately, haha.
-# ... But at least we aren't using their API, right?
-
-plist_file="/tmp/$(mktemp -u yt-search_XXXXXX)"
-
-st-download https://youtube.com/playlist?list=$plist $plist_file
-
-# Now for displaying the search results
-temp_file="/tmp/$(mktemp -u yt-result_XXXXXX)"
-grep " $temp_file
-
-item_num=0
-cat $temp_file | while IFS='' read -r CUR_LINE
-do
- item_num=$(($item_num+1))
-
- if [ $row -eq 1 ]
- then
- #color='\033[1;34m'
- #color2='\033[1;34m'
- printf '\033[1;34m'
- row=0
- elif [ $row -eq 0 ]
- then
- #color='\033[1;31m'
- #color2='\033[1;31m'
- printf '\033[1;31m'
- row=1
- fi
-
- itemid=$(echo "$CUR_LINE" | sed 's/.*data-video-id="//' | sed 's/".*//')
- title=$(echo "$CUR_LINE" | sed 's/.*data-title="//' | sed 's/".*//')
- author=$(grep -C3 " $(echo $title)" "$plist_file" | grep "by " | sed 's/.*">//' | sed 's^.*^^')
-
- if [ $item_num -ge $((results+1)) ]
- then
- break
- elif [ $item_num -lt 10 ]
- then
- printf '%s. ' "$item_num"
- else
- printf '%s. ' "$item_num"
- fi
- printf '%s\n' "$title"
- printf ' '
- i=0
- while [ $i -lt 16 ]
- do
- i=$((i+1))
- char=$(echo $author | cut -c$i)
- if [ -z $char ]
- then
- printf ' '
- else
- printf '%s' "$char"
- fi
- done
- printf ' | '
- i=0
- while [ $i -lt 5 ]
- do
- i=$((i+1))
- char=$(echo $duration | cut -c$i)
- if [ -z $char ]
- then
- printf ' '
- else
- printf '%s' "$char"
- fi
- done
- printf ' | %s\n' "$itemid"
-done
-
-printf '\033[0m'
-
-if [ $interactive_mode -eq 1 ]
-then
- get_input
-fi
diff --git a/lib/yt-search b/lib/yt-search
deleted file mode 100755
index 56ec4e8..0000000
--- a/lib/yt-search
+++ /dev/null
@@ -1,190 +0,0 @@
-#####################
-# Name: yt-result.sh
-# Date: 2016-12-10
-# Lisc: ISC
-# Main: jadedctrl
-# Desc: Search YT videos and display
-# in easy-to-read and easy-to # -parse results
-#####################
-
-# Usage: yt-search.sh "$search_string"
-
-if [ -e $HOME/.config/shelltube ]
-then
- . $HOME/.config/shelltube
-else
- results=21
-fi
-
-if [ -e "./lib/yt-meta" ]
-then
- alias yt-channel="./lib/yt-channel"
- alias yt-search="./lib/yt-down"
- alias yt-meta="./lib/yt-meta"
- alias yt-search="./lib/yt-search"
- alias yt-down="./lib/yt-channel"
- alias st-download="./lib/st-download"
- alias st-video="./lib/st-video"
-fi
-
-row=0
-
-if [ "$1" == "-i" ]
-then
- interactive_mode=1
- query="$(echo "$2" | sed 's/ /+/g')"
- output="$3"
-else
- interactive_mode=0
- query="$(echo "$1" | sed 's/ /+/g')"
-fi
-
-function get_input() {
- printf '\033[0;32m>>>\033[0m '
- read -r n
-
- if [ "$n" == "exit" ]
- then
- exit
- elif [ "$n" == "*" ]
- then
- cat $temp_file | while IFS='' read -r CUR_LINE
- do
- echo "$CUR_LINE" | sed 's/.*> $output
- done
- cp $output /tmp/yt-queue
- #test $n -ge 0 &> /dev/null
- elif [ $? -gt 1 ]
- then
- echo "Bad input, mate. Type in a valid number or 'exit'."
- get_input
- elif [ $n -gt 20 ]
- then
- echo "Out of range. Type in a valid number or 'exit'."
- get_input
- elif [ $n -gt 0 ] && [ $n -lt 20 ]
- then
- if sed -n ${n}p $temp_file | grep "View full playlist" > /dev/null
- then
- sed -n ${n}p $temp_file | sed 's/.*&list=//' | sed 's/".*//' > $output
- else
- sed -n ${n}p $temp_file | sed 's/.* $output
- fi
- else
- echo "Bad input, mate. Type in a valid number or 'exit'."
- get_input
- fi
-}
-
-# If Google adds any extra features or changes the webpage
-# layout, this script'll break immediately, haha.
-# ... But at least we aren't using their API, right?
-
-search_file="/tmp/$(mktemp -u yt-search_XXXXXX)"
-
-st-download https://youtube.com/results?search_query=$query $search_file
-
-# Now for displaying the search results
-temp_file="/tmp/$(mktemp -u yt-result_XXXXXX)"
-grep " $temp_file
-item_num=0
-cat $temp_file | while IFS='' read -r CUR_LINE
-do
- item_num=$(($item_num+1))
- # These tags trip up 'title=' and '" >' queries later on. Strip 'em.
- LINE="$(echo $CUR_LINE | sed 's/.*//')"
- LINE="$(echo $LINE | sed 's/views<\/li>.*//')"
- LINE="$(echo $LINE | sed 's/title="Verified"//')"
-
- if [ $row -eq 1 ]
- then
- #color='\033[1;34m'
- #color2='\033[1;34m'
- printf '\033[1;34m'
- row=0
- elif [ $row -eq 0 ]
- then
- #color='\033[1;31m'
- #color2='\033[1;31m'
- printf '\033[1;31m'
- row=1
- fi
-
- if echo "$LINE" | grep "View full playlist" > /dev/null
- then
- type="Playlist"
- title=$(echo "$LINE" | sed 's/.*title="//' | sed 's/".*//')
- items=$(echo "$LINE" | sed 's/.*View full playlist (//' | sed 's/).*//')
- itemid=$(echo "$LINE" | sed 's/.*&list=//' | sed 's/".*//')
- if [ $item_num -ge $((results+1)) ]
- then
- break
- elif [ $item_num -lt 10 ]
- then
- printf '%s. ' "$item_num"
- else
- printf '%s. ' "$item_num"
- fi
- printf '%s\n' "$title"
- printf ' '
- printf '%s | %s | %s\n' "$type" "$items" "$itemid"
- else
- type="Video"
- duration=$(echo "$LINE" | sed 's/.*Duration: //' | sed 's/\..*//')
- itemid=$(echo "$LINE" | sed 's/.* /dev/null
- then
- # For /channel/ users
- author=$(echo "$LINE" | sed 's/.*" >//' | sed 's/<\/a>.*//')
- else
- # For /user/ users
- author=$(echo "$LINE" | sed 's/.*\/user\///' | sed 's/".*//')
- fi
-
- if [ $item_num -ge $((results+1)) ]
- then
- break
- elif [ $item_num -lt 10 ]
- then
- printf '%s. ' "$item_num"
- else
- printf '%s. ' "$item_num"
- fi
- printf '%s\n' "$title"
- printf ' '
- i=0
- while [ $i -lt 16 ]
- do
- i=$((i+1))
- char=$(echo $author | cut -c$i)
- if [ -z $char ]
- then
- printf ' '
- else
- printf '%s' "$char"
- fi
- done
- printf ' | '
- i=0
- while [ $i -lt 5 ]
- do
- i=$((i+1))
- char=$(echo $duration | cut -c$i)
- if [ -z $char ]
- then
- printf ' '
- else
- printf '%s' "$char"
- fi
- done
- printf ' | %s\n' "$itemid"
- fi
-done
-
-printf '\033[0m'
-
-if [ $interactive_mode -eq 1 ]
-then
- get_input
-fi
diff --git a/shelltube b/shelltube
deleted file mode 100755
index d25016e..0000000
--- a/shelltube
+++ /dev/null
@@ -1,229 +0,0 @@
-#!/bin/sh
-
-####################
-# Name: shelltube.sh
-# Lisc: ISC
-# Main: jadedctrl
-# Desc: Full-shell YT client that avoids the YT API.
- Vers=0.5.2
-#####################
-
-# Roadmap 1.0:
-# yt-meta:
-# [X] Args for specific info
-# [X] Better argument handling
-# yt-playlist:
-# [X] Playlist support
-# [ ] Better argument handling
-# yt-channel:
-# [X] Channel support
-# [ ] Better argument handling
-# yt-search:
-# [|] Channel & Playlist search
-# [ ] Search filters
-# [ ] Better argument handling
-# general:
-# [|] Config video player, etc
-# [|] Cli args as commands
-
-
-if [ -e "$HOME/.config/shelltube" ]
-then
- . "$HOME/.config/shelltube"
-fi
-
-if [ -e "./lib/yt-meta" ]
-then
- alias yt-channel="./lib/yt-channel"
- alias yt-meta="./lib/yt-meta"
- alias yt-playlist="./lib/yt-playlist"
- alias yt-search="./lib/yt-search"
- alias yt-down="./lib/yt-down"
- alias st-download="./lib/st-download"
- alias st-video="./lib/st-video"
-fi
-
-search() {
- output="$(mktemp -u /tmp/yt_XXXXXX)"
- yt-search -i "$1" "$output"
- if sed -n ${1}p "$output" | grep "^PL" > /dev/null
- then
- playlist "$(sed -n ${1}p "$output")"
- else
- selected_video="$(sed -n ${1}p "$output")"
- yt-meta "$selected_video"
- fi
-}
-
-playlist() {
- output="$(mktemp -u /tmp/yt_XXXXXX)"
- yt-playlist -i "$1" "$output"
- selected_video="$(sed -n ${1}p "$output")"
- yt-meta "$selected_video"
-}
-
-channel() {
- output="$(mktemp -u /tmp/yt-channel_XXXXXX)"
- case "$1" in
- UC* )
- yt-channel -ic "$1" "$output"
- ;;
- * )
- yt-channel -iu "$1" "$output"
- ;;
- esac
- selected_video="$(sed -n 1p "$output")"
- yt-meta "$selected_video"
-}
-
-about() {
- printf '\n \033[1mshell\033[41m Tube \033[0;1;30m v%s\033[m\n\n' "$Vers"
- printf '\033[32mDesc: \033[0;34mYT client written in shell.\033[m\n'
- printf '\033[32mMain: \033[0;34mjadedml@openmailbox.org\033[m\n'
- printf '\033[32mLisc: \033[0;34mISC; yt-down GPLv2\033[m\n'
-}
-
-help() {
- printf "\
-about | ! View the about page.
-clear | cls Clear the screen.
-download | dl Download the selected video.
-exit | ctrl+c Exit Shelltube.
-help | ? Display this message.
-metadata | md Display selected video's metadata.
-playlist | // Display a playlist's videos.
-search | / Perform a search.
-channel | chan Show newest videos of a channel.
-stream | str Stream the selected video.
-video | sel | url Select video based on URL or ID.
-queue | lq List videos in the queue.
-squeue | sq Stream all videos in the queue.
-dqueue | dq Download all videos in the queue.
-
-Note about usage:
-Both 'video ID; download' and 'download ID' are valid. You don't need to
-select a video to run commands on it, but if you use metadata, download, or
-stream on an unselected video you must specify the ID or URL after the command.
-"
-}
-
-parse() {
- command="$1" argument="$2"
-
- case "$command" in
- help | '?' )
- help
- ;;
- playlist )
- playlist "$argument"
- ;;
- //* )
- playlist "${command#//}"
- ;;
- search )
- search "$argument"
- ;;
- /* )
- search "${command#/} $argument"
- ;;
- channel )
- channel "$argument"
- ;;
- chan )
- channel "$argument"
- ;;
- video | sel | url )
- case "$argument" in
- *youtube.com* )
- selected_video="$argument"
- ;;
- *)
- selected_video="$argument"
- ;;
- esac
- yt-meta "$selected_video"
- ;;
- metadata | md )
- selected_video="${argument:-$selected_video}"
- yt-meta "$selected_video"
- ;;
- download | dl )
- selected_video="${argument:-$selected_video}"
- yt-down "$selected_video"
- ;;
- stream | str )
- selected_video="${argument:-$selected_video}"
- yt-down -s "$selected_video"
- ;;
- queue | lq )
- cat /tmp/yt-queue | while IFS='' read -r CUR_LINE
- do
- if [ $row -eq 1 ]
- then
- printf '\033[1;34m%s\n' "$CUR_LINE"
- row=0
- else
- printf '\033[1;31m%s\n' "$CUR_LINE"
- row=1
- fi
- done
- ;;
- cqueue | cq )
- rm /tmp/yt-queue
- touch /tmp/yt-queue
- ;;
- dqueue | dq )
- for LINE in $(cat /tmp/yt-queue)
- do
- itemid="$(echo "$LINE" | sed 's/.*\| //')"
- echo $itemid
- sleep 3
- yt-down -D "$itemid"
- grep -v "$itemid" /tmp/yt-queue > /tmp/yt-queue.tmp
- mv /tmp/yt-queue.tmp /tmp/yt-queue
- done
- ;;
- squeue | sq )
- for LINE in $(cat /tmp/yt-queue)
- do
- itemid="$(echo "$LINE" | sed 's/.*| //')"
- echo $itemid
- sleep 3
- yt-down -S "$itemid"
- grep -v "$itemid" /tmp/yt-queue > /tmp/yt-queue.tmp
- mv /tmp/yt-queue.tmp /tmp/yt-queue
- done
- ;;
- about | ! )
- about
- ;;
- clear | cls )
- printf '\033[H\033[J'
- ;;
- exit )
- rm -f "/tmp/yt-$$"
- exit
- ;;
- '' ) ;;
- * )
- echo "Unknown command: \"$command\""
- echo "Try \"help\" or \"?\""
- ;;
- esac
-}
-
-if [ "$#" -gt 0 ]
-then
- for arg in "$@"
- do
- parse "${arg%% *}" "${arg#* }"
- done
-else
- printf '\n \033[1mshell\033[41m Tube \033[0;1;30m v%s\033[m\n\n' "$Vers"
-
- while printf '\033[0;34m%s \033[0;32m>>\033[m ' "$selected_video"
- do
- read -r command argument
- parse "$command" "$argument"
- done
-fi
diff --git a/yt-search b/yt-search
new file mode 100755
index 0000000..6f9a31b
--- /dev/null
+++ b/yt-search
@@ -0,0 +1,280 @@
+##############################
+# name: yt-search
+# lisc: gnu gplv3
+# main: jadedctrl
+# desc: search youtube simply.
+##############################
+
+# Usage: yt-search [-csmb] "$search_string"
+
+# --------------------------------------
+# a bit of math...
+
+# NUMBER NUMBER --> NUMBER
+# Well, subtraction. Y'know...
+function subtract
+{
+ local operated=$1
+ local operatee=$2
+ echo "${1}-${2}" | bc
+}
+
+
+
+# --------------------------------------
+# ... now some string manip...
+
+# NIL --> STRING
+# Print an ANSI "unbold" escape string.
+function unbold
+{
+ printf "$(tput sgr0)"
+}
+
+# STRING --> STRING
+# Print an ANSI "bold" escape string.
+function bold
+{
+ printf "$(tput bold)"
+}
+
+# STRING --> NUMBER
+# Return the length of a string
+function char_length
+{
+ subtract $(echo $1 | wc -c) 1
+}
+
+# STRING NUMBER [STRING] --> STRING
+# pad string $1 out to the minimum length $2 with padding $3 (default: "0")
+function min_string_length
+{
+ local string="$1"
+ local length=$2
+ if test -z "$3"; then
+ local padding="0"
+ else
+ local padding="$3"
+ fi
+ local new="$string"
+ if test $(char_length $1) -eq $2; then
+ echo $1
+ else
+ while test $(char_length $new) -lt $2; do
+ new="${new}${padding}"
+ done
+ echo $new
+ fi
+}
+
+# STRING NUMBER --> STRING
+# get the first $2 characters in string $1
+function char_get
+{
+ local number=$2
+ local string="$1"
+ string="$(min_string_length "$string" $number " ")"
+ echo "$string" \
+ | grep -o "^$(min_string_length "." $number ".")"
+}
+
+
+
+# --------------------------------------
+# ... now for the real deal~!
+
+# STRING --> STRING
+# Pass the raw search HTML, get raw video result-lines
+function result_lines
+{
+ local search_html="$1"
+ echo "$search_html" \
+ | grep " STRING
+# Return the video ID of a result_line.
+function result_id
+{
+ local result_line="$1"
+ echo "$result_line" \
+ | sed 's%.* STRING
+# Return the title of a result-line.
+function result_title
+{
+ local result_line="$1"
+ echo "$result_line" \
+ | sed 's%.*" title="%%' \
+ | sed 's%".*%%'
+}
+
+function result_name
+{
+ local result_line="$1"
+ local title="$(result_title "$result_line")"
+ echo "$(bold)${title}$(unbold)"
+}
+
+function result_title_backup
+{
+ local result_line="$1"
+ echo "$result_line" \
+ | sed 's%.*title="%%' \
+ | sed 's%".*%%'
+}
+
+# STRING --> STRING
+# Return the duration of a result-line.
+function result_duration
+{
+ local result_line="$1"
+ echo "$result_line" \
+ | sed 's%.*> - Duration: %%' \
+ | sed 's%\..*%%'
+}
+
+# STRING --> STRING
+# Return the .yt-lockup-meta-info of a result-line
+function result_meta_ul
+{
+ local result_line="$1"
+ echo "$result_line" \
+ | sed 's%.*.*%%'
+}
+
+# STRING --> STRING
+# Return the "Uploaded..." string of a result-line
+function result_uploaded
+{
+ local result_line="$1"
+ local result_meta_ul="$(result_meta_ul "$result_line")"
+ echo "$result_meta_ul" \
+ | sed 's%- %%' \
+ | sed 's% ago
.*%%'
+}
+
+# STRING --> NUMBER
+# Return the view-count of a result-line
+function result_views
+{
+ local result_line="$1"
+ local result_meta_ul="$(result_meta_ul "$result_line")"
+ echo "$result_meta_ul" \
+ | sed 's%.*- %%g' \
+ | sed 's% views
.*%%' \
+ | sed 's%,%%g'
+}
+
+# STRING --> STRING
+# Format a result-line into a mediumly-pretty, one-line string~
+function result_format_compact
+{
+ local result_line="$1"
+ local title="$(char_get "$(result_name "$result_line")" 40)$(unbold)"
+ local id="$(result_id "$result_line")"
+
+ echo "$name | $id"
+}
+
+# STRING --> STRING
+# Format a result-line into a mediumly-pretty, one-line string~
+function result_format_small
+{
+ local result_line="$1"
+ local name="$(char_get "$(result_name "$result_line")" 40)$(unbold)"
+ local url="$(result_url "$result_line")"
+
+ echo "$name | $url"
+}
+
+# STRING --> STRING
+# Format a result-line into a mediumly-pretty, one-line string~
+function result_format_medium
+{
+ local result_line="$1"
+ local name="$(char_get "$(result_name "$result_line")" 40)$(unbold)"
+ local duration="$(result_duration "$result_line")"
+ local url="$(result_url "$result_line")"
+
+ echo "$name | $duration | $url"
+}
+
+# STRING --> STRING
+# Format a result-line into a pretty string~
+function result_format_big
+{
+ local result_line="$1"
+ local name="$(char_get "$(result_name "$result_line")" 79)$(unbold)"
+ local duration="$(result_duration "$result_line")"
+ local uploaded="$(result_uploaded "$result_line")"
+ local views="$(result_views "$result_line")"
+ local url="$(result_url "$result_line")"
+
+ echo "$name"
+ echo "$duration | $uploaded | $views | $url"
+}
+
+
+
+# --------------------------------------
+# cushiness, ensuring valid input, etc.
+
+USAGE="usage: yt-search [-csmb] query"
+
+if test -z "$1"
+then
+ echo "$USAGE"
+ exit 2
+fi
+
+user_query="$1"
+format="big"
+
+if test -n "$2"
+then
+ user_query="$2"
+ case "$1" in
+ "-c") format="compact" ;;
+ "-s") format="small" ;;
+ "-m") format="medium" ;;
+ "-b") format="big" ;;
+ esac
+fi
+
+
+
+# --------------------------------------
+# invocation <3
+
+query="$(echo "$user_query" | sed 's/ /+/g')"
+search_html="$(./gendl "https://youtube.com/results?search_query=$query")"
+result_lines="$(result_lines "$search_html")"
+
+
+IFS='
+'
+
+for result in $result_lines
+do
+ case "$format" in
+ "compact") result_format_compact "$result" ;;
+ "small") result_format_small "$result" ;;
+ "medium") result_format_medium "$result" ;;
+ "big") result_format_big "$result" ;;
+ esac
+done