-pypo update
This commit is contained in:
parent
0d2314cf32
commit
209e8b5998
|
@ -1,6 +0,0 @@
|
|||
This tool was born out of a collaboration between Open Broadcast
|
||||
and Sourcefabric. The authors of the code are:
|
||||
|
||||
Jonas Ohrstrom <jonas@digris.ch>
|
||||
Paul Baranowski <paul.baranowski@sourcefabric.org>
|
||||
|
675
pypo/LICENSE
675
pypo/LICENSE
|
@ -1,675 +0,0 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
__all__ = ["api_client"]
|
|
@ -1,585 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
###############################################################################
|
||||
# This file holds the implementations for all the API clients.
|
||||
#
|
||||
# If you want to develop a new client, here are some suggestions:
|
||||
# Get the fetch methods working first, then the push, then the liquidsoap notifier.
|
||||
# You will probably want to create a script on your server side to automatically
|
||||
# schedule a playlist one minute from the current time.
|
||||
###############################################################################
|
||||
|
||||
import sys
|
||||
import time
|
||||
import urllib
|
||||
import logging
|
||||
from util import json
|
||||
import os
|
||||
from urlparse import urlparse
|
||||
|
||||
|
||||
def api_client_factory(config):
|
||||
if config["api_client"] == "airtime":
|
||||
return AirTimeApiClient(config)
|
||||
elif config["api_client"] == "obp":
|
||||
return ObpApiClient(config)
|
||||
else:
|
||||
print 'API Client "'+config["api_client"]+'" not supported. Please check your config file.'
|
||||
print
|
||||
sys.exit()
|
||||
|
||||
class ApiClientInterface:
|
||||
|
||||
# Implementation: optional
|
||||
#
|
||||
# Called from: beginning of all scripts
|
||||
#
|
||||
# Should exit the program if this version of pypo is not compatible with
|
||||
# 3rd party software.
|
||||
def is_server_compatible(self, verbose = True):
|
||||
pass
|
||||
|
||||
# Implementation: Required
|
||||
#
|
||||
# Called from: fetch loop
|
||||
#
|
||||
# This is the main method you need to implement when creating a new API client.
|
||||
# start and end are for testing purposes.
|
||||
# start and end are strings in the format YYYY-DD-MM-hh-mm-ss
|
||||
def get_schedule(self, start=None, end=None):
|
||||
return 0, []
|
||||
|
||||
# Implementation: Required
|
||||
#
|
||||
# Called from: fetch loop
|
||||
#
|
||||
# This downloads the media from the server.
|
||||
def get_media(self, src, dst):
|
||||
pass
|
||||
|
||||
# Implementation: optional
|
||||
#
|
||||
# Called from: push loop
|
||||
#
|
||||
# Tell server that the scheduled *playlist* has started.
|
||||
def notify_scheduled_item_start_playing(self, pkey, schedule):
|
||||
pass
|
||||
|
||||
# Implementation: optional
|
||||
# You dont actually have to implement this function for the liquidsoap playout to work.
|
||||
#
|
||||
# Called from: pypo_notify.py
|
||||
#
|
||||
# This is a callback from liquidsoap, we use this to notify about the
|
||||
# currently playing *song*. We get passed a JSON string which we handed to
|
||||
# liquidsoap in get_liquidsoap_data().
|
||||
def notify_media_item_start_playing(self, data, media_id):
|
||||
pass
|
||||
|
||||
# Implementation: optional
|
||||
# You dont actually have to implement this function for the liquidsoap playout to work.
|
||||
def generate_range_dp(self):
|
||||
pass
|
||||
|
||||
# Implementation: optional
|
||||
#
|
||||
# Called from: push loop
|
||||
#
|
||||
# Return a dict of extra info you want to pass to liquidsoap
|
||||
# You will be able to use this data in update_start_playing
|
||||
def get_liquidsoap_data(self, pkey, schedule):
|
||||
pass
|
||||
|
||||
# Put here whatever tests you want to run to make sure your API is working
|
||||
def test(self):
|
||||
pass
|
||||
|
||||
|
||||
#def get_media_type(self, playlist):
|
||||
# nil
|
||||
|
||||
################################################################################
|
||||
# Airtime API Client
|
||||
################################################################################
|
||||
|
||||
class AirTimeApiClient(ApiClientInterface):
|
||||
|
||||
def __init__(self, config):
|
||||
self.config = config
|
||||
|
||||
def __get_airtime_version(self, verbose = True):
|
||||
logger = logging.getLogger()
|
||||
url = self.config["base_url"] + self.config["api_base"] + self.config["version_url"]
|
||||
url = url.replace("%%api_key%%", self.config["api_key"])
|
||||
|
||||
try:
|
||||
logger.debug("Trying to contact %s", url)
|
||||
response = urllib.urlopen(url)
|
||||
data = response.read()
|
||||
logger.debug("Data: %s", data)
|
||||
response_json = json.read(data)
|
||||
version = response_json['version']
|
||||
logger.debug("Airtime Version %s detected", version)
|
||||
except Exception, e:
|
||||
try:
|
||||
if e[1] == 401:
|
||||
if (verbose):
|
||||
print '#####################################'
|
||||
print '# YOUR API KEY SEEMS TO BE INVALID:'
|
||||
print '# ' + self.config["api_key"]
|
||||
print '#####################################'
|
||||
return False
|
||||
except Exception, e:
|
||||
pass
|
||||
|
||||
try:
|
||||
if e[1] == 404:
|
||||
if (verbose):
|
||||
print '#####################################'
|
||||
print '# Unable to contact the Airtime-API'
|
||||
print '# ' + url
|
||||
print '#####################################'
|
||||
return False
|
||||
except Exception, e:
|
||||
pass
|
||||
|
||||
version = 0
|
||||
logger.error("Unable to detect Airtime Version - %s, Response: %s", e, response)
|
||||
|
||||
return version
|
||||
|
||||
|
||||
def test(self):
|
||||
logger = logging.getLogger()
|
||||
status, items = self.get_schedule('2010-01-01-00-00-00', '2011-01-01-00-00-00')
|
||||
schedule = items["playlists"]
|
||||
logger.debug("Number of playlists found: %s", str(len(schedule)))
|
||||
count = 1
|
||||
for pkey in sorted(schedule.iterkeys()):
|
||||
logger.debug("Playlist #%s",str(count))
|
||||
count+=1
|
||||
#logger.info("found playlist at %s", pkey)
|
||||
playlist = schedule[pkey]
|
||||
for item in playlist["medias"]:
|
||||
filename = urlparse(item["uri"])
|
||||
filename = filename.query[5:]
|
||||
self.get_media(item["uri"], filename)
|
||||
|
||||
|
||||
def is_server_compatible(self, verbose = True):
|
||||
version = self.__get_airtime_version(verbose)
|
||||
if (version == 0 or version == False):
|
||||
if (verbose):
|
||||
print 'Unable to get Airtime version number.'
|
||||
print
|
||||
return False
|
||||
elif (version[0:4] != "1.6."):
|
||||
if (verbose):
|
||||
print 'Airtime version: ' + str(version)
|
||||
print 'pypo not compatible with this version of Airtime.'
|
||||
print
|
||||
return False
|
||||
else:
|
||||
if (verbose):
|
||||
print 'Airtime version: ' + str(version)
|
||||
print 'pypo is compatible with this version of Airtime.'
|
||||
print
|
||||
return True
|
||||
|
||||
|
||||
def get_schedule(self, start=None, end=None):
|
||||
logger = logging.getLogger()
|
||||
|
||||
"""
|
||||
calculate start/end time range (format: YYYY-DD-MM-hh-mm-ss,YYYY-DD-MM-hh-mm-ss)
|
||||
(seconds are ignored, just here for consistency)
|
||||
"""
|
||||
tnow = time.localtime(time.time())
|
||||
if (not start):
|
||||
tstart = time.localtime(time.time() - 3600 * int(self.config["cache_for"]))
|
||||
start = "%04d-%02d-%02d-%02d-%02d" % (tstart[0], tstart[1], tstart[2], tstart[3], tstart[4])
|
||||
|
||||
if (not end):
|
||||
tend = time.localtime(time.time() + 3600 * int(self.config["prepare_ahead"]))
|
||||
end = "%04d-%02d-%02d-%02d-%02d" % (tend[0], tend[1], tend[2], tend[3], tend[4])
|
||||
|
||||
range = {}
|
||||
range['start'] = start
|
||||
range['end'] = end
|
||||
|
||||
# Construct the URL
|
||||
export_url = self.config["base_url"] + self.config["api_base"] + self.config["export_url"]
|
||||
#logger.debug("Exporting schedule using URL: "+export_url)
|
||||
|
||||
# Insert the start and end times into the URL
|
||||
export_url = export_url.replace('%%api_key%%', self.config["api_key"])
|
||||
export_url = export_url.replace('%%from%%', range['start'])
|
||||
export_url = export_url.replace('%%to%%', range['end'])
|
||||
logger.info("Fetching schedule from %s", export_url)
|
||||
|
||||
response = ""
|
||||
status = 0
|
||||
try:
|
||||
response_json = urllib.urlopen(export_url).read()
|
||||
#logger.debug("%s", response_json)
|
||||
response = json.read(response_json)
|
||||
#logger.info("export status %s", response['check'])
|
||||
status = response['check']
|
||||
except Exception, e:
|
||||
print e
|
||||
|
||||
#schedule = response["playlists"]
|
||||
#scheduleKeys = sorted(schedule.iterkeys())
|
||||
#
|
||||
## Remove all playlists that have passed current time
|
||||
#try:
|
||||
# tnow = time.localtime(time.time())
|
||||
# str_tnow_s = "%04d-%02d-%02d-%02d-%02d-%02d" % (tnow[0], tnow[1], tnow[2], tnow[3], tnow[4], tnow[5])
|
||||
# toRemove = []
|
||||
# for pkey in scheduleKeys:
|
||||
# if (str_tnow_s > schedule[pkey]['end']):
|
||||
# toRemove.append(pkey)
|
||||
# else:
|
||||
# break
|
||||
# #logger.debug("Remove keys: %s", toRemove)
|
||||
# for index in toRemove:
|
||||
# del schedule[index]
|
||||
# #logger.debug("Schedule dict: %s", schedule)
|
||||
#except Exception, e:
|
||||
# logger.debug("'Ignore Past Playlists' feature not supported by API: %s", e)
|
||||
#response["playlists"] = schedule
|
||||
|
||||
return status, response
|
||||
|
||||
|
||||
def get_media(self, src, dst):
|
||||
logger = logging.getLogger()
|
||||
|
||||
try:
|
||||
src = src + "/api_key/" + self.config["api_key"]
|
||||
logger.debug("try to download from %s to %s", src, dst)
|
||||
# check if file exists already before downloading again
|
||||
filename, headers = urllib.urlretrieve(src, dst)
|
||||
|
||||
logger.info("downloaded %s to %s", src, dst)
|
||||
except Exception, e:
|
||||
logger.error("%s", e)
|
||||
|
||||
|
||||
"""
|
||||
Tell server that the scheduled *playlist* has started.
|
||||
"""
|
||||
def notify_scheduled_item_start_playing(self, pkey, schedule):
|
||||
logger = logging.getLogger()
|
||||
playlist = schedule[pkey]
|
||||
schedule_id = playlist["schedule_id"]
|
||||
url = self.config["base_url"] + self.config["api_base"] + self.config["update_item_url"]
|
||||
url = url.replace("%%schedule_id%%", str(schedule_id))
|
||||
url = url.replace("%%api_key%%", self.config["api_key"])
|
||||
logger.debug(url)
|
||||
|
||||
try:
|
||||
response = urllib.urlopen(url)
|
||||
response = json.read(response.read())
|
||||
logger.info("API-Status %s", response['status'])
|
||||
logger.info("API-Message %s", response['message'])
|
||||
|
||||
except Exception, e:
|
||||
logger.critical("Unable to connect - %s", e)
|
||||
|
||||
return response
|
||||
|
||||
|
||||
"""
|
||||
This is a callback from liquidsoap, we use this to notify about the
|
||||
currently playing *song*. We get passed a JSON string which we handed to
|
||||
liquidsoap in get_liquidsoap_data().
|
||||
"""
|
||||
def notify_media_item_start_playing(self, data, media_id):
|
||||
logger = logging.getLogger()
|
||||
response = ''
|
||||
if (data[0] != '{'):
|
||||
return response
|
||||
try:
|
||||
data = json.read(data)
|
||||
logger.debug(str(data))
|
||||
schedule_id = data["schedule_id"]
|
||||
url = self.config["base_url"] + self.config["api_base"] + self.config["update_start_playing_url"]
|
||||
url = url.replace("%%media_id%%", str(media_id))
|
||||
url = url.replace("%%schedule_id%%", str(schedule_id))
|
||||
url = url.replace("%%api_key%%", self.config["api_key"])
|
||||
logger.debug(url)
|
||||
response = urllib.urlopen(url)
|
||||
response = json.read(response.read())
|
||||
logger.info("API-Status %s", response['status'])
|
||||
logger.info("API-Message %s", response['message'])
|
||||
|
||||
except Exception, e:
|
||||
logger.critical("Exception: %s", e)
|
||||
|
||||
return response
|
||||
|
||||
|
||||
def generate_range_dp(self):
|
||||
pass
|
||||
#logger = logging.getLogger()
|
||||
#
|
||||
#url = self.api_url + 'schedule/generate_range_dp.php'
|
||||
#
|
||||
#try:
|
||||
# response = urllib.urlopen(url, self.api_auth)
|
||||
# response = json.read(response.read())
|
||||
# logger.debug("Trying to contact %s", url)
|
||||
# logger.info("API-Status %s", response['status'])
|
||||
# logger.info("API-Message %s", response['message'])
|
||||
#
|
||||
#except Exception, e:
|
||||
# print e
|
||||
# api_status = False
|
||||
# logger.critical("Unable to handle the request - %s", e)
|
||||
#
|
||||
#return response
|
||||
|
||||
def get_liquidsoap_data(self, pkey, schedule):
|
||||
logger = logging.getLogger()
|
||||
playlist = schedule[pkey]
|
||||
data = dict()
|
||||
try:
|
||||
data["schedule_id"] = playlist['id']
|
||||
except Exception, e:
|
||||
data["schedule_id"] = 0
|
||||
data = json.write(data)
|
||||
return data
|
||||
|
||||
|
||||
|
||||
################################################################################
|
||||
# OpenBroadcast API Client
|
||||
################################################################################
|
||||
# Also check out the php counterpart that handles the api requests:
|
||||
# https://lab.digris.ch/svn/elgg/trunk/unstable/mod/medialibrary/application/controllers/api/pypo.php
|
||||
|
||||
OBP_MIN_VERSION = 2010100101 # required obp version
|
||||
|
||||
class ObpApiClient():
|
||||
|
||||
def __init__(self, config):
|
||||
self.config = config
|
||||
self.api_auth = urllib.urlencode({'api_key': self.config["api_key"]})
|
||||
|
||||
def is_server_compatible(self, verbose = True):
|
||||
obp_version = self.get_obp_version()
|
||||
|
||||
if obp_version == 0:
|
||||
if (verbose):
|
||||
print '#################################################'
|
||||
print 'Unable to get OBP version. Is OBP up and running?'
|
||||
print '#################################################'
|
||||
print
|
||||
return False
|
||||
elif obp_version < OBP_MIN_VERSION:
|
||||
if (verbose):
|
||||
print 'OBP version: ' + str(obp_version)
|
||||
print 'OBP min-version: ' + str(OBP_MIN_VERSION)
|
||||
print 'pypo not compatible with this version of OBP'
|
||||
print
|
||||
return False
|
||||
else:
|
||||
if (verbose):
|
||||
print 'OBP API: ' + str(API_BASE)
|
||||
print 'OBP version: ' + str(obp_version)
|
||||
print 'OBP min-version: ' + str(OBP_MIN_VERSION)
|
||||
print 'pypo is compatible with this version of OBP'
|
||||
print
|
||||
return True
|
||||
|
||||
|
||||
def get_obp_version(self):
|
||||
logger = logging.getLogger()
|
||||
|
||||
# lookup OBP version
|
||||
url = self.config["base_url"] + self.config["api_base"]+ self.config["version_url"]
|
||||
|
||||
try:
|
||||
logger.debug("Trying to contact %s", url)
|
||||
response = urllib.urlopen(url, self.api_auth)
|
||||
response_json = json.read(response.read())
|
||||
obp_version = int(response_json['version'])
|
||||
logger.debug("OBP Version %s detected", obp_version)
|
||||
|
||||
except Exception, e:
|
||||
try:
|
||||
if e[1] == 401:
|
||||
print '#####################################'
|
||||
print '# YOUR API KEY SEEMS TO BE INVALID'
|
||||
print '# ' + self.config["api_auth"]
|
||||
print '#####################################'
|
||||
sys.exit()
|
||||
|
||||
except Exception, e:
|
||||
pass
|
||||
|
||||
try:
|
||||
if e[1] == 404:
|
||||
print '#####################################'
|
||||
print '# Unable to contact the OBP-API'
|
||||
print '# ' + url
|
||||
print '#####################################'
|
||||
sys.exit()
|
||||
|
||||
except Exception, e:
|
||||
pass
|
||||
|
||||
obp_version = 0
|
||||
logger.error("Unable to detect OBP Version - %s", e)
|
||||
|
||||
return obp_version
|
||||
|
||||
|
||||
def get_schedule(self, start=None, end=None):
|
||||
logger = logging.getLogger()
|
||||
|
||||
"""
|
||||
calculate start/end time range (format: YYYY-DD-MM-hh-mm-ss,YYYY-DD-MM-hh-mm-ss)
|
||||
(seconds are ignored, just here for consistency)
|
||||
"""
|
||||
tnow = time.localtime(time.time())
|
||||
if (not start):
|
||||
tstart = time.localtime(time.time() - 3600 * int(self.config["cache_for"]))
|
||||
start = "%04d-%02d-%02d-%02d-%02d" % (tstart[0], tstart[1], tstart[2], tstart[3], tstart[4])
|
||||
|
||||
if (not end):
|
||||
tend = time.localtime(time.time() + 3600 * int(self.config["prepare_ahead"]))
|
||||
end = "%04d-%02d-%02d-%02d-%02d" % (tend[0], tend[1], tend[2], tend[3], tend[4])
|
||||
|
||||
range = {}
|
||||
range['start'] = start
|
||||
range['end'] = end
|
||||
|
||||
# Construct the URL
|
||||
export_url = self.config["base_url"] + self.config["api_base"] + self.config["export_url"]
|
||||
|
||||
# Insert the start and end times into the URL
|
||||
export_url = export_url.replace('%%api_key%%', self.config["api_key"])
|
||||
export_url = export_url.replace('%%from%%', range['start'])
|
||||
export_url = export_url.replace('%%to%%', range['end'])
|
||||
logger.info("export from %s", export_url)
|
||||
|
||||
response = ""
|
||||
status = 0
|
||||
try:
|
||||
response_json = urllib.urlopen(export_url).read()
|
||||
logger.debug("%s", response_json)
|
||||
response = json.read(response_json)
|
||||
logger.info("export status %s", response['check'])
|
||||
status = response['check']
|
||||
except Exception, e:
|
||||
print e
|
||||
|
||||
return status, response
|
||||
|
||||
|
||||
def get_media(self, src, dest):
|
||||
try:
|
||||
print '** urllib auth with: ',
|
||||
print self.api_auth
|
||||
urllib.urlretrieve(src, dst, False, self.api_auth)
|
||||
logger.info("downloaded %s to %s", src, dst)
|
||||
except Exception, e:
|
||||
logger.error("%s", e)
|
||||
|
||||
|
||||
"""
|
||||
Tell server that the scheduled *playlist* has started.
|
||||
"""
|
||||
def notify_scheduled_item_start_playing(self, pkey, schedule):
|
||||
#def update_scheduled_item(self, item_id, value):
|
||||
logger = logging.getLogger()
|
||||
url = self.config["base_url"] + self.config["api_base"] + self.config["update_item_url"]
|
||||
url = url.replace("%%item_id%%", str(schedule[pkey]["id"]))
|
||||
url = url.replace("%%played%%", "1")
|
||||
|
||||
try:
|
||||
response = urllib.urlopen(url, self.api_auth)
|
||||
response = json.read(response.read())
|
||||
logger.info("API-Status %s", response['status'])
|
||||
logger.info("API-Message %s", response['message'])
|
||||
|
||||
except Exception, e:
|
||||
print e
|
||||
api_status = False
|
||||
logger.critical("Unable to connect to the OBP API - %s", e)
|
||||
|
||||
return response
|
||||
|
||||
"""
|
||||
This is a callback from liquidsoap, we use this to notify about the
|
||||
currently playing *song*. We get passed a JSON string which we handed to
|
||||
liquidsoap in get_liquidsoap_data().
|
||||
"""
|
||||
def notify_media_item_start_playing(self, data, media_id):
|
||||
# def update_start_playing(self, playlist_type, export_source, media_id, playlist_id, transmission_id):
|
||||
logger = logging.getLogger()
|
||||
playlist_type = data["playlist_type"]
|
||||
export_source = data["export_source"]
|
||||
playlist_id = data["playlist_id"]
|
||||
transmission_id = data["transmission_id"]
|
||||
|
||||
url = self.config["base_url"] + self.config["api_base"] + self.config["update_start_playing_url"]
|
||||
url = url.replace("%%playlist_type%%", str(playlist_type))
|
||||
url = url.replace("%%export_source%%", str(export_source))
|
||||
url = url.replace("%%media_id%%", str(media_id))
|
||||
url = url.replace("%%playlist_id%%", str(playlist_id))
|
||||
url = url.replace("%%transmission_id%%", str(transmission_id))
|
||||
print url
|
||||
|
||||
try:
|
||||
response = urllib.urlopen(url, self.api_auth)
|
||||
response = json.read(response.read())
|
||||
logger.info("API-Status %s", response['status'])
|
||||
logger.info("API-Message %s", response['message'])
|
||||
logger.info("TXT %s", response['str_dls'])
|
||||
|
||||
except Exception, e:
|
||||
print e
|
||||
api_status = False
|
||||
logger.critical("Unable to connect to the OBP API - %s", e)
|
||||
|
||||
return response
|
||||
|
||||
|
||||
def generate_range_dp(self):
|
||||
logger = logging.getLogger()
|
||||
|
||||
url = self.config["base_url"] + self.config["api_base"] + self.config["generate_range_url"]
|
||||
|
||||
try:
|
||||
response = urllib.urlopen(url, self.api_auth)
|
||||
response = json.read(response.read())
|
||||
logger.debug("Trying to contact %s", url)
|
||||
logger.info("API-Status %s", response['status'])
|
||||
logger.info("API-Message %s", response['message'])
|
||||
|
||||
except Exception, e:
|
||||
print e
|
||||
api_status = False
|
||||
logger.critical("Unable to handle the OBP API request - %s", e)
|
||||
|
||||
return response
|
||||
|
||||
def get_liquidsoap_data(self, pkey, schedule):
|
||||
playlist = schedule[pkey]
|
||||
data = dict()
|
||||
data["ptype"] = playlist['subtype']
|
||||
try:
|
||||
data["user_id"] = playlist['user_id']
|
||||
data["playlist_id"] = playlist['id']
|
||||
data["transmission_id"] = playlist['schedule_id']
|
||||
except Exception, e:
|
||||
data["playlist_id"] = 0
|
||||
data["user_id"] = 0
|
||||
data["transmission_id"] = 0
|
||||
data = json.write(data)
|
||||
return data
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
import airtime_api_client
|
||||
import obp_api_client
|
||||
|
||||
def create_api_client(config):
|
||||
if config["api_client"] == "airtime":
|
||||
return campcaster_api_client.AirtimeApiClient(config)
|
||||
elif config["api_client"] == "obp":
|
||||
return obp_api_client.ObpApiClient(config)
|
||||
|
121
pypo/config.cfg
121
pypo/config.cfg
|
@ -1,121 +0,0 @@
|
|||
############################################
|
||||
# pypo - configuration #
|
||||
############################################
|
||||
|
||||
# Set the type of client you are using.
|
||||
# Currently supported types:
|
||||
# 1) "obp" = Open Broadcast Platform
|
||||
# 2) "airtime"
|
||||
#
|
||||
api_client = "airtime"
|
||||
|
||||
############################################
|
||||
# Directories / Hosts #
|
||||
# _include_ trailing slash !! #
|
||||
############################################
|
||||
cache_dir = '/opt/pypo/cache/'
|
||||
file_dir = '/opt/pypo/files/'
|
||||
tmp_dir = '/opt/pypo/tmp/'
|
||||
|
||||
# Hostname
|
||||
base_url = 'http://localhost/'
|
||||
|
||||
############################################
|
||||
# Liquidsoap settings #
|
||||
############################################
|
||||
ls_host = '127.0.0.1'
|
||||
ls_port = '1234'
|
||||
|
||||
############################################
|
||||
# pypo preferences #
|
||||
############################################
|
||||
prepare_ahead = 24 #in hours
|
||||
cache_for = 24 #how long to hold the cache, in hours
|
||||
|
||||
# Poll interval in seconds.
|
||||
#
|
||||
# This is how often the poll script downloads new schedules and files from the
|
||||
# server.
|
||||
#
|
||||
# For production use, this number depends on whether you plan on making any
|
||||
# last-minute changes to your schedule. This number should be set to half of
|
||||
# the time you expect to "lock-in" your schedule. So if your schedule is set
|
||||
# 24 hours in advance, this can be set to poll every 12 hours.
|
||||
#
|
||||
poll_interval = 30 # in seconds.
|
||||
|
||||
|
||||
# Push interval in seconds.
|
||||
#
|
||||
# This is how often the push script checks whether it has something new to
|
||||
# push to liquidsoap.
|
||||
#
|
||||
# It's hard to imagine a situation where this should be more than 1 second.
|
||||
#
|
||||
push_interval = 1 # in seconds
|
||||
|
||||
# 'pre' or 'otf'. 'pre' cues while playlist preparation
|
||||
# while 'otf' (on the fly) cues while loading into ls
|
||||
# (needs the post_processor patch)
|
||||
cue_style = 'pre'
|
||||
|
||||
|
||||
################################################################################
|
||||
# Uncomment *one of the sets* of values from the API clients below, and comment
|
||||
# out all the others.
|
||||
################################################################################
|
||||
|
||||
#####################
|
||||
# Airtime Config #
|
||||
#####################
|
||||
# Value needed to access the API
|
||||
api_key = 'AAA'
|
||||
|
||||
# Path to the base of the API
|
||||
api_base = 'api/'
|
||||
|
||||
# URL to get the version number of the server API
|
||||
version_url = 'version/api_key/%%api_key%%'
|
||||
|
||||
# Schedule export path.
|
||||
# %%from%% - starting date/time in the form YYYY-MM-DD-hh-mm
|
||||
# %%to%% - starting date/time in the form YYYY-MM-DD-hh-mm
|
||||
export_url = 'schedule/api_key/%%api_key%%/from/%%from%%/to/%%to%%'
|
||||
|
||||
# Update whether a schedule group has begun playing.
|
||||
update_item_url = 'notify-schedule-group-play/api_key/%%api_key%%/schedule_id/%%schedule_id%%'
|
||||
|
||||
# Update whether an audio clip is currently playing.
|
||||
update_start_playing_url = 'notify-media-item-start-play/api_key/%%api_key%%/media_id/%%media_id%%/schedule_id/%%schedule_id%%'
|
||||
|
||||
# ???
|
||||
generate_range_url = 'generate_range_dp.php'
|
||||
|
||||
|
||||
##############
|
||||
# OBP config #
|
||||
##############
|
||||
# Value needed to access the API
|
||||
#api_key = 'AAA'
|
||||
|
||||
#base_url = 'http://localhost/'
|
||||
|
||||
# Path to the base of the API
|
||||
#api_base = ''
|
||||
|
||||
# URL to get the version number of the server API
|
||||
#version_url = 'api/pypo/status/json'
|
||||
|
||||
# Schedule export path.
|
||||
# %%from%% - starting date/time in the form YYYY-MM-DD-hh-mm
|
||||
# %%to%% - starting date/time in the form YYYY-MM-DD-hh-mm
|
||||
|
||||
# Update whether an item has been played.
|
||||
#update_item_url = 'api/pypo/update_shedueled_item/$$item_id%%?played=%%played%%'
|
||||
|
||||
# Update whether an item is currently playing.
|
||||
#update_start_playing_url = 'api/pypo/mod/medialibrary/?playlist_type=%%playlist_type%%&export_source=%%export_source%%&media_id=%%media_id%%&playlist_id=%%playlist_id%%&transmission_id=%%transmission_id%%'
|
||||
|
||||
# ???
|
||||
#generate_range_url = 'api/pypo/generate_range_dp/'
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
############################################
|
||||
# pypo - configuration #
|
||||
############################################
|
||||
|
||||
############################################
|
||||
# Directories / Hosts #
|
||||
# _include_ trailing slash !! #
|
||||
############################################
|
||||
cache_dir = '/storage/pypo/cache/'
|
||||
file_dir = '/storage/pypo/files/'
|
||||
tmp_dir = '/var/tmp/obp/'
|
||||
|
||||
############################################
|
||||
# API path & co #
|
||||
############################################
|
||||
base_url = 'http://test.local.obp.ch/'
|
||||
obp_api_key = 'AAA-BBB-CCC-EEE'
|
||||
|
||||
export_path = 'api/pypo/export_range/' # YYYY-MM-DD-hh-mm will be added in script, exports json
|
||||
export_source = 'scheduler' # choose "dayparts" or "scheduler"
|
||||
|
||||
############################################
|
||||
# Liquidsoap settings #
|
||||
############################################
|
||||
ls_host = '127.0.0.1'
|
||||
ls_port = '1234'
|
||||
|
||||
############################################
|
||||
# pypo preferences #
|
||||
############################################
|
||||
prepare_ahead = 12 #in hours
|
||||
cache_for = 12 #how long to hold the cache, in hours
|
||||
|
||||
poll_interval = 10 # in seconds
|
||||
push_interval = 1 # in seconds
|
||||
|
||||
# 'pre' or 'otf'. 'pre' cues while pplaylist preparation
|
||||
# while 'otf' (on the fly) cues while loading into ls
|
||||
# (needs the post_processor patch)
|
||||
cue_style = 'pre'
|
|
@ -1,3 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from dls_client import *
|
|
@ -1,90 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# author Jonas Ohrstrom <jonas@digris.ch>
|
||||
|
||||
import sys
|
||||
import time
|
||||
|
||||
import logging
|
||||
|
||||
from util import json
|
||||
|
||||
import os
|
||||
import socket
|
||||
|
||||
|
||||
|
||||
class DlsClient():
|
||||
|
||||
def __init__(self, dls_host, dls_port, dls_user, dls_pass):
|
||||
self.dls_host = dls_host
|
||||
self.dls_port = dls_port
|
||||
self.dls_user = dls_user
|
||||
self.dls_pass = dls_pass
|
||||
|
||||
def set_txt(self, txt):
|
||||
|
||||
logger = logging.getLogger("DlsClient.set_txt")
|
||||
|
||||
try:
|
||||
|
||||
print 'trying to update dls'
|
||||
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
s.connect((self.dls_host, self.dls_port))
|
||||
|
||||
s.send('client_zzzz')
|
||||
s.send("\r\n")
|
||||
data = s.recv(1024)
|
||||
print data;
|
||||
|
||||
s.send('RS_DLS_VERSION' + ' ' + '1')
|
||||
s.send("\r\n")
|
||||
data = s.recv(1024)
|
||||
print data;
|
||||
|
||||
s.send('SERVICE' + ' ' + self.dls_user)
|
||||
s.send("\r\n")
|
||||
|
||||
s.send('PASSWORD' + ' ' + self.dls_pass)
|
||||
s.send("\r\n")
|
||||
data = s.recv(1024)
|
||||
print data;
|
||||
|
||||
s.send('SET_DLS_CHARSET' + ' ' + '4')
|
||||
s.send("\r\n")
|
||||
data = s.recv(1024)
|
||||
print data;
|
||||
|
||||
s.send('CLEAR_DLS')
|
||||
s.send("\r\n")
|
||||
|
||||
s.send('SET_DLS' + ' ' + txt)
|
||||
s.send("\r\n")
|
||||
data = s.recv(1024)
|
||||
print data;
|
||||
|
||||
s.send('CLOSE_DLS')
|
||||
s.send("\r\n")
|
||||
data = s.recv(1024)
|
||||
print data;
|
||||
|
||||
s.close()
|
||||
|
||||
|
||||
print 'OK'
|
||||
|
||||
except Exception, e:
|
||||
#print e
|
||||
print 'did not work out.'
|
||||
dls_status = False
|
||||
logger.info("Unable to connect to the update metadata - %s", e)
|
||||
|
||||
|
||||
return
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
#!/bin/sh
|
||||
pypo_user="pypo"
|
||||
export HOME="/home/pypo/"
|
||||
# Location of pypo_cli.py Python script
|
||||
pypo_path="/opt/pypo/bin/"
|
||||
pypo_script="pypo-cli.py"
|
||||
echo "*** Daemontools: starting daemon"
|
||||
cd ${pypo_path}
|
||||
exec 2>&1
|
||||
# Note the -u when calling python! we need it to get unbuffered binary stdout and stderr
|
||||
exec setuidgid ${pypo_user} \
|
||||
python -u ${pypo_path}${pypo_script} \
|
||||
-f
|
||||
# EOF
|
|
@ -1,13 +0,0 @@
|
|||
#!/bin/sh
|
||||
ls_user="pypo"
|
||||
export HOME="/home/pypo/"
|
||||
#ls_path="/usr/local/bin/liquidsoap"
|
||||
ls_path="/opt/pypo/bin/liquidsoap/liquidsoap"
|
||||
ls_param="/opt/pypo/bin/scripts/ls_script.liq"
|
||||
echo "*** Daemontools: starting liquidsoap"
|
||||
echo "cp /opt/pypo/files/basic/silence.lsp /opt/pypo/cache/current.lsp"
|
||||
cp /opt/pypo/files/basic/silence.lsp /opt/pypo/cache/current.lsp
|
||||
exec 2>&1
|
||||
echo "exec sudo -u ${ls_user} ${ls_path} ${ls_param} "
|
||||
cd /opt/pypo/bin/scripts && sudo -u ${ls_user} ${ls_path} ${ls_param}
|
||||
# EOF
|
|
@ -1,2 +0,0 @@
|
|||
#!/bin/sh
|
||||
exec setuidgid pypo multilog t ./main
|
|
@ -1,14 +0,0 @@
|
|||
#!/bin/sh
|
||||
pypo_user="pypo"
|
||||
export HOME="/home/pypo/"
|
||||
# Location of pypo_cli.py Python script
|
||||
pypo_path="/opt/pypo/bin/"
|
||||
pypo_script="pypo-cli.py"
|
||||
echo "*** Daemontools: starting daemon"
|
||||
cd ${pypo_path}
|
||||
exec 2>&1
|
||||
# Note the -u when calling python! we need it to get unbuffered binary stdout and stderr
|
||||
exec setuidgid ${pypo_user} \
|
||||
python -u ${pypo_path}${pypo_script} \
|
||||
-p
|
||||
# EOF
|
|
@ -1,147 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import time
|
||||
import os
|
||||
import traceback
|
||||
from optparse import *
|
||||
import sys
|
||||
import time
|
||||
import datetime
|
||||
import logging
|
||||
import logging.config
|
||||
import shutil
|
||||
import string
|
||||
import platform
|
||||
from subprocess import Popen, PIPE, STDOUT
|
||||
|
||||
if os.geteuid() != 0:
|
||||
print "Please run this as root."
|
||||
sys.exit(1)
|
||||
|
||||
BASE_PATH = '/opt/pypo/'
|
||||
|
||||
def create_path(path):
|
||||
if not (os.path.exists(path)):
|
||||
print "Creating directory " + path
|
||||
os.makedirs(path)
|
||||
|
||||
def create_user(username):
|
||||
print "Checking for user "+username
|
||||
p = Popen('id '+username, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)
|
||||
output = p.stdout.read()
|
||||
if (output[0:3] != "uid"):
|
||||
# Make the pypo user
|
||||
print "Creating user "+username
|
||||
os.system("adduser --system --quiet --group --shell /bin/bash "+username)
|
||||
|
||||
#add pypo to audio group
|
||||
os.system("adduser " + username + " audio")
|
||||
|
||||
#set pypo password
|
||||
p = os.popen('/usr/bin/passwd pypo', 'w')
|
||||
p.write('pypo\n')
|
||||
p.write('pypo\n')
|
||||
p.close()
|
||||
else:
|
||||
print "User already exists."
|
||||
|
||||
def copy_dir(src_dir, dest_dir):
|
||||
if (os.path.exists(dest_dir)) and (dest_dir != "/"):
|
||||
print "Removing old directory "+dest_dir
|
||||
shutil.rmtree(dest_dir)
|
||||
if not (os.path.exists(dest_dir)):
|
||||
print "Copying directory "+src_dir+" to "+dest_dir
|
||||
shutil.copytree(src_dir, dest_dir)
|
||||
|
||||
try:
|
||||
# Create users
|
||||
create_user("pypo")
|
||||
|
||||
print "Creating log directories"
|
||||
create_path("/var/log/pypo")
|
||||
os.system("chmod -R 755 /var/log/pypo")
|
||||
os.system("chown -R pypo:pypo /var/log/pypo")
|
||||
|
||||
create_path(BASE_PATH)
|
||||
create_path(BASE_PATH+"bin")
|
||||
create_path(BASE_PATH+"cache")
|
||||
create_path(BASE_PATH+"files")
|
||||
create_path(BASE_PATH+"tmp")
|
||||
create_path(BASE_PATH+"files/basic")
|
||||
create_path(BASE_PATH+"files/fallback")
|
||||
create_path(BASE_PATH+"files/jingles")
|
||||
create_path(BASE_PATH+"archive")
|
||||
|
||||
print "Copying pypo files"
|
||||
shutil.copy("../scripts/silence-playlist.lsp", BASE_PATH+"files/basic")
|
||||
shutil.copy("../scripts/silence.mp3", BASE_PATH+"files/basic")
|
||||
|
||||
if platform.architecture()[0] == '64bit':
|
||||
print "Installing 64-bit liquidsoap binary"
|
||||
shutil.copy("../liquidsoap/liquidsoap64", "../liquidsoap/liquidsoap")
|
||||
elif platform.architecture()[0] == '32bit':
|
||||
print "Installing 32-bit liquidsoap binary"
|
||||
shutil.copy("../liquidsoap/liquidsoap32", "../liquidsoap/liquidsoap")
|
||||
else:
|
||||
print "Unknown system architecture."
|
||||
sys.exit(1)
|
||||
|
||||
copy_dir("..", BASE_PATH+"bin/")
|
||||
|
||||
print "Setting permissions"
|
||||
os.system("chmod -R 755 "+BASE_PATH)
|
||||
os.system("chown -R pypo:pypo "+BASE_PATH)
|
||||
|
||||
print "Installing daemontool script pypo-fetch"
|
||||
create_path("/etc/service/pypo-fetch")
|
||||
create_path("/etc/service/pypo-fetch/log")
|
||||
shutil.copy("pypo-daemontools-fetch.sh", "/etc/service/pypo-fetch/run")
|
||||
shutil.copy("pypo-daemontools-logger.sh", "/etc/service/pypo-fetch/log/run")
|
||||
os.system("chmod -R 755 /etc/service/pypo-fetch")
|
||||
os.system("chown -R pypo:pypo /etc/service/pypo-fetch")
|
||||
|
||||
print "Installing daemontool script pypo-push"
|
||||
create_path("/etc/service/pypo-push")
|
||||
create_path("/etc/service/pypo-push/log")
|
||||
shutil.copy("pypo-daemontools-push.sh", "/etc/service/pypo-push/run")
|
||||
shutil.copy("pypo-daemontools-logger.sh", "/etc/service/pypo-push/log/run")
|
||||
os.system("chmod -R 755 /etc/service/pypo-push")
|
||||
os.system("chown -R pypo:pypo /etc/service/pypo-push")
|
||||
|
||||
print "Installing daemontool script pypo-liquidsoap"
|
||||
os.system("svc -dx /etc/service/pypo-liquidsoap 1>/dev/null 2>&1")
|
||||
create_path("/etc/service/pypo-liquidsoap")
|
||||
create_path("/etc/service/pypo-liquidsoap/log")
|
||||
shutil.copy("pypo-daemontools-liquidsoap.sh", "/etc/service/pypo-liquidsoap/run")
|
||||
shutil.copy("pypo-daemontools-logger.sh", "/etc/service/pypo-liquidsoap/log/run")
|
||||
os.system("chmod -R 755 /etc/service/pypo-liquidsoap")
|
||||
os.system("chown -R pypo:pypo /etc/service/pypo-liquidsoap")
|
||||
|
||||
print "Waiting for processes to start..."
|
||||
time.sleep(5)
|
||||
os.system("killall liquidsoap")
|
||||
os.system("python ./pypo-start.py")
|
||||
time.sleep(2)
|
||||
|
||||
p = Popen('svstat /etc/service/pypo-fetch', shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)
|
||||
output = p.stdout.read()
|
||||
if (output.find("unable to open supervise/ok: file does not exist") >= 0):
|
||||
print "Install has completed, but daemontools is not running, please make sure you have it installed and then reboot."
|
||||
sys.exit()
|
||||
print output
|
||||
|
||||
p = Popen('svstat /etc/service/pypo-push', shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)
|
||||
output = p.stdout.read()
|
||||
print output
|
||||
|
||||
p = Popen('svstat /etc/service/pypo-liquidsoap', shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)
|
||||
output = p.stdout.read()
|
||||
print output
|
||||
|
||||
print "Install complete."
|
||||
except Exception, e:
|
||||
print "exception:" + str(e)
|
||||
|
||||
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
if os.geteuid() != 0:
|
||||
print "Please run this as root."
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
print "Starting daemontool script pypo-fetch"
|
||||
os.system("svc -t /etc/service/pypo-fetch")
|
||||
|
||||
print "Starting daemontool script pypo-push"
|
||||
os.system("svc -t /etc/service/pypo-push")
|
||||
|
||||
print "Starting daemontool script pypo-liquidsoap"
|
||||
os.system("svc -t /etc/service/pypo-liquidsoap")
|
||||
|
||||
except Exception, e:
|
||||
print "exception:" + str(e)
|
|
@ -1,22 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
if os.geteuid() != 0:
|
||||
print "Please run this as root."
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
print "Stopping daemontool script pypo-fetch"
|
||||
os.system("svc -dx /etc/service/pypo-fetch")
|
||||
|
||||
print "Stopping daemontool script pypo-push"
|
||||
os.system("svc -dx /etc/service/pypo-push")
|
||||
|
||||
print "Stopping daemontool script pypo-liquidsoap"
|
||||
os.system("svc -dx /etc/service/pypo-liquidsoap")
|
||||
|
||||
except Exception, e:
|
||||
print "exception:" + str(e)
|
|
@ -1,47 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
|
||||
if os.geteuid() != 0:
|
||||
print "Please run this as root."
|
||||
sys.exit(1)
|
||||
|
||||
BASE_PATH = '/opt/pypo/'
|
||||
|
||||
def remove_path(path):
|
||||
os.system("rm -rf " + path)
|
||||
|
||||
def remove_user(username):
|
||||
os.system("killall -u " + username)
|
||||
|
||||
#allow all process to be completely closed before we attempt to delete user
|
||||
print "Waiting for processes to close..."
|
||||
time.sleep(5)
|
||||
|
||||
os.system("deluser --remove-home " + username + " 1>/dev/null")
|
||||
|
||||
try:
|
||||
os.system("python ./pypo-stop.py")
|
||||
|
||||
print "Removing log directories"
|
||||
remove_path("/var/log/pypo")
|
||||
|
||||
print "Removing pypo files"
|
||||
remove_path(BASE_PATH)
|
||||
|
||||
print "Removing daemontool script pypo-fetch"
|
||||
remove_path("rm -rf /etc/service/pypo-fetch")
|
||||
|
||||
print "Removing daemontool script pypo-push"
|
||||
remove_path("rm -rf /etc/service/pypo-push")
|
||||
|
||||
print "Removing daemontool script pypo-liquidsoap"
|
||||
remove_path("rm -rf /etc/service/pypo-liquidsoap")
|
||||
|
||||
remove_user("pypo")
|
||||
print "Uninstall complete."
|
||||
except Exception, e:
|
||||
print "exception:" + str(e)
|
Binary file not shown.
Binary file not shown.
|
@ -1,59 +0,0 @@
|
|||
[loggers]
|
||||
keys=root
|
||||
|
||||
[handlers]
|
||||
keys=consoleHandler,fileHandlerERROR,fileHandlerDEBUG,nullHandler
|
||||
|
||||
[formatters]
|
||||
keys=simpleFormatter
|
||||
|
||||
[logger_root]
|
||||
level=DEBUG
|
||||
handlers=consoleHandler,fileHandlerERROR,fileHandlerDEBUG
|
||||
|
||||
[logger_libs]
|
||||
handlers=nullHandler
|
||||
level=CRITICAL
|
||||
qualname="process"
|
||||
propagate=0
|
||||
|
||||
[handler_consoleHandler]
|
||||
class=StreamHandler
|
||||
level=CRITICAL
|
||||
formatter=simpleFormatter
|
||||
args=(sys.stdout,)
|
||||
|
||||
[handler_fileHandlerERROR]
|
||||
class=FileHandler
|
||||
level=CRITICAL
|
||||
formatter=simpleFormatter
|
||||
args=("./error-unit-test.log",)
|
||||
|
||||
[handler_fileHandlerDEBUG]
|
||||
class=FileHandler
|
||||
level=CRITICAL
|
||||
formatter=simpleFormatter
|
||||
args=("./debug-unit-test.log",)
|
||||
|
||||
[handler_nullHandler]
|
||||
class=FileHandler
|
||||
level=CRITICAL
|
||||
formatter=simpleFormatter
|
||||
args=("./log-null-unit-test.log",)
|
||||
|
||||
|
||||
[formatter_simpleFormatter]
|
||||
format=%(asctime)s %(levelname)s - [%(filename)s : %(funcName)s() : line %(lineno)d] - %(message)s
|
||||
datefmt=
|
||||
|
||||
|
||||
## multitail color sheme
|
||||
## pyml / python
|
||||
# colorscheme:pyml:www.obp.net
|
||||
# cs_re:blue:\[[^ ]*\]
|
||||
# cs_re:red:CRITICAL:*
|
||||
# cs_re:red,black,blink:ERROR:*
|
||||
# cs_re:blue:NOTICE:*
|
||||
# cs_re:cyan:INFO:*
|
||||
# cs_re:green:DEBUG:*
|
||||
|
|
@ -1,61 +0,0 @@
|
|||
[loggers]
|
||||
keys=root
|
||||
|
||||
[handlers]
|
||||
keys=consoleHandler,fileHandlerERROR,fileHandlerDEBUG,nullHandler
|
||||
|
||||
[formatters]
|
||||
keys=simpleFormatter
|
||||
|
||||
[logger_root]
|
||||
level=DEBUG
|
||||
handlers=consoleHandler,fileHandlerERROR,fileHandlerDEBUG
|
||||
|
||||
[logger_libs]
|
||||
handlers=nullHandler
|
||||
level=DEBUG
|
||||
qualname="process"
|
||||
propagate=0
|
||||
|
||||
|
||||
|
||||
[handler_consoleHandler]
|
||||
class=StreamHandler
|
||||
level=DEBUG
|
||||
formatter=simpleFormatter
|
||||
args=(sys.stdout,)
|
||||
|
||||
[handler_fileHandlerERROR]
|
||||
class=FileHandler
|
||||
level=WARNING
|
||||
formatter=simpleFormatter
|
||||
args=("./error.log",)
|
||||
|
||||
[handler_fileHandlerDEBUG]
|
||||
class=FileHandler
|
||||
level=DEBUG
|
||||
formatter=simpleFormatter
|
||||
args=("./debug.log",)
|
||||
|
||||
[handler_nullHandler]
|
||||
class=FileHandler
|
||||
level=DEBUG
|
||||
formatter=simpleFormatter
|
||||
args=("/tmp/sessionlog_null.log",)
|
||||
|
||||
|
||||
[formatter_simpleFormatter]
|
||||
format=%(asctime)s %(levelname)s - [%(filename)s : %(funcName)s() : line %(lineno)d] - %(message)s
|
||||
datefmt=
|
||||
|
||||
|
||||
## multitail color sheme
|
||||
## pyml / python
|
||||
# colorscheme:pyml:www.obp.net
|
||||
# cs_re:blue:\[[^ ]*\]
|
||||
# cs_re:red:CRITICAL:*
|
||||
# cs_re:red,black,blink:ERROR:*
|
||||
# cs_re:blue:NOTICE:*
|
||||
# cs_re:cyan:INFO:*
|
||||
# cs_re:green:DEBUG:*
|
||||
|
|
@ -1,74 +0,0 @@
|
|||
import time
|
||||
import os
|
||||
import traceback
|
||||
from optparse import *
|
||||
import sys
|
||||
import time
|
||||
import datetime
|
||||
import logging
|
||||
import logging.config
|
||||
import shutil
|
||||
import urllib
|
||||
import urllib2
|
||||
import pickle
|
||||
import telnetlib
|
||||
import random
|
||||
import string
|
||||
import operator
|
||||
import inspect
|
||||
|
||||
# additional modules (should be checked)
|
||||
from configobj import ConfigObj
|
||||
|
||||
# custom imports
|
||||
from util import *
|
||||
from api_clients import *
|
||||
|
||||
import random
|
||||
import unittest
|
||||
|
||||
# configure logging
|
||||
logging.config.fileConfig("logging-api-validator.cfg")
|
||||
|
||||
try:
|
||||
config = ConfigObj('config.cfg')
|
||||
except Exception, e:
|
||||
print 'Error loading config file: ', e
|
||||
sys.exit()
|
||||
|
||||
|
||||
class TestApiFunctions(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.api_client = api_client.api_client_factory(config)
|
||||
|
||||
def test_is_server_compatible(self):
|
||||
self.assertTrue(self.api_client.is_server_compatible(False))
|
||||
|
||||
def test_get_schedule(self):
|
||||
status, response = self.api_client.get_schedule()
|
||||
self.assertTrue(response.has_key("status"))
|
||||
self.assertTrue(response.has_key("playlists"))
|
||||
self.assertTrue(response.has_key("check"))
|
||||
self.assertTrue(status == 1)
|
||||
|
||||
def test_get_media(self):
|
||||
self.assertTrue(True)
|
||||
|
||||
def test_notify_scheduled_item_start_playing(self):
|
||||
arr = dict()
|
||||
arr["x"] = dict()
|
||||
arr["x"]["schedule_id"]=1
|
||||
|
||||
response = self.api_client.notify_scheduled_item_start_playing("x", arr)
|
||||
self.assertTrue(response.has_key("status"))
|
||||
self.assertTrue(response.has_key("message"))
|
||||
|
||||
def test_notify_media_item_start_playing(self):
|
||||
response = self.api_client.notify_media_item_start_playing('{"schedule_id":1}', 5)
|
||||
self.assertTrue(response.has_key("status"))
|
||||
self.assertTrue(response.has_key("message"))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
885
pypo/pypo-cli.py
885
pypo/pypo-cli.py
|
@ -1,885 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
Python part of radio playout (pypo)
|
||||
|
||||
The main functions are "fetch" (./pypo_cli.py -f) and "push" (./pypo_cli.py -p)
|
||||
|
||||
There are two layers: scheduler & daypart (fallback)
|
||||
|
||||
The daypart is a fallback-layer generated by the playlists daypart-settings
|
||||
(eg a playlist creator can say that the list is good for Monday and Tues,
|
||||
between 14:00 and 16:00). So if there is nothing in the schedule, pypo will
|
||||
still play something (instead of silence..) This layer is optional.
|
||||
It is there so that you dont have a fallback player which plays the same 100
|
||||
tracks over and over again.
|
||||
|
||||
Attention & ToDos
|
||||
- liquidsoap does not like mono files! So we have to make sure that only files with
|
||||
2 channels are fed to LiquidSoap
|
||||
(solved: current = audio_to_stereo(current) - maybe not with ultimate performance)
|
||||
|
||||
|
||||
made for python version 2.5!!
|
||||
should work with 2.6 as well with a bit of adaption. for
|
||||
sure the json parsing has to be changed
|
||||
(2.6 has an parser, pypo brings it's own -> util/json.py)
|
||||
"""
|
||||
|
||||
# python defaults (debian default)
|
||||
import time
|
||||
import os
|
||||
import traceback
|
||||
from optparse import *
|
||||
import sys
|
||||
import time
|
||||
import datetime
|
||||
import logging
|
||||
import logging.config
|
||||
import shutil
|
||||
import urllib
|
||||
import urllib2
|
||||
import pickle
|
||||
import telnetlib
|
||||
import random
|
||||
import string
|
||||
import operator
|
||||
import inspect
|
||||
|
||||
# additional modules (should be checked)
|
||||
from configobj import ConfigObj
|
||||
|
||||
# custom imports
|
||||
from util import *
|
||||
from api_clients import *
|
||||
|
||||
PYPO_VERSION = '0.2'
|
||||
PYPO_MEDIA_SKIP = 1
|
||||
PYPO_MEDIA_LIVE_SESSION = 2
|
||||
PYPO_MEDIA_STREAM = 3
|
||||
PYPO_MEDIA_FILE_URL = 4
|
||||
PYPO_MEDIA_FILE_LOCAL = 5
|
||||
|
||||
# Set up command-line options
|
||||
parser = OptionParser()
|
||||
|
||||
# help screeen / info
|
||||
usage = "%prog [options]" + " - python playout system"
|
||||
parser = OptionParser(usage=usage)
|
||||
|
||||
# Options
|
||||
parser.add_option("-v", "--compat", help="Check compatibility with server API version", default=False, action="store_true", dest="check_compat")
|
||||
|
||||
parser.add_option("-t", "--test", help="Do a test to make sure everything is working properly.", default=False, action="store_true", dest="test")
|
||||
parser.add_option("-f", "--fetch-scheduler", help="Fetch the schedule from server. This is a polling process that runs forever.", default=False, action="store_true", dest="fetch_scheduler")
|
||||
parser.add_option("-p", "--push-scheduler", help="Push the schedule to Liquidsoap. This is a polling process that runs forever.", default=False, action="store_true", dest="push_scheduler")
|
||||
|
||||
parser.add_option("-F", "--fetch-daypart", help="Fetch from daypart - scheduler (loop, interval in config file)", default=False, action="store_true", dest="fetch_daypart")
|
||||
parser.add_option("-P", "--push-daypart", help="Push daypart to Liquidsoap (loop, interval in config file)", default=False, action="store_true", dest="push_daypart")
|
||||
|
||||
parser.add_option("-b", "--cleanup", help="Cleanup", default=False, action="store_true", dest="cleanup")
|
||||
#parser.add_option("-j", "--jingles", help="Get new jingles from server, comma separated list if jingle-id's as argument", metavar="LIST")
|
||||
parser.add_option("-c", "--check", help="Check the cached schedule and exit", default=False, action="store_true", dest="check")
|
||||
|
||||
# parse options
|
||||
(options, args) = parser.parse_args()
|
||||
|
||||
# configure logging
|
||||
logging.config.fileConfig("logging.cfg")
|
||||
|
||||
# loading config file
|
||||
try:
|
||||
config = ConfigObj('config.cfg')
|
||||
POLL_INTERVAL = float(config['poll_interval'])
|
||||
PUSH_INTERVAL = 0.5
|
||||
#PUSH_INTERVAL = float(config['push_interval'])
|
||||
LS_HOST = config['ls_host']
|
||||
LS_PORT = config['ls_port']
|
||||
except Exception, e:
|
||||
print 'Error loading config file: ', e
|
||||
sys.exit()
|
||||
|
||||
class Global:
|
||||
def __init__(self):
|
||||
print
|
||||
|
||||
def selfcheck(self):
|
||||
self.api_client = api_client.api_client_factory(config)
|
||||
if (not self.api_client.is_server_compatible()):
|
||||
sys.exit()
|
||||
|
||||
|
||||
class Playout:
|
||||
def __init__(self):
|
||||
self.api_client = api_client.api_client_factory(config)
|
||||
self.cue_file = CueFile()
|
||||
self.silence_file = config["file_dir"] + 'basic/silence.mp3'
|
||||
self.push_ahead = 15
|
||||
self.range_updated = False
|
||||
|
||||
|
||||
def test_api(self):
|
||||
self.api_client.test()
|
||||
|
||||
|
||||
def set_export_source(self, export_source):
|
||||
self.export_source = export_source
|
||||
self.cache_dir = config["cache_dir"] + self.export_source + '/'
|
||||
self.schedule_file = self.cache_dir + 'schedule.pickle'
|
||||
self.schedule_tracker_file = self.cache_dir + "schedule_tracker.pickle"
|
||||
|
||||
|
||||
"""
|
||||
Fetching part of pypo
|
||||
- Reads the scheduled entries of a given range (actual time +/- "prepare_ahead" / "cache_for")
|
||||
- Saves a serialized file of the schedule
|
||||
- playlists are prepared. (brought to liquidsoap format) and, if not mounted via nsf, files are copied
|
||||
to the cache dir (Folder-structure: cache/YYYY-MM-DD-hh-mm-ss)
|
||||
- runs the cleanup routine, to get rid of unused cashed files
|
||||
"""
|
||||
def fetch(self, export_source):
|
||||
"""
|
||||
wrapper script for fetching the whole schedule (in json)
|
||||
"""
|
||||
logger = logging.getLogger()
|
||||
|
||||
self.set_export_source(export_source)
|
||||
|
||||
try: os.mkdir(self.cache_dir)
|
||||
except Exception, e: pass
|
||||
|
||||
"""
|
||||
Trigger daypart range-generation. (Only if daypart-instance)
|
||||
"""
|
||||
if self.export_source == 'daypart':
|
||||
|
||||
print '******************************'
|
||||
print '*** TRIGGER DAYPART UPDATE ***'
|
||||
print '******************************'
|
||||
|
||||
try:
|
||||
self.generate_range_dp()
|
||||
except Exception, e:
|
||||
logger.error("%s", e)
|
||||
|
||||
# get schedule
|
||||
try:
|
||||
while self.get_schedule() != 1:
|
||||
logger.warning("failed to read from export url")
|
||||
time.sleep(1)
|
||||
|
||||
except Exception, e: logger.error("%s", e)
|
||||
|
||||
# prepare the playlists
|
||||
if config["cue_style"] == 'pre':
|
||||
try: self.prepare_playlists_cue()
|
||||
except Exception, e: logger.error("%s", e)
|
||||
elif config["cue_style"] == 'otf':
|
||||
try: self.prepare_playlists(self.export_source)
|
||||
except Exception, e: logger.error("%s", e)
|
||||
|
||||
# cleanup
|
||||
try: self.cleanup(self.export_source)
|
||||
except Exception, e: logger.error("%s", e)
|
||||
|
||||
#logger.info("fetch loop completed")
|
||||
|
||||
|
||||
"""
|
||||
This is actually a bit ugly (again feel free to improve!!)
|
||||
The generate_range_dp function should be called once a day,
|
||||
we do this at 18h. The hour before the state is set back to 'False'
|
||||
"""
|
||||
def generate_range_dp(self):
|
||||
logger = logging.getLogger()
|
||||
logger.debug("trying to trigger daypart update")
|
||||
|
||||
tnow = time.localtime(time.time())
|
||||
|
||||
if (tnow[3] == 16):
|
||||
self.range_updated = False
|
||||
|
||||
if (tnow[3] == 17 and self.range_updated == False):
|
||||
try:
|
||||
print self.api_client.generate_range_dp()
|
||||
logger.info("daypart updated")
|
||||
self.range_updated = True
|
||||
|
||||
except Exception, e:
|
||||
print e
|
||||
|
||||
|
||||
def get_schedule(self):
|
||||
logger = logging.getLogger()
|
||||
status, response = self.api_client.get_schedule()
|
||||
|
||||
if status == 1:
|
||||
logger.info("dump serialized schedule to %s", self.schedule_file)
|
||||
schedule = response['playlists']
|
||||
try:
|
||||
schedule_file = open(self.schedule_file, "w")
|
||||
pickle.dump(schedule, schedule_file)
|
||||
schedule_file.close()
|
||||
|
||||
except Exception, e:
|
||||
logger.critical("Exception %s", e)
|
||||
status = 0
|
||||
|
||||
return status
|
||||
|
||||
|
||||
"""
|
||||
Alternative version of playout preparation. Every playlist entry is
|
||||
pre-cued if neccessary (cue_in/cue_out != 0) and stored in the
|
||||
playlist folder.
|
||||
file is eg 2010-06-23-15-00-00/17_cue_10.132-123.321.mp3
|
||||
"""
|
||||
def prepare_playlists_cue(self):
|
||||
logger = logging.getLogger()
|
||||
|
||||
# Load schedule from disk
|
||||
schedule = self.load_schedule()
|
||||
|
||||
# Dont do anything if schedule is empty
|
||||
if (not schedule):
|
||||
logger.debug("Schedule is empty.")
|
||||
return
|
||||
|
||||
scheduleKeys = sorted(schedule.iterkeys())
|
||||
|
||||
try:
|
||||
for pkey in scheduleKeys:
|
||||
logger.info("found playlist at %s", pkey)
|
||||
playlist = schedule[pkey]
|
||||
|
||||
# create playlist directory
|
||||
try:
|
||||
os.mkdir(self.cache_dir + str(pkey))
|
||||
except Exception, e:
|
||||
pass
|
||||
|
||||
ls_playlist = '';
|
||||
|
||||
logger.debug('*****************************************')
|
||||
logger.debug('pkey: ' + str(pkey))
|
||||
logger.debug('cached at : ' + self.cache_dir + str(pkey))
|
||||
logger.debug('subtype: ' + str(playlist['subtype']))
|
||||
logger.debug('played: ' + str(playlist['played']))
|
||||
logger.debug('schedule id: ' + str(playlist['schedule_id']))
|
||||
logger.debug('duration: ' + str(playlist['duration']))
|
||||
logger.debug('source id: ' + str(playlist['x_ident']))
|
||||
logger.debug('*****************************************')
|
||||
|
||||
# Creating an API call like the next two lines would make this more flexible
|
||||
# mediaType = api_client.get_media_type(playlist)
|
||||
# if (mediaType == PYPO_MEDIA_SKIP):
|
||||
|
||||
if int(playlist['played']) == 1:
|
||||
logger.info("playlist %s already played / sent to liquidsoap, so will ignore it", pkey)
|
||||
|
||||
elif int(playlist['subtype']) == 5:
|
||||
ls_playlist = self.handle_live_session(playlist, pkey, ls_playlist)
|
||||
|
||||
elif int(playlist['subtype']) == 6:
|
||||
ls_playlist = self.handle_live_cast(playlist, pkey, ls_playlist)
|
||||
|
||||
elif int(playlist['subtype']) > 0 and int(playlist['subtype']) < 5:
|
||||
ls_playlist = self.handle_media_file(playlist, pkey, ls_playlist)
|
||||
|
||||
"""
|
||||
This is kind of hackish. We add a bunch of "silence" tracks to the end of each playlist.
|
||||
So we can make sure the list does not get repeated just before a new one is called.
|
||||
(or in case nothing is in the scheduler afterwards)
|
||||
20 x silence = 10 hours
|
||||
"""
|
||||
for i in range (0, 1):
|
||||
ls_playlist += self.silence_file + "\n"
|
||||
print '',
|
||||
|
||||
# write playlist file
|
||||
plfile = open(self.cache_dir + str(pkey) + '/list.lsp', "w")
|
||||
plfile.write(ls_playlist)
|
||||
plfile.close()
|
||||
logger.info('ls playlist file written to %s', self.cache_dir + str(pkey) + '/list.lsp')
|
||||
|
||||
except Exception, e:
|
||||
logger.info("%s", e)
|
||||
|
||||
|
||||
def handle_live_session(self, playlist, pkey, ls_playlist):
|
||||
"""
|
||||
This is a live session, so silence is scheduled.
|
||||
Maybe not the most elegant solution :)
|
||||
It adds 20 times 30min silence to the playlist
|
||||
Silence file has to be in <file_dir>/basic/silence.mp3
|
||||
"""
|
||||
logger = logging.getLogger()
|
||||
logger.debug("found %s seconds of live/studio session at %s", pkey, playlist['duration'])
|
||||
|
||||
if os.path.isfile(self.silence_file):
|
||||
logger.debug('file stored at: %s' + self.silence_file)
|
||||
|
||||
for i in range (0, 19):
|
||||
ls_playlist += self.silence_file + "\n"
|
||||
|
||||
else:
|
||||
print 'Could not find silence file!'
|
||||
print 'File is expected to be at: ' + self.silence_file
|
||||
logger.critical('File is expected to be at: %s', self.silence_file)
|
||||
sys.exit()
|
||||
return ls_playlist
|
||||
|
||||
|
||||
def handle_live_cast(self, playlist, pkey, ls_playlist):
|
||||
"""
|
||||
This is a live-cast session
|
||||
Create a silence list. (could eg also be a fallback list..)
|
||||
"""
|
||||
logger = logging.getLogger()
|
||||
logger.debug("found %s seconds of live-cast session at %s", pkey, playlist['duration'])
|
||||
|
||||
if os.path.isfile(self.silence_file):
|
||||
logger.debug('file stored at: %s' + self.silence_file)
|
||||
|
||||
for i in range (0, 19):
|
||||
ls_playlist += self.silence_file + "\n"
|
||||
|
||||
else:
|
||||
print 'Could not find silence file!'
|
||||
print 'File is expected to be at: ' + self.silence_file
|
||||
logger.critical('File is expected to be at: %s', self.silence_file)
|
||||
sys.exit()
|
||||
return ls_playlist
|
||||
|
||||
|
||||
def handle_media_file(self, playlist, pkey, ls_playlist):
|
||||
"""
|
||||
This handles both remote and local files.
|
||||
Returns an updated ls_playlist string.
|
||||
"""
|
||||
logger = logging.getLogger()
|
||||
for media in playlist['medias']:
|
||||
logger.debug("Processing track %s", media['uri'])
|
||||
|
||||
fileExt = os.path.splitext(media['uri'])[1]
|
||||
try:
|
||||
if str(media['cue_in']) == '0' and str(media['cue_out']) == '0':
|
||||
logger.debug('No cue in/out detected for this file')
|
||||
dst = "%s%s/%s%s" % (self.cache_dir, str(pkey), str(media['id']), str(fileExt))
|
||||
do_cue = False
|
||||
else:
|
||||
logger.debug('Cue in/out detected')
|
||||
dst = "%s%s/%s_cue_%s-%s%s" % \
|
||||
(self.cache_dir, str(pkey), str(media['id']), str(float(media['cue_in']) / 1000), str(float(media['cue_out']) / 1000), str(fileExt))
|
||||
do_cue = True
|
||||
|
||||
# check if it is a remote file, if yes download
|
||||
if media['uri'][0:4] == 'http':
|
||||
self.handle_remote_file(media, dst, do_cue)
|
||||
else:
|
||||
# Assume local file
|
||||
self.handle_local_file(media, dst, do_cue)
|
||||
|
||||
if True == os.access(dst, os.R_OK):
|
||||
# check filesize (avoid zero-byte files)
|
||||
try: fsize = os.path.getsize(dst)
|
||||
except Exception, e:
|
||||
logger.error("%s", e)
|
||||
fsize = 0
|
||||
|
||||
if fsize > 0:
|
||||
pl_entry = 'annotate:export_source="%s",media_id="%s",liq_start_next="%s",liq_fade_in="%s",liq_fade_out="%s":%s' % \
|
||||
(str(media['export_source']), media['id'], 0, str(float(media['fade_in']) / 1000), str(float(media['fade_out']) / 1000), dst)
|
||||
|
||||
logger.debug(pl_entry)
|
||||
|
||||
"""
|
||||
Tracks are only added to the playlist if they are accessible
|
||||
on the file system and larger than 0 bytes.
|
||||
So this can lead to playlists shorter than expectet.
|
||||
(there is a hardware silence detector for this cases...)
|
||||
"""
|
||||
ls_playlist += pl_entry + "\n"
|
||||
|
||||
logger.debug("everything ok, adding %s to playlist", pl_entry)
|
||||
else:
|
||||
print 'zero-file: ' + dst + ' from ' + media['uri']
|
||||
logger.warning("zero-size file - skiping %s. will not add it to playlist", dst)
|
||||
|
||||
else:
|
||||
logger.warning("something went wrong. file %s not available. will not add it to playlist", dst)
|
||||
|
||||
except Exception, e: logger.info("%s", e)
|
||||
return ls_playlist
|
||||
|
||||
|
||||
def handle_remote_file(self, media, dst, do_cue):
|
||||
logger = logging.getLogger()
|
||||
if do_cue == False:
|
||||
if os.path.isfile(dst):
|
||||
logger.debug("file already in cache: %s", dst)
|
||||
else:
|
||||
logger.debug("try to download %s", media['uri'])
|
||||
self.api_client.get_media(media['uri'], dst)
|
||||
|
||||
else:
|
||||
if os.path.isfile(dst):
|
||||
logger.debug("file already in cache: %s", dst)
|
||||
|
||||
else:
|
||||
logger.debug("try to download and cue %s", media['uri'])
|
||||
|
||||
fileExt = os.path.splitext(media['uri'])[1]
|
||||
dst_tmp = config["tmp_dir"] + "".join([random.choice(string.letters) for i in xrange(10)]) + fileExt
|
||||
self.api_client.get_media(media['uri'], dst_tmp)
|
||||
|
||||
# cue
|
||||
logger.debug("STARTING CUE")
|
||||
debugDst = self.cue_file.cue(dst_tmp, dst, float(media['cue_in']) / 1000, float(media['cue_out']) / 1000)
|
||||
logger.debug(debugDst)
|
||||
logger.debug("END CUE")
|
||||
|
||||
if True == os.access(dst, os.R_OK):
|
||||
try: fsize = os.path.getsize(dst)
|
||||
except Exception, e:
|
||||
logger.error("%s", e)
|
||||
fsize = 0
|
||||
|
||||
if fsize > 0:
|
||||
logger.debug('try to remove temporary file: %s' + dst_tmp)
|
||||
try: os.remove(dst_tmp)
|
||||
except Exception, e:
|
||||
logger.error("%s", e)
|
||||
|
||||
else:
|
||||
logger.warning('something went wrong cueing: %s - using uncued file' + dst)
|
||||
try: os.rename(dst_tmp, dst)
|
||||
except Exception, e:
|
||||
logger.error("%s", e)
|
||||
|
||||
|
||||
def handle_local_file(self, media, dst, do_cue):
|
||||
"""
|
||||
Handle files on NAS. Pre-cueing not implemented at the moment.
|
||||
(not needed by openbroadcast, feel free to add this)
|
||||
Here's an implementation for locally stored files.
|
||||
Works the same as with remote files, just replaced API-download with
|
||||
file copy.
|
||||
"""
|
||||
logger = logging.getLogger()
|
||||
if do_cue == False:
|
||||
if os.path.isfile(dst):
|
||||
logger.debug("file already in cache: %s", dst)
|
||||
|
||||
else:
|
||||
logger.debug("try to copy file to cache %s", media['uri'])
|
||||
try:
|
||||
shutil.copy(media['uri'], dst)
|
||||
logger.info("copied %s to %s", media['uri'], dst)
|
||||
except Exception, e:
|
||||
logger.error("%s", e)
|
||||
else:
|
||||
if os.path.isfile(dst):
|
||||
logger.debug("file already in cache: %s", dst)
|
||||
|
||||
else:
|
||||
logger.debug("try to copy and cue %s", media['uri'])
|
||||
|
||||
print '***'
|
||||
dst_tmp = config["tmp_dir"] + "".join([random.choice(string.letters) for i in xrange(10)])
|
||||
print dst_tmp
|
||||
print '***'
|
||||
|
||||
try:
|
||||
shutil.copy(media['uri'], dst_tmp)
|
||||
logger.info("copied %s to %s", media['uri'], dst_tmp)
|
||||
except Exception, e:
|
||||
logger.error("%s", e)
|
||||
|
||||
# cue
|
||||
print "STARTING CUE"
|
||||
print self.cue_file.cue(dst_tmp, dst, float(media['cue_in']) / 1000, float(media['cue_out']) / 1000)
|
||||
print "END CUE"
|
||||
|
||||
if True == os.access(dst, os.R_OK):
|
||||
try: fsize = os.path.getsize(dst)
|
||||
except Exception, e:
|
||||
logger.error("%s", e)
|
||||
fsize = 0
|
||||
|
||||
if fsize > 0:
|
||||
logger.debug('try to remove temporary file: %s' + dst_tmp)
|
||||
try: os.remove(dst_tmp)
|
||||
except Exception, e:
|
||||
logger.error("%s", e)
|
||||
|
||||
else:
|
||||
logger.warning('something went wrong cueing: %s - using uncued file' + dst)
|
||||
try: os.rename(dst_tmp, dst)
|
||||
except Exception, e:
|
||||
logger.error("%s", e)
|
||||
|
||||
|
||||
def cleanup(self, export_source):
|
||||
"""
|
||||
Cleans up folders in cache_dir. Look for modification date older than "now - CACHE_FOR"
|
||||
and deletes them.
|
||||
"""
|
||||
logger = logging.getLogger()
|
||||
|
||||
self.set_export_source(export_source)
|
||||
offset = 3600 * int(config["cache_for"])
|
||||
now = time.time()
|
||||
|
||||
for r, d, f in os.walk(self.cache_dir):
|
||||
for dir in d:
|
||||
try:
|
||||
timestamp = time.mktime(time.strptime(dir, "%Y-%m-%d-%H-%M-%S"))
|
||||
#logger.debug('dir : %s', (dir))
|
||||
#logger.debug('age : %s', (round((now - timestamp),1)))
|
||||
#logger.debug('delete in : %ss', (round((offset - (now - timestamp)),1)))
|
||||
#logger.debug('Folder "Age": %s - %s', round((((now - offset) - timestamp) / 60), 2), os.path.join(r, dir))
|
||||
|
||||
if (now - timestamp) > offset:
|
||||
try:
|
||||
logger.debug('trying to remove %s - timestamp: %s', os.path.join(r, dir), timestamp)
|
||||
shutil.rmtree(os.path.join(r, dir))
|
||||
except Exception, e:
|
||||
logger.error("%s", e)
|
||||
pass
|
||||
else:
|
||||
logger.info('sucessfully removed %s', os.path.join(r, dir))
|
||||
except Exception, e:
|
||||
print e
|
||||
logger.error("%s", e)
|
||||
|
||||
|
||||
"""
|
||||
The Push Loop - the push loop periodically (minimal 1/2 of the playlist-grid)
|
||||
checks if there is a playlist that should be scheduled at the current time.
|
||||
If yes, the temporary liquidsoap playlist gets replaced with the corresponding one,
|
||||
then liquidsoap is asked (via telnet) to reload and immediately play it.
|
||||
"""
|
||||
def push(self, export_source):
|
||||
logger = logging.getLogger()
|
||||
|
||||
self.set_export_source(export_source)
|
||||
|
||||
#try:
|
||||
# dummy = self.schedule
|
||||
# logger.debug('schedule already loaded')
|
||||
#except Exception, e:
|
||||
# self.schedule = self.push_init(self.export_source)
|
||||
|
||||
self.schedule = self.load_schedule()
|
||||
playedItems = self.load_schedule_tracker()
|
||||
|
||||
tcoming = time.localtime(time.time() + self.push_ahead)
|
||||
tnow = time.localtime(time.time())
|
||||
|
||||
str_tcoming_s = "%04d-%02d-%02d-%02d-%02d-%02d" % (tcoming[0], tcoming[1], tcoming[2], tcoming[3], tcoming[4], tcoming[5])
|
||||
|
||||
if self.schedule == None:
|
||||
logger.warn('Unable to loop schedule - maybe write in progress?')
|
||||
logger.warn('Will try again in next loop.')
|
||||
|
||||
else:
|
||||
for pkey in self.schedule:
|
||||
playedFlag = (pkey in playedItems) and playedItems[pkey].get("played", 0)
|
||||
if pkey[0:19] <= str_tcoming_s and not playedFlag:
|
||||
logger.debug('Preparing to push playlist scheduled at: %s', pkey)
|
||||
playlist = self.schedule[pkey]
|
||||
|
||||
ptype = playlist['subtype']
|
||||
|
||||
# We have a match, replace the current playlist and
|
||||
# force liquidsoap to refresh.
|
||||
if (self.push_liquidsoap(pkey, self.schedule, ptype) == 1):
|
||||
logger.debug("Pushed to liquidsoap, updating 'played' status.")
|
||||
# Marked the current playlist as 'played' in the schedule tracker
|
||||
# so it is not called again in the next push loop.
|
||||
# Write changes back to tracker file.
|
||||
playedItems[pkey] = playlist
|
||||
playedItems[pkey]['played'] = 1
|
||||
schedule_tracker = open(self.schedule_tracker_file, "w")
|
||||
pickle.dump(playedItems, schedule_tracker)
|
||||
schedule_tracker.close()
|
||||
logger.debug("Wrote schedule to disk: "+str(playedItems))
|
||||
|
||||
# Call API to update schedule states
|
||||
logger.debug("Doing callback to server to update 'played' status.")
|
||||
self.api_client.notify_scheduled_item_start_playing(pkey, self.schedule)
|
||||
|
||||
|
||||
def load_schedule(self):
|
||||
logger = logging.getLogger()
|
||||
schedule = None
|
||||
|
||||
# create the file if it doesnt exist
|
||||
if (not os.path.exists(self.schedule_file)):
|
||||
logger.debug('creating file ' + self.schedule_file)
|
||||
open(self.schedule_file, 'w').close()
|
||||
else:
|
||||
# load the schedule from cache
|
||||
#logger.debug('loading schedule file '+self.schedule_file)
|
||||
try:
|
||||
schedule_file = open(self.schedule_file, "r")
|
||||
schedule = pickle.load(schedule_file)
|
||||
schedule_file.close()
|
||||
|
||||
except Exception, e:
|
||||
logger.error('%s', e)
|
||||
|
||||
return schedule
|
||||
|
||||
|
||||
def load_schedule_tracker(self):
|
||||
logger = logging.getLogger()
|
||||
playedItems = dict()
|
||||
|
||||
# create the file if it doesnt exist
|
||||
if (not os.path.exists(self.schedule_tracker_file)):
|
||||
logger.debug('creating file ' + self.schedule_tracker_file)
|
||||
schedule_tracker = open(self.schedule_tracker_file, 'w')
|
||||
pickle.dump(playedItems, schedule_tracker)
|
||||
schedule_tracker.close()
|
||||
else:
|
||||
try:
|
||||
#logger.debug('loading schedule tracker file '+ self.schedule_tracker_file)
|
||||
schedule_tracker = open(self.schedule_tracker_file, "r")
|
||||
playedItems = pickle.load(schedule_tracker)
|
||||
schedule_tracker.close()
|
||||
except Exception, e:
|
||||
logger.error('Unable to load schedule tracker file: %s', e)
|
||||
|
||||
return playedItems
|
||||
|
||||
|
||||
def push_liquidsoap(self, pkey, schedule, ptype):
|
||||
logger = logging.getLogger()
|
||||
|
||||
src = self.cache_dir + str(pkey) + '/list.lsp'
|
||||
|
||||
try:
|
||||
if True == os.access(src, os.R_OK):
|
||||
logger.debug('OK - Can read playlist file')
|
||||
|
||||
pl_file = open(src, "r")
|
||||
|
||||
"""
|
||||
i know this could be wrapped, maybe later..
|
||||
"""
|
||||
tn = telnetlib.Telnet(LS_HOST, 1234)
|
||||
|
||||
if (int(ptype) == 6):
|
||||
tn.write("live_in.start")
|
||||
tn.write("\n")
|
||||
|
||||
if (int(ptype) < 5):
|
||||
for line in pl_file.readlines():
|
||||
logger.debug(line.strip())
|
||||
tn.write(self.export_source + '.push %s' % (line.strip()))
|
||||
tn.write("\n")
|
||||
|
||||
tn.write("exit\n")
|
||||
logger.debug(tn.read_all())
|
||||
logger.debug('sleeping for %s s' % (self.push_ahead))
|
||||
time.sleep(self.push_ahead)
|
||||
|
||||
logger.debug('sending "flip"')
|
||||
tn = telnetlib.Telnet(LS_HOST, 1234)
|
||||
|
||||
# Get any extra information for liquidsoap (which will be sent back to us)
|
||||
liquidsoap_data = self.api_client.get_liquidsoap_data(pkey, schedule)
|
||||
logger.debug("Sending additional data to liquidsoap: "+liquidsoap_data)
|
||||
|
||||
#Sending JSON string. Example: {"schedule_id":"13"}
|
||||
tn.write("vars.pypo_data "+liquidsoap_data+"\n")
|
||||
|
||||
tn.write(self.export_source + '.flip')
|
||||
tn.write("\n")
|
||||
|
||||
if (int(ptype) == 6):
|
||||
tn.write("live.active 1")
|
||||
tn.write("\n")
|
||||
else:
|
||||
tn.write("live.active 0")
|
||||
tn.write("\n")
|
||||
tn.write("live_in.stop")
|
||||
tn.write("\n")
|
||||
|
||||
tn.write("exit\n")
|
||||
|
||||
tn.read_all()
|
||||
status = 1
|
||||
except Exception, e:
|
||||
logger.error('%s', e)
|
||||
status = 0
|
||||
|
||||
return status
|
||||
|
||||
|
||||
"""
|
||||
Updates the jingles. Give comma separated list of jingle tracks.
|
||||
|
||||
NOTE: commented out because it needs to be converted to use the API client. - Paul
|
||||
"""
|
||||
#def update_jingles(self, options):
|
||||
# print 'jingles'
|
||||
#
|
||||
# jingle_list = string.split(options, ',')
|
||||
# print jingle_list
|
||||
# for media_id in jingle_list:
|
||||
# # api path maybe should not be hard-coded
|
||||
# src = API_BASE + 'api/pypo/get_media/' + str(media_id)
|
||||
# print src
|
||||
# # include the hourly jungles for the moment
|
||||
# dst = "%s%s/%s.mp3" % (config["file_dir"], 'jingles/hourly', str(media_id))
|
||||
# print dst
|
||||
#
|
||||
# try:
|
||||
# print '** urllib auth with: ',
|
||||
# print self.api_auth
|
||||
# opener = urllib.URLopener()
|
||||
# opener.retrieve (src, dst, False, self.api_auth)
|
||||
# logger.info("downloaded %s to %s", src, dst)
|
||||
# except Exception, e:
|
||||
# print e
|
||||
# logger.error("%s", e)
|
||||
|
||||
|
||||
def check_schedule(self, export_source):
|
||||
logger = logging.getLogger()
|
||||
|
||||
self.set_export_source(export_source)
|
||||
|
||||
try:
|
||||
schedule_file = open(self.schedule_file, "r")
|
||||
schedule = pickle.load(schedule_file)
|
||||
schedule_file.close()
|
||||
|
||||
except Exception, e:
|
||||
logger.error("%s", e)
|
||||
schedule = None
|
||||
|
||||
for pkey in sorted(schedule.iterkeys()):
|
||||
playlist = schedule[pkey]
|
||||
print '*****************************************'
|
||||
print '\033[0;32m%s %s\033[m' % ('scheduled at:', str(pkey))
|
||||
print 'cached at : ' + self.cache_dir + str(pkey)
|
||||
print 'subtype: ' + str(playlist['subtype'])
|
||||
print 'played: ' + str(playlist['played'])
|
||||
print 'schedule id: ' + str(playlist['schedule_id'])
|
||||
print 'duration: ' + str(playlist['duration'])
|
||||
print 'source id: ' + str(playlist['x_ident'])
|
||||
print '-----------------------------------------'
|
||||
|
||||
for media in playlist['medias']:
|
||||
print media
|
||||
|
||||
print
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print
|
||||
print '###########################################'
|
||||
print '# *** pypo *** #'
|
||||
print '# Liquidsoap + External Scheduler #'
|
||||
print '# Playout System #'
|
||||
print '###########################################'
|
||||
print
|
||||
|
||||
# initialize
|
||||
g = Global()
|
||||
g.selfcheck()
|
||||
po = Playout()
|
||||
|
||||
|
||||
run = True
|
||||
while run == True:
|
||||
logger = logging.getLogger()
|
||||
|
||||
loops = 0
|
||||
|
||||
if options.test:
|
||||
po.test_api()
|
||||
sys.exit()
|
||||
|
||||
while options.fetch_scheduler:
|
||||
try: po.fetch('scheduler')
|
||||
except Exception, e:
|
||||
print e
|
||||
sys.exit()
|
||||
|
||||
#print 'ZZzZzZzzzzZZZz.... sleeping for ' + str(POLL_INTERVAL) + ' seconds'
|
||||
#logger.info('fetch loop %s - ZZzZzZzzzzZZZz.... sleeping for %s seconds', loops, POLL_INTERVAL)
|
||||
if (loops%2 == 0):
|
||||
logger.info("heartbeat\n\n\n\n")
|
||||
loops += 1
|
||||
time.sleep(POLL_INTERVAL)
|
||||
|
||||
while options.fetch_daypart:
|
||||
try: po.fetch('daypart')
|
||||
except Exception, e:
|
||||
print e
|
||||
sys.exit()
|
||||
|
||||
#print 'ZZzZzZzzzzZZZz.... sleeping for ' + str(POLL_INTERVAL) + ' seconds'
|
||||
#logger.info('fetch loop %s - ZZzZzZzzzzZZZz.... sleeping for %s seconds', loops, POLL_INTERVAL)
|
||||
loops += 1
|
||||
time.sleep(POLL_INTERVAL)
|
||||
|
||||
|
||||
while options.push_scheduler:
|
||||
po.push('scheduler')
|
||||
|
||||
try: po.push('scheduler')
|
||||
except Exception, e:
|
||||
print 'PUSH ERROR!! WILL EXIT NOW:('
|
||||
print e
|
||||
sys.exit()
|
||||
|
||||
if (loops%20 == 0):
|
||||
logger.info("heartbeat")
|
||||
|
||||
#logger.info('push loop %s - ZZzZzZzzzzZZZz.... sleeping for %s seconds', loops, PUSH_INTERVAL)
|
||||
loops += 1
|
||||
time.sleep(PUSH_INTERVAL)
|
||||
|
||||
|
||||
while options.push_daypart:
|
||||
po.push('daypart')
|
||||
|
||||
try: po.push('daypart')
|
||||
except Exception, e:
|
||||
print 'PUSH ERROR!! WILL EXIT NOW:('
|
||||
print e
|
||||
sys.exit()
|
||||
|
||||
#logger.info('push loop %s - ZZzZzZzzzzZZZz.... sleeping for %s seconds', loops, PUSH_INTERVAL)
|
||||
loops += 1
|
||||
time.sleep(PUSH_INTERVAL)
|
||||
|
||||
|
||||
#while options.jingles:
|
||||
# try: po.update_jingles(options.jingles)
|
||||
# except Exception, e:
|
||||
# print e
|
||||
# sys.exit()
|
||||
|
||||
|
||||
while options.check:
|
||||
try: po.check_schedule()
|
||||
except Exception, e:
|
||||
print e
|
||||
sys.exit()
|
||||
|
||||
while options.cleanup:
|
||||
try: po.cleanup('scheduler')
|
||||
except Exception, e:
|
||||
print e
|
||||
sys.exit()
|
||||
|
||||
|
||||
sys.exit()
|
|
@ -1,42 +0,0 @@
|
|||
import unittest
|
||||
|
||||
from util.cue_file import CueFile
|
||||
|
||||
from mutagen.mp3 import MP3
|
||||
from mutagen.oggvorbis import OggVorbis
|
||||
import random
|
||||
import string
|
||||
|
||||
class test(unittest.TestCase):
|
||||
|
||||
"""
|
||||
|
||||
A test class for the cue_in module.
|
||||
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
self.cue_file = CueFile()
|
||||
|
||||
def test_cue_mp3(self):
|
||||
src = '../audio_samples/OpSound/Peter_Rudenko_-_Opening.mp3'
|
||||
dst = '/tmp/' + "".join([random.choice(string.letters) for i in xrange(10)]) + '.mp3'
|
||||
self.cue_file.cue(src, dst, 5, 5)
|
||||
src_length = MP3(src).info.length
|
||||
dst_length = MP3(dst).info.length
|
||||
print src + " " + str(src_length)
|
||||
print dst + " " + str(dst_length)
|
||||
self.assertTrue(dst_length < src_length)
|
||||
|
||||
def test_cue_ogg(self):
|
||||
src = '../audio_samples/OpSound/ACDC_-_Back_In_Black-sample.ogg'
|
||||
dst = '/tmp/' + "".join([random.choice(string.letters) for i in xrange(10)]) + '.ogg'
|
||||
self.cue_file.cue(src, dst, 5, 5)
|
||||
src_length = OggVorbis(src).info.length
|
||||
dst_length = OggVorbis(dst).info.length
|
||||
print src + " " + str(src_length)
|
||||
print dst + " " + str(dst_length)
|
||||
self.assertTrue(dst_length < src_length)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
195
pypo/pypo-dls.py
195
pypo/pypo-dls.py
|
@ -1,195 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
Python part of radio playout (pypo)
|
||||
|
||||
This function acts as a gateway between liquidsoap and the obp-api.
|
||||
Mainliy used to tell the platform what pypo/LS does.
|
||||
|
||||
Main case:
|
||||
- whenever Liquidsoap starts playing a new track, its on_metadata callback calls
|
||||
a function in liquidsoap (notify(m)) which then calls the python script here
|
||||
with the currently starting filename as parameter
|
||||
- this python script takes this parameter, tries to extract the actual
|
||||
media id from it, and then calls back to API to tell it about it.
|
||||
|
||||
"""
|
||||
|
||||
# python defaults (debian default)
|
||||
import time
|
||||
import os
|
||||
import traceback
|
||||
from optparse import *
|
||||
import sys
|
||||
import time
|
||||
import datetime
|
||||
import logging
|
||||
import logging.config
|
||||
import urllib
|
||||
import urllib2
|
||||
import string
|
||||
|
||||
import socket
|
||||
|
||||
# additional modules (should be checked)
|
||||
from configobj import ConfigObj
|
||||
|
||||
# custom imports
|
||||
from util import *
|
||||
from obp import *
|
||||
|
||||
PYPO_VERSION = '0.9'
|
||||
|
||||
#set up command-line options
|
||||
parser = OptionParser()
|
||||
|
||||
# help screeen / info
|
||||
usage = "%prog [options]" + " - notification gateway"
|
||||
parser = OptionParser(usage=usage)
|
||||
|
||||
#options
|
||||
parser.add_option("-p", "--playing", help="Tell daddy what is playing right now", metavar="path")
|
||||
|
||||
# parse options
|
||||
(options, args) = parser.parse_args()
|
||||
|
||||
# configure logging
|
||||
logging.config.fileConfig("logging.cfg")
|
||||
|
||||
# loading config file
|
||||
try:
|
||||
config = ConfigObj('config.cfg')
|
||||
TMP_DIR = config['tmp_dir']
|
||||
BASE_URL = config['base_url']
|
||||
API_BASE = BASE_URL + 'mod/medialibrary/'
|
||||
EXPORT_SOURCE = config['export_source']
|
||||
API_KEY = config['api_key']
|
||||
|
||||
except Exception, e:
|
||||
print 'error: ', e
|
||||
sys.exit()
|
||||
|
||||
|
||||
class Global:
|
||||
def __init__(self):
|
||||
print
|
||||
|
||||
def selfcheck(self):
|
||||
self.api_auth = urllib.urlencode({'api_key': API_KEY})
|
||||
self.api_client = api_client.api_client_factory(config)
|
||||
if (not self.api_client.is_server_compatible()):
|
||||
sys.exit()
|
||||
|
||||
class Notify:
|
||||
def __init__(self):
|
||||
|
||||
self.tmp_dir = TMP_DIR
|
||||
self.export_source = EXPORT_SOURCE
|
||||
|
||||
self.api_auth = urllib.urlencode({'api_key': API_KEY})
|
||||
self.api_client = api_client.api_client_factory(config)
|
||||
|
||||
|
||||
def start_playing(self, options):
|
||||
logger = logging.getLogger("start_playing")
|
||||
|
||||
tnow = time.localtime(time.time())
|
||||
|
||||
path = options
|
||||
|
||||
try:
|
||||
file = path.split("/")[-1:][0]
|
||||
if file.find('_cue_') > 0:
|
||||
id = file.split("_cue_")[0]
|
||||
else:
|
||||
id = file.split(".")[-2:][0]
|
||||
|
||||
except Exception, e:
|
||||
#print e
|
||||
id = False
|
||||
|
||||
try:
|
||||
id = int(id)
|
||||
except Exception, e:
|
||||
#print e
|
||||
id = False
|
||||
|
||||
print
|
||||
print "Media ID: ",
|
||||
print id
|
||||
|
||||
# self.api_client.update_start_playing(id, self.export_source, path)
|
||||
txt = "test this update"
|
||||
|
||||
# Echo client program
|
||||
HOST = '172.16.16.128' # The remote host
|
||||
PORT = 50008 # The same port as used by the server
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
s.connect((HOST, PORT))
|
||||
|
||||
s.send('client_zzzz')
|
||||
s.send("\r\n")
|
||||
data = s.recv(1024)
|
||||
print data;
|
||||
|
||||
s.send('RS_DLS_VERSION' + ' ' + '1')
|
||||
s.send("\r\n")
|
||||
data = s.recv(1024)
|
||||
print data;
|
||||
|
||||
s.send('SERVICE' + ' ' + 'OPENBRO+')
|
||||
s.send("\r\n")
|
||||
|
||||
s.send('PASSWORD' + ' ' + 'OPENBRO+')
|
||||
s.send("\r\n")
|
||||
data = s.recv(1024)
|
||||
print data;
|
||||
|
||||
s.send('CLEAR_DLS')
|
||||
s.send("\r\n")
|
||||
|
||||
s.send('SET_DLS' + ' ' + txt)
|
||||
s.send("\r\n")
|
||||
data = s.recv(1024)
|
||||
print data;
|
||||
|
||||
s.close()
|
||||
|
||||
print data
|
||||
|
||||
if data == "session":
|
||||
print 'KKK'
|
||||
|
||||
time.sleep(0.1)
|
||||
print 'DONE'
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print
|
||||
print '#########################################'
|
||||
print '# *** pypo *** #'
|
||||
print '# pypo notification gateway #'
|
||||
print '#########################################'
|
||||
print
|
||||
|
||||
# initialize
|
||||
g = Global()
|
||||
g.selfcheck()
|
||||
n = Notify()
|
||||
|
||||
|
||||
run = True
|
||||
while run == True:
|
||||
|
||||
logger = logging.getLogger("pypo notify")
|
||||
|
||||
while options.playing:
|
||||
try: n.start_playing(options.playing)
|
||||
except Exception, e:
|
||||
print e
|
||||
sys.exit()
|
||||
|
||||
sys.exit()
|
|
@ -1,15 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
clear
|
||||
echo
|
||||
echo "##############################"
|
||||
echo "# STARTING PYPO MULTI-LOG #"
|
||||
echo "##############################"
|
||||
sleep 1
|
||||
clear
|
||||
|
||||
# split
|
||||
multitail -s 2 /var/log/pypo/debug.log \
|
||||
/var/log/pypo-push/log/main/current \
|
||||
/var/log/pypo-fetch/log/main/current \
|
||||
/var/log/pypo-liquidsoap/log/main/current
|
|
@ -1,233 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
Python part of radio playout (pypo)
|
||||
|
||||
This function acts as a gateway between liquidsoap and the server API.
|
||||
Mainly used to tell the platform what pypo/liquidsoap does.
|
||||
|
||||
Main case:
|
||||
- whenever LS starts playing a new track, its on_metadata callback calls
|
||||
a function in ls (notify(m)) which then calls the python script here
|
||||
with the currently starting filename as parameter
|
||||
- this python script takes this parameter, tries to extract the actual
|
||||
media id from it, and then calls back to the API to tell about it about it.
|
||||
|
||||
"""
|
||||
|
||||
# python defaults (debian default)
|
||||
import time
|
||||
import os
|
||||
import traceback
|
||||
from optparse import *
|
||||
import sys
|
||||
import time
|
||||
import datetime
|
||||
import logging
|
||||
import logging.config
|
||||
import urllib
|
||||
import urllib2
|
||||
import string
|
||||
|
||||
# additional modules (should be checked)
|
||||
from configobj import ConfigObj
|
||||
|
||||
# custom imports
|
||||
from util import *
|
||||
from api_clients import *
|
||||
from dls import *
|
||||
|
||||
PYPO_VERSION = '0.9'
|
||||
|
||||
|
||||
# Set up command-line options
|
||||
parser = OptionParser()
|
||||
|
||||
# help screeen / info
|
||||
usage = "%prog [options]" + " - notification gateway"
|
||||
parser = OptionParser(usage=usage)
|
||||
|
||||
# Options
|
||||
parser.add_option("-d", "--data", help="Pass JSON data from liquidsoap into this script.", metavar="data")
|
||||
#parser.add_option("-p", "--playing", help="Tell server what is playing right now.", default=False, action="store_true", dest="playing")
|
||||
#parser.add_option("-t", "--playlist-type", help="", metavar="playlist_type")
|
||||
parser.add_option("-m", "--media-id", help="ID of the file that is currently playing.", metavar="media_id")
|
||||
#parser.add_option("-U", "--user-id", help="", metavar="user_id")
|
||||
#parser.add_option("-P", "--playlist-id", help="", metavar="playlist_id")
|
||||
#parser.add_option("-T", "--transmission-id", help="", metavar="transmission_id")
|
||||
#parser.add_option("-E", "--export-source", help="", metavar="export_source")
|
||||
|
||||
# parse options
|
||||
(options, args) = parser.parse_args()
|
||||
|
||||
# configure logging
|
||||
logging.config.fileConfig("logging.cfg")
|
||||
|
||||
# loading config file
|
||||
try:
|
||||
config = ConfigObj('config.cfg')
|
||||
|
||||
except Exception, e:
|
||||
print 'error: ', e
|
||||
sys.exit()
|
||||
|
||||
|
||||
class Global:
|
||||
def __init__(self):
|
||||
print
|
||||
|
||||
def selfcheck(self):
|
||||
pass
|
||||
#self.api_client = api_client.api_client_factory(config)
|
||||
#self.api_client.check_version()
|
||||
|
||||
class Notify:
|
||||
def __init__(self):
|
||||
self.api_client = api_client.api_client_factory(config)
|
||||
#self.dls_client = DlsClient('127.0.0.128', 50008, 'myusername', 'mypass')
|
||||
|
||||
|
||||
def notify_media_start_playing(self, data, media_id):
|
||||
logger = logging.getLogger()
|
||||
#tnow = time.localtime(time.time())
|
||||
|
||||
logger.debug('#################################################')
|
||||
logger.debug('# Calling server to update about what\'s playing #')
|
||||
logger.debug('#################################################')
|
||||
logger.debug('data = '+ str(data))
|
||||
#print 'options.data = '+ options.data
|
||||
#data = json.read(options.data)
|
||||
response = self.api_client.notify_media_item_start_playing(data, media_id)
|
||||
logger.debug("Response: "+str(response))
|
||||
|
||||
#def start_playing(self, options):
|
||||
# logger = logging.getLogger("start_playing")
|
||||
# tnow = time.localtime(time.time())
|
||||
#
|
||||
# #print options
|
||||
#
|
||||
# logger.debug('#################################################')
|
||||
# logger.debug('# Calling server to update about what\'s playing #')
|
||||
# logger.debug('#################################################')
|
||||
#
|
||||
# if int(options.playlist_type) < 5:
|
||||
# logger.debug('seems to be a playlist')
|
||||
#
|
||||
# try:
|
||||
# media_id = int(options.media_id)
|
||||
# except Exception, e:
|
||||
# media_id = 0
|
||||
#
|
||||
# response = self.api_client.update_start_playing(options.playlist_type, options.export_source, media_id, options.playlist_id, options.transmission_id)
|
||||
#
|
||||
# logger.debug(response)
|
||||
#
|
||||
# if int(options.playlist_type) == 6:
|
||||
# logger.debug('seems to be a couchcast')
|
||||
#
|
||||
# try:
|
||||
# media_id = int(options.media_id)
|
||||
# except Exception, e:
|
||||
# media_id = 0
|
||||
#
|
||||
# response = self.api_client.update_start_playing(options.playlist_type, options.export_source, media_id, options.playlist_id, options.transmission_id)
|
||||
#
|
||||
# logger.debug(response)
|
||||
#
|
||||
# sys.exit()
|
||||
|
||||
#def start_playing_legacy(self, options):
|
||||
# logger = logging.getLogger("start_playing")
|
||||
# tnow = time.localtime(time.time())
|
||||
#
|
||||
# print '#################################################'
|
||||
# print '# Calling server to update about what\'s playing #'
|
||||
# print '#################################################'
|
||||
#
|
||||
# path = options
|
||||
#
|
||||
# print
|
||||
# print path
|
||||
# print
|
||||
#
|
||||
# if 'pl_id' in path:
|
||||
# print 'seems to be a playlist'
|
||||
# type = 'playlist'
|
||||
# id = path[5:]
|
||||
#
|
||||
# elif 'text' in path:
|
||||
# print 'seems to be a playlist'
|
||||
# type = 'text'
|
||||
# id = path[4:]
|
||||
# print id
|
||||
#
|
||||
# else:
|
||||
# print 'seems to be a single track (media)'
|
||||
# type = 'media'
|
||||
# try:
|
||||
# file = path.split("/")[-1:][0]
|
||||
# if file.find('_cue_') > 0:
|
||||
# id = file.split("_cue_")[0]
|
||||
# else:
|
||||
# id = file.split(".")[-2:][0]
|
||||
#
|
||||
# except Exception, e:
|
||||
# #print e
|
||||
# id = False
|
||||
#
|
||||
# try:
|
||||
# id = id
|
||||
# except Exception, e:
|
||||
# #print e
|
||||
# id = False
|
||||
#
|
||||
# print
|
||||
# print type + " id: ",
|
||||
# print id
|
||||
#
|
||||
#
|
||||
# response = self.api_client.update_start_playing(type, id, self.export_source, path)
|
||||
#
|
||||
# print 'DONE'
|
||||
#
|
||||
# try:
|
||||
# txt = response['txt']
|
||||
# print '#######################################'
|
||||
# print txt
|
||||
# print '#######################################'
|
||||
# #self.dls_client.set_txt(txt)
|
||||
#
|
||||
# except Exception, e:
|
||||
# print e
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print
|
||||
print '#########################################'
|
||||
print '# *** pypo *** #'
|
||||
print '# pypo notification gateway #'
|
||||
print '#########################################'
|
||||
|
||||
# initialize
|
||||
g = Global()
|
||||
logger = logging.getLogger()
|
||||
#if options.playing:
|
||||
# try: n.start_playing(options)
|
||||
# except Exception, e:
|
||||
# print e
|
||||
# sys.exit()
|
||||
if not options.data:
|
||||
print "NOTICE: 'data' command-line argument not given."
|
||||
sys.exit()
|
||||
|
||||
if not options.media_id:
|
||||
print "NOTICE: 'media_id' command-line argument not given."
|
||||
sys.exit()
|
||||
|
||||
try:
|
||||
g.selfcheck()
|
||||
n = Notify()
|
||||
n.notify_media_start_playing(options.data, options.media_id)
|
||||
except Exception, e:
|
||||
print e
|
|
@ -1,23 +0,0 @@
|
|||
This directory contains scripts not directly related to pypo
|
||||
These mainly are things related to liquidsoap & playout
|
||||
|
||||
I added those scripts here to have them at hand for
|
||||
development and also to update/share them via svn
|
||||
|
||||
|
||||
scripts here:
|
||||
|
||||
- ls_run.sh
|
||||
wrapper to run liquid soap. makes sure that the "current" playlist is
|
||||
filled with silence
|
||||
|
||||
- ls_script.liq (called by ls_run.sh)
|
||||
the main liquidsoap control-script
|
||||
|
||||
- ls_cue.liq (included by ls_script.liq)
|
||||
contains a custom protocol that registers the cue-in/out values from the playlist script
|
||||
|
||||
- cue_file.py (called by ls_cue.liq)
|
||||
a wrapper that does the actual cutting.
|
||||
it is called with: path_to_file[path] cue_in[ss.ms] cue_out[ss.ms] and does the mp3 cutting (with mp3cut)
|
||||
returns a temporary file that can be used by ls (make sure to set "TEMP_DIR" in script)
|
|
@ -1,141 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
|
||||
"""
|
||||
cue script that gets called by liquidsoap if a file in the playlist
|
||||
gives orders to cue (in/out). eg:
|
||||
cue_file:cue_in=90.0,cue_out=110.0:annotate:***
|
||||
|
||||
cue_in is number of seconds from the beginning of the file.
|
||||
cue_out is number of seconds from the end of the file.
|
||||
|
||||
params: path_to_file, cue_in [float, seconds], cue_out [float, seconds]
|
||||
returns: path to the cued temp-file
|
||||
|
||||
examples:
|
||||
calling: ./cue_file.py /storage/pypo/cache/2010-06-25-15-05-00/35.mp3 10 120.095
|
||||
returns: /tmp/lstf_UwDKcEngvF
|
||||
|
||||
In this example, the first 10 seconds and last 120.095 seconds are cut off. The
|
||||
middle part of the file is returned.
|
||||
|
||||
One thing to mention here:
|
||||
The way pypo (ab)uses liquidsoap can bring in some unwanted effects. liquidsoap
|
||||
is built in a way that it tries to collect the needed files to playout in advance.
|
||||
we 'force' liquidsoap to immediately start playing a newly loaded list, so ls has
|
||||
no time to prepare the files. If a file is played without cues, this does not affect
|
||||
the playout too much. My testing on a lame VM added a delay of +/- 10ms.
|
||||
|
||||
If the first file in a playlist is cued, the "mp3cut" command takes time to execute.
|
||||
On the same VM this takes an additional 200ms for an average size mp3-file.
|
||||
So the playout will start a bit delayed. This should not be a too big issue, but
|
||||
think about this behaviour if you eg access the files via network (nas) as the reading
|
||||
of files could take some time as well.
|
||||
|
||||
So maybe we should think about a different implementation. One way would be to do the
|
||||
cueing during playlist preparation, so all the files would be pre-cut when they are
|
||||
passed to liquidsoap.
|
||||
Additionally this would allow to run an unpathed version of ls.
|
||||
|
||||
"""
|
||||
|
||||
import sys
|
||||
import shutil
|
||||
import random
|
||||
import string
|
||||
import time
|
||||
from datetime import timedelta
|
||||
import os
|
||||
|
||||
from mutagen.mp3 import MP3
|
||||
from mutagen.oggvorbis import OggVorbis
|
||||
|
||||
TEMP_DIR = '/tmp/';
|
||||
|
||||
|
||||
sys.stderr.write('\n** starting mp3/ogg cutter **\n\n')
|
||||
|
||||
try: src = sys.argv[1]
|
||||
except Exception, e:
|
||||
sys.stderr.write('No file given. Exiting...\n')
|
||||
sys.exit()
|
||||
|
||||
try: cue_in = float(sys.argv[2])
|
||||
except Exception, e:
|
||||
cue_in = float(0)
|
||||
pass
|
||||
|
||||
try: cue_out = float(sys.argv[3])
|
||||
except Exception, e:
|
||||
cue_out = float(0)
|
||||
pass
|
||||
|
||||
sys.stderr.write('in: %s - out: %s file: %s \n' % (cue_in, cue_out, src))
|
||||
dst = TEMP_DIR + 'lstf_' + "".join( [random.choice(string.letters) for i in xrange(10)] )
|
||||
#TODO, there is no checking whether this randomly generated file name already exists!
|
||||
|
||||
|
||||
# get length of track using mutagen.
|
||||
#audio
|
||||
#command
|
||||
if src.lower().endswith('.mp3'):
|
||||
audio = MP3(src)
|
||||
dur = round(audio.info.length, 3)
|
||||
|
||||
sys.stderr.write('duration: ' + str(dur) + '\n')
|
||||
|
||||
cue_out = round(float(dur) - cue_out, 3)
|
||||
|
||||
str_cue_in = str(timedelta(seconds=cue_in)).replace(".", "+") # hh:mm:ss+mss, eg 00:00:20+000
|
||||
str_cue_out = str(timedelta(seconds=cue_out)).replace(".", "+") #
|
||||
|
||||
"""
|
||||
now a bit a hackish part, don't know how to do this better...
|
||||
need to cut the digits after the "+"
|
||||
|
||||
"""
|
||||
ts = str_cue_in.split("+")
|
||||
try:
|
||||
if len(ts[1]) == 6:
|
||||
ts[1] = ts[1][0:3]
|
||||
str_cue_in = "%s+%s" % (ts[0], ts[1])
|
||||
except Exception, e:
|
||||
pass
|
||||
|
||||
ts = str_cue_out.split("+")
|
||||
try:
|
||||
if len(ts[1]) == 6:
|
||||
ts[1] = ts[1][0:3]
|
||||
str_cue_out = "%s+%s" % (ts[0], ts[1])
|
||||
except Exception, e:
|
||||
pass
|
||||
|
||||
sys.stderr.write('in: ' + str_cue_in + '\n')
|
||||
sys.stderr.write('abs: ' + str(str_cue_out) + '\n\n')
|
||||
|
||||
command = 'mp3cut -o %s -t %s-%s %s' % (dst, str_cue_in, str_cue_out, src)
|
||||
elif src.lower().endswith('.ogg'):
|
||||
audio = OggVorbis(src)
|
||||
dur = audio.info.length
|
||||
sys.stderr.write('duration: ' + str(dur) + '\n')
|
||||
|
||||
cue_out = float(dur) - cue_out
|
||||
|
||||
#convert input format of ss.mmm to milliseconds and to string<
|
||||
str_cue_in = str(int(round(cue_in*1000)))
|
||||
|
||||
#convert input format of ss.mmm to milliseconds and to string
|
||||
str_cue_out = str(int(round(cue_out*1000)))
|
||||
|
||||
command = 'oggCut -s %s -e %s %s %s' % (str_cue_in, str_cue_out, src, dst)
|
||||
else:
|
||||
sys.stderr.write('File name with invalid extension. Exiting...\n')
|
||||
sys.exit()
|
||||
|
||||
|
||||
|
||||
sys.stderr.write(command + '\n\n\n')
|
||||
os.system(command + ' > /dev/null 2>&1')
|
||||
|
||||
print dst + "\n";
|
|
@ -1,70 +0,0 @@
|
|||
|
||||
#########################################
|
||||
# A/B queue-setup daypart
|
||||
#########################################
|
||||
|
||||
# a/b queue setup
|
||||
daypart_q0 = request.queue(conservative=true,length=600.,id="daypart_q0")
|
||||
daypart_q1 = request.queue(conservative=true,length=600.,id="daypart_q1")
|
||||
|
||||
daypart_q0 = audio_to_stereo(daypart_q0)
|
||||
daypart_q1 = audio_to_stereo(daypart_q1)
|
||||
|
||||
daypart_active = ref 0
|
||||
daypart_queue = ref 1
|
||||
daypart_q0_enabled = ref false
|
||||
daypart_q1_enabled = ref false
|
||||
|
||||
# push function, enqueues file in inactive queue (does not start automatically)
|
||||
def daypart_push(s)
|
||||
list.hd(server.execute("daypart_q#{!daypart_queue}.push #{s}"))
|
||||
print('push to #{!daypart_queue} - #{s}')
|
||||
"Done"
|
||||
end
|
||||
|
||||
|
||||
# flips the queues
|
||||
def daypart_flip()
|
||||
|
||||
# set a/b-queue corresponding to active, see fallback below
|
||||
if !daypart_active==1 then daypart_q0_enabled:=true else daypart_q0_enabled:=false end
|
||||
if !daypart_active==0 then daypart_q1_enabled:=true else daypart_q1_enabled:=false end
|
||||
|
||||
# get playing (active) queue and flush it
|
||||
l = list.hd(server.execute("daypart_q#{!daypart_active}.queue"))
|
||||
l = string.split(separator=" ",l)
|
||||
list.iter(fun (rid) -> ignore(server.execute("daypart_q#{!daypart_active}.ignore #{rid}")), l)
|
||||
|
||||
# skip the playing item
|
||||
# source.skip(if !daypart_active==0 then daypart_q0 else daypart_q1 end)
|
||||
|
||||
# flip variables
|
||||
daypart_active := 1-!daypart_active
|
||||
daypart_queue := 1-!daypart_active
|
||||
|
||||
"Done"
|
||||
end
|
||||
|
||||
|
||||
# print status
|
||||
def daypart_status()
|
||||
print('daypart_active: #{!daypart_active}')
|
||||
print('daypart_queue : #{!daypart_queue}')
|
||||
"Done"
|
||||
end
|
||||
|
||||
# register for telnet access
|
||||
server.register(namespace="daypart","push", daypart_push)
|
||||
server.register(namespace="daypart","flip", fun (_) -> daypart_flip())
|
||||
server.register(namespace="daypart","status", fun (_) -> daypart_status())
|
||||
|
||||
|
||||
# activate / deactivate queues, needed for fallback to work
|
||||
daypart_q0 = switch(track_sensitive=true, [({!daypart_q0_enabled},daypart_q0)])
|
||||
daypart_q1 = switch(track_sensitive=true, [({!daypart_q1_enabled},daypart_q1)])
|
||||
daypart_q_holder = fallback(track_sensitive=true, [daypart_q0, daypart_q1])
|
||||
|
||||
|
||||
# finally the resulting daypart source
|
||||
daypart = fallback(track_sensitive=false, [daypart_q_holder, default])
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
#######################################################################
|
||||
# Dynamic variables
|
||||
#######################################################################
|
||||
|
||||
playlist_type = ref '0'
|
||||
pypo_data = ref '0'
|
||||
|
||||
def set_playlist_type(s)
|
||||
playlist_type := s
|
||||
end
|
||||
|
||||
def set_pypo_data(s)
|
||||
pypo_data := s
|
||||
end
|
||||
|
||||
server.register(namespace="vars", "playlist_type", fun (s) -> begin set_playlist_type(s) "Done!" end)
|
||||
server.register(namespace="vars", "pypo_data", fun (s) -> begin set_pypo_data(s) "Done!" end)
|
|
@ -1,20 +0,0 @@
|
|||
#######################################################################
|
||||
# Live input - From external icecast server
|
||||
#######################################################################
|
||||
live_in = input.http(id="live_in",autostart=false,buffer=.1, max=12.,couchcaster_list)
|
||||
live_in = buffer(id="buffer_live_in",buffer=.1,fallible=true,live_in)
|
||||
live_in = mksafe(live_in)
|
||||
|
||||
live_active = ref false
|
||||
def live_switch(i)
|
||||
print(i)
|
||||
if i=='1' then live_active:=true else live_active:=false end
|
||||
print(live_active)
|
||||
"Done"
|
||||
end
|
||||
server.register(namespace="live","active", live_switch)
|
||||
|
||||
live = switch(track_sensitive=false, [({!live_active},live_in)])
|
||||
|
||||
to_live_s = to_live(jingles_cc)
|
||||
to_scheduler_s = to_scheduler()
|
|
@ -1,22 +0,0 @@
|
|||
########################################
|
||||
# call pypo api gateway
|
||||
########################################
|
||||
|
||||
def notify(m)
|
||||
|
||||
if !playlist_type=='5' then
|
||||
#print('livesession')
|
||||
system("./notify.sh --data='#{!pypo_data}' --media-id=#{m['media_id']} --export-source=scheduler")
|
||||
end
|
||||
|
||||
if !playlist_type=='6' then
|
||||
#print('couchcaster')
|
||||
system("./notify.sh --data='#{!pypo_data}' --media-id=#{m['media_id']} --export-source=scheduler")
|
||||
end
|
||||
|
||||
if !playlist_type=='0' or !playlist_type=='1' or !playlist_type=='2' or !playlist_type=='3' or !playlist_type=='4' then
|
||||
#print('include_notify.liq: notify on playlist')
|
||||
system("./notify.sh --data='#{!pypo_data}' --media-id=#{m['media_id']}")
|
||||
end
|
||||
|
||||
end
|
|
@ -1,78 +0,0 @@
|
|||
|
||||
#########################################
|
||||
# A/B queue-setup Scheduler
|
||||
#########################################
|
||||
|
||||
# a/b queue setup
|
||||
scheduler_q0 = request.queue(conservative=true,length=600.,id="scheduler_q0")
|
||||
scheduler_q1 = request.queue(conservative=true,length=600.,id="scheduler_q1")
|
||||
|
||||
scheduler_q0 = audio_to_stereo(scheduler_q0)
|
||||
scheduler_q1 = audio_to_stereo(scheduler_q1)
|
||||
|
||||
scheduler_active = ref 0
|
||||
scheduler_queue = ref 1
|
||||
scheduler_q0_enabled = ref false
|
||||
scheduler_q1_enabled = ref false
|
||||
|
||||
# push function, enqueues file in inactive queue (does not start automatically)
|
||||
def scheduler_push(s)
|
||||
list.hd(server.execute("scheduler_q#{!scheduler_queue}.push #{s}"))
|
||||
print('push to #{!scheduler_queue} - #{s}')
|
||||
"Done"
|
||||
end
|
||||
|
||||
|
||||
# flips the queues
|
||||
def scheduler_flip()
|
||||
|
||||
# set a/b-queue corresponding to active, see fallback below
|
||||
if !scheduler_active==1 then scheduler_q0_enabled:=true else scheduler_q0_enabled:=false end
|
||||
if !scheduler_active==0 then scheduler_q1_enabled:=true else scheduler_q1_enabled:=false end
|
||||
|
||||
# get playing (active) queue and flush it
|
||||
l = list.hd(server.execute("scheduler_q#{!scheduler_active}.queue"))
|
||||
l = string.split(separator=" ",l)
|
||||
list.iter(fun (rid) -> ignore(server.execute("scheduler_q#{!scheduler_active}.ignore #{rid}")), l)
|
||||
|
||||
# skip the playing item
|
||||
source.skip(if !scheduler_active==0 then scheduler_q0 else scheduler_q1 end)
|
||||
|
||||
# flip variables
|
||||
scheduler_active := 1-!scheduler_active
|
||||
scheduler_queue := 1-!scheduler_active
|
||||
|
||||
|
||||
"Done"
|
||||
end
|
||||
|
||||
|
||||
# print status
|
||||
def scheduler_status()
|
||||
print('scheduler_active: #{!scheduler_active}')
|
||||
print('scheduler_queue : #{!scheduler_queue}')
|
||||
print('pypo_data: #{!pypo_data}')
|
||||
|
||||
#print('user_id: #{!user_id}')
|
||||
#print('playlist_id: #{!playlist_id}')
|
||||
#print('transmission_id: #{!transmission_id}')
|
||||
#print('playlist_type: #{!playlist_type}')
|
||||
|
||||
"Done"
|
||||
end
|
||||
|
||||
# register for telnet access
|
||||
server.register(namespace="scheduler","push", scheduler_push)
|
||||
server.register(namespace="scheduler","flip", fun (_) -> scheduler_flip())
|
||||
server.register(namespace="scheduler","status", fun (_) -> scheduler_status())
|
||||
|
||||
|
||||
# activate / deactivate queues, needed for fallback to work
|
||||
scheduler_q0 = switch(track_sensitive=true, [({!scheduler_q0_enabled},scheduler_q0)])
|
||||
scheduler_q1 = switch(track_sensitive=true, [({!scheduler_q1_enabled},scheduler_q1)])
|
||||
scheduler_q_holder = fallback(track_sensitive=true, [scheduler_q0, scheduler_q1])
|
||||
|
||||
|
||||
# finally the resulting scheduler source
|
||||
scheduler = fallback(track_sensitive=false, [scheduler_q_holder, default])
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
# Define a transition that fades out the
|
||||
# old source, adds a single, and then
|
||||
# plays the new source
|
||||
def to_live(jingle,old,new) =
|
||||
# Fade out old source
|
||||
old = fade.final(old)
|
||||
# Supperpose the jingle
|
||||
s = add([jingle,old])
|
||||
# Compose this in sequence with
|
||||
# the new source
|
||||
sequence([s,new])
|
||||
end
|
||||
|
||||
def to_scheduler(old,new) =
|
||||
# We skip the file
|
||||
# currently in new
|
||||
# in order to being with
|
||||
# a fresh file
|
||||
# source.skip(new)
|
||||
sequence([old,new])
|
||||
end
|
||||
|
||||
# A transition when switching back to files:
|
||||
def to_file(old,new) =
|
||||
# We skip the file
|
||||
# currently in new
|
||||
# in order to being with
|
||||
# a fresh file
|
||||
# source.skip(new)
|
||||
sequence([old,new])
|
||||
end
|
||||
|
||||
|
||||
def dp_to_scheduler(old,new) =
|
||||
old = fade.final(type='log',duration=2.1,old)
|
||||
sequence([old,new])
|
||||
end
|
|
@ -1,6 +0,0 @@
|
|||
|
||||
DISTFILES = $(wildcard *.in) Makefile ask-liquidsoap.rb ask-liquidsoap.pl \
|
||||
$(wildcard *.liq) extract-replaygain
|
||||
|
||||
top_srcdir = ..
|
||||
include $(top_srcdir)/Makefile.rules
|
|
@ -1,12 +0,0 @@
|
|||
#!/usr/bin/perl -w
|
||||
|
||||
use strict ;
|
||||
use Net::Telnet ;
|
||||
|
||||
my $telnet = new Net::Telnet ( Timeout=>10, Errmode=>'die', Port=>1234) ;
|
||||
$telnet->open('localhost') ;
|
||||
|
||||
die "Usage: $0 <command>\n" unless @ARGV ;
|
||||
$telnet->print($ARGV[0]) ;
|
||||
my ($output,$end) = $telnet->waitfor('/END$/') ;
|
||||
print $output;
|
|
@ -1,13 +0,0 @@
|
|||
#!/usr/bin/ruby
|
||||
|
||||
require 'net/telnet'
|
||||
|
||||
liq_host = "localhost"
|
||||
liq_port = 1234
|
||||
|
||||
conn = Net::Telnet::new("Host" => liq_host, "Port" => liq_port)
|
||||
|
||||
conn.puts(ARGV[0])
|
||||
conn.waitfor("Match" => /^END$/) do |data|
|
||||
puts data.sub(/\nEND\n/,"")
|
||||
end
|
|
@ -1,314 +0,0 @@
|
|||
# These operators need to be updated..
|
||||
|
||||
|
||||
# Stream data from mplayer
|
||||
# @category Source / Input
|
||||
# @param s data URI.
|
||||
# @param ~restart restart on exit.
|
||||
# @param ~restart_on_error restart on exit with error.
|
||||
# @param ~buffer Duration of the pre-buffered data.
|
||||
# @param ~max Maximum duration of the buffered data.
|
||||
def input.mplayer(~id="input.mplayer",
|
||||
~restart=true,~restart_on_error=false,
|
||||
~buffer=0.2,~max=10.,s) =
|
||||
input.external(id=id,restart=restart,
|
||||
restart_on_error=restart_on_error,
|
||||
buffer=buffer,max=max,
|
||||
"mplayer -really-quiet -ao pcm:file=/dev/stdout \
|
||||
-vc null -vo null #{quote(s)} 2>/dev/null")
|
||||
end
|
||||
|
||||
|
||||
# Output the stream using aplay.
|
||||
# Using this turns "root.sync" to false
|
||||
# since aplay will do the synchronisation
|
||||
# @category Source / Output
|
||||
# @param ~id Output's ID
|
||||
# @param ~device Alsa pcm device name
|
||||
# @param ~restart_on_crash Restart external process on crash. If false, liquidsoap will stop.
|
||||
# @param ~fallible Allow the child source to fail, in which case the output will be (temporarily) stopped.
|
||||
# @param ~on_start Callback executed when outputting starts.
|
||||
# @param ~on_stop Callback executed when outputting stops.
|
||||
# @param s Source to play
|
||||
def output.aplay(~id="output.aplay",~device="default",
|
||||
~fallible=false,~on_start={()},~on_stop={()},
|
||||
~restart_on_crash=false,s)
|
||||
def aplay_p(m) =
|
||||
"aplay -D #{device}"
|
||||
end
|
||||
log(label=id,level=3,"Setting root.sync to false")
|
||||
set("root.sync",false)
|
||||
output.pipe.external(id=id,
|
||||
fallible=fallible,on_start=on_start,on_stop=on_stop,
|
||||
restart_on_crash=restart_on_crash,
|
||||
restart_on_new_track=false,
|
||||
process=aplay_p,s)
|
||||
end
|
||||
|
||||
%ifdef output.icecast.external
|
||||
# Output to icecast using the lame command line encoder.
|
||||
# @category Source / Output
|
||||
# @param ~id Output's ID
|
||||
# @param ~start Start output threads on operator initialization.
|
||||
# @param ~restart Restart output after a failure. By default, liquidsoap will stop if the output failed.
|
||||
# @param ~restart_delay Delay, in seconds, before attempting new connection, if restart is enabled.
|
||||
# @param ~restart_on_crash Restart external process on crash. If false, liquidsoap will stop.
|
||||
# @param ~restart_on_new_track Restart encoder upon new track.
|
||||
# @param ~restart_encoder_delay Restart the encoder after this delay, in seconds.
|
||||
# @param ~user User for shout source connection. Useful only in special cases, like with per-mountpoint users.
|
||||
# @param ~lame The lame binary
|
||||
# @param ~bitrate Encoder bitrate
|
||||
# @param ~swap Swap audio samples. Depends on local machine's endianess and lame's version. Test this parameter if you experience garbaged mp3 audio data. On intel 32 and 64 architectures, the parameter should be "true" for lame version >= 3.98.
|
||||
# @param ~dumpfile Dump stream to file, for debugging purpose. Disabled if empty.
|
||||
# @param ~protocol Protocol of the streaming server: 'http' for Icecast, 'icy' for Shoutcast.
|
||||
# @param ~fallible Allow the child source to fail, in which case the output will be (temporarily) stopped.
|
||||
# @param ~on_start Callback executed when outputting starts.
|
||||
# @param ~on_stop Callback executed when outputting stops.
|
||||
# @param s The source to output
|
||||
def output.icecast.lame(
|
||||
~id="output.icecast.lame",~start=true,
|
||||
~restart=false,~restart_delay=3,
|
||||
~host="localhost",~port=8000,
|
||||
~user="source",~password="hackme",
|
||||
~genre="Misc",~url="http://savonet.sf.net/",
|
||||
~description="OCaml Radio!",~public=true,
|
||||
~dumpfile="",~mount="Use [name]",
|
||||
~name="Use [mount]",~protocol="http",
|
||||
~lame="lame",~bitrate=128,~swap=false,
|
||||
~fallible=false,~on_start={()},~on_stop={()},
|
||||
~restart_on_crash=false,~restart_on_new_track=false,
|
||||
~restart_encoder_delay=3600,~headers=[],s)
|
||||
samplerate = get(default=44100,"frame.samplerate")
|
||||
samplerate = float_of_int(samplerate) / 1000.
|
||||
channels = get(default=2,"frame.channels")
|
||||
swap = if swap then "-x" else "" end
|
||||
mode =
|
||||
if channels == 2 then
|
||||
"j" # Encoding in joint stereo..
|
||||
else
|
||||
"m"
|
||||
end
|
||||
# Metadata update is set by ICY with icecast
|
||||
def lame_p(m)
|
||||
"#{lame} -b #{bitrate} -r --bitwidth 16 -s #{samplerate} \
|
||||
--signed -m #{mode} --nores #{swap} -t - -"
|
||||
end
|
||||
output.icecast.external(id=id,
|
||||
process=lame_p,bitrate=bitrate,start=start,
|
||||
restart=restart,restart_delay=restart_delay,
|
||||
host=host,port=port,user=user,password=password,
|
||||
genre=genre,url=url,description=description,
|
||||
public=public,dumpfile=dumpfile,restart_encoder_delay=restart_encoder_delay,
|
||||
name=name,mount=mount,protocol=protocol,
|
||||
header=false,restart_on_crash=restart_on_crash,
|
||||
restart_on_new_track=restart_on_new_track,headers=headers,
|
||||
fallible=fallible,on_start=on_start,on_stop=on_stop,
|
||||
s)
|
||||
end
|
||||
|
||||
# Output to shoutcast using the lame encoder.
|
||||
# @category Source / Output
|
||||
# @param ~id Output's ID
|
||||
# @param ~start Start output threads on operator initialization.
|
||||
# @param ~restart Restart output after a failure. By default, liquidsoap will stop if the output failed.
|
||||
# @param ~restart_delay Delay, in seconds, before attempting new connection, if restart is enabled.
|
||||
# @param ~restart_on_crash Restart external process on crash. If false, liquidsoap will stop.
|
||||
# @param ~restart_on_new_track Restart encoder upon new track.
|
||||
# @param ~restart_encoder_delay Restart the encoder after this delay, in seconds.
|
||||
# @param ~user User for shout source connection. Useful only in special cases, like with per-mountpoint users.
|
||||
# @param ~lame The lame binary
|
||||
# @param ~bitrate Encoder bitrate
|
||||
# @param ~icy_reset Reset shoutcast source buffer upon connecting (necessary for NSV).
|
||||
# @param ~dumpfile Dump stream to file, for debugging purpose. Disabled if empty.
|
||||
# @param ~fallible Allow the child source to fail, in which case the output will be (temporarily) stopped.
|
||||
# @param ~on_start Callback executed when outputting starts.
|
||||
# @param ~on_stop Callback executed when outputting stops.
|
||||
# @param s The source to output
|
||||
def output.shoutcast.lame(
|
||||
~id="output.shoutcast.mp3",~start=true,
|
||||
~restart=false,~restart_delay=3,
|
||||
~host="localhost",~port=8000,
|
||||
~user="source",~password="hackme",
|
||||
~genre="Misc",~url="http://savonet.sf.net/",
|
||||
~description="OCaml Radio!",~public=true,
|
||||
~dumpfile="",~name="Use [mount]",~icy_reset=true,
|
||||
~lame="lame",~aim="",~icq="",~irc="",
|
||||
~fallible=false,~on_start={()},~on_stop={()},
|
||||
~restart_on_crash=false,~restart_on_new_track=false,
|
||||
~restart_encoder_delay=3600,~bitrate=128,s) =
|
||||
icy_reset = if icy_reset then "1" else "0" end
|
||||
headers = [("icy-aim",aim),("icy-irc",irc),
|
||||
("icy-icq",icq),("icy-reset",icy_reset)]
|
||||
output.icecast.lame(
|
||||
id=id, headers=headers, lame=lame,
|
||||
bitrate=bitrate, start=start,
|
||||
restart=restart, restart_encoder_delay=restart_encoder_delay,
|
||||
host=host, port=port, user=user, password=password,
|
||||
genre=genre, url=url, description=description,
|
||||
public=public, dumpfile=dumpfile,
|
||||
restart_on_crash=restart_on_crash,
|
||||
restart_on_new_track=restart_on_new_track,
|
||||
name=name, mount="/", protocol="icy",
|
||||
fallible=fallible,on_start=on_start,on_stop=on_stop,
|
||||
s)
|
||||
end
|
||||
|
||||
# Output to icecast using the flac command line encoder.
|
||||
# @category Source / Output
|
||||
# @param ~id Output's ID
|
||||
# @param ~start Start output threads on operator initialization.
|
||||
# @param ~restart Restart output after a failure. By default, liquidsoap will stop if the output failed.
|
||||
# @param ~restart_delay Delay, in seconds, before attempting new connection, if restart is enabled.
|
||||
# @param ~restart_on_crash Restart external process on crash. If false, liquidsoap will stop.
|
||||
# @param ~restart_on_new_track Restart encoder upon new track. If false, the resulting stream will have a single track.
|
||||
# @param ~restart_encoder_delay Restart the encoder after this delay, in seconds.
|
||||
# @param ~user User for shout source connection. Useful only in special cases, like with per-mountpoint users.
|
||||
# @param ~flac The flac binary
|
||||
# @param ~quality Encoder quality (0..8)
|
||||
# @param ~dumpfile Dump stream to file, for debugging purpose. Disabled if empty.
|
||||
# @param ~protocol Protocol of the streaming server: 'http' for Icecast, 'icy' for Shoutcast.
|
||||
# @param ~fallible Allow the child source to fail, in which case the output will be (temporarily) stopped.
|
||||
# @param ~on_start Callback executed when outputting starts.
|
||||
# @param ~on_stop Callback executed when outputting stops.
|
||||
# @param s The source to output
|
||||
def output.icecast.flac(
|
||||
~id="output.icecast.flac",~start=true,
|
||||
~restart=false,~restart_delay=3,
|
||||
~host="localhost",~port=8000,
|
||||
~user="source",~password="hackme",
|
||||
~genre="Misc",~url="http://savonet.sf.net/",
|
||||
~description="OCaml Radio!",~public=true,
|
||||
~dumpfile="",~mount="Use [name]",
|
||||
~name="Use [mount]",~protocol="http",
|
||||
~flac="flac",~quality=6,
|
||||
~restart_on_crash=false,
|
||||
~restart_on_new_track=true,
|
||||
~restart_encoder_delay=(-1),
|
||||
~fallible=false,~on_start={()},~on_stop={()},
|
||||
s)
|
||||
# We will use raw format, to
|
||||
# bypass input length value in WAV
|
||||
# header (input length is not known)
|
||||
channels = get(default=2,"frame.channels")
|
||||
samplerate = get(default=44100,"frame.samplerate")
|
||||
def flac_p(m)=
|
||||
def option(x) =
|
||||
"-T #{quote(fst(x))}=#{quote(snd(x))}"
|
||||
end
|
||||
m = list.map(option,m)
|
||||
m = string.concat(separator=" ",m)
|
||||
"#{flac} --force-raw-format --endian=little --channels=#{channels} \
|
||||
--bps=16 --sample-rate=#{samplerate} --sign=signed #{m} \
|
||||
-#{quality} --ogg -c -"
|
||||
end
|
||||
output.icecast.external(id=id,
|
||||
process=flac_p,bitrate=(-1),start=start,
|
||||
restart=restart,restart_delay=restart_delay,
|
||||
host=host,port=port,user=user,password=password,
|
||||
genre=genre,url=url,description=description,
|
||||
public=public,dumpfile=dumpfile,
|
||||
name=name,mount=mount,protocol=protocol,
|
||||
fallible=fallible,on_start=on_start,on_stop=on_stop,
|
||||
restart_on_new_track=restart_on_new_track,
|
||||
format="ogg",header=false,icy_metadata=false,
|
||||
restart_on_crash=restart_on_crash,
|
||||
restart_encoder_delay=restart_encoder_delay,
|
||||
s)
|
||||
end
|
||||
|
||||
# Output to icecast using the aacplusenc command line encoder.
|
||||
# @category Source / Output
|
||||
# @param ~id Output's ID
|
||||
# @param ~start Start output threads on operator initialization.
|
||||
# @param ~restart Restart output after a failure. By default, liquidsoap will stop if the output failed.
|
||||
# @param ~restart_delay Delay, in seconds, before attempting new connection, if restart is enabled.
|
||||
# @param ~restart_on_crash Restart external process on crash. If false, liquidsoap will stop.
|
||||
# @param ~restart_on_new_track Restart encoder upon new track.
|
||||
# @param ~restart_encoder_delay Restart the encoder after this delay, in seconds.
|
||||
# @param ~user User for shout source connection. Useful only in special cases, like with per-mountpoint users.
|
||||
# @param ~aacplusenc The aacplusenc binary
|
||||
# @param ~bitrate Encoder bitrate
|
||||
# @param ~dumpfile Dump stream to file, for debugging purpose. Disabled if empty.
|
||||
# @param ~protocol Protocol of the streaming server: 'http' for Icecast, 'icy' for Shoutcast.
|
||||
# @param ~fallible Allow the child source to fail, in which case the output will be (temporarily) stopped.
|
||||
# @param ~on_start Callback executed when outputting starts.
|
||||
# @param ~on_stop Callback executed when outputting stops.
|
||||
# @param s The source to output
|
||||
def output.icecast.aacplusenc(
|
||||
~id="output.icecast.aacplusenc",~start=true,
|
||||
~restart=false,~restart_delay=3,
|
||||
~host="localhost",~port=8000,
|
||||
~user="source",~password="hackme",
|
||||
~genre="Misc",~url="http://savonet.sf.net/",
|
||||
~description="OCaml Radio!",~public=true,
|
||||
~dumpfile="",~mount="Use [name]",
|
||||
~name="Use [mount]",~protocol="http",
|
||||
~aacplusenc="aacplusenc",~bitrate=64,
|
||||
~fallible=false,~on_start={()},~on_stop={()},
|
||||
~restart_on_crash=false,~restart_on_new_track=false,
|
||||
~restart_encoder_delay=3600,~headers=[],s)
|
||||
# Metadata update is set by ICY with icecast
|
||||
def aacplusenc_p(m)
|
||||
"#{aacplusenc} - - #{bitrate}"
|
||||
end
|
||||
output.icecast.external(id=id,
|
||||
process=aacplusenc_p,bitrate=bitrate,start=start,
|
||||
restart=restart,restart_delay=restart_delay,
|
||||
host=host,port=port,user=user,password=password,
|
||||
genre=genre,url=url,description=description,
|
||||
public=public,dumpfile=dumpfile,
|
||||
name=name,mount=mount,protocol=protocol,
|
||||
fallible=fallible,on_start=on_start,on_stop=on_stop,
|
||||
header=true,restart_on_crash=restart_on_crash,
|
||||
restart_on_new_track=restart_on_new_track,headers=headers,
|
||||
restart_encoder_delay=restart_encoder_delay,format="audio/aacp",s)
|
||||
end
|
||||
|
||||
# Output to shoutcast using the aacplusenc encoder.
|
||||
# @category Source / Output
|
||||
# @param ~id Output's ID
|
||||
# @param ~start Start output threads on operator initialization.
|
||||
# @param ~restart Restart output after a failure. By default, liquidsoap will stop if the output failed.
|
||||
# @param ~restart_delay Delay, in seconds, before attempting new connection, if restart is enabled.
|
||||
# @param ~restart_on_crash Restart external process on crash. If false, liquidsoap will stop.
|
||||
# @param ~restart_on_new_track Restart encoder upon new track.
|
||||
# @param ~restart_encoder_delay Restart the encoder after this delay, in seconds.
|
||||
# @param ~user User for shout source connection. Useful only in special cases, like with per-mountpoint users.
|
||||
# @param ~aacplusenc The aacplusenc binary
|
||||
# @param ~bitrate Encoder bitrate
|
||||
# @param ~icy_reset Reset shoutcast source buffer upon connecting (necessary for NSV).
|
||||
# @param ~dumpfile Dump stream to file, for debugging purpose. Disabled if empty.
|
||||
# @param ~fallible Allow the child source to fail, in which case the output will be (temporarily) stopped.
|
||||
# @param ~on_start Callback executed when outputting starts.
|
||||
# @param ~on_stop Callback executed when outputting stops.
|
||||
# @param s The source to output
|
||||
def output.shoutcast.aacplusenc(
|
||||
~id="output.shoutcast.aacplusenc",~start=true,
|
||||
~restart=false,~restart_delay=3,
|
||||
~host="localhost",~port=8000,
|
||||
~user="source",~password="hackme",
|
||||
~genre="Misc",~url="http://savonet.sf.net/",
|
||||
~description="OCaml Radio!",~public=true,
|
||||
~fallible=false,~on_start={()},~on_stop={()},
|
||||
~dumpfile="",~name="Use [mount]",~icy_reset=true,
|
||||
~aim="",~icq="",~irc="",~aacplusenc="aacplusenc",
|
||||
~restart_on_crash=false,~restart_on_new_track=false,
|
||||
~restart_encoder_delay=3600,~bitrate=64,s) =
|
||||
icy_reset = if icy_reset then "1" else "0" end
|
||||
headers = [("icy-aim",aim),("icy-irc",irc),
|
||||
("icy-icq",icq),("icy-reset",icy_reset)]
|
||||
output.icecast.aacplusenc(
|
||||
id=id, headers=headers, aacplusenc=aacplusenc,
|
||||
bitrate=bitrate, start=start,
|
||||
restart=restart, restart_delay=restart_delay,
|
||||
host=host, port=port, user=user, password=password,
|
||||
genre=genre, url=url, description=description,
|
||||
public=public, dumpfile=dumpfile,
|
||||
fallible=fallible,on_start=on_start,on_stop=on_stop,
|
||||
restart_on_crash=restart_on_crash, restart_encoder_delay=restart_encoder_delay,
|
||||
restart_on_new_track=restart_on_new_track,
|
||||
name=name, mount="/", protocol="icy",
|
||||
s)
|
||||
end
|
||||
%endif
|
||||
|
|
@ -1,191 +0,0 @@
|
|||
# Decoders, enabled when the binary is detected and the os is not Win32.
|
||||
|
||||
# Get_mime is not always defined
|
||||
# so we define a default in this case..
|
||||
my_get_mime = fun (_) -> ""
|
||||
%ifdef get_mime
|
||||
my_get_mime = get_mime
|
||||
%endif
|
||||
get_mime = my_get_mime
|
||||
|
||||
%ifdef add_decoder
|
||||
if test_process("which flac") then
|
||||
log(level=3,"Found flac binary: enabling flac external decoder.")
|
||||
flac_p = "flac -d -c - 2>/dev/null"
|
||||
def test_flac(file) =
|
||||
if test_process("which metaflac") then
|
||||
channels = list.hd(get_process_lines("metaflac \
|
||||
--show-channels #{quote(file)} \
|
||||
2>/dev/null"))
|
||||
# If the value is not an int, this returns 0 and we are ok :)
|
||||
int_of_string(channels)
|
||||
else
|
||||
# Try to detect using mime test..
|
||||
mime = get_mime(file)
|
||||
if string.match(pattern="flac",file) then
|
||||
# We do not know the number of audio channels
|
||||
# so setting to -1
|
||||
(-1)
|
||||
else
|
||||
# All tests failed: no audio decodable using flac..
|
||||
0
|
||||
end
|
||||
end
|
||||
end
|
||||
add_decoder(name="FLAC",description="Decode files using the flac \
|
||||
decoder binary.", test=test_flac,flac_p)
|
||||
else
|
||||
log(level=3,"Did not find flac binary: flac decoder disabled.")
|
||||
end
|
||||
%endif
|
||||
|
||||
if os.type != "Win32" then
|
||||
if test_process("which metaflac") then
|
||||
log(level=3,"Found metaflac binary: enabling flac external metadata \
|
||||
resolver.")
|
||||
def flac_meta(file)
|
||||
ret = get_process_lines("metaflac --export-tags-to=- \
|
||||
#{quote(file)} 2>/dev/null")
|
||||
ret = list.map(string.split(separator="="),ret)
|
||||
# Could be made better..
|
||||
def f(l',l)=
|
||||
if list.length(l) >= 2 then
|
||||
list.append([(list.hd(l),list.nth(l,1))],l')
|
||||
else
|
||||
if list.length(l) >= 1 then
|
||||
list.append([(list.hd(l),"")],l')
|
||||
else
|
||||
l'
|
||||
end
|
||||
end
|
||||
end
|
||||
list.fold(f,[],ret)
|
||||
end
|
||||
add_metadata_resolver("FLAC",flac_meta)
|
||||
else
|
||||
log(level=3,"Did not find metaflac binary: flac metadata resolver disabled.")
|
||||
end
|
||||
end
|
||||
|
||||
# A list of know extensions and content-type for AAC.
|
||||
# Values from http://en.wikipedia.org/wiki/Advanced_Audio_Coding
|
||||
# TODO: can we register a setting for that ??
|
||||
aac_mimes =
|
||||
["audio/aac", "audio/aacp", "audio/3gpp", "audio/3gpp2", "audio/mp4",
|
||||
"audio/MP4A-LATM", "audio/mpeg4-generic", "audio/x-hx-aac-adts"]
|
||||
aac_filexts = ["m4a", "m4b", "m4p", "m4v",
|
||||
"m4r", "3gp", "mp4", "aac"]
|
||||
|
||||
# Faad is not very selective so
|
||||
# We are checking only file that
|
||||
# end with a known extension or mime type
|
||||
def faad_test(file) =
|
||||
# Get the file's mime
|
||||
mime = get_mime(file)
|
||||
# Test mime
|
||||
if list.mem(mime,aac_mimes) then
|
||||
true
|
||||
else
|
||||
# Otherwise test file extension
|
||||
ret = string.extract(pattern='\.(.+)$',file)
|
||||
if list.length(ret) != 0 then
|
||||
ext = ret["1"]
|
||||
list.mem(ext,aac_filexts)
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if os.type != "Win32" then
|
||||
if test_process("which faad") then
|
||||
log(level=3,"Found faad binary: enabling external faad decoder and \
|
||||
metadata resolver.")
|
||||
faad_p = (fun (f) -> "faad -w #{quote(f)} 2>/dev/null")
|
||||
def test_faad(file) =
|
||||
if faad_test(file) then
|
||||
channels = list.hd(get_process_lines("faad -i #{quote(file)} 2>&1 | \
|
||||
grep 'ch,'"))
|
||||
ret = string.extract(pattern=", (\d) ch,",channels)
|
||||
ret =
|
||||
if list.length(ret) == 0 then
|
||||
# If we pass the faad_test, chances are
|
||||
# high that the file will contain aac audio data..
|
||||
"-1"
|
||||
else
|
||||
ret["1"]
|
||||
end
|
||||
int_of_string(default=(-1),ret)
|
||||
else
|
||||
0
|
||||
end
|
||||
end
|
||||
%ifdef add_oblivious_decoder
|
||||
add_oblivious_decoder(name="FAAD",description="Decode files using \
|
||||
the faad binary.", test=test_faad, faad_p)
|
||||
%endif
|
||||
def faad_meta(file) =
|
||||
if faad_test(file) then
|
||||
ret = get_process_lines("faad -i \
|
||||
#{quote(file)} 2>&1")
|
||||
# Yea, this is tuff programming (again) !
|
||||
def get_meta(l,s)=
|
||||
ret = string.extract(pattern="^(\w+):\s(.+)$",s)
|
||||
if list.length(ret) > 0 then
|
||||
list.append([(ret["1"],ret["2"])],l)
|
||||
else
|
||||
l
|
||||
end
|
||||
end
|
||||
list.fold(get_meta,[],ret)
|
||||
else
|
||||
[]
|
||||
end
|
||||
end
|
||||
add_metadata_resolver("FAAD",faad_meta)
|
||||
else
|
||||
log(level=3,"Did not find faad binary: faad decoder disabled.")
|
||||
end
|
||||
end
|
||||
|
||||
# Standard function for displaying metadata.
|
||||
# Shows artist and title, using "Unknown" when a field is empty.
|
||||
# @param m Metadata packet to be displayed.
|
||||
def string_of_metadata(m)
|
||||
artist = m["artist"]
|
||||
title = m["title"]
|
||||
artist = if ""==artist then "Unknown" else artist end
|
||||
title = if ""==title then "Unknown" else title end
|
||||
"#{artist} -- #{title}"
|
||||
end
|
||||
|
||||
# Use X On Screen Display to display metadata info.
|
||||
# @param ~color Color of the text.
|
||||
# @param ~position Position of the text (top|middle|bottom).
|
||||
# @param ~font Font used (xfontsel is your friend...)
|
||||
# @param ~display Function used to display a metadata packet.
|
||||
def osd_metadata(~color="green",~position="top",
|
||||
~font="-*-courier-*-r-*-*-*-240-*-*-*-*-*-*",
|
||||
~display=string_of_metadata,
|
||||
s)
|
||||
osd = 'osd_cat -p #{position} --font #{quote(font)}'
|
||||
^ ' --color #{color}'
|
||||
def feedback(m)
|
||||
system("echo #{quote(display(m))} | #{osd} &")
|
||||
end
|
||||
on_metadata(feedback,s)
|
||||
end
|
||||
|
||||
# Use notify to display metadata info.
|
||||
# @param ~urgency Urgency (low|normal|critical).
|
||||
# @param ~icon Icon filename or stock icon to display.
|
||||
# @param ~time Timeout in milliseconds.
|
||||
# @param ~display Function used to display a metadata packet.
|
||||
# @param ~title Title of the notification message.
|
||||
def notify_metadata(~urgency="low",~icon="stock_smiley-22",~time=3000,
|
||||
~display=string_of_metadata,
|
||||
~title="Liquidsoap: new track",s)
|
||||
send = 'notify-send -i #{icon} -u #{urgency}'
|
||||
^ ' -t #{time} #{quote(title)} '
|
||||
on_metadata(fun (m) -> system(send^quote(display(m))),s)
|
||||
end
|
|
@ -1,73 +0,0 @@
|
|||
#!/usr/bin/perl -w
|
||||
|
||||
use strict ;
|
||||
|
||||
my $file = $ARGV[0] || die ;
|
||||
|
||||
sub test_mime {
|
||||
my $file = shift ;
|
||||
if (`which file`) {
|
||||
return `file -b --mime-type "$file"`;
|
||||
}
|
||||
}
|
||||
|
||||
if (($file =~ /\.mp3$/i) || (test_mime($file) =~ /audio\/mpeg/)) {
|
||||
|
||||
if (`which mp3gain`) {
|
||||
|
||||
my $out = `mp3gain -q "$file" 2> /dev/null` ;
|
||||
$out =~ /Recommended "Track" dB change: (.*)$/m || die ;
|
||||
print "$1 dB\n" ;
|
||||
|
||||
} else {
|
||||
|
||||
print STDERR "Cannot find mp3gain binary!\n";
|
||||
|
||||
}
|
||||
|
||||
} elsif (($file =~ /\.ogg$/i) || (test_mime($file) =~ /application\/ogg/)) {
|
||||
|
||||
if ((`which vorbisgain`) && (`which ogginfo`)) {
|
||||
|
||||
system("vorbisgain -q -f \"$file\" 2>/dev/null >/dev/null") ;
|
||||
my $info = `ogginfo "$file"` ;
|
||||
$info =~ /REPLAYGAIN_TRACK_GAIN=(.*) dB/ || die ;
|
||||
print "$1 dB\n" ;
|
||||
|
||||
} else {
|
||||
|
||||
print STDERR "Cannot find vorbisgain or ogginfo!\n";
|
||||
|
||||
}
|
||||
|
||||
} elsif (($file =~ /\.flac$/i) || (test_mime($file) =~ /audio\/x-flac/)) {
|
||||
|
||||
if (`which metaflac`) {
|
||||
|
||||
my $info = `metaflac --show-tag=REPLAYGAIN_TRACK_GAIN "$file"` ;
|
||||
$info =~ /REPLAYGAIN_TRACK_GAIN=(.*) dB/;
|
||||
if (defined($1)) {
|
||||
|
||||
print "$1 dB\n" ;
|
||||
|
||||
} else {
|
||||
|
||||
system("metaflac --add-replay-gain \"$file\" \
|
||||
2>/dev/null >/dev/null") ;
|
||||
$info = `metaflac --show-tag=REPLAYGAIN_TRACK_GAIN "$file"` ;
|
||||
$info =~ /REPLAYGAIN_TRACK_GAIN=(.*) dB/ || die "Error in $file" ;
|
||||
print "$1 dB\n" ;
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
print STDERR "Cannot find metaflac!\n";
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
print STDERR "File format not supported...\n";
|
||||
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
# Launch with: screen -c interactive.screen
|
||||
screen -t Liquidsoap liquidsoap --interactive 'set("log.file.path","/tmp/interactive.log") system("echo \"setenv PID #{getpid()}\" > /tmp/interactive.env")'
|
||||
verbose
|
||||
# Yeah, this is a trick
|
||||
# to wait for interactive.env
|
||||
# to be created
|
||||
logfile /dev/null
|
||||
log
|
||||
source /tmp/interactive.env
|
||||
screen -t Log tail --pid=$PID -f /tmp/interactive.log
|
||||
split -v
|
||||
select 0
|
||||
focus
|
||||
select 1
|
||||
focus
|
|
@ -1,133 +0,0 @@
|
|||
|
||||
dummy = fun () -> log("Lastfm/audioscrobbler support was not compiled.")
|
||||
|
||||
%ifdef input.lastfm
|
||||
dummy = fun () -> ()
|
||||
|
||||
# Utility to compose last.fm URIs.
|
||||
# @category String
|
||||
# @param ~user Lastfm user
|
||||
# @param ~password Lastfm password
|
||||
# @param ~discovery Allow lastfm suggestions
|
||||
# @param radio URI, e.g. user/toots5446/playlist, globaltags/rocksteady.
|
||||
def lastfm.uri(~user="",~password="",~discovery=false,
|
||||
radio="globaltags/creative-commons")
|
||||
auth = if user == "" then "" else "#{user}:#{password}@" end
|
||||
discovery = if discovery == true then "1" else "0" end
|
||||
"lastfm://#{auth}#{radio}?discovery=#{discovery}"
|
||||
end
|
||||
|
||||
# Submit metadata to libre.fm using the audioscrobbler protocol.
|
||||
# @category Interaction
|
||||
# @param ~source Source for tracks. Should be one of: "broadcast", "user", "recommendation" or "unknown". Since liquidsoap is intented for radio broadcasting, this is the default. Sources other than user don't need duration to be set.
|
||||
# @param ~length Try to submit length information. This operation can be CPU intensive. Value forced to true when used with the "user" source type.
|
||||
def librefm.submit(~user,~password,~source="broadcast",~length=false,m) =
|
||||
audioscrobbler.submit(user=user,password=password,
|
||||
source=source,length=length,
|
||||
host="turtle.libre.fm",port=80,
|
||||
m)
|
||||
end
|
||||
|
||||
# Submit metadata to lastfm.fm using the audioscrobbler protocol.
|
||||
# @category Interaction
|
||||
# @param ~source Source for tracks. Should be one of: "broadcast", "user", "recommendation" or "unknown". Since liquidsoap is intented for radio broadcasting, this is the default. Sources other than user don't need duration to be set.
|
||||
# @param ~length Try to submit length information. This operation can be CPU intensive. Value forced to true when used with the "user" source type.
|
||||
def lastfm.submit(~user,~password,~source="broadcast",~length=false,m) =
|
||||
audioscrobbler.submit(user=user,password=password,
|
||||
source=source,length=length,
|
||||
host="post.audioscrobbler.com",port=80,
|
||||
m)
|
||||
end
|
||||
|
||||
# Submit metadata to libre.fm using the audioscrobbler protocol (nowplaying mode).
|
||||
# @category Interaction
|
||||
# @param ~length Try to submit length information. This operation can be CPU intensive. Value forced to true when used with the "user" source type.
|
||||
def librefm.nowplaying(~user,~password,~length=false,m) =
|
||||
audioscrobbler.nowplaying(user=user,password=password,length=length,
|
||||
host="turtle.libre.fm",port=80,
|
||||
m)
|
||||
end
|
||||
|
||||
# Submit metadata to lastfm.fm using the audioscrobbler protocol (nowplaying mode).
|
||||
# @category Interaction
|
||||
# @param ~length Try to submit length information. This operation can be CPU intensive. Value forced to true when used with the "user" source type.
|
||||
def lastfm.nowplaying(~user,~password,~length=false,m) =
|
||||
audioscrobbler.nowplaying(user=user,password=password,length=length,
|
||||
host="post.audioscrobbler.com",port=80,
|
||||
m)
|
||||
end
|
||||
|
||||
# Submit songs using audioscrobbler, respecting the full protocol:
|
||||
# First signal song as now playing when starting, and
|
||||
# then submit song when it ends.
|
||||
# @category Interaction
|
||||
# @param ~source Source for tracks. Should be one of: "broadcast", "user", "recommendation" or "unknown". Since liquidsoap is intented for radio broadcasting, this is the default. Sources other than user don't need duration to be set.
|
||||
# @param ~length Try to submit length information. This operation can be CPU intensive. Value forced to true when used with the "user" source type.
|
||||
# @param ~delay Submit song when there is only this delay left, in seconds.
|
||||
# @param ~force If remaining time is null, the song will be assumed to be skipped or cuted, and not submitted. Set to zero to disable this behaviour.
|
||||
def audioscrobbler.submit.full(
|
||||
~user,~password,
|
||||
~host="post.audioscrobbler.com",~port=80,
|
||||
~source="broadcast",~length=false,
|
||||
~delay=10.,~force=false,s) =
|
||||
f = audioscrobbler.nowplaying(
|
||||
user=user,password=password,
|
||||
host=host,port=port,length=length)
|
||||
s = on_metadata(f,s)
|
||||
f = fun (rem,m) ->
|
||||
# Avoid skipped songs
|
||||
if rem > 0. or force then
|
||||
audioscrobbler.submit(
|
||||
user=user,password=password,
|
||||
host=host,port=port,length=length,
|
||||
source=source,m)
|
||||
else
|
||||
log(label="audioscrobbler.submit.full",
|
||||
level=4,"Remaining time null: \
|
||||
will not submit song (song skipped ?)")
|
||||
end
|
||||
on_end(delay=delay,f,s)
|
||||
end
|
||||
|
||||
# Submit songs to librefm using audioscrobbler, respecting the full protocol:
|
||||
# First signal song as now playing when starting, and
|
||||
# then submit song when it ends.
|
||||
# @category Interaction
|
||||
# @param ~source Source for tracks. Should be one of: "broadcast", "user", "recommendation" or "unknown". Since liquidsoap is intented for radio broadcasting, this is the default. Sources other than user don't need duration to be set.
|
||||
# @param ~length Try to submit length information. This operation can be CPU intensive. Value forced to true when used with the "user" source type.
|
||||
# @param ~delay Submit song when there is only this delay left, in seconds. If remaining time is less than this value, the song will be assumed to be skipped or cuted, and not submitted. Set to zero to disable this behaviour.
|
||||
# @param ~force If remaining time is null, the song will be assumed to be skipped or cuted, and not submitted. Set to zero to disable this behaviour.
|
||||
def librefm.submit.full(
|
||||
~user,~password,
|
||||
~source="broadcast",~length=false,
|
||||
~delay=10.,~force=false,s) =
|
||||
audioscrobbler.submit.full(
|
||||
user=user,password=password,
|
||||
source=source,length=length,
|
||||
host="turtle.libre.fm",port=80,
|
||||
delay=delay,force=force,s)
|
||||
end
|
||||
|
||||
# Submit songs to lastfm using audioscrobbler, respecting the full protocol:
|
||||
# First signal song as now playing when starting, and
|
||||
# then submit song when it ends.
|
||||
# @category Interaction
|
||||
# @param ~source Source for tracks. Should be one of: "broadcast", "user", "recommendation" or "unknown". Since liquidsoap is intented for radio broadcasting, this is the default. Sources other than user don't need duration to be set.
|
||||
# @param ~length Try to submit length information. This operation can be CPU intensive. Value forced to true when used with the "user" source type.
|
||||
# @param ~delay Submit song when there is only this delay left, in seconds. If remaining time is less than this value, the song will be assumed to be skipped or cuted, and not submitted. Set to zero to disable this behaviour.
|
||||
# @param ~force If remaining time is null, the song will be assumed to be skipped or cuted, and not submitted. Set to zero to disable this behaviour.
|
||||
def lastfm.submit.full(
|
||||
~user,~password,
|
||||
~source="broadcast",~length=false,
|
||||
~delay=10.,~force=false,s) =
|
||||
audioscrobbler.submit.full(
|
||||
user=user,password=password,
|
||||
source=source,length=length,
|
||||
host="post.audioscrobbler.com",port=80,
|
||||
delay=delay,force=force,s)
|
||||
end
|
||||
|
||||
%endif
|
||||
|
||||
dummy ()
|
||||
|
|
@ -1,43 +0,0 @@
|
|||
#!/sbin/runscript
|
||||
|
||||
user=liquidsoap
|
||||
group=liquidsoap
|
||||
prefix=/usr/local
|
||||
exec_prefix=${prefix}
|
||||
confdir=${prefix}/etc/liquidsoap
|
||||
liquidsoap=${exec_prefix}/bin/liquidsoap
|
||||
rundir=${prefix}/var/run/liquidsoap
|
||||
|
||||
depend() {
|
||||
after net icecast
|
||||
}
|
||||
|
||||
start() {
|
||||
cd $confdir
|
||||
for liq in *.liq ; do
|
||||
if test $liq != '*.liq' ; then
|
||||
ebegin "Starting $liq"
|
||||
start-stop-daemon --start --quiet --pidfile $rundir/${liq%.liq}.pid \
|
||||
--chuid $user:$group --exec $liquidsoap -- -d $confdir/$liq
|
||||
eend $?
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
stop() {
|
||||
cd $rundir
|
||||
for liq in *.pid ; do
|
||||
if test $liq != '*.pid' ; then
|
||||
ebegin "Stopping $liq"
|
||||
start-stop-daemon --stop --quiet --pidfile $liq
|
||||
eend $?
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
restart() {
|
||||
svc_stop
|
||||
einfo "Sleeping 4 seconds ..."
|
||||
sleep 4
|
||||
svc_start
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
#!/sbin/runscript
|
||||
|
||||
user=@install_user@
|
||||
group=@install_group@
|
||||
prefix=@prefix@
|
||||
exec_prefix=@exec_prefix@
|
||||
confdir=@sysconfdir@/liquidsoap
|
||||
liquidsoap=@bindir@/liquidsoap
|
||||
rundir=@localstatedir@/run/liquidsoap
|
||||
|
||||
depend() {
|
||||
after net icecast
|
||||
}
|
||||
|
||||
start() {
|
||||
cd $confdir
|
||||
for liq in *.liq ; do
|
||||
if test $liq != '*.liq' ; then
|
||||
ebegin "Starting $liq"
|
||||
start-stop-daemon --start --quiet --pidfile $rundir/${liq%.liq}.pid \
|
||||
--chuid $user:$group --exec $liquidsoap -- -d $confdir/$liq
|
||||
eend $?
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
stop() {
|
||||
cd $rundir
|
||||
for liq in *.pid ; do
|
||||
if test $liq != '*.pid' ; then
|
||||
ebegin "Stopping $liq"
|
||||
start-stop-daemon --stop --quiet --pidfile $liq
|
||||
eend $?
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
restart() {
|
||||
svc_stop
|
||||
einfo "Sleeping 4 seconds ..."
|
||||
sleep 4
|
||||
svc_start
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
#!/bin/sh
|
||||
### BEGIN INIT INFO
|
||||
# Provides: liquidsoap
|
||||
# Required-Start: $remote_fs $network $time
|
||||
# Required-Stop: $remote_fs $network $time
|
||||
# Should-Start:
|
||||
# Should-Stop:
|
||||
# Default-Start: 2 3 4 5
|
||||
# Default-Stop: 0 1 6
|
||||
# Short-Description: Starts the liquidsoap daemon
|
||||
# Description:
|
||||
### END INIT INFO
|
||||
|
||||
user=liquidsoap
|
||||
group=liquidsoap
|
||||
prefix=/usr/local
|
||||
exec_prefix=${prefix}
|
||||
confdir=${prefix}/etc/liquidsoap
|
||||
liquidsoap=${exec_prefix}/bin/liquidsoap
|
||||
rundir=${prefix}/var/run/liquidsoap
|
||||
|
||||
# Test if $rundir exists
|
||||
if [ ! -d $rundir ]; then
|
||||
mkdir -p $rundir;
|
||||
chown $user:$group $rundir
|
||||
fi
|
||||
|
||||
case "$1" in
|
||||
stop)
|
||||
echo -n "Stopping channels: "
|
||||
cd $rundir
|
||||
for liq in *.pid ; do
|
||||
if test $liq != '*.pid' ; then
|
||||
echo -n "$liq "
|
||||
start-stop-daemon --stop --quiet --pidfile $liq --retry 4
|
||||
fi
|
||||
done
|
||||
echo "OK"
|
||||
;;
|
||||
|
||||
start)
|
||||
echo -n "Starting channels: "
|
||||
cd $confdir
|
||||
for liq in *.liq ; do
|
||||
if test $liq != '*.liq' ; then
|
||||
echo -n "$liq "
|
||||
start-stop-daemon --start --quiet --pidfile $rundir/${liq%.liq}.pid \
|
||||
--chuid $user:$group --exec $liquidsoap -- -d $confdir/$liq
|
||||
fi
|
||||
done
|
||||
echo "OK"
|
||||
;;
|
||||
|
||||
restart|force-reload)
|
||||
$0 stop
|
||||
$0 start
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "Usage: $0 {start|stop|restart|force-reload}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
|
@ -1,63 +0,0 @@
|
|||
#!/bin/sh
|
||||
### BEGIN INIT INFO
|
||||
# Provides: liquidsoap
|
||||
# Required-Start: $remote_fs $network $time
|
||||
# Required-Stop: $remote_fs $network $time
|
||||
# Should-Start:
|
||||
# Should-Stop:
|
||||
# Default-Start: 2 3 4 5
|
||||
# Default-Stop: 0 1 6
|
||||
# Short-Description: Starts the liquidsoap daemon
|
||||
# Description:
|
||||
### END INIT INFO
|
||||
|
||||
user=@install_user@
|
||||
group=@install_group@
|
||||
prefix=@prefix@
|
||||
exec_prefix=@exec_prefix@
|
||||
confdir=@sysconfdir@/liquidsoap
|
||||
liquidsoap=@bindir@/liquidsoap
|
||||
rundir=@localstatedir@/run/liquidsoap
|
||||
|
||||
# Test if $rundir exists
|
||||
if [ ! -d $rundir ]; then
|
||||
mkdir -p $rundir;
|
||||
chown $user:$group $rundir
|
||||
fi
|
||||
|
||||
case "$1" in
|
||||
stop)
|
||||
echo -n "Stopping channels: "
|
||||
cd $rundir
|
||||
for liq in *.pid ; do
|
||||
if test $liq != '*.pid' ; then
|
||||
echo -n "$liq "
|
||||
start-stop-daemon --stop --quiet --pidfile $liq --retry 4
|
||||
fi
|
||||
done
|
||||
echo "OK"
|
||||
;;
|
||||
|
||||
start)
|
||||
echo -n "Starting channels: "
|
||||
cd $confdir
|
||||
for liq in *.liq ; do
|
||||
if test $liq != '*.liq' ; then
|
||||
echo -n "$liq "
|
||||
start-stop-daemon --start --quiet --pidfile $rundir/${liq%.liq}.pid \
|
||||
--chuid $user:$group --exec $liquidsoap -- -d $confdir/$liq
|
||||
fi
|
||||
done
|
||||
echo "OK"
|
||||
;;
|
||||
|
||||
restart|force-reload)
|
||||
$0 stop
|
||||
$0 start
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "Usage: $0 {start|stop|restart|force-reload}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
|
@ -1,15 +0,0 @@
|
|||
/usr/local/var/log/liquidsoap/*.log {
|
||||
compress
|
||||
rotate 5
|
||||
size 300k
|
||||
missingok
|
||||
notifempty
|
||||
sharedscripts
|
||||
postrotate
|
||||
for liq in /usr/local/var/run/liquidsoap/*.pid ; do
|
||||
if test $liq != '/usr/local/var/run/liquidsoap/*.pid' ; then
|
||||
start-stop-daemon --stop --signal USR1 --quiet --pidfile $liq
|
||||
fi
|
||||
done
|
||||
endscript
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
@localstatedir@/log/liquidsoap/*.log {
|
||||
compress
|
||||
rotate 5
|
||||
size 300k
|
||||
missingok
|
||||
notifempty
|
||||
sharedscripts
|
||||
postrotate
|
||||
for liq in @localstatedir@/run/liquidsoap/*.pid ; do
|
||||
if test $liq != '@localstatedir@/run/liquidsoap/*.pid' ; then
|
||||
start-stop-daemon --stop --signal USR1 --quiet --pidfile $liq
|
||||
fi
|
||||
done
|
||||
endscript
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
# This script is called from liquidsoap for generating a file
|
||||
# for "say:voice/text" URIs.
|
||||
# Usage: liquidtts text output_file voice
|
||||
|
||||
echo $1 | /usr/bin/text2wave -f 44100 > $2.tmp.wav && /usr/bin/sox $2.tmp.wav -t wav -c 2 -r 44100 $2 2> /dev/null > /dev/null
|
||||
return=$?
|
||||
/bin/rm $2.tmp.wav
|
||||
false $2 2> /dev/null > /dev/null
|
||||
exit $return
|
|
@ -1,11 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
# This script is called from liquidsoap for generating a file
|
||||
# for "say:voice/text" URIs.
|
||||
# Usage: liquidtts text output_file voice
|
||||
|
||||
echo $1 | @TEXT2WAVE@ -f 44100 > $2.tmp.wav && @SOX@ 2> /dev/null > /dev/null
|
||||
return=$?
|
||||
@RM@ $2.tmp.wav
|
||||
@NORMALIZE@ $2 2> /dev/null > /dev/null
|
||||
exit $return
|
|
@ -1,4 +0,0 @@
|
|||
%include "utils.liq"
|
||||
%include "externals.liq"
|
||||
%include "shoutcast.liq"
|
||||
%include "lastfm.liq"
|
|
@ -1,49 +0,0 @@
|
|||
|
||||
%ifdef output.icecast
|
||||
# Output to shoutcast.
|
||||
# @category Source / Output
|
||||
# @param ~id Output's ID
|
||||
# @param ~start Start output threads on operator initialization.
|
||||
# @param ~restart Restart output after a failure. By default, liquidsoap will stop if the output failed.
|
||||
# @param ~restart_delay Delay, in seconds, before attempting new connection, if restart is enabled.
|
||||
# @param ~user User for shout source connection. Useful only in special cases, like with per-mountpoint users.
|
||||
# @param ~icy_reset Reset shoutcast source buffer upon connecting (necessary for NSV).
|
||||
# @param ~dumpfile Dump stream to file, for debugging purpose. Disabled if empty.
|
||||
# @param ~fallible Allow the child source to fail, in which case the output will be (temporarily) stopped.
|
||||
# @param ~on_start Callback executed when outputting starts.
|
||||
# @param ~on_stop Callback executed when outputting stops.
|
||||
# @param ~on_connect Callback executed when connection starts.
|
||||
# @param ~on_disconnect Callback executed when connection stops.
|
||||
# @param ~icy_metadata Send new metadata using the ICY protocol. One of: "guess", "true", "false"
|
||||
# @param ~format Format, e.g. "audio/ogg". When empty, the encoder is used to guess.
|
||||
# @param e Endoding format. For shoutcast, should be mp3 or AAC(+).
|
||||
# @param s The source to output
|
||||
def output.shoutcast(
|
||||
~id="output.shoutcast",~start=true,
|
||||
~restart=false,~restart_delay=3,
|
||||
~host="localhost",~port=8000,
|
||||
~user="source",~password="hackme",
|
||||
~genre="Misc",~url="http://savonet.sf.net/",
|
||||
~name="OCaml Radio!",~public=true, ~format="",
|
||||
~dumpfile="", ~icy_metadata="guess",
|
||||
~on_connect={()}, ~on_disconnect={()},
|
||||
~aim="",~icq="",~irc="",~icy_reset=true,
|
||||
~fallible=false,~on_start={()},~on_stop={()},
|
||||
e,s) =
|
||||
icy_reset = if icy_reset then "1" else "0" end
|
||||
headers = [("icy-aim",aim),("icy-irc",irc),
|
||||
("icy-icq",icq),("icy-reset",icy_reset)]
|
||||
output.icecast(
|
||||
e, format=format,
|
||||
id=id, headers=headers,
|
||||
start=start,icy_metadata=icy_metadata,
|
||||
on_connect=on_connect, on_disconnect=on_disconnect,
|
||||
restart=restart, restart_delay=restart_delay,
|
||||
host=host, port=port, user=user, password=password,
|
||||
genre=genre, url=url, description="UNUSED",
|
||||
public=public, dumpfile=dumpfile,encoding="ISO-8859-1",
|
||||
name=name, mount="/", protocol="icy",
|
||||
fallible=fallible,on_start=on_start,on_stop=on_stop,
|
||||
s)
|
||||
end
|
||||
%endif
|
|
@ -1,33 +0,0 @@
|
|||
set("log.file",false)
|
||||
|
||||
echo = fun (x) -> system("echo "^quote(x))
|
||||
|
||||
def test(lbl,f)
|
||||
if f() then echo(lbl) else system("echo fail "^lbl) end
|
||||
end
|
||||
|
||||
test("1",{ 1==1 })
|
||||
test("2",{ 1+1==2 })
|
||||
test("3",{ (-1)+2==1 })
|
||||
test("4",{ (-1)+2 <= 3*2 })
|
||||
test("5",{ true })
|
||||
test("6",{ true and true })
|
||||
test("7",{ 1==1 and 1==1 })
|
||||
test("8",{ (1==1) and (1==1) })
|
||||
test("9",{ true and (-1)+2 <= 3*2 })
|
||||
|
||||
l = [ ("bla",""), ("bli","x"), ("blo","xx"), ("blu","xxx"), ("dix","10") ]
|
||||
echo(l["dix"])
|
||||
test("11",{ 2 == list.length(string.split(separator="",l["blo"])) })
|
||||
|
||||
%ifdef foobarbaz
|
||||
if = if is not a well-formed expression, and we do not care...
|
||||
%endif
|
||||
|
||||
echo("1#{1+1}")
|
||||
echo(string_of(int_of_float(float_of_string(default=13.,"blah"))))
|
||||
|
||||
f=fun(x)->x
|
||||
# Checking that the following is not recursive:
|
||||
f=fun(x)->f(x)
|
||||
print(f(14))
|
|
@ -1,112 +0,0 @@
|
|||
# Check these examples with: liquidsoap --no-libs -i -c typing.liq
|
||||
|
||||
# TODO Throughout this file, parsing locations displayed in error messages
|
||||
# are often much too inaccurate.
|
||||
|
||||
set("log.file",false)
|
||||
|
||||
# Check that some polymorphism is allowed.
|
||||
# id :: (string,'a)->'a
|
||||
def id(a,b)
|
||||
log(a)
|
||||
b
|
||||
end
|
||||
ignore("bla"==id("bla","bla"))
|
||||
ignore(0==id("zero",0))
|
||||
|
||||
# Reporting locations for the next error is non-trivial, because it is about
|
||||
# an instantiation of the type of id. The deep error doesn't have relevant
|
||||
# information about why the int should be a string, the outer one has.
|
||||
# id(0,0)
|
||||
|
||||
# Polymorphism is limited to outer generalizations, this is not system F.
|
||||
# apply :: ((string)->'a)->'a
|
||||
def apply(f)
|
||||
f("bla")
|
||||
# f is not polymorphic, the following is forbidden:
|
||||
# f(0)
|
||||
# f(f)
|
||||
end
|
||||
|
||||
# The level checks forbid abusive generalization.
|
||||
# id' :: ('a)->'a
|
||||
def id'(x)
|
||||
# If one isn't careful about levels/scoping, f2 gets the type ('a)->'b
|
||||
# and so does twisted_id.
|
||||
def f2(y)
|
||||
x
|
||||
end
|
||||
f2(x)
|
||||
end
|
||||
|
||||
# More errors...
|
||||
# 0=="0"
|
||||
# [3,""]
|
||||
|
||||
# Subtyping, functions and lists.
|
||||
f1 = fun () -> 3
|
||||
f2 = fun (a=1) -> a
|
||||
|
||||
# This is OK, l1 is a list of elements of type f1.
|
||||
l1 = [f1,f2]
|
||||
list.iter(fun (f) -> log(string_of(f())), l1)
|
||||
# Forbidden. Indeed, f1 doesn't accept any argument -- although f2 does.
|
||||
# Here the error message may even be too detailed since it goes back to the
|
||||
# definition of l1 and requires that f1 has type (int)->int.
|
||||
# list.iter(fun (f) -> log(string_of(f(42))), l1)
|
||||
|
||||
# Actually, this is forbidden too, but the reason is more complex...
|
||||
# The infered type for the function is ((int)->int)->unit,
|
||||
# and (int)->int is not a subtype of (?int)->int.
|
||||
# There's no most general answer here since (?int)->int is not a
|
||||
# subtype of (int)->int either.
|
||||
# list.iter(fun (f) -> log(string_of(f(42))), [f2])
|
||||
|
||||
# Unlike l1, this is not OK, since we don't leave open subtyping constraints
|
||||
# while infering types.
|
||||
# I hope we can make the inference smarter in the future, without obfuscating
|
||||
# the error messages too much.
|
||||
# The type error here shows the use of all the displayed positions:
|
||||
# f1 has type t1, f2 has type t2, t1 should be <: t2
|
||||
# l2 = [ f2, f1 ]
|
||||
|
||||
# An error where contravariance flips the roles of both sides..
|
||||
# [fun (x) -> x+1, fun (y) -> y^"."]
|
||||
|
||||
# An error without much locations..
|
||||
# TODO An explaination about the missing label would help a lot here.
|
||||
# def f(f)
|
||||
# f(output.icecast.vorbis)
|
||||
# f(output.icecast.mp3)
|
||||
# end
|
||||
|
||||
# This causes an occur-check error.
|
||||
# TODO The printing of the types breaks the sharing of one EVAR
|
||||
# across two types. Here the sharing is actually the origin of the occur-check
|
||||
# error. And it's not easy to understand..
|
||||
# omega = fun (x) -> x(x)
|
||||
|
||||
# Now let's test ad-hoc polymorphism.
|
||||
|
||||
echo = fun(x) -> system("echo #{quote(string_of(x))}")
|
||||
|
||||
echo("bla")
|
||||
echo((1,3.12))
|
||||
echo(1 + 1)
|
||||
echo(1. + 2.14)
|
||||
|
||||
# string is not a Num
|
||||
# echo("bl"+"a")
|
||||
|
||||
echo(1 <= 2)
|
||||
echo((1,2) == (1,3))
|
||||
|
||||
# float <> int
|
||||
# echo(1 == 2.)
|
||||
|
||||
# source is not an Ord
|
||||
# echo(blank()==blank())
|
||||
|
||||
def sum_eq(a,b)
|
||||
a+b == a
|
||||
end
|
|
@ -1,649 +0,0 @@
|
|||
|
||||
# Turn a source into an infaillible source.
|
||||
# by adding blank when the source is not available.
|
||||
# @param s the source to turn infaillible
|
||||
# @category Source / Track Processing
|
||||
def mksafe(s)
|
||||
fallback(id="mksafe",track_sensitive=false,[s,blank(id="safe_blank")])
|
||||
end
|
||||
|
||||
# Alias for the <code>l[k]</code> notation.
|
||||
# @category List
|
||||
# @param a Key to look for
|
||||
# @param l List of pairs (key,value)
|
||||
def list.assoc(a,l)
|
||||
l[a]
|
||||
end
|
||||
|
||||
# list.mem_assoc(key,l) returns true if l contains a pair
|
||||
# (key,value)
|
||||
# @category List
|
||||
# @param a Key to look for
|
||||
# @param l List of pairs (key,value)
|
||||
def list.mem_assoc(a,l)
|
||||
v = list.assoc(a,l)
|
||||
# We check for existence, since "" may indicate
|
||||
# either a binding (a,"") or no binding..
|
||||
list.mem((a,v),l)
|
||||
end
|
||||
|
||||
# Remove a pair from an associative list
|
||||
# @category List
|
||||
# @param a Key of pair to be removed
|
||||
# @param l List of pairs (key,value)
|
||||
def list.remove_assoc(a,l)
|
||||
list.remove((a,list.assoc(a,l)),l)
|
||||
end
|
||||
|
||||
# Rewrite metadata on the fly using a list of (target,rules).
|
||||
# @category Source / Track Processing
|
||||
# @param l \
|
||||
# List of (target,value) rewriting rules.
|
||||
# @param ~insert_missing \
|
||||
# Treat track beginnings without metadata as having empty ones. \
|
||||
# The operational order is: \
|
||||
# create empty if needed, map and strip if enabled.
|
||||
# @param ~update \
|
||||
# Only update metadata. \
|
||||
# If false, only returned values will be set as metadata.
|
||||
# @param ~strip \
|
||||
# Completly remove empty metadata. \
|
||||
# Operates on both empty values and empty metadata chunk.
|
||||
def rewrite_metadata(l,~insert_missing=true,
|
||||
~update=true,~strip=false,
|
||||
s)
|
||||
# We don't need to return all values, since
|
||||
# map_metadata only update returned values.
|
||||
# So, we simply apply all rewrite rules !
|
||||
def map(m)
|
||||
def apply(x)
|
||||
label = fst(x)
|
||||
value = snd(x)
|
||||
(label,value % m)
|
||||
end
|
||||
list.map(apply,l)
|
||||
end
|
||||
map_metadata(map,insert_missing=insert_missing,
|
||||
update=update,strip=strip,s)
|
||||
end
|
||||
|
||||
# Add a skip function to a source
|
||||
# when it does not have one
|
||||
# by default
|
||||
# @category Interaction
|
||||
# @param s The source to attach the command to.
|
||||
def add_skip_command(s) =
|
||||
# A command to skip
|
||||
def skip(_) =
|
||||
source.skip(s)
|
||||
"Done!"
|
||||
end
|
||||
# Register the command:
|
||||
server.register(namespace="#{source.id(s)}",
|
||||
usage="skip",
|
||||
description="Skip the current song.",
|
||||
"skip",skip)
|
||||
end
|
||||
|
||||
# Removes all metadata coming from a source
|
||||
# @category Source / Track Processing
|
||||
def drop_metadata(s)
|
||||
map_metadata(fun(_)->[],update=false,strip=true,insert_missing=false,s)
|
||||
end
|
||||
|
||||
# Merge all tracks from a source, provided that it does not fail
|
||||
# @category Source / Track Processing
|
||||
def merge_tracks(s)
|
||||
sequence(merge=true,[s])
|
||||
end
|
||||
|
||||
output.prefered=output.dummy
|
||||
%ifdef output.oss
|
||||
output.prefered=output.oss
|
||||
%endif
|
||||
%ifdef output.alsa
|
||||
output.prefered=output.alsa
|
||||
%endif
|
||||
%ifdef output.pulseaudio
|
||||
output.prefered=output.pulseaudio
|
||||
%endif
|
||||
%ifdef output.ao
|
||||
output.prefered=output.ao
|
||||
%endif
|
||||
# Output to local audio card using the first available driver in this list:
|
||||
# ao, pulseaudio, alsa, oss, dummy
|
||||
# @category Source / Output
|
||||
def output.prefered(~id="",s)
|
||||
output.prefered(id=id,s)
|
||||
end
|
||||
|
||||
in = fun () -> blank()
|
||||
%ifdef input.oss
|
||||
in = fun () -> input.oss(id="oss_mic")
|
||||
%endif
|
||||
%ifdef input.alsa
|
||||
in = fun () -> input.alsa(id="alsa_mic")
|
||||
%endif
|
||||
%ifdef input.portaudio
|
||||
in = fun () -> input.portaudio(id="pa_mic")
|
||||
%endif
|
||||
# Create a source from the first available input driver in this list:
|
||||
# portaudio, alsa, oss, blank.
|
||||
# @category Source / Input
|
||||
def in()
|
||||
in()
|
||||
end
|
||||
|
||||
# Output a stream using the 'output.prefered' operator. The input source does
|
||||
# not need to be infallible, blank will just be played during failures.
|
||||
# @param s the source to output
|
||||
# @category Source / Output
|
||||
def out(s)
|
||||
output.prefered(mksafe(s))
|
||||
end
|
||||
|
||||
# Special track insensitive fallback that
|
||||
# always skip current song before switching.
|
||||
# @category Source / Track Processing
|
||||
# @param ~input The input source
|
||||
# @param f The fallback source
|
||||
def fallback.skip(~input,f)
|
||||
def transition(a,b) =
|
||||
source.skip(a)
|
||||
# This eats the last remaining frame from a
|
||||
sequence([a,b])
|
||||
end
|
||||
fallback(track_sensitive=false,transitions=[transition,transition],[input,f])
|
||||
end
|
||||
|
||||
# Compress and normalize, producing a more uniform and "full" sound.
|
||||
# @category Source / Sound Processing
|
||||
# @param s The input source.
|
||||
def nrj(s)
|
||||
compress(threshold=-15.,ratio=3.,gain=3.,normalize(s))
|
||||
end
|
||||
|
||||
# Multiband-compression.
|
||||
# @category Source / Sound Processing
|
||||
# @param s The input source.
|
||||
def sky(s)
|
||||
# 3-band crossover
|
||||
low = filter.iir.eq.low(frequency = 168.)
|
||||
mh = filter.iir.eq.high(frequency = 100.)
|
||||
mid = filter.iir.eq.low(frequency = 1800.)
|
||||
high = filter.iir.eq.high(frequency = 1366.)
|
||||
|
||||
# Add back
|
||||
add(normalize = false,
|
||||
[ compress(attack = 100., release = 200., threshold = -20.,
|
||||
ratio = 6., gain = 6.7, knee = 0.3,
|
||||
low(s)),
|
||||
compress(attack = 100., release = 200., threshold = -20.,
|
||||
ratio = 6., gain = 6.7, knee = 0.3,
|
||||
mid(mh(s))),
|
||||
compress(attack = 100., release = 200., threshold = -20.,
|
||||
ratio = 6., gain = 6.7, knee = 0.3,
|
||||
high(s))
|
||||
])
|
||||
end
|
||||
|
||||
# Simple crossfade.
|
||||
# @category Source / Track Processing
|
||||
# @param ~start_next Duration in seconds of the crossed end of track.
|
||||
# @param ~fade_in Duration of the fade in for next track
|
||||
# @param ~fade_out Duration of the fade out for previous track
|
||||
# @param s The source to use
|
||||
def crossfade(~id="",~start_next,~fade_in,~fade_out,s)
|
||||
s = fade.in(duration=fade_in,s)
|
||||
s = fade.out(duration=fade_out,s)
|
||||
fader = fun (a,b) -> add(normalize=false,[b,a])
|
||||
cross(id=id,conservative=true,duration=start_next,fader,s)
|
||||
end
|
||||
|
||||
# Append speech-synthesized tracks reading the metadata.
|
||||
# @category Source / Track Processing
|
||||
# @param ~pattern Pattern to use
|
||||
# @param s The source to use
|
||||
def say_metadata
|
||||
p = 'say:$(if $(artist),"It was $(artist)$(if $(title),\", $(title)\").")'
|
||||
fun (s,~pattern=p) ->
|
||||
append(s,fun (m) -> request.queue(queue=[request.create(pattern % m)],
|
||||
interactive=false))
|
||||
end
|
||||
|
||||
%ifdef soundtouch
|
||||
# Increases the pitch, making voices sound like on helium.
|
||||
# @category Source / Sound Processing
|
||||
# @param s The input source.
|
||||
def helium(s)
|
||||
soundtouch(pitch=1.5,s)
|
||||
end
|
||||
%endif
|
||||
|
||||
# Return true if process exited with 0 code.
|
||||
# Command should return quickly.
|
||||
# @category System
|
||||
# @param command Command to test
|
||||
def test_process(command)
|
||||
lines =
|
||||
get_process_lines("(" ^ command ^ " >/dev/null 2>&1 && echo 0) || echo 1")
|
||||
if list.length(lines) == 0 then
|
||||
false
|
||||
else
|
||||
"0" == list.hd(lines)
|
||||
end
|
||||
end
|
||||
|
||||
# Split an url of the form foo?arg=bar&arg2=bar2
|
||||
# into ("foo",[("arg","bar"),("arg2","bar2")]
|
||||
# @category String
|
||||
# @param uri Url to split
|
||||
def url.split(uri) =
|
||||
ret = string.extract(pattern="([^\?]*)\?(.*)",uri)
|
||||
args = ret["2"]
|
||||
if args != "" then
|
||||
l = string.split(separator="&",args)
|
||||
def f(x) =
|
||||
ret = string.split(separator="=",x)
|
||||
(url.decode(list.nth(ret,0)),
|
||||
url.decode(list.nth(ret,1)))
|
||||
end
|
||||
l = list.map(f,l)
|
||||
(ret["1"],l)
|
||||
else
|
||||
(uri,[])
|
||||
end
|
||||
end
|
||||
|
||||
# Register a server/telnet command to
|
||||
# update a source's metadata. Returns
|
||||
# a new source, which will receive the
|
||||
# updated metadata. Semantics is the
|
||||
# same as pre 1.0 insert_metadata operator,
|
||||
# i.e. @insert key1="val1",key2="val2",..@
|
||||
# @category Source / Track Processing
|
||||
# @param ~id Force the value of the source ID.
|
||||
def server.insert_metadata(~id="",s) =
|
||||
x = insert_metadata(id=id,s)
|
||||
insert = fst(x)
|
||||
s = snd(x)
|
||||
def insert(s) =
|
||||
l = string.split(separator='([^=]+\s*=\s*"(\\"|[^"])*")\s*,\s*',s)
|
||||
def f(l,x) =
|
||||
sub = fun (s) -> string.replace(pattern='\\"',fun (_) -> '"',s)
|
||||
if x != "" then
|
||||
ret = string.extract(pattern='([^=]+)\s*=\s*"((?:\\"|[^"])*)"',x)
|
||||
if ret["1"] != "" then
|
||||
list.append(l,[(ret["1"],
|
||||
sub(ret["2"]))])
|
||||
else
|
||||
l
|
||||
end
|
||||
else
|
||||
l
|
||||
end
|
||||
end
|
||||
meta = list.fold(f,[],l)
|
||||
if meta != [] then
|
||||
insert(meta)
|
||||
"Done"
|
||||
else
|
||||
"Syntax error or no metadata given. \
|
||||
Use key1=\"val1\",key2=\"val2\",.."
|
||||
end
|
||||
end
|
||||
id = source.id(s)
|
||||
server.register(namespace="#{id}",
|
||||
description="Insert a metadata chunk.",
|
||||
usage="insert key1=\"val1\",key2=\"val2\",..",
|
||||
"insert",insert)
|
||||
s
|
||||
end
|
||||
|
||||
# Get the base name of a path.
|
||||
# Implemented using the corresponding shell command.
|
||||
# @category System
|
||||
# @param s Path
|
||||
def basename(s)
|
||||
lines = get_process_lines("basename #{quote(s)}")
|
||||
if list.length(lines) > 0 then
|
||||
list.hd(lines)
|
||||
else
|
||||
# Don't know what to do.. output s
|
||||
s
|
||||
end
|
||||
end
|
||||
|
||||
# Get the directory name of a path.
|
||||
# Implemented using the corresponding shell command.
|
||||
# @category System
|
||||
# @param s Path
|
||||
# @param ~default Value returned in case of error.
|
||||
def dirname(~default="/nonexistent",s)
|
||||
lines = get_process_lines("dirname #{quote(s)}")
|
||||
if list.length(lines) > 0 then
|
||||
list.hd(lines)
|
||||
else
|
||||
default
|
||||
end
|
||||
end
|
||||
|
||||
# Read some value from standard input (console).
|
||||
# @category System
|
||||
# @param ~hide Hide typed characters (for passwords).
|
||||
def read(~hide=false)
|
||||
if hide then
|
||||
system("stty -echo")
|
||||
end
|
||||
s = list.hd(get_process_lines("read BLA && echo $BLA"))
|
||||
if hide then
|
||||
system("stty echo")
|
||||
end
|
||||
print("")
|
||||
s
|
||||
end
|
||||
|
||||
# Generic mime test. First try to use file.mime if it exist.
|
||||
# Otherwise try to get the value using the file binary.
|
||||
# Returns "" (empty string) if no value can be find.
|
||||
# @category System
|
||||
# @param file The file to test
|
||||
def get_mime(file) =
|
||||
def file_method(file) =
|
||||
if test_process("which file") then
|
||||
list.hd(get_process_lines("file -b --mime-type \
|
||||
#{quote(file)}"))
|
||||
else
|
||||
""
|
||||
end
|
||||
end
|
||||
def mime_method(file) =
|
||||
ret = ""
|
||||
%ifdef file.mime
|
||||
ret = file.mime(file)
|
||||
%endif
|
||||
ret
|
||||
end
|
||||
# First try mime method
|
||||
ret = mime_method(file)
|
||||
if ret != "" then
|
||||
ret
|
||||
else
|
||||
# Now try file method
|
||||
file_method(file)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# Remove low frequencies often produced by microphones.
|
||||
# @category Source / Sound Processing
|
||||
# @param s The input source.
|
||||
def mic_filter(s)
|
||||
filter(freq=200.,q=1.,mode="high",s)
|
||||
end
|
||||
|
||||
# Creates a source that fails to produce anything.
|
||||
# @category Source / Input
|
||||
def fail()
|
||||
fallback([])
|
||||
end
|
||||
|
||||
# Creates a source that plays only one track of the input source.
|
||||
# @category Source / Track Processing
|
||||
# @param s The input source.
|
||||
def once(s)
|
||||
sequence([s,fail()])
|
||||
end
|
||||
|
||||
# Crossfade between tracks, taking the respective volume levels into account in
|
||||
# the choice of the transition.
|
||||
# @category Source / Track Processing
|
||||
# @param ~start_next Crossing duration, if any.
|
||||
# @param ~fade_in Fade-in duration, if any.
|
||||
# @param ~fade_out Fade-out duration, if any.
|
||||
# @param ~width Width of the volume analysis window.
|
||||
# @param ~conservative Always prepare for a premature end-of-track.
|
||||
# @param ~default Transition used when no rule applies \
|
||||
# (default: sequence).
|
||||
# @param ~high Value, in dB, for loud sound level
|
||||
# @param ~medium Value, in dB, for medium sound level
|
||||
# @param ~margin Margin to detect sources that have too different \
|
||||
# sound level for crossing.
|
||||
# @param s The input source.
|
||||
def smart_crossfade (~start_next=5.,~fade_in=3.,~fade_out=3.,
|
||||
~default=(fun (a,b) -> sequence([a, b])),
|
||||
~high=-15., ~medium=-32., ~margin=4.,
|
||||
~width=2.,~conservative=false,s)
|
||||
fade.out = fade.out(type="sin",duration=fade_out)
|
||||
fade.in = fade.in(type="sin",duration=fade_in)
|
||||
add = fun (a,b) -> add(normalize=false,[b, a])
|
||||
log = log(label="smart_crossfade")
|
||||
|
||||
def transition(a,b,ma,mb,sa,sb)
|
||||
|
||||
list.iter(fun(x)-> log(level=4,"Before: #{x}"),ma)
|
||||
list.iter(fun(x)-> log(level=4,"After : #{x}"),mb)
|
||||
|
||||
if
|
||||
# If A and B are not too loud and close, fully cross-fade them.
|
||||
a <= medium and b <= medium and abs(a - b) <= margin
|
||||
then
|
||||
log("Old <= medium, new <= medium and |old-new| <= margin.")
|
||||
log("Old and new source are not too loud and close.")
|
||||
log("Transition: crossed, fade-in, fade-out.")
|
||||
add(fade.out(sa),fade.in(sb))
|
||||
|
||||
elsif
|
||||
# If B is significantly louder than A, only fade-out A.
|
||||
# We don't want to fade almost silent things, ask for >medium.
|
||||
b >= a + margin and a >= medium and b <= high
|
||||
then
|
||||
log("new >= old + margin, old >= medium and new <= high.")
|
||||
log("New source is significantly louder than old one.")
|
||||
log("Transition: crossed, fade-out.")
|
||||
add(fade.out(sa),sb)
|
||||
|
||||
elsif
|
||||
# Opposite as the previous one.
|
||||
a >= b + margin and b >= medium and a <= high
|
||||
then
|
||||
log("old >= new + margin, new >= medium and old <= high")
|
||||
log("Old source is significantly louder than new one.")
|
||||
log("Transition: crossed, fade-in.")
|
||||
add(sa,fade.in(sb))
|
||||
|
||||
elsif
|
||||
# Do not fade if it's already very low.
|
||||
b >= a + margin and a <= medium and b <= high
|
||||
then
|
||||
log("new >= old + margin, old <= medium and new <= high.")
|
||||
log("Do not fade if it's already very low.")
|
||||
log("Transition: crossed, no fade.")
|
||||
add(sa,sb)
|
||||
|
||||
# What to do with a loud end and a quiet beginning ?
|
||||
# A good idea is to use a jingle to separate the two tracks,
|
||||
# but that's another story.
|
||||
|
||||
else
|
||||
# Otherwise, A and B are just too loud to overlap nicely,
|
||||
# or the difference between them is too large and overlapping would
|
||||
# completely mask one of them.
|
||||
log("No transition: using default.")
|
||||
default(sa, sb)
|
||||
end
|
||||
end
|
||||
|
||||
smart_cross(width=width, duration=start_next, conservative=conservative,
|
||||
transition,s)
|
||||
end
|
||||
|
||||
# Custom playlist source written using the script language.
|
||||
# Will read directory or playlist, play all files and stop
|
||||
# @category Source / Input
|
||||
# @param ~random Randomize playlist content
|
||||
# @param ~on_done Function to execute when the playlist is finished
|
||||
# @param uri Playlist URI
|
||||
def playlist.once(~random=false,~on_done={()},uri)
|
||||
x = ref 0
|
||||
def playlist.custom(files)
|
||||
length = list.length(files)
|
||||
if length == 0 then
|
||||
log("Empty playlist..")
|
||||
fail ()
|
||||
else
|
||||
files =
|
||||
if random then
|
||||
list.sort(fun (x,y) -> int_of_float(random.float()), files)
|
||||
else
|
||||
files
|
||||
end
|
||||
def next () =
|
||||
state = !x
|
||||
file =
|
||||
if state < length then
|
||||
x := state + 1
|
||||
list.nth(files,state)
|
||||
else
|
||||
# Playlist finished
|
||||
on_done ()
|
||||
""
|
||||
end
|
||||
request.create(file)
|
||||
end
|
||||
request.dynamic(next)
|
||||
end
|
||||
end
|
||||
if test_process("test -d #{quote(uri)}") then
|
||||
files = get_process_lines("find #{quote(uri)} -type f | sort")
|
||||
playlist.custom(files)
|
||||
else
|
||||
playlist = request.create.raw(uri)
|
||||
result =
|
||||
if request.resolve(playlist) then
|
||||
playlist = request.filename(playlist)
|
||||
files = playlist.parse(playlist)
|
||||
files = list.map(snd,files)
|
||||
playlist.custom(files)
|
||||
else
|
||||
log("Couldn't read playlist: request resolution failed.")
|
||||
fail ()
|
||||
end
|
||||
request.destroy(playlist)
|
||||
result
|
||||
end
|
||||
end
|
||||
|
||||
# Mixes two streams, with faded transitions between the state when only the
|
||||
# normal stream is available and when the special stream gets added on top of
|
||||
# it.
|
||||
# @category Source / Track Processing
|
||||
# @param ~delay Delay before starting the special source.
|
||||
# @param ~p Portion of amplitude of the normal source in the mix.
|
||||
# @param ~normal The normal source, which could be called the carrier too.
|
||||
# @param ~special The special source.
|
||||
def smooth_add(~delay=0.5,~p=0.2,~normal,~special)
|
||||
d = delay
|
||||
fade.final = fade.final(duration=d*2.)
|
||||
fade.initial = fade.initial(duration=d*2.)
|
||||
q = 1. - p
|
||||
c = amplify
|
||||
fallback(track_sensitive=false,
|
||||
[special,normal],
|
||||
transitions=[
|
||||
fun(normal,special)->
|
||||
add(normalize=false,
|
||||
[c(p,normal),
|
||||
c(q,fade.final(type="sin",normal)),
|
||||
sequence([blank(duration=d),c(q,special)])]),
|
||||
fun(special,normal)->
|
||||
add(normalize=false,
|
||||
[c(p,normal),
|
||||
c(q,fade.initial(type="sin",normal))])
|
||||
])
|
||||
end
|
||||
|
||||
# Restrict a source to play only when a predicate is true.
|
||||
# @category Source / Track Processing
|
||||
# @param pred The predicate, typically a time interval such as \
|
||||
# <code>{10h-10h30}</code>.
|
||||
def at(pred,s)
|
||||
switch([(pred,s)])
|
||||
end
|
||||
|
||||
# Execute a given action when a predicate is true.
|
||||
# This will be run in background.
|
||||
# @category System
|
||||
# @param ~freq Frequency for checking the predicate, in seconds.
|
||||
# @param ~pred Predicate indicating when to execute the function, \
|
||||
# typically a time interval such as <code>{10h-10h30}</code>.
|
||||
# @param f Function to execute when the predicate is true.
|
||||
def exec_at(~freq=1.,~pred,f)
|
||||
def check()
|
||||
if pred() then
|
||||
f()
|
||||
end
|
||||
freq
|
||||
end
|
||||
add_timeout(freq,check)
|
||||
end
|
||||
|
||||
# Register the replaygain protocol
|
||||
def replaygain_protocol(arg,delay)
|
||||
# The extraction program
|
||||
extract_replaygain = "#{configure.libdir}/extract-replaygain"
|
||||
x = get_process_lines("#{extract_replaygain} #{quote(arg)}")
|
||||
if list.hd(x) != "" then
|
||||
["annotate:replay_gain=\"#{list.hd(x)}\":#{arg}"]
|
||||
else
|
||||
[arg]
|
||||
end
|
||||
end
|
||||
add_protocol("replay_gain", replaygain_protocol)
|
||||
|
||||
# Enable replay gain metadata resolver. This resolver will
|
||||
# process any file decoded by liquidsoap and add a @replay_gain@
|
||||
# metadata when this value could be computed. For a finer-grained
|
||||
# replay gain processing, use the @replay_gain@ protocol.
|
||||
# @category Liquidsoap
|
||||
# @param ~extract_replaygain The extraction program
|
||||
def enable_replaygain_metadata(
|
||||
~extract_replaygain="#{configure.libdir}/extract-replaygain")
|
||||
def replaygain_metadata(file)
|
||||
x = get_process_lines("#{extract_replaygain} \
|
||||
#{quote(file)}")
|
||||
if list.hd(x) != "" then
|
||||
[("replay_gain",list.hd(x))]
|
||||
else
|
||||
[]
|
||||
end
|
||||
end
|
||||
add_metadata_resolver("replay_gain", replaygain_metadata)
|
||||
end
|
||||
|
||||
# Create a log of clock times for all the clocks initially present.
|
||||
# The log is in a simple format which you can directly use with gnuplot.
|
||||
# @category Liquidsoap
|
||||
# @param ~interval Polling interval.
|
||||
# @param ~delay Delay before setting up the clock logger. This should \
|
||||
# be used to ensure that the logger starts only after \
|
||||
# the clocks are created.
|
||||
# @param unlabeled Path of the log file.
|
||||
def log_clocks(~delay=0.,~interval=1.,logfile)
|
||||
# Get the current clocks
|
||||
clocks = list.map(fst,get_clock_status())
|
||||
# Column headers
|
||||
system("echo \# #{string.concat(separator=' ',clocks)} > #{(logfile:string)}")
|
||||
def report()
|
||||
status = get_clock_status()
|
||||
status = list.map(fun (x) -> (fst(x),string_of(snd(x))), status)
|
||||
status = list.map(fun (c) -> status[c], clocks)
|
||||
system("echo #{string.concat(separator=' ',status)} >> #{logfile}")
|
||||
interval
|
||||
end
|
||||
if delay<=0. then
|
||||
add_timeout(interval,report)
|
||||
else
|
||||
add_timeout(delay,{add_timeout(interval,report) (-1.)})
|
||||
end
|
||||
end
|
|
@ -1,18 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
DATE=$(date '+%Y-%m-%d')
|
||||
CI_LOG=/var/log/obp/ci/log-$DATE.php
|
||||
|
||||
clear
|
||||
echo
|
||||
echo "##############################"
|
||||
echo "# STARTING PYPO MULTI-LOG #"
|
||||
echo "##############################"
|
||||
sleep 1
|
||||
clear
|
||||
|
||||
# split
|
||||
multitail -s 2 -cS pyml /var/log/obp/pypo/debug.log \
|
||||
-cS pyml /var/log/obp/pypo/error.log \
|
||||
-l "tail -f -n 50 $CI_LOG | grep API" \
|
||||
/var/log/obp/ls/ls_script.log
|
|
@ -1,42 +0,0 @@
|
|||
###########################################
|
||||
# liquidsoap config file #
|
||||
###########################################
|
||||
# This config assumes that there are
|
||||
# two instances of LS running
|
||||
# the "scheduler" & the "fallback" instance
|
||||
|
||||
|
||||
###########################################
|
||||
# general settings #
|
||||
###########################################
|
||||
|
||||
log_file = "/var/log/pypo/<script>.log"
|
||||
log_level = 3
|
||||
|
||||
# archive directory
|
||||
archive_dir = "/opt/pypo/archive/"
|
||||
|
||||
# list pointing to the current couchcaster mountpoint
|
||||
couchcaster_list = "http://vdeb.openbroadcast.ch/mod/ml/api/pypo/current_couchcaster"
|
||||
|
||||
|
||||
###########################################
|
||||
# stream settings #
|
||||
###########################################
|
||||
icecast_host = "127.0.0.1"
|
||||
icecast_port = 8000
|
||||
icecast_pass = "hackme"
|
||||
|
||||
# mountpoints
|
||||
mount_scheduler = "pypo_scheduler.mp3"
|
||||
mount_fallback = "pypo_fallback.mp3"
|
||||
mount_final = "pypo_final.mp3"
|
||||
|
||||
# mount intra is used for scheduler >>> fallback stream
|
||||
mount_intra = "pypo_intra"
|
||||
|
||||
# intra-LS streaming (no icecast here)
|
||||
intra_host = "127.0.0.1"
|
||||
intra_port = 9000
|
||||
intra_pass = "hackme"
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
###########################################
|
||||
# liquidsoap config file #
|
||||
###########################################
|
||||
|
||||
# This config assumes that there are
|
||||
# two instances of LS running
|
||||
# the "scheduler" & the "fallback" instance
|
||||
|
||||
|
||||
###########################################
|
||||
# general settings #
|
||||
###########################################
|
||||
|
||||
log_file = "/var/log/pypo/<script>.log"
|
||||
log_level = 5
|
||||
|
||||
# archive directory
|
||||
archive_dir = "/opt/pypo/archive/"
|
||||
|
||||
# list pointing to the current couchcaster mountpoint
|
||||
couchcaster_list = "http://stage.openbroadcast.ch/mod/ml/api/pypo/current_couchcaster"
|
||||
|
||||
|
||||
|
||||
###########################################
|
||||
# stream settings #
|
||||
###########################################
|
||||
icecast_host = "stream.domain.com"
|
||||
icecast_port = 8000
|
||||
icecast_pass = "hackme"
|
||||
|
||||
# mountpoints
|
||||
mount_scheduler = "pypo_scheduler.mp3"
|
||||
mount_fallback = "pypo_fallback.mp3"
|
||||
mount_final = "pypo_final.mp3"
|
||||
|
||||
# mount intra is used for scheduler >>> fallback stream
|
||||
mount_intra = "pypo_intra"
|
||||
|
||||
# intra-LS streaming (no icecast here)
|
||||
intra_host = "pypo-fallback.my-playout-server.xyz.net"
|
||||
intra_port = 9000
|
||||
intra_pass = "hackmetoo"
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
|
||||
# Register the cut protocol
|
||||
def cue_protocol(arg,delay)
|
||||
# The extraction program
|
||||
# cut_file = "#{configure.libdir}/cut-file.py"
|
||||
cue_script = "./cue_file.py"
|
||||
# Parse args
|
||||
ret = string.extract(pattern="cue_in=(\d+)",arg)
|
||||
start =
|
||||
if list.length(ret) == 0 then
|
||||
"0"
|
||||
else
|
||||
ret["1"]
|
||||
end
|
||||
ret = string.extract(pattern="cue_out=(\d+)",arg)
|
||||
stop =
|
||||
if list.length(ret) == 0 then
|
||||
"0"
|
||||
else
|
||||
ret["1"]
|
||||
end
|
||||
ret = string.extract(pattern=":(.*)$",arg)
|
||||
uri =
|
||||
if list.length(ret) == 0 then
|
||||
""
|
||||
else
|
||||
ret["1"]
|
||||
end
|
||||
x = get_process_lines("#{cue_script} #{quote(uri)} #{start} #{stop}")
|
||||
if list.hd(x) != "" then
|
||||
([list.hd(x)],[])
|
||||
else
|
||||
([uri],[])
|
||||
end
|
||||
end
|
||||
add_post_processor("cue_file", temporary=true, cue_protocol)
|
|
@ -1,7 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
# export home dir
|
||||
#export HOME=/home/pypo/
|
||||
|
||||
# start liquidsoap with corresponding user & scrupt
|
||||
sudo -u pypo /usr/local/bin/liquidsoap ls_script.liq
|
|
@ -1,106 +0,0 @@
|
|||
######################################
|
||||
# main liquidsoap development script #
|
||||
######################################
|
||||
# author Jonas Ohrstrom <jonas@digris.ch>
|
||||
|
||||
########################################
|
||||
# include configuration #
|
||||
########################################
|
||||
|
||||
%include "library/pervasives.liq"
|
||||
%include "ls_config.liq"
|
||||
%include "library.liq"
|
||||
%include "include_dynamic_vars.liq"
|
||||
%include "include_notify.liq"
|
||||
|
||||
silence_threshold = -50.
|
||||
silence_time = 3.
|
||||
|
||||
# log
|
||||
set("log.file.path",log_file)
|
||||
set("log.stdout", true)
|
||||
set("log.level",log_level)
|
||||
|
||||
# telnet server
|
||||
set("server.telnet", true)
|
||||
|
||||
######################################
|
||||
# some functions needed #
|
||||
######################################
|
||||
def fcross(a,b) =
|
||||
add(normalize=false,[b,a])
|
||||
end
|
||||
|
||||
######################################
|
||||
# live recording functions
|
||||
######################################
|
||||
def live_start() =
|
||||
log("got live source")
|
||||
ignore(execute("archives.start"))
|
||||
end
|
||||
|
||||
def live_stop() =
|
||||
log("live source has gone")
|
||||
ignore(execute("archives.stop"))
|
||||
end
|
||||
|
||||
|
||||
#######################################################################
|
||||
# File locations / sources
|
||||
#######################################################################
|
||||
silence = single("/opt/pypo/files/basic/silence.mp3")
|
||||
jingles_cc = playlist("/opt/pypo/files/jingles/jcc")
|
||||
fallback_airtime = playlist("/opt/pypo/files/basic/silence-playlist.lsp")
|
||||
fallback_airtime = audio_to_stereo(fallback_airtime)
|
||||
|
||||
|
||||
# default
|
||||
default = silence
|
||||
|
||||
special = request.queue(id="special")
|
||||
|
||||
|
||||
#######################################################################
|
||||
# Includeing two A/B Queues, daypart & scheduler
|
||||
# this will give us the sources 'daypart' & 'scheduler'
|
||||
#######################################################################
|
||||
%include "include_daypart.liq"
|
||||
%include "include_scheduler.liq"
|
||||
|
||||
source = fallback(track_sensitive=false,transitions=[dp_to_scheduler],[strip_blank(threshold=silence_threshold,length=silence_time,scheduler),daypart])
|
||||
|
||||
%include "include_live_in.liq"
|
||||
|
||||
live = fallback(track_sensitive=false,[strip_blank(threshold=silence_threshold,length=silence_time,live),fallback_airtime])
|
||||
live = switch(track_sensitive=false, [({!live_active},live)])
|
||||
|
||||
source = fallback(track_sensitive=false,transitions=[to_live_s, to_scheduler_s],[live, source])
|
||||
|
||||
# handle the annotate fades
|
||||
faded = fade.in(type="log", fade.out(type="log", source))
|
||||
|
||||
# add up with a crossfade function (defined above)
|
||||
source = cross(fcross,faded)
|
||||
|
||||
# track start detection (for notifications)
|
||||
source = on_metadata(notify, source)
|
||||
#source = on_track(notify, source)
|
||||
|
||||
# special to mix with final source
|
||||
source = smooth_add(normal=source,special=special)
|
||||
|
||||
|
||||
#####################################
|
||||
# Stream Output
|
||||
#####################################
|
||||
# finally the output | mp3
|
||||
#clock(id="clock_icecast",
|
||||
# output.icecast(%mp3,
|
||||
# host = icecast_host, port = icecast_port,
|
||||
# password = icecast_pass, mount = mount_scheduler,
|
||||
# fallible = true,
|
||||
# restart = true,
|
||||
# restart_delay = 5,
|
||||
# buffer(source)))
|
||||
|
||||
out(source)
|
|
@ -1,7 +0,0 @@
|
|||
#!/bin/sh
|
||||
############################################
|
||||
# just a wrapper to call the notifyer #
|
||||
# needed here to keep dirs/configs clean #
|
||||
# and maybe to set user-rights #
|
||||
############################################
|
||||
cd ../ && ./pypo-notify.py $1 $2 $3 $4 $5 $6 $7 $8 &
|
|
@ -1,48 +0,0 @@
|
|||
/opt/pypo/files/basic/silence.mp3
|
||||
/opt/pypo/files/basic/silence.mp3
|
||||
/opt/pypo/files/basic/silence.mp3
|
||||
/opt/pypo/files/basic/silence.mp3
|
||||
/opt/pypo/files/basic/silence.mp3
|
||||
/opt/pypo/files/basic/silence.mp3
|
||||
/opt/pypo/files/basic/silence.mp3
|
||||
/opt/pypo/files/basic/silence.mp3
|
||||
/opt/pypo/files/basic/silence.mp3
|
||||
/opt/pypo/files/basic/silence.mp3
|
||||
/opt/pypo/files/basic/silence.mp3
|
||||
/opt/pypo/files/basic/silence.mp3
|
||||
/opt/pypo/files/basic/silence.mp3
|
||||
/opt/pypo/files/basic/silence.mp3
|
||||
/opt/pypo/files/basic/silence.mp3
|
||||
/opt/pypo/files/basic/silence.mp3
|
||||
/opt/pypo/files/basic/silence.mp3
|
||||
/opt/pypo/files/basic/silence.mp3
|
||||
/opt/pypo/files/basic/silence.mp3
|
||||
/opt/pypo/files/basic/silence.mp3
|
||||
/opt/pypo/files/basic/silence.mp3
|
||||
/opt/pypo/files/basic/silence.mp3
|
||||
/opt/pypo/files/basic/silence.mp3
|
||||
/opt/pypo/files/basic/silence.mp3
|
||||
/opt/pypo/files/basic/silence.mp3
|
||||
/opt/pypo/files/basic/silence.mp3
|
||||
/opt/pypo/files/basic/silence.mp3
|
||||
/opt/pypo/files/basic/silence.mp3
|
||||
/opt/pypo/files/basic/silence.mp3
|
||||
/opt/pypo/files/basic/silence.mp3
|
||||
/opt/pypo/files/basic/silence.mp3
|
||||
/opt/pypo/files/basic/silence.mp3
|
||||
/opt/pypo/files/basic/silence.mp3
|
||||
/opt/pypo/files/basic/silence.mp3
|
||||
/opt/pypo/files/basic/silence.mp3
|
||||
/opt/pypo/files/basic/silence.mp3
|
||||
/opt/pypo/files/basic/silence.mp3
|
||||
/opt/pypo/files/basic/silence.mp3
|
||||
/opt/pypo/files/basic/silence.mp3
|
||||
/opt/pypo/files/basic/silence.mp3
|
||||
/opt/pypo/files/basic/silence.mp3
|
||||
/opt/pypo/files/basic/silence.mp3
|
||||
/opt/pypo/files/basic/silence.mp3
|
||||
/opt/pypo/files/basic/silence.mp3
|
||||
/opt/pypo/files/basic/silence.mp3
|
||||
/opt/pypo/files/basic/silence.mp3
|
||||
/opt/pypo/files/basic/silence.mp3
|
||||
/opt/pypo/files/basic/silence.mp3
|
Binary file not shown.
|
@ -1,97 +0,0 @@
|
|||
<?php
|
||||
require_once '../../application/configs/conf.php';
|
||||
require_once 'DB.php';
|
||||
require_once '../../application/models/Playlist.php';
|
||||
require_once '../../application/models/StoredFile.php';
|
||||
require_once(__DIR__.'/../../library/propel/runtime/lib/Propel.php');
|
||||
// Initialize Propel with the runtime configuration
|
||||
Propel::init(__DIR__."/../../application/configs/propel-config.php");
|
||||
// Add the generated 'classes' directory to the include path
|
||||
set_include_path(__DIR__."/../../application/models" . PATH_SEPARATOR . get_include_path());
|
||||
|
||||
$dsn = $CC_CONFIG['dsn'];
|
||||
|
||||
$CC_DBC = DB::connect($dsn, TRUE);
|
||||
if (PEAR::isError($CC_DBC)) {
|
||||
echo "ERROR: ".$CC_DBC->getMessage()." ".$CC_DBC->getUserInfo()."\n";
|
||||
exit(1);
|
||||
}
|
||||
$CC_DBC->setFetchMode(DB_FETCHMODE_ASSOC);
|
||||
|
||||
|
||||
$playlistName = "pypo_playlist_test";
|
||||
$minutesFromNow = 1;
|
||||
|
||||
echo " ************************************************************** \n";
|
||||
echo " This script schedules a playlist to play $minutesFromNow minute(s) from now.\n";
|
||||
echo " This is a utility to help you debug the scheduler.\n";
|
||||
echo " ************************************************************** \n";
|
||||
echo "\n";
|
||||
echo "Deleting playlists with the name '$playlistName'...";
|
||||
// Delete any old playlists
|
||||
$pl2 = Playlist::findPlaylistByName($playlistName);
|
||||
foreach ($pl2 as $playlist) {
|
||||
//var_dump($playlist);
|
||||
$playlist->delete();
|
||||
}
|
||||
echo "done.\n";
|
||||
|
||||
// Create a new playlist
|
||||
echo "Creating new playlist '$playlistName'...";
|
||||
$pl = new Playlist();
|
||||
$pl->create($playlistName);
|
||||
|
||||
// Add a media clip
|
||||
$mediaFile = StoredFile::findByOriginalName("ACDC_-_Back_In_Black-sample.ogg");
|
||||
if (is_null($mediaFile)) {
|
||||
echo "Adding test audio clip to the database.\n";
|
||||
$v = array("filepath" => __DIR__."/../../audio_samples/OpSound/ACDC_-_Back_In_Black-sample.ogg");
|
||||
$mediaFile = StoredFile::Insert($v);
|
||||
if (PEAR::isError($mediaFile)) {
|
||||
var_dump($mediaFile);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
$pl->addAudioClip($mediaFile->getId());
|
||||
|
||||
$mediaFile = StoredFile::findByOriginalName("Peter_Rudenko_-_Opening.mp3");
|
||||
if (is_null($mediaFile)) {
|
||||
echo "Adding test audio clip to the database.\n";
|
||||
$v = array("filepath" => __DIR__."/../../audio_samples/OpSound/Peter Rudenko - Opening.mp3");
|
||||
$mediaFile = StoredFile::Insert($v);
|
||||
if (PEAR::isError($mediaFile)) {
|
||||
var_dump($mediaFile);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
$pl->addAudioClip($mediaFile->getId());
|
||||
echo "done.\n";
|
||||
|
||||
//$pl2 = Playlist::findPlaylistByName("pypo_playlist_test");
|
||||
//var_dump($pl2);
|
||||
|
||||
// Get current time
|
||||
// In the format YYYY-MM-DD HH:MM:SS.nnnnnn
|
||||
$startTime = date("Y-m-d H:i:s");
|
||||
$endTime = date("Y-m-d H:i:s", time()+(60*60));
|
||||
|
||||
echo "Removing everything from the scheduler between $startTime and $endTime...";
|
||||
// Scheduler: remove any playlists for the next hour
|
||||
Schedule::RemoveItemsInRange($startTime, $endTime);
|
||||
// Check for succcess
|
||||
$scheduleClear = Schedule::isScheduleEmptyInRange($startTime, "01:00:00");
|
||||
if (!$scheduleClear) {
|
||||
echo "\nERROR: Schedule could not be cleared.\n\n";
|
||||
var_dump(Schedule::GetItems($startTime, $endTime));
|
||||
exit;
|
||||
}
|
||||
echo "done.\n";
|
||||
|
||||
// Schedule the playlist for two minutes from now
|
||||
echo "Scheduling new playlist...\n";
|
||||
$playTime = date("Y-m-d H:i:s", time()+(60*$minutesFromNow));
|
||||
$scheduleGroup = new ScheduleGroup();
|
||||
$scheduleGroup->add($playTime, null, $pl->getId());
|
||||
|
||||
echo " SUCCESS: Playlist scheduled at $playTime\n\n";
|
||||
?>
|
|
@ -1,5 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from json import *
|
||||
from status import *
|
||||
from cue_file import *
|
|
@ -1,90 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import sys
|
||||
import shutil
|
||||
import random
|
||||
import string
|
||||
import time
|
||||
from datetime import timedelta
|
||||
import os
|
||||
import logging
|
||||
|
||||
from mutagen.mp3 import MP3
|
||||
from mutagen.oggvorbis import OggVorbis
|
||||
|
||||
class CueFile():
|
||||
|
||||
def __init__(self):
|
||||
logger = logging.getLogger("cue_file")
|
||||
logger.debug("init")
|
||||
|
||||
def cue(self, src, dst, cue_in, cue_out):
|
||||
|
||||
logger = logging.getLogger("cue_file.cue")
|
||||
logger.debug("cue file: %s %s %s %s", src, dst, cue_in, cue_out)
|
||||
|
||||
if src.lower().endswith('.mp3'):
|
||||
# mutagen
|
||||
audio = MP3(src)
|
||||
dur = round(audio.info.length, 3)
|
||||
|
||||
logger.debug("duration by mutagen: %s", dur)
|
||||
|
||||
cue_out = round(float(dur) - cue_out, 3)
|
||||
|
||||
str_cue_in = str(timedelta(seconds=cue_in)).replace(".", "+") # hh:mm:ss+mss, eg 00:00:20+000
|
||||
str_cue_out = str(timedelta(seconds=cue_out)).replace(".", "+") #
|
||||
|
||||
"""
|
||||
now a bit a hackish part, don't know how to do this better...
|
||||
need to cut the digits after the "+"
|
||||
"""
|
||||
ts = str_cue_in.split("+")
|
||||
try:
|
||||
if len(ts[1]) == 6:
|
||||
ts[1] = ts[1][0:3]
|
||||
str_cue_in = "%s+%s" % (ts[0], ts[1])
|
||||
except Exception, e:
|
||||
pass
|
||||
|
||||
ts = str_cue_out.split("+")
|
||||
try:
|
||||
if len(ts[1]) == 6:
|
||||
ts[1] = ts[1][0:3]
|
||||
str_cue_out = "%s+%s" % (ts[0], ts[1])
|
||||
except Exception, e:
|
||||
pass
|
||||
|
||||
logger.debug("in: %s", str_cue_in)
|
||||
logger.debug("out: %s", str(str_cue_out) )
|
||||
|
||||
command = 'mp3cut -o %s -t %s-%s %s' % (dst + '.tmp.mp3', str_cue_in, str_cue_out, src);
|
||||
logger.info("command: %s", command)
|
||||
print command
|
||||
os.system(command + ' > /dev/null 2>&1')
|
||||
|
||||
command = 'lame -b 32 %s %s' % (dst + '.tmp.mp3', dst);
|
||||
logger.info("command: %s", command)
|
||||
print command
|
||||
os.system(command + ' > /dev/null 2>&1')
|
||||
elif src.lower().endswith('.ogg'):
|
||||
audio = OggVorbis(src)
|
||||
dur = audio.info.length
|
||||
sys.stderr.write('duration: ' + str(dur) + '\n')
|
||||
|
||||
cue_out = float(dur) - cue_out
|
||||
|
||||
#convert input format of ss.mmm to milliseconds and to string<
|
||||
str_cue_in = str(int(round(cue_in*1000)))
|
||||
|
||||
#convert input format of ss.mmm to milliseconds and to string
|
||||
str_cue_out = str(int(round(cue_out*1000)))
|
||||
|
||||
command = 'oggCut -s %s -e %s %s %s' % (str_cue_in, str_cue_out, src, dst)
|
||||
logger.info("command: %s", command)
|
||||
os.system(command + ' > /dev/null 2>&1')
|
||||
else:
|
||||
logger.debug("in: %s", 'File name with invalid extension. File will not be cut\n')
|
||||
|
||||
return dst
|
|
@ -1,310 +0,0 @@
|
|||
import string
|
||||
import types
|
||||
|
||||
## json.py implements a JSON (http://json.org) reader and writer.
|
||||
## Copyright (C) 2005 Patrick D. Logan
|
||||
## Contact mailto:patrickdlogan@stardecisions.com
|
||||
##
|
||||
## This library is free software; you can redistribute it and/or
|
||||
## modify it under the terms of the GNU Lesser General Public
|
||||
## License as published by the Free Software Foundation; either
|
||||
## version 2.1 of the License, or (at your option) any later version.
|
||||
##
|
||||
## This library 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
|
||||
## Lesser General Public License for more details.
|
||||
##
|
||||
## You should have received a copy of the GNU Lesser General Public
|
||||
## License along with this library; if not, write to the Free Software
|
||||
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
|
||||
class _StringGenerator(object):
|
||||
def __init__(self, string):
|
||||
self.string = string
|
||||
self.index = -1
|
||||
def peek(self):
|
||||
i = self.index + 1
|
||||
if i < len(self.string):
|
||||
return self.string[i]
|
||||
else:
|
||||
return None
|
||||
def next(self):
|
||||
self.index += 1
|
||||
if self.index < len(self.string):
|
||||
return self.string[self.index]
|
||||
else:
|
||||
raise StopIteration
|
||||
def all(self):
|
||||
return self.string
|
||||
|
||||
class WriteException(Exception):
|
||||
pass
|
||||
|
||||
class ReadException(Exception):
|
||||
pass
|
||||
|
||||
class JsonReader(object):
|
||||
hex_digits = {'A': 10,'B': 11,'C': 12,'D': 13,'E': 14,'F':15}
|
||||
escapes = {'t':'\t','n':'\n','f':'\f','r':'\r','b':'\b'}
|
||||
|
||||
def read(self, s):
|
||||
self._generator = _StringGenerator(s)
|
||||
result = self._read()
|
||||
return result
|
||||
|
||||
def _read(self):
|
||||
self._eatWhitespace()
|
||||
peek = self._peek()
|
||||
if peek is None:
|
||||
raise ReadException, "Nothing to read: '%s'" % self._generator.all()
|
||||
if peek == '{':
|
||||
return self._readObject()
|
||||
elif peek == '[':
|
||||
return self._readArray()
|
||||
elif peek == '"':
|
||||
return self._readString()
|
||||
elif peek == '-' or peek.isdigit():
|
||||
return self._readNumber()
|
||||
elif peek == 't':
|
||||
return self._readTrue()
|
||||
elif peek == 'f':
|
||||
return self._readFalse()
|
||||
elif peek == 'n':
|
||||
return self._readNull()
|
||||
elif peek == '/':
|
||||
self._readComment()
|
||||
return self._read()
|
||||
else:
|
||||
raise ReadException, "Input is not valid JSON: '%s'" % self._generator.all()
|
||||
|
||||
def _readTrue(self):
|
||||
self._assertNext('t', "true")
|
||||
self._assertNext('r', "true")
|
||||
self._assertNext('u', "true")
|
||||
self._assertNext('e', "true")
|
||||
return True
|
||||
|
||||
def _readFalse(self):
|
||||
self._assertNext('f', "false")
|
||||
self._assertNext('a', "false")
|
||||
self._assertNext('l', "false")
|
||||
self._assertNext('s', "false")
|
||||
self._assertNext('e', "false")
|
||||
return False
|
||||
|
||||
def _readNull(self):
|
||||
self._assertNext('n', "null")
|
||||
self._assertNext('u', "null")
|
||||
self._assertNext('l', "null")
|
||||
self._assertNext('l', "null")
|
||||
return None
|
||||
|
||||
def _assertNext(self, ch, target):
|
||||
if self._next() != ch:
|
||||
raise ReadException, "Trying to read %s: '%s'" % (target, self._generator.all())
|
||||
|
||||
def _readNumber(self):
|
||||
isfloat = False
|
||||
result = self._next()
|
||||
peek = self._peek()
|
||||
while peek is not None and (peek.isdigit() or peek == "."):
|
||||
isfloat = isfloat or peek == "."
|
||||
result = result + self._next()
|
||||
peek = self._peek()
|
||||
try:
|
||||
if isfloat:
|
||||
return float(result)
|
||||
else:
|
||||
return int(result)
|
||||
except ValueError:
|
||||
raise ReadException, "Not a valid JSON number: '%s'" % result
|
||||
|
||||
def _readString(self):
|
||||
result = ""
|
||||
assert self._next() == '"'
|
||||
try:
|
||||
while self._peek() != '"':
|
||||
ch = self._next()
|
||||
if ch == "\\":
|
||||
ch = self._next()
|
||||
if ch in 'brnft':
|
||||
ch = self.escapes[ch]
|
||||
elif ch == "u":
|
||||
ch4096 = self._next()
|
||||
ch256 = self._next()
|
||||
ch16 = self._next()
|
||||
ch1 = self._next()
|
||||
n = 4096 * self._hexDigitToInt(ch4096)
|
||||
n += 256 * self._hexDigitToInt(ch256)
|
||||
n += 16 * self._hexDigitToInt(ch16)
|
||||
n += self._hexDigitToInt(ch1)
|
||||
ch = unichr(n)
|
||||
elif ch not in '"/\\':
|
||||
raise ReadException, "Not a valid escaped JSON character: '%s' in %s" % (ch, self._generator.all())
|
||||
result = result + ch
|
||||
except StopIteration:
|
||||
raise ReadException, "Not a valid JSON string: '%s'" % self._generator.all()
|
||||
assert self._next() == '"'
|
||||
return result
|
||||
|
||||
def _hexDigitToInt(self, ch):
|
||||
try:
|
||||
result = self.hex_digits[ch.upper()]
|
||||
except KeyError:
|
||||
try:
|
||||
result = int(ch)
|
||||
except ValueError:
|
||||
raise ReadException, "The character %s is not a hex digit." % ch
|
||||
return result
|
||||
|
||||
def _readComment(self):
|
||||
assert self._next() == "/"
|
||||
second = self._next()
|
||||
if second == "/":
|
||||
self._readDoubleSolidusComment()
|
||||
elif second == '*':
|
||||
self._readCStyleComment()
|
||||
else:
|
||||
raise ReadException, "Not a valid JSON comment: %s" % self._generator.all()
|
||||
|
||||
def _readCStyleComment(self):
|
||||
try:
|
||||
done = False
|
||||
while not done:
|
||||
ch = self._next()
|
||||
done = (ch == "*" and self._peek() == "/")
|
||||
if not done and ch == "/" and self._peek() == "*":
|
||||
raise ReadException, "Not a valid JSON comment: %s, '/*' cannot be embedded in the comment." % self._generator.all()
|
||||
self._next()
|
||||
except StopIteration:
|
||||
raise ReadException, "Not a valid JSON comment: %s, expected */" % self._generator.all()
|
||||
|
||||
def _readDoubleSolidusComment(self):
|
||||
try:
|
||||
ch = self._next()
|
||||
while ch != "\r" and ch != "\n":
|
||||
ch = self._next()
|
||||
except StopIteration:
|
||||
pass
|
||||
|
||||
def _readArray(self):
|
||||
result = []
|
||||
assert self._next() == '['
|
||||
done = self._peek() == ']'
|
||||
while not done:
|
||||
item = self._read()
|
||||
result.append(item)
|
||||
self._eatWhitespace()
|
||||
done = self._peek() == ']'
|
||||
if not done:
|
||||
ch = self._next()
|
||||
if ch != ",":
|
||||
raise ReadException, "Not a valid JSON array: '%s' due to: '%s'" % (self._generator.all(), ch)
|
||||
assert ']' == self._next()
|
||||
return result
|
||||
|
||||
def _readObject(self):
|
||||
result = {}
|
||||
assert self._next() == '{'
|
||||
done = self._peek() == '}'
|
||||
while not done:
|
||||
key = self._read()
|
||||
if type(key) is not types.StringType:
|
||||
raise ReadException, "Not a valid JSON object key (should be a string): %s" % key
|
||||
self._eatWhitespace()
|
||||
ch = self._next()
|
||||
if ch != ":":
|
||||
raise ReadException, "Not a valid JSON object: '%s' due to: '%s'" % (self._generator.all(), ch)
|
||||
self._eatWhitespace()
|
||||
val = self._read()
|
||||
result[key] = val
|
||||
self._eatWhitespace()
|
||||
done = self._peek() == '}'
|
||||
if not done:
|
||||
ch = self._next()
|
||||
if ch != ",":
|
||||
raise ReadException, "Not a valid JSON array: '%s' due to: '%s'" % (self._generator.all(), ch)
|
||||
assert self._next() == "}"
|
||||
return result
|
||||
|
||||
def _eatWhitespace(self):
|
||||
p = self._peek()
|
||||
while p is not None and p in string.whitespace or p == '/':
|
||||
if p == '/':
|
||||
self._readComment()
|
||||
else:
|
||||
self._next()
|
||||
p = self._peek()
|
||||
|
||||
def _peek(self):
|
||||
return self._generator.peek()
|
||||
|
||||
def _next(self):
|
||||
return self._generator.next()
|
||||
|
||||
class JsonWriter(object):
|
||||
|
||||
def _append(self, s):
|
||||
self._results.append(s)
|
||||
|
||||
def write(self, obj, escaped_forward_slash=False):
|
||||
self._escaped_forward_slash = escaped_forward_slash
|
||||
self._results = []
|
||||
self._write(obj)
|
||||
return "".join(self._results)
|
||||
|
||||
def _write(self, obj):
|
||||
ty = type(obj)
|
||||
if ty is types.DictType:
|
||||
n = len(obj)
|
||||
self._append("{")
|
||||
for k, v in obj.items():
|
||||
self._write(k)
|
||||
self._append(":")
|
||||
self._write(v)
|
||||
n = n - 1
|
||||
if n > 0:
|
||||
self._append(",")
|
||||
self._append("}")
|
||||
elif ty is types.ListType or ty is types.TupleType:
|
||||
n = len(obj)
|
||||
self._append("[")
|
||||
for item in obj:
|
||||
self._write(item)
|
||||
n = n - 1
|
||||
if n > 0:
|
||||
self._append(",")
|
||||
self._append("]")
|
||||
elif ty is types.StringType or ty is types.UnicodeType:
|
||||
self._append('"')
|
||||
obj = obj.replace('\\', r'\\')
|
||||
if self._escaped_forward_slash:
|
||||
obj = obj.replace('/', r'\/')
|
||||
obj = obj.replace('"', r'\"')
|
||||
obj = obj.replace('\b', r'\b')
|
||||
obj = obj.replace('\f', r'\f')
|
||||
obj = obj.replace('\n', r'\n')
|
||||
obj = obj.replace('\r', r'\r')
|
||||
obj = obj.replace('\t', r'\t')
|
||||
self._append(obj)
|
||||
self._append('"')
|
||||
elif ty is types.IntType or ty is types.LongType:
|
||||
self._append(str(obj))
|
||||
elif ty is types.FloatType:
|
||||
self._append("%f" % obj)
|
||||
elif obj is True:
|
||||
self._append("true")
|
||||
elif obj is False:
|
||||
self._append("false")
|
||||
elif obj is None:
|
||||
self._append("null")
|
||||
else:
|
||||
raise WriteException, "Cannot write in JSON: %s" % repr(obj)
|
||||
|
||||
def write(obj, escaped_forward_slash=False):
|
||||
return JsonWriter().write(obj, escaped_forward_slash)
|
||||
|
||||
def read(s):
|
||||
return JsonReader().read(s)
|
|
@ -1,59 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
import sys
|
||||
import time
|
||||
import urllib
|
||||
|
||||
import logging
|
||||
|
||||
import telnetlib
|
||||
|
||||
from util import json
|
||||
|
||||
import os
|
||||
|
||||
ALLOWED_EXTS = ('mp3')
|
||||
|
||||
class Callable:
|
||||
def __init__(self, anycallable):
|
||||
self.__call__ = anycallable
|
||||
|
||||
class Status:
|
||||
def __init__(self, status_url):
|
||||
self.status_url = status_url
|
||||
def get_obp_version(self):
|
||||
logger = logging.getLogger("status.get_obp_version")
|
||||
# lookup OBP version
|
||||
try:
|
||||
response = urllib.urlopen(self.status_url)
|
||||
response_json = json.read(response.read())
|
||||
obp_version = int(response_json['version'])
|
||||
logger.debug("OBP Version %s detected", obp_version)
|
||||
|
||||
except Exception, e:
|
||||
print e
|
||||
obp_version = 0
|
||||
logger.error("Unable to detect OBP Version - %s", e)
|
||||
|
||||
|
||||
return obp_version
|
||||
|
||||
|
||||
def check_ls(self, ls_host, ls_port):
|
||||
logger = logging.getLogger("status.get_ls_version")
|
||||
# lookup OBP version
|
||||
try:
|
||||
tn = telnetlib.Telnet(ls_host, ls_port)
|
||||
tn.write("\n")
|
||||
tn.write("version\n")
|
||||
tn.write("exit\n")
|
||||
print tn.read_all()
|
||||
logger.info("liquidsoap connection ok")
|
||||
return 1
|
||||
|
||||
except Exception, e:
|
||||
obp_version = 0
|
||||
logger.error("Unable to connect to liquidsoap")
|
||||
return 0
|
||||
|
||||
|
Loading…
Reference in New Issue