libis-format 1.2.9 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/Gemfile +2 -0
 - data/data/types.yml +1 -1
 - data/lib/libis/format/command_line.rb +2 -3
 - data/lib/libis/format/config.rb +18 -19
 - data/lib/libis/format/converter/base.rb +9 -16
 - data/lib/libis/format/converter/chain.rb +36 -28
 - data/lib/libis/format/converter/email_converter.rb +5 -8
 - data/lib/libis/format/converter/fop_pdf_converter.rb +4 -6
 - data/lib/libis/format/converter/image_converter.rb +51 -58
 - data/lib/libis/format/converter/jp2_converter.rb +33 -35
 - data/lib/libis/format/converter/office_converter.rb +19 -23
 - data/lib/libis/format/converter/pdf_converter.rb +22 -28
 - data/lib/libis/format/converter/repository.rb +7 -13
 - data/lib/libis/format/converter/spreadsheet_converter.rb +7 -11
 - data/lib/libis/format/converter/video_converter.rb +41 -55
 - data/lib/libis/format/converter/xslt_converter.rb +14 -13
 - data/lib/libis/format/converter.rb +1 -1
 - data/lib/libis/format/identifier.rb +41 -43
 - data/lib/libis/format/tool/droid.rb +29 -30
 - data/lib/libis/format/tool/ff_mpeg.rb +11 -13
 - data/lib/libis/format/tool/fido.rb +1 -1
 - data/lib/libis/format/tool/pdf_copy.rb +17 -18
 - data/lib/libis/format/tool/pdf_merge.rb +17 -17
 - data/lib/libis/format/tool/pdf_optimizer.rb +18 -20
 - data/lib/libis/format/tool/spreadsheet_to_ods.rb +23 -20
 - data/lib/libis/format/tool.rb +2 -2
 - data/lib/libis/format/type_database.rb +51 -28
 - data/lib/libis/format/type_database_impl.rb +57 -24
 - data/lib/libis/format/version.rb +1 -1
 - data/lib/libis/format.rb +3 -2
 - data/lib/libis-format.rb +2 -0
 - metadata +3 -3
 
| 
         @@ -1,4 +1,5 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            #  
     | 
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       2 
3 
     | 
    
         
             
            require 'libis-tools'
         
     | 
| 
       3 
4 
     | 
    
         
             
            require 'fileutils'
         
     | 
| 
       4 
5 
     | 
    
         
             
            require 'libis/format/config'
         
     | 
| 
         @@ -7,32 +8,31 @@ require_relative 'base' 
     | 
|
| 
       7 
8 
     | 
    
         
             
            module Libis
         
     | 
| 
       8 
9 
     | 
    
         
             
              module Format
         
     | 
| 
       9 
10 
     | 
    
         
             
                module Converter
         
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
11 
     | 
    
         
             
                  class Jp2Converter < Libis::Format::Converter::Base
         
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
12 
     | 
    
         
             
                    def self.input_types
         
     | 
