pax_global_header 0000666 0000000 0000000 00000000064 14171042373 0014514 g ustar 00root root 0000000 0000000 52 comment=6073355fc9a5cbe5d2bce68c9fbb215df91d3015
vlc-bittorrent-2.14/ 0000775 0000000 0000000 00000000000 14171042373 0014420 5 ustar 00root root 0000000 0000000 vlc-bittorrent-2.14/.clang-format 0000664 0000000 0000000 00000000276 14171042373 0017000 0 ustar 00root root 0000000 0000000 ---
Language: Cpp
BasedOnStyle: WebKit
ColumnLimit: 80
AlignEscapedNewlines: DontAlign
AllowShortFunctionsOnASingleLine: Empty
AlwaysBreakAfterReturnType: All
SpaceAfterCStyleCast: true
---
vlc-bittorrent-2.14/.dockerignore 0000664 0000000 0000000 00000000005 14171042373 0017067 0 ustar 00root root 0000000 0000000 .git
vlc-bittorrent-2.14/.github/ 0000775 0000000 0000000 00000000000 14171042373 0015760 5 ustar 00root root 0000000 0000000 vlc-bittorrent-2.14/.github/workflows/ 0000775 0000000 0000000 00000000000 14171042373 0020015 5 ustar 00root root 0000000 0000000 vlc-bittorrent-2.14/.github/workflows/ci.yml 0000664 0000000 0000000 00000001631 14171042373 0021134 0 ustar 00root root 0000000 0000000 name: vlc-bittorrent CI
on:
push:
branches: '*'
schedule:
- cron: "00 22 * * 0"
jobs:
ubuntu:
runs-on: ubuntu-latest
name: 'Ubuntu (${{ matrix.image }})'
timeout-minutes: 20
strategy:
matrix:
image:
- 'ubuntu:latest'
- 'ubuntu:rolling'
- 'ubuntu:devel'
fail-fast: false
container:
image: ${{ matrix.image }}
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install dependencies
env:
DEBIAN_FRONTEND: noninteractive
run: |
apt-get update
apt-get -y install autoconf autoconf-archive automake build-essential libtool libtorrent-rasterbar-dev libvlccore-dev libvlc-dev vlc
- name: Build
run: |
autoreconf -i
./configure --with-tests
make
- name: Test
run: |
make check || (cat test/*.log test/data/*.log && false)
vlc-bittorrent-2.14/.gitignore 0000664 0000000 0000000 00000000411 14171042373 0016404 0 ustar 00root root 0000000 0000000 *.a
*.la
*.lai
*.lo
*.o
*.so
# generated files
m4
Makefile
Makefile.in
.deps
.libs
/aclocal.m4
/autom4te.cache
/build-aux
/compile
/config.guess
/config.log
/config.status
/config.sub
/configure
/depcomp
/install-sh
/libtool
/ltmain.sh
/missing
.dirstamp
.gdbinit
vlc-bittorrent-2.14/LICENSE 0000664 0000000 0000000 00000104505 14171042373 0015432 0 ustar 00root root 0000000 0000000 GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc.
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
{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 .
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:
{project} Copyright (C) {year} {fullname}
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
.
vlc-bittorrent-2.14/Makefile.am 0000664 0000000 0000000 00000000151 14171042373 0016451 0 ustar 00root root 0000000 0000000 AUTOMAKE_OPTIONS = foreign
SUBDIRS = src data
if WITH_TESTS
SUBDIRS += test
endif
EXTRA_DIST = LICENSE
vlc-bittorrent-2.14/README.md 0000664 0000000 0000000 00000003017 14171042373 0015700 0 ustar 00root root 0000000 0000000 # vlc-bittorrent (Bittorrent plugin for VLC)
## What is this?
With vlc-bittorrent, you can open a **.torrent** file or **magnet link** with VLC and stream any media that it contains.
## Example usage
$ vlc video.torrent
$ vlc http://example.com/video.torrent
$ vlc https://example.com/video.torrent
$ vlc ftp://example.com/video.torrent
$ vlc "magnet:?xt=urn:btih:...&dn=...&tr=..."
$ vlc "magnet://?xt=urn:btih:...&dn=...&tr=..."
## Installing on Debian/Ubuntu
$ sudo apt-get install vlc-plugin-bittorrent
## Installing on Fedora
$ sudo dnf install vlc-bittorrent
## FAQ
### Does it upload/share/seed while playing?
Yes. It works as a regular Bittorrent client. It will upload as long as it's playing.
### Does it work on Ubuntu/Debian?
Yes!
### Does it work on Windows, Mac OS X, Android, Windows RT, iOS, my toaster?
Probably. I have not tested. It should run since libtorrent works on most systems and the plugin is just standard C and C++. Patches are welcome.
## Dependencies (on Linux)
* libtorrent ("libtorrent-rasterbar9" in Ubuntu 18.04)
## Building from git on a recent Debian/Ubuntu
$ sudo apt-get install autoconf automake libtool make libvlc-dev libvlccore-dev libtorrent-rasterbar-dev g++
$ git clone https://github.com/johang/vlc-bittorrent.git vlc-bittorrent
$ cd vlc-bittorrent
$ autoreconf -i
$ ./configure --prefix=/tmp/vlc
$ make
$ make install
Then, to load it in VLC player:
$ VLC_PLUGIN_PATH=/tmp/vlc/lib vlc --no-plugins-cache video.torrent
vlc-bittorrent-2.14/configure.ac 0000664 0000000 0000000 00000001662 14171042373 0016713 0 ustar 00root root 0000000 0000000 AC_PREREQ([2.69])
AC_INIT(vlc-plugin-bittorrent, 2.14, johan.gunnarsson@gmail.com, vlc-bittorrent, https://github.com/johang/vlc-bittorrent)
AC_CONFIG_SRCDIR([src/module.cpp])
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_AUX_DIR([build-aux])
AC_REQUIRE_AUX_FILE([tap-driver.sh])
# Check programs
AC_PROG_CXX
AC_PROG_AWK
# Check automake
AM_INIT_AUTOMAKE
# Check libraries
PKG_CHECK_MODULES(VLC_PLUGIN, vlc-plugin >= 3.0.0)
PKG_CHECK_MODULES(LIBTORRENT, libtorrent-rasterbar >= 1.0.0)
# Check libvlc library only if --with-tests
AC_ARG_WITH(
[tests],
[AS_HELP_STRING([--with-tests], [enable tests])],
[with_tests=yes])
AM_CONDITIONAL([WITH_TESTS], [test x$with_tests = xyes])
AM_COND_IF([WITH_TESTS], [PKG_CHECK_MODULES(LIBVLC, libvlc >= 3.0.0)])
# Compile with -std=c++14 or later
AX_CXX_COMPILE_STDCXX_14(noext, mandatory)
# Check libtool
LT_INIT
AC_CONFIG_HEADERS(src/config.h)
AC_OUTPUT(Makefile src/Makefile test/Makefile data/Makefile)
vlc-bittorrent-2.14/data/ 0000775 0000000 0000000 00000000000 14171042373 0015331 5 ustar 00root root 0000000 0000000 vlc-bittorrent-2.14/data/Makefile.am 0000664 0000000 0000000 00000000122 14171042373 0017360 0 ustar 00root root 0000000 0000000 desktopdir = $(datadir)/applications
desktop_DATA = vlc-plugin-bittorrent.desktop
vlc-bittorrent-2.14/data/vlc-plugin-bittorrent.desktop 0000664 0000000 0000000 00000000721 14171042373 0023176 0 ustar 00root root 0000000 0000000 [Desktop Entry]
Version=1.0
Name=VLC media player (bittorrent)
GenericName=Bittorrent streaming media player
Comment=Read, capture, broadcast your multimedia streams
TryExec=/usr/bin/vlc
Exec=/usr/bin/vlc --started-from-file %U
Icon=vlc
Terminal=false
NoDisplay=true
Type=Application
Categories=AudioVideo;Player;Recorder;Network;FileTransfer;P2P;
Keywords=Player;Capture;DVD;Audio;Video;Server;Broadcast;
MimeType=application/x-bittorrent;x-scheme-handler/magnet;
vlc-bittorrent-2.14/scripts/ 0000775 0000000 0000000 00000000000 14171042373 0016107 5 ustar 00root root 0000000 0000000 vlc-bittorrent-2.14/scripts/build-libtorrent 0000775 0000000 0000000 00000001716 14171042373 0021323 0 ustar 00root root 0000000 0000000 #!/usr/bin/env sh
# Copyright 2018 Johan Gunnarsson
#
# This file is part of vlc-bittorrent.
#
# vlc-bittorrent 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.
#
# vlc-bittorrent 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 vlc-bittorrent. If not, see .
git clone --depth 1 -b "${1:-master}" https://github.com/arvidn/libtorrent.git &&
cd libtorrent &&
./autotool.sh &&
./configure --prefix="${2:-/tmp}" \
--disable-encryption &&
make &&
make install
vlc-bittorrent-2.14/scripts/build-vlc 0000775 0000000 0000000 00000002347 14171042373 0017724 0 ustar 00root root 0000000 0000000 #!/usr/bin/env sh
# Copyright 2018 Johan Gunnarsson
#
# This file is part of vlc-bittorrent.
#
# vlc-bittorrent 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.
#
# vlc-bittorrent 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 vlc-bittorrent. If not, see .
git clone --depth 1 https://git.videolan.org/git/vlc/${1:-vlc}.git vlc &&
cd vlc &&
./bootstrap &&
./configure --prefix="${2:-/tmp}" \
--enable-debug \
--disable-lua \
--disable-avcodec \
--disable-swscale \
--disable-a52 \
--disable-xcb \
--disable-wayland \
--disable-alsa \
--disable-chromecast \
--disable-nls \
--disable-sparkle &&
make &&
make install
vlc-bittorrent-2.14/scripts/rungdb 0000775 0000000 0000000 00000000142 14171042373 0017313 0 ustar 00root root 0000000 0000000 #!/bin/sh
VLC_PLUGIN_PATH=$(dirname "$0")/../src/.libs gdb vlc -ex "r --reset-plugins-cache '$1'"
vlc-bittorrent-2.14/src/ 0000775 0000000 0000000 00000000000 14171042373 0015207 5 ustar 00root root 0000000 0000000 vlc-bittorrent-2.14/src/.gitignore 0000664 0000000 0000000 00000000036 14171042373 0017176 0 ustar 00root root 0000000 0000000 config.h
config.h.in
stamp-h1
vlc-bittorrent-2.14/src/Makefile.am 0000664 0000000 0000000 00000001321 14171042373 0017240 0 ustar 00root root 0000000 0000000 lib_LTLIBRARIES = libaccess_bittorrent_plugin.la
# Great and cool CFLAGS
COOLCFLAGS = \
-Wno-deprecated-declarations \
-Wall \
-Wextra \
-Wconversion \
-Wsign-compare \
-Wsign-conversion \
-Wno-unused-parameter \
-Wno-unused \
-Wodr
libaccess_bittorrent_plugin_la_SOURCES = \
module.cpp \
metadata.cpp \
magnetmetadata.cpp \
data.cpp \
download.cpp \
session.cpp \
vlc.cpp
libaccess_bittorrent_plugin_la_CXXFLAGS = \
$(COOLCFLAGS) \
$(VLC_PLUGIN_CFLAGS) \
$(LIBTORRENT_CFLAGS) \
-DMODULE_STRING=\"bittorrent\"
libaccess_bittorrent_plugin_la_LIBADD = \
$(VLC_PLUGIN_LIBS) \
$(LIBTORRENT_LIBS)
libaccess_bittorrent_plugin_la_LDFLAGS = \
-avoid-version \
-module \
-export-symbol-regex ^vlc_entry
vlc-bittorrent-2.14/src/data.cpp 0000664 0000000 0000000 00000011277 14171042373 0016634 0 ustar 00root root 0000000 0000000 /*
Copyright 2016 Johan Gunnarsson
This file is part of vlc-bittorrent.
vlc-bittorrent 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.
vlc-bittorrent 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 vlc-bittorrent. If not, see .
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include
#include "data.h"
#include "download.h"
#include "vlc.h"
#define MIN_CACHING_TIME (10000)
#define D(x)
struct data_sys {
std::shared_ptr p_download;
// Current open file
int i_file;
// Current position within the current open file
uint64_t i_pos;
};
static ssize_t
DataRead(stream_extractor_t* p_extractor, void* p_data, size_t i_size)
{
D(printf("%s:%d: %s()\n", __FILE__, __LINE__, __func__));
data_sys* p_sys = (data_sys*) p_extractor->p_sys;
if (!p_sys)
return -1;
else if (!p_sys->p_download)
return -1;
try {
ssize_t size = p_sys->p_download->read((int) p_sys->i_file,
(int64_t) p_sys->i_pos, (char*) p_data, i_size);
if (size > 0)
p_sys->i_pos += (uint64_t) size;
else if (size < 0)
return 0;
return size;
} catch (std::runtime_error& e) {
msg_Dbg(p_extractor, "Read failed: %s", e.what());
}
return -1;
}
static int
DataSeek(stream_extractor_t* p_extractor, uint64_t i_pos)
{
D(printf("%s:%d: %s(%lu)\n", __FILE__, __LINE__, __func__, i_pos));
if (!p_extractor)
return VLC_EGENERIC;
data_sys* p_sys = (data_sys*) p_extractor->p_sys;
if (!p_sys)
return VLC_EGENERIC;
p_sys->i_pos = i_pos;
return VLC_SUCCESS;
}
static int
DataControl(stream_extractor_t* p_extractor, int i_query, va_list args)
{
D(printf("%s:%d: %s()\n", __FILE__, __LINE__, __func__));
if (!p_extractor)
return VLC_EGENERIC;
data_sys* p_sys = (data_sys*) p_extractor->p_sys;
if (!p_sys)
return VLC_EGENERIC;
else if (!p_sys->p_download)
return VLC_EGENERIC;
switch (i_query) {
case STREAM_CAN_SEEK:
*va_arg(args, bool*) = true;
break;
case STREAM_CAN_FASTSEEK:
*va_arg(args, bool*) = true;
break;
case STREAM_CAN_PAUSE:
*va_arg(args, bool*) = true;
break;
case STREAM_CAN_CONTROL_PACE:
*va_arg(args, bool*) = true;
break;
case STREAM_GET_PTS_DELAY:
*va_arg(args, int64_t*) = INT64_C(1000)
* __MAX(MIN_CACHING_TIME,
var_InheritInteger(p_extractor, "network-caching"));
break;
case STREAM_SET_PAUSE_STATE:
break;
case STREAM_GET_SIZE:
*va_arg(args, uint64_t*)
= p_sys->p_download->get_file(p_extractor->identifier).second;
break;
default:
return VLC_EGENERIC;
}
return VLC_SUCCESS;
}
int
DataOpen(vlc_object_t* p_obj)
{
D(printf("%s:%d: %s()\n", __FILE__, __LINE__, __func__));
stream_extractor_t* p_extractor = (stream_extractor_t*) p_obj;
msg_Info(p_extractor, "Opening %s", p_extractor->identifier);
// Temporary buffer to hold metadata
auto md = std::make_unique(0x100000);
ssize_t mdsz = vlc_stream_Read(p_extractor->source, md.get(), 0x100000);
if (mdsz < 0)
return VLC_EGENERIC;
auto p_sys = std::make_unique();
try {
p_sys->p_download = Download::get_download(md.get(), (size_t) mdsz,
get_download_directory(p_obj), get_keep_files(p_obj));
msg_Dbg(p_extractor, "Added download");
p_sys->i_file
= p_sys->p_download->get_file(p_extractor->identifier).first;
msg_Dbg(p_extractor, "Found file %d", p_sys->i_file);
} catch (std::runtime_error& e) {
msg_Err(p_extractor, "Failed to add download: %s", e.what());
return VLC_EGENERIC;
}
p_extractor->p_sys = p_sys.release();
p_extractor->pf_read = DataRead;
p_extractor->pf_control = DataControl;
p_extractor->pf_block = NULL;
p_extractor->pf_seek = DataSeek;
return VLC_SUCCESS;
}
void
DataClose(vlc_object_t* p_obj)
{
D(printf("%s:%d: %s()\n", __FILE__, __LINE__, __func__));
stream_extractor_t* p_extractor = (stream_extractor_t*) p_obj;
data_sys* p_sys = (data_sys*) p_extractor->p_sys;
std::unique_ptr sys(p_sys);
}
vlc-bittorrent-2.14/src/data.h 0000664 0000000 0000000 00000001551 14171042373 0016273 0 ustar 00root root 0000000 0000000 /*
Copyright 2016 Johan Gunnarsson
This file is part of vlc-bittorrent.
vlc-bittorrent 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.
vlc-bittorrent 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 vlc-bittorrent. If not, see .
*/
#ifndef VLC_BITTORRENT_DATA_H
#define VLC_BITTORRENT_DATA_H
#include "vlc.h"
int
DataOpen(vlc_object_t*);
void
DataClose(vlc_object_t*);
#endif
vlc-bittorrent-2.14/src/download.cpp 0000664 0000000 0000000 00000041276 14171042373 0017534 0 ustar 00root root 0000000 0000000 /*
Copyright 2016 Johan Gunnarsson
This file is part of vlc-bittorrent.
vlc-bittorrent 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.
vlc-bittorrent 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 vlc-bittorrent. If not, see .
*/
/*
XXX: This file is basically just glue code so vlc can make interruptible
blocking calls to libtorrent.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include
#include
#include
#include
#include
#include
#include
#include "download.h"
#include "session.h"
#include "vlc.h"
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wsign-conversion"
#pragma GCC diagnostic ignored "-Wconversion"
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#pragma GCC diagnostic pop
#define D(x)
#define DD(x)
#define kB (1024)
#define MB (1024 * kB)
#define PRIO_HIGHEST 7
#define PRIO_HIGHER 6
#define PRIO_HIGH 5
namespace lt = libtorrent;
template class vlc_interrupt_guard {
public:
vlc_interrupt_guard(T& pr)
{
vlc_interrupt_register(abort, &pr);
}
~vlc_interrupt_guard()
{
vlc_interrupt_unregister();
}
private:
static void
abort(void* data)
{
try {
// Interrupt get()/wait() on this promise
static_cast(data)->set_exception(
std::make_exception_ptr(std::runtime_error("vlc interrupted")));
} catch (...) {
}
}
};
template class AlertSubscriber {
public:
AlertSubscriber(std::shared_ptr dl, T* pr)
: m_session(dl)
, m_promise(pr)
{
m_session->register_alert_listener(m_promise);
}
~AlertSubscriber()
{
m_session->unregister_alert_listener(m_promise);
}
private:
std::shared_ptr m_session;
T* m_promise;
};
using ReadValue = std::pair, int>;
class ReadPiecePromise : public std::promise, public Alert_Listener {
public:
ReadPiecePromise(lt::sha1_hash ih, int p)
: m_ih(ih)
, m_piece(p)
{
}
void
handle_alert(lt::alert* a) override
{
if (auto* x = lt::alert_cast(a)) {
if (x->handle.info_hash() != m_ih)
return;
if (x->piece != m_piece)
return;
if (x->ec)
set_exception(
std::make_exception_ptr(std::runtime_error("read failed")));
else
// Read is done
set_value(std::make_pair(x->buffer, x->size));
}
}
private:
lt::sha1_hash m_ih;
int m_piece;
};
class DownloadPiecePromise : public std::promise, public Alert_Listener {
public:
DownloadPiecePromise(lt::sha1_hash ih, int p)
: m_ih(ih)
, m_piece(p)
{
}
void
handle_alert(lt::alert* a) override
{
if (auto* x = lt::alert_cast(a)) {
if (x->handle.info_hash() != m_ih)
return;
if (x->piece_index != m_piece)
return;
// Download is done
set_value();
}
}
private:
lt::sha1_hash m_ih;
int m_piece;
};
class MetadataDownloadPromise : public std::promise,
public Alert_Listener {
public:
MetadataDownloadPromise(lt::sha1_hash ih)
: m_ih(ih)
{
}
void
handle_alert(lt::alert* a) override
{
if (auto* x = lt::alert_cast(a)) {
if (x->handle.info_hash() != m_ih)
return;
set_exception(
std::make_exception_ptr(std::runtime_error("metadata failed")));
} else if (auto* x = lt::alert_cast(a)) {
if (x->handle.info_hash() != m_ih)
return;
set_exception(
std::make_exception_ptr(std::runtime_error("metadata failed")));
} else if (auto* x = lt::alert_cast(a)) {
if (x->handle.info_hash() != m_ih)
return;
// Metadata download is done
set_value();
}
}
private:
lt::sha1_hash m_ih;
};
class RemovePromise : public std::promise, public Alert_Listener {
public:
RemovePromise(lt::sha1_hash ih)
: m_ih(ih)
{
}
void
handle_alert(lt::alert* a) override
{
if (auto* x = lt::alert_cast(a)) {
if (x->info_hash != m_ih)
return;
// Remove is done
set_value();
}
}
private:
lt::sha1_hash m_ih;
};
Download::Download(std::mutex& mtx, lt::add_torrent_params& atp, bool k)
: m_lock(mtx)
, m_keep(k)
, m_session(Session::get())
{
D(printf("%s:%d: %s (from atp)\n", __FILE__, __LINE__, __func__));
// Doesn't matter if it's duplicate since we never remove torrents
m_th = m_session->add_torrent(atp);
if (!m_th.is_valid())
throw std::runtime_error("Failed to add torrent");
// Need to give libtorrent some time to breethe
std::this_thread::sleep_for(std::chrono::milliseconds(500));
}
Download::~Download()
{
D(printf("%s:%d: %s()\n", __FILE__, __LINE__, __func__));
if (m_th.is_valid()) {
RemovePromise rmprom(m_th.info_hash());
AlertSubscriber sub(m_session, &rmprom);
auto f = rmprom.get_future();
m_session->remove_torrent(m_th, m_keep);
// Wait for remove to complete
f.wait_for(std::chrono::seconds(5));
}
}
ssize_t
Download::read(int file, int64_t fileoff, char* buf, size_t buflen,
DataProgressCb progress_cb)
{
D(printf("%s:%d: %s(%d, %lu, %p, %lu)\n", __FILE__, __LINE__, __func__,
file, fileoff, buf, buflen));
download_metadata();
auto ti = m_th.torrent_file();
auto fs = ti->files();
if (file >= fs.num_files() || file < 0)
throw std::runtime_error("File not found");
if (fileoff < 0)
throw std::runtime_error("File offset negative");
int64_t filesz = fs.file_size(file);
if (fileoff >= filesz)
return 0;
// Figure out what to read
auto part = ti->map_file(file, fileoff,
(int) std::min({ (int64_t) std::numeric_limits::max(),
(int64_t) buflen, filesz - fileoff }));
if (part.length <= 0)
return 0;
// Set highest priority to the requested range
set_piece_priority(file, fileoff, part.length, PRIO_HIGHEST);
// Set second highest priority to the first and last 0.1% or 64 kB
int64_t p01 = std::max(
std::min((int64_t) std::numeric_limits::max(), filesz / 1000),
(int64_t) 128 * kB);
set_piece_priority(file, 0, (int) p01, PRIO_HIGHER);
set_piece_priority(file, filesz - p01, (int) p01, PRIO_HIGHER);
// Set third highest priority to the next 5% or 64 MB
int64_t p5 = std::max(
std::min((int64_t) std::numeric_limits::max(), 5 * filesz / 100),
(int64_t) 32 * MB);
set_piece_priority(file, fileoff, (int) p5, PRIO_HIGH);
if (!m_th.have_piece(part.piece))
download(part, progress_cb);
return read(part, buf, buflen);
}
void
Download::set_piece_priority(int file, int64_t off, int size, int prio)
{
D(printf("%s:%d: %s()\n", __FILE__, __LINE__, __func__));
download_metadata();
auto ti = m_th.torrent_file();
auto fs = ti->files();
// Make sure off + size <= file size
int64_t filesz = fs.file_size(file);
off = std::min(off, filesz);
size = (int) std::min({ (int64_t) std::numeric_limits::max(),
(int64_t) size, filesz - off });
auto part = ti->map_file(file, off, size);
for (; part.length > 0; part.length -= ti->piece_size(part.piece++)) {
if (!m_th.have_piece(part.piece)
&& m_th.piece_priority(part.piece) < prio)
m_th.piece_priority(part.piece, prio);
}
}
std::vector>
Download::get_files()
{
D(printf("%s:%d: %s()\n", __FILE__, __LINE__, __func__));
download_metadata();
std::vector> files;
const lt::file_storage& fs = m_th.torrent_file()->files();
for (int i = 0; i < fs.num_files(); i++) {
files.push_back(std::make_pair(fs.file_path(i), fs.file_size(i)));
}
return files;
}
// static
std::vector>
Download::get_files(char* metadata, size_t metadatasz)
{
D(printf("%s:%d: %s()\n", __FILE__, __LINE__, __func__));
lt::error_code ec;
lt::torrent_info ti(metadata, (int) metadatasz, ec);
if (ec)
throw std::runtime_error("Failed to parse metadata");
std::vector> files;
const lt::file_storage& fs = ti.files();
for (int i = 0; i < fs.num_files(); i++) {
files.push_back(std::make_pair(fs.file_path(i), fs.file_size(i)));
}
return files;
}
// static
std::shared_ptr>
Download::get_metadata(std::string url, std::string save_path,
std::string cache_path, MetadataProgressCb cb)
{
D(printf("%s:%d: %s()\n", __FILE__, __LINE__, __func__));
lt::add_torrent_params atp;
atp.save_path = save_path;
atp.flags &= ~lt::add_torrent_params::flag_auto_managed;
atp.flags &= ~lt::add_torrent_params::flag_paused;
lt::error_code ec;
lt::parse_magnet_uri(url, atp, ec);
if (ec) {
#if LIBTORRENT_VERSION_NUM < 10200
atp.ti = boost::make_shared(url, boost::ref(ec));
#else
atp.ti = std::make_shared(url, std::ref(ec));
#endif
if (ec)
throw std::runtime_error("Failed to parse metadata");
} else {
std::string path = cache_path + DIR_SEP
+ lt::to_hex(atp.info_hash.to_string()) + ".torrent";
// Try to read up cache
#if LIBTORRENT_VERSION_NUM < 10200
atp.ti = boost::make_shared(path, boost::ref(ec));
#else
atp.ti = std::make_shared(path, std::ref(ec));
#endif
if (ec) {
// The torrent_info from was is invalid
atp.ti = NULL;
// Dowload metadata
auto metadata = Download::get_download(atp, true)->get_metadata(cb);
// Write metadata to cache
std::ofstream os(path, std::ios::binary);
std::ostream_iterator osi(os);
std::copy(std::begin(*metadata), std::end(*metadata), osi);
return metadata;
}
}
// Add trackers from magnet URL to the cached metadata
for (auto& tracker : atp.trackers) {
atp.ti->add_tracker(tracker);
}
auto entry = lt::create_torrent(*atp.ti).generate();
auto metadata = std::make_shared>();
// Bencode metadata into vector
lt::bencode(std::back_inserter(*metadata), entry);
return metadata;
}
// static
std::shared_ptr
Download::get_download(lt::add_torrent_params& atp, bool k)
{
D(printf("%s:%d: %s (from atp)\n", __FILE__, __LINE__, __func__));
lt::sha1_hash ih = atp.ti ? atp.ti->info_hash() : atp.info_hash;
static std::mutex mtx;
std::unique_lock lock(mtx);
// Re-use Download instance if possible, else create new instance
static std::map> dls;
static std::map dls_mtx;
std::shared_ptr dl = dls[ih].lock();
if (!dl)
dls[ih] = dl = std::make_shared(dls_mtx[ih], atp, k);
return dl;
}
// static
std::shared_ptr
Download::get_download(char* md, size_t mdsz, std::string sp, bool k)
{
D(printf("%s:%d: %s (from buf)\n", __FILE__, __LINE__, __func__));
lt::add_torrent_params atp;
atp.save_path = sp;
atp.flags &= ~lt::add_torrent_params::flag_auto_managed;
atp.flags &= ~lt::add_torrent_params::flag_paused;
atp.flags &= ~lt::add_torrent_params::flag_duplicate_is_error;
lt::error_code ec;
#if LIBTORRENT_VERSION_NUM < 10200
atp.ti = boost::make_shared(md, mdsz, boost::ref(ec));
#else
atp.ti = std::make_shared(md, mdsz, std::ref(ec));
#endif
if (ec)
throw std::runtime_error("Failed to parse metadata");
return Download::get_download(atp, k);
}
std::pair
Download::get_file(std::string path)
{
D(printf("%s:%d: %s()\n", __FILE__, __LINE__, __func__));
download_metadata();
const lt::file_storage& fs = m_th.torrent_file()->files();
for (int i = 0; i < fs.num_files(); i++) {
if (fs.file_path(i) == path)
return std::make_pair(i, (uint64_t) fs.file_size(i));
}
throw std::runtime_error("Failed to find file");
}
std::string
Download::get_name()
{
D(printf("%s:%d: %s()\n", __FILE__, __LINE__, __func__));
download_metadata();
return m_th.torrent_file()->name();
}
std::string
Download::get_infohash()
{
D(printf("%s:%d: %s()\n", __FILE__, __LINE__, __func__));
download_metadata();
return lt::to_hex(m_th.torrent_file()->info_hash().to_string());
}
std::shared_ptr>
Download::get_metadata(MetadataProgressCb cb)
{
D(printf("%s:%d: %s()\n", __FILE__, __LINE__, __func__));
download_metadata(cb);
auto entry = lt::create_torrent(*m_th.torrent_file()).generate();
auto buffer = std::make_shared>();
// Bencode metadata into vector
lt::bencode(std::back_inserter(*buffer), entry);
return buffer;
}
void
Download::download_metadata(MetadataProgressCb cb)
{
D(printf("%s:%d: %s()\n", __FILE__, __LINE__, __func__));
if (m_th.status().has_metadata)
return;
MetadataDownloadPromise dlprom(m_th.info_hash());
AlertSubscriber sub(m_session, &dlprom);
vlc_interrupt_guard intrguard(dlprom);
auto f = dlprom.get_future();
if (cb)
cb(0.0);
// Wait for metadata to download
while (!m_th.status().has_metadata) {
auto r = f.wait_for(std::chrono::seconds(1));
if (r == std::future_status::ready)
// At this point, we know either metadata download is done and we
// can return early, or there was error and get() will throw and
// exception.
return f.get();
}
if (cb)
cb(100.0);
}
void
Download::download(lt::peer_request part, DataProgressCb cb)
{
D(printf("%s:%d: %s()\n", __FILE__, __LINE__, __func__));
download_metadata();
if (m_th.have_piece(part.piece))
return;
DownloadPiecePromise dlprom(m_th.info_hash(), part.piece);
AlertSubscriber sub(m_session, &dlprom);
vlc_interrupt_guard intrguard(dlprom);
auto f = dlprom.get_future();
if (cb)
cb(0.0);
// Wait for download
while (!m_th.have_piece(part.piece)) {
auto r = f.wait_for(std::chrono::seconds(1));
if (r == std::future_status::ready)
// At this point, we know either download is done and we can return
// early, or there was error and get() will throw and exception.
return f.get();
}
if (cb)
cb(100.0);
}
ssize_t
Download::read(lt::peer_request part, char* buf, size_t buflen)
{
D(printf("%s:%d: %s()\n", __FILE__, __LINE__, __func__));
download_metadata();
ReadPiecePromise rdprom(m_th.info_hash(), part.piece);
AlertSubscriber sub(m_session, &rdprom);
vlc_interrupt_guard intrguard(rdprom);
auto f = rdprom.get_future();
// Trigger read
m_th.read_piece(part.piece);
// Wait for read to complete
boost::shared_array piece_buffer;
int piece_size;
std::tie(piece_buffer, piece_size) = f.get();
int len = std::min({ piece_size - part.start, (int) buflen, part.length });
if (len < 0)
return -1;
// Copy from libtorrent buffer to VLC buffer
memcpy(buf, piece_buffer.get() + part.start, (size_t) len);
return (ssize_t) len;
}
vlc-bittorrent-2.14/src/download.h 0000664 0000000 0000000 00000007176 14171042373 0017202 0 ustar 00root root 0000000 0000000 /*
Copyright 2016 Johan Gunnarsson
This file is part of vlc-bittorrent.
vlc-bittorrent 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.
vlc-bittorrent 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 vlc-bittorrent. If not, see .
*/
#ifndef VLC_BITTORRENT_DOWNLOAD_H
#define VLC_BITTORRENT_DOWNLOAD_H
#include
#include
#include
#include
#include
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wsign-conversion"
#pragma GCC diagnostic ignored "-Wconversion"
#include
#include
#include
#include
#pragma GCC diagnostic pop
#include "session.h"
namespace lt = libtorrent;
using MetadataProgressCb = std::function;
using DataProgressCb = std::function;
class Download {
public:
Download(const Download&) = delete;
Download&
operator=(const Download&)
= delete;
Download(std::mutex& mtx, lt::add_torrent_params& atp, bool k);
~Download();
static std::shared_ptr
get_download(
char* metadata, size_t metadatalen, std::string save_path, bool keep);
/**
* Get a part of the data of this download. If the data is not
* available, it will download it and wait for it to become available.
*/
ssize_t
read(int file, int64_t off, char* buf, size_t buflen,
DataProgressCb progress_cb);
ssize_t
read(int file, int64_t off, char* buf, size_t buflen)
{
return read(file, off, buf, buflen, nullptr);
}
static std::vector>
get_files(char* metadata, size_t metadatalen);
std::vector>
get_files();
static std::shared_ptr>
get_metadata(std::string url, std::string save_path, std::string cache_path,
MetadataProgressCb progress_cb);
static std::shared_ptr>
get_metadata(std::string url, std::string save_path, std::string cache_path)
{
return get_metadata(url, save_path, cache_path, nullptr);
}
std::shared_ptr>
get_metadata(MetadataProgressCb progress_cb);
std::shared_ptr>
get_metadata()
{
return get_metadata(nullptr);
}
std::pair
get_file(std::string path);
std::string
get_name();
std::string
get_infohash();
private:
static std::shared_ptr
get_download(lt::add_torrent_params& atp, bool k);
void
download_metadata(MetadataProgressCb cb);
void
download_metadata()
{
download_metadata(nullptr);
}
void
download(lt::peer_request part, DataProgressCb cb);
void
download(lt::peer_request part)
{
download(part, nullptr);
}
ssize_t
read(lt::peer_request part, char* buf, size_t buflen);
void
set_piece_priority(int file, int64_t off, int size, int prio);
// Locks mutex passed to constructor
std::unique_lock m_lock;
bool m_keep;
std::shared_ptr m_session;
lt::torrent_handle m_th;
};
#endif
vlc-bittorrent-2.14/src/magnetmetadata.cpp 0000664 0000000 0000000 00000010763 14171042373 0020676 0 ustar 00root root 0000000 0000000 /*
Copyright 2016 Johan Gunnarsson
This file is part of vlc-bittorrent.
vlc-bittorrent 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.
vlc-bittorrent 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 vlc-bittorrent. If not, see .
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "download.h"
#include "magnetmetadata.h"
#include "vlc.h"
#define D(x)
struct magnetmetadata_sys {
std::shared_ptr> p_metadata;
// Current position within the metadata
size_t i_pos;
};
static ssize_t
MagnetMetadataRead(stream_t* p_access, void* p_buffer, size_t i_len)
{
D(printf("%s:%d: %s()\n", __FILE__, __LINE__, __func__));
if (!p_access->p_sys)
return -1;
magnetmetadata_sys* p_sys = (magnetmetadata_sys*) p_access->p_sys;
if (!p_sys->p_metadata)
return -1;
ssize_t len
= (ssize_t) std::min(i_len, p_sys->p_metadata->size() - p_sys->i_pos);
if (len < 0)
return -1;
std::copy(p_sys->p_metadata->begin() + (ssize_t) p_sys->i_pos,
p_sys->p_metadata->begin() + (ssize_t) p_sys->i_pos + len,
(char*) p_buffer);
p_sys->i_pos += (size_t) len;
return len;
}
static int
MagnetMetadataControl(stream_t* access, int query, va_list args)
{
D(printf("%s:%d: %s(0x%x)\n", __FILE__, __LINE__, __func__, query));
switch (query) {
case STREAM_GET_PTS_DELAY:
*va_arg(args, int64_t*) = DEFAULT_PTS_DELAY;
break;
case STREAM_CAN_SEEK:
*va_arg(args, bool*) = false;
break;
case STREAM_CAN_PAUSE:
*va_arg(args, bool*) = false;
break;
case STREAM_CAN_CONTROL_PACE:
*va_arg(args, bool*) = true;
break;
case STREAM_GET_CONTENT_TYPE:
*va_arg(args, char**) = strdup("application/x-bittorrent");
break;
default:
return VLC_EGENERIC;
}
return VLC_SUCCESS;
}
int
MagnetMetadataOpen(vlc_object_t* p_this)
{
D(printf("%s:%d: %s()\n", __FILE__, __LINE__, __func__));
stream_t* p_access = (stream_t*) p_this;
std::string name(p_access->psz_name ?: "");
std::string filepath(p_access->psz_filepath ?: "");
std::string location(p_access->psz_location ?: "");
std::string magnet;
if (name == "magnet") {
magnet = "magnet:" + location;
} else if (name == "file") {
size_t index = filepath.rfind("magnet:?");
if (index != std::string::npos) {
magnet = filepath.substr(index);
} else {
return VLC_EGENERIC;
}
} else {
return VLC_EGENERIC;
}
auto p_sys = std::make_unique();
try {
msg_Info(p_access, "Reading metadata");
auto del = [&](vlc_dialog_id* dialog) {
vlc_dialog_release(p_this, dialog);
};
std::unique_ptr dialog(nullptr, del);
auto prog = [&](float progress) {
if (!dialog)
dialog.reset(vlc_dialog_display_progress(p_this, true, progress,
NULL, "Downloading metadata",
"Downloading metadata from peers..."));
else
vlc_dialog_update_progress_text(p_this, dialog.get(), progress,
"Downloading metadata from peers...");
};
p_sys->p_metadata = Download::get_metadata(magnet,
get_download_directory(p_this), get_cache_directory(p_this), prog);
msg_Dbg(p_access, "Got %zu bytes metadata", p_sys->p_metadata->size());
} catch (std::runtime_error& e) {
msg_Err(p_access, "Failed to get metadata: %s", e.what());
return VLC_EGENERIC;
}
p_access->p_sys = p_sys.release();
p_access->pf_read = MagnetMetadataRead;
p_access->pf_control = MagnetMetadataControl;
return VLC_SUCCESS;
}
void
MagnetMetadataClose(vlc_object_t* p_this)
{
D(printf("%s:%d: %s()\n", __FILE__, __LINE__, __func__));
stream_t* p_access = (stream_t*) p_this;
magnetmetadata_sys* p_sys = (magnetmetadata_sys*) p_access->p_sys;
std::unique_ptr sys(p_sys);
}
vlc-bittorrent-2.14/src/magnetmetadata.h 0000664 0000000 0000000 00000001621 14171042373 0020334 0 ustar 00root root 0000000 0000000 /*
Copyright 2016 Johan Gunnarsson
This file is part of vlc-bittorrent.
vlc-bittorrent 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.
vlc-bittorrent 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 vlc-bittorrent. If not, see .
*/
#ifndef VLC_BITTORRENT_MAGNETMETADATA_H
#define VLC_BITTORRENT_MAGNETMETADATA_H
#include "vlc.h"
int
MagnetMetadataOpen(vlc_object_t*);
void
MagnetMetadataClose(vlc_object_t*);
#endif
vlc-bittorrent-2.14/src/metadata.cpp 0000664 0000000 0000000 00000005371 14171042373 0017501 0 ustar 00root root 0000000 0000000 /*
Copyright 2016 Johan Gunnarsson
This file is part of vlc-bittorrent.
vlc-bittorrent 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.
vlc-bittorrent 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 vlc-bittorrent. If not, see .
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include
#include
#include "download.h"
#include "metadata.h"
#include "vlc.h"
#define D(x)
static int
MetadataReadDir(stream_directory_t* p_directory, input_item_node_t* p_node)
{
D(printf("%s:%d: %s()\n", __FILE__, __LINE__, __func__));
// Temporary buffer to hold metadata
auto md = std::make_unique(0x100000);
ssize_t mdsz = vlc_stream_Read(p_directory->source, md.get(), 0x100000);
if (mdsz < 0)
return VLC_EGENERIC;
std::vector> files;
try {
files = Download::get_files(md.get(), (size_t) mdsz);
} catch (std::runtime_error& e) {
msg_Err(p_directory, "Failed to parse metadata: %s", e.what());
return VLC_EGENERIC;
}
struct vlc_readdir_helper rdh;
vlc_readdir_helper_init(&rdh, p_directory, p_node);
for (auto f : files) {
std::unique_ptr mrl(
vlc_stream_extractor_CreateMRL(p_directory, f.first.c_str()), free);
if (!mrl)
continue;
int ret = vlc_readdir_helper_additem(
&rdh, mrl.get(), f.first.c_str(), NULL, ITEM_TYPE_FILE, ITEM_LOCAL);
if (ret != VLC_SUCCESS)
msg_Warn(p_directory, "Failed to add %s", mrl.get());
}
vlc_readdir_helper_finish(&rdh, true);
return VLC_SUCCESS;
}
int
MetadataOpen(vlc_object_t* p_obj)
{
D(printf("%s:%d: %s()\n", __FILE__, __LINE__, __func__));
stream_directory_t* p_directory = (stream_directory_t*) p_obj;
if (!stream_IsMimeType(p_directory->source, "application/x-bittorrent")
&& !stream_HasExtension(p_directory->source, ".torrent"))
return VLC_EGENERIC;
// Attempt to read 1 byte of the metadata
const uint8_t* data = NULL;
ssize_t len = vlc_stream_Peek(p_directory->source, &data, 1);
// All bittorrent metadata files starts with a 'd'
if (len < 1 || data[0] != 'd')
return VLC_EGENERIC;
p_directory->pf_readdir = MetadataReadDir;
return VLC_SUCCESS;
}
vlc-bittorrent-2.14/src/metadata.h 0000664 0000000 0000000 00000001533 14171042373 0017142 0 ustar 00root root 0000000 0000000 /*
Copyright 2016 Johan Gunnarsson
This file is part of vlc-bittorrent.
vlc-bittorrent 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.
vlc-bittorrent 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 vlc-bittorrent. If not, see .
*/
#ifndef VLC_BITTORRENT_METADATA_H
#define VLC_BITTORRENT_METADATA_H
#include "vlc.h"
int
MetadataOpen(vlc_object_t* p_obj);
#endif
vlc-bittorrent-2.14/src/module.cpp 0000664 0000000 0000000 00000003717 14171042373 0017210 0 ustar 00root root 0000000 0000000 /*
Copyright 2016 Johan Gunnarsson
This file is part of vlc-bittorrent.
vlc-bittorrent 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.
vlc-bittorrent 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 vlc-bittorrent. If not, see .
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include
#include "data.h"
#include "magnetmetadata.h"
#include "metadata.h"
// clang-format off
vlc_module_begin()
set_shortname("bittorrent")
set_category(CAT_INPUT)
set_subcategory(SUBCAT_INPUT_STREAM_FILTER)
set_description("Bittorrent metadata access")
set_capability("stream_directory", 99)
set_callbacks(MetadataOpen, NULL)
#if 1
add_directory(DLDIR_CONFIG, NULL, "Downloads",
"Directory where VLC will put downloaded files.", false)
add_bool(KEEP_CONFIG, false, "Don't delete files",
"Don't delete files after download.", true)
#else
add_directory(DLDIR_CONFIG, NULL, "Downloads",
"Directory where VLC will put downloaded files.")
add_bool(KEEP_CONFIG, false, "Don't delete files",
"Don't delete files after download.")
#endif
add_submodule()
set_description("Bittorrent data access")
set_capability("stream_extractor", 99)
set_callbacks(DataOpen, DataClose)
add_submodule()
set_description("Bittorrent magnet metadata access")
set_capability("access", 60)
add_shortcut("file", "magnet")
set_callbacks(MagnetMetadataOpen, MagnetMetadataClose)
vlc_module_end()
vlc-bittorrent-2.14/src/session.cpp 0000664 0000000 0000000 00000010055 14171042373 0017377 0 ustar 00root root 0000000 0000000 /*
Copyright 2016 Johan Gunnarsson
This file is part of vlc-bittorrent.
vlc-bittorrent 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.
vlc-bittorrent 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 vlc-bittorrent. If not, see .
*/
#include "session.h"
#define D(x)
#define DD(x)
#define LIBTORRENT_ADD_TORRENT_ALERTS \
(lt::alert::storage_notification | lt::alert::progress_notification \
| lt::alert::status_notification | lt::alert::error_notification)
#define LIBTORRENT_DHT_NODES \
("router.bittorrent.com:6881," \
"router.utorrent.com:6881," \
"dht.transmissionbt.com:6881")
Session::Session(std::mutex& mtx)
: m_lock(mtx)
, m_session_thread_quit(false)
{
D(printf("%s:%d: %s()\n", __FILE__, __LINE__, __func__));
lt::settings_pack sp = lt::default_settings();
sp.set_int(sp.alert_mask, LIBTORRENT_ADD_TORRENT_ALERTS);
sp.set_str(sp.dht_bootstrap_nodes, LIBTORRENT_DHT_NODES);
/* Really aggressive settings to optimize time-to-play */
sp.set_bool(sp.strict_end_game_mode, false);
sp.set_bool(sp.announce_to_all_trackers, true);
sp.set_bool(sp.announce_to_all_tiers, true);
sp.set_int(sp.stop_tracker_timeout, 1);
sp.set_int(sp.request_timeout, 2);
sp.set_int(sp.whole_pieces_threshold, 5);
sp.set_int(sp.request_queue_time, 1);
sp.set_int(sp.urlseed_pipeline_size, 2);
#if LIBTORRENT_VERSION_NUM >= 10102
sp.set_int(sp.urlseed_max_request_bytes, 100 * 1024);
#endif
m_session = std::make_unique(sp);
m_session_thread = std::thread([&] {
while (!m_session_thread_quit) {
m_session->wait_for_alert(std::chrono::seconds(1));
std::vector alerts;
// Get all pending requests
m_session->pop_alerts(&alerts);
for (auto* a : alerts) {
std::unique_lock lock(m_listeners_mtx);
for (auto* h : m_listeners) {
try {
h->handle_alert(a);
} catch (...) {
}
}
}
}
});
}
Session::~Session()
{
D(printf("%s:%d: %s()\n", __FILE__, __LINE__, __func__));
m_session_thread_quit = true;
if (m_session_thread.joinable())
m_session_thread.join();
}
void
Session::register_alert_listener(Alert_Listener* al)
{
D(printf("%s:%d: %s()\n", __FILE__, __LINE__, __func__));
std::unique_lock lock(m_listeners_mtx);
m_listeners.push_front(al);
}
void
Session::unregister_alert_listener(Alert_Listener* al)
{
D(printf("%s:%d: %s()\n", __FILE__, __LINE__, __func__));
std::unique_lock lock(m_listeners_mtx);
m_listeners.remove(al);
}
lt::torrent_handle
Session::add_torrent(lt::add_torrent_params& atp)
{
D(printf("%s:%d: %s()\n", __FILE__, __LINE__, __func__));
return m_session->add_torrent(atp);
}
void
Session::remove_torrent(lt::torrent_handle& th, bool k)
{
D(printf("%s:%d: %s()\n", __FILE__, __LINE__, __func__));
if (k)
m_session->remove_torrent(th);
else
m_session->remove_torrent(th, lt::session::delete_files);
}
std::shared_ptr
Session::get()
{
D(printf("%s:%d: %s()\n", __FILE__, __LINE__, __func__));
static std::mutex mtx;
std::unique_lock lock(mtx);
// Re-use Session instance if possible, else create new instance
static std::weak_ptr session;
static std::mutex session_mtx;
std::shared_ptr s = session.lock();
if (!s)
session = s = std::make_shared(session_mtx);
return s;
}
vlc-bittorrent-2.14/src/session.h 0000664 0000000 0000000 00000003564 14171042373 0017053 0 ustar 00root root 0000000 0000000 /*
Copyright 2018 Johan Gunnarsson
This file is part of vlc-bittorrent.
vlc-bittorrent 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.
vlc-bittorrent 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 vlc-bittorrent. If not, see .
*/
#ifndef VLC_BITTORRENT_LIBTORRENT_H
#define VLC_BITTORRENT_LIBTORRENT_H
#include
#include
#include
#include
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wsign-conversion"
#pragma GCC diagnostic ignored "-Wconversion"
#include
#include
#pragma GCC diagnostic pop
struct Alert_Listener {
virtual ~Alert_Listener() { }
virtual void
handle_alert(lt::alert* alert)
= 0;
};
class Session {
public:
Session(std::mutex& mtx);
~Session();
void
register_alert_listener(Alert_Listener* al);
void
unregister_alert_listener(Alert_Listener* al);
lt::torrent_handle
add_torrent(lt::add_torrent_params& atp);
void
remove_torrent(lt::torrent_handle& th, bool k);
static std::shared_ptr
get();
private:
// Locks mutex passed to constructor
std::unique_lock m_lock;
std::unique_ptr m_session;
std::thread m_session_thread;
std::atomic m_session_thread_quit;
std::forward_list m_listeners;
std::mutex m_listeners_mtx;
};
#endif
vlc-bittorrent-2.14/src/vlc.cpp 0000664 0000000 0000000 00000004672 14171042373 0016510 0 ustar 00root root 0000000 0000000 /*
Copyright 2018 Johan Gunnarsson
This file is part of vlc-bittorrent.
vlc-bittorrent 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.
vlc-bittorrent 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 vlc-bittorrent. If not, see .
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include
#include
#include
#include
#include "vlc.h"
std::string
get_download_directory(vlc_object_t* p_this)
{
std::string dldir;
std::unique_ptr dir(
var_InheritString(p_this, DLDIR_CONFIG), free);
if (!dir) {
std::unique_ptr dir(
config_GetUserDir(VLC_DOWNLOAD_DIR), free);
if (!dir)
throw std::runtime_error("Failed to find download directory");
dldir = std::string(dir.get());
if (vlc_mkdir(dldir.c_str(), 0777)) {
if (errno != EEXIST)
throw std::runtime_error("Failed to create directory (" + dldir
+ "): " + strerror(errno));
}
dldir += DIR_SEP;
dldir += PACKAGE;
} else {
dldir = std::string(dir.get());
}
if (vlc_mkdir(dldir.c_str(), 0777)) {
if (errno != EEXIST)
throw std::runtime_error("Failed to create directory (" + dldir
+ "): " + strerror(errno));
}
return dldir;
}
std::string
get_cache_directory(vlc_object_t* p_this)
{
std::string cachedir;
std::unique_ptr dir(
config_GetUserDir(VLC_CACHE_DIR), free);
if (!dir)
throw std::runtime_error("Failed to find cache directory");
cachedir = std::string(dir.get());
if (vlc_mkdir(cachedir.c_str(), 0777)) {
if (errno != EEXIST)
throw std::runtime_error("Failed to create directory (" + cachedir
+ "): " + strerror(errno));
}
return cachedir;
}
bool
get_keep_files(vlc_object_t* p_this)
{
return var_InheritBool(p_this, KEEP_CONFIG);
}
vlc-bittorrent-2.14/src/vlc.h 0000664 0000000 0000000 00000003342 14171042373 0016146 0 ustar 00root root 0000000 0000000 /*
Copyright 2016 Johan Gunnarsson
This file is part of vlc-bittorrent.
vlc-bittorrent 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.
vlc-bittorrent 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 vlc-bittorrent. If not, see .
*/
#ifndef VLC_BITTORRENT_VLC_H
#define VLC_BITTORRENT_VLC_H
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wsign-conversion"
#pragma GCC diagnostic ignored "-Wconversion"
// clang-format off
// This has to be first because the libvlc headers have issues
#include
// clang-format off
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#pragma GCC diagnostic pop
#define DLDIR_CONFIG "bittorrent-download-path"
#define KEEP_CONFIG "bittorrent-keep-files"
std::string
get_download_directory(vlc_object_t* p_this);
std::string
get_cache_directory(vlc_object_t* p_this);
bool
get_keep_files(vlc_object_t* p_this);
#endif
vlc-bittorrent-2.14/test/ 0000775 0000000 0000000 00000000000 14171042373 0015377 5 ustar 00root root 0000000 0000000 vlc-bittorrent-2.14/test/.gitignore 0000664 0000000 0000000 00000000056 14171042373 0017370 0 ustar 00root root 0000000 0000000 *.trs
*.log
vlcdummy
miniclient
downloaddummy
vlc-bittorrent-2.14/test/Makefile.am 0000664 0000000 0000000 00000002054 14171042373 0017434 0 ustar 00root root 0000000 0000000 TESTS = vlcdummy.test downloaddummy.test
TEST_LOG_COMPILE = $(SHELL)
TEST_LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) $(top_srcdir)/build-aux/tap-driver.sh
AUTOMAKE_OPTIONS = subdir-objects
# Great and cool CFLAGS
COOLCFLAGS = \
-Wno-deprecated-declarations \
-Wall \
-Wextra \
-Wconversion \
-Wsign-compare \
-Wsign-conversion \
-Wno-unused-parameter \
-Wno-unused
# Great and cool CXXFLAGS
COOLCXXFLAGS = \
$(COOLCFLAGS)
# Support programs
check_PROGRAMS = vlcdummy miniclient downloaddummy
vlcdummy_SOURCES = vlcdummy.c
vlcdummy_CFLAGS = $(LIBVLC_CFLAGS) $(COOLCFLAGS)
vlcdummy_LDFLAGS =
vlcdummy_LDADD = $(LIBVLC_LIBS)
miniclient_SOURCES = miniclient.cpp
miniclient_CXXFLAGS = $(LIBTORRENT_CFLAGS) $(COOLCXXFLAGS)
miniclient_LDFLAGS =
miniclient_LDADD = $(LIBTORRENT_LIBS) -lpthread
downloaddummy_SOURCES = downloaddummy.cpp ../src/download.cpp ../src/session.cpp
downloaddummy_CXXFLAGS = -I../src $(LIBTORRENT_CFLAGS) $(VLC_PLUGIN_CFLAGS) $(COOLCXXFLAGS)
downloaddummy_LDFLAGS = -lpthread
downloaddummy_LDADD = $(LIBTORRENT_LIBS) $(VLC_PLUGIN_LIBS)
vlc-bittorrent-2.14/test/data/ 0000775 0000000 0000000 00000000000 14171042373 0016310 5 ustar 00root root 0000000 0000000 vlc-bittorrent-2.14/test/data/18945a9300abfe4ff2442559bb08b8ddb357c16f.torrent 0000664 0000000 0000000 00000000356 14171042373 0025376 0 ustar 00root root 0000000 0000000 d8:announce30:http://localhost:6969/announce4:infod5:filesld6:lengthi476e4:pathl11:denmark.pngeed6:lengthi744e4:pathl10:norway.pngeed6:lengthi636e4:pathl10:sweden.pngeee4:name5:flags12:piece lengthi262144e6:pieces20:p N_ÆЗZѻee vlc-bittorrent-2.14/test/data/6fa46c9a0bb4eecb837c25845d39c5324be66401.torrent 0000664 0000000 0000000 00000000345 14171042373 0025371 0 ustar 00root root 0000000 0000000 d8:announce30:http://localhost:6969/announce13:creation datei1545429773e4:infod5:filesld6:lengthi104050e4:pathl9:nasa2.ogveed6:lengthi88445e4:pathl9:nasa3.ogveee4:name4:nasa12:piece lengthi262144e6:pieces20:%d fKwR<ee vlc-bittorrent-2.14/test/data/8a32f3f6f3c9125da79e29c869122758004ee837.torrent 0000664 0000000 0000000 00000000247 14171042373 0025121 0 ustar 00root root 0000000 0000000 d8:announce30:http://localhost:6969/announce13:creation datei1545429783e4:infod6:lengthi58703e4:name9:nasa1.ogv12:piece lengthi262144e6:pieces20:W#tm瑶ee vlc-bittorrent-2.14/test/data/fce002e43ed1159f4612982ce8fcdb9d30e48f1e.torrent 0000664 0000000 0000000 00000000213 14171042373 0025531 0 ustar 00root root 0000000 0000000 d8:announce30:http://localhost:6969/announce4:infod6:lengthi636e4:name10:sweden.png12:piece lengthi262144e6:pieces20:Jʖd
9]yMՍ@ee vlc-bittorrent-2.14/test/data/flags.torrent 0000664 0000000 0000000 00000000356 14171042373 0021027 0 ustar 00root root 0000000 0000000 d8:announce30:http://localhost:6969/announce4:infod5:filesld6:lengthi476e4:pathl11:denmark.pngeed6:lengthi744e4:pathl10:norway.pngeed6:lengthi636e4:pathl10:sweden.pngeee4:name5:flags12:piece lengthi262144e6:pieces20:p N_ÆЗZѻee vlc-bittorrent-2.14/test/data/flags.torrent-magnet.data-expected.txt 0000664 0000000 0000000 00000002057 14171042373 0025625 0 ustar 00root root 0000000 0000000 VLCDUMMY ITEM magnet:?xt=urn:btih:18945a9300abfe4ff2442559bb08b8ddb357c16f&dn=flags
VLCDUMMY STATE magnet:?xt=urn:btih:18945a9300abfe4ff2442559bb08b8ddb357c16f&dn=flags OPENING
VLCDUMMY STATE magnet:?xt=urn:btih:18945a9300abfe4ff2442559bb08b8ddb357c16f&dn=flags PLAYING
VLCDUMMY SUBITEM flags (DIRECTORY)
VLCDUMMY SUBITEM denmark.png (FILE)
VLCDUMMY SUBITEM norway.png (FILE)
VLCDUMMY SUBITEM sweden.png (FILE)
VLCDUMMY STATE magnet:?xt=urn:btih:18945a9300abfe4ff2442559bb08b8ddb357c16f&dn=flags ENDED (0 audio frames, 0 video frames)
VLCDUMMY STATE flags OPENING
VLCDUMMY STATE flags PLAYING
VLCDUMMY STATE flags ENDED (0 audio frames, 0 video frames)
VLCDUMMY STATE denmark.png OPENING
VLCDUMMY STATE denmark.png PLAYING
VLCDUMMY STATE denmark.png ENDED (0 audio frames, >0 video frames)
VLCDUMMY STATE norway.png OPENING
VLCDUMMY STATE norway.png PLAYING
VLCDUMMY STATE norway.png ENDED (0 audio frames, >0 video frames)
VLCDUMMY STATE sweden.png OPENING
VLCDUMMY STATE sweden.png PLAYING
VLCDUMMY STATE sweden.png ENDED (0 audio frames, >0 video frames)
VLCDUMMY END
vlc-bittorrent-2.14/test/data/flags.torrent-magnet.downloaddummy-metadata-expected.txt 0000664 0000000 0000000 00000000344 14171042373 0031352 0 ustar 00root root 0000000 0000000 DOWNLOADDUMMY NAME flags
DOWNLOADDUMMY INFOHASH 18945a9300abfe4ff2442559bb08b8ddb357c16f
DOWNLOADDUMMY FILE flags/denmark.png 476
DOWNLOADDUMMY FILE flags/norway.png 744
DOWNLOADDUMMY FILE flags/sweden.png 636
DOWNLOADDUMMY END
vlc-bittorrent-2.14/test/data/flags.torrent-magnet.downloaddummy-read-expected.txt 0000664 0000000 0000000 00000000135 14171042373 0030503 0 ustar 00root root 0000000 0000000 DOWNLOADDUMMY READ 476 0
DOWNLOADDUMMY READ 744 1
DOWNLOADDUMMY READ 636 2
DOWNLOADDUMMY END
vlc-bittorrent-2.14/test/data/flags.torrent-magnet.metadata-expected.txt 0000664 0000000 0000000 00000001044 14171042373 0026467 0 ustar 00root root 0000000 0000000 VLCDUMMY ITEM magnet:?xt=urn:btih:18945a9300abfe4ff2442559bb08b8ddb357c16f&dn=flags
VLCDUMMY STATE magnet:?xt=urn:btih:18945a9300abfe4ff2442559bb08b8ddb357c16f&dn=flags OPENING
VLCDUMMY STATE magnet:?xt=urn:btih:18945a9300abfe4ff2442559bb08b8ddb357c16f&dn=flags PLAYING
VLCDUMMY SUBITEM flags (DIRECTORY)
VLCDUMMY SUBITEM denmark.png (FILE)
VLCDUMMY SUBITEM norway.png (FILE)
VLCDUMMY SUBITEM sweden.png (FILE)
VLCDUMMY STATE magnet:?xt=urn:btih:18945a9300abfe4ff2442559bb08b8ddb357c16f&dn=flags ENDED (0 audio frames, 0 video frames)
VLCDUMMY END
vlc-bittorrent-2.14/test/data/flags.torrent.data-expected.txt 0000664 0000000 0000000 00000001517 14171042373 0024354 0 ustar 00root root 0000000 0000000 VLCDUMMY ITEM flags.torrent
VLCDUMMY STATE flags.torrent OPENING
VLCDUMMY STATE flags.torrent PLAYING
VLCDUMMY SUBITEM flags (DIRECTORY)
VLCDUMMY SUBITEM denmark.png (FILE)
VLCDUMMY SUBITEM norway.png (FILE)
VLCDUMMY SUBITEM sweden.png (FILE)
VLCDUMMY STATE flags.torrent ENDED (0 audio frames, 0 video frames)
VLCDUMMY STATE flags OPENING
VLCDUMMY STATE flags PLAYING
VLCDUMMY STATE flags ENDED (0 audio frames, 0 video frames)
VLCDUMMY STATE denmark.png OPENING
VLCDUMMY STATE denmark.png PLAYING
VLCDUMMY STATE denmark.png ENDED (0 audio frames, >0 video frames)
VLCDUMMY STATE norway.png OPENING
VLCDUMMY STATE norway.png PLAYING
VLCDUMMY STATE norway.png ENDED (0 audio frames, >0 video frames)
VLCDUMMY STATE sweden.png OPENING
VLCDUMMY STATE sweden.png PLAYING
VLCDUMMY STATE sweden.png ENDED (0 audio frames, >0 video frames)
VLCDUMMY END
vlc-bittorrent-2.14/test/data/flags.torrent.downloaddummy-metadata-expected.txt 0000664 0000000 0000000 00000000344 14171042373 0030101 0 ustar 00root root 0000000 0000000 DOWNLOADDUMMY NAME flags
DOWNLOADDUMMY INFOHASH 18945a9300abfe4ff2442559bb08b8ddb357c16f
DOWNLOADDUMMY FILE flags/denmark.png 476
DOWNLOADDUMMY FILE flags/norway.png 744
DOWNLOADDUMMY FILE flags/sweden.png 636
DOWNLOADDUMMY END
vlc-bittorrent-2.14/test/data/flags.torrent.downloaddummy-read-expected.txt 0000664 0000000 0000000 00000000135 14171042373 0027232 0 ustar 00root root 0000000 0000000 DOWNLOADDUMMY READ 476 0
DOWNLOADDUMMY READ 744 1
DOWNLOADDUMMY READ 636 2
DOWNLOADDUMMY END
vlc-bittorrent-2.14/test/data/flags.torrent.metadata-expected.txt 0000664 0000000 0000000 00000000504 14171042373 0025216 0 ustar 00root root 0000000 0000000 VLCDUMMY ITEM flags.torrent
VLCDUMMY STATE flags.torrent OPENING
VLCDUMMY STATE flags.torrent PLAYING
VLCDUMMY SUBITEM flags (DIRECTORY)
VLCDUMMY SUBITEM denmark.png (FILE)
VLCDUMMY SUBITEM norway.png (FILE)
VLCDUMMY SUBITEM sweden.png (FILE)
VLCDUMMY STATE flags.torrent ENDED (0 audio frames, 0 video frames)
VLCDUMMY END
vlc-bittorrent-2.14/test/data/flags/ 0000775 0000000 0000000 00000000000 14171042373 0017404 5 ustar 00root root 0000000 0000000 vlc-bittorrent-2.14/test/data/flags/denmark.png 0000664 0000000 0000000 00000000734 14171042373 0021537 0 ustar 00root root 0000000 0000000 PNG
IHDR z B gAMA a cHRM z&