Class: Id3Taginator::Id3v24Tag

Inherits:
Id3v2Tag
  • Object
show all
Defined in:
lib/id3taginator/id3v24_tag.rb

Constant Summary collapse

HEADER_SIZE =
10

Constants inherited from Id3v2Tag

Id3Taginator::Id3v2Tag::IDENTIFIER

Instance Attribute Summary

Attributes inherited from Id3v2Tag

#options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Id3v2Tag

#add_frame, #add_size_tag_if_not_present, build_for_version, build_from_file, #frames, id3v2_tag?, #number_of_frames, #parse_frames, #to_bytes, #total_tag_size, #unsynchronized=, #unsynchronized?, #version

Methods included from Frames::CustomFrames

#add_custom_frame, #custom_frame, #remove_custom_frame

Methods included from Frames::Frameable

#find_frame, #find_frames, #set_frame_fields, #set_frame_fields_by_selector, #unsupported_frame

Methods included from Frames::PrivateFrames

#private_frames, #private_frames=, #remove_private_frame

Methods included from Frames::GroupingFrames

#group_identifications, #group_identifications=, #grouping, #grouping=, #remove_group_identification, #remove_grouping

Methods included from Frames::EncryptionFrames

#audio_encryptions, #audio_encryptions=, #encryption_methods, #encryption_methods=, #remove_audio_encryption, #remove_encryption_method

Methods included from Frames::ToSFrames

#ownership, #ownership=, #remove_ownership, #remove_terms_of_use, #terms_of_use, #terms_of_use=

Methods included from Frames::BufferFrames

#recommended_buffer_size, #recommended_buffer_size=, #remove_recommended_buffer_size

Methods included from Frames::CountFrames

#play_counter, #play_counter=, #popularity, #popularity=, #remove_play_counter, #remove_popularity

Methods included from Frames::GeoFrames

#encapsulated_object=, #encapsulated_objects, #remove_encapsulated_object

Methods included from Frames::PictureFrames

#pictures, #pictures=, #remove_picture

Methods included from Frames::CommentFrames

#comment=, #comments, #remove_comment

Methods included from Frames::LyricsFrames

#remove_unsync_lyrics, #unsync_lyrics, #unsync_lyrics=

Methods included from Frames::McdiFrames

#music_cd_identifier, #music_cd_identifier=, #remove_music_cd_identifier

Methods included from Frames::IplFrames

#involved_people, #involved_people=, #remove_involved_people

Methods included from Frames::UrlFrames

#commercial_information_url, #commercial_information_url=, #copyright_information_url, #copyright_information_url=, #official_artist_url, #official_artist_url=, #official_audio_file_url, #official_audio_file_url=, #official_publisher_webpage, #official_publisher_webpage=, #official_radio_station_homepage, #official_radio_station_homepage=, #official_source_url, #official_source_url=, #payment_url, #payment_url=, #remove_commercial_information_url, #remove_copyright_information_url, #remove_official_artist_url, #remove_official_audio_file_url, #remove_official_publisher_webpage, #remove_official_radio_station_homepage, #remove_official_source_url, #remove_payment_url, #remove_user_custom_url_link, #user_custom_url_link=, #user_custom_url_links

Methods included from Frames::TextFrames

#album, #album=, #album_artist, #album_artist=, #album_sort_order, #album_sort_order=, #artists, #artists=, #bpm, #bpm=, #composers, #composers=, #conductor, #conductor=, #content_group_description, #content_group_description=, #copyright, #copyright=, #date, #date=, #encoded_by, #encoded_by=, #encoder, #encoder=, #file_owner, #file_owner=, #file_type, #file_type=, #genres, #genres=, #initial_key, #initial_key=, #internet_radio_station_name, #internet_radio_station_name=, #isrc, #isrc=, #languages, #languages=, #length, #length=, #media_type, #media_type=, #modified_by, #modified_by=, #original_album, #original_album=, #original_artists, #original_artists=, #original_filename, #original_filename=, #original_release_year, #original_release_year=, #original_writers, #original_writers=, #part_of_set, #part_of_set=, #performer_sort_order, #performer_sort_order=, #playlist_delay, #playlist_delay=, #publisher, #publisher=, #recording_dates, #recording_dates=, #remove_album, #remove_album_artist, #remove_album_sort_order, #remove_artists, #remove_bpm, #remove_composers, #remove_conductor, #remove_content_group_description, #remove_copyright, #remove_date, #remove_encoded_by, #remove_encoder, #remove_file_owner, #remove_file_type, #remove_genres, #remove_initial_key, #remove_internet_radio_station_name, #remove_isrc, #remove_languages, #remove_length, #remove_media_type, #remove_modified_by, #remove_original_album, #remove_original_artists, #remove_original_filename, #remove_original_release_year, #remove_original_writers, #remove_part_of_set, #remove_performer_sort_order, #remove_playlist_delay, #remove_publisher, #remove_recording_dates, #remove_size, #remove_subtitle, #remove_time, #remove_title, #remove_title_sort_order, #remove_track_number, #remove_user_custom_text_information, #remove_writers, #remove_year, #size, #size=, #subtitle, #subtitle=, #time, #time=, #title, #title=, #title_sort_order, #title_sort_order=, #track_number, #track_number=, #user_custom_text_information, #user_custom_text_information=, #writers, #writers=, #year, #year=

