id3_tags 0.0.1
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/.gitignore +16 -0
- data/.rspec +1 -0
- data/Gemfile +6 -0
- data/HISTORY.md +1 -0
- data/MIT-LICENSE +20 -0
- data/README.md +32 -0
- data/Rakefile +12 -0
- data/TODO.md +2 -0
- data/doc/Id3Tags.html +495 -0
- data/doc/_index.html +110 -0
- data/doc/class_list.html +53 -0
- data/doc/css/common.css +1 -0
- data/doc/css/full_list.css +57 -0
- data/doc/css/style.css +338 -0
- data/doc/file.README.html +102 -0
- data/doc/file_list.html +55 -0
- data/doc/frames.html +28 -0
- data/doc/index.html +102 -0
- data/doc/js/app.js +214 -0
- data/doc/js/full_list.js +178 -0
- data/doc/js/jquery.js +4 -0
- data/doc/method_list.html +64 -0
- data/doc/top-level-namespace.html +112 -0
- data/id3_tags.gemspec +30 -0
- data/lib/id3_tags/version.rb +3 -0
- data/lib/id3_tags.rb +182 -0
- data/spec/assets/all_id3.mp3 +0 -0
- data/spec/assets/black_pixel.png +0 -0
- data/spec/assets/no_id3.mp3 +0 -0
- data/spec/helpers/duplicate_file_helper.rb +11 -0
- data/spec/lib/idempotency_spec.rb +14 -0
- data/spec/lib/read_id3_tags_spec.rb +72 -0
- data/spec/lib/write_id3_tags_spec.rb +67 -0
- metadata +207 -0
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/HISTORY.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
v0.0.1 - 2013/06/13 Implements `read_tags_from` and `write_tags_to`
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2013 Topspin Media Inc.
|
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,32 @@
|
|
1
|
+
What is ID3 Tags
|
2
|
+
================
|
3
|
+
|
4
|
+
A ruby gem to read and write ID3 metadata from/to MP3 files}
|
5
|
+
|
6
|
+
Why ID3 Tags was born
|
7
|
+
=======================
|
8
|
+
|
9
|
+
At [Topspin](http://topspinmedia.com) we provide [ArtistLink](http://artistlink.com), a platform for musician to upload and share their songs.
|
10
|
+
Artistlink provides a form to read and edit the songs' metadata and stores this information in the ID3 tags of a song.
|
11
|
+
For this task, we created the ID3 Tags gem
|
12
|
+
|
13
|
+
How to install
|
14
|
+
==============
|
15
|
+
|
16
|
+
Run `gem install id3_tags`.
|
17
|
+
Alternatively, you can include `id3_tags` in the Gemfile of your bundled project.
|
18
|
+
|
19
|
+
How to use
|
20
|
+
==========
|
21
|
+
|
22
|
+
* To read metadata from a file, run `Id3Tags.read_from_file(file_path)`
|
23
|
+
* To write metadata to a file, run `Id3Tags.write_to_file(file_path, metadata)`
|
24
|
+
|
25
|
+
For more details about the format of the metadata, check the [specs](http://github.com/topspin/id3_tags/tree/master/spec/lib) or the [documentation at RubyDoc.info](http://rubydoc.info/github/topspin/id3_tags/frames).
|
26
|
+
|
27
|
+
How to contribute
|
28
|
+
=================
|
29
|
+
|
30
|
+
Make sure tests pass, then either submit a Pull Request.
|
31
|
+
A list of [nice TODOs](http://github.com/topspin/id3_tags/tree/master/TODO.md) is provided.
|
32
|
+
You can also build a new version of the gem and move it to your gem repository.
|
data/Rakefile
ADDED
data/TODO.md
ADDED
data/doc/Id3Tags.html
ADDED
@@ -0,0 +1,495 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
4
|
+
<head>
|
5
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
6
|
+
<title>
|
7
|
+
Module: Id3Tags
|
8
|
+
|
9
|
+
— Documentation by YARD 0.8.6.1
|
10
|
+
|
11
|
+
</title>
|
12
|
+
|
13
|
+
<link rel="stylesheet" href="css/style.css" type="text/css" charset="utf-8" />
|
14
|
+
|
15
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" charset="utf-8" />
|
16
|
+
|
17
|
+
<script type="text/javascript" charset="utf-8">
|
18
|
+
hasFrames = window.top.frames.main ? true : false;
|
19
|
+
relpath = '';
|
20
|
+
framesUrl = "frames.html#!" + escape(window.location.href);
|
21
|
+
</script>
|
22
|
+
|
23
|
+
|
24
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
25
|
+
|
26
|
+
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
|
27
|
+
|
28
|
+
|
29
|
+
</head>
|
30
|
+
<body>
|
31
|
+
<div id="header">
|
32
|
+
<div id="menu">
|
33
|
+
|
34
|
+
<a href="_index.html">Index (I)</a> »
|
35
|
+
|
36
|
+
|
37
|
+
<span class="title">Id3Tags</span>
|
38
|
+
|
39
|
+
|
40
|
+
<div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
|
41
|
+
</div>
|
42
|
+
|
43
|
+
<div id="search">
|
44
|
+
|
45
|
+
<a class="full_list_link" id="class_list_link"
|
46
|
+
href="class_list.html">
|
47
|
+
Class List
|
48
|
+
</a>
|
49
|
+
|
50
|
+
<a class="full_list_link" id="method_list_link"
|
51
|
+
href="method_list.html">
|
52
|
+
Method List
|
53
|
+
</a>
|
54
|
+
|
55
|
+
<a class="full_list_link" id="file_list_link"
|
56
|
+
href="file_list.html">
|
57
|
+
File List
|
58
|
+
</a>
|
59
|
+
|
60
|
+
</div>
|
61
|
+
<div class="clear"></div>
|
62
|
+
</div>
|
63
|
+
|
64
|
+
<iframe id="search_frame"></iframe>
|
65
|
+
|
66
|
+
<div id="content"><h1>Module: Id3Tags
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
</h1>
|
71
|
+
|
72
|
+
<dl class="box">
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
<dt class="r1 last">Defined in:</dt>
|
82
|
+
<dd class="r1 last">lib/id3_tags.rb<span class="defines">,<br />
|
83
|
+
lib/id3_tags/version.rb</span>
|
84
|
+
</dd>
|
85
|
+
|
86
|
+
</dl>
|
87
|
+
<div class="clear"></div>
|
88
|
+
|
89
|
+
<h2>Overview</h2><div class="docstring">
|
90
|
+
<div class="discussion">
|
91
|
+
<p>
|
92
|
+
Provides two methods to read and write ID3 metadata from an MP3 file
|
93
|
+
</p>
|
94
|
+
|
95
|
+
|
96
|
+
</div>
|
97
|
+
</div>
|
98
|
+
<div class="tags">
|
99
|
+
|
100
|
+
|
101
|
+
</div>
|
102
|
+
<h2>Constant Summary</h2>
|
103
|
+
|
104
|
+
<dl class="constants">
|
105
|
+
|
106
|
+
<dt id="VERSION-constant" class="">VERSION =
|
107
|
+
|
108
|
+
</dt>
|
109
|
+
<dd><pre class="code"><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>0.0.1</span><span class='tstring_end'>'</span></span></pre></dd>
|
110
|
+
|
111
|
+
</dl>
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
<h2>
|
122
|
+
Class Method Summary
|
123
|
+
<small>(<a href="#" class="summary_toggle">collapse</a>)</small>
|
124
|
+
</h2>
|
125
|
+
|
126
|
+
<ul class="summary">
|
127
|
+
|
128
|
+
<li class="public ">
|
129
|
+
<span class="summary_signature">
|
130
|
+
|
131
|
+
<a href="#read_tags_from-class_method" title="read_tags_from (class method)">+ (Hash) <strong>read_tags_from</strong>(file_path) </a>
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
</span>
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
<span class="summary_desc"><div class='inline'><p>
|
146
|
+
Returns a Hash of ID3 attributes stored in the file located at
|
147
|
+
<tt>file_path</tt>.
|
148
|
+
</p>
|
149
|
+
</div></span>
|
150
|
+
|
151
|
+
</li>
|
152
|
+
|
153
|
+
|
154
|
+
<li class="public ">
|
155
|
+
<span class="summary_signature">
|
156
|
+
|
157
|
+
<a href="#write_tags_to-class_method" title="write_tags_to (class method)">+ (Boolean) <strong>write_tags_to</strong>(file_path, attrs = {}) </a>
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
</span>
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
<span class="summary_desc"><div class='inline'><p>
|
172
|
+
Stores the <tt>attrs</tt> Hash of ID3 attributes into the file at
|
173
|
+
<tt>file_path</tt>.
|
174
|
+
</p>
|
175
|
+
</div></span>
|
176
|
+
|
177
|
+
</li>
|
178
|
+
|
179
|
+
|
180
|
+
</ul>
|
181
|
+
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
<div id="class_method_details" class="method_details_list">
|
186
|
+
<h2>Class Method Details</h2>
|
187
|
+
|
188
|
+
|
189
|
+
<div class="method_details first">
|
190
|
+
<h3 class="signature first" id="read_tags_from-class_method">
|
191
|
+
|
192
|
+
+ (<tt>Hash</tt>) <strong>read_tags_from</strong>(file_path)
|
193
|
+
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
|
198
|
+
</h3><div class="docstring">
|
199
|
+
<div class="discussion">
|
200
|
+
<p>
|
201
|
+
Returns a Hash of ID3 attributes stored in the file located at
|
202
|
+
<tt>file_path</tt>.
|
203
|
+
</p>
|
204
|
+
|
205
|
+
|
206
|
+
</div>
|
207
|
+
</div>
|
208
|
+
<div class="tags">
|
209
|
+
|
210
|
+
<div class="examples">
|
211
|
+
<p class="tag_title">Examples:</p>
|
212
|
+
|
213
|
+
|
214
|
+
<p class="example_title"><div class='inline'><p>
|
215
|
+
Read tags from an MP3 full of metadata
|
216
|
+
</p>
|
217
|
+
</div></p>
|
218
|
+
|
219
|
+
<pre class="example code"><code>Id3Tags.read_tags_from("all_id3.mp3")
|
220
|
+
|
221
|
+
# => {title: "Sample track", album: "Sample album", artist: Sample
|
222
|
+
artist", :comment=>"Sample comments", genre: "Sample Genre",
|
223
|
+
year: 1979, bitrate: 128, channels: 2, length: 38, samplerate:
|
224
|
+
44100, bpm: 110, lyrics: "Sample lyrics line 1\rand line 2",
|
225
|
+
composer: "Sample composer", grouping: "Sample group",
|
226
|
+
album_artist: "Sample album artist", compilation: true, track:
|
227
|
+
{number: 3, count: 12}, disk: {number: 1, count: 2}, cover_art:
|
228
|
+
{mime_type: "image/png", data: "\x89PNG\r\n\x1A[...]"}}</code></pre>
|
229
|
+
|
230
|
+
</div>
|
231
|
+
<p class="tag_title">Parameters:</p>
|
232
|
+
<ul class="param">
|
233
|
+
|
234
|
+
<li>
|
235
|
+
|
236
|
+
<span class='name'>file_path</span>
|
237
|
+
|
238
|
+
|
239
|
+
<span class='type'>(<tt>String</tt>)</span>
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
—
|
244
|
+
<div class='inline'><p>
|
245
|
+
Local path to an MP3 file
|
246
|
+
</p>
|
247
|
+
</div>
|
248
|
+
|
249
|
+
</li>
|
250
|
+
|
251
|
+
</ul>
|
252
|
+
|
253
|
+
<p class="tag_title">Returns:</p>
|
254
|
+
<ul class="return">
|
255
|
+
|
256
|
+
<li>
|
257
|
+
|
258
|
+
|
259
|
+
<span class='type'>(<tt>Hash</tt>)</span>
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
—
|
264
|
+
<div class='inline'><p>
|
265
|
+
the ID3 attributes stored in the file
|
266
|
+
</p>
|
267
|
+
</div>
|
268
|
+
|
269
|
+
</li>
|
270
|
+
|
271
|
+
</ul>
|
272
|
+
|
273
|
+
</div><table class="source_code">
|
274
|
+
<tr>
|
275
|
+
<td>
|
276
|
+
<pre class="lines">
|
277
|
+
|
278
|
+
|
279
|
+
23
|
280
|
+
24
|
281
|
+
25
|
282
|
+
26
|
283
|
+
27
|
284
|
+
28
|
285
|
+
29
|
286
|
+
30
|
287
|
+
31
|
288
|
+
32
|
289
|
+
33
|
290
|
+
34
|
291
|
+
35
|
292
|
+
36
|
293
|
+
37
|
294
|
+
38
|
295
|
+
39
|
296
|
+
40
|
297
|
+
41
|
298
|
+
42
|
299
|
+
43
|
300
|
+
44</pre>
|
301
|
+
</td>
|
302
|
+
<td>
|
303
|
+
<pre class="code"><span class="info file"># File 'lib/id3_tags.rb', line 23</span>
|
304
|
+
|
305
|
+
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_read_tags_from'>read_tags_from</span><span class='lparen'>(</span><span class='id identifier rubyid_file_path'>file_path</span><span class='rparen'>)</span>
|
306
|
+
<span class='id identifier rubyid_attrs'>attrs</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span>
|
307
|
+
<span class='const'>TagLib</span><span class='op'>::</span><span class='const'>MPEG</span><span class='op'>::</span><span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_open'>open</span><span class='lparen'>(</span><span class='id identifier rubyid_file_path'>file_path</span><span class='rparen'>)</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_file'>file</span><span class='op'>|</span>
|
308
|
+
<span class='id identifier rubyid_tag_fields'>tag_fields</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_field'>field</span><span class='comma'>,</span> <span class='id identifier rubyid_opts'>opts</span><span class='op'>|</span>
|
309
|
+
<span class='id identifier rubyid_value'>value</span> <span class='op'>=</span> <span class='id identifier rubyid_file'>file</span><span class='period'>.</span><span class='id identifier rubyid_tag'>tag</span><span class='period'>.</span><span class='id identifier rubyid_send'>send</span> <span class='id identifier rubyid_opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:method</span><span class='rbracket'>]</span>
|
310
|
+
<span class='id identifier rubyid_assign!'>assign!</span> <span class='id identifier rubyid_attrs'>attrs</span><span class='comma'>,</span> <span class='id identifier rubyid_field'>field</span><span class='comma'>,</span> <span class='id identifier rubyid_value'>value</span><span class='comma'>,</span> <span class='id identifier rubyid_opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:type</span><span class='rbracket'>]</span>
|
311
|
+
<span class='kw'>end</span> <span class='kw'>unless</span> <span class='id identifier rubyid_file'>file</span><span class='period'>.</span><span class='id identifier rubyid_tag'>tag</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span>
|
312
|
+
|
313
|
+
<span class='id identifier rubyid_audio_properties_fields'>audio_properties_fields</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_field'>field</span><span class='comma'>,</span> <span class='id identifier rubyid_opts'>opts</span><span class='op'>|</span>
|
314
|
+
<span class='id identifier rubyid_value'>value</span> <span class='op'>=</span> <span class='id identifier rubyid_file'>file</span><span class='period'>.</span><span class='id identifier rubyid_audio_properties'>audio_properties</span><span class='period'>.</span><span class='id identifier rubyid_send'>send</span> <span class='id identifier rubyid_opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:method</span><span class='rbracket'>]</span>
|
315
|
+
<span class='id identifier rubyid_assign!'>assign!</span> <span class='id identifier rubyid_attrs'>attrs</span><span class='comma'>,</span> <span class='id identifier rubyid_field'>field</span><span class='comma'>,</span> <span class='id identifier rubyid_value'>value</span><span class='comma'>,</span> <span class='id identifier rubyid_opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:type</span><span class='rbracket'>]</span>
|
316
|
+
<span class='kw'>end</span> <span class='kw'>unless</span> <span class='id identifier rubyid_file'>file</span><span class='period'>.</span><span class='id identifier rubyid_audio_properties'>audio_properties</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span>
|
317
|
+
|
318
|
+
<span class='id identifier rubyid_id3v2_tag_fields'>id3v2_tag_fields</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_field'>field</span><span class='comma'>,</span> <span class='id identifier rubyid_opts'>opts</span><span class='op'>|</span>
|
319
|
+
<span class='id identifier rubyid_value'>value</span> <span class='op'>=</span> <span class='id identifier rubyid_file'>file</span><span class='period'>.</span><span class='id identifier rubyid_id3v2_tag'>id3v2_tag</span><span class='period'>.</span><span class='id identifier rubyid_frame_list'>frame_list</span><span class='lparen'>(</span><span class='id identifier rubyid_opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:frame_id</span><span class='rbracket'>]</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_first'>first</span>
|
320
|
+
<span class='id identifier rubyid_value'>value</span> <span class='op'>=</span> <span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_to_string'>to_string</span> <span class='kw'>if</span> <span class='id identifier rubyid_value'>value</span> <span class='kw'>and</span> <span class='id identifier rubyid_opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:type</span><span class='rbracket'>]</span> <span class='op'>!=</span> <span class='symbol'>:image</span>
|
321
|
+
<span class='id identifier rubyid_assign!'>assign!</span> <span class='id identifier rubyid_attrs'>attrs</span><span class='comma'>,</span> <span class='id identifier rubyid_field'>field</span><span class='comma'>,</span> <span class='id identifier rubyid_value'>value</span><span class='comma'>,</span> <span class='id identifier rubyid_opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:type</span><span class='rbracket'>]</span>
|
322
|
+
<span class='kw'>end</span> <span class='kw'>unless</span> <span class='id identifier rubyid_file'>file</span><span class='period'>.</span><span class='id identifier rubyid_id3v2_tag'>id3v2_tag</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span>
|
323
|
+
<span class='kw'>end</span>
|
324
|
+
|
325
|
+
<span class='id identifier rubyid_attrs'>attrs</span><span class='period'>.</span><span class='id identifier rubyid_symbolize_keys'>symbolize_keys</span>
|
326
|
+
<span class='kw'>end</span></pre>
|
327
|
+
</td>
|
328
|
+
</tr>
|
329
|
+
</table>
|
330
|
+
</div>
|
331
|
+
|
332
|
+
<div class="method_details ">
|
333
|
+
<h3 class="signature " id="write_tags_to-class_method">
|
334
|
+
|
335
|
+
+ (<tt>Boolean</tt>) <strong>write_tags_to</strong>(file_path, attrs = {})
|
336
|
+
|
337
|
+
|
338
|
+
|
339
|
+
|
340
|
+
|
341
|
+
</h3><div class="docstring">
|
342
|
+
<div class="discussion">
|
343
|
+
<p>
|
344
|
+
Stores the <tt>attrs</tt> Hash of ID3 attributes into the file at
|
345
|
+
<tt>file_path</tt>.
|
346
|
+
</p>
|
347
|
+
|
348
|
+
|
349
|
+
</div>
|
350
|
+
</div>
|
351
|
+
<div class="tags">
|
352
|
+
|
353
|
+
<div class="examples">
|
354
|
+
<p class="tag_title">Examples:</p>
|
355
|
+
|
356
|
+
|
357
|
+
<p class="example_title"><div class='inline'><p>
|
358
|
+
Write ID3 tags to an MP3 file
|
359
|
+
</p>
|
360
|
+
</div></p>
|
361
|
+
|
362
|
+
<pre class="example code"><code>Id3Tags.write_tags_to("no_id3.mp3", {title: "Sample track", album:
|
363
|
+
"Sample album", artist: Sample artist", :comment=>"Sample comments",
|
364
|
+
genre: "Sample Genre", year: 1979, bitrate: 128, channels: 2,
|
365
|
+
length: 38, samplerate: 44100, bpm: 110, lyrics: "Sample lyrics
|
366
|
+
line 1\rand line 2", composer: "Sample composer", grouping: "Sample
|
367
|
+
group", album_artist: "Sample album artist", compilation: true,
|
368
|
+
track: {number: 3, count: 12}, disk: {number: 1, count: 2},
|
369
|
+
cover_art: {mime_type: "image/png", data: "\x89PNG\r\n\x1A[...]"}}
|
370
|
+
|
371
|
+
# => true</code></pre>
|
372
|
+
|
373
|
+
</div>
|
374
|
+
<p class="tag_title">Parameters:</p>
|
375
|
+
<ul class="param">
|
376
|
+
|
377
|
+
<li>
|
378
|
+
|
379
|
+
<span class='name'>file_path</span>
|
380
|
+
|
381
|
+
|
382
|
+
<span class='type'>(<tt>String</tt>)</span>
|
383
|
+
|
384
|
+
|
385
|
+
|
386
|
+
—
|
387
|
+
<div class='inline'><p>
|
388
|
+
Local path to an MP3 file
|
389
|
+
</p>
|
390
|
+
</div>
|
391
|
+
|
392
|
+
</li>
|
393
|
+
|
394
|
+
<li>
|
395
|
+
|
396
|
+
<span class='name'>attrs</span>
|
397
|
+
|
398
|
+
|
399
|
+
<span class='type'>(<tt>Hash</tt>)</span>
|
400
|
+
|
401
|
+
|
402
|
+
<em class="default">(defaults to: <tt>{}</tt>)</em>
|
403
|
+
|
404
|
+
|
405
|
+
—
|
406
|
+
<div class='inline'><p>
|
407
|
+
the ID3 attributes stored in the file
|
408
|
+
</p>
|
409
|
+
</div>
|
410
|
+
|
411
|
+
</li>
|
412
|
+
|
413
|
+
</ul>
|
414
|
+
|
415
|
+
<p class="tag_title">Returns:</p>
|
416
|
+
<ul class="return">
|
417
|
+
|
418
|
+
<li>
|
419
|
+
|
420
|
+
|
421
|
+
<span class='type'>(<tt>Boolean</tt>)</span>
|
422
|
+
|
423
|
+
|
424
|
+
|
425
|
+
—
|
426
|
+
<div class='inline'><p>
|
427
|
+
true (the file gets changed)
|
428
|
+
</p>
|
429
|
+
</div>
|
430
|
+
|
431
|
+
</li>
|
432
|
+
|
433
|
+
</ul>
|
434
|
+
|
435
|
+
</div><table class="source_code">
|
436
|
+
<tr>
|
437
|
+
<td>
|
438
|
+
<pre class="lines">
|
439
|
+
|
440
|
+
|
441
|
+
63
|
442
|
+
64
|
443
|
+
65
|
444
|
+
66
|
445
|
+
67
|
446
|
+
68
|
447
|
+
69
|
448
|
+
70
|
449
|
+
71
|
450
|
+
72
|
451
|
+
73
|
452
|
+
74
|
453
|
+
75
|
454
|
+
76
|
455
|
+
77
|
456
|
+
78
|
457
|
+
79</pre>
|
458
|
+
</td>
|
459
|
+
<td>
|
460
|
+
<pre class="code"><span class="info file"># File 'lib/id3_tags.rb', line 63</span>
|
461
|
+
|
462
|
+
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_write_tags_to'>write_tags_to</span><span class='lparen'>(</span><span class='id identifier rubyid_file_path'>file_path</span><span class='comma'>,</span> <span class='id identifier rubyid_attrs'>attrs</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span>
|
463
|
+
<span class='id identifier rubyid_attrs'>attrs</span><span class='period'>.</span><span class='id identifier rubyid_symbolize_keys!'>symbolize_keys!</span>
|
464
|
+
|
465
|
+
<span class='const'>TagLib</span><span class='op'>::</span><span class='const'>MPEG</span><span class='op'>::</span><span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_open'>open</span><span class='lparen'>(</span><span class='id identifier rubyid_file_path'>file_path</span><span class='rparen'>)</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_file'>file</span><span class='op'>|</span>
|
466
|
+
<span class='id identifier rubyid_tag_fields'>tag_fields</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_field'>field</span><span class='comma'>,</span> <span class='id identifier rubyid_opts'>opts</span><span class='op'>|</span>
|
467
|
+
<span class='id identifier rubyid_file'>file</span><span class='period'>.</span><span class='id identifier rubyid_tag'>tag</span><span class='period'>.</span><span class='id identifier rubyid_send'>send</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:method</span><span class='rbracket'>]</span><span class='rbrace'>}</span><span class='tstring_content'>=</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='lparen'>(</span><span class='id identifier rubyid_attrs'>attrs</span><span class='lbracket'>[</span><span class='id identifier rubyid_field'>field</span><span class='rbracket'>]</span> <span class='op'>||</span> <span class='id identifier rubyid_opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:default</span><span class='rbracket'>]</span><span class='rparen'>)</span>
|
468
|
+
<span class='kw'>end</span> <span class='kw'>unless</span> <span class='id identifier rubyid_file'>file</span><span class='period'>.</span><span class='id identifier rubyid_tag'>tag</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span>
|
469
|
+
|
470
|
+
<span class='id identifier rubyid_id3v2_tag_fields'>id3v2_tag_fields</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_field'>field</span><span class='comma'>,</span> <span class='id identifier rubyid_opts'>opts</span><span class='op'>|</span>
|
471
|
+
<span class='id identifier rubyid_file'>file</span><span class='period'>.</span><span class='id identifier rubyid_id3v2_tag'>id3v2_tag</span><span class='period'>.</span><span class='id identifier rubyid_remove_frames'>remove_frames</span> <span class='id identifier rubyid_opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:frame_id</span><span class='rbracket'>]</span>
|
472
|
+
<span class='id identifier rubyid_frame'>frame</span> <span class='op'>=</span> <span class='id identifier rubyid_new_frame_for'>new_frame_for</span> <span class='id identifier rubyid_attrs'>attrs</span><span class='lbracket'>[</span><span class='id identifier rubyid_field'>field</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='id identifier rubyid_opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:frame_id</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='id identifier rubyid_opts'>opts</span><span class='lbracket'>[</span><span class='symbol'>:type</span><span class='rbracket'>]</span>
|
473
|
+
<span class='id identifier rubyid_file'>file</span><span class='period'>.</span><span class='id identifier rubyid_id3v2_tag'>id3v2_tag</span><span class='period'>.</span><span class='id identifier rubyid_add_frame'>add_frame</span> <span class='id identifier rubyid_frame'>frame</span> <span class='kw'>if</span> <span class='id identifier rubyid_frame'>frame</span>
|
474
|
+
<span class='kw'>end</span> <span class='kw'>unless</span> <span class='id identifier rubyid_file'>file</span><span class='period'>.</span><span class='id identifier rubyid_id3v2_tag'>id3v2_tag</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span>
|
475
|
+
|
476
|
+
<span class='id identifier rubyid_file'>file</span><span class='period'>.</span><span class='id identifier rubyid_save'>save</span>
|
477
|
+
<span class='kw'>end</span>
|
478
|
+
<span class='kw'>end</span></pre>
|
479
|
+
</td>
|
480
|
+
</tr>
|
481
|
+
</table>
|
482
|
+
</div>
|
483
|
+
|
484
|
+
</div>
|
485
|
+
|
486
|
+
</div>
|
487
|
+
|
488
|
+
<div id="footer">
|
489
|
+
Generated on Fri Jun 14 11:03:18 2013 by
|
490
|
+
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
491
|
+
0.8.6.1 (ruby-1.9.2).
|
492
|
+
</div>
|
493
|
+
|
494
|
+
</body>
|
495
|
+
</html>
|