• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

palfrey / tagpy / 24634022518

19 Apr 2026 04:42PM UTC coverage: 66.259% (-25.4%) from 91.613%
24634022518

Pull #62

github

web-flow
Merge 45cbfd92f into 1750d723e
Pull Request #62: Remove ignore-errors from lcov

448 of 945 branches covered (47.41%)

Branch coverage included in aggregate %.

689 of 771 relevant lines covered (89.36%)

46.66 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

66.94
/src/wrapper/rest.cpp
1
// Copyright (c) 2006-2008 Andreas Kloeckner
2
//
3
// Permission is hereby granted, free of charge, to any person obtaining a copy
4
// of this software and associated documentation files (the "Software"), to
5
// deal in the Software without restriction, including without limitation the
6
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7
// sell copies of the Software, and to permit persons to whom the Software is
8
// furnished to do so, subject to the following conditions:
9
//
10
// The above copyright notice and this permission notice shall be included in
11
// all copies or substantial portions of the Software.
12
//
13
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19
// IN THE SOFTWARE.
20

21

22

23

24
#include <taglib/apetag.h>
25
#include <taglib/mpcfile.h>
26
#include <taglib/flacfile.h>
27
#include <taglib/xiphcomment.h>
28
#include <taglib/oggflacfile.h>
29
#include <taglib/vorbisfile.h>
30
#include <taglib/apefooter.h>
31
#include <taglib/apeitem.h>
32
#include <taglib/id3v1tag.h>
33
#include <taglib/id3v2tag.h>
34
#include <taglib/wavfile.h>
35
#include <taglib/mp4file.h>
36
#include <taglib/mp4tag.h>
37
#include <taglib/mp4coverart.h>
38
#include <taglib/mp4item.h>
39
#include <taglib/opusfile.h>
40

41
#include "common.hpp"
42

43

44

45

46
namespace
47
{
48
  // -------------------------------------------------------------
49
  // FLAC
50
  // -------------------------------------------------------------
51
  MF_OL(ID3v1Tag, 0, 1);
×
52
  MF_OL(ID3v2Tag, 0, 1);
×
53
  MF_OL(xiphComment, 0, 1);
×
54

55
  // -------------------------------------------------------------
56
  // Ogg
57
  // -------------------------------------------------------------
58
  MF_OL(addField, 2, 3);
×
59
  #if TAGLIB_HEX_VERSION < CHECK_VERSION(1,11,0)
60
  MF_OL(removeField, 1, 2);
61
  #else
62
  MF_OL(removeFields, 1, 2);
63
  #endif
64
  MF_OL(render, 0, 1);
×
65

66
  // -------------------------------------------------------------
67
  // APE
68
  // -------------------------------------------------------------
69
  MF_OL(addValue, 2, 3);
×
70

71
  // -------------------------------------------------------------
72
  // MPC
73
  // -------------------------------------------------------------
74
  #if (TAGLIB_MAJOR_VERSION == 1)
75
  MF_OL(remove, 0, 1);
76
  #endif
77
  //MF_OL(ID3v1Tag, 0, 1);
78
  MF_OL(APETag, 0, 1);
×
79

80
  // WAV
81
  MF_OL(strip, 0, 1);
×
82

83
  #if TAGLIB_HEX_VERSION >= CHECK_VERSION(1,10,0)
84
  // MP4
85
  TagLib::MP4::CoverArtList mp4_Tag_GetCovers(TagLib::MP4::Tag &t) {
86
    if (!t.contains("covr")) {
×
87
      return {};
88
    }
89
    return t.item("covr").toCoverArtList();
×
90
  }
91
  void mp4_Tag_SetCovers(TagLib::MP4::Tag &t, TagLib::MP4::CoverArtList& l) {
25✔
92
    return t.setItem("covr", l);
25!
93
  }
94
  #endif
95
}
96

