mkvtoolnix 0.7.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 +7 -0
- data/.gitignore +33 -0
- data/.rubocop.yml +24 -0
- data/CODE_OF_CONDUCT.md +73 -0
- data/Gemfile +12 -0
- data/LICENSE.txt +21 -0
- data/README.md +238 -0
- data/Rakefile +12 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/mkvtoolnix/errors/mkvtoolnix_error.rb +13 -0
- data/lib/mkvtoolnix/extensions/iterable.rb +18 -0
- data/lib/mkvtoolnix/modules/mkv_module.rb +37 -0
- data/lib/mkvtoolnix/modules/mkvextract.rb +152 -0
- data/lib/mkvtoolnix/modules/mkvmerge.rb +33 -0
- data/lib/mkvtoolnix/modules/mkvpropedit.rb +243 -0
- data/lib/mkvtoolnix/propedit_selector.rb +65 -0
- data/lib/mkvtoolnix/types/extract/attachment.rb +18 -0
- data/lib/mkvtoolnix/types/extract/track.rb +17 -0
- data/lib/mkvtoolnix/types/info/attachment.rb +27 -0
- data/lib/mkvtoolnix/types/info/audio.rb +53 -0
- data/lib/mkvtoolnix/types/info/mkv_container.rb +58 -0
- data/lib/mkvtoolnix/types/info/subtitle.rb +51 -0
- data/lib/mkvtoolnix/types/info/video.rb +69 -0
- data/lib/mkvtoolnix/types/propedit/audio_property.rb +17 -0
- data/lib/mkvtoolnix/types/propedit/common_property.rb +29 -0
- data/lib/mkvtoolnix/types/propedit/info_property.rb +17 -0
- data/lib/mkvtoolnix/types/propedit/property.rb +17 -0
- data/lib/mkvtoolnix/types/propedit/subtitle_property.rb +12 -0
- data/lib/mkvtoolnix/types/propedit/video_property.rb +19 -0
- data/lib/mkvtoolnix.rb +70 -0
- data/mkvtoolnix.gemspec +34 -0
- metadata +80 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e948c21a4ec224548451bef5cb144ef2f3a1b3f4c3955dfbd019158f7c2a2b6f
|
4
|
+
data.tar.gz: 98410a664b3d1b2fa218de1803438e8d0e9cc42038bf97d956c402449e769a38
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a296517bee0136c8c2c3cf6d80db74ddf229aa2f84898bb99b58db108e3fc8a2b1f9f8b8a472616ae41356cae2f11f0f5896616a562c96a6882f2920d9a272ea
|
7
|
+
data.tar.gz: 010a4cfe800ff5e5e09e88c44c4780bfd50d6f7b11bb801e77815c415025788315d1122b571c83cbfa9801b68d4c18041741d85522a4472073edd01653acf9cc
|
data/.gitignore
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
|
2
|
+
#
|
3
|
+
# If you find yourself ignoring temporary files generated by your text editor
|
4
|
+
# or operating system, you probably want to add a global ignore instead:
|
5
|
+
# git config --global core.excludesfile '~/.gitignore_global'
|
6
|
+
|
7
|
+
# Ignore bundler config.
|
8
|
+
/.bundle
|
9
|
+
/.idea
|
10
|
+
Gemfile.lock
|
11
|
+
.rspec_status
|
12
|
+
|
13
|
+
# Ignore the default SQLite database.
|
14
|
+
/db/*.sqlite3
|
15
|
+
/db/*.sqlite3-*
|
16
|
+
|
17
|
+
# Ignore all logfiles and tempfiles.
|
18
|
+
/log/*
|
19
|
+
/tmp/*
|
20
|
+
!/log/.keep
|
21
|
+
!/tmp/.keep
|
22
|
+
|
23
|
+
# Ignore pidfiles, but keep the session.
|
24
|
+
/tmp/pids/*
|
25
|
+
!/tmp/pids/
|
26
|
+
!/tmp/pids/.keep
|
27
|
+
|
28
|
+
|
29
|
+
/public/assets
|
30
|
+
.byebug_history
|
31
|
+
|
32
|
+
# Ignore master key for decrypting credentials and more.
|
33
|
+
/config/master.key
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
Metrics/ParameterLists:
|
2
|
+
Enabled: false
|
3
|
+
Layout/EmptyLinesAroundClassBody:
|
4
|
+
Enabled: false
|
5
|
+
Metrics/ClassLength:
|
6
|
+
Enabled: false
|
7
|
+
Metrics/AbcSize:
|
8
|
+
Enabled: false
|
9
|
+
Metrics/CyclomaticComplexity:
|
10
|
+
Enabled: false
|
11
|
+
Metrics/BlockLength:
|
12
|
+
Enabled: false
|
13
|
+
Metrics/MethodLength:
|
14
|
+
Enabled: false
|
15
|
+
Metrics/PerceivedComplexity:
|
16
|
+
Enabled: false
|
17
|
+
Metrics/ModuleLength:
|
18
|
+
Enabled: false
|
19
|
+
Style/OptionalBooleanParameter:
|
20
|
+
Enabled: false
|
21
|
+
Style/Documentation:
|
22
|
+
Enabled: false
|
23
|
+
Naming/MethodName:
|
24
|
+
Enabled: false
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
education, socio-economic status, nationality, personal appearance, race,
|
10
|
+
religion, or sexual identity and orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at {{ email }}. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
|
72
|
+
|
73
|
+
[homepage]: https://www.contributor-covenant.org
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 Christian Feier
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,238 @@
|
|
1
|
+
# RubyMkvToolNix
|
2
|
+
|
3
|
+
RubyMkvToolNix is a work in-progress wrapper for [MkvToolNix](https://mkvtoolnix.download/)
|
4
|
+
|
5
|
+
Currently the following modules are implemented (fully):
|
6
|
+
* [mkvpropedit](https://mkvtoolnix.download/doc/mkvpropedit.html)
|
7
|
+
* [mkvextract](https://mkvtoolnix.download/doc/mkvextract.html)
|
8
|
+
|
9
|
+
Partly implemented (aka just started :p, this one is pretty complex, and I am still thinking about how to make it as simple as possible without sacrificing functionality)
|
10
|
+
* [mkvmerge](https://mkvtoolnix.download/doc/mkvmerge.html)
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
from [rubygems](https://rubygems.org/gems/mkvtoolnix)
|
15
|
+
|
16
|
+
```shell
|
17
|
+
gem 'mkvtoolnix'
|
18
|
+
```
|
19
|
+
or from the sources using
|
20
|
+
```shell
|
21
|
+
gem build mkvtoolnix.gemspec
|
22
|
+
```
|
23
|
+
and then execute
|
24
|
+
```shell
|
25
|
+
gem install mkvtoolnix-x.x.x.gem
|
26
|
+
```
|
27
|
+
|
28
|
+
## Usage
|
29
|
+
|
30
|
+
### Create MkvToolNix
|
31
|
+
|
32
|
+
To use the modules, the toolset must be initialized first, to do so, just provide the path to the `bin` folder, e.g.
|
33
|
+
`/users/thats_me/mkvtoolnix/bin/` or you installed `mkvtoolnix` e.g. using [Homebrew](https://formulae.brew.sh/formula/mkvtoolnix) and have it available in your PATH, means you can
|
34
|
+
execute the following command
|
35
|
+
```shell
|
36
|
+
$ mkvextract -V
|
37
|
+
```
|
38
|
+
without getting an error, then you don't need to provide a path to the `bin` folder at all. Initialize the toolset using
|
39
|
+
```ruby
|
40
|
+
mkv = MkvToolNix.init
|
41
|
+
```
|
42
|
+
with no binary path or
|
43
|
+
```ruby
|
44
|
+
mkv = MkvToolNix.mkv_bin_path('/users/thats_me/mkvtoolnix/bin/')
|
45
|
+
```
|
46
|
+
if you need to provide a binary path.
|
47
|
+
|
48
|
+
Optionally, you can also pass some more flags:
|
49
|
+
* `abort_at_warning` - (default: `false`) which stops the process at the first warning (otherwise warnings will be ignored)
|
50
|
+
* `disable_language_ietf` - (default: `false`) per default, if the `language` property in `mkvpropedit` will be set, the field `language_ietf` will be updated automatically. If this is disabled, the `language_ietf` field will not be touched.
|
51
|
+
|
52
|
+
To set an additional option, just chain it together when initializing:
|
53
|
+
```ruby
|
54
|
+
mkv = MkvToolNix.mkv_bin_path('/users/thats_me/mkvtoolnix/bin/').abort_at_warning.disable_language_ietf
|
55
|
+
```
|
56
|
+
|
57
|
+
To get a specific module, such as `mkvpropedit` or `mkvextract`, just use the available reader:
|
58
|
+
```ruby
|
59
|
+
extract = mkv.mkvextract
|
60
|
+
propedit = mkv.mkvpropedit
|
61
|
+
merge = mkv.mkvmerge # currently not implemented
|
62
|
+
```
|
63
|
+
|
64
|
+
to analyze a file, the `mkvmerge` can be used, or to shorten it, the `info(file)` is also available in the `mkv` instance itself
|
65
|
+
```ruby
|
66
|
+
container_info = mkv.info('myFile.mkv')
|
67
|
+
# => biiiig instance with lot of information
|
68
|
+
# #<MkvToolNix::Types::Info::MkvContainer:0x000000014dbf9278
|
69
|
+
# @attachments=[#<MkvToolNix::Types::Info::Attachment:0x000000014dbf97c8 @content_type="jpeg/jpg", @description="--update-attachment", @file_name="new name", @id=1, @size_in_b=26457, @uid=12345>],
|
70
|
+
# @audios=
|
71
|
+
# [#<MkvToolNix::Types::Info::Audio:0x000000014dbf9368
|
72
|
+
# @bit_depth=nil,
|
73
|
+
# @channels=2,
|
74
|
+
# @codec="E-AC-3",
|
75
|
+
# ...
|
76
|
+
# ],
|
77
|
+
# @container_type=17,
|
78
|
+
# @file_name="myFile.mkv",
|
79
|
+
# @type="Matroska",
|
80
|
+
# ...,
|
81
|
+
# @videos=
|
82
|
+
# [#<MkvToolNix::Types::Info::Video:0x000000014dbf9688
|
83
|
+
# @codec="AVC/H.264/MPEG-4p10",
|
84
|
+
# @codec_id="V_MPEG4/ISO/AVC",
|
85
|
+
# @stereo_mode=nil,
|
86
|
+
# @track_number=1,
|
87
|
+
# @uid=219622901820485794>,
|
88
|
+
# ...],
|
89
|
+
# ...
|
90
|
+
```
|
91
|
+
|
92
|
+
### mkvpropedit
|
93
|
+
|
94
|
+
Is used to modify mkv properties. Per default, this will only take the available metadata and modifies them. Optionally,
|
95
|
+
a full parse can be performed instead of using the existing metadata. This can be done by setting the `full_parse_mode` flag to true, which is
|
96
|
+
present for each method. But take care, this can take several minutes, and should only be done if really necessary, e.g. if the
|
97
|
+
existing metadata are broken.
|
98
|
+
|
99
|
+
All properties can be found in `MkvToolNix::Types::PropEdit::InfoProperty`, `MkvToolNix::Types::PropEdit::VideoProperty`,
|
100
|
+
`MkvToolNix::Types::PropEdit::AudioProperty` and `MkvToolNix::Types::PropEdit::SubtitleProperty`.
|
101
|
+
|
102
|
+
Also note, a `Track` can either be a `video`, `audio` or `subtitle`.
|
103
|
+
|
104
|
+
#### available commands
|
105
|
+
* version
|
106
|
+
* delete_track_statistics_tags
|
107
|
+
* add_track_statistics_tags
|
108
|
+
* set_chapters
|
109
|
+
* set_tags
|
110
|
+
* remove_property
|
111
|
+
* set_property (add or update)
|
112
|
+
* remove_attachment
|
113
|
+
* replace_attachment
|
114
|
+
* add_attachment
|
115
|
+
* update_attachment
|
116
|
+
|
117
|
+
#### Selectors
|
118
|
+
|
119
|
+
Some methods like setting a tag or property, or removing one require a selector. The action will be performed on each element that matches
|
120
|
+
the selector. All selectors are described [here](https://mkvtoolnix.download/doc/mkvpropedit.html#mkvpropedit.edit_selectors). To simplify this,
|
121
|
+
the Module `MkvToolNix::PropEditSelector` offers several methods:
|
122
|
+
* `info` (fields such as the `title`)
|
123
|
+
* `for_nth_track` - the nth track, with n > 0, e.g. 1 is usually the video track)
|
124
|
+
* `for_nth_video` - the nth video track, with n > 0
|
125
|
+
* `for_nth_audio` - the nth audio track, with n > 0
|
126
|
+
* `for_nth_subtitle` - the nth subtitle track, with n > 0
|
127
|
+
* `by_track_number` - the track number can be found by using the `info(file)` method which returns the analyzed `mkv_container`. Each track has a field `track_number`. Alternatively `mkvmerge file.mkv --identify` can be used.
|
128
|
+
* `by_track_uid` - using the `uid` of each track
|
129
|
+
* `for_attachment_by_id` - by providing the attachments `id`
|
130
|
+
* `for_attachment_by_name` - by providing the attachments `name`
|
131
|
+
* `for_attachment_by_mime_type` - by providing the attachments `mime-type`
|
132
|
+
* `tag_all` - to write to all tag fields
|
133
|
+
* `tag_global` - only write to global ones (so not for tracks)
|
134
|
+
|
135
|
+
#### Examples
|
136
|
+
|
137
|
+
##### Set Tags
|
138
|
+
|
139
|
+
```ruby
|
140
|
+
set_tags('myFile.mkv', 'myTagsFile.xml')
|
141
|
+
# => nil, or an error if something goes wrong
|
142
|
+
```
|
143
|
+
Updates the tags of the file with the tags of `MyTagsFile.xml`
|
144
|
+
|
145
|
+
##### Remove Property
|
146
|
+
```ruby
|
147
|
+
remove_property('myFile.mkv', MkvToolNix::PropEditSelector.for_nth_track(1), 'name')
|
148
|
+
# => nil, or an error if something goes wrong
|
149
|
+
```
|
150
|
+
removes the `name` property of the first track, which is usually the video track. As seen, the provided property is just a
|
151
|
+
`String`. If the property is invalid, an error will be raised. If the property is passed as a `String`, it will be automatically
|
152
|
+
mapped to a Property. Alternatively, the Property can already be provided:
|
153
|
+
```ruby
|
154
|
+
remove_property('myFile.mkv', MkvToolNix::PropEditSelector.for_nth_track(1), MkvToolNix::Types::PropEdit::VideoProperty::NAME)
|
155
|
+
# => nil, or an error if something goes wrong
|
156
|
+
```
|
157
|
+
|
158
|
+
##### Remove Attachment
|
159
|
+
|
160
|
+
```ruby
|
161
|
+
remove_attachment('myFile,mkv', MkvToolNix::PropEditSelector.for_attachment_by_name('RemoveDatAttachment'))
|
162
|
+
# => nil, or an error if something goes wrong
|
163
|
+
```
|
164
|
+
This will remove all attachments with the name `RemoveDatAttachment`. Note, if there are multiple attachments that matches the selector, all of them
|
165
|
+
will be removed.
|
166
|
+
|
167
|
+
### mkvextract
|
168
|
+
|
169
|
+
extracts specific parts of MKV files.
|
170
|
+
|
171
|
+
#### available commands
|
172
|
+
* version
|
173
|
+
* extract_tracks
|
174
|
+
* extract_attachments
|
175
|
+
* extract_chapters
|
176
|
+
* extract_tags
|
177
|
+
* extract_cue_sheet
|
178
|
+
* extract_timestamps
|
179
|
+
* extract_cues
|
180
|
+
|
181
|
+
#### Tracks/Attachments list
|
182
|
+
|
183
|
+
methods such as `extract_attachments` or `extract_tracks` can extract multiple entries at once. For this, a list of elements to export can be provided.
|
184
|
+
To simplify the process, this list can be given in several ways. The `MkvToolNix::Types::Extract::Track/Attachment` type can be used, a hash, just a string or array can be provided.
|
185
|
+
In general, the Track/Attachment ID and an output file is required for each entry.
|
186
|
+
* `Type`: just provide the ID and the output file in the defined `new(id, output_file)` constructor
|
187
|
+
* `Hash`: provide a hash of the form `{ id: [the id], output_file: [the output file]}`
|
188
|
+
* `String`: just give the `output_file`, the id will be determined by the position of the string in the array
|
189
|
+
* `Array`: by providing a 2 elment array of the form `[id, output_file]`
|
190
|
+
|
191
|
+
For example the input `[Track.new(0, 'file0'), { id: 1, output_file: 'file1' }, 'file2', [3, 'file3']]`
|
192
|
+
will be converted to `[Track.new(0, 'file0'), Track.new(1, 'file1'), Track.new(2, 'file2'), Track.new(3, 'file3')]`
|
193
|
+
|
194
|
+
#### Examples
|
195
|
+
|
196
|
+
##### extract Tags
|
197
|
+
```ruby
|
198
|
+
extract_tags('myFile.mkv', 'exported_tags.xml')
|
199
|
+
# => nil, or an error if something goes wrong
|
200
|
+
```
|
201
|
+
will export the Tags from the file to `exported_tags.xml`.
|
202
|
+
Note, that the file will only be created, if Tags exist.
|
203
|
+
|
204
|
+
##### extract Tracks
|
205
|
+
|
206
|
+
```ruby
|
207
|
+
extract_tracks(`myFile.mkv`, [Track.new(0, 'video.h264'), Track.new(2, 'german.eac3')])
|
208
|
+
# => nil, or an error if something goes wrong
|
209
|
+
```
|
210
|
+
will extract the video track at ID 0 to file `video.h264` and the audio track at ID 2 to file `german.eac3`.
|
211
|
+
Note that ID 1 could be another audio track, e.g. for english.
|
212
|
+
|
213
|
+
##### extract Attachments
|
214
|
+
|
215
|
+
```ruby
|
216
|
+
extract_attachments('myFile.mkv', [Attachment.new(0, 'attachment1.jpeg'), 'attachment2.png'])
|
217
|
+
# => nil, or an error if something goes wrong
|
218
|
+
```
|
219
|
+
will extract the attachments of the given file with ID 0 to `attachment1.jpeg` and ID 2 to `attachment.2.png`.
|
220
|
+
|
221
|
+
|
222
|
+
## Development
|
223
|
+
|
224
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
225
|
+
|
226
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
227
|
+
|
228
|
+
## Contributing
|
229
|
+
|
230
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/cfe86/mkvtoolnix. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/cfe86/mkvtoolnix/blob/master/CODE_OF_CONDUCT.md).
|
231
|
+
|
232
|
+
## License
|
233
|
+
|
234
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
235
|
+
|
236
|
+
## Code of Conduct
|
237
|
+
|
238
|
+
Everyone interacting in the Mkvtoolnix project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/mkvtoolnix/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "mkvtoolnix"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MkvToolNix
|
4
|
+
module Extensions
|
5
|
+
# offers iterable methods
|
6
|
+
module Iterable
|
7
|
+
|
8
|
+
# @return [Array<Property>] returns all constant values if sorted order
|
9
|
+
def all_properties
|
10
|
+
constants.map { |it| const_get(it) }.sort! { |a, b| a.property <=> b.property }
|
11
|
+
end
|
12
|
+
|
13
|
+
def find_property(property_name)
|
14
|
+
all_properties.find { |it| it.property == property_name }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MkvToolNix
|
4
|
+
module Modules
|
5
|
+
|
6
|
+
module MkvModule
|
7
|
+
|
8
|
+
def call_cmd(cmd)
|
9
|
+
status, out, err = nil
|
10
|
+
Open3.popen3(*cmd) do |_, stdout, stderr, thread|
|
11
|
+
out = stdout.read
|
12
|
+
err = stderr.read
|
13
|
+
status = thread.value
|
14
|
+
end
|
15
|
+
|
16
|
+
raise Errors::MkvToolNixError, out if status != 0
|
17
|
+
|
18
|
+
CmdResult.new(out, err, status)
|
19
|
+
end
|
20
|
+
|
21
|
+
class CmdResult
|
22
|
+
|
23
|
+
attr_reader :stdout, :stderr, :status
|
24
|
+
|
25
|
+
def initialize(stdout, stderr, status)
|
26
|
+
@stdout = stdout
|
27
|
+
@stderr = stderr
|
28
|
+
@status = status
|
29
|
+
end
|
30
|
+
|
31
|
+
def error?
|
32
|
+
status != 0
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,152 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MkvToolNix
|
4
|
+
module Modules
|
5
|
+
# https://mkvtoolnix.download/doc/mkvpropedit.html#mkvpropedit.edit_selectors
|
6
|
+
class MkvExtract
|
7
|
+
include MkvModule
|
8
|
+
|
9
|
+
attr_accessor :abort_at_warning
|
10
|
+
|
11
|
+
def initialize(bin_path)
|
12
|
+
@bin_path = "#{bin_path}mkvextract"
|
13
|
+
@abort_at_warning = false
|
14
|
+
end
|
15
|
+
|
16
|
+
# returns the mkvextract version
|
17
|
+
#
|
18
|
+
# return [String] the version string
|
19
|
+
def version
|
20
|
+
cmd = [@bin_path, '-V']
|
21
|
+
|
22
|
+
result = call_cmd(cmd)
|
23
|
+
|
24
|
+
result.stdout.strip
|
25
|
+
end
|
26
|
+
|
27
|
+
# extracts the selected tracks
|
28
|
+
#
|
29
|
+
# @param file [String] path to the mkv file
|
30
|
+
# @param tracks [Array] a list of Tracks, Strings or Hashes or a mix of them.
|
31
|
+
# @param extract_cuesheet [Boolean] extracts the cuesheet to [filename].cue
|
32
|
+
# @param raw [Boolean] if true, extracts the raw file, does not contain the CodecPrivate element
|
33
|
+
# @param full_raw [Boolean] if true, extracts the raw file, does contain the CodecPrivate element
|
34
|
+
# @param full_parse_mode [Boolean] sets full parse mod
|
35
|
+
def extract_tracks(file, tracks, extract_cuesheet: false, raw: false, full_raw: false, full_parse_mode: false)
|
36
|
+
cmd = [@bin_path, file, 'tracks']
|
37
|
+
add_default_options(cmd, full_parse_mode)
|
38
|
+
cmd << '--cuesheet' if extract_cuesheet
|
39
|
+
cmd << '--raw' if raw
|
40
|
+
cmd << '--fullraw' if full_raw
|
41
|
+
|
42
|
+
add_id_file_list(cmd, tracks)
|
43
|
+
|
44
|
+
call_cmd(cmd)
|
45
|
+
end
|
46
|
+
|
47
|
+
# extracts the selected attachments
|
48
|
+
#
|
49
|
+
# @param file [String] path to the mkv file
|
50
|
+
# @param attachments [Array] a list of Attachments, Strings or Hashes or a mix of them.
|
51
|
+
# @param full_parse_mode [Boolean] sets full parse mod
|
52
|
+
def extract_attachments(file, attachments, full_parse_mode: false)
|
53
|
+
cmd = [@bin_path, file, 'attachments']
|
54
|
+
add_default_options(cmd, full_parse_mode)
|
55
|
+
|
56
|
+
add_id_file_list(cmd, attachments)
|
57
|
+
|
58
|
+
call_cmd(cmd)
|
59
|
+
end
|
60
|
+
|
61
|
+
# extracts the chapter xml file
|
62
|
+
#
|
63
|
+
# @param file [String] path to the mkv file
|
64
|
+
# @param out_file [String] path to the file to write the chapter xml file to
|
65
|
+
# @param full_parse_mode [Boolean] sets full parse mod
|
66
|
+
def extract_chapters(file, out_file, simple: false, simple_language: nil, full_parse_mode: false)
|
67
|
+
cmd = [@bin_path, file, 'chapters']
|
68
|
+
add_default_options(cmd, full_parse_mode)
|
69
|
+
|
70
|
+
cmd << '--simple' if simple
|
71
|
+
cmd << '--simple-language' << simple_language unless simple_language.nil?
|
72
|
+
|
73
|
+
cmd << out_file
|
74
|
+
|
75
|
+
call_cmd(cmd)
|
76
|
+
end
|
77
|
+
|
78
|
+
# extracts the tags xml file
|
79
|
+
#
|
80
|
+
# @param file [String] path to the mkv file
|
81
|
+
# @param out_file [String] path to the file to write the tags xml file to
|
82
|
+
# @param full_parse_mode [Boolean] sets full parse mod
|
83
|
+
def extract_tags(file, out_file, full_parse_mode: false)
|
84
|
+
cmd = [@bin_path, file, 'tags']
|
85
|
+
add_default_options(cmd, full_parse_mode)
|
86
|
+
|
87
|
+
cmd << out_file
|
88
|
+
|
89
|
+
call_cmd(cmd)
|
90
|
+
end
|
91
|
+
|
92
|
+
# extracts the cue sheet
|
93
|
+
#
|
94
|
+
# @param file [String] path to the mkv file
|
95
|
+
# @param out_file [String] path to the file to write cue sheet file to
|
96
|
+
# @param full_parse_mode [Boolean] sets full parse mod
|
97
|
+
def extract_cue_sheet(file, out_file, full_parse_mode: false)
|
98
|
+
cmd = [@bin_path, file, 'cuesheet']
|
99
|
+
add_default_options(cmd, full_parse_mode)
|
100
|
+
|
101
|
+
cmd << out_file
|
102
|
+
|
103
|
+
call_cmd(cmd)
|
104
|
+
end
|
105
|
+
|
106
|
+
# extracts the timestamps of the selected tracks
|
107
|
+
#
|
108
|
+
# @param file [String] path to the mkv file
|
109
|
+
# @param tracks [Array] a list of Tracks, Strings or Hashes or a mix of them.
|
110
|
+
# @param full_parse_mode [Boolean] sets full parse mod
|
111
|
+
def extract_timestamps(file, tracks, full_parse_mode: false)
|
112
|
+
cmd = [@bin_path, file, 'timestamps_v2']
|
113
|
+
add_default_options(cmd, full_parse_mode)
|
114
|
+
|
115
|
+
add_id_file_list(cmd, tracks)
|
116
|
+
|
117
|
+
call_cmd(cmd)
|
118
|
+
end
|
119
|
+
|
120
|
+
# extracts the cues of the selected tracks
|
121
|
+
#
|
122
|
+
# @param file [String] path to the mkv file
|
123
|
+
# @param tracks [Array] a list of Tracks, Strings or Hashes or a mix of them.
|
124
|
+
# @param full_parse_mode [Boolean] sets full parse mod
|
125
|
+
def extract_cues(file, tracks, full_parse_mode: false)
|
126
|
+
cmd = [@bin_path, file, 'cues']
|
127
|
+
add_default_options(cmd, full_parse_mode)
|
128
|
+
|
129
|
+
add_id_file_list(cmd, tracks)
|
130
|
+
|
131
|
+
call_cmd(cmd)
|
132
|
+
end
|
133
|
+
|
134
|
+
def add_id_file_list(cmd, id_file_list)
|
135
|
+
id_file_list.each_with_index do |ele, index|
|
136
|
+
cmd << "#{ele.track_id}:#{ele.output_file}" if ele.is_a?(Types::Extract::Track)
|
137
|
+
cmd << "#{ele.attachment_id}:#{ele.output_file}" if ele.is_a?(Types::Extract::Attachment)
|
138
|
+
cmd << "#{ele[:id]}:#{ele[:output_file]}" if ele.is_a?(Hash)
|
139
|
+
cmd << "#{ele[0]}:#{ele[1]}" if ele.is_a?(Array)
|
140
|
+
cmd << "#{index + 1}:#{ele}" if ele.is_a?(String)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
def add_default_options(cmd, full_parse_mode)
|
145
|
+
cmd << '--parse-fully' if full_parse_mode
|
146
|
+
cmd << '--abort-on-warnings' if @abort_at_warning
|
147
|
+
end
|
148
|
+
|
149
|
+
private :add_default_options, :add_id_file_list
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|