| 
       14 
     | 
    
         
            -
                      [ 
     | 
| 
      
 13 
     | 
    
         
            +
                      %i[TIFF JPG PNG BMP GIF PDF]
         
     | 
| 
       15 
14 
     | 
    
         
             
                    end
         
     | 
| 
       16 
15 
     | 
    
         | 
| 
       17 
16 
     | 
    
         
             
                    def self.output_types(format = nil)
         
     | 
| 
       18 
17 
     | 
    
         
             
                      return [] unless input_types.include?(format)
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
       19 
19 
     | 
    
         
             
                      [:JP2]
         
     | 
| 
       20 
20 
     | 
    
         
             
                    end
         
     | 
| 
       21 
21 
     | 
    
         | 
| 
       22 
22 
     | 
    
         
             
                    def initialize
         
     | 
| 
       23 
23 
     | 
    
         
             
                      super
         
     | 
| 
       24 
24 
     | 
    
         
             
                      @options = {
         
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
      
 25 
     | 
    
         
            +
                        color_xform: false,
         
     | 
| 
      
 26 
     | 
    
         
            +
                        error_resilience: :ALL,
         
     | 
| 
      
 27 
     | 
    
         
            +
                        lossless: true,
         
     | 
| 
      
 28 
     | 
    
         
            +
                        progression_order: 'RLCP',
         
     | 
| 
      
 29 
     | 
    
         
            +
                        tile_size: [1024, 1024],
         
     | 
| 
      
 30 
     | 
    
         
            +
                        codeblock_size: [6, 6]
         
     | 
| 
       31 
31 
     | 
    
         
             
                      }
         
     | 
| 
       32 
32 
     | 
    
         
             
                    end
         
     | 
| 
       33 
33 
     | 
    
         | 
| 
       34 
34 
     | 
    
         
             
                    def j2kdriver(_)
         
     | 
| 
       35 
     | 
    
         
            -
                      #force usage of this converter
         
     | 
| 
      
 35 
     | 
    
         
            +
                      # force usage of this converter
         
     | 
| 
       36 
36 
     | 
    
         
             
                    end
         
     | 
| 
       37 
37 
     | 
    
         | 
| 
       38 
38 
     | 
    
         
             
                    def color_xform(flag = true)
         
     | 
| 
         @@ -68,38 +68,36 @@ module Libis 
     | 
|
| 
       68 
68 
     | 
    
         | 
| 
       69 
69 
     | 
    
         
             
                      @options.each do |key, value|
         
     | 
| 
       70 
70 
     | 
    
         
             
                        case key
         
     | 
| 
       71 
     | 
    
         
            -
             
     | 
| 
       72 
     | 
    
         
            -
             
     | 
| 
       73 
     | 
    
         
            -
             
     | 
| 
       74 
     | 
    
         
            -
             
     | 
| 
       75 
     | 
    
         
            -
             
     | 
| 
       76 
     | 
    
         
            -
             
     | 
| 
       77 
     | 
    
         
            -
             
     | 
| 
       78 
     | 
    
         
            -
                            else
         
     | 
| 
       79 
     | 
    
         
            -
                              options << '--set-output-j2k-xform' << 'I97' << '--set-output-j2k-psnr' << '46'
         
     | 
| 
       80 
     | 
    
         
            -
                            end
         
     | 
| 
       81 
     | 
    
         
            -
                          when :progression_order
         
     | 
| 
       82 
     | 
    
         
            -
                            options << '--set-output-j2k-progression-order' << value.to_s
         
     | 
| 
       83 
     | 
    
         
            -
                          when :tile_size
         
     | 
| 
       84 
     | 
    
         
            -
                            options << '--set-output-j2k-tile-size' << value[0].to_s << value[1].to_s
         
     | 
| 
       85 
     | 
    
         
            -
                          when :codeblock_size
         
     | 
| 
       86 
     | 
    
         
            -
                            options << '--set-output-j2k-codeblock-size' << value[0].to_s << value[1].to_s
         
     | 
| 
      
 71 
     | 
    
         
            +
                        when :color_xform
         
     | 
| 
      
 72 
     | 
    
         
            +
                          options << '--set-output-j2k-color-xform' << (value ? 'YES' : 'NO')
         
     | 
| 
      
 73 
     | 
    
         
            +
                        when :error_resilience
         
     | 
| 
      
 74 
     | 
    
         
            +
                          options << '--set-output-j2k-error-resilience' << value.to_s
         
     | 
| 
      
 75 
     | 
    
         
            +
                        when :lossless
         
     | 
| 
      
 76 
     | 
    
         
            +
                          if value
         
     | 
| 
      
 77 
     | 
    
         
            +
                            options << '--set-output-j2k-xform' << 'R53' << '5' << '--set-output-j2k-ratio' << '0'
         
     | 
| 
       87 
78 
     | 
    
         
             
                          else
         
     | 
| 
       88 
     | 
    
         
            -
                             
     | 
| 
      
 79 
     | 
    
         
            +
                            options << '--set-output-j2k-xform' << 'I97' << '--set-output-j2k-psnr' << '46'
         
     | 
| 
      
 80 
     | 
    
         
            +
                          end
         
     | 
| 
      
 81 
     | 
    
         
            +
                        when :progression_order
         
     | 
| 
      
 82 
     | 
    
         
            +
                          options << '--set-output-j2k-progression-order' << value.to_s
         
     | 
| 
      
 83 
     | 
    
         
            +
                        when :tile_size
         
     | 
| 
      
 84 
     | 
    
         
            +
                          options << '--set-output-j2k-tile-size' << value[0].to_s << value[1].to_s
         
     | 
| 
      
 85 
     | 
    
         
            +
                        when :codeblock_size
         
     | 
| 
      
 86 
     | 
    
         
            +
                          options << '--set-output-j2k-codeblock-size' << value[0].to_s << value[1].to_s
         
     | 
| 
      
 87 
     | 
    
         
            +
                        else # rubocop:disable Style/EmptyElse
         
     | 
| 
      
 88 
     | 
    
         
            +
                          # do nothing
         
     | 
| 
       89 
89 
     | 
    
         
             
                        end
         
     | 
| 
       90 
90 
     | 
    
         
             
                      end
         
     | 
| 
       91 
91 
     | 
    
         | 
| 
       92 
     | 
    
         
            -
             
     | 
| 
       93 
92 
     | 
    
         
             
                      result = Libis::Tools::Command.run(
         
     | 
| 
       94 
     | 
    
         
            -
             
     | 
| 
       95 
     | 
    
         
            -
             
     | 
| 
       96 
     | 
    
         
            -
             
     | 
| 
       97 
     | 
    
         
            -
             
     | 
| 
       98 
     | 
    
         
            -
             
     | 
| 
      
 93 
     | 
    
         
            +
                        Libis::Format::Config[:j2k_cmd],
         
     | 
| 
      
 94 
     | 
    
         
            +
                        '--input-file-name', source,
         
     | 
| 
      
 95 
     | 
    
         
            +
                        '--set-output-type', 'JP2',
         
     | 
| 
      
 96 
     | 
    
         
            +
                        *options,
         
     | 
| 
      
 97 
     | 
    
         
            +
                        '--output-file-name', target
         
     | 
| 
       99 
98 
     | 
    
         
             
                      )
         
     | 
| 
       100 
99 
     | 
    
         | 
| 
       101 
100 
     | 
    
         
             
                      result.merge(files: [target], converter: self.class.name)
         
     | 
| 
       102 
     | 
    
         
            -
             
     | 
| 
       103 
101 
     | 
    
         
             
                    end
         
     | 
| 
       104 
102 
     | 
    
         
             
                  end
         
     | 
| 
       105 
103 
     | 
    
         
             
                end
         
     | 
| 
         @@ -1,4 +1,4 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            #  
     | 
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            require_relative 'base'
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
         @@ -8,47 +8,43 @@ require 'libis/format/type_database' 
     | 
|
| 
       8 
8 
     | 
    
         
             
            module Libis
         
     | 
| 
       9 
9 
     | 
    
         
             
              module Format
         
     | 
| 
       10 
10 
     | 
    
         
             
                module Converter
         
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
11 
     | 
    
         
             
                  class OfficeConverter < Libis::Format::Converter::Base
         
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
12 
     | 
    
         
             
                    def self.input_types
         
     | 
| 
       15 
     | 
    
         
            -
                      [
         
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
      
 13 
     | 
    
         
            +
                      %i[
         
     | 
| 
      
 14 
     | 
    
         
            +
                        TXT
         
     | 
| 
      
 15 
     | 
    
         
            +
                        RTF
         
     | 
| 
      
 16 
     | 
    
         
            +
                        HTML
         
     | 
| 
      
 17 
     | 
    
         
            +
                        MSDOC
         
     | 
| 
      
 18 
     | 
    
         
            +
                        MSDOT
         
     | 
| 
      
 19 
     | 
    
         
            +
                        MSXLS
         
     | 
| 
      
 20 
     | 
    
         
            +
                        MSPPT
         
     | 
| 
      
 21 
     | 
    
         
            +
                        MSDOCX
         
     | 
| 
      
 22 
     | 
    
         
            +
                        MSDOTX
         
     | 
| 
      
 23 
     | 
    
         
            +
                        MSXLSX
         
     | 
| 
      
 24 
     | 
    
         
            +
                        MSPPTX
         
     | 
| 
      
 25 
     | 
    
         
            +
                        WORDPERFECT
         
     | 
| 
      
 26 
     | 
    
         
            +
                        OO_WRITER
         
     | 
| 
      
 27 
     | 
    
         
            +
                        OO_IMPRESS
         
     | 
| 
      
 28 
     | 
    
         
            +
                        OO_CALC
         
     | 
| 
       31 
29 
     | 
    
         
             
                      ]
         
     | 
| 
       32 
30 
     | 
    
         
             
                    end
         
     | 
| 
       33 
31 
     | 
    
         | 
| 
       34 
32 
     | 
    
         
             
                    def self.output_types(format = nil)
         
     | 
| 
       35 
33 
     | 
    
         
             
                      return [] unless input_types.include?(format)
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
       36 
35 
     | 
    
         
             
                      [:PDF]
         
     | 
| 
       37 
36 
     | 
    
         
             
                    end
         
     | 
| 
       38 
37 
     | 
    
         | 
| 
       39 
38 
     | 
    
         
             
                    def office_convert(_)
         
     | 
| 
       40 
     | 
    
         
            -
                      #force usage of this converter
         
     | 
| 
      
 39 
     | 
    
         
            +
                      # force usage of this converter
         
     | 
| 
       41 
40 
     | 
    
         
             
                    end
         
     | 
| 
       42 
41 
     | 
    
         | 
| 
       43 
42 
     | 
    
         
             
                    def convert(source, target, format, opts = {})
         
     | 
| 
       44 
43 
     | 
    
         
             
                      super
         
     | 
| 
       45 
44 
     | 
    
         | 
| 
       46 
45 
     | 
    
         
             
                      Format::Tool::OfficeToPdf.run(source, target)
         
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
       48 
46 
     | 
    
         
             
                    end
         
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
47 
     | 
    
         
             
                  end
         
     | 
| 
       51 
     | 
    
         
            -
             
     | 
| 
       52 
48 
     | 
    
         
             
                end
         
     | 
| 
       53 
49 
     | 
    
         
             
              end
         
     | 
| 
       54 
50 
     | 
    
         
             
            end
         
     | 
| 
         @@ -1,4 +1,4 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            #  
     | 
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            require_relative 'base'
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
         @@ -11,20 +11,19 @@ require 'libis/format/tool/pdf_optimizer' 
     | 
|
| 
       11 
11 
     | 
    
         
             
            module Libis
         
     | 
| 
       12 
12 
     | 
    
         
             
              module Format
         
     | 
| 
       13 
13 
     | 
    
         
             
                module Converter
         
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
14 
     | 
    
         
             
                  class PdfConverter < Libis::Format::Converter::Base
         
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
15 
     | 
    
         
             
                    def self.input_types
         
     | 
| 
       18 
16 
     | 
    
         
             
                      [:PDF]
         
     | 
| 
       19 
17 
     | 
    
         
             
                    end
         
     | 
| 
       20 
18 
     | 
    
         | 
| 
       21 
19 
     | 
    
         
             
                    def self.output_types(format = nil)
         
     | 
| 
       22 
20 
     | 
    
         
             
                      return [] unless input_types.include?(format)
         
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
                      %i[PDF PDFA]
         
     | 
| 
       24 
23 
     | 
    
         
             
                    end
         
     | 
| 
       25 
24 
     | 
    
         | 
| 
       26 
25 
     | 
    
         
             
                    def pdf_convert(_)
         
     | 
| 
       27 
     | 
    
         
            -
                      #force usage of this converter
         
     | 
| 
      
 26 
     | 
    
         
            +
                      # force usage of this converter
         
     | 
| 
       28 
27 
     | 
    
         
             
                    end
         
     | 
| 
       29 
28 
     | 
    
         | 
| 
       30 
29 
     | 
    
         
             
                    # Set metadata for Pdf file
         
     | 
| 
         @@ -40,7 +39,8 @@ module Libis 
     | 
|
| 
       40 
39 
     | 
    
         
             
                    def metadata(values = {})
         
     | 
| 
       41 
40 
     | 
    
         
             
                      values.key_strings_to_symbols!
         
     | 
| 
       42 
41 
     | 
    
         
             
                      values.each do |k, v|
         
     | 
| 
       43 
     | 
    
         
            -
                        next unless [ 
     | 
| 
      
 42 
     | 
    
         
            +
                        next unless %i[title author creator keywords subject].include?(k)
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
       44 
44 
     | 
    
         
             
                        @options["md_#{k}"] = v
         
     | 
| 
       45 
45 
     | 
    
         
             
                      end
         
     | 
| 
       46 
46 
     | 
    
         
             
                    end
         
     | 
| 
         @@ -59,7 +59,8 @@ module Libis 
     | 
|
| 
       59 
59 
     | 
    
         
             
                    #     - rotation: rotation of the watermark text (in degrees; integer number)
         
     | 
| 
       60 
60 
     | 
    
         
             
                    #     - size: font size of the watermark text
         
     | 
| 
       61 
61 
     | 
    
         
             
                    #     - opacity: opacity of the watermark (fraction 0.0 - 1.0)
         
     | 
| 
       62 
     | 
    
         
            -
                    #     - gap: size of the gap between watermark instances. Integer value is absolute size in points (1/72 inch). 
     | 
| 
      
 62 
     | 
    
         
            +
                    #     - gap: size of the gap between watermark instances. Integer value is absolute size in points (1/72 inch).
         
     | 
| 
      
 63 
     | 
    
         
            +
                    #            Fractions are percentage of widht/height.
         
     | 
| 
       63 
64 
     | 
    
         
             
                    # If both options are given, the file will be used as-is if it exists and is a valid image file. Otherwise the
         
     | 
| 
       64 
65 
     | 
    
         
             
                    # file will be created or overwritten with a newly created watermark image.
         
     | 
| 
       65 
66 
     | 
    
         
             
                    #
         
     | 
| 
         @@ -96,7 +97,7 @@ module Libis 
     | 
|
| 
       96 
97 
     | 
    
         
             
                    #
         
     | 
| 
       97 
98 
     | 
    
         
             
                    # @param [Integer] setting quality setting. [0-4]
         
     | 
| 
       98 
99 
     | 
    
         
             
                    def optimize(setting = 1)
         
     | 
| 
       99 
     | 
    
         
            -
                      @options['optimize'] = %w 
     | 
| 
      
 100 
     | 
    
         
            +
                      @options['optimize'] = %w[screen ebook default printer prepress][setting] if (0..4).include?(setting)
         
     | 
| 
       100 
101 
     | 
    
         
             
                    end
         
     | 
| 
       101 
102 
     | 
    
         | 
| 
       102 
103 
     | 
    
         
             
                    def convert(source, target, format, opts = {})
         
     | 
| 
         @@ -107,31 +108,29 @@ module Libis 
     | 
|
| 
       107 
108 
     | 
    
         
             
                      if (quality = @options.delete('optimize'))
         
     | 
| 
       108 
109 
     | 
    
         
             
                        result = optimize_pdf(source, target, quality)
         
     | 
| 
       109 
110 
     | 
    
         
             
                        return nil unless result
         
     | 
| 
      
 111 
     | 
    
         
            +
             
     | 
| 
       110 
112 
     | 
    
         
             
                        source = result
         
     | 
| 
       111 
113 
     | 
    
         
             
                      end
         
     | 
| 
       112 
114 
     | 
    
         | 
| 
       113 
115 
     | 
    
         
             
                      unless @options.empty?
         
     | 
| 
       114 
116 
     | 
    
         
             
                        result = convert_pdf(source, target)
         
     | 
| 
       115 
117 
     | 
    
         
             
                        return nil unless result
         
     | 
| 
      
 118 
     | 
    
         
            +
             
     | 
| 
       116 
119 
     | 
    
         
             
                        source = result
         
     | 
| 
       117 
120 
     | 
    
         
             
                      end
         
     | 
| 
       118 
121 
     | 
    
         | 
| 
       119 
     | 
    
         
            -
                      if format == :PDFA  
     | 
| 
       120 
     | 
    
         
            -
                        result = pdf_to_pdfa(source, target)
         
     | 
| 
       121 
     | 
    
         
            -
                      end
         
     | 
| 
      
 122 
     | 
    
         
            +
                      result = pdf_to_pdfa(source, target) if (format == :PDFA) && source
         
     | 
| 
       122 
123 
     | 
    
         | 
| 
       123 
     | 
    
         
            -
                      { 
     | 
| 
      
 124 
     | 
    
         
            +
                      {
         
     | 
| 
       124 
125 
     | 
    
         
             
                        files: [result],
         
     | 
| 
       125 
126 
     | 
    
         
             
                        converter: self.class.name
         
     | 
| 
       126 
127 
     | 
    
         
             
                      }
         
     | 
| 
       127 
     | 
    
         
            -
             
     | 
| 
       128 
128 
     | 
    
         
             
                    end
         
     | 
| 
       129 
129 
     | 
    
         | 
| 
       130 
130 
     | 
    
         
             
                    def optimize_pdf(source, target, quality)
         
     | 
| 
       131 
     | 
    
         
            -
             
     | 
| 
       132 
131 
     | 
    
         
             
                      using_temp(target) do |tmpname|
         
     | 
| 
       133 
132 
     | 
    
         
             
                        result = Libis::Format::Tool::PdfOptimizer.run(source, tmpname, quality)
         
     | 
| 
       134 
     | 
    
         
            -
                        unless result[:status] 
     | 
| 
      
 133 
     | 
    
         
            +
                        unless (result[:status]).zero?
         
     | 
| 
       135 
134 
     | 
    
         
             
                          error("Pdf optimization encountered errors:\n%s", (result[:err] + result[:out]).join("\n"))
         
     | 
| 
       136 
135 
     | 
    
         
             
                          next nil
         
     | 
| 
       137 
136 
     | 
    
         
             
                        end
         
     | 
| 
         @@ -140,16 +139,16 @@ module Libis 
     | 
|
| 
       140 
139 
     | 
    
         
             
                    end
         
     | 
| 
       141 
140 
     | 
    
         | 
| 
       142 
141 
     | 
    
         
             
                    def convert_pdf(source, target)
         
     | 
| 
       143 
     | 
    
         
            -
             
     | 
| 
       144 
142 
     | 
    
         
             
                      using_temp(target) do |tmpname|
         
     | 
| 
       145 
143 
     | 
    
         
             
                        result = Libis::Format::Tool::PdfCopy.run(
         
     | 
| 
       146 
     | 
    
         
            -
             
     | 
| 
       147 
     | 
    
         
            -
             
     | 
| 
       148 
     | 
    
         
            -
             
     | 
| 
       149 
     | 
    
         
            -
             
     | 
| 
       150 
     | 
    
         
            -
             
     | 
| 
       151 
     | 
    
         
            -
             
     | 
| 
       152 
     | 
    
         
            -
             
     | 
| 
      
 144 
     | 
    
         
            +
                          source, tmpname,
         
     | 
| 
      
 145 
     | 
    
         
            +
                          @options.map do |k, v|
         
     | 
| 
      
 146 
     | 
    
         
            +
                            if v.nil?
         
     | 
| 
      
 147 
     | 
    
         
            +
                              nil
         
     | 
| 
      
 148 
     | 
    
         
            +
                            else
         
     | 
| 
      
 149 
     | 
    
         
            +
                              ["--#{k}", (v.is_a?(Array) ? v : v.to_s)]
         
     | 
| 
      
 150 
     | 
    
         
            +
                            end
         
     | 
| 
      
 151 
     | 
    
         
            +
                          end.flatten
         
     | 
| 
       153 
152 
     | 
    
         
             
                        )
         
     | 
| 
       154 
153 
     | 
    
         
             
                        unless result[:err].empty?
         
     | 
| 
       155 
154 
     | 
    
         
             
                          error("Pdf conversion encountered errors:\n%s", result[:err].join(join("\n")))
         
     | 
| 
         @@ -157,11 +156,9 @@ module Libis 
     | 
|
| 
       157 
156 
     | 
    
         
             
                        end
         
     | 
| 
       158 
157 
     | 
    
         
             
                        tmpname
         
     | 
| 
       159 
158 
     | 
    
         
             
                      end
         
     | 
| 
       160 
     | 
    
         
            -
             
     | 
| 
       161 
159 
     | 
    
         
             
                    end
         
     | 
| 
       162 
160 
     | 
    
         | 
| 
       163 
161 
     | 
    
         
             
                    def pdf_to_pdfa(source, target)
         
     | 
| 
       164 
     | 
    
         
            -
             
     | 
| 
       165 
162 
     | 
    
         
             
                      using_temp(target) do |tmpname|
         
     | 
| 
       166 
163 
     | 
    
         
             
                        result = Libis::Format::Tool::PdfToPdfa.run source, tmpname
         
     | 
| 
       167 
164 
     | 
    
         | 
| 
         @@ -177,11 +174,8 @@ module Libis 
     | 
|
| 
       177 
174 
     | 
    
         
             
                        end
         
     | 
| 
       178 
175 
     | 
    
         
             
                        tmpname
         
     | 
| 
       179 
176 
     | 
    
         
             
                      end
         
     | 
| 
       180 
     | 
    
         
            -
             
     | 
| 
       181 
177 
     | 
    
         
             
                    end
         
     | 
| 
       182 
     | 
    
         
            -
             
     | 
| 
       183 
178 
     | 
    
         
             
                  end
         
     | 
| 
       184 
     | 
    
         
            -
             
     | 
| 
       185 
179 
     | 
    
         
             
                end
         
     | 
| 
       186 
180 
     | 
    
         
             
              end
         
     | 
| 
       187 
181 
     | 
    
         
             
            end
         
     | 
| 
         @@ -1,6 +1,5 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            #  
     | 
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
     | 
    
         
            -
            require 'set'
         
     | 
| 
       4 
3 
     | 
    
         
             
            require 'singleton'
         
     | 
| 
       5 
4 
     | 
    
         | 
| 
       6 
5 
     | 
    
         
             
            require 'libis/tools/logger'
         
     | 
| 
         @@ -11,7 +10,6 @@ require_relative 'chain' 
     | 
|
| 
       11 
10 
     | 
    
         
             
            module Libis
         
     | 
| 
       12 
11 
     | 
    
         
             
              module Format
         
     | 
| 
       13 
12 
     | 
    
         
             
                module Converter
         
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
13 
     | 
    
         
             
                  class Repository
         
     | 
| 
       16 
14 
     | 
    
         
             
                    include Singleton
         
     | 
| 
       17 
15 
     | 
    
         
             
                    include ::Libis::Tools::Logger
         
     | 
| 
         @@ -24,15 +22,15 @@ module Libis 
     | 
|
| 
       24 
22 
     | 
    
         
             
                      @converters_glob = File.join(File.dirname(__FILE__), '*_converter.rb')
         
     | 
| 
       25 
23 
     | 
    
         
             
                    end
         
     | 
| 
       26 
24 
     | 
    
         | 
| 
       27 
     | 
    
         
            -
                    def  
     | 
| 
      
 25 
     | 
    
         
            +
                    def self.register(converter_class)
         
     | 
| 
       28 
26 
     | 
    
         
             
                      instance.converters.add? converter_class
         
     | 
| 
       29 
27 
     | 
    
         
             
                    end
         
     | 
| 
       30 
28 
     | 
    
         | 
| 
       31 
     | 
    
         
            -
                    def  
     | 
| 
      
 29 
     | 
    
         
            +
                    def self.get_converters # rubocop:disable Naming/AccessorMethodName
         
     | 
| 
       32 
30 
     | 
    
         
             
                      instance.get_converters
         
     | 
| 
       33 
31 
     | 
    
         
             
                    end
         
     | 
| 
       34 
32 
     | 
    
         | 
| 
       35 
     | 
    
         
            -
                    def get_converters
         
     | 
| 
      
 33 
     | 
    
         
            +
                    def get_converters # rubocop:disable Naming/AccessorMethodName
         
     | 
| 
       36 
34 
     | 
    
         
             
                      if converters.empty?
         
     | 
| 
       37 
35 
     | 
    
         
             
                        Dir.glob(converters_glob).each do |filename|
         
     | 
| 
       38 
36 
     | 
    
         
             
                          # noinspection RubyResolve
         
     | 
| 
         @@ -42,12 +40,12 @@ module Libis 
     | 
|
| 
       42 
40 
     | 
    
         
             
                      converters
         
     | 
| 
       43 
41 
     | 
    
         
             
                    end
         
     | 
| 
       44 
42 
     | 
    
         | 
| 
       45 
     | 
    
         
            -
                    def  
     | 
| 
      
 43 
     | 
    
         
            +
                    def self.get_converter_chain(src_type, tgt_type, operations = {})
         
     | 
| 
       46 
44 
     | 
    
         
             
                      instance.get_converter_chain src_type, tgt_type, operations
         
     | 
| 
       47 
45 
     | 
    
         
             
                    end
         
     | 
| 
       48 
46 
     | 
    
         | 
| 
       49 
47 
     | 
    
         
             
                    def get_converter_chain(src_type, tgt_type, operations = {})
         
     | 
| 
       50 
     | 
    
         
            -
                      msg = "conversion from #{src_type 
     | 
| 
      
 48 
     | 
    
         
            +
                      msg = "conversion from #{src_type} to #{tgt_type}"
         
     | 
| 
       51 
49 
     | 
    
         
             
                      chain_list = find_chains src_type, tgt_type, operations
         
     | 
| 
       52 
50 
     | 
    
         
             
                      # if chain_list.length > 1
         
     | 
| 
       53 
51 
     | 
    
         
             
                      #   warn "Found more than one conversion chain for #{msg}. Picking the first one."
         
     | 
| 
         @@ -70,7 +68,6 @@ module Libis 
     | 
|
| 
       70 
68 
     | 
    
         
             
                    end
         
     | 
| 
       71 
69 
     | 
    
         | 
| 
       72 
70 
     | 
    
         
             
                    def build_chains(chain)
         
     | 
| 
       73 
     | 
    
         
            -
             
     | 
| 
       74 
71 
     | 
    
         
             
                      found = []
         
     | 
| 
       75 
72 
     | 
    
         
             
                      chains = [chain]
         
     | 
| 
       76 
73 
     | 
    
         | 
| 
         @@ -81,18 +78,15 @@ module Libis 
     | 
|
| 
       81 
78 
     | 
    
         
             
                          new_chains += chains.map { |c| c.append(converter) }.flatten
         
     | 
| 
       82 
79 
     | 
    
         
             
                        end
         
     | 
| 
       83 
80 
     | 
    
         | 
| 
       84 
     | 
    
         
            -
                        found = new_chains.select 
     | 
| 
      
 81 
     | 
    
         
            +
                        found = new_chains.select(&:valid?)
         
     | 
| 
       85 
82 
     | 
    
         
             
                        return found unless found.empty?
         
     | 
| 
       86 
83 
     | 
    
         | 
| 
       87 
84 
     | 
    
         
             
                        chains = new_chains
         
     | 
| 
       88 
85 
     | 
    
         
             
                      end
         
     | 
| 
       89 
86 
     | 
    
         | 
| 
       90 
87 
     | 
    
         
             
                      found
         
     | 
| 
       91 
     | 
    
         
            -
             
     | 
| 
       92 
88 
     | 
    
         
             
                    end
         
     | 
| 
       93 
     | 
    
         
            -
             
     | 
| 
       94 
89 
     | 
    
         
             
                  end
         
     | 
| 
       95 
     | 
    
         
            -
             
     | 
| 
       96 
90 
     | 
    
         
             
                end
         
     | 
| 
       97 
91 
     | 
    
         
             
              end
         
     | 
| 
       98 
92 
     | 
    
         
             
            end
         
     | 
| 
         @@ -1,4 +1,4 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            #  
     | 
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            require_relative 'base'
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
         @@ -8,35 +8,31 @@ require 'libis/format/type_database' 
     | 
|
| 
       8 
8 
     | 
    
         
             
            module Libis
         
     | 
| 
       9 
9 
     | 
    
         
             
              module Format
         
     | 
| 
       10 
10 
     | 
    
         
             
                module Converter
         
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
11 
     | 
    
         
             
                  class SpreadsheetConverter < Libis::Format::Converter::Base
         
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
12 
     | 
    
         
             
                    def self.input_types
         
     | 
| 
       15 
     | 
    
         
            -
                      [
         
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
      
 13 
     | 
    
         
            +
                      %i[
         
     | 
| 
      
 14 
     | 
    
         
            +
                        MSXLS
         
     | 
| 
      
 15 
     | 
    
         
            +
                        MSXLSX
         
     | 
| 
      
 16 
     | 
    
         
            +
                        OO_CALC
         
     | 
| 
       19 
17 
     | 
    
         
             
                      ]
         
     | 
| 
       20 
18 
     | 
    
         
             
                    end
         
     | 
| 
       21 
19 
     | 
    
         | 
| 
       22 
20 
     | 
    
         
             
                    def self.output_types(format = nil)
         
     | 
| 
       23 
21 
     | 
    
         
             
                      return [] unless input_types.include?(format)
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
       24 
23 
     | 
    
         
             
                      [:OO_CALC]
         
     | 
| 
       25 
24 
     | 
    
         
             
                    end
         
     | 
| 
       26 
25 
     | 
    
         | 
| 
       27 
26 
     | 
    
         
             
                    def spreadsheet_convert(_)
         
     | 
| 
       28 
     | 
    
         
            -
                      #force usage of this converter
         
     | 
| 
      
 27 
     | 
    
         
            +
                      # force usage of this converter
         
     | 
| 
       29 
28 
     | 
    
         
             
                    end
         
     | 
| 
       30 
29 
     | 
    
         | 
| 
       31 
30 
     | 
    
         
             
                    def convert(source, target, format, opts = {})
         
     | 
| 
       32 
31 
     | 
    
         
             
                      super
         
     | 
| 
       33 
32 
     | 
    
         | 
| 
       34 
33 
     | 
    
         
             
                      Format::Tool::SpreadsheetToOds.run(source, target)
         
     | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
       36 
34 
     | 
    
         
             
                    end
         
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
       38 
35 
     | 
    
         
             
                  end
         
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
36 
     | 
    
         
             
                end
         
     | 
| 
       41 
37 
     | 
    
         
             
              end
         
     | 
| 
       42 
38 
     | 
    
         
             
            end
         
     | 
| 
         @@ -1,3 +1,5 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       1 
3 
     | 
    
         
             
            require_relative 'base'
         
     | 
| 
       2 
4 
     | 
    
         
             
            require 'libis/format/tool/ff_mpeg'
         
     | 
| 
       3 
5 
     | 
    
         | 
| 
         @@ -6,24 +8,19 @@ require 'fileutils' 
     | 
|
| 
       6 
8 
     | 
    
         
             
            module Libis
         
     | 
| 
       7 
9 
     | 
    
         
             
              module Format
         
     | 
| 
       8 
10 
     | 
    
         
             
                module Converter
         
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
11 
     | 
    
         
             
                  class VideoConverter < Libis::Format::Converter::Base
         
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
12 
     | 
    
         
             
                    def self.input_types
         
     | 
| 
       13 
     | 
    
         
            -
                      [ 
     | 
| 
      
 13 
     | 
    
         
            +
                      %i[WEBM MP4 MPG MKV MJP2 QTFF AVI OGGV WMV DV FLV SWF]
         
     | 
| 
       14 
14 
     | 
    
         
             
                    end
         
     | 
| 
       15 
15 
     | 
    
         | 
| 
       16 
16 
     | 
    
         
             
                    def self.output_types(format = nil)
         
     | 
| 
       17 
17 
     | 
    
         
             
                      return [] unless input_types.include?(format)
         
     | 
| 
       18 
     | 
    
         
            -
                      [:GIF, :WEBM, :MP4, :MPG, :MKV, :MJP2, :QTFF, :AVI, :OGGV, :WMV, :DV, :FLV, :SWF]
         
     | 
| 
       19 
     | 
    
         
            -
                    end
         
     | 
| 
       20 
18 
     | 
    
         | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
                      super
         
     | 
| 
      
 19 
     | 
    
         
            +
                      %i[GIF WEBM MP4 MPG MKV MJP2 QTFF AVI OGGV WMV DV FLV SWF]
         
     | 
| 
       23 
20 
     | 
    
         
             
                    end
         
     | 
| 
       24 
21 
     | 
    
         | 
| 
       25 
     | 
    
         
            -
                    def quiet( 
     | 
| 
       26 
     | 
    
         
            -
                      @flags[:quiet] = !! 
     | 
| 
      
 22 
     | 
    
         
            +
                    def quiet(value)
         
     | 
| 
      
 23 
     | 
    
         
            +
                      @flags[:quiet] = !!value
         
     | 
| 
       27 
24 
     | 
    
         
             
                    end
         
     | 
| 
       28 
25 
     | 
    
         | 
| 
       29 
26 
     | 
    
         
             
                    def format(format)
         
     | 
| 
         @@ -126,10 +123,10 @@ module Libis 
     | 
|
| 
       126 
123 
     | 
    
         | 
| 
       127 
124 
     | 
    
         
             
                    # @param [Boolean] value If set to true automatically selects optimal format for web viewing. Default: false
         
     | 
| 
       128 
125 
     | 
    
         
             
                    def web_stream(value)
         
     | 
| 
       129 
     | 
    
         
            -
                       
     | 
| 
       130 
     | 
    
         
            -
             
     | 
| 
       131 
     | 
    
         
            -
             
     | 
| 
       132 
     | 
    
         
            -
                       
     | 
| 
      
 126 
     | 
    
         
            +
                      return unless value
         
     | 
| 
      
 127 
     | 
    
         
            +
             
     | 
| 
      
 128 
     | 
    
         
            +
                      @options[:video_codec] = 'h264'
         
     | 
| 
      
 129 
     | 
    
         
            +
                      @options[:audio_codec] = 'acc'
         
     | 
| 
       133 
130 
     | 
    
         
             
                    end
         
     | 
| 
       134 
131 
     | 
    
         | 
| 
       135 
132 
     | 
    
         
             
                    # @param [String] name name of a preset. See FFMpeg documentation for more info
         
     | 
| 
         @@ -170,7 +167,7 @@ module Libis 
     | 
|
| 
       170 
167 
     | 
    
         | 
| 
       171 
168 
     | 
    
         
             
                      elsif File.directory?(source)
         
     | 
| 
       172 
169 
     | 
    
         | 
| 
       173 
     | 
    
         
            -
                        sources = Dir[File.join(source, '**', '*')].reject {|p| File.directory? p}
         
     | 
| 
      
 170 
     | 
    
         
            +
                        sources = Dir[File.join(source, '**', '*')].reject { |p| File.directory? p }
         
     | 
| 
       174 
171 
     | 
    
         
             
                        assemble_and_convert(sources, target)
         
     | 
| 
       175 
172 
     | 
    
         | 
| 
       176 
173 
     | 
    
         
             
                      else
         
     | 
| 
         @@ -183,14 +180,13 @@ module Libis 
     | 
|
| 
       183 
180 
     | 
    
         
             
                        files: [target],
         
     | 
| 
       184 
181 
     | 
    
         
             
                        converter: self.class.name
         
     | 
| 
       185 
182 
     | 
    
         
             
                      }
         
     | 
| 
       186 
     | 
    
         
            -
             
     | 
| 
       187 
183 
     | 
    
         
             
                    end
         
     | 
| 
       188 
184 
     | 
    
         | 
| 
       189 
185 
     | 
    
         
             
                    def assemble_and_convert(sources, target)
         
     | 
| 
       190 
     | 
    
         
            -
                      Tempfile.create(%w 
     | 
| 
       191 
     | 
    
         
            -
                        sources.each {|src| f.puts src}
         
     | 
| 
      
 186 
     | 
    
         
            +
                      Tempfile.create(%w[list .txt]) do |f|
         
     | 
| 
      
 187 
     | 
    
         
            +
                        sources.each { |src| f.puts src }
         
     | 
| 
       192 
188 
     | 
    
         
             
                        opts[:global] ||= []
         
     | 
| 
       193 
     | 
    
         
            -
                        opts[:global] += %w 
     | 
| 
      
 189 
     | 
    
         
            +
                        opts[:global] += %w[-f concat]
         
     | 
| 
       194 
190 
     | 
    
         
             
                        f.close
         
     | 
| 
       195 
191 
     | 
    
         
             
                        target = convert_file(f.to_path, target)
         
     | 
| 
       196 
192 
     | 
    
         
             
                      end
         
     | 
| 
         @@ -201,15 +197,15 @@ module Libis 
     | 
|
| 
       201 
197 
     | 
    
         | 
| 
       202 
198 
     | 
    
         
             
                    def convert_file(source, target)
         
     | 
| 
       203 
199 
     | 
    
         
             
                      # FLV special: only supports aac and speex audio codecs
         
     | 
| 
       204 
     | 
    
         
            -
                      format = (@options[:format] || File.extname(target)[1 
     | 
| 
       205 
     | 
    
         
            -
                      @options[:audio_codec] ||= 'aac' if %w 
     | 
| 
      
 200 
     | 
    
         
            +
                      format = (@options[:format] || File.extname(target)[1..]).to_s.downcase
         
     | 
| 
      
 201 
     | 
    
         
            +
                      @options[:audio_codec] ||= 'aac' if %w[flv].include?(format)
         
     | 
| 
       206 
202 
     | 
    
         | 
| 
       207 
203 
     | 
    
         
             
                      # SWF special: only supports mp3 audio codec
         
     | 
| 
       208 
     | 
    
         
            -
                      format = (@options[:format] || File.extname(target)[1 
     | 
| 
       209 
     | 
    
         
            -
                      @options[:audio_codec] ||= 'mp3' if %w 
     | 
| 
      
 204 
     | 
    
         
            +
                      format = (@options[:format] || File.extname(target)[1..]).to_s.downcase
         
     | 
| 
      
 205 
     | 
    
         
            +
                      @options[:audio_codec] ||= 'mp3' if %w[swf].include?(format)
         
     | 
| 
       210 
206 
     | 
    
         | 
| 
       211 
207 
     | 
    
         
             
                      # Set up FFMpeg command line parameters
         
     | 
| 
       212 
     | 
    
         
            -
                      opts = {global: [], input: [], filter: [], output: []}
         
     | 
| 
      
 208 
     | 
    
         
            +
                      opts = { global: [], input: [], filter: [], output: [] }
         
     | 
| 
       213 
209 
     | 
    
         
             
                      opts[:global] << '-hide_banner'
         
     | 
| 
       214 
210 
     | 
    
         
             
                      opts[:global] << '-loglevel' << (@options[:quiet] ? 'fatal' : 'warning')
         
     | 
| 
       215 
211 
     | 
    
         | 
| 
         @@ -217,29 +213,21 @@ module Libis 
     | 
|
| 
       217 
213 
     | 
    
         
             
                      @options[:watermark_opacity] ||= 0.5
         
     | 
| 
       218 
214 
     | 
    
         
             
                      if @options[:watermark_image]
         
     | 
| 
       219 
215 
     | 
    
         
             
                        opts[:filter] << '-i' << @options[:watermark_image] << '-filter_complex'
         
     | 
| 
       220 
     | 
    
         
            -
                        opts[:filter] <<  
     | 
| 
       221 
     | 
    
         
            -
             
     | 
| 
      
 216 
     | 
    
         
            +
                        opts[:filter] << Kernel.format('[1:v]format=argb,colorchannelmixer=aa=%f[wm];[0:v][wm]overlay=%s',
         
     | 
| 
      
 217 
     | 
    
         
            +
                                                       @options[:watermark_opacity], watermark_position_text)
         
     | 
| 
       222 
218 
     | 
    
         
             
                      elsif @options[:watermark_text]
         
     | 
| 
       223 
219 
     | 
    
         
             
                        @options[:watermark_text_size] ||= 10
         
     | 
| 
       224 
220 
     | 
    
         
             
                        @options[:watermark_text_color] ||= 'white'
         
     | 
| 
       225 
221 
     | 
    
         
             
                        @options[:watermark_text_shadow_color] ||= 'black'
         
     | 
| 
       226 
222 
     | 
    
         
             
                        @options[:watermark_text_shadow_offset] ||= 1
         
     | 
| 
       227 
     | 
    
         
            -
                        filter_text = "drawtext=text='%s':%s:fontfile=%s:fontsize=%d:fontcolor=%s@%f" 
     | 
| 
       228 
     | 
    
         
            -
             
     | 
| 
       229 
     | 
    
         
            -
             
     | 
| 
       230 
     | 
    
         
            -
             
     | 
| 
       231 
     | 
    
         
            -
             
     | 
| 
       232 
     | 
    
         
            -
             
     | 
| 
       233 
     | 
    
         
            -
             
     | 
| 
       234 
     | 
    
         
            -
             
     | 
| 
       235 
     | 
    
         
            -
                            ]
         
     | 
| 
       236 
     | 
    
         
            -
                        filter_text += ':shadowcolor=%s@%f:shadowx=%d:shadowy=%d' %
         
     | 
| 
       237 
     | 
    
         
            -
                            [
         
     | 
| 
       238 
     | 
    
         
            -
                                @options[:watermark_text_shadow_color],
         
     | 
| 
       239 
     | 
    
         
            -
                                @options[:watermark_opacity],
         
     | 
| 
       240 
     | 
    
         
            -
                                @options[:watermark_text_shadow_offset],
         
     | 
| 
       241 
     | 
    
         
            -
                                @options[:watermark_text_shadow_offset]
         
     | 
| 
       242 
     | 
    
         
            -
                            ] if @options[:watermark_text_shadow_offset] > 0
         
     | 
| 
      
 223 
     | 
    
         
            +
                        filter_text = Kernel.format("drawtext=text='%s':%s:fontfile=%s:fontsize=%d:fontcolor=%s@%f",
         
     | 
| 
      
 224 
     | 
    
         
            +
                                                    @options[:watermark_text], watermark_position_text(true), Config[:watermark_font],
         
     | 
| 
      
 225 
     | 
    
         
            +
                                                    @options[:watermark_text_size], @options[:watermark_text_color], @options[:watermark_opacity])
         
     | 
| 
      
 226 
     | 
    
         
            +
                        if (@options[:watermark_text_shadow_offset]).positive?
         
     | 
| 
      
 227 
     | 
    
         
            +
                          filter_text += Kernel.format(':shadowcolor=%s@%f:shadowx=%d:shadowy=%d',
         
     | 
| 
      
 228 
     | 
    
         
            +
                                                       @options[:watermark_text_shadow_color], @options[:watermark_opacity],
         
     | 
| 
      
 229 
     | 
    
         
            +
                                                       @options[:watermark_text_shadow_offset], @options[:watermark_text_shadow_offset])
         
     | 
| 
      
 230 
     | 
    
         
            +
                        end
         
     | 
| 
       243 
231 
     | 
    
         
             
                        opts[:filter] << '-vf' << filter_text
         
     | 
| 
       244 
232 
     | 
    
         
             
                      end
         
     | 
| 
       245 
233 
     | 
    
         
             
                      opts[:output] << '-ac' << @options[:audio_channels] if @options[:audio_channels]
         
     | 
| 
         @@ -251,7 +239,7 @@ module Libis 
     | 
|
| 
       251 
239 
     | 
    
         
             
                      opts[:output] << '-map_metadata:g' << '0:g' # Copy global metadata
         
     | 
| 
       252 
240 
     | 
    
         
             
                      opts[:output] << '-map_metadata:s:a' << '0:s:a' # Copy audio metadata
         
     | 
| 
       253 
241 
     | 
    
         
             
                      opts[:output] << '-map_metadata:s:v' << '0:s:v' # Copy video metadata
         
     | 
| 
       254 
     | 
    
         
            -
                      opts[:input] << '-accurate_seek' << (@options[:start].to_i  
     | 
| 
      
 242 
     | 
    
         
            +
                      opts[:input] << '-accurate_seek' << (@options[:start].to_i.negative? ? '-sseof' : '-ss') << @options[:start] if @options[:start]
         
     | 
| 
       255 
243 
     | 
    
         
             
                      opts[:input] << '-t' << @options[:duration] if @options[:duration]
         
     | 
| 
       256 
244 
     | 
    
         
             
                      opts[:output] << '-qscale' << @options[:video_quality] if @options[:video_quality]
         
     | 
| 
       257 
245 
     | 
    
         
             
                      opts[:output] << '-q:a' << @options[:audio_quality] if @options[:audio_quality]
         
     | 
| 
         @@ -277,21 +265,19 @@ module Libis 
     | 
|
| 
       277 
265 
     | 
    
         
             
                      w = for_text ? 'tw' : 'w'
         
     | 
| 
       278 
266 
     | 
    
         
             
                      h = for_text ? 'th' : 'h'
         
     | 
| 
       279 
267 
     | 
    
         
             
                      case @options[:watermark_position]
         
     | 
| 
       280 
     | 
    
         
            -
             
     | 
| 
       281 
     | 
    
         
            -
             
     | 
| 
       282 
     | 
    
         
            -
             
     | 
| 
       283 
     | 
    
         
            -
             
     | 
| 
       284 
     | 
    
         
            -
             
     | 
| 
       285 
     | 
    
         
            -
             
     | 
| 
       286 
     | 
    
         
            -
             
     | 
| 
       287 
     | 
    
         
            -
             
     | 
| 
       288 
     | 
    
         
            -
             
     | 
| 
       289 
     | 
    
         
            -
             
     | 
| 
      
 268 
     | 
    
         
            +
                      when 'bottom_left'
         
     | 
| 
      
 269 
     | 
    
         
            +
                        "x=#{margin}:y=H-#{h}-#{margin}"
         
     | 
| 
      
 270 
     | 
    
         
            +
                      when 'top_left'
         
     | 
| 
      
 271 
     | 
    
         
            +
                        "x=#{margin}:y=#{margin}"
         
     | 
| 
      
 272 
     | 
    
         
            +
                      when 'bottom_right'
         
     | 
| 
      
 273 
     | 
    
         
            +
                        "x=W-#{w}-#{margin}:y=H-#{h}-#{margin}"
         
     | 
| 
      
 274 
     | 
    
         
            +
                      when 'top_right'
         
     | 
| 
      
 275 
     | 
    
         
            +
                        "x=W-#{w}-#{margin}:y=#{margin}"
         
     | 
| 
      
 276 
     | 
    
         
            +
                      else
         
     | 
| 
      
 277 
     | 
    
         
            +
                        "x=#{margin}:y=H-#{h}-#{margin}"
         
     | 
| 
       290 
278 
     | 
    
         
             
                      end
         
     | 
| 
       291 
279 
     | 
    
         
             
                    end
         
     | 
| 
       292 
     | 
    
         
            -
             
     | 
| 
       293 
280 
     | 
    
         
             
                  end
         
     | 
| 
       294 
     | 
    
         
            -
             
     | 
| 
       295 
281 
     | 
    
         
             
                end
         
     | 
| 
       296 
282 
     | 
    
         
             
              end
         
     | 
| 
       297 
     | 
    
         
            -
            end
         
     | 
| 
      
 283 
     | 
    
         
            +
            end
         
     |