class MultimediaParadise::AudioTagReader

Constants

N_PAD
#

N_PAD

#

Public Class Methods

[](i = '') click to toggle source
#

MultimediaParadise::AudioTagReader[]

#
# File lib/multimedia_paradise/audio/audio_tag_reader/audio_tag_reader.rb, line 485
def self.[](i = '')
  new(i) { :be_quiet}
end
new( commandline_arguments = nil, run_already = true ) { || ... } click to toggle source
#

initialize

#
# File lib/multimedia_paradise/audio/audio_tag_reader/audio_tag_reader.rb, line 34
def initialize(
    commandline_arguments = nil,
    run_already           = true
  )
  reset
  set_commandline_arguments(
    commandline_arguments
  )
  # ======================================================================= #
  # === Handle blocks next
  # ======================================================================= #
  if block_given?
    yielded = yield
    case yielded
    # ===================================================================== #
    # === :do_not_report_anything
    # ===================================================================== #
    when :do_not_report_anything,
         :be_quiet,
         :be_silent
      @may_we_report = false
    end
  end
  run if run_already
end

Public Instance Methods

album()
Alias for: album?
album=(i)
Alias for: set_album
album?() click to toggle source
#

album?

#
# File lib/multimedia_paradise/audio/audio_tag_reader/audio_tag_reader.rb, line 216
def album?
  @album
end
Also aliased as: album
artist()
Alias for: artist?
artist=(i)
Alias for: set_artist
artist?() click to toggle source
#

artist?

#
# File lib/multimedia_paradise/audio/audio_tag_reader/audio_tag_reader.rb, line 188
def artist?
  @artist
end
Also aliased as: artist
band()
Alias for: band?
band?() click to toggle source
#

band?

#
# File lib/multimedia_paradise/audio/audio_tag_reader/audio_tag_reader.rb, line 230
def band?
  @band
end
Also aliased as: band
bpm()
Alias for: bpm?
bpm?() click to toggle source
#

bpm?

#
# File lib/multimedia_paradise/audio/audio_tag_reader/audio_tag_reader.rb, line 209
def bpm?
  @bpm
end
Also aliased as: bpm
comment()
Alias for: comment?
comment=(i)
Alias for: set_comment
comment?() click to toggle source
#

comment?

#
# File lib/multimedia_paradise/audio/audio_tag_reader/audio_tag_reader.rb, line 251
def comment?
  @comment
end
Also aliased as: comment
date()
Alias for: date?
date?() click to toggle source
#

date?

#
# File lib/multimedia_paradise/audio/audio_tag_reader/audio_tag_reader.rb, line 195
def date?
  @date
end
Also aliased as: date
disc()
Alias for: disc?
disc?() click to toggle source
#

disc?

#
# File lib/multimedia_paradise/audio/audio_tag_reader/audio_tag_reader.rb, line 202
def disc?
  @disc
end
Also aliased as: disc
do_determine_the_length_of_the_song( this_file = main_file? ) click to toggle source
#

do_determine_the_length_of_the_song

The first argument should be the name of the .mp3 file at hand.

#
# File lib/multimedia_paradise/audio/audio_tag_reader/audio_tag_reader.rb, line 404
def do_determine_the_length_of_the_song(
    this_file = main_file?
  )
  # ======================================================================= #
  # The way for the mp3-library goes like this:
  #   @length_in_seconds = @properties.length_in_seconds  # => 335 (song length)
  # But this was buggy for me, so we query ffmpeg instead. The code above
  # is retained, though, in the event that we may want to re-instate it
  # one day. (Noted this down at 26.10.2021)
  # ======================================================================= #
  @length_in_seconds = ::MultimediaParadise.length_of?(this_file)
end
genre()
Alias for: genre?
genre=(i)
Alias for: set_genre
genre?() click to toggle source
#

genre?

