pax_global_header00006660000000000000000000000064143126346470014524gustar00rootroot0000000000000052 comment=5ced53d80258ce2cf16bb94f723af8f1d5b69b48 ocaml-taglib-0.3.10/000077500000000000000000000000001431263464700141405ustar00rootroot00000000000000ocaml-taglib-0.3.10/.github/000077500000000000000000000000001431263464700155005ustar00rootroot00000000000000ocaml-taglib-0.3.10/.github/workflows/000077500000000000000000000000001431263464700175355ustar00rootroot00000000000000ocaml-taglib-0.3.10/.github/workflows/main.yml000066400000000000000000000006231431263464700212050ustar00rootroot00000000000000name: Build on: [push] jobs: build: runs-on: ${{ matrix.operating-system }} strategy: matrix: operating-system: [ubuntu-latest, macos-latest] steps: - name: Checkout latest code uses: actions/checkout@v1 - name: Install ocaml uses: ocaml/setup-ocaml@v2 - name: Install module run: opam install --cli=2.1 --with-test --confirm-level=unsafe-yes . ocaml-taglib-0.3.10/.gitignore000066400000000000000000000000721431263464700161270ustar00rootroot00000000000000*~ _build *.byte *.native _tests .merlin *.install .*.sw* ocaml-taglib-0.3.10/.ocamlformat000066400000000000000000000003371431263464700164500ustar00rootroot00000000000000version=0.19.0 profile = conventional break-separators = after space-around-lists = false doc-comments = before match-indent = 2 match-indent-nested = always parens-ite exp-grouping = preserve module-item-spacing = compact ocaml-taglib-0.3.10/CHANGES000066400000000000000000000036601431263464700151400ustar00rootroot000000000000000.3.10 (21-09-2022) ====== * Add support for `OggOpus` 0.3.9 (09-02-2022) ===== * Fix segfault (#11) 0.3.8 (04-01-2022) ===== * Get rid of naked pointers. 0.3.7 (31-10-2021) 🎃 ===== * Switched to dune 0.3.6 (04-08-2019) ===== * Use OCaml conversion functions for filename on windows platforms. * Make taglib safe-string compatible * Bump minimum OCaml version. 0.3.5 (17-09-2018) ===== * Fix unicode filename on windows platforms. 0.3.4 (12-10-2017) ===== * Fix MXE/MinGW compilation. 0.3.3 (11-04-2017) ===== * Fix values string encoding in set_properties callback. 0.3.2 (03-08-2015) ===== * Raise Invalid_file instead of Not_found when TagLib open returns a NULL pointer 0.3.1 (08-05-2013) ===== * Wrapped file opening within caml_release_runtime_system()/caml_acquire_runtime_system() calls to avoid deadlock when Taglib writes to stderr in daemon mode. 0.3.0 (18-02-2013) ===== * Added {set_}properties API. 0.2.0 (31-08-2011) ===== * Reworked binding using C++ functions * Added Inline module to manipulate binary tags without a corresponding file. Only id2v3 tags are supported for now.. 0.1.4 (02-07-2011) ===== * Reworked build system, now using pkg-config. * Added new file formats. Raises Not_implemented if using formats not implemented, i.e. using taglib <= 1.5 * Using type t for the main type (standard notation). 0.1.3 (20-06-2009) ===== * Added support for --enable-debugging configure option * Fixed Makefile for BSD: call $(MAKE) for generating documentation. * Makefile now honnors LIBDIRS variable for linking against libraries located in other places than then standard ones. * Added prefix to main compilation variables if passed to configure. * Added NO_CUSTOM to build in standard mode. * Create file is now done in blocking section. 0.1.2 (16-04-2008) ===== * Add header detection to configure * Install .cmx file 0.1.1 (17-12-2007) ===== * Safer file opening 0.1.0 (08-11-2007) ===== * Initial release ocaml-taglib-0.3.10/COPYING000066400000000000000000000654371431263464700152120ustar00rootroot00000000000000This program is released under the LGPL version 2.1 (see the text below) with the additional exemption that compiling, linking, and/or using OpenSSL is allowed. As a special exception to the GNU Library General Public License, you may also link, statically or dynamically, a "work that uses the Library" with a publicly distributed version of the Library to produce an executable file containing portions of the Library, and distribute that executable file under terms of your choice, without any of the additional requirements listed in clause 6 of the GNU Library General Public License. By "a publicly distributed version of the Library", we mean either the unmodified Library, or a modified version of the Library that is distributed under the conditions defined in clause 3 of the GNU Library General Public License. This exception does not however invalidate any other reasons why the executable file might be covered by the GNU Library General Public License. GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999 Copyright (C) 1991, 1999 Free Software Foundation, Inc. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. [This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. When we speak of free software, we are referring to freedom of use, 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 this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. GNU LESSER GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) "Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) The modified work must itself be a software library. b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code of the Library into a program that is not a library. 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. 6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. 10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. 11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), 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 distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 13. The Free Software Foundation may publish revised and/or new versions of the Lesser 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 Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "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 LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY 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 LIBRARY (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 LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Libraries If you develop a new library, and you want it to be of the greatest possible use to the public, we recommend making it free software that everyone can redistribute and change. You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License). To apply these terms, attach the following notices to the library. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the library, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the library `Frob' (a library for tweaking knobs) written by James Random Hacker. , 1 April 1990 Ty Coon, President of Vice That's all there is to it! ocaml-taglib-0.3.10/README.md000066400000000000000000000016011431263464700154150ustar00rootroot00000000000000ocaml-taglib ============ This package contains an O'Caml interface for TagLib Audio Meta-Data Library, otherwise known as taglib. Please read the COPYING file before using this software. Prerequisites ============= * ocaml >= 4.02.0 * Taglib >= 1.8 * findlib >= 1.3.3 * dune >= 2 Compilation ============ ``` $ dune build ``` This should build both the native and the byte-code version of the extension library. Installation ============= Via `opam`: ```sh $ opam install taglib ``` Via `dune` (for developers): ```sh $ dune ``` Known Issues ============ File opening is somewhat unsafe. This has been wrapped in a unix stat test, but you should ensure that your file is really valid before opening it. See: http://bugs.debian.org/454732 Author ------ This author of this software may be contacted by electronic mail at the following address: savonet-users@lists.sourceforge.net. ocaml-taglib-0.3.10/dune-project000066400000000000000000000011431431263464700164610ustar00rootroot00000000000000(lang dune 2.8) (version 0.3.10) (name taglib) (source (github savonet/ocaml-taglib)) (license "LGPL-2.1-only WITH OCaml-LGPL-linking-exception") (authors "The Savonet Team ") (maintainers "The Savonet Team ") (generate_opam_files true) (use_standard_c_and_cxx_flags false) (package (name taglib) (synopsis "Bindings for the taglib library") (description "Bindings for the taglib library which provides functions for reading tags in headers of audio files") (depends dune (ocaml (>= 4.07)) conf-taglib dune-configurator) ) ocaml-taglib-0.3.10/examples/000077500000000000000000000000001431263464700157565ustar00rootroot00000000000000ocaml-taglib-0.3.10/examples/dune000066400000000000000000000006201431263464700166320ustar00rootroot00000000000000(executable (name read_tags) (modules read_tags) (libraries taglib)) (executable (name properties) (modules properties) (libraries taglib)) (executable (name tagutil) (modules tagutil) (libraries taglib)) (rule (alias runtest) (package taglib) (deps (:mp3 test.mp3) (:properties ./properties.exe)) (action (system "./%{properties} %{mp3} | grep ocaml_taglib_test >/dev/null"))) ocaml-taglib-0.3.10/examples/properties.ml000066400000000000000000000006741431263464700205130ustar00rootroot00000000000000let () = let fname = Sys.argv.(1) in let f = Taglib.File.open_file `Autodetect fname in let prop = Taglib.File.properties f in Hashtbl.iter (fun t v -> let v = String.concat " / " v in Printf.printf " - %s : %s\n%!" t v) prop; Hashtbl.replace prop "PUBLISHER" ["foobarlol"]; Taglib.File.set_properties f prop; Taglib.tag_set_title f "Some title"; ignore (Taglib.File.file_save f); Taglib.File.close_file f ocaml-taglib-0.3.10/examples/read_tags.ml000066400000000000000000000007571431263464700202520ustar00rootroot00000000000000let () = let fname = Sys.argv.(1) in let f = Taglib.File.open_file `Autodetect fname in let t fn f = try fn f with _ -> "(none)" in let td fn f = try string_of_int (fn f) with _ -> "(none)" in Taglib.( Printf.printf "Track: %s, Artist: %s, Title: %s, Album: %s, Comment: %s, Genre: %s, \ Year: %s\n\ %!" (td tag_track f) (t tag_artist f) (t tag_title f) (t tag_album f) (t tag_comment f) (t tag_genre f) (td tag_year f)); Taglib.File.close_file f ocaml-taglib-0.3.10/examples/tagutil.ml000066400000000000000000000027601431263464700177660ustar00rootroot00000000000000let usage = "usage: tagutil [ -s ]" type mode = Strip | Generate let strip = ref false let args = [("-s", Arg.Set strip, "Switch to strip mode.")] let gen_tag () = let tag = Taglib.Inline.Id3v2.init () in let tag = Taglib.Inline.Id3v2.attach_frame tag "TSSE" "tagutil example" in let tag = Taglib.Inline.Id3v2.tag_set_title tag "some title" in let read tag = Taglib.Inline.Id3v2.attach_frame tag (read_line ()) (read_line ()) in let rec f tag = try f (read tag) with _ -> tag in let tag = f tag in output_string stdout (Taglib.Inline.Id3v2.render tag) let strip_tag () = let buf = Buffer.create 1024 in let tmp = Bytes.create 1024 in while Buffer.length buf < Taglib.Inline.Id3v2.header_size do let ret = input stdin tmp 0 Taglib.Inline.Id3v2.header_size in Buffer.add_subbytes buf tmp 0 ret done; let tag_size = try let t = Taglib.Inline.Id3v2.init () in let t = Taglib.Inline.Id3v2.parse_header t (Buffer.contents buf) in Taglib.Inline.Id3v2.tag_size t with _ -> 0 in while Buffer.length buf < tag_size do let ret = input stdin tmp 0 tag_size in Buffer.add_subbytes buf tmp 0 ret done; let len = Buffer.length buf in output_string stdout (Buffer.sub buf tag_size (len - tag_size)); let rec f () = let ret = input stdin tmp 0 1024 in if ret > 0 then begin output_bytes stdout (Bytes.sub tmp 0 ret); f () end in f () let () = Arg.parse args ignore usage; if !strip then strip_tag () else gen_tag () ocaml-taglib-0.3.10/examples/test.mp3000066400000000000000000000012411431263464700173540ustar00rootroot00000000000000ID3@TIT2ocaml_taglib_testTSSELavf58.76.100@InfoWLavc58.13$WXËP dS25f6\,h>ܵ.#j ,ׄ<Y4`-B Рd~^WzR" >A pgHct$N@~B2dG1æb04@bzBED8+*[[T)/^Ǿ8OV_Y}ATАLz5E-6@LCRm4WMbq-I#$$kAz.!>W3i6^U_ 4xJ ,5X+b#|JLAME3.100ocaml-taglib-0.3.10/src/000077500000000000000000000000001431263464700147275ustar00rootroot00000000000000ocaml-taglib-0.3.10/src/config/000077500000000000000000000000001431263464700161745ustar00rootroot00000000000000ocaml-taglib-0.3.10/src/config/discover.ml000066400000000000000000000047701431263464700203540ustar00rootroot00000000000000module C = Configurator.V1 let check_class_code = Printf.sprintf {| #include <%s> int main() { %s *x = NULL; return 0; } |} let () = C.main ~name:"taglib-pkg-config" (fun c -> let default : C.Pkg_config.package_conf = { libs = ["-ltaglib"]; cflags = [] } in let conf = match C.Pkg_config.get c with | None -> default | Some pc -> ( match C.Pkg_config.query_expr_err pc ~package:"taglib" ~expr:"taglib >= 1.6" with | Error msg -> failwith msg | Ok deps -> deps) in C.Flags.write_sexp "c_flags.sexp" ("-fPIC" :: conf.cflags); C.Flags.write_sexp "c_library_flags.sexp" ("-lstdc++" :: conf.libs); let has_properties = C.c_test ~c_flags:(["-x"; "c++"] @ conf.cflags) ~link_flags:conf.libs c (check_class_code "tpropertymap.h" "TagLib::PropertyMap") in let has_wavpack = C.c_test ~c_flags:(["-x"; "c++"] @ conf.cflags) ~link_flags:conf.libs c (check_class_code "wavpackfile.h" "TagLib::WavPack::File") in let has_speex = C.c_test ~c_flags:(["-x"; "c++"] @ conf.cflags) ~link_flags:conf.libs c (check_class_code "speexfile.h" "TagLib::Ogg::Speex::File") in let has_opus = C.c_test ~c_flags:(["-x"; "c++"] @ conf.cflags) ~link_flags:conf.libs c (check_class_code "opusfile.h" "TagLib::Ogg::Opus::File") in let has_mp4 = C.c_test ~c_flags:(["-x"; "c++"] @ conf.cflags) ~link_flags:conf.libs c (check_class_code "mp4file.h" "TagLib::MP4::File") in let has_asf = C.c_test ~c_flags:(["-x"; "c++"] @ conf.cflags) ~link_flags:conf.libs c (check_class_code "asffile.h" "TagLib::ASF::File") in let has_trueaudio = C.c_test ~c_flags:(["-x"; "c++"] @ conf.cflags) ~link_flags:conf.libs c (check_class_code "trueaudiofile.h" "TagLib::TrueAudio::File") in C.C_define.gen_header_file c ~fname:"config.h" [ ("HAS_PROPERTIES", Switch has_properties); ("HAS_WAVPACK", Switch has_wavpack); ("HAS_SPEEX", Switch has_speex); ("HAS_OPUS", Switch has_opus); ("HAS_MP4", Switch has_mp4); ("HAS_ASF", Switch has_asf); ("HAS_TRUEAUDIO", Switch has_trueaudio); ]) ocaml-taglib-0.3.10/src/config/dune000066400000000000000000000000751431263464700170540ustar00rootroot00000000000000(executable (name discover) (libraries dune.configurator)) ocaml-taglib-0.3.10/src/dune000066400000000000000000000005721431263464700156110ustar00rootroot00000000000000(library (name taglib) (public_name taglib) (synopsis "OCaml bindings for taglib") (libraries unix) (foreign_stubs (language cxx) (names taglib_stubs) (extra_deps config.h) (flags (:include c_flags.sexp))) (c_library_flags (:include c_library_flags.sexp))) (rule (targets config.h c_flags.sexp c_library_flags.sexp) (action (run ./config/discover.exe))) ocaml-taglib-0.3.10/src/taglib.ml000066400000000000000000000226771431263464700165410ustar00rootroot00000000000000(* * Copyright 2007-2011 Romain Beauxis * * This file is part of ocaml-taglib. * * ocaml-taglib is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * ocaml-taglib 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 Lesser General Public License * along with ocaml-taglib; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * As a special exception to the GNU Library General Public License, you may * link, statically or dynamically, a "work that uses the Library" with a publicly * distributed version of the Library to produce an executable file containing * portions of the Library, and distribute that executable file under terms of * your choice, without any of the additional requirements listed in clause 6 * of the GNU Library General Public License. * By "a publicly distributed version of the Library", we mean either the unmodified * Library as distributed by The Savonet Team, or a modified version of the Library that is * distributed under the conditions defined in clause 3 of the GNU Library General * Public License. This exception does not however invalidate any other reasons why * the executable file might be covered by the GNU Library General Public License. * *) (* @author Romain Beauxis *) external init : unit -> unit = "caml_taglib_init" let () = Callback.register_exception "taglib_exn_not_found" Not_found; init () type tag type 'a t = 'a * ('a -> tag) external version : unit -> string = "caml_taglib_version" let version = version () module File = struct type taglib_file type audioproperties type file_type = [ `Autodetect | `Mpeg | `OggVorbis | `OggOpus | `Flac | `Mpc | `OggFlac | `WavPack | `Speex | `TrueAudio | `Mp4 | `Asf ] type 'a fileref = { file_type : 'a; mutable taglib_file : taglib_file option; } constraint 'a = [< file_type ] (** Type for a file. *) type 'a file_tag = 'a fileref type 'a file = 'a fileref t exception Invalid_file exception Closed exception Not_implemented let _ = Callback.register_exception "taglib_exn_invalid_file" Invalid_file; Callback.register_exception "taglib_exn_not_implemented" Not_implemented external open_file : file_type -> string -> taglib_file = "caml_taglib_file_new" external close_file : taglib_file -> unit = "caml_taglib_file_free" let close_file (d, _) = match d with | { taglib_file = None; _ } -> () | { taglib_file = Some f; _ } -> close_file f; d.taglib_file <- None external file_tag : taglib_file -> tag = "caml_taglib_file_tag" external file_audioproperties : taglib_file -> audioproperties = "caml_taglib_file_audioproperties" let get_taglib_file f = match f with | { taglib_file = None; _ } -> raise Closed | { taglib_file = Some f; _ } -> f external file_save : taglib_file -> bool = "caml_taglib_file_save" let file_save (f, _) = file_save (get_taglib_file f) let file_type (d, _) = match d with { taglib_file = None; _ } -> raise Closed | _ -> d.file_type let open_file file_type name = (* Test whether file exist to avoid library issue. See: http://bugs.debian.org/454732 *) begin try ignore (Unix.stat name) with _ -> raise Not_found end; let f = open_file file_type name in let file = { taglib_file = Some f; file_type } in let file = ( file, fun f -> match f with | { taglib_file = None; _ } -> raise Closed | { taglib_file = Some f; _ } -> file_tag f ) in Gc.finalise close_file file; file external properties : taglib_file -> (string -> string -> unit) -> unit = "caml_taglib_file_get_properties" let properties (f, _) = let f = get_taglib_file f in let props = Hashtbl.create 5 in let fn key value = let values = try Hashtbl.find props key with Not_found -> [] in Hashtbl.replace props key (value :: values) in properties f fn; props external set_properties : taglib_file -> (string * string array) array -> unit = "caml_taglib_file_set_properties" let set_properties (f, _) props = let f = get_taglib_file f in let props = Hashtbl.fold (fun key values props -> (key, Array.of_list values) :: props) props [] in set_properties f (Array.of_list props) external audioproperties_get_int : audioproperties -> string -> int = "caml_taglib_audioproperties_get_int" let audioproperties_get_int (f, _) s = let f = get_taglib_file f in audioproperties_get_int (file_audioproperties f) s let audioproperties_length p = audioproperties_get_int p "length" let audioproperties_bitrate p = audioproperties_get_int p "bitrate" let audioproperties_samplerate p = audioproperties_get_int p "samplerate" let audioproperties_channels p = audioproperties_get_int p "channels" end let tag_extract (x, f) = f x external tag_get_string : tag -> string -> string = "caml_taglib_tag_get_string" let tag_get_string d s = tag_get_string (tag_extract d) s let tag_title t = tag_get_string t "title" let tag_artist t = tag_get_string t "artist" let tag_album t = tag_get_string t "album" let tag_comment t = tag_get_string t "comment" let tag_genre t = tag_get_string t "genre" external tag_get_int : tag -> string -> int = "caml_taglib_tag_get_int" let tag_get_int d s = tag_get_int (tag_extract d) s let tag_year t = tag_get_int t "year" let tag_track t = tag_get_int t "track" external tag_set_string : tag -> string -> string -> unit = "caml_taglib_tag_set_string" let tag_set_string t s v = tag_set_string (tag_extract t) s v let tag_set_title t = tag_set_string t "title" let tag_set_artist t = tag_set_string t "artist" let tag_set_album t = tag_set_string t "album" let tag_set_comment t = tag_set_string t "comment" let tag_set_genre t = tag_set_string t "genre" external tag_set_int : tag -> string -> int -> unit = "caml_taglib_tag_set_int" let tag_set_int t s v = tag_set_int (tag_extract t) s v let tag_set_year t = tag_set_int t "year" let tag_set_track t = tag_set_int t "track" module Inline = struct module Id3v2 = struct type state = [ `Invalid | `Parsed | `Valid ] type 'a id3v2_tag = unit constraint 'a = [< state ] type 'a id3v2 = 'a id3v2_tag t type frame_type = string type frame_text = string external init : unit -> tag = "caml_taglib_id3v2_init" let init () = let t = init () in ((), fun () -> t) external header_size : unit -> int = "caml_taglib_id3v2_header_len" let header_size = header_size () let grab_tag ((), f) = f () external parse_header : tag -> string -> unit = "caml_taglib_id3v2_parse_header" external tag_size : tag -> int = "caml_taglib_id3v2_tag_size" let tag_size t = tag_size (grab_tag t) let parse_header t h = if String.length h < header_size then failwith "header string too short."; parse_header (grab_tag t) h; if tag_size t <= header_size then failwith "invalid header"; t external parse_tag : tag -> string -> unit = "caml_taglib_id3v2_parse_tag" let parse_tag t h = if String.length h < tag_size t then failwith "tag data too short."; parse_tag (grab_tag t) h; t external render : tag -> bytes = "caml_taglib_id3v2_render" let render t = Bytes.unsafe_to_string (render (grab_tag t)) external attach_frame : tag -> string -> string -> unit = "caml_taglib_id3v2_attach_frame" let attach_frame t l c = attach_frame (grab_tag t) l c; t let tag_set_title t s = tag_set_title t s; t let tag_set_artist t s = tag_set_artist t s; t let tag_set_album t s = tag_set_album t s; t let tag_set_comment t s = tag_set_comment t s; t let tag_set_genre t s = tag_set_genre t s; t let tag_set_year t s = tag_set_year t s; t let tag_set_track t s = tag_set_track t s; t end end type file_type = | Mpeg | OggVorbis | OggOpus | Flac | Mpc | OggFlac | WavPack | Speex | TrueAudio | Mp4 | Asf exception Closed exception Not_implemented let set_strings_unicode _ = () let open_file ?file_type f = let f x = File.open_file x f in match file_type with | None -> f `Autodetect | Some t -> ( match t with | Mpeg -> f `Mpeg | OggVorbis -> f `OggVorbis | OggOpus -> f `OggOpus | Flac -> f `Flac | Mpc -> f `Mpc | OggFlac -> f `OggFlac | WavPack -> f `WavPack | Speex -> f `Speex | TrueAudio -> f `TrueAudio | Mp4 -> f `Mp4 | Asf -> f `Asf) let w f t = try f t with | File.Closed -> raise Closed | File.Not_implemented -> raise Not_implemented let audioproperties_length = w File.audioproperties_length let audioproperties_bitrate = w File.audioproperties_bitrate let audioproperties_samplerate = w File.audioproperties_samplerate let audioproperties_channels = w File.audioproperties_channels let close_file = w File.close_file let file_save = w File.file_save ocaml-taglib-0.3.10/src/taglib.mli000066400000000000000000000171161431263464700167020ustar00rootroot00000000000000(* * Copyright 2007-2011 Romain Beauxis * * This file is part of ocaml-taglib. * * ocaml-taglib is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * ocaml-taglib 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 Lesser General Public License * along with ocaml-taglib; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * As a special exception to the GNU Library General Public License, you may * link, statically or dynamically, a "work that uses the Library" with a publicly * distributed version of the Library to produce an executable file containing * portions of the Library, and distribute that executable file under terms of * your choice, without any of the additional requirements listed in clause 6 * of the GNU Library General Public License. * By "a publicly distributed version of the Library", we mean either the unmodified * Library as distributed by The Savonet Team, or a modified version of the Library that is * distributed under the conditions defined in clause 3 of the GNU Library General * Public License. This exception does not however invalidate any other reasons why * the executable file might be covered by the GNU Library General Public License. * *) (* @author Romain Beauxis *) (** Ocaml bindings to taglib *) (** Taglib provides a set/get interface for several audio file format's tags informations. * * All strings used in this module should be UTF8-encoded. *) (** {2 Types } *) (** Main type. *) type 'a t (** {2 Values } *) (** Taglib's version. *) val version : string (** {2 Generic tag interface } *) val tag_title : 'a t -> string val tag_artist : 'a t -> string val tag_album : 'a t -> string val tag_comment : 'a t -> string val tag_genre : 'a t -> string val tag_year : 'a t -> int val tag_track : 'a t -> int (** {2 Set tag interface } *) val tag_set_title : 'a t -> string -> unit val tag_set_artist : 'a t -> string -> unit val tag_set_album : 'a t -> string -> unit val tag_set_comment : 'a t -> string -> unit val tag_set_genre : 'a t -> string -> unit val tag_set_year : 'a t -> int -> unit val tag_set_track : 'a t -> int -> unit (** {2 File interface } *) module File : sig (** Supported file types. Warning, types: [WavPack], * [Speex] and [TrueAudio] are only supported in * Taglib >= 1.5. * Types: [Mp4], [Asf] are only supported with * Taglib >= 1.6. * Type: [OggOpus] is only supported with * Taglib >= 1.9 and does not seem to be supported * in [`Autodetect] mode. *) type file_type = [ `Autodetect | `Mpeg | `OggVorbis | `OggOpus | `Flac | `Mpc | `OggFlac | `WavPack | `Speex | `TrueAudio | `Mp4 | `Asf ] (** Type for a file. *) type 'a file_tag constraint 'a = [< file_type ] type 'a file = 'a file_tag t (** Raised when using a file that has been closed *) exception Closed (** Raised when using a file format not supported by * the system's taglib library. *) exception Not_implemented (** Raised when taglib cannot parse a file. *) exception Invalid_file (** Open a file. Raises [Not_found] if file does not exist or could not be opened. Raises [Invalid_file] if taglib could not parse the file. Raises [Not_implemented] if given [file_type] is not implemented by taglib. *) val open_file : file_type -> string -> file_type file val close_file : file_type file -> unit val file_save : file_type file -> bool val file_type : file_type file -> file_type val properties : file_type file -> (string, string list) Hashtbl.t val set_properties : file_type file -> (string, string list) Hashtbl.t -> unit (** {2 Get audio properties interface } *) val audioproperties_length : file_type file -> int val audioproperties_bitrate : file_type file -> int val audioproperties_samplerate : file_type file -> int val audioproperties_channels : file_type file -> int end (** {2 Inline interface } *) (** This module provides an API to manipulate tags not * attached to a file. *) module Inline : sig (** Parse and generate id3v2 binary tags. * * This module provides ways to manipulate id3v2 tags * not attached to a file. It is quite low-level and, * despite good care in tightening its API, it is possible * to generate invalid id3v2 tags using it. The user is thus * advised to read about the id3v2 standard before using this * module. * * Currently, only attaching text-based frames are supported. * Reading tag's frames can only be done currently through the * common [tag_title], ... API. * * See [examples/tagutil.ml] for an example of the use of this module. *) module Id3v2 : sig (** State of the tag. This is used to enforce validity of * the generated tag. * * A tag is valid iff it has been properly parsed or * at least one frame has been added to it. *) type state = [ `Invalid | `Parsed | `Valid ] type 'a id3v2_tag constraint 'a = [< state ] type 'a id3v2 = 'a id3v2_tag t (** A frame type is the id3v2 identifier, e.g. TIT2, TALB, ... *) type frame_type = string (** Text content of a frame. *) type frame_text = string val init : unit -> [ `Invalid ] id3v2 val header_size : int val parse_header : [ `Invalid ] id3v2 -> string -> [ `Parsed ] id3v2 val tag_size : [< `Parsed | `Valid ] id3v2 -> int val parse_tag : [ `Parsed ] id3v2 -> string -> [ `Valid ] id3v2 val attach_frame : [< `Invalid | `Valid ] id3v2 -> frame_type -> frame_text -> [ `Valid ] id3v2 val render : [ `Valid ] id3v2 -> string (** {2 Generic set functions} *) (** These functions perform the same operations as their counter-part from [Taglib]. * The only difference here is that they return a valid tag. *) val tag_set_title : [< `Invalid | `Valid ] id3v2 -> string -> [ `Valid ] id3v2 val tag_set_artist : [< `Invalid | `Valid ] id3v2 -> string -> [ `Valid ] id3v2 val tag_set_album : [< `Invalid | `Valid ] id3v2 -> string -> [ `Valid ] id3v2 val tag_set_comment : [< `Invalid | `Valid ] id3v2 -> string -> [ `Valid ] id3v2 val tag_set_genre : [< `Invalid | `Valid ] id3v2 -> string -> [ `Valid ] id3v2 val tag_set_year : [< `Invalid | `Valid ] id3v2 -> int -> [ `Valid ] id3v2 val tag_set_track : [< `Invalid | `Valid ] id3v2 -> int -> [ `Valid ] id3v2 end end (** {2 Deprecated } *) (** This section is for backward compatibility with previous API. It * may be removed at any time. *) type file_type = | Mpeg | OggVorbis | OggOpus | Flac | Mpc | OggFlac | WavPack | Speex | TrueAudio | Mp4 | Asf exception Closed exception Not_implemented (** This does not do anything now.. *) val set_strings_unicode : bool -> unit val open_file : ?file_type:file_type -> string -> File.file_type File.file val audioproperties_length : File.file_type File.file -> int val audioproperties_bitrate : File.file_type File.file -> int val audioproperties_samplerate : File.file_type File.file -> int val audioproperties_channels : File.file_type File.file -> int val close_file : File.file_type File.file -> unit val file_save : File.file_type File.file -> bool ocaml-taglib-0.3.10/src/taglib_stubs.cc000066400000000000000000000404561431263464700177310ustar00rootroot00000000000000/* * Copyright 2007-2011 Romain Beauxis * * This file is part of ocaml-taglib. * * ocaml-taglib is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * ocaml-taglib 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 Lesser General Public License * along with ocaml-taglib; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * As a special exception to the GNU Library General Public License, you may * link, statically or dynamically, a "work that uses the Library" with a * publicly distributed version of the Library to produce an executable file * containing portions of the Library, and distribute that executable file under * terms of your choice, without any of the additional requirements listed in * clause 6 of the GNU Library General Public License. By "a publicly * distributed version of the Library", we mean either the unmodified Library as * distributed by The Savonet Team, or a modified version of the Library that is * distributed under the conditions defined in clause 3 of the GNU Library * General Public License. This exception does not however invalidate any other * reasons why the executable file might be covered by the GNU Library General * Public License. * */ /* * Ocaml interface to taglib * * @author Romain Beauxis */ #include "config.h" #include #include #include #ifdef HAS_ASF #include #endif #include #include #include #include #ifdef HAS_OPUS #include #endif #ifdef HAS_MP4 #include #endif #ifdef HAS_MPC #include #endif #ifdef HAS_WAVPACK #include #endif #ifdef HAS_SPEEX #include #endif #ifdef HAS_TRUEAUDIO #include #endif #ifdef HAS_PROPERTIES #include #else #include #endif #include #include #include #include #include using namespace TagLib; /* Declaring the functions which should be accessible on the C side. */ extern "C" { #define CAML_INTERNALS #include #include #include #include #include #include #ifdef WIN32 #include #endif /* Use new thread syntax in a backward fashion. */ #define caml_acquire_runtime_system caml_leave_blocking_section #define caml_release_runtime_system caml_enter_blocking_section #include CAMLprim value caml_taglib_version(value unit); CAMLprim value caml_taglib_init(value unit); CAMLprim value caml_taglib_file_new(value type, value name); CAMLprim value caml_taglib_file_free(value f); CAMLprim value caml_taglib_file_tag(value f); CAMLprim value caml_taglib_file_audioproperties(value f); CAMLprim value caml_taglib_file_save(value f); CAMLprim value caml_taglib_tag_get_string(value t, value name); CAMLprim value caml_taglib_tag_get_int(value t, value name); CAMLprim value caml_taglib_file_get_properties(value f, value fn); CAMLprim value caml_taglib_tag_set_string(value t, value name, value v); CAMLprim value caml_taglib_tag_set_int(value t, value name, value v); CAMLprim value caml_taglib_file_set_properties(value t, value properties); CAMLprim value caml_taglib_audioproperties_get_int(value p, value name); CAMLprim value caml_taglib_id3v2_init(value unit); CAMLprim value caml_taglib_id3v2_clean(value t); CAMLprim value caml_taglib_id3v2_header_len(value t); CAMLprim value caml_taglib_id3v2_parse_header(value t, value h); CAMLprim value caml_taglib_id3v2_tag_size(value t); CAMLprim value caml_taglib_id3v2_parse_tag(value t, value h); CAMLprim value caml_taglib_id3v2_render(value t); CAMLprim value caml_taglib_id3v2_attach_frame(value t, value l, value c); } CAMLprim value caml_taglib_version(value unit) { return caml_copy_string( "TAGLIB_MAJOR_VERSION.TAGLIB_MINOR_VERSION.TAGLIB_PATCH_VERSION"); } /* polymorphic variant utility macros */ #define decl_var(x) static value var_##x #define import_var(x) var_##x = caml_hash_variant(#x) #define get_var(x) var_##x /* cached polymorphic variants */ decl_var(Autodetect); decl_var(Mpeg); decl_var(OggVorbis); decl_var(OggOpus); decl_var(Flac); decl_var(Mpc); decl_var(OggFlac); decl_var(WavPack); decl_var(Speex); decl_var(TrueAudio); decl_var(Mp4); decl_var(Asf); CAMLprim value caml_taglib_init(value unit) { CAMLparam0(); /* initialize polymorphic variants */ import_var(Autodetect); import_var(Mpeg); import_var(OggVorbis); import_var(OggOpus); import_var(Flac); import_var(Mpc); import_var(OggFlac); import_var(WavPack); import_var(Speex); import_var(TrueAudio); import_var(Mp4); import_var(Asf); CAMLreturn(Val_unit); } #define Taglib_file_val(v) (*((File **)Data_abstract_val(v))) static inline value value_of_taglib_file(value v, File *f) { v = caml_alloc(1, Abstract_tag); *((File **)Data_abstract_val(v)) = f; return v; } #define Taglib_tag_val(v) (*((Tag **)Data_custom_val(v))) // tag are implemented as custom val in the id3v2 case so we need // to be consistent here. static struct custom_operations tag_ops = { (char *)"ocaml_taglib_tag", custom_finalize_default, custom_compare_default, custom_hash_default, custom_serialize_default, custom_deserialize_default}; static inline value value_of_taglib_tag(value v, Tag *tag) { v = caml_alloc_custom(&tag_ops, sizeof(Tag *), 1, 0); Taglib_tag_val(v) = tag; return v; } #define Taglib_audioproperties_val(v) \ (*((AudioProperties **)Data_abstract_val(v))) static inline value value_of_taglib_audioproperties(value v, AudioProperties *f) { v = caml_alloc(1, Abstract_tag); *((AudioProperties **)Data_abstract_val(v)) = f; return v; } CAMLprim value caml_taglib_file_new(value type, value name) { CAMLparam2(name, type); CAMLlocal1(ret); File *f = NULL; #ifdef WIN32 wchar_t *filename = caml_stat_strdup_to_os(String_val(name)); #else char *filename = strdup(String_val(name)); #endif if (filename == NULL) caml_raise_out_of_memory(); caml_release_runtime_system(); if (type == get_var(Autodetect)) f = FileRef::create(filename); else if (type == get_var(Mpeg)) f = new MPEG::File(filename); else if (type == get_var(OggVorbis)) f = new Ogg::Vorbis::File(filename); #ifdef HAS_OPUS else if (type == get_var(OggOpus)) f = new Ogg::Opus::File(filename); #endif else if (type == get_var(Flac)) f = new FLAC::File(filename); #ifdef HAS_MPC else if (type == get_var(Mpc)) f = new MPC::File(filename); #endif else if (type == get_var(OggFlac)) f = new Ogg::FLAC::File(filename); #ifdef HAS_WAVPACK else if (type == get_var(WavPack)) f = new MPEG::File(filename); #endif #ifdef HAS_SPEEX else if (type == get_var(Speex)) f = new Ogg::Speex::File(filename); #endif #ifdef HAS_TRUEAUDIO else if (type == get_var(TrueAudio)) f = new TrueAudio::File(filename); #endif #ifdef HAS_MP4 else if (type == get_var(Mp4)) f = new MP4::File(filename); #endif #ifdef HAS_ASF else if (type == get_var(Mpeg)) f = new MPEG::File(filename); #endif else { free(filename); caml_acquire_runtime_system(); caml_raise_constant(*caml_named_value("taglib_exn_not_implemented")); } free(filename); caml_acquire_runtime_system(); if (!(f && f->isValid())) { delete f; caml_raise_constant(*caml_named_value("taglib_exn_invalid_file")); } CAMLreturn(value_of_taglib_file(ret, f)); } CAMLprim value caml_taglib_file_free(value f) { CAMLparam1(f); delete Taglib_file_val(f); CAMLreturn(Val_unit); } CAMLprim value caml_taglib_file_tag(value f) { CAMLparam1(f); CAMLlocal1(ret); Tag *t = Taglib_file_val(f)->tag(); if (t == NULL) caml_raise_constant(*caml_named_value("taglib_exn_not_found")); CAMLreturn(value_of_taglib_tag(ret, t)); } CAMLprim value caml_taglib_file_audioproperties(value f) { CAMLparam1(f); CAMLlocal1(ret); AudioProperties *p = Taglib_file_val(f)->audioProperties(); if (p == NULL) caml_raise_constant(*caml_named_value("taglib_exn_not_found")); CAMLreturn(value_of_taglib_audioproperties(ret, p)); } CAMLprim value caml_taglib_file_save(value f) { CAMLparam1(f); int ret; caml_release_runtime_system(); ret = Taglib_file_val(f)->save(); caml_acquire_runtime_system(); CAMLreturn(Val_bool(ret)); } CAMLprim value caml_taglib_tag_get_string(value t, value name) { CAMLparam2(t, name); CAMLlocal1(ans); const Tag *tag = Taglib_tag_val(t); const char *s = String_val(name); String tmp = ""; if (!strcmp(s, "title")) tmp = tag->title(); else if (!strcmp(s, "artist")) tmp = tag->artist(); else if (!strcmp(s, "album")) tmp = tag->album(); else if (!strcmp(s, "comment")) tmp = tag->comment(); else if (!strcmp(s, "genre")) tmp = tag->genre(); else caml_failwith("Invalid value"); if (tmp.isEmpty()) caml_raise_constant(*caml_named_value("taglib_exn_not_found")); ans = caml_copy_string(tmp.toCString(bool(true))); CAMLreturn(ans); } CAMLprim value caml_taglib_tag_get_int(value t, value name) { CAMLparam2(t, name); const Tag *tag = Taglib_tag_val(t); const char *s = String_val(name); int tmp; if (!strcmp(s, "year")) tmp = tag->year(); else if (!strcmp(s, "track")) tmp = tag->track(); else caml_failwith("Invalid value"); if (tmp == 0) caml_raise_constant(*caml_named_value("taglib_exn_not_found")); CAMLreturn(Val_int(tmp)); } CAMLprim value caml_taglib_file_get_properties(value f, value fn) { CAMLparam2(f, fn); File *file = Taglib_file_val(f); #ifdef HAS_PROPERTIES PropertyMap props = file->properties(); PropertyMap::Iterator i; StringList l; const char *key; StringList::Iterator j; for (i = props.begin(); i != props.end(); i++) { key = (*i).first.toCString(bool(true)); l = (*i).second; for (j = l.begin(); j != l.end(); j++) { caml_callback2(fn, caml_copy_string(key), caml_copy_string((*j).toCString(bool(true)))); } } #else const Tag *tag = file->tag(); caml_callback2(fn, caml_copy_string("title"), caml_copy_string(tag->title().toCString(bool(true)))); caml_callback2(fn, caml_copy_string("artist"), caml_copy_string(tag->artist().toCString(bool(true)))); caml_callback2(fn, caml_copy_string("album"), caml_copy_string(tag->album().toCString(bool(true)))); caml_callback2(fn, caml_copy_string("comment"), caml_copy_string(tag->comment().toCString(bool(true)))); caml_callback2(fn, caml_copy_string("genre"), caml_copy_string(tag->genre().toCString(bool(true)))); char s[16]; snprintf(s, 16, "%d", tag->year()); caml_callback2(fn, caml_copy_string("year"), caml_copy_string(s)); snprintf(s, 16, "%d", tag->track()); caml_callback2(fn, caml_copy_string("track"), caml_copy_string(s)); #endif CAMLreturn(Val_unit); } CAMLprim value caml_taglib_file_set_properties(value f, value properties) { CAMLparam2(f, properties); #ifdef HAS_PROPERTIES CAMLlocal1(caml_values); File *file = Taglib_file_val(f); PropertyMap props; const char *caml_key, *caml_val; StringList *values; String *key, *val; int i, j; for (i = 0; i < Wosize_val(properties); i++) { caml_key = String_val(Field(Field(properties, i), 0)); caml_values = Field(Field(properties, i), 1); key = new String(caml_key, String::UTF8); values = new StringList(); for (j = 0; j < Wosize_val(caml_values); j++) { caml_val = String_val(Field(caml_values, j)); val = new String(caml_val, String::UTF8); values->append(*val); } props.insert(*key, *values); delete key; delete values; } // TODO: Catch this: // This default implementation sets only the tags for which // setter methods exist in this class (artist, album, ...), and // only one value per key; the rest will be contained in the // returned PropertyMap. file->setProperties(props); #else caml_failwith("Not implemented with taglib < 1.8."); #endif CAMLreturn(Val_unit); } CAMLprim value caml_taglib_tag_set_string(value t, value name, value v) { CAMLparam3(t, name, v); Tag *tag = Taglib_tag_val(t); const char *s = String_val(name); const char *x = String_val(v); if (!strcmp(s, "title")) tag->setTitle(String(x, String::UTF8)); else if (!strcmp(s, "artist")) tag->setArtist(String(x, String::UTF8)); else if (!strcmp(s, "album")) tag->setAlbum(String(x, String::UTF8)); else if (!strcmp(s, "comment")) tag->setComment(String(x, String::UTF8)); else if (!strcmp(s, "genre")) tag->setGenre(String(x, String::UTF8)); else caml_failwith("Invalid value"); CAMLreturn(Val_unit); } CAMLprim value caml_taglib_tag_set_int(value t, value name, value v) { CAMLparam3(t, name, v); Tag *tag = Taglib_tag_val(t); const char *s = String_val(name); int x = Int_val(v); if (!strcmp(s, "year")) tag->setYear(x); else if (!strcmp(s, "track")) tag->setTrack(x); else caml_failwith("Invalid value"); CAMLreturn(Val_unit); } CAMLprim value caml_taglib_audioproperties_get_int(value p, value name) { CAMLparam2(p, name); const AudioProperties *prop = Taglib_audioproperties_val(p); const char *s = String_val(name); int tmp; if (!strcmp(s, "length")) tmp = prop->length(); else if (!strcmp(s, "bitrate")) tmp = prop->bitrate(); else if (!strcmp(s, "samplerate")) tmp = prop->sampleRate(); else if (!strcmp(s, "channels")) tmp = prop->channels(); else caml_failwith("Invalid value"); CAMLreturn(Val_int(tmp)); } /* Id3v2 support. */ class myId3v2 : public TagLib::ID3v2::Tag { public: void doParse(const TagLib::ByteVector &data) { parse(data); } }; #define Id3v2_tag_val(v) (*((myId3v2 **)Data_custom_val(v))) static void finalize_id3v2_tag(value t) { myId3v2 *tag = Id3v2_tag_val(t); delete tag; } static struct custom_operations id3v2_tag_ops = { (char *)"ocaml_taglib_id3v2_tag", finalize_id3v2_tag, custom_compare_default, custom_hash_default, custom_serialize_default, custom_deserialize_default}; CAMLprim value caml_taglib_id3v2_init(value unit) { CAMLparam0(); CAMLlocal1(ret); myId3v2 *tag = new myId3v2(); ret = caml_alloc_custom(&id3v2_tag_ops, sizeof(ID3v2::Tag *), 1, 0); Id3v2_tag_val(ret) = tag; CAMLreturn(ret); } CAMLprim value caml_taglib_id3v2_header_len(value unit) { CAMLparam0(); CAMLreturn(Val_int(ID3v2::Header::size())); } #include #include CAMLprim value caml_taglib_id3v2_parse_header(value t, value h) { CAMLparam2(t, h); myId3v2 *tag = Id3v2_tag_val(t); tag->header()->setData(ByteVector(String_val(h), caml_string_length(h))); CAMLreturn(Val_unit); } CAMLprim value caml_taglib_id3v2_tag_size(value t) { CAMLparam1(t); myId3v2 *tag = Id3v2_tag_val(t); CAMLreturn(Val_int(tag->header()->completeTagSize())); } CAMLprim value caml_taglib_id3v2_parse_tag(value t, value h) { CAMLparam2(t, h); myId3v2 *tag = Id3v2_tag_val(t); const char *s = String_val(h); TagLib::uint size = ID3v2::Header::size(); tag->doParse(ByteVector(s + size, caml_string_length(h) - size)); CAMLreturn(Val_unit); } CAMLprim value caml_taglib_id3v2_render(value t) { CAMLparam1(t); CAMLlocal1(ret); myId3v2 *tag = Id3v2_tag_val(t); ByteVector r = tag->render(); ret = caml_alloc_string(r.size()); #ifdef CAML_SAFE_STRING memcpy(Bytes_val(ret), r.data(), r.size()); #else memcpy(String_val(ret), r.data(), r.size()); #endif CAMLreturn(ret); } CAMLprim value caml_taglib_id3v2_attach_frame(value t, value l, value c) { CAMLparam3(t, l, c); myId3v2 *tag = Id3v2_tag_val(t); ByteVector label = ByteVector(String_val(l)); ID3v2::TextIdentificationFrame *frame = new ID3v2::TextIdentificationFrame(label, TagLib::String::UTF8); frame->setText(TagLib::String(String_val(c))); tag->addFrame(frame); CAMLreturn(Val_unit); } ocaml-taglib-0.3.10/taglib.opam000066400000000000000000000016171431263464700162650ustar00rootroot00000000000000# This file is generated by dune, edit dune-project instead opam-version: "2.0" version: "0.3.10" synopsis: "Bindings for the taglib library" description: "Bindings for the taglib library which provides functions for reading tags in headers of audio files" maintainer: ["The Savonet Team "] authors: ["The Savonet Team "] license: "LGPL-2.1-only WITH OCaml-LGPL-linking-exception" homepage: "https://github.com/savonet/ocaml-taglib" bug-reports: "https://github.com/savonet/ocaml-taglib/issues" depends: [ "dune" {>= "2.8"} "ocaml" {>= "4.07"} "conf-taglib" "dune-configurator" "odoc" {with-doc} ] build: [ ["dune" "subst"] {dev} [ "dune" "build" "-p" name "-j" jobs "@install" "@runtest" {with-test} "@doc" {with-doc} ] ] dev-repo: "git+https://github.com/savonet/ocaml-taglib.git"