Methods included from Frames::UfidFrames

#remove_unique_file_identifier, #unique_file_identifiers, #unique_file_identifiers=

Constructor Details

#initialize(minor_version, flags, tag_size, tag_data_stream, options) ⇒ Id3v24Tag

Constructor

Parameters:

  • minor_version (Integer)

    the minor version, in v2..[minor]

  • flags (Header::Id3v2Flags)

    the 2 Byte header flags wrapped in the entity

  • tag_size (Integer)

    number of bytes the excluding header/footer of the tag

  • tag_data_stream (StringIO, IO, File)

    the file stream

  • options (Options::Options)

    the options to use



24
25
26
27
28
29
30
# File 'lib/id3taginator/id3v24_tag.rb', line 24

def initialize(minor_version, flags, tag_size, tag_data_stream, options)
  @options = options
  ext_header = flags.extended_header? && tag_size.positive? ? parse_extended_header(tag_data_stream) : nil

  frames = tag_size.positive? ? parse_frames(tag_data_stream, 4) : []
  super(HEADER_SIZE, 4, minor_version, flags, tag_size, frames, ext_header)
end

Class Method Details

.build_empty(options) ⇒ Id3v24Tag

builds an empty Id3v2.4 tag with the given options set

Parameters:

Returns:

  • (Id3v24Tag)

    returns an empty Id3v2.4 tag



13
14
15
# File 'lib/id3taginator/id3v24_tag.rb', line 13

def self.build_empty(options)
  new(0, Header::Id3v2Flags.new(0x00), 0, StringIO.new, options)
end

Instance Method Details

#experimental?Boolean

determines if experimental tags are present

Returns:

  • (Boolean)

    true if experimental tags present, else false



57
58
59
# File 'lib/id3taginator/id3v24_tag.rb', line 57

def experimental?
  @flags.experimental?
end

#extended_header?Boolean

determines if an extended header is present

Returns:

  • (Boolean)

    true if header is present, else false



50
51
52
# File 'lib/id3taginator/id3v24_tag.rb', line 50

def extended_header?
  @flags.extended_header?
end

#footer=(enabled = true) ⇒ Object

enables or disables a footer

Parameters:

  • enabled (Boolean) (defaults to: true)

    true, if the footer should be set to the tag, else false



71
72
73
# File 'lib/id3taginator/id3v24_tag.rb', line 71

def footer=(enabled = true)
  @flags.footer = enabled
end

#footer?Boolean

determines if a footer is present

Returns:

  • (Boolean)

    true if a footer is present, else false



64
65
66
# File 'lib/id3taginator/id3v24_tag.rb', line 64

def footer?
  @flags.footer?
end

#parse_extended_header(file) ⇒ Header::Id3v24ExtendedHeader

parses the extended header if present

Parameters:

  • file (StringIO, IO, File)

    the file stream

Returns:

Raises:



37
38
39
40
41
42
43
44
45
# File 'lib/id3taginator/id3v24_tag.rb', line 37

def parse_extended_header(file)
  size = Util::MathUtil.to_32_synchsafe_integer(file.read(4)&.bytes)
  number_of_flags = file.readbyte
  flags = file.read(number_of_flags)

  raise Errors::Id3TagError, 'Could not find extended header flag bytes. ID3v2 Tag is corrupt.' if flags.nil?

  Header::Id3v24ExtendedHeader.new(size, flags)
end