#
# File lib/multimedia_paradise/audio/audio_tag_reader/audio_tag_reader.rb, line 237
def genre?
  @genre
end
Also aliased as: genre
length_in_seconds?() click to toggle source
#

length_in_seconds?

#
# File lib/multimedia_paradise/audio/audio_tag_reader/audio_tag_reader.rb, line 395
def length_in_seconds?
  @length_in_seconds
end
main_file?()
Alias for: this_file?
performer()
Alias for: performer?
performer?() click to toggle source
#

performer?

#
# File lib/multimedia_paradise/audio/audio_tag_reader/audio_tag_reader.rb, line 244
def performer?
  @performer
end
Also aliased as: performer
report()
Alias for: report_everything
report_album(i = @album) click to toggle source
#

report_album

#
# File lib/multimedia_paradise/audio/audio_tag_reader/audio_tag_reader.rb, line 127
def report_album(i = @album)
  e sfancy('  Album: '.ljust(N_PAD))+
    right_colour(i.to_s)
end
report_artist(i = @artist) click to toggle source
#

report_artist

#
# File lib/multimedia_paradise/audio/audio_tag_reader/audio_tag_reader.rb, line 119
def report_artist(i = @artist)
  e sfancy('  Artist: '.ljust(N_PAD))+
    right_colour(i.to_s)
end
report_comment(i = @comment) click to toggle source
#

report_comment

#
# File lib/multimedia_paradise/audio/audio_tag_reader/audio_tag_reader.rb, line 135
def report_comment(i = @comment)
  e sfancy('  Comment: '.ljust(N_PAD))+
    right_colour(i.to_s)
end
report_everything() click to toggle source
#

report_everything

This method will report as much as possible about the song at hand.

“track” would also be a tag that could be shown. Personally I don’t really need it, though.

#
# File lib/multimedia_paradise/audio/audio_tag_reader/audio_tag_reader.rb, line 333
def report_everything
  report_title
  report_artist
  report_album
  report_year
  report_genre
  report_comment
  report_length_in_seconds
end
Also aliased as: report
report_genre(i = @genre) click to toggle source
#

report_genre

To get all available genres, see:

https://en.wikipedia.org/wiki/ID3#Genre_list_in_ID3v1[12]
#
# File lib/multimedia_paradise/audio/audio_tag_reader/audio_tag_reader.rb, line 148
def report_genre(i = @genre)
  e sfancy('  Genre: '.ljust(N_PAD))+
    right_colour(i.to_s)
end
report_length_in_seconds( i = @length_in_seconds ) click to toggle source
#

report_length_in_seconds

#
# File lib/multimedia_paradise/audio/audio_tag_reader/audio_tag_reader.rb, line 164
def report_length_in_seconds(
    i = @length_in_seconds
  )
  e sfancy('  Duration (in seconds): '.ljust(N_PAD))+
    right_colour(i.to_s)
end
report_title(i = @title) click to toggle source
#

report_title

#
# File lib/multimedia_paradise/audio/audio_tag_reader/audio_tag_reader.rb, line 104
def report_title(i = @title)
  e sfancy('  Title: '.ljust(N_PAD))+
    right_colour(i.to_s)
end
report_year(i = @year) click to toggle source
#

report_year

#
# File lib/multimedia_paradise/audio/audio_tag_reader/audio_tag_reader.rb, line 156
def report_year(i = @year)
  e sfancy('  Year: '.ljust(N_PAD))+
    right_colour(i.to_s)
end
reset() click to toggle source
#

reset (reset tag)