97
#if TAGLIB_HEX_VERSION >= CHECK_VERSION(1,11,0)
98
void addPictureWithOwnership(Ogg::XiphComment &cl, std::auto_ptr<TagLib::FLAC::Picture> picture) {
20✔
99
  cl.addPicture(picture.get());
20✔
100
  picture.release();
20✔
101
}
20✔
102
#endif
103

104
void flacAddPictureWithOwnership(FLAC::File &cl, std::auto_ptr<TagLib::FLAC::Picture> picture) {
30✔
105
  cl.addPicture(picture.get());
30✔
106
  picture.release();
30✔
107
}
30✔
108

109
void flacAddPictureCopy(FLAC::File &cl, TagLib::FLAC::Picture *picture) {
60✔
110
  TagLib::FLAC::Picture *picture_copy = new TagLib::FLAC::Picture(picture->render());
60!
111
  cl.addPicture(picture_copy);
60✔
112
}
60✔
113

114
void exposeRest()
30✔
115
{
116
  // -------------------------------------------------------------
117
  // Ogg
118
  // -------------------------------------------------------------
119
  exposeMap<String, StringList>("ogg_FieldListMap");
30✔
120

121
  {
30✔
122
    typedef Ogg::XiphComment cl;
30✔
123
    class_<cl, bases<Tag>, boost::noncopyable>
30✔
124
      ("ogg_XiphComment", init<boost::python::optional<const ByteVector &> >())
30✔
125
      .DEF_SIMPLE_METHOD(fieldCount)
30!
126
      .def("fieldListMap", &cl::fieldListMap,
30!
127
           return_internal_reference<>())
30✔
128
      .DEF_SIMPLE_METHOD(vendorID)
30!
129
      .DEF_OVERLOADED_METHOD(addField, void (cl::*)(const String &, const String &, bool))
30!
130
      #if TAGLIB_HEX_VERSION < CHECK_VERSION(1,11,0)
131
      .DEF_OVERLOADED_METHOD(removeField, void (cl::*)(const String &, const String &))
10!
132
      .DEF_OVERLOADED_METHOD(removeField, void (cl::*)(const String &, const String &))
10!
133
      #else
134
      .DEF_OVERLOADED_METHOD(removeFields, void (cl::*)(const String &, const String &))
20!
135
      .DEF_OVERLOADED_METHOD(removeFields, void (cl::*)(const String &, const String &))
20!
136
      #endif
137
      .DEF_OVERLOADED_METHOD(render, ByteVector (cl::*)(bool) const)
50!
138
      #if TAGLIB_HEX_VERSION >= CHECK_VERSION(1,11,0)
139
      .DEF_SIMPLE_METHOD(pictureList)
20!
140
      .DEF_SIMPLE_METHOD(removeAllPictures)
20!
141
      .def("removePicture", &cl::removePicture)
20!
142
      .def("addPicture", addPictureWithOwnership);
20!
143
      #endif
144
      ;
20✔
145
  }
146

147
  {
30✔
148
    typedef Ogg::File cl;
30✔
149
    class_<cl, bases<File>, boost::noncopyable>
30✔
150
      ("ogg_File", no_init)
151
      .DEF_SIMPLE_METHOD(packet)
30!
152
      .DEF_SIMPLE_METHOD(setPacket)
30!
153
      // MISSING: page headers
154
      ;
155
  }
156

157
  {
30✔
158
    typedef Ogg::FLAC::File cl;
30✔
159
    class_<cl, bases<Ogg::File>, boost::noncopyable>
30✔
160
      ("ogg_flac_File", init<const char *, boost::python::optional<bool, AudioProperties::ReadStyle> >())
30✔
161
      ;
162
  }
163

164
  {
30✔
165
    typedef Ogg::Vorbis::File cl;
30✔
166
    class_<cl, bases<Ogg::File>, boost::noncopyable>
30✔
167
      ("ogg_vorbis_File", init<const char *, boost::python::optional<bool, AudioProperties::ReadStyle> >())
30✔
168
      ;
169
  }
170

171
  {
30✔
172
    typedef Ogg::Opus::File cl;
30✔
173
    class_<cl, bases<Ogg::File>, boost::noncopyable>
30✔
174
      ("ogg_opus_File", init<const char *, boost::python::optional<bool, AudioProperties::ReadStyle> >())
30✔
175
      ;
176
  }
177

178
  // -------------------------------------------------------------
179
  // APE
180
  // -------------------------------------------------------------
181
  {
30✔
182
    typedef APE::Footer cl;
30✔
183
    class_<cl, boost::noncopyable>(
30✔
184
      "ape_Footer", init<boost::python::optional<const ByteVector &> >())
30✔
185
      .DEF_SIMPLE_METHOD(version)
30!
186
      .DEF_SIMPLE_METHOD(headerPresent)
30!
187
      .DEF_SIMPLE_METHOD(footerPresent)
30!
188
      .DEF_SIMPLE_METHOD(isHeader)
30!
189
      .DEF_SIMPLE_METHOD(setHeaderPresent)
30!
190
      .DEF_SIMPLE_METHOD(itemCount)
30!
191
      .DEF_SIMPLE_METHOD(setItemCount)
30!
192
      .DEF_SIMPLE_METHOD(tagSize)
30!
193
      .DEF_SIMPLE_METHOD(completeTagSize)
30!
194
      .DEF_SIMPLE_METHOD(setTagSize)
30!
195
      .DEF_SIMPLE_METHOD(setData)
30!
196
      .DEF_SIMPLE_METHOD(renderFooter)
30!
197
      .DEF_SIMPLE_METHOD(renderHeader)
30!
198
      ;
199
  }
200

201
  {
30✔
202
    typedef APE::Item scope;
30✔
203
    enum_<scope::ItemTypes>("ape_ItemTypes")
30!
204
      .ENUM_VALUE(Text)
30!
205
      .ENUM_VALUE(Binary)
30!
206
      .ENUM_VALUE(Locator)
30!
207
      ;
208
  }
209

210
  {
30✔
211
    typedef APE::Item cl;
30✔
212
    class_<cl>("ape_Item")
30✔
213
      .def(init<const String &, const String &>())
30!
214
      .def(init<const String &, const StringList &>())
30!
215
      .def(init<const cl &>())
60!
216
      .DEF_SIMPLE_METHOD(key)
30!
217
      .DEF_SIMPLE_METHOD(binaryData)
30!
218
      .DEF_SIMPLE_METHOD(size)
30!
219
      .DEF_SIMPLE_METHOD(toString)
30!
220
      .DEF_SIMPLE_METHOD(values)
30!
221
      .DEF_SIMPLE_METHOD(render)
30!
222
      .DEF_SIMPLE_METHOD(parse)
30!
223
      .DEF_SIMPLE_METHOD(setReadOnly)
30!
224
      .DEF_SIMPLE_METHOD(isReadOnly)
30!
225
      .DEF_SIMPLE_METHOD(setType)
30!
226
      .DEF_SIMPLE_METHOD(type)
30!
227
      .DEF_SIMPLE_METHOD(isEmpty)
30!
228
      ;
229
  }
230

231
  exposeMap<const String, APE::Item>("ape_ItemListMap");
30✔
232

233
  {
30✔
234
    typedef APE::Tag cl;
30✔
235
    class_<cl, bases<Tag>, boost::noncopyable>("ape_Tag")
30✔
236
      .def(init<File *, long>())
30!
237
      .def("footer", &cl::footer, return_internal_reference<>())
30!
238
      .def("itemListMap", &cl::itemListMap, return_internal_reference<>())
30!
239
      .DEF_SIMPLE_METHOD(removeItem)
30!
240
      .DEF_OVERLOADED_METHOD(addValue, void (cl::*)(const String &, const String &,bool))
60!
241
      .DEF_SIMPLE_METHOD(setItem)
30!
242
      ;
243
  }
244

245
  // -------------------------------------------------------------
246
  // FLAC
247
  // -------------------------------------------------------------
248
  enum_<TagLib::FLAC::Picture::Type>("flac_PictureType")
30!
249
    .value("Other", TagLib::FLAC::Picture::Type::Other)
30!
250
    .value("FileIcon", TagLib::FLAC::Picture::Type::FileIcon)
30!
251
    .value("OtherFileIcon", TagLib::FLAC::Picture::Type::OtherFileIcon)
30!
252
    .value("FrontCover", TagLib::FLAC::Picture::Type::FrontCover)
30!
253
    .value("BackCover", TagLib::FLAC::Picture::Type::BackCover)
30!
254
    .value("LeafletPage", TagLib::FLAC::Picture::Type::LeafletPage)
30!
255
    .value("Media", TagLib::FLAC::Picture::Type::Media)
30!
256
    .value("LeadArtist", TagLib::FLAC::Picture::Type::LeadArtist)
30!
257
    .value("Artist", TagLib::FLAC::Picture::Type::Artist)
30!
258
    .value("Conductor", TagLib::FLAC::Picture::Type::Conductor)
30!
259
    .value("Band", TagLib::FLAC::Picture::Type::Band)
30!
260
    .value("Composer", TagLib::FLAC::Picture::Type::Composer)
30!
261
    .value("Lyricist", TagLib::FLAC::Picture::Type::Lyricist)
30!
262
    .value("RecordingLocation", TagLib::FLAC::Picture::Type::RecordingLocation)
30!
263
    .value("DuringRecording", TagLib::FLAC::Picture::Type::DuringRecording)
30!
264
    .value("DuringPerformance", TagLib::FLAC::Picture::Type::DuringPerformance)
30!
265
    .value("MovieScreenCapture", TagLib::FLAC::Picture::Type::MovieScreenCapture)
30!
266
    .value("ColouredFish", TagLib::FLAC::Picture::Type::ColouredFish)
30!
267
    .value("Illustration", TagLib::FLAC::Picture::Type::Illustration)
30!
268
    .value("BandLogo", TagLib::FLAC::Picture::Type::BandLogo)
30!
269
    .value("PublisherLogo", TagLib::FLAC::Picture::Type::PublisherLogo)
30!
270
    ;
271

272
  {
30✔
273
    typedef TagLib::FLAC::Picture cl;
30✔
274
    class_<cl, std::auto_ptr<cl>, boost::noncopyable>
30✔
275
      ("flac_Picture", init<>())
30✔
276
      .DEF_SIMPLE_METHOD(type)
30!
277
      .DEF_SIMPLE_METHOD(setType)
30!
278

279
      .DEF_SIMPLE_METHOD(data)
30!
280
      .DEF_SIMPLE_METHOD(setData)
30!
281

282
      .DEF_SIMPLE_METHOD(mimeType)
30!
283
      .DEF_SIMPLE_METHOD(setMimeType)
30!
284

285
      .DEF_SIMPLE_METHOD(description)
30!
286
      .DEF_SIMPLE_METHOD(setDescription)
30!
287

288
      .DEF_SIMPLE_METHOD(width)
30!
289
      .DEF_SIMPLE_METHOD(setWidth)
30!
290

291
      .DEF_SIMPLE_METHOD(height)
30!
292
      .DEF_SIMPLE_METHOD(setHeight)
30!
293

294
      .DEF_SIMPLE_METHOD(colorDepth)
30!
295
      .DEF_SIMPLE_METHOD(setColorDepth)
30!
296

297
      .DEF_SIMPLE_METHOD(numColors)
30!
298
      .DEF_SIMPLE_METHOD(setNumColors)
30!
299
      ;
300

301
  }
302

303
  exposePointerList<TagLib::FLAC::Picture>("flac_PictureList");
30✔
304

305
  {
30✔
306
    typedef FLAC::File cl;
30✔
307
    class_<cl, boost::noncopyable, bases<File> >("flac_File",
30✔
308
                                   init<const char *, boost::python::optional<bool, AudioProperties::ReadStyle> >())
30✔
309
      .def(init<const char *, ID3v2::FrameFactory *, boost::python::optional<bool, AudioProperties::ReadStyle> >())
30!
310
      .def("ID3v1Tag",
30!
311
           (ID3v1::Tag *(FLAC::File::*)(bool))
312
           &FLAC::File::ID3v1Tag,
313
           ID3v1Tag_overloads()[return_internal_reference<>()])
30!
314
      .def("ID3v2Tag",
30!
315
           (ID3v2::Tag *(FLAC::File::*)(bool))
316
           &FLAC::File::ID3v2Tag,
317
           ID3v2Tag_overloads()[return_internal_reference<>()])
30!
318
      .def("xiphComment",
30!
319
           (Ogg::XiphComment *(FLAC::File::*)(bool))
320
           &FLAC::File::xiphComment,
321
           xiphComment_overloads()[return_internal_reference<>()])
60!
322
      .DEF_SIMPLE_METHOD(pictureList)
30!
323
      .DEF_SIMPLE_METHOD(removePictures)
30!
324
      .DEF_SIMPLE_METHOD(removePicture)
30!
325
      // For existing picture objects from other FLAC files
326
      .def("addPicture", flacAddPictureCopy)
30!
327
      // For freshly created Picture objects
328
      .def("addPicture", flacAddPictureWithOwnership)
30!
329
      ;
330
  }
331

332
  // -------------------------------------------------------------
333
  // MPC
334
  // -------------------------------------------------------------
335
  enum_<MPC::File::TagTypes>("mpc_TagTypes")
30!
336
    .value("NoTags", MPC::File::NoTags)
30!
337
    .value("ID3v1", MPC::File::ID3v1)
30!
338
    .value("ID3v2", MPC::File::ID3v2)
30!
339
    .value("APE", MPC::File::APE)
30!
340
    .value("AllTags", MPC::File::AllTags)
30!
341
    ;
342

343
  {
30✔
344
    typedef MPC::File cl;
30✔
345
    class_<MPC::File, bases<File>, boost::noncopyable>
30✔
346
      ("mpc_File", init<const char *, boost::python::optional<bool, AudioProperties::ReadStyle> >())
30✔
347
      .def("ID3v1Tag",
30!
348
           (ID3v1::Tag *(cl::*)(bool))
349
           &cl::ID3v1Tag,
350
           ID3v1Tag_overloads()[return_internal_reference<>()])
30!
351
      .def("APETag",
30!
352
           (APE::Tag *(cl::*)(bool))
353
           &cl::APETag,
354
           APETag_overloads()[return_internal_reference<>()])
30!
355
      .def("remove",
60✔
356
           (void (cl::*)(int))
357
           &cl::strip,
358
           strip_overloads())
30!
359
      ;
360
  }
361

362
  /// WAV
363

364
  enum_<TagLib::RIFF::WAV::File::TagTypes>("wav_TagTypes")
30!
365
    .value("NoTags", TagLib::RIFF::WAV::File::NoTags)
30!
366
    .value("ID3v2", TagLib::RIFF::WAV::File::ID3v2)
30!
367
    .value("Info", TagLib::RIFF::WAV::File::Info)
30!
368
    .value("AllTags", TagLib::RIFF::WAV::File::AllTags)
30!
369
    ;
370

371
  {
30✔
372
    typedef TagLib::RIFF::WAV::File cl;
30✔
373
    class_<cl, bases<File>, boost::noncopyable>
30✔
374
      ("wav_File", init<const char *, boost::python::optional<bool, AudioProperties::ReadStyle> >())
30✔
375
      .def("ID3v2Tag",
30!
376
           (ID3v2::Tag *(TagLib::RIFF::WAV::File::*)())
377
           &cl::ID3v2Tag,
378
           return_internal_reference<>())
30✔
379
      .def("InfoTag",
30!
380
           (TagLib::RIFF::Info::Tag *(TagLib::RIFF::WAV::File::*)())
381
           &cl::InfoTag,
382
           return_internal_reference<>())
30!
383
      #if (TAGPY_TAGLIB_HEX_VERSION >= 0x11100)
384
      .DEF_OVERLOADED_METHOD(strip, void (cl::*)(TagLib::RIFF::WAV::File::TagTypes) const)
385
      #endif
386
      ;
387
  }
388

389
    /// MP4
390
  #if TAGLIB_HEX_VERSION >= CHECK_VERSION(1,13,0)
391
  enum_<TagLib::MP4::File::TagTypes>("mp4_TagTypes")
10!
392
    .value("NoTags", TagLib::MP4::File::NoTags)
10!
393
    .value("MP4", TagLib::MP4::File::MP4)
10!
394
    .value("AllTags", TagLib::MP4::File::AllTags)
10!
395
    ;
396
  #endif
397
  {
30✔
398
    typedef TagLib::MP4::File cl;
30✔
399
    class_<cl, bases<File>, boost::noncopyable>
30✔
400
      ("mp4_File", init<const char *, boost::python::optional<bool, AudioProperties::ReadStyle> >())
30✔
401
      .def("tag",
30!
402
           (MP4::Tag *(cl::*)() const)
403
           &cl::tag,
404
           return_internal_reference<>())
30!
405
      ;
406
  }
407
  enum_<TagLib::MP4::CoverArt::Format>("mp4_CoverArtFormats")
30!
408
    .value("JPEG", TagLib::MP4::CoverArt::JPEG)
30!
409
    .value("PNG", TagLib::MP4::CoverArt::PNG)
30!
410
    .value("BMP", TagLib::MP4::CoverArt::BMP)
30!
411
    .value("GIF", TagLib::MP4::CoverArt::GIF)
30!
412
    .value("Unknown", TagLib::MP4::CoverArt::Unknown)
30!
413
    ;
414
  {
30✔
415
    typedef TagLib::MP4::CoverArt cl;
30✔
416
    class_<cl>
30✔
417
      ("mp4_CoverArt", init<TagLib::MP4::CoverArt::Format, const ByteVector &>())
30✔
418
      .DEF_SIMPLE_METHOD(format)
30!
419
      .DEF_SIMPLE_METHOD(data)
30!
420
      ;
421
  }
422
  exposeList<TagLib::MP4::CoverArt>("mp4_CoverArtList");
30✔
423
  {
30✔
424
    typedef TagLib::MP4::Tag cl;
30✔
425
    class_<TagWrap<cl>, boost::noncopyable>("Tag", no_init)
30✔
426
      .add_property("title", &cl::title, &cl::setTitle)
30!
427
      .add_property("artist", &cl::artist, &cl::setArtist)
30!
428
      .add_property("album", &cl::album, &cl::setAlbum)
30!
429
      .add_property("comment", &cl::comment, &cl::setComment)
30!
430
      .add_property("genre", &cl::genre, &cl::setGenre)
30!
431
      .add_property("year", &cl::year, &cl::setYear)
30!
432
      .add_property("track", &cl::track, &cl::setTrack)
30!
433
      #if TAGLIB_HEX_VERSION >= CHECK_VERSION(1,10,0)
434
      .add_property("covers", &mp4_Tag_GetCovers, &mp4_Tag_SetCovers)
25!
435
      #endif
436
      .DEF_VIRTUAL_METHOD(isEmpty)
30!
437
      .DEF_SIMPLE_METHOD(duplicate)
30!
438
      .staticmethod("duplicate")
30!
439
      ;
440
  }
441

442
}
30✔
443

444
// EMACS-FORMAT-TAG
445
//
446
// Local Variables:
447
// mode: C++
448
// eval: (c-set-style "stroustrup")
449
// eval: (c-set-offset 'access-label -2)
450
// eval: (c-set-offset 'inclass '++)
451
// c-basic-offset: 2
452
// tab-width: 8
453
// End:
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc