vtt2an 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1d4e6633e56935f6c5f212ceb604a0cc0841b95e
4
+ data.tar.gz: 979fa966902bb0bed9da8e5e8e133fc121e0b928
5
+ SHA512:
6
+ metadata.gz: a5b446814967b4070b1bff0360322e5b8b0d4daef210e1bcf3cb3ae1a74a3d81fddc008d61991c4e8535f65a4f4b6439049af7fcc0c75827f218db2e80c7d765
7
+ data.tar.gz: 0fb9a3e3eeac3ca07af6ebaf6bc72e58ce7ee5457947ce061be75370e5bf6432d2a32d67c3bcb26ed517bb9a7b96c658b42942b734e9ad320b40b9cd9ca328b3
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
@@ -0,0 +1 @@
1
+ 2.3.1
@@ -0,0 +1,13 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.12.5
6
+ deploy:
7
+ provider: rubygems
8
+ api_key:
9
+ secure: Lm+6OZVuwMjtu3n1XiluIlvgLjgN1itJ59JVLoBC+XsMkUXPzYVi5XJA1SGp1RMtYoHauOsii5Mp3zJux828sUc/BulBB5OYqmYVA3+mFSsYH8yQnSDbBosbea4bgpnThBGk4l5kjbfk+yw+u8Z4YP2FOYLJgoDzYqKtSDSIE8D2rtRK96yp95oWCeN0XZE/5P8QrvEC6reEtdCPzybPfwP4jk3SGdYzxWF6CCS5Bv0CKihhfCVo+8eE9KQgO0mvlo5fdlFvLc5/xv9obrlJ5YSbEw9ujf1Nx+YFFWa+jfnWHLN7q0ubpGyu8wyM8Foo+BuQohP4ID18GdbZkm6Yf47Zz2nJP9cZY1DxFMIxXqClX1vURy4+DFHhsbG7n57FHjt/qAMOgCQrYfsBxRFHsfc9YyTHbcBiR7F3lTwXLZhnJYXNx/sgZQ+HpDKISXzDtyrRxzf2QBHCKJ2BCit0UDRLYUfO+Iz9+lDuXi3OIEBLHicuLiQAuyUGwuJtFqG3JgQg0qiWBl0ExonfNqkh9vOqroxNdmOXtTQszxBCLYlCWSslhGDybRsW3mEywF4LNFUsRGAO1dKnSOGMQWl4iHCqKD9rIy3+dNERhYQ/HtKrEIkQdH1T6ILSiERkDEJU++4yU8HFJAQ9UqXjfcChTzDqLViQkSlPF/gl7ngToOU=
10
+ gem: vtt2an
11
+ on:
12
+ tags: true
13
+ repo: Floppy/vtt2an
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at james@floppy.org.uk. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2016 James Smith
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,45 @@
1
+ # vtt2an
2
+
3
+ [![Build Status](http://img.shields.io/travis/Floppy/vtt2an.svg?style=flat-square)](https://travis-ci.org/Floppy/vtt2an)
4
+ [![Dependency Status](http://img.shields.io/gemnasium/github.com/Floppy/vtt2an.svg?style=flat-square)](https://gemnasium.com/github.com/Floppy/vtt2an)
5
+ [![Coverage Status](http://img.shields.io/coveralls/Floppy/vtt2an.svg?style=flat-square)](https://coveralls.io/r/Floppy/vtt2an)
6
+ [![Code Climate](http://img.shields.io/codeclimate/github/Floppy/vtt2an.svg?style=flat-square)](https://codeclimate.com/github/Floppy/vtt2an)
7
+ [![Gem Version](http://img.shields.io/gem/v/vtt2an.svg?style=flat-square)](https://rubygems.org/gems/vtt2an)
8
+ [![License](http://img.shields.io/:license-mit-blue.svg?style=flat-square)](http://Floppy.mit-license.org)
9
+
10
+ Convert WebVTT subtitles files into Akoma Ntoso transcripts.
11
+
12
+ ## Installation
13
+
14
+ Ruby 2.3.1 recommended, then:
15
+
16
+ `gem install vtt2an`
17
+
18
+ or add to your Gemfile:
19
+
20
+ `gem "vtt2an"`
21
+
22
+ and then
23
+
24
+ `bundle`
25
+
26
+ ## Usage
27
+
28
+ ### Ruby
29
+
30
+ Load a WebVTT file using [webvtt-ruby](https://github.com/opencoconut/webvtt-ruby), then convert it using `Vtt2An::Converter` to a `REXML::Document` in Akoma Ntoso format:
31
+
32
+ ```
33
+ webvtt = WebVTT.read "in.wtt"
34
+ converter = Vtt2An::Converter.new webvtt
35
+ output = converter.convert
36
+ File.open("out.an", "w") do |f|
37
+ output.write f
38
+ end
39
+ ```
40
+
41
+ ### Command line
42
+
43
+ If you just want to convert files, you can use the handy command-line tool:
44
+
45
+ `bundle exec exe/vtt2an.rb /path/to/file.vtt /path/to/output.an`
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'vtt2an'
5
+
6
+ # Read the subtitle file
7
+ webvtt = WebVTT.read(ARGV[0])
8
+ # Convert
9
+ converter = Vtt2An::Converter.new(webvtt)
10
+ output = converter.convert
11
+ # Write output to file
12
+ File.open(ARGV[1], "w") do |f|
13
+ output.write(f, 1)
14
+ end
@@ -0,0 +1,9 @@
1
+ require "webvtt"
2
+
3
+ # Monkeypatch WebVTT
4
+ # We'll push this upstream at some point
5
+ require "vtt2an/webvtt/file"
6
+ require "vtt2an/webvtt/cue"
7
+
8
+ # require vtt2an files
9
+ require "vtt2an/converter"
@@ -0,0 +1,48 @@
1
+ require 'active_support/inflector'
2
+ require 'rexml/document'
3
+
4
+ module Vtt2An
5
+
6
+ class Converter
7
+
8
+ attr_accessor :webvtt
9
+
10
+ def initialize(webvtt)
11
+ @webvtt = webvtt
12
+ end
13
+
14
+ def convert
15
+
16
+ output = REXML::Document.new
17
+ an = output.add_element("akomaNtoso")
18
+ debate = an.add_element("debate")
19
+ meta = debate.add_element("meta")
20
+ references = meta.add_element("references")
21
+
22
+ webvtt.speakers.each do |speaker|
23
+ references.add_element("TLCPerson",
24
+ "href" => "",
25
+ "id" => speaker.parameterize,
26
+ "showAs" => speaker
27
+ )
28
+ end
29
+
30
+ body = debate.add_element("debateBody")
31
+ section = body.add_element("debateSection")
32
+ heading = section.add_element("heading")
33
+ heading.add_text "Title"
34
+
35
+ webvtt.merged_cues.each do |cue|
36
+ speech = section.add_element("speech",
37
+ "by" => "##{cue.speaker.parameterize}"
38
+ )
39
+ p = speech.add_element("p")
40
+ p.add_text cue.text
41
+ end
42
+
43
+ output
44
+ end
45
+
46
+ end
47
+
48
+ end
@@ -0,0 +1,3 @@
1
+ module Vtt2An
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,26 @@
1
+ class WebVTT::Cue
2
+
3
+ VOICE_SPAN_REGEX = /<v\.?([\w\.]*?) (.*?)\>(.*)/
4
+
5
+ def speaker
6
+ raw_text =~ VOICE_SPAN_REGEX
7
+ $2 || "Speaker"
8
+ end
9
+
10
+ alias_method :raw_text, :text
11
+
12
+ def text
13
+ raw_text =~ VOICE_SPAN_REGEX
14
+ $3 || raw_text
15
+ end
16
+
17
+ def voice_span
18
+ raw_text =~ VOICE_SPAN_REGEX
19
+ if $1
20
+ $1.split(".")
21
+ else
22
+ []
23
+ end
24
+ end
25
+
26
+ end
@@ -0,0 +1,23 @@
1
+ class WebVTT::File
2
+
3
+ def speakers
4
+ cues.map{|x|x.speaker}.uniq
5
+ end
6
+
7
+ def merged_cues
8
+ merged = []
9
+ last_speaker = nil
10
+ cues.each do |input_cue|
11
+ if input_cue.speaker != last_speaker
12
+ merged.last.parse unless merged.empty?
13
+ merged << WebVTT::Cue.new(input_cue.instance_variable_get(:@content))
14
+ else
15
+ merged.last.instance_variable_set(:@content, "#{merged.last.instance_variable_get(:@content)} #{input_cue.text}")
16
+ end
17
+ last_speaker = input_cue.speaker
18
+ end
19
+ merged.last.parse unless merged.empty?
20
+ merged
21
+ end
22
+
23
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'vtt2an/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "vtt2an"
8
+ spec.version = Vtt2An::VERSION
9
+ spec.authors = ["James Smith"]
10
+ spec.email = ["james@floppy.org.uk"]
11
+
12
+ spec.summary = %q{Convert WebVTT subtitles to Akoma Ntoso transcripts}
13
+ spec.homepage = "https://github.com/Floppy/vtt2an"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.bindir = "exe"
17
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.12"
21
+ spec.add_development_dependency "rake", "~> 11.0"
22
+ spec.add_development_dependency "rspec", "~> 3.5"
23
+ spec.add_development_dependency "coveralls", "~> 0.8"
24
+ spec.add_dependency "webvtt-ruby", "~> 0.3"
25
+ spec.add_dependency "activesupport", "~> 5.0"
26
+ end
metadata ADDED
@@ -0,0 +1,144 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vtt2an
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - James Smith
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-12-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '11.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '11.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: coveralls
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.8'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.8'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webvtt-ruby
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.3'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.3'
83
+ - !ruby/object:Gem::Dependency
84
+ name: activesupport
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '5.0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '5.0'
97
+ description:
98
+ email:
99
+ - james@floppy.org.uk
100
+ executables:
101
+ - vtt2an.rb
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - ".rspec"
107
+ - ".ruby-version"
108
+ - ".travis.yml"
109
+ - CODE_OF_CONDUCT.md
110
+ - Gemfile
111
+ - LICENSE.md
112
+ - README.md
113
+ - Rakefile
114
+ - exe/vtt2an.rb
115
+ - lib/vtt2an.rb
116
+ - lib/vtt2an/converter.rb
117
+ - lib/vtt2an/version.rb
118
+ - lib/vtt2an/webvtt/cue.rb
119
+ - lib/vtt2an/webvtt/file.rb
120
+ - vtt2an.gemspec
121
+ homepage: https://github.com/Floppy/vtt2an
122
+ licenses: []
123
+ metadata: {}
124
+ post_install_message:
125
+ rdoc_options: []
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ requirements: []
139
+ rubyforge_project:
140
+ rubygems_version: 2.4.5
141
+ signing_key:
142
+ specification_version: 4
143
+ summary: Convert WebVTT subtitles to Akoma Ntoso transcripts
144
+ test_files: []