chapter 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE.txt +20 -0
- data/README.md +56 -0
- data/ext/chapter/chapter.c +74 -0
- data/ext/chapter/extconf.rb +4 -0
- data/lib/chapter.rb +1 -0
- metadata +137 -0
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Pascal Jungblut
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
#chapter#
|
2
|
+
|
3
|
+
chapter is a simple gem to set mp4 chapter information.
|
4
|
+
|
5
|
+
##prerequisites##
|
6
|
+
To use it, you'll need [mp4v2][1] installed on your system.
|
7
|
+
|
8
|
+
On OS X:
|
9
|
+
|
10
|
+
brew install mp4v2
|
11
|
+
On FreeBSD:
|
12
|
+
|
13
|
+
cd /usr/ports/multimedia/mp4v2 && make install clean
|
14
|
+
On other systems you might need to compile it yourself. Please refer to the mp4v2 [documentation][2] on how to do that.
|
15
|
+
##Installation##
|
16
|
+
Via Rubygems:
|
17
|
+
|
18
|
+
gem install chapter
|
19
|
+
Or add the gem to your `Gemfile`:
|
20
|
+
|
21
|
+
gem 'chapter'
|
22
|
+
|
23
|
+
##Usage##
|
24
|
+
|
25
|
+
###Get the chapters in a file###
|
26
|
+
|
27
|
+
require 'chapter'
|
28
|
+
chapters = Chapter.chapters '/path/to/file.m4a'
|
29
|
+
`chapters` will be an array of hashes. Each hash represents a chapter with its position and duration (both in microseconds) and its title.
|
30
|
+
####Example
|
31
|
+
|
32
|
+
[
|
33
|
+
{"title"=>"Introduction", "duration"=>12325, "position"=>0},
|
34
|
+
{"title"=>"Discussion", "duration"=>655325, "position"=>12325}
|
35
|
+
]
|
36
|
+
###Set chapters
|
37
|
+
Setting the chapters is just as simple:
|
38
|
+
|
39
|
+
require 'chapter'
|
40
|
+
chapters = [{"title"=>"Introduction", "duration"=>12325},
|
41
|
+
{"title"=>"Discussion", "duration"=>655325}]
|
42
|
+
Chapter.set_chapters("/path/fo/file.m4a", chapters)
|
43
|
+
**CAUTON**: `set_chapters` will overwrite any existing chapters in the file.
|
44
|
+
|
45
|
+
##Copyright
|
46
|
+
###The MIT Licence
|
47
|
+
Copyright (c) 2012 Pascal Jungblut
|
48
|
+
|
49
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
50
|
+
|
51
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
52
|
+
|
53
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
54
|
+
|
55
|
+
[1]: https://code.google.com/p/mp4v2/
|
56
|
+
[2]: https://code.google.com/p/mp4v2/wiki/BuildSource
|
@@ -0,0 +1,74 @@
|
|
1
|
+
#include <ruby.h>
|
2
|
+
#include <mp4v2/mp4v2.h>
|
3
|
+
#include <stdio.h>
|
4
|
+
#include <string.h>
|
5
|
+
|
6
|
+
static VALUE
|
7
|
+
rb_get_chapters(VALUE self, VALUE path) {
|
8
|
+
char* fileName = StringValuePtr(path);
|
9
|
+
MP4FileHandle file = MP4Read(fileName, 0);
|
10
|
+
if(file == MP4_INVALID_FILE_HANDLE )
|
11
|
+
{
|
12
|
+
rb_raise(rb_eException, "could not load file");
|
13
|
+
return Qnil;
|
14
|
+
}
|
15
|
+
|
16
|
+
MP4Chapter_t * chapters = 0;
|
17
|
+
uint32_t chapterCount = 0;
|
18
|
+
|
19
|
+
// get the list of chapters
|
20
|
+
MP4ChapterType chtp = MP4GetChapters(file, &chapters, &chapterCount, MP4ChapterTypeAny);
|
21
|
+
|
22
|
+
uint32_t i;
|
23
|
+
uint32_t pos = 0;
|
24
|
+
VALUE result = rb_ary_new();
|
25
|
+
for (i = 0; i < chapterCount; ++i)
|
26
|
+
{
|
27
|
+
VALUE chapter = rb_hash_new();
|
28
|
+
// print the infos
|
29
|
+
rb_hash_aset(chapter, rb_str_new2("title"), rb_str_new2(chapters[i].title));
|
30
|
+
rb_hash_aset(chapter, rb_str_new2("duration"), INT2NUM(chapters[i].duration));
|
31
|
+
rb_hash_aset(chapter, rb_str_new2("position"), INT2NUM(pos));
|
32
|
+
rb_ary_push(result, chapter);
|
33
|
+
pos = pos + chapters[i].duration;
|
34
|
+
|
35
|
+
}
|
36
|
+
// free up the memory
|
37
|
+
MP4Free(chapters);
|
38
|
+
return result;
|
39
|
+
}
|
40
|
+
|
41
|
+
static VALUE
|
42
|
+
rb_set_chapters(VALUE self, VALUE path, VALUE chapters) {
|
43
|
+
char* fileName = StringValuePtr(path);
|
44
|
+
MP4FileHandle file = MP4Modify(fileName, 0, 0);
|
45
|
+
if(file == MP4_INVALID_FILE_HANDLE )
|
46
|
+
{
|
47
|
+
rb_raise(rb_eException, "could not load file");
|
48
|
+
return Qnil;
|
49
|
+
}
|
50
|
+
uint32_t chapter_len = RARRAY_LEN(chapters);
|
51
|
+
uint32_t i;
|
52
|
+
MP4Chapter_t newChapters[chapter_len];
|
53
|
+
for (i = 0; i < chapter_len; i++) {
|
54
|
+
|
55
|
+
VALUE duration = rb_hash_aref(rb_ary_entry(chapters, i), rb_str_new2("duration"));
|
56
|
+
VALUE title = rb_hash_aref(rb_ary_entry(chapters, i), rb_str_new2("title"));
|
57
|
+
|
58
|
+
MP4Chapter_t *chapter = malloc(sizeof(MP4Chapter_t));
|
59
|
+
chapter->duration = NUM2UINT(duration);
|
60
|
+
strcpy(chapter->title, StringValuePtr(title));
|
61
|
+
newChapters[i] = *chapter;
|
62
|
+
}
|
63
|
+
|
64
|
+
MP4SetChapters(file, &newChapters[0], chapter_len, MP4ChapterTypeQt);
|
65
|
+
MP4Close(file);
|
66
|
+
return Qnil;
|
67
|
+
}
|
68
|
+
|
69
|
+
/* ruby calls this to load the extension */
|
70
|
+
void Init_chapter(void) {
|
71
|
+
VALUE klass = rb_define_class("Chapter", rb_cObject);
|
72
|
+
rb_define_singleton_method(klass, "chapters", rb_get_chapters, 1);
|
73
|
+
rb_define_singleton_method(klass, "set_chapters", rb_set_chapters, 2);
|
74
|
+
}
|
data/lib/chapter.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'chapter/chapter'
|
metadata
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: chapter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Pascal Jungblut
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-08-27 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: shoulda
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rdoc
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '3.12'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '3.12'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: bundler
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '1'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: jeweler
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.8.4
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 1.8.4
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: simplecov
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
description: This very simple gem uses the mp4v2 C library to read and set the chapters
|
95
|
+
of mp4 files.
|
96
|
+
email: mail@pascal-jungblut.com
|
97
|
+
executables: []
|
98
|
+
extensions:
|
99
|
+
- ext/chapter/extconf.rb
|
100
|
+
extra_rdoc_files:
|
101
|
+
- LICENSE.txt
|
102
|
+
- README.md
|
103
|
+
files:
|
104
|
+
- ext/chapter/chapter.c
|
105
|
+
- ext/chapter/extconf.rb
|
106
|
+
- lib/chapter.rb
|
107
|
+
- LICENSE.txt
|
108
|
+
- README.md
|
109
|
+
homepage: http://github.com/pascalj/chapter
|
110
|
+
licenses:
|
111
|
+
- MIT
|
112
|
+
post_install_message:
|
113
|
+
rdoc_options: []
|
114
|
+
require_paths:
|
115
|
+
- lib
|
116
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
117
|
+
none: false
|
118
|
+
requirements:
|
119
|
+
- - ! '>='
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
segments:
|
123
|
+
- 0
|
124
|
+
hash: -1952082223091747186
|
125
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
|
+
none: false
|
127
|
+
requirements:
|
128
|
+
- - ! '>='
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
requirements: []
|
132
|
+
rubyforge_project:
|
133
|
+
rubygems_version: 1.8.21
|
134
|
+
signing_key:
|
135
|
+
specification_version: 3
|
136
|
+
summary: Read and write chapters of mp4 files
|
137
|
+
test_files: []
|