Class: TagLib::MPEG::File

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

Overview

The file class for .mp3 and other MPEG files.

Examples:

Reading a title

title = TagLib::MPEG::File.open("file.mp3") do |file|
  tag = file.tag
  tag.title
end

Constant Summary collapse

NoTags =
0x0000
ID3v1 =
0x0001
ID3v2 =
0x0002
APE =
0x0004
AllTags =
0xffff

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from File

#close

Constructor Details

#initialize(filename, read_properties = true) ⇒ File

Load an MPEG file.

Parameters:

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

    if audio properties should be read



32
33
# File 'docs/taglib/mpeg.rb', line 32

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

Since:

  • 0.4.0



24
25
# File 'docs/taglib/mpeg.rb', line 24

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

Instance Method Details

#ape_tag?Boolean

Returns Whether or not the file on disk actually has an APE tag.

Returns:

  • (Boolean)

    Whether or not the file on disk actually has an APE tag.

Since:

  • 1.0.0



114
115
# File 'docs/taglib/mpeg.rb', line 114

def ape_tag?
end

#audio_propertiesTagLib::MPEG::Properties

Returns audio properties.



54
55
# File 'docs/taglib/mpeg.rb', line 54

def audio_properties
end

#id3v1_tag(create = false) ⇒ TagLib::ID3v1::Tag?

Returns the ID3v1 tag.

Parameters:

  • create (defaults to: false)

    if a new tag should be created when none exists

Returns:



40
41
# File 'docs/taglib/mpeg.rb', line 40

def id3v1_tag(create=false)
end

#id3v1_tag?Boolean

Returns Whether or not the file on disk actually has an ID3v1 tag.

Returns:

  • (Boolean)

    Whether or not the file on disk actually has an ID3v1 tag.

Since:

  • 1.0.0



102
103
# File 'docs/taglib/mpeg.rb', line 102

def id3v1_tag?
end

#id3v2_tag(create = false) ⇒ TagLib::ID3v2::Tag?

Returns the ID3v2 tag.

Parameters:

  • create (defaults to: false)

    if a new tag should be created when none exists

Returns:



48
49
# File 'docs/taglib/mpeg.rb', line 48

def id3v2_tag(create=false)
end

#id3v2_tag?Boolean

Returns Whether or not the file on disk actually has an ID3v2 tag.

Returns:

  • (Boolean)

    Whether or not the file on disk actually has an ID3v2 tag.

Since:

  • 1.0.0



108
109
# File 'docs/taglib/mpeg.rb', line 108

def id3v2_tag?
end

#save(tags = TagLib::MPEG::File::AllTags, strip_others = true) ⇒ Boolean #save(tags, strip_others, id3v2_version) ⇒ Boolean

Save the file and the associated tags.

Overloads:

  • #save(tags = TagLib::MPEG::File::AllTags, strip_others = true) ⇒ Boolean

    Parameters:

    • tags (Integer) (defaults to: TagLib::MPEG::File::AllTags)

      The tag types to save (see constants), e.g. ID3v2. To specify more than one tag type, or them together using |, e.g. TagLib::MPEG::File::ID3v1 | TagLib::MPEG::File::ID3v2.

    • strip_others (Boolean) (defaults to: true)

      true if tag types other than the specified ones should be stripped from the file

  • #save(tags, strip_others, id3v2_version) ⇒ Boolean

    This overload can only be called if the extension was compiled against TagLib >= 1.8. Otherwise it will raise an ArgumentError. So either check the version using TAGLIB_MAJOR_VERSION and TAGLIB_MINOR_VERSION or be prepared to rescue the ArgumentError.

    Parameters:

    • id3v2_version (Integer)

      3 if the saved ID3v2 tag should be in version ID3v2.3, or 4 if it should use ID3v2.4

Returns:

  • (Boolean)

    whether saving was successful



83
84
# File 'docs/taglib/mpeg.rb', line 83

def save(tags=TagLib::MPEG::File::AllTags, strip_others=TagLib::File::StripOthers)
end

#strip(tags = TagLib::MPEG::File::AllTags) ⇒ Boolean

Strip the specified tags from the file. Note that this directly updates the file, a call to save afterwards is not necessary (closing the file is necessary as always, though).

Parameters:

  • tags (Integer) (defaults to: TagLib::MPEG::File::AllTags)

    The tag types to strip (see constants), e.g. ID3v2. To specify more than one tag type, or them together using |, e.g. TagLib::MPEG::File::ID3v1 | TagLib::MPEG::File::ID3v2.

Returns:

  • (Boolean)

    whether stripping was successful



96
97
# File 'docs/taglib/mpeg.rb', line 96

def strip(tags=TagLib::MPEG::File::AllTags)
end