diff --git a/Gemfile b/Gemfile index 5f59b34..2fce5d3 100644 --- a/Gemfile +++ b/Gemfile @@ -9,6 +9,8 @@ gem 'sqlite3', '~> 1.6' gem 'kramdown', '~> 2.4' +gem 'pandoc-ruby', '~> 2.1' + # Use rerun gem to auto-reload app gem 'rerun' diff --git a/Gemfile.lock b/Gemfile.lock index 83ed571..1d1fa73 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -11,6 +11,7 @@ GEM mustermann (3.0.0) ruby2_keywords (~> 0.0.1) nio4r (2.5.8) + pandoc-ruby (2.1.7) puma (6.1.1) nio4r (~> 2.0) rack (2.2.6.2) @@ -43,6 +44,7 @@ PLATFORMS DEPENDENCIES kramdown (~> 2.4) + pandoc-ruby (~> 2.1) puma (~> 6.1) rerun sequel (~> 5.66) diff --git a/lib/models/video.rb b/lib/models/video.rb index 224a3c2..951fdb9 100644 --- a/lib/models/video.rb +++ b/lib/models/video.rb @@ -1,4 +1,5 @@ require 'kramdown' +require 'pandoc-ruby' class Video < Sequel::Model @@ -21,4 +22,11 @@ class Video < Sequel::Model return Kramdown::Document.new(@values[:script]).to_html end + def importScript() + scripts = Dir.glob("#{@values[:directory_path]}/*Script.docx") + script_content = PandocRuby.convert([scripts[0].dump()], from: :docx, to: :markdown) + @values[:script] = script_content + self.save() + end + end diff --git a/scan.rb b/scan.rb index 53a931e..3f9afe9 100755 --- a/scan.rb +++ b/scan.rb @@ -21,7 +21,7 @@ unless ARGV.length == 1 end channel = Channel.where(name: ARGV[0]).first() -channel_dir = channel.directory_path +channel_dir = File.join(channel.directory_path, 'Main') subs = Dir["#{channel_dir}/*"] subs.each do |d| @@ -49,6 +49,8 @@ subs.each do |d| script: "# Introduction\n\n# Body\n\n# Conclusions" ) + video.importScript() + puts "Successfully added video ##{video.serial} - #{video.name} for channel '#{channel.name}' to the database." end end