mp4info 1.7.3
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.
- data/README.rdoc +74 -0
- data/docs/license.txt +340 -0
- data/lib/mp4info-windows-binmode.patch +15 -0
- data/lib/mp4info.rb +505 -0
- data/test/test.rb +201 -0
- metadata +65 -0
data/README.rdoc
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
= Introduction
|
2
|
+
MP4Info supports the reading of tags and file info from MP4 audio files.
|
3
|
+
It is based on the Perl module MP4::Info (http://search.cpan.org/~jhar/MP4-Info/)
|
4
|
+
Note: MP4Info does not currently support Unicode strings.
|
5
|
+
|
6
|
+
= License
|
7
|
+
This program is free software; you can redistribute it and/or modify
|
8
|
+
it under the terms of version 2 of the GNU General Public License as
|
9
|
+
published by the Free Software Foundation.
|
10
|
+
|
11
|
+
This program is distributed in the hope that it will be useful,
|
12
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
GNU General Public License for more details.
|
15
|
+
|
16
|
+
You should have received a copy of the GNU General Public License
|
17
|
+
along with this program; if not, write to the Free Software
|
18
|
+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
19
|
+
|
20
|
+
= Usage
|
21
|
+
|
22
|
+
With mp4info.rb in your load path, do:
|
23
|
+
|
24
|
+
require 'mp4info'
|
25
|
+
|
26
|
+
Once the library is loaded, an MP4Info object is created by sending an IO
|
27
|
+
object to MP4Info#new. MP4Info also provides the MP4Info#open method, which
|
28
|
+
takes String containing a filename.
|
29
|
+
|
30
|
+
file = "my_favorite_song.mp4"
|
31
|
+
info = MP4Info.open(file)
|
32
|
+
|
33
|
+
io_stream = File.new("that_other_song.m4a")
|
34
|
+
other_info = MP4Info.new(io_stream)
|
35
|
+
|
36
|
+
Once an MP4Info object is succesfully created, a number of tags are
|
37
|
+
avalible:
|
38
|
+
|
39
|
+
* ALB - Album
|
40
|
+
* APID - Apple Store ID
|
41
|
+
* ART - Artist
|
42
|
+
* CMT - Comment
|
43
|
+
* COVR - Album art (typically jpeg data)
|
44
|
+
* CPIL - Compilation (boolean)
|
45
|
+
* CPRT - Copyright statement
|
46
|
+
* DAY - Year
|
47
|
+
* DISK - Disk number & total (Array of two integers)
|
48
|
+
* GNRE - Genre
|
49
|
+
* GRP - Grouping
|
50
|
+
* NAM - Title
|
51
|
+
* RTNG - Rating (integer)
|
52
|
+
* TMPO - Tempo (integer)
|
53
|
+
* TOO - Encoder
|
54
|
+
* TRKN - Track number & total (Array of two integers)
|
55
|
+
* WRT - Author or composer
|
56
|
+
|
57
|
+
The following extra information about the audio file is also provided:
|
58
|
+
|
59
|
+
* VERSION - MPEG version (=4)
|
60
|
+
* LAYER - Doesn't really mean antyhing, but here in case we need it
|
61
|
+
for compatibility with an MP3 library...
|
62
|
+
* BITRATE - Bitrate in kbps (average for VBR files)
|
63
|
+
The formula used to generate this seems a little suspect.
|
64
|
+
* FREQUENCY - Frequency in kHz
|
65
|
+
* SIZE - Bytes in audio stream
|
66
|
+
|
67
|
+
* SECS - Total seconds, rounded to nearest second
|
68
|
+
* MM - Minutes
|
69
|
+
* SS - Leftover seconds
|
70
|
+
* MS - Leftover milliseconds, rounded to nearest millisecond
|
71
|
+
* TIME - Time in MM:SS, rounded to nearest second
|
72
|
+
|
73
|
+
* COPYRIGHT - Non-nil if audio is copyrighted
|
74
|
+
* ENCRYPTED - Non-nil if audio data is encrypted
|
data/docs/license.txt
ADDED
@@ -0,0 +1,340 @@
|
|
1
|
+
GNU GENERAL PUBLIC LICENSE
|
2
|
+
Version 2, June 1991
|
3
|
+
|
4
|
+
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
5
|
+
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
6
|
+
Everyone is permitted to copy and distribute verbatim copies
|
7
|
+
of this license document, but changing it is not allowed.
|
8
|
+
|
9
|
+
Preamble
|
10
|
+
|
11
|
+
The licenses for most software are designed to take away your
|
12
|
+
freedom to share and change it. By contrast, the GNU General Public
|
13
|
+
License is intended to guarantee your freedom to share and change free
|
14
|
+
software--to make sure the software is free for all its users. This
|
15
|
+
General Public License applies to most of the Free Software
|
16
|
+
Foundation's software and to any other program whose authors commit to
|
17
|
+
using it. (Some other Free Software Foundation software is covered by
|
18
|
+
the GNU Library General Public License instead.) You can apply it to
|
19
|
+
your programs, too.
|
20
|
+
|
21
|
+
When we speak of free software, we are referring to freedom, not
|
22
|
+
price. Our General Public Licenses are designed to make sure that you
|
23
|
+
have the freedom to distribute copies of free software (and charge for
|
24
|
+
this service if you wish), that you receive source code or can get it
|
25
|
+
if you want it, that you can change the software or use pieces of it
|
26
|
+
in new free programs; and that you know you can do these things.
|
27
|
+
|
28
|
+
To protect your rights, we need to make restrictions that forbid
|
29
|
+
anyone to deny you these rights or to ask you to surrender the rights.
|
30
|
+
These restrictions translate to certain responsibilities for you if you
|
31
|
+
distribute copies of the software, or if you modify it.
|
32
|
+
|
33
|
+
For example, if you distribute copies of such a program, whether
|
34
|
+
gratis or for a fee, you must give the recipients all the rights that
|
35
|
+
you have. You must make sure that they, too, receive or can get the
|
36
|
+
source code. And you must show them these terms so they know their
|
37
|
+
rights.
|
38
|
+
|
39
|
+
We protect your rights with two steps: (1) copyright the software, and
|
40
|
+
(2) offer you this license which gives you legal permission to copy,
|
41
|
+
distribute and/or modify the software.
|
42
|
+
|
43
|
+
Also, for each author's protection and ours, we want to make certain
|
44
|
+
that everyone understands that there is no warranty for this free
|
45
|
+
software. If the software is modified by someone else and passed on, we
|
46
|
+
want its recipients to know that what they have is not the original, so
|
47
|
+
that any problems introduced by others will not reflect on the original
|
48
|
+
authors' reputations.
|
49
|
+
|
50
|
+
Finally, any free program is threatened constantly by software
|
51
|
+
patents. We wish to avoid the danger that redistributors of a free
|
52
|
+
program will individually obtain patent licenses, in effect making the
|
53
|
+
program proprietary. To prevent this, we have made it clear that any
|
54
|
+
patent must be licensed for everyone's free use or not licensed at all.
|
55
|
+
|
56
|
+
The precise terms and conditions for copying, distribution and
|
57
|
+
modification follow.
|
58
|
+
|
59
|
+
GNU GENERAL PUBLIC LICENSE
|
60
|
+
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
61
|
+
|
62
|
+
0. This License applies to any program or other work which contains
|
63
|
+
a notice placed by the copyright holder saying it may be distributed
|
64
|
+
under the terms of this General Public License. The "Program", below,
|
65
|
+
refers to any such program or work, and a "work based on the Program"
|
66
|
+
means either the Program or any derivative work under copyright law:
|
67
|
+
that is to say, a work containing the Program or a portion of it,
|
68
|
+
either verbatim or with modifications and/or translated into another
|
69
|
+
language. (Hereinafter, translation is included without limitation in
|
70
|
+
the term "modification".) Each licensee is addressed as "you".
|
71
|
+
|
72
|
+
Activities other than copying, distribution and modification are not
|
73
|
+
covered by this License; they are outside its scope. The act of
|
74
|
+
running the Program is not restricted, and the output from the Program
|
75
|
+
is covered only if its contents constitute a work based on the
|
76
|
+
Program (independent of having been made by running the Program).
|
77
|
+
Whether that is true depends on what the Program does.
|
78
|
+
|
79
|
+
1. You may copy and distribute verbatim copies of the Program's
|
80
|
+
source code as you receive it, in any medium, provided that you
|
81
|
+
conspicuously and appropriately publish on each copy an appropriate
|
82
|
+
copyright notice and disclaimer of warranty; keep intact all the
|
83
|
+
notices that refer to this License and to the absence of any warranty;
|
84
|
+
and give any other recipients of the Program a copy of this License
|
85
|
+
along with the Program.
|
86
|
+
|
87
|
+
You may charge a fee for the physical act of transferring a copy, and
|
88
|
+
you may at your option offer warranty protection in exchange for a fee.
|
89
|
+
|
90
|
+
2. You may modify your copy or copies of the Program or any portion
|
91
|
+
of it, thus forming a work based on the Program, and copy and
|
92
|
+
distribute such modifications or work under the terms of Section 1
|
93
|
+
above, provided that you also meet all of these conditions:
|
94
|
+
|
95
|
+
a) You must cause the modified files to carry prominent notices
|
96
|
+
stating that you changed the files and the date of any change.
|
97
|
+
|
98
|
+
b) You must cause any work that you distribute or publish, that in
|
99
|
+
whole or in part contains or is derived from the Program or any
|
100
|
+
part thereof, to be licensed as a whole at no charge to all third
|
101
|
+
parties under the terms of this License.
|
102
|
+
|
103
|
+
c) If the modified program normally reads commands interactively
|
104
|
+
when run, you must cause it, when started running for such
|
105
|
+
interactive use in the most ordinary way, to print or display an
|
106
|
+
announcement including an appropriate copyright notice and a
|
107
|
+
notice that there is no warranty (or else, saying that you provide
|
108
|
+
a warranty) and that users may redistribute the program under
|
109
|
+
these conditions, and telling the user how to view a copy of this
|
110
|
+
License. (Exception: if the Program itself is interactive but
|
111
|
+
does not normally print such an announcement, your work based on
|
112
|
+
the Program is not required to print an announcement.)
|
113
|
+
|
114
|
+
These requirements apply to the modified work as a whole. If
|
115
|
+
identifiable sections of that work are not derived from the Program,
|
116
|
+
and can be reasonably considered independent and separate works in
|
117
|
+
themselves, then this License, and its terms, do not apply to those
|
118
|
+
sections when you distribute them as separate works. But when you
|
119
|
+
distribute the same sections as part of a whole which is a work based
|
120
|
+
on the Program, the distribution of the whole must be on the terms of
|
121
|
+
this License, whose permissions for other licensees extend to the
|
122
|
+
entire whole, and thus to each and every part regardless of who wrote it.
|
123
|
+
|
124
|
+
Thus, it is not the intent of this section to claim rights or contest
|
125
|
+
your rights to work written entirely by you; rather, the intent is to
|
126
|
+
exercise the right to control the distribution of derivative or
|
127
|
+
collective works based on the Program.
|
128
|
+
|
129
|
+
In addition, mere aggregation of another work not based on the Program
|
130
|
+
with the Program (or with a work based on the Program) on a volume of
|
131
|
+
a storage or distribution medium does not bring the other work under
|
132
|
+
the scope of this License.
|
133
|
+
|
134
|
+
3. You may copy and distribute the Program (or a work based on it,
|
135
|
+
under Section 2) in object code or executable form under the terms of
|
136
|
+
Sections 1 and 2 above provided that you also do one of the following:
|
137
|
+
|
138
|
+
a) Accompany it with the complete corresponding machine-readable
|
139
|
+
source code, which must be distributed under the terms of Sections
|
140
|
+
1 and 2 above on a medium customarily used for software interchange; or,
|
141
|
+
|
142
|
+
b) Accompany it with a written offer, valid for at least three
|
143
|
+
years, to give any third party, for a charge no more than your
|
144
|
+
cost of physically performing source distribution, a complete
|
145
|
+
machine-readable copy of the corresponding source code, to be
|
146
|
+
distributed under the terms of Sections 1 and 2 above on a medium
|
147
|
+
customarily used for software interchange; or,
|
148
|
+
|
149
|
+
c) Accompany it with the information you received as to the offer
|
150
|
+
to distribute corresponding source code. (This alternative is
|
151
|
+
allowed only for noncommercial distribution and only if you
|
152
|
+
received the program in object code or executable form with such
|
153
|
+
an offer, in accord with Subsection b above.)
|
154
|
+
|
155
|
+
The source code for a work means the preferred form of the work for
|
156
|
+
making modifications to it. For an executable work, complete source
|
157
|
+
code means all the source code for all modules it contains, plus any
|
158
|
+
associated interface definition files, plus the scripts used to
|
159
|
+
control compilation and installation of the executable. However, as a
|
160
|
+
special exception, the source code distributed need not include
|
161
|
+
anything that is normally distributed (in either source or binary
|
162
|
+
form) with the major components (compiler, kernel, and so on) of the
|
163
|
+
operating system on which the executable runs, unless that component
|
164
|
+
itself accompanies the executable.
|
165
|
+
|
166
|
+
If distribution of executable or object code is made by offering
|
167
|
+
access to copy from a designated place, then offering equivalent
|
168
|
+
access to copy the source code from the same place counts as
|
169
|
+
distribution of the source code, even though third parties are not
|
170
|
+
compelled to copy the source along with the object code.
|
171
|
+
|
172
|
+
4. You may not copy, modify, sublicense, or distribute the Program
|
173
|
+
except as expressly provided under this License. Any attempt
|
174
|
+
otherwise to copy, modify, sublicense or distribute the Program is
|
175
|
+
void, and will automatically terminate your rights under this License.
|
176
|
+
However, parties who have received copies, or rights, from you under
|
177
|
+
this License will not have their licenses terminated so long as such
|
178
|
+
parties remain in full compliance.
|
179
|
+
|
180
|
+
5. You are not required to accept this License, since you have not
|
181
|
+
signed it. However, nothing else grants you permission to modify or
|
182
|
+
distribute the Program or its derivative works. These actions are
|
183
|
+
prohibited by law if you do not accept this License. Therefore, by
|
184
|
+
modifying or distributing the Program (or any work based on the
|
185
|
+
Program), you indicate your acceptance of this License to do so, and
|
186
|
+
all its terms and conditions for copying, distributing or modifying
|
187
|
+
the Program or works based on it.
|
188
|
+
|
189
|
+
6. Each time you redistribute the Program (or any work based on the
|
190
|
+
Program), the recipient automatically receives a license from the
|
191
|
+
original licensor to copy, distribute or modify the Program subject to
|
192
|
+
these terms and conditions. You may not impose any further
|
193
|
+
restrictions on the recipients' exercise of the rights granted herein.
|
194
|
+
You are not responsible for enforcing compliance by third parties to
|
195
|
+
this License.
|
196
|
+
|
197
|
+
7. If, as a consequence of a court judgment or allegation of patent
|
198
|
+
infringement or for any other reason (not limited to patent issues),
|
199
|
+
conditions are imposed on you (whether by court order, agreement or
|
200
|
+
otherwise) that contradict the conditions of this License, they do not
|
201
|
+
excuse you from the conditions of this License. If you cannot
|
202
|
+
distribute so as to satisfy simultaneously your obligations under this
|
203
|
+
License and any other pertinent obligations, then as a consequence you
|
204
|
+
may not distribute the Program at all. For example, if a patent
|
205
|
+
license would not permit royalty-free redistribution of the Program by
|
206
|
+
all those who receive copies directly or indirectly through you, then
|
207
|
+
the only way you could satisfy both it and this License would be to
|
208
|
+
refrain entirely from distribution of the Program.
|
209
|
+
|
210
|
+
If any portion of this section is held invalid or unenforceable under
|
211
|
+
any particular circumstance, the balance of the section is intended to
|
212
|
+
apply and the section as a whole is intended to apply in other
|
213
|
+
circumstances.
|
214
|
+
|
215
|
+
It is not the purpose of this section to induce you to infringe any
|
216
|
+
patents or other property right claims or to contest validity of any
|
217
|
+
such claims; this section has the sole purpose of protecting the
|
218
|
+
integrity of the free software distribution system, which is
|
219
|
+
implemented by public license practices. Many people have made
|
220
|
+
generous contributions to the wide range of software distributed
|
221
|
+
through that system in reliance on consistent application of that
|
222
|
+
system; it is up to the author/donor to decide if he or she is willing
|
223
|
+
to distribute software through any other system and a licensee cannot
|
224
|
+
impose that choice.
|
225
|
+
|
226
|
+
This section is intended to make thoroughly clear what is believed to
|
227
|
+
be a consequence of the rest of this License.
|
228
|
+
|
229
|
+
8. If the distribution and/or use of the Program is restricted in
|
230
|
+
certain countries either by patents or by copyrighted interfaces, the
|
231
|
+
original copyright holder who places the Program under this License
|
232
|
+
may add an explicit geographical distribution limitation excluding
|
233
|
+
those countries, so that distribution is permitted only in or among
|
234
|
+
countries not thus excluded. In such case, this License incorporates
|
235
|
+
the limitation as if written in the body of this License.
|
236
|
+
|
237
|
+
9. The Free Software Foundation may publish revised and/or new versions
|
238
|
+
of the General Public License from time to time. Such new versions will
|
239
|
+
be similar in spirit to the present version, but may differ in detail to
|
240
|
+
address new problems or concerns.
|
241
|
+
|
242
|
+
Each version is given a distinguishing version number. If the Program
|
243
|
+
specifies a version number of this License which applies to it and "any
|
244
|
+
later version", you have the option of following the terms and conditions
|
245
|
+
either of that version or of any later version published by the Free
|
246
|
+
Software Foundation. If the Program does not specify a version number of
|
247
|
+
this License, you may choose any version ever published by the Free Software
|
248
|
+
Foundation.
|
249
|
+
|
250
|
+
10. If you wish to incorporate parts of the Program into other free
|
251
|
+
programs whose distribution conditions are different, write to the author
|
252
|
+
to ask for permission. For software which is copyrighted by the Free
|
253
|
+
Software Foundation, write to the Free Software Foundation; we sometimes
|
254
|
+
make exceptions for this. Our decision will be guided by the two goals
|
255
|
+
of preserving the free status of all derivatives of our free software and
|
256
|
+
of promoting the sharing and reuse of software generally.
|
257
|
+
|
258
|
+
NO WARRANTY
|
259
|
+
|
260
|
+
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
261
|
+
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
262
|
+
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
263
|
+
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
264
|
+
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
265
|
+
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
266
|
+
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
267
|
+
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
268
|
+
REPAIR OR CORRECTION.
|
269
|
+
|
270
|
+
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
271
|
+
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
272
|
+
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
273
|
+
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
274
|
+
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
275
|
+
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
276
|
+
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
277
|
+
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
278
|
+
POSSIBILITY OF SUCH DAMAGES.
|
279
|
+
|
280
|
+
END OF TERMS AND CONDITIONS
|
281
|
+
|
282
|
+
How to Apply These Terms to Your New Programs
|
283
|
+
|
284
|
+
If you develop a new program, and you want it to be of the greatest
|
285
|
+
possible use to the public, the best way to achieve this is to make it
|
286
|
+
free software which everyone can redistribute and change under these terms.
|
287
|
+
|
288
|
+
To do so, attach the following notices to the program. It is safest
|
289
|
+
to attach them to the start of each source file to most effectively
|
290
|
+
convey the exclusion of warranty; and each file should have at least
|
291
|
+
the "copyright" line and a pointer to where the full notice is found.
|
292
|
+
|
293
|
+
<one line to give the program's name and a brief idea of what it does.>
|
294
|
+
Copyright (C) <year> <name of author>
|
295
|
+
|
296
|
+
This program is free software; you can redistribute it and/or modify
|
297
|
+
it under the terms of the GNU General Public License as published by
|
298
|
+
the Free Software Foundation; either version 2 of the License, or
|
299
|
+
(at your option) any later version.
|
300
|
+
|
301
|
+
This program is distributed in the hope that it will be useful,
|
302
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
303
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
304
|
+
GNU General Public License for more details.
|
305
|
+
|
306
|
+
You should have received a copy of the GNU General Public License
|
307
|
+
along with this program; if not, write to the Free Software
|
308
|
+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
309
|
+
|
310
|
+
|
311
|
+
Also add information on how to contact you by electronic and paper mail.
|
312
|
+
|
313
|
+
If the program is interactive, make it output a short notice like this
|
314
|
+
when it starts in an interactive mode:
|
315
|
+
|
316
|
+
Gnomovision version 69, Copyright (C) year name of author
|
317
|
+
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
318
|
+
This is free software, and you are welcome to redistribute it
|
319
|
+
under certain conditions; type `show c' for details.
|
320
|
+
|
321
|
+
The hypothetical commands `show w' and `show c' should show the appropriate
|
322
|
+
parts of the General Public License. Of course, the commands you use may
|
323
|
+
be called something other than `show w' and `show c'; they could even be
|
324
|
+
mouse-clicks or menu items--whatever suits your program.
|
325
|
+
|
326
|
+
You should also get your employer (if you work as a programmer) or your
|
327
|
+
school, if any, to sign a "copyright disclaimer" for the program, if
|
328
|
+
necessary. Here is a sample; alter the names:
|
329
|
+
|
330
|
+
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
331
|
+
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
332
|
+
|
333
|
+
<signature of Ty Coon>, 1 April 1989
|
334
|
+
Ty Coon, President of Vice
|
335
|
+
|
336
|
+
This General Public License does not permit incorporating your program into
|
337
|
+
proprietary programs. If your program is a subroutine library, you may
|
338
|
+
consider it more useful to permit linking proprietary applications with the
|
339
|
+
library. If this is what you want to do, use the GNU Library General
|
340
|
+
Public License instead of this License.
|
@@ -0,0 +1,15 @@
|
|
1
|
+
Index: mp4info.rb
|
2
|
+
===================================================================
|
3
|
+
--- mp4info.rb (revision 41)
|
4
|
+
+++ mp4info.rb (working copy)
|
5
|
+
@@ -185,6 +185,10 @@
|
6
|
+
data = read_or_raise(io_stream, size, "Premature end of file")
|
7
|
+
|
8
|
+
cache = Tempfile.new "mp4info"
|
9
|
+
+
|
10
|
+
+ # required for Windows
|
11
|
+
+ cache.binmode
|
12
|
+
+
|
13
|
+
cache.write data
|
14
|
+
cache.open
|
15
|
+
cache.rewind
|
data/lib/mp4info.rb
ADDED
@@ -0,0 +1,505 @@
|
|
1
|
+
# = Introduction
|
2
|
+
# MP4Info supports the reading of tags and file info from MP4 audio files.
|
3
|
+
# It is based on the Perl module MP4::Info (http://search.cpan.org/~jhar/MP4-Info/)
|
4
|
+
# Note: MP4Info does not currently support Unicode strings.
|
5
|
+
#
|
6
|
+
# = License
|
7
|
+
# Copyright (c) 2004-2007 Jonathan Harris <jhar@cpan.org>
|
8
|
+
# Copyright (C) 2006-2007 Jason Terk <rain@xidus.net>
|
9
|
+
#
|
10
|
+
# This program is free software; you can redistribute it and/or modify
|
11
|
+
# it under the terms of version 2 of the GNU General Public License as
|
12
|
+
# published by the Free Software Foundation.
|
13
|
+
#
|
14
|
+
# This program is distributed in the hope that it will be useful,
|
15
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17
|
+
# GNU General Public License for more details.
|
18
|
+
#
|
19
|
+
# You should have received a copy of the GNU General Public License
|
20
|
+
# along with this program; if not, write to the Free Software
|
21
|
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
22
|
+
#
|
23
|
+
# See the README file for usage information.
|
24
|
+
|
25
|
+
require 'tempfile'
|
26
|
+
|
27
|
+
class MP4Info
|
28
|
+
# Initialize a new MP4Info object from an IO object
|
29
|
+
def initialize(io_stream)
|
30
|
+
# Tag atoms
|
31
|
+
@data_atoms = {
|
32
|
+
"AART" => nil, "ALB" => nil, "ART" => nil, "CMT" => nil,
|
33
|
+
"COVR" => nil, "CPIL" => nil, "CPRT" => nil, "DAY" => nil,
|
34
|
+
"DISK" => nil, "GEN" => nil, "GNRE" => nil, "GRP" => nil,
|
35
|
+
"NAM" => nil, "RTNG" => nil, "TMPO" => nil, "TOO" => nil,
|
36
|
+
"TRKN" => nil, "WRT" => nil, "APID" => nil, "AKID" => nil,
|
37
|
+
"ATID" => nil, "CNID" => nil, "GEID" => nil, "PLID" => nil,
|
38
|
+
"TITL" => nil, "DSCP" => nil, "PERF" => nil, "AUTH" => nil
|
39
|
+
}
|
40
|
+
|
41
|
+
# Info atoms
|
42
|
+
@info_atoms = {
|
43
|
+
"VERSION" => nil, "BITRATE" => nil, "FREQUENCY" => nil, "MS" => nil,
|
44
|
+
"SIZE" => nil, "SECS" => nil, "MM" => nil, "SS" => nil, "ENCRYPTED" => nil,
|
45
|
+
"TIME" => nil, "COPYRIGHT" => nil, "LAYER" => nil
|
46
|
+
}
|
47
|
+
|
48
|
+
# Atoms that contain other atoms
|
49
|
+
@container_atoms = {
|
50
|
+
"ILST" => nil, "MDIA" => nil, "MINF" => nil, "MOOV" => nil,
|
51
|
+
"STBL" => nil, "TRAK" => nil, "UDTA" => nil
|
52
|
+
}
|
53
|
+
|
54
|
+
# Non standard data atoms
|
55
|
+
@other_atoms = {
|
56
|
+
"MDAT" => :parse_mdat, "META" => :parse_meta,
|
57
|
+
"MVHD" => :parse_mvhd, "STSD" => :parse_stsd,
|
58
|
+
"MOOV" => :parse_moov, "UUID" => :parse_uuid
|
59
|
+
}
|
60
|
+
|
61
|
+
# Info/Tag aliases
|
62
|
+
@aliases = {}
|
63
|
+
|
64
|
+
# Just in case
|
65
|
+
io_stream.binmode
|
66
|
+
|
67
|
+
# Sanity check
|
68
|
+
head = read_or_raise(io_stream, 8, "#{io_stream} does not appear to be an IO stream")
|
69
|
+
raise "#{io_stream} does not appear to be an MP4 file" unless head[4..7].downcase == "ftyp"
|
70
|
+
|
71
|
+
# Back to the beginning
|
72
|
+
io_stream.rewind
|
73
|
+
|
74
|
+
parse_container io_stream, 0, io_stream.stat.size
|
75
|
+
|
76
|
+
@info_atoms["VERSION"] = 4
|
77
|
+
@info_atoms["LAYER"] = 1 if @info_atoms["FREQUENCY"]
|
78
|
+
if (@info_atoms["SIZE"] && @info_atoms["MS"])
|
79
|
+
@info_atoms["BITRATE"] = ( 0.5 + @info_atoms["SIZE"] /
|
80
|
+
( ( @info_atoms["MM"] * 60 + @info_atoms["SS"] + (@info_atoms["MS"] * 1.0) / 1000 ) * 128 ) ).floor
|
81
|
+
end
|
82
|
+
@info_atoms["COPYRIGHT"] = true if @info_atoms["CPRT"]
|
83
|
+
end
|
84
|
+
|
85
|
+
# Get an MP4Info object from a file name
|
86
|
+
def MP4Info.open(file_name)
|
87
|
+
MP4Info.new(File.new(file_name))
|
88
|
+
end
|
89
|
+
|
90
|
+
# Dynamically get tags and info
|
91
|
+
def method_missing(id)
|
92
|
+
field = id.to_s
|
93
|
+
|
94
|
+
if (@data_atoms.has_key?(field))
|
95
|
+
@data_atoms[field]
|
96
|
+
elsif (@info_atoms.has_key?(field))
|
97
|
+
@info_atoms[field]
|
98
|
+
elsif (@aliases.has_key?(field))
|
99
|
+
@aliases[field]
|
100
|
+
else
|
101
|
+
nil
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
private
|
106
|
+
# Parse a container
|
107
|
+
def parse_container(io_stream, level, size)
|
108
|
+
level += 1
|
109
|
+
container_end = io_stream.pos + size
|
110
|
+
|
111
|
+
while io_stream.pos < container_end do
|
112
|
+
parse_atom io_stream, level, container_end - io_stream.pos
|
113
|
+
end
|
114
|
+
|
115
|
+
if (io_stream.pos != container_end)
|
116
|
+
raise "Parse error"
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
# Parse an atom
|
121
|
+
def parse_atom(io_stream, level, parent_size)
|
122
|
+
head = read_or_raise(io_stream, 8, "Premature end of file")
|
123
|
+
|
124
|
+
size, id = head.unpack("Na4")
|
125
|
+
|
126
|
+
if (size == 0)
|
127
|
+
position = io_stream.pos
|
128
|
+
io_stream.seek(0, 2)
|
129
|
+
size = io_stream.pos - position
|
130
|
+
io_stream.seek(position, 0)
|
131
|
+
elsif (size == 1)
|
132
|
+
# Extended size, whatever that means
|
133
|
+
head = read_or_raise(io_stream, 8, "Premature end of file")
|
134
|
+
hi, low = head.unpack("NN")
|
135
|
+
size = hi * (2**32) + low - 16
|
136
|
+
|
137
|
+
if (size > parent_size)
|
138
|
+
# Atom extends outside of parent container; skip to the end
|
139
|
+
io_stream.seek(parent_size - 16, 1)
|
140
|
+
return
|
141
|
+
end
|
142
|
+
|
143
|
+
size -= 16
|
144
|
+
else
|
145
|
+
if (size > parent_size)
|
146
|
+
# Atom extends outside of parent container; skip to the end
|
147
|
+
io_stream.seek(parent_size - 8, 1)
|
148
|
+
return
|
149
|
+
end
|
150
|
+
|
151
|
+
size -= 8;
|
152
|
+
end
|
153
|
+
|
154
|
+
if (size < 0)
|
155
|
+
raise "Parse error"
|
156
|
+
end
|
157
|
+
|
158
|
+
if id[0] == 169
|
159
|
+
# strip copyright sign at the beginning
|
160
|
+
id = id[1..-1]
|
161
|
+
end
|
162
|
+
id = id.upcase
|
163
|
+
|
164
|
+
printf "%s%s: %d bytes\n", ' ' * ( 2 * level ), id, size if $DEBUG
|
165
|
+
|
166
|
+
if (@data_atoms.has_key?(id))
|
167
|
+
parse_data io_stream, level, size, id
|
168
|
+
elsif (@other_atoms.has_key?(id))
|
169
|
+
self.send(@other_atoms[id], io_stream, level, size)
|
170
|
+
elsif (@container_atoms.has_key?(id))
|
171
|
+
parse_container io_stream, level, size
|
172
|
+
else
|
173
|
+
# Unknown atom, move on
|
174
|
+
io_stream.seek size, 1
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
# Parse a MOOV container
|
179
|
+
#
|
180
|
+
# Pre-conditions: size = size of atom contents
|
181
|
+
# io_stream points to start of atom contents
|
182
|
+
#
|
183
|
+
# Post-condition: io_stream points past end of atom contents
|
184
|
+
def parse_moov(io_stream, level, size)
|
185
|
+
data = read_or_raise(io_stream, size, "Premature end of file")
|
186
|
+
|
187
|
+
cache = Tempfile.new "mp4info"
|
188
|
+
|
189
|
+
# required for Windows
|
190
|
+
cache.binmode
|
191
|
+
|
192
|
+
cache.write data
|
193
|
+
cache.open
|
194
|
+
cache.rewind
|
195
|
+
|
196
|
+
parse_container(cache, level, size)
|
197
|
+
|
198
|
+
cache.close!
|
199
|
+
end
|
200
|
+
|
201
|
+
# Parse an MDAT atom
|
202
|
+
#
|
203
|
+
# Pre-conditions: size = size of atom contents
|
204
|
+
# io_stream points to start of atom contents
|
205
|
+
#
|
206
|
+
# Post-condition: io_stream points past end of atom contents
|
207
|
+
def parse_mdat(io_stream, level, size)
|
208
|
+
@info_atoms["SIZE"] = 0 unless @info_atoms["SIZE"]
|
209
|
+
@info_atoms["SIZE"] += size
|
210
|
+
io_stream.seek(size, 1)
|
211
|
+
end
|
212
|
+
|
213
|
+
# Parse a META atom
|
214
|
+
#
|
215
|
+
# Pre-conditions: size = size of atom contents
|
216
|
+
# io_stream points to start of atom contents
|
217
|
+
#
|
218
|
+
# Post-condition: io_stream points past end of atom contents
|
219
|
+
def parse_meta(io_stream, level, size)
|
220
|
+
# META is a container preceeded by a version field
|
221
|
+
io_stream.seek(4, 1)
|
222
|
+
parse_container(io_stream, level, size - 4)
|
223
|
+
end
|
224
|
+
|
225
|
+
# Parse an MVHD atom
|
226
|
+
#
|
227
|
+
# Pre-conditions: size = size of atom contents
|
228
|
+
# io_stream points to start of atom contents
|
229
|
+
#
|
230
|
+
# Post-condition: io_stream points past end of atom contents
|
231
|
+
def parse_mvhd(io_stream, level, size)
|
232
|
+
raise "Parse error" if size < 32
|
233
|
+
data = read_or_raise(io_stream, size, "Premature end of file")
|
234
|
+
|
235
|
+
version = data.unpack("C")[0] & 255
|
236
|
+
if (version == 0)
|
237
|
+
scale, duration = data[12..19].unpack("NN")
|
238
|
+
elsif (version == 1)
|
239
|
+
scale, hi, low = data[20..31].unpack("NNN")
|
240
|
+
duration = hi * (2**32) + low
|
241
|
+
else
|
242
|
+
return
|
243
|
+
end
|
244
|
+
|
245
|
+
printf " %sDur/Scl=#{duration}/#{scale}\n", ' ' * ( 2 * level ) if $DEBUG
|
246
|
+
|
247
|
+
secs = (duration * 1.0) / scale
|
248
|
+
@info_atoms["SECS"] = (secs).round
|
249
|
+
@info_atoms["MM"] = (secs / 60).floor
|
250
|
+
@info_atoms["SS"] = (secs - @info_atoms["MM"] * 60).floor
|
251
|
+
@info_atoms["MS"] = (1000 * (secs - secs.floor)).round
|
252
|
+
@info_atoms["TIME"] = sprintf "%02d:%02d", @info_atoms["MM"],
|
253
|
+
@info_atoms["SECS"] - @info_atoms["MM"] * 60;
|
254
|
+
end
|
255
|
+
|
256
|
+
# Parse an STSD atom
|
257
|
+
#
|
258
|
+
# Pre-conditions: size = size of atom contents
|
259
|
+
# io_stream points to start of atom contents
|
260
|
+
#
|
261
|
+
# Post-condition: io_stream points past end of atom contents
|
262
|
+
def parse_stsd(io_stream, level, size)
|
263
|
+
raise "Parse error" if size < 44
|
264
|
+
data = read_or_raise(io_stream, size, "Premature end of headers")
|
265
|
+
|
266
|
+
printf " %sSample=%s\n", ' ' * ( 2 * level ), data[12..15] if $DEBUG
|
267
|
+
|
268
|
+
data_format = data[12..15].downcase
|
269
|
+
|
270
|
+
# Is this an audio track?
|
271
|
+
if (data_format == "mp4a" || data_format == "drms" ||
|
272
|
+
data_format == "samr" || data_format == "sawb" ||
|
273
|
+
data_format == "sawp" || data_format == "enca" ||
|
274
|
+
data_format == "alac" )
|
275
|
+
@info_atoms["ENCODING"] = data_format
|
276
|
+
@info_atoms["FREQUENCY"] = (data[40..43].unpack("N")[0] * 1.0) / 65536000
|
277
|
+
printf " %sFreq=%s\n", ' ' * ( 2 * level ), @info_atoms["FREQUENCY"] if $DEBUG
|
278
|
+
end
|
279
|
+
|
280
|
+
if (data_format == "drms" || data_format[0..2] == "enc")
|
281
|
+
@info_atoms["ENCRYPTED"] = true;
|
282
|
+
end
|
283
|
+
end
|
284
|
+
|
285
|
+
# User-defined box. Used by PSP - See ffmpeg libavformat/movenc.c
|
286
|
+
#
|
287
|
+
# Pre-conditions: size = size of atom contents
|
288
|
+
# io_stream points to start of atom contents
|
289
|
+
#
|
290
|
+
# Post-condition: io_stream points past end of atom contents
|
291
|
+
def parse_uuid(io_stream, level, size)
|
292
|
+
data = read_or_raise(io_stream, size, "Premature end of file")
|
293
|
+
|
294
|
+
return unless size > 26
|
295
|
+
|
296
|
+
u1, u2, u3, u4 = data.unpack 'a4NNN'
|
297
|
+
|
298
|
+
if (u1 == "USMT")
|
299
|
+
pspsize, pspid = data[16..23].unpack 'Na4'
|
300
|
+
|
301
|
+
return unless pspsize == size - 16
|
302
|
+
|
303
|
+
if (pspid == "MTDT")
|
304
|
+
nblocks = data[24..25].unpack 'n'
|
305
|
+
data = data[26..(data.length - 1)]
|
306
|
+
|
307
|
+
while nblocks
|
308
|
+
bsize, btype, flags, ptype = data.unpack 'nNnn'
|
309
|
+
|
310
|
+
if (btype == 1 && bsize == 12 &&
|
311
|
+
ptype == 1 && @data_atoms["NAM"].nil?)
|
312
|
+
@data_atoms["NAM"] = data[10..(10 + bsize - 11)]
|
313
|
+
elsif (btype == 4 && bsize > 12 && ptype == 1)
|
314
|
+
@data_atoms["TOO"] = data[10..(10 + bsize - 11)]
|
315
|
+
end
|
316
|
+
|
317
|
+
data = data[bsize..(data.length - 1)]
|
318
|
+
nblocks -= 1
|
319
|
+
end
|
320
|
+
end
|
321
|
+
end
|
322
|
+
end
|
323
|
+
|
324
|
+
def parse_data(io_stream, level, size, id)
|
325
|
+
# Possible genres...
|
326
|
+
mp4_genres = [
|
327
|
+
'N/A', 'Blues',
|
328
|
+
'Classic Rock', 'Country',
|
329
|
+
'Dance', 'Disco',
|
330
|
+
'Funk', 'Grunge',
|
331
|
+
'Hip-Hop', 'Jazz',
|
332
|
+
'Metal', 'New Age',
|
333
|
+
'Oldies', 'Other',
|
334
|
+
'Pop', 'R&B',
|
335
|
+
'Rap', 'Reggae',
|
336
|
+
'Rock', 'Techno',
|
337
|
+
'Industrial', 'Alternative',
|
338
|
+
'Ska', 'Death Metal',
|
339
|
+
'Pranks', 'Soundtrack',
|
340
|
+
'Euro-Techno', 'Ambient',
|
341
|
+
'Trip-Hop', 'Vocal',
|
342
|
+
'Jazz+Funk', 'Fusion',
|
343
|
+
'Trance', 'Classical',
|
344
|
+
'Instrumental', 'Acid',
|
345
|
+
'House', 'Game',
|
346
|
+
'Sound Clip', 'Gospel',
|
347
|
+
'Noise', 'AlternRock',
|
348
|
+
'Bass', 'Soul',
|
349
|
+
'Punk', 'Space',
|
350
|
+
'Meditative', 'Instrumental Pop',
|
351
|
+
'Instrumental Rock', 'Ethnic',
|
352
|
+
'Gothic', 'Darkwave',
|
353
|
+
'Techno-Industrial', 'Electronic',
|
354
|
+
'Pop-Folk', 'Eurodance',
|
355
|
+
'Dream', 'Southern Rock',
|
356
|
+
'Comedy', 'Cult',
|
357
|
+
'Gangsta', 'Top 40',
|
358
|
+
'Christian Rap', 'Pop/Funk',
|
359
|
+
'Jungle', 'Native American',
|
360
|
+
'Cabaret', 'New Wave',
|
361
|
+
'Psychadelic', 'Rave',
|
362
|
+
'Showtunes', 'Trailer',
|
363
|
+
'Lo-Fi', 'Tribal',
|
364
|
+
'Acid Punk', 'Acid Jazz',
|
365
|
+
'Polka', 'Retro',
|
366
|
+
'Musical', 'Rock & Roll',
|
367
|
+
'Hard Rock', 'Folk',
|
368
|
+
'Folk/Rock', 'National Folk',
|
369
|
+
'Swing', 'Fast-Fusion',
|
370
|
+
'Bebob', 'Latin',
|
371
|
+
'Revival', 'Celtic',
|
372
|
+
'Bluegrass', 'Avantgarde',
|
373
|
+
'Gothic Rock', 'Progressive Rock',
|
374
|
+
'Psychedelic Rock', 'Symphonic Rock',
|
375
|
+
'Slow Rock', 'Big Band',
|
376
|
+
'Chorus', 'Easy Listening',
|
377
|
+
'Acoustic', 'Humour',
|
378
|
+
'Speech', 'Chanson',
|
379
|
+
'Opera', 'Chamber Music',
|
380
|
+
'Sonata', 'Symphony',
|
381
|
+
'Booty Bass', 'Primus',
|
382
|
+
'Porn Groove', 'Satire',
|
383
|
+
'Slow Jam', 'Club',
|
384
|
+
'Tango', 'Samba',
|
385
|
+
'Folklore', 'Ballad',
|
386
|
+
'Power Ballad', 'Rhythmic Soul',
|
387
|
+
'Freestyle', 'Duet',
|
388
|
+
'Punk Rock', 'Drum Solo',
|
389
|
+
'A capella', 'Euro-House',
|
390
|
+
'Dance Hall', 'Goa',
|
391
|
+
'Drum & Bass', 'Club House',
|
392
|
+
'Hardcore', 'Terror',
|
393
|
+
'Indie', 'BritPop',
|
394
|
+
'NegerPunk', 'Polsk Punk',
|
395
|
+
'Beat', 'Christian Gangsta',
|
396
|
+
'Heavy Metal', 'Black Metal',
|
397
|
+
'Crossover', 'Contemporary C',
|
398
|
+
'Christian Rock', 'Merengue',
|
399
|
+
'Salsa', 'Thrash Metal',
|
400
|
+
'Anime', 'JPop',
|
401
|
+
'SynthPop'
|
402
|
+
]
|
403
|
+
|
404
|
+
data = read_or_raise(io_stream, size, "Premature end of file")
|
405
|
+
|
406
|
+
if (id == "TITL" || id == "DSCP" || id == "CPRT" ||
|
407
|
+
id == "PERF" || id == "AUTH" || id == "GNRE")
|
408
|
+
ver = data.unpack("N")[0]
|
409
|
+
if (ver == 0)
|
410
|
+
return unless size > 7
|
411
|
+
size -= 7
|
412
|
+
type = 1
|
413
|
+
data = data[6..(6 + size - 1)]
|
414
|
+
|
415
|
+
if (id == "TITL")
|
416
|
+
return if !@data_atoms["NAM"].nil?
|
417
|
+
id = "NAM"
|
418
|
+
elsif (id == "DSCP")
|
419
|
+
return if !@data_atoms["CMT"].nil?
|
420
|
+
id = "CMT"
|
421
|
+
elsif (id == "PERF")
|
422
|
+
return if !@data_atoms["ART"].nil?
|
423
|
+
id = "ART"
|
424
|
+
elsif (id == "AUTH")
|
425
|
+
return if !@data_atoms["WRT"].nil?
|
426
|
+
id = "WRT"
|
427
|
+
end
|
428
|
+
end
|
429
|
+
end
|
430
|
+
|
431
|
+
if (id == "MEAN" || id == "NAME" || id == "DATA")
|
432
|
+
if id == "DATA"
|
433
|
+
data = data[8..(data.length - 1)]
|
434
|
+
else
|
435
|
+
data = data[4..(data.length - 1)]
|
436
|
+
end
|
437
|
+
|
438
|
+
@data_atoms[id] = data
|
439
|
+
return
|
440
|
+
end
|
441
|
+
|
442
|
+
if (type.nil?)
|
443
|
+
return unless size > 16
|
444
|
+
size, atom, type = data.unpack("Na4N")
|
445
|
+
|
446
|
+
return unless atom.downcase == "data" and size > 16
|
447
|
+
|
448
|
+
size = size - 16
|
449
|
+
type = type & 255
|
450
|
+
data = data[16..(16 + size - 1)]
|
451
|
+
end
|
452
|
+
|
453
|
+
printf " %sType=#{type}, Size=#{size}\n", ' ' * ( 2 * level ) if $DEBUG
|
454
|
+
|
455
|
+
if (id == "COVR")
|
456
|
+
@data_atoms[id] = data
|
457
|
+
elsif (type == 0)
|
458
|
+
ints = data.unpack("n" * (size / 2))
|
459
|
+
if (id == "GNRE")
|
460
|
+
@data_atoms[id] = mp4_genres[ints[0]]
|
461
|
+
elsif (id == "DISK" || id == "TRKN")
|
462
|
+
@data_atoms[id] = [ints[1], (size >= 6 ? ints[2] : 0)] if size >= 4
|
463
|
+
elsif (size >= 4)
|
464
|
+
@data_atoms[id] = ints[1]
|
465
|
+
end
|
466
|
+
elsif (type == 1)
|
467
|
+
if (id == "GEN")
|
468
|
+
return if !@data_atoms["GNRE"].nil?
|
469
|
+
id = "GNRE"
|
470
|
+
elsif (id == "AART")
|
471
|
+
return if !@data_atoms["ART"].nil?
|
472
|
+
id = "ART"
|
473
|
+
elsif (id == "DAY")
|
474
|
+
data = data[0..3]
|
475
|
+
return if data == 0
|
476
|
+
end
|
477
|
+
|
478
|
+
@data_atoms[id] = data
|
479
|
+
elsif (type == 21)
|
480
|
+
if (size == 1)
|
481
|
+
@data_atoms[id] = data.unpack("C")[0]
|
482
|
+
elsif (size == 2)
|
483
|
+
@data_atoms[id] = data.unpack("n")[0]
|
484
|
+
elsif (size == 4)
|
485
|
+
@data_atoms[id] = data.unpack("N")[0]
|
486
|
+
elsif (size == 8)
|
487
|
+
hi, low = data.unpack("NN")
|
488
|
+
@data_atoms[id] = hi * (2 ** 32) + low
|
489
|
+
else
|
490
|
+
@data_atoms[id] = data
|
491
|
+
end
|
492
|
+
elsif (type == 13 || type == 14)
|
493
|
+
@data_atoms[id] = data
|
494
|
+
end
|
495
|
+
end
|
496
|
+
|
497
|
+
# Utility method; read bytes bytes from io_stream or raise message message
|
498
|
+
def read_or_raise(io_stream, bytes, message)
|
499
|
+
buffer = io_stream.read(bytes)
|
500
|
+
if (buffer.length != bytes)
|
501
|
+
raise message
|
502
|
+
end
|
503
|
+
buffer
|
504
|
+
end
|
505
|
+
end
|
data/test/test.rb
ADDED
@@ -0,0 +1,201 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Copyright (c) 2004-2007 Jonathan Harris <jhar@cpan.org>
|
4
|
+
# Copyright (C) 2006-2007 Jason Terk <rain@xidus.net>
|
5
|
+
#
|
6
|
+
# This program is free software; you can redistribute it and/or modify
|
7
|
+
# it under the terms of version 2 of the GNU General Public License as
|
8
|
+
# published by the Free Software Foundation.
|
9
|
+
#
|
10
|
+
# This program is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
# GNU General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU General Public License
|
16
|
+
# along with this program; if not, write to the Free Software
|
17
|
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
18
|
+
|
19
|
+
$KCODE="u"
|
20
|
+
$:.unshift File.join(File.dirname(__FILE__), "..", "lib")
|
21
|
+
require "mp4info"
|
22
|
+
require "test/unit"
|
23
|
+
|
24
|
+
# Tests for MP4Info
|
25
|
+
#
|
26
|
+
# This test case covers a small number of possible encoders and
|
27
|
+
# tag/info fields. More cases are needed to fully test the library.
|
28
|
+
class TestMP4Info < Test::Unit::TestCase
|
29
|
+
|
30
|
+
# Test an mp4 file created by the FAAC encoder
|
31
|
+
def test_faac
|
32
|
+
file = "faac.m4a"
|
33
|
+
|
34
|
+
info = {
|
35
|
+
:ALB => 'Album',
|
36
|
+
:APID => nil,
|
37
|
+
:ART => 'Artist',
|
38
|
+
:CMT => 'This is a Comment',
|
39
|
+
:COVR => nil,
|
40
|
+
:CPIL => 1,
|
41
|
+
:CPRT => nil,
|
42
|
+
:DAY => '2004',
|
43
|
+
:DISK => [3,4],
|
44
|
+
:GNRE => 'Acid Jazz',
|
45
|
+
:GRP => nil,
|
46
|
+
:NAM => 'Name',
|
47
|
+
:TMPO => nil,
|
48
|
+
:TOO => 'FAAC 1.24+ (Jul 14 2004) UNSTABLE',
|
49
|
+
:TRKN => [1,2],
|
50
|
+
:WRT => 'Composer',
|
51
|
+
:VERSION => 4,
|
52
|
+
:LAYER => 1,
|
53
|
+
:BITRATE => 16,
|
54
|
+
:FREQUENCY => 8,
|
55
|
+
:SIZE => 2353,
|
56
|
+
:SECS => 1,
|
57
|
+
:MM => 0,
|
58
|
+
:MS => 178,
|
59
|
+
:SS => 1,
|
60
|
+
:TIME => '00:01',
|
61
|
+
:COPYRIGHT => nil,
|
62
|
+
:ENCRYPTED => nil
|
63
|
+
}
|
64
|
+
|
65
|
+
mp4 = MP4Info.open(file)
|
66
|
+
|
67
|
+
info.each do |key, value|
|
68
|
+
assert_equal(value, mp4.send(key))
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
# Test an mp4 file created by the iTunes encoder
|
73
|
+
def test_itunes
|
74
|
+
file = "iTunes.m4a"
|
75
|
+
|
76
|
+
info = {
|
77
|
+
:ALB => 'Album',
|
78
|
+
:APID => nil,
|
79
|
+
:ART => 'Artist',
|
80
|
+
:CMT => "Comment\r\n2nd line",
|
81
|
+
:COVR => nil,
|
82
|
+
:CPIL => 0,
|
83
|
+
:CPRT => nil,
|
84
|
+
:DAY => '2004',
|
85
|
+
:DISK => [3,4],
|
86
|
+
:GNRE => 'Acid Jazz',
|
87
|
+
:GRP => 'Grouping',
|
88
|
+
:NAM => 'Name',
|
89
|
+
:TMPO => 100,
|
90
|
+
:TOO => 'iTunes v4.6.0.15, QuickTime 6.5.1',
|
91
|
+
:TRKN => [1,2],
|
92
|
+
:WRT => 'Composer',
|
93
|
+
:VERSION => 4,
|
94
|
+
:LAYER => 1,
|
95
|
+
:BITRATE => 50,
|
96
|
+
:FREQUENCY => 44.1,
|
97
|
+
:SIZE => 6962,
|
98
|
+
:SECS => 1,
|
99
|
+
:MM => 0,
|
100
|
+
:SS => 1,
|
101
|
+
:MS => 90,
|
102
|
+
:TIME => '00:01',
|
103
|
+
:COPYRIGHT => nil,
|
104
|
+
:ENCRYPTED => nil
|
105
|
+
}
|
106
|
+
|
107
|
+
mp4 = MP4Info.open(file)
|
108
|
+
|
109
|
+
info.each do |key, value|
|
110
|
+
assert_equal(value, mp4.send(key))
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
# Test an mp4 file created by the Nero encoder
|
115
|
+
def test_nero
|
116
|
+
file = "nero.mp4"
|
117
|
+
|
118
|
+
info = {
|
119
|
+
:ALB => nil,
|
120
|
+
:APID => nil,
|
121
|
+
:ART => 'Artist',
|
122
|
+
:CMT => nil,
|
123
|
+
:COVR => nil,
|
124
|
+
:CPIL => nil,
|
125
|
+
:CPRT => nil,
|
126
|
+
:DAY => nil,
|
127
|
+
:DISK => nil,
|
128
|
+
:GNRE => nil,
|
129
|
+
:GRP => nil,
|
130
|
+
:NAM => 'Name',
|
131
|
+
:TMPO => nil,
|
132
|
+
:TOO => 'Nero AAC Codec 2.9.9.91',
|
133
|
+
:TRKN => nil,
|
134
|
+
:WRT => nil,
|
135
|
+
:VERSION => 4,
|
136
|
+
:LAYER => 1,
|
137
|
+
:BITRATE => 21,
|
138
|
+
:FREQUENCY => 8,
|
139
|
+
:SIZE => 3030,
|
140
|
+
:SECS => 1,
|
141
|
+
:MM => 0,
|
142
|
+
:SS => 1,
|
143
|
+
:MS => 153,
|
144
|
+
:TIME => '00:01',
|
145
|
+
:COPYRIGHT => nil,
|
146
|
+
:ENCRYPTED => nil
|
147
|
+
}
|
148
|
+
|
149
|
+
mp4 = MP4Info.open(file)
|
150
|
+
|
151
|
+
info.each do |key, value|
|
152
|
+
assert_equal(value, mp4.send(key))
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
# Test an mp4 file created by the Real (Helix Producer) encoder
|
157
|
+
#
|
158
|
+
# This test will fail because MP4Info does not support Unicode
|
159
|
+
# strings; see bug 3512
|
160
|
+
# (http://rubyforge.org/tracker/index.php?func=detail&aid=3512&group_id=1175&atid=4589)
|
161
|
+
def test_real
|
162
|
+
file = "real.m4a"
|
163
|
+
|
164
|
+
info = {
|
165
|
+
:ALB => 'Album',
|
166
|
+
:APID => nil,
|
167
|
+
:ART => 'AÆtist',
|
168
|
+
:CMT => 'Comment',
|
169
|
+
:COVR => nil,
|
170
|
+
:CPIL => nil,
|
171
|
+
:CPRT => nil,
|
172
|
+
:DAY => "2004",
|
173
|
+
:DISK => [0, 0],
|
174
|
+
:GNRE => 'Acid Jazz',
|
175
|
+
:GRP => nil,
|
176
|
+
:NAM => 'N™me',
|
177
|
+
:TMPO => nil,
|
178
|
+
:TOO => 'Helix Producer SDK 10.0 for Windows, Build 10.0.0.240',
|
179
|
+
:TRKN => [1,0],
|
180
|
+
:WRT => nil,
|
181
|
+
:VERSION => 4,
|
182
|
+
:LAYER => 1,
|
183
|
+
:BITRATE => 93,
|
184
|
+
:FREQUENCY => 1, # What part of "the sampling rate of the audio should be ... documented in the samplerate field" don't Real understand?
|
185
|
+
:SIZE => 131682,
|
186
|
+
:SECS => 11,
|
187
|
+
:MM => 0,
|
188
|
+
:SS => 11,
|
189
|
+
:MS => 53,
|
190
|
+
:TIME => '00:11',
|
191
|
+
:COPYRIGHT => nil,
|
192
|
+
:ENCRYPTED => nil
|
193
|
+
}
|
194
|
+
|
195
|
+
mp4 = MP4Info.open(file)
|
196
|
+
|
197
|
+
info.each do |key, value|
|
198
|
+
assert_equal(value, mp4.send(key), "bad #{key}")
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mp4info
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 1
|
7
|
+
- 7
|
8
|
+
- 3
|
9
|
+
version: 1.7.3
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- arbarlow
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2009-09-17 00:00:00 +01:00
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: Rubygem for getting and setting mp4 info
|
22
|
+
email: alexbarlowis@me.com
|
23
|
+
executables: []
|
24
|
+
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files:
|
28
|
+
- README.rdoc
|
29
|
+
files:
|
30
|
+
- docs/license.txt
|
31
|
+
- lib/mp4info-windows-binmode.patch
|
32
|
+
- lib/mp4info.rb
|
33
|
+
- README.rdoc
|
34
|
+
has_rdoc: true
|
35
|
+
homepage: http://github.com/arbarlow/ruby-mp4info/
|
36
|
+
licenses: []
|
37
|
+
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options:
|
40
|
+
- --charset=UTF-8
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
segments:
|
48
|
+
- 0
|
49
|
+
version: "0"
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
segments:
|
55
|
+
- 0
|
56
|
+
version: "0"
|
57
|
+
requirements: []
|
58
|
+
|
59
|
+
rubyforge_project:
|
60
|
+
rubygems_version: 1.3.6
|
61
|
+
signing_key:
|
62
|
+
specification_version: 3
|
63
|
+
summary: Rubygem for getting and setting mp4 info
|
64
|
+
test_files:
|
65
|
+
- test/test.rb
|