Class: TagLib::MP4::File

Inherits:
File
  • Object
show all
Defined in:
docs/taglib/mp4.rb

Overview

The file class for '.m4a' files.

Examples:

Finding an MP4 item by field name

TagLib::MP4::File.open("file.m4a") do |mp4|
  item_list_map = mp4.tag.item_list_map
  title = item_list_map["\xC2\xA9nam"].to_string_list
  puts title.first
end

Add new cover art to a tag

image_data = File.open('cover_art.jpeg', 'rb') { |f| f.read }
cover_art = TagLib::MP4::CoverArt.new(TagLib::MP4::CoverArt::JPEG, image_data)
item = TagLib::MP4::Item.from_cover_art_list([cover_art])
mp4.tag.item_list_map.insert('covr', item)
# => nil
mp4.save
# => true

Extract cover art from a tag and save it to disk

cover_art_list = mp4.tag.item_list_map['covr'].to_cover_art_list
cover_art = cover_art_list.first
cover_art.format
# => 13
cover_art.format == TagLib::MP4::CoverArt::JPEG
# => true
File.open('cover_art.jpeg', 'wb') do |file|
  file.write(cover_art.data)
end
# => 3108

List all keys and items in the tag

mp4.tag.item_list_map.to_a
# => [["covr",
#   #<TagLib::MP4::Item:0x007f9bab61e3d0 @__swigtype__="_p_TagLib__MP4__Item">],
#  ["trkn",
#   #<TagLib::MP4::Item:0x007f9bab61e268 @__swigtype__="_p_TagLib__MP4__Item">],
#  ["©ART",
#   #<TagLib::MP4::Item:0x007f9bab61e128 @__swigtype__="_p_TagLib__MP4__Item">],
#  ["©alb",
#   #<TagLib::MP4::Item:0x007f9bab61df48 @__swigtype__="_p_TagLib__MP4__Item">],
#  ["©cmt",
#   #<TagLib::MP4::Item:0x007f9bab61de08 @__swigtype__="_p_TagLib__MP4__Item">],
#  ["©cpy",
#   #<TagLib::MP4::Item:0x007f9bab61dc78 @__swigtype__="_p_TagLib__MP4__Item">],
#  ["©day",
#   #<TagLib::MP4::Item:0x007f9bab61db88 @__swigtype__="_p_TagLib__MP4__Item">],
#  ["©gen",
#   #<TagLib::MP4::Item:0x007f9bab61da48 @__swigtype__="_p_TagLib__MP4__Item">],
#  ["©nam",
#   #<TagLib::MP4::Item:0x007f9bab61d930 @__swigtype__="_p_TagLib__MP4__Item">],
#  ["©too",
#   #<TagLib::MP4::Item:0x007f9bab61d818 @__swigtype__="_p_TagLib__MP4__Item">]]

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from File

#close, #save

Constructor Details

#initialize(filename, read_properties = true) ⇒ TagLib::MP4::File

Load an M4A file.

Parameters:

  • filename (String)
  • read_properties (Boolean) (defaults to: true)

    if audio properties should be read



70
71
# File 'docs/taglib/mp4.rb', line 70

def initialize(filename, read_properties=true)
end

Class Method Details

.open(filename, read_properties = true) {|file| ... } ⇒ Object

Creates a new file and passes it to the provided block, closing the file automatically at the end of the block.

Note that after the block is done, the file is closed and all memory is released for objects read from the file (basically everything from the TagLib namespace).

Using open is preferable to using new and then manually close.

Parameters:

  • filename (String)
  • read_properties (Boolean) (defaults to: true)

    if audio properties should be read

Yields:

Returns:

  • the return value of the block



61
62
# File 'docs/taglib/mp4.rb', line 61

def self.open(filename, read_properties=true)
end

Instance Method Details

#audio_propertiesTagLib::MP4::Properties



81
82
# File 'docs/taglib/mp4.rb', line 81

def audio_properties
end

#mp4_tag?Boolean

file has a Metadata Item List (ilst) atom.

Returns:

  • (Boolean)

    Returns whether or not the file actually has an MP4 tag, or the

Since:

  • 1.0.0



88
89
# File 'docs/taglib/mp4.rb', line 88

def mp4_tag?
end

#tagTagLib::MP4::Tag?

Returns the MP4 tag in the file

Returns:



77
78
# File 'docs/taglib/mp4.rb', line 77

def tag
end