1{ lib, stdenv, fetchurl, fetchpatch, substituteAll
2, libtool, gettext, zlib, bzip2, flac, libvorbis
3, exiv2, libgsf, pkg-config
4, rpmSupport ? stdenv.isLinux, rpm
5, gstreamerSupport ? true, gst_all_1
6# ^ Needed e.g. for proper id3 and FLAC support.
7# Set to `false` to decrease package closure size by about 87 MB (53%).
8, gstPlugins ? (gst: [ gst.gst-plugins-base gst.gst-plugins-good ])
9# If an application needs additional gstreamer plugins it can also make them
10# available by adding them to the environment variable
11# GST_PLUGIN_SYSTEM_PATH_1_0, e.g. like this:
12# postInstall = ''
13# wrapProgram $out/bin/extract --prefix GST_PLUGIN_SYSTEM_PATH_1_0 : "$GST_PLUGIN_SYSTEM_PATH_1_0"
14# '';
15# See also <https://nixos.org/nixpkgs/manual/#sec-language-gnome>.
16, gtkSupport ? true, glib, gtk3
17, videoSupport ? true, ffmpeg_4, libmpeg2
18}:
19
20stdenv.mkDerivation rec {
21 pname = "libextractor";
22 version = "1.11";
23
24 src = fetchurl {
25 url = "mirror://gnu/libextractor/${pname}-${version}.tar.gz";
26 sha256 = "sha256-FvYzq4dGo4VHxKHaP0WRGSsIJa2DxDNvBXW4WEPYvY8=";
27 };
28
29 patches = [
30 (fetchpatch {
31 name = "libextractor-exiv2-0.28.patch";
32 url = "https://git.pld-linux.org/?p=packages/libextractor.git;a=blob_plain;f=libextractor-exiv2-0.28.patch;h=d763b65f2578f1127713de8dc82f432d34f95a85;hb=0e7de1c6794e8c331a1a1a6a829993c7cd217d3a";
33 hash = "sha256-szAv2A+NmiQyj2+R7BO6fHX588vlTgljPtrnMR6mgGY=";
34 })
35 ] ++ lib.optionals gstreamerSupport [
36
37 # Libraries cannot be wrapped so we need to hardcode the plug-in paths.
38 (substituteAll {
39 src = ./gst-hardcode-plugins.patch;
40 load_gst_plugins = lib.concatMapStrings
41 (plugin: ''gst_registry_scan_path(gst_registry_get(), "${lib.getLib plugin}/lib/gstreamer-1.0");'')
42 (gstPlugins gst_all_1);
43 })
44 ];
45
46 preConfigure =
47 '' echo "patching installation directory in \`extractor.c'..."
48 sed -i "src/main/extractor.c" \
49 -e "s|pexe[[:blank:]]*=.*$|pexe = strdup(\"$out/lib/\");|g"
50 '';
51
52 nativeBuildInputs = [ pkg-config ];
53
54 buildInputs =
55 [ libtool gettext zlib bzip2 flac libvorbis exiv2
56 libgsf
57 ] ++ lib.optionals rpmSupport [ rpm ]
58 ++ lib.optionals gstreamerSupport
59 ([ gst_all_1.gstreamer ] ++ gstPlugins gst_all_1)
60 ++ lib.optionals gtkSupport [ glib gtk3 ]
61 ++ lib.optionals videoSupport [ ffmpeg_4 libmpeg2 ];
62
63 configureFlags = [
64 "--disable-ltdl-install"
65 "--with-ltdl-include=${libtool}/include"
66 "--with-ltdl-lib=${libtool.lib}/lib"
67 "--enable-xpdf"
68 ];
69
70 # Checks need to be run after "make install", otherwise plug-ins are not in
71 # the search path, etc.
72 doCheck = false;
73 doInstallCheck = !stdenv.isDarwin;
74 installCheckPhase = "make check";
75
76 meta = with lib; {
77 description = "Simple library for keyword extraction";
78
79 longDescription =
80 '' GNU libextractor is a library used to extract meta-data from files
81 of arbitrary type. It is designed to use helper-libraries to perform
82 the actual extraction, and to be trivially extendable by linking
83 against external extractors for additional file types.
84
85 The goal is to provide developers of file-sharing networks or
86 WWW-indexing bots with a universal library to obtain simple keywords
87 to match against queries. libextractor contains a shell-command
88 extract that, similar to the well-known file command, can extract
89 meta-data from a file an print the results to stdout.
90
91 Currently, libextractor supports the following formats: HTML, PDF,
92 PS, OLE2 (DOC, XLS, PPT), OpenOffice (sxw), StarOffice (sdw), DVI,
93 MAN, FLAC, MP3 (ID3v1 and ID3v2), NSF(E) (NES music), SID (C64
94 music), OGG, WAV, EXIV2, JPEG, GIF, PNG, TIFF, DEB, RPM, TAR(.GZ),
95 ZIP, ELF, S3M (Scream Tracker 3), XM (eXtended Module), IT (Impulse
96 Tracker), FLV, REAL, RIFF (AVI), MPEG, QT and ASF. Also, various
97 additional MIME types are detected.
98 '';
99
100 license = licenses.gpl3Plus;
101
102 maintainers = [ maintainers.jorsn ];
103 platforms = platforms.unix;
104 };
105}