Module: Pptx2Medias

Defined in:
lib/pptx2medias.rb

Constant Summary collapse

VERSION =
'0.0.2'

Class Method Summary collapse

Class Method Details

.extract(input) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/pptx2medias.rb', line 4

def self.extract(input)
  file_path = input.strip
  file_type = `file -b "#{file_path}"`
  file_ext = File.extname(file_path)

  puts "- Input file: #{file_path}"
  puts "- File type: #{file_type}"

  unless file_type.include?('PowerPoint') && file_ext == '.pptx'
    puts 'Input file is not a valid PPTX. Exiting...'
    return
  end

  puts 'Input file is a PowerPoint presentation. Processing...'

  dir = File.dirname(file_path)
  basename = File.basename(file_path, file_ext)

  system("cp \"#{file_path}\" \"#{dir}/archive.zip\"")
  system("unzip \"#{dir}/archive.zip\" ppt/media/* -d #{dir}")
  system("mv \"#{dir}/ppt/media\" \"#{dir}/#{basename}_media\"")

  medias_count = `ls -1 \"#{dir}/#{basename}_media\" | wc -l`.strip.to_i
  videos_count = `ls -1 \"#{dir}/#{basename}_media\" | grep .mp4 | wc -l`.strip.to_i

  puts "File has been processed. Found #{medias_count} medias (including #{videos_count} videos). Cleaning..."

  system("rmdir \"#{dir}/ppt\"")
  system("rm \"#{dir}/archive.zip\"")

  puts "Done!"
end