#
Calls superclass method MultimediaParadise::Base#reset
# File lib/multimedia_paradise/audio/audio_tag_reader/audio_tag_reader.rb, line 63
def reset
  super()
  # ======================================================================= #
  # === @performer
  # ======================================================================= #
  @performer = nil
  # ======================================================================= #
  # === @band
  # ======================================================================= #
  @band = nil
  # ======================================================================= #
  # === @bpm
  # ======================================================================= #
  @bpm = nil
  # ======================================================================= #
  # === @date
  # ======================================================================= #
  @date = nil
  # ======================================================================= #
  # === @disc
  # ======================================================================= #
  @disc = nil
  # ======================================================================= #
  # === @may_we_report
  #
  # Whether to output anything to the user on the commandline or not,
  # by default.
  # ======================================================================= #
  @may_we_report = true
end
right_colour(i) click to toggle source
#

right_colour

#
# File lib/multimedia_paradise/audio/audio_tag_reader/audio_tag_reader.rb, line 112
def right_colour(i)
  mediumpurple(i)
end
run() click to toggle source
#

run (run tag)

#
# File lib/multimedia_paradise/audio/audio_tag_reader/audio_tag_reader.rb, line 471
def run
  try_to_require_the_tablib_gem
  # ======================================================================= #
  # We will assume that the first argument given is the file we want to
  # work on.
  # ======================================================================= #
  this_file = first_argument?.to_s.dup
  set_this_file(this_file)
  work_on_this_file(@this_file)
end
save() click to toggle source
#

save

#
# File lib/multimedia_paradise/audio/audio_tag_reader/audio_tag_reader.rb, line 464
def save
  @tag.save
end
set_album(i) click to toggle source
#

set_album

#
# File lib/multimedia_paradise/audio/audio_tag_reader/audio_tag_reader.rb, line 272
def set_album(i)
  @album = i.to_s
end
Also aliased as: album=
set_artist(i) click to toggle source
#

set_artist

#
# File lib/multimedia_paradise/audio/audio_tag_reader/audio_tag_reader.rb, line 279
def set_artist(i)
  @artist = i.to_s
end
Also aliased as: artist=
set_comment(i) click to toggle source
#

set_comment

#
# File lib/multimedia_paradise/audio/audio_tag_reader/audio_tag_reader.rb, line 286
def set_comment(i)
  @comment = i.to_s
end
Also aliased as: comment=
set_genre(i) click to toggle source
#

set_genre

#
# File lib/multimedia_paradise/audio/audio_tag_reader/audio_tag_reader.rb, line 307
def set_genre(i)
  @genre = i.to_s
end
Also aliased as: genre=
set_new_album(i) click to toggle source
#

set_new_album

#
# File lib/multimedia_paradise/audio/audio_tag_reader/audio_tag_reader.rb, line 321
def set_new_album(i)
  @tag.album = i
end
set_new_year(i) click to toggle source
#

set_new_year

#
# File lib/multimedia_paradise/audio/audio_tag_reader/audio_tag_reader.rb, line 314
def set_new_year(i)
  @tag.year = i.to_i # This must be an Integer.
end
set_this_file(i) click to toggle source
#

set_this_file

#
# File lib/multimedia_paradise/audio/audio_tag_reader/audio_tag_reader.rb, line 97
def set_this_file(i)
  @this_file = i
end
set_title(i) click to toggle source
#

set_title

#
# File lib/multimedia_paradise/audio/audio_tag_reader/audio_tag_reader.rb, line 265
def set_title(i)
  @title = i.to_s
end
Also aliased as: title=
set_track(i) click to toggle source
#

set_track

#
# File lib/multimedia_paradise/audio/audio_tag_reader/audio_tag_reader.rb, line 293
def set_track(i)
  @track = i.to_i # This must be an Integer.
end
Also aliased as: track=
set_year(i) click to toggle source
#

set_year

#
# File lib/multimedia_paradise/audio/audio_tag_reader/audio_tag_reader.rb, line 300
def set_year(i)
  @year = i.to_i # This must be an Integer.
end
Also aliased as: year=
tag()
Alias for: tag?
tag?() click to toggle source
#

tag?

#
# File lib/multimedia_paradise/audio/audio_tag_reader/audio_tag_reader.rb, line 174
def tag?
  @tag
end
Also aliased as: tag
this_file?() click to toggle source
#

this_file?

#
# File lib/multimedia_paradise/audio/audio_tag_reader/audio_tag_reader.rb, line 388
def this_file?
  @this_file
end
Also aliased as: main_file?
title()
Alias for: title?
title=(i)
Alias for: set_title
title?() click to toggle source
#

title?

#
# File lib/multimedia_paradise/audio/audio_tag_reader/audio_tag_reader.rb, line 181
def title?
  @title
end
Also aliased as: title
track()
Alias for: track?
track=(i)
Alias for: set_track
track?() click to toggle source
#

track?

#
# File lib/multimedia_paradise/audio/audio_tag_reader/audio_tag_reader.rb, line 258
def track?
  @track
end
Also aliased as: track
try_to_require_the_tablib_gem() click to toggle source
#

try_to_require_the_tablib_gem

#
# File lib/multimedia_paradise/audio/audio_tag_reader/audio_tag_reader.rb, line 420
def try_to_require_the_tablib_gem
  begin
    # ===================================================================== #
    # Require the taglib-ruby gem.
    #
    # See: https://rubygems.org/gems/taglib-ruby
    # ===================================================================== #
    require 'taglib'
  rescue LoadError; end
end
update!( this_file = @this_file, title = @title, artist = @artist, genre = @genre, comment = @comment, track = @track ) click to toggle source
#

update!

This method can be used to update the tags.

#
# File lib/multimedia_paradise/audio/audio_tag_reader/audio_tag_reader.rb, line 436
def update!( 
    this_file = @this_file,
    title     = @title,
    artist    = @artist,
    genre     = @genre,
    comment   = @comment,
    track     = @track
  )
  TagLib::FileRef.open(this_file) { |fileref| # of class TagLib::FileRef.
    unless fileref.null?
      @tag       = fileref.tag # Keep a reference to it here.
      set_new_album(@album) # Use the old reference.
      set_new_year(@year)  # Use the old reference, via @year.
      @tag.title   = title.to_s
      @tag.artist  = artist.to_s
      @tag.genre   = genre.to_s
      @tag.comment = comment.to_s
      if track
        @tag.track = track.to_i # This must be an integer.
      end
      fileref.save
    end
  }
end
work_on_this_file( this_file = @this_file ) click to toggle source
#

work_on_this_file

#
# File lib/multimedia_paradise/audio/audio_tag_reader/audio_tag_reader.rb, line 346
  def work_on_this_file(
      this_file = @this_file
    )
    unless Object.const_defined? :TagLib
      text = <<-EOF
Please install TagLib first via:

  gem install taglib

EOF
      e text
      return text
    end
    # ======================================================================= #
    # Load up the file via TagLib first.
    # ======================================================================= #
    TagLib::FileRef.open(this_file) { |fileref| # of class TagLib::FileRef.
      unless fileref.null?
        @tag       = fileref.tag  # Keep a reference to it here.
        @title     = @tag.title   # => "Wake Up"
        @artist    = @tag.artist  # => "DJ Punk"
        @album     = @tag.album   # => "Funeral"
        @year      = @tag.year    # => 2004
        @genre     = @tag.genre   # => "Indie Rock"
        @comment   = @tag.comment
        @track     = @tag.track
        # @band    = @tag.band # Does not exist.
        @performer = @tag.performer if @tag.respond_to? :performer
        @properties = fileref.audio_properties
        do_determine_the_length_of_the_song(this_file)
        if @may_we_report
          e
          report_everything
          e
        end
      end
    } # File is automatically closed at block end.
  end
year()
Alias for: year?
year=(i)
Alias for: set_year
year?() click to toggle source
#

year?

#
# File lib/multimedia_paradise/audio/audio_tag_reader/audio_tag_reader.rb, line 223
def year?
  @year
end
Also aliased as: year