class MultimediaParadise::GUI::Gtk::TagMp3Files
Public Class Methods
#¶ ↑
MultimediaParadise::GUI::Gtk::TagMp3Files.run
¶ ↑
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/misc.rb, line 405 def self.run( i = ARGV )require 'gtk_paradise/app/app' tag_mp3_files = ::MultimediaParadise::GUI::Gtk::TagMp3Files.new(i) r = ::Gtk.app r << tag_mp3_files r.on_button_press_event { |widget, event| if ::Gtk.right_mouse_click?(event) # right mouse click event. tag_mp3_files.context_menu?.popup_based_on_this_event(event) end } tag_mp3_files.parent_widget = r r.automatic_size_then_automatic_title r.top_left_then_run end
Public Instance Methods
#¶ ↑
add_custom_CSS_rules
(CSS tag)¶ ↑
This method is used to add additional CSS rules to this widget.
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/misc.rb, line 1575 def add_custom_CSS_rules # ======================================================================= # # The first rule is to style the separator. # ======================================================================= # more_CSS_rules_then_apply_them ' button { border-color: steelblue; border-width: 2px; } .button_class { border: 2px solid steelblue;; } #fancy_separator separator { border: 1px dotted lightgrey; padding: 0px; margin: 4px; } .save_button { border: 3px dashed steelblue; padding: 2px; margin: 4px; } .fancy_combobox window.popup { color: royalblue; font-weight: bold; border: 3px dashed lightgreen; } /* style the top header bar next */ #header_bar_on_top { border: 2px dotted royalblue; } ' end
#¶ ↑
album?¶ ↑
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/misc.rb, line 836 def album? @album end
#¶ ↑
artist?¶ ↑
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/misc.rb, line 216 def artist? @entry_for_the_artist.text? end
#¶ ↑
band?¶ ↑
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/misc.rb, line 850 def band? @band end
#¶ ↑
bpm?¶ ↑
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/misc.rb, line 829 def bpm? @bpm end
#¶ ↑
comment?¶ ↑
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/misc.rb, line 871 def comment? @comment end
#¶ ↑
connect_skeleton
(connect skeleton, connect tag)¶ ↑
This method should ideally reside in the file connect_skeleton.rb
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/connect_skeleton.rb, line 20 def connect_skeleton abort_on_exception # ======================================================================= # # The first dragger is the one close to the top of the main application. # It will contain the header bar, as well as the widget that is on # the second row. # ======================================================================= # first_dragger = drag_via_up_and_down_movement( header_bar?, # The header bar on top. widget_second_row # The main entry below the header bar. ) first_dragger.position = header_bar_height? # This height should be the height of the header bar. minimal(first_dragger) # ======================================================================= # # Next the middle box - this one will contain several widgets at the # same time. # ======================================================================= # middle_box = drag_via_left_and_right_movement( widget_left, widget_in_the_middle ) middle_box.set_name('fancy_separator') middle_box.position = 880 second_dragger = drag_via_left_and_right_movement(middle_box, widget_right) use_this_position = 1600 if use_this_position > max_width? use_this_position = max_width? * 0.8 end second_dragger.position = use_this_position # ======================================================================= # # The last dragger will add the status bar to the top. # ======================================================================= # third_dragger = drag_via_up_and_down_movement( second_dragger, @status_bar # The middle vbox contains the three main widgets. ) third_dragger.position = 1300 minimal(third_dragger) end
#¶ ↑
create_skeleton
(create tag, skeleton tag)¶ ↑
The order for the various create-method calls is important.
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/create.rb, line 394 def create_skeleton create_the_labels # (1) Must come before create_the_header_bar() create_the_entries # (4) Must come before we create the header, the main grid and the buttons. create_the_header_bar # (2) create_the_context_menu # (3) Ok to call it here. create_the_buttons # (5) Must come after we create_the_entries(). create_the_status_bar # (6) create_status_icon # (7) create_the_settings # (8) end
#¶ ↑
create_status_icon
¶ ↑
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/create.rb, line 200 def create_status_icon( tooltip_text = 'This text will show up upon a hover-event.' ) @status_icon = gtk_status_icon @status_icon.stock = ::Gtk::Stock::DIALOG_INFO @status_icon.set_icon_name('default_status_icon_name') # We can set a name. @status_icon.set_tooltip_text(tooltip_text) @status_icon.signal_connect(:activate) { |icon| if icon.respond_to? :blinking icon.blinking = !(icon.blinking?) end } # =========================================================================== # # Add a menu and a quit-button too. These will be triggered upon a # right-mouse-button presse vent. # =========================================================================== # menu = gtk_menu play_button = ::Gtk::ImageMenuItem.new(stock: ::Gtk::Stock::MEDIA_PLAY) play_button.signal_connect(:activate) { do_play_the_selected_song } menu.append(play_button) quit_button = ::Gtk::ImageMenuItem.new(stock: ::Gtk::Stock::QUIT) quit_button.signal_connect(:activate) { ::Gtk.main_quit } menu.append(quit_button) menu.show_all @status_icon.signal_connect(:popup_menu) { |icon, button, time| menu.popup(nil, nil, button, time) } end
#¶ ↑
create_the_combo_box_entry_for_genre_select
¶ ↑
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/create.rb, line 159 def create_the_combo_box_entry_for_genre_select if File.exist? FILE_MUSIC_GENRES array_available_genres = YAML.load_file(FILE_MUSIC_GENRES) else array_available_genres = [] # Safeguard. end # ======================================================================= # # === @combo_box_entry_for_genre_select # ======================================================================= # @combo_box_entry_for_genre_select = return_combo_box_entry( with_these_elements: array_available_genres ) @combo_box_entry_for_genre_select.clear_background # @combo_box_entry_for_genre_select.bblack1 @combo_box_entry_for_genre_select.pad1px @combo_box_entry_for_genre_select.css_class('fancy_combobox') @combo_box_entry_for_genre_select.six_per_row # ======================================================================= # # Next we will unify the background for these entries here. Disabled # in August 2021. # ======================================================================= # # set_a_uniform_background_for_the_entries_on_the_right_side_widget # ======================================================================= # # Next add the combo-box that contains all genres. We will not set # an active entry, so that we can determine that this depends on # the user having set it (or not, accordingly). # # @combo_box_entry_for_genre_select.active = 0 # # ======================================================================= # @combo_box_entry_for_genre_select.on_changed { if @combo_box_entry_for_genre_select.active_iter text = @combo_box_entry_for_genre_select.active_text sync_this_text_onto_the_genre_entry(text) end } end
#¶ ↑
create_the_entries
(entries tag, entry tag)¶ ↑
This method will bundle - and create - all relevant gtk-entries in this application.
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/create.rb, line 95 def create_the_entries # ======================================================================= # # === @entry_use_this_as_the_directory_to_the_local_songs # # This entry can be used to designate another directory for the # local .mp3 files. # ======================================================================= # @entry_use_this_as_the_directory_to_the_local_songs = gtk_entry @entry_use_this_as_the_directory_to_the_local_songs.set_text( PATH_TO_THE_LOCAL_AUDIO_DIRECTORY ) # ======================================================================= # # === @entry_for_the_comment # ======================================================================= # @entry_for_the_comment = gtk_entry @entry_for_the_comment.set_max_length(120) @entry_for_the_comment.set_size_request(680, 40) # ======================================================================= # # === @entry_for_the_title_of_the_song # # The next entry contains the title of the song. # ======================================================================= # @entry_for_the_title_of_the_song = gtk_entry @entry_for_the_title_of_the_song.set_max_length(150) # ======================================================================= # # === @entry_file_path # # The next entry, stored in @entry_file_path, will keep track # of our audio-file. This is the most important entry. # ======================================================================= # @entry_file_path = gtk_entry @entry_file_path.clear_background @entry_file_path.pad5px @entry_file_path.css_class('mar4px') @entry_file_path.yellow_background @entry_file_path.bblack2 @entry_file_path.make_bold @entry_file_path.width_height(620, 42) @entry_file_path.ghost_text('Provide the path to the .mp3 file here ...') array = Dir['/home/x/songs/*'].map {|entry| File.basename(entry) } @entry_file_path.simple_completion(array) @entry_file_path.on_enter { do_analyse_the_mp3_file } @entry_file_path.make_scrollable @entry_file_path.signal_connect(:event) {|widget, event| if scroll_up_event?(event) do_assign_a_new_random_audio_file elsif scroll_down_event?(event) do_assign_a_new_random_audio_file end } # ======================================================================= # # If the user double-clicks on the file path then a new local file # will be added. # ======================================================================= # @entry_file_path.on_mouse_double_click_event {|widget, event| do_open_a_local_file_and_then_set_the_proper_entry } end
#¶ ↑
create_the_header_bar
(header tag)¶ ↑
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/create.rb, line 382 def create_the_header_bar # ======================================================================= # # === @header_bar # ======================================================================= # @header_bar = widget_top end
#¶ ↑
create_the_labels
(labels tag, label tag)¶ ↑
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/create.rb, line 48 def create_the_labels # ======================================================================= # # === @label_description # # This is the very top-level description. # ======================================================================= # @label_description = bold_label( 'This widget can be used to modify the ID3 tags of .mp3 files' ) @label_description.css_class('indigo') @label_description.font_to_use = FONT_TO_USE_FOR_THE_MAIN_DESCRIPTION end
#¶ ↑
create_the_settings
¶ ↑
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/create.rb, line 64 def create_the_settings # ======================================================================= # # === @settings_vbox # ======================================================================= # @settings_vbox = gtk_vbox # ======================================================================= # # Style this vbox a bit: # ======================================================================= # @settings_vbox.pad5px @settings_vbox.set_border_width(20) @settings_vbox.use_this_font = main_font? _ = text("Settings\n") _.use_this_font = main_font? @settings_vbox.add(_) @settings_vbox.add_hspacer hbox = gtk_hbox hbox.minimal(left_aligned_text('Specify the directory to the local songs here: '), 2) hbox.minimal(@entry_use_this_as_the_directory_to_the_local_songs) @settings_vbox << hbox @settings_vbox.add_hspacer @settings_vbox.use_this_font = main_font? @settings_vbox.width_height(800, 300) @settings_vbox.show_all end
#¶ ↑
create_the_status_bar
¶ ↑
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/create.rb, line 36 def create_the_status_bar # ======================================================================= # # === @status_bar # ======================================================================= # @status_bar = gtk_status_bar @status_bar.bblack1 @status_bar_context_id = @status_bar.get_context_id('tag_mp3_files') end
#¶ ↑
date?¶ ↑
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/misc.rb, line 815 def date? @date end
#¶ ↑
disc?¶ ↑
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/misc.rb, line 822 def disc? @disc end
#¶ ↑
display_information_about_the_song
(debug tag)¶ ↑
This method exists mostly to simplify debugging the application at hand.
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/misc.rb, line 1692 def display_information_about_the_song # ======================================================================= # # Get and set text frames with convenience methods. # ======================================================================= # e horizontal_unicode_bar*80 dataset = metadata? if dataset ee 'Title: '.ljust(30); pp dataset.title # => "Talk" ee 'Album: '.ljust(30); pp dataset.album # new album setter ee 'Performer: (not in use) '.ljust(30);pp dataset.performer # performer; this is not in use by this application though. ee 'Artist: '.ljust(30); pp dataset.artist ee 'Band: '.ljust(30); pp dataset.band ee 'bpm: '.ljust(30); pp dataset.bpm ee 'Date: '.ljust(30); pp dataset.date ee 'Disc: '.ljust(30); pp dataset.disc ee 'Genre: '.ljust(30); pp dataset.genre ee 'time: '.ljust(30); pp dataset.time if dataset.respond_to? :time ee 'track: '.ljust(30); pp dataset.track if dataset.respond_to? :track ee 'language: '.ljust(30); pp dataset.language if dataset.respond_to? :language ee 'Grouping: '.ljust(30); pp dataset.grouping if dataset.respond_to? :grouping ee 'Encoded by: '.ljust(30);pp dataset.encoded_by if dataset.respond_to? :encoded_by ee 'composer: '.ljust(30); pp dataset.composer if dataset.respond_to? :composer ee 'Track: '.ljust(30); pp dataset.track if dataset.respond_to? :track # new track setter ee 'Year: '.ljust(30); pp dataset.year # 2000, query year. ee 'Comment: '.ljust(30); pp dataset.comment # Comments are listed there. e horizontal_unicode_bar*80 e else e 'No dataset has been assigned yet.' end end
#¶ ↑
do_analyse_the_audio_file_then_set_all_relevant_entries
¶ ↑
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/misc.rb, line 1565 def do_analyse_the_audio_file_then_set_all_relevant_entries do_analyse_the_audio_file(entry_file_path_text?) set_all_relevant_entries_based_on_the_metadata end
#¶ ↑
do_analyse_the_mp3_file
(analyse tag, load tag)¶ ↑
This is closely related to the method called do_analyse_the_audio_file_then_set_all_relevant_entries
().
This is the method that should be called when the user wants to obtain information about the metadata of the song (.mp3 file) at hand.
It will not do anything with the different gtk-widgets in use, so you have to call other methods if you want to sync towards the gtk-widgets.
We also need to check whether ID3Lib is available if this is used; in particular windows-users may often not have it installed by default.
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/misc.rb, line 1205 def do_analyse_the_mp3_file( _ = entry_file_path_text? ) if _ and !_.empty? and File.exist?(_) # ===================================================================== # # First we have to honour the correct id-tagger to use, as specified # by the user. # ===================================================================== # case ID_TAGGER_TO_USE_FOR_THE_MP3_FILES # ===================================================================== # # === :taglib # # We must notify the user that taglib is mandatory - otherwise the # application will not work properly. # ===================================================================== # when :taglib unless Object.const_defined? :TagLib text_to_display = <<-EOF Please install TagLib first via: <b>gem install taglib-ruby</b> EOF custom_widget = gtk_vbox custom_widget.pad12px custom_widget.bblack1 button_to_use = button('gem install taglib-ruby') button_to_use.on_clicked { esystem(button_to_use.text?) } custom_widget.maximal(button_to_use) custom_widget.show_all a_new_popup = return_popover( text_to_display, entry_on_top?, 25, # Padding is 25 px. custom_widget ) a_new_popup.popup end # ===================================================================== # # === :id3lib # ===================================================================== # when :id3lib if Object.const_defined? :ID3Lib this_song = ID3Lib::Tag.new(this_song) # Enable the save-button functionality. This is currently (2021) # not needed anymore. # the_save_button_is_available_again else e 'ID3Lib is not available/installed. Please install '\ 'it for your platform / operating-system.' end end @spinner.start_spinning Thread.new { # =================================================================== # # Clear the old status-bar message first. # =================================================================== # add_this_text_to_the_status_bar('') # =================================================================== # # The class here is: MultimediaParadise::AudioTagReader. # The old code used MultimediaParadise::AudioTagReader.new() # directly. In September 2021 this was changed to a # toplevel-method instead. # =================================================================== # clear_old_entries e steelblue('-' * 60) instantiate_the_metadata_from_this_file(_)# This will set @metadata_for_the_song @metadata_for_the_song.report # This can be used for debugging. @information_about_a_mp3_file.set_duration(@metadata_for_the_song.length_in_seconds?.to_s) file_size = File.size(_) @information_about_a_mp3_file.set_filesize(file_size.to_s) # entry_for_the_title_of_the_song?.set_text(@metadata_for_the_song.title?.to_s) do_assume_the_name_of_the_song_and_the_artist_from_the_filename_directly sync_everything @spinner.stop_spinning # Now we can stop spinning. if is_on_roebe? display_information_about_the_song e 'Next, as we are on roebe, we will display the '+ ::Colours.steelblue('@dataset')+' variable.' pp dataset? end } else e 'First assign a path, please.' end end
#¶ ↑
do_assign_a_new_random_audio_file
¶ ↑
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/misc.rb, line 1455 def do_assign_a_new_random_audio_file _ = return_random_audio_file.to_s unless _.empty? # Check against no results. entry_file_path?.set_text(_) do_open_a_random_audio_file_and_then_set_the_proper_entry end end
#¶ ↑
do_assume_the_name_of_the_song_and_the_artist_from_the_filename_directly
¶ ↑
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/misc.rb, line 1751 def do_assume_the_name_of_the_song_and_the_artist_from_the_filename_directly _ = filename? if _ and File.exist?(_) raw_name = File.basename(_) # ===================================================================== # # Get rid of the extension. # ===================================================================== # raw_name.delete_suffix!( File.extname(raw_name) ) if raw_name.include? '_' splitted = raw_name.split('_') artist_name = splitted.first.to_s song_name = splitted.last.to_s @entry_for_the_artist.set_text(artist_name) entry_for_the_song_name?.set_text(song_name) else @entry_for_the_artist.set_text(raw_name) end else e 'No file has been assigned yet. Please assign a file first.' end end
#¶ ↑
do_determine_the_length_of_the_song
¶ ↑
The first argument should be the name of the .mp3 file at hand.
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/misc.rb, line 1024 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
#¶ ↑
do_look_for_a_local_file_and_then_analyse_the_audio_file_at_once
(open tag)¶ ↑
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/misc.rb, line 1342 def do_look_for_a_local_file_and_then_analyse_the_audio_file_at_once look_for_a_local_file {{ filter_for: %w( .mp3 .ogg ), start_directory: return_path_to_the_local_songs_directory_or_return_pwd, additional_directories: [return_pwd] # Always add the current working directory. }} @entry_file_path.set_text(::Gtk.main_file?.to_s) do_analyse_the_audio_file_at_once end
#¶ ↑
do_open_a_random_audio_file_and_then_set_the_proper_entry
¶ ↑
The first argument to this method must be the file path to the local .mp3 file at hand.
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/misc.rb, line 1161 def do_open_a_random_audio_file_and_then_set_the_proper_entry( _ = return_random_audio_file ) clear_old_entries # We must clear old entries as well. entry_file_path?.set_text(_.to_s) # ======================================================================= # # If the file exists we will also update the file size label. # ======================================================================= # if File.exist? _ do_analyse_the_audio_file(entry_file_path_text?) set_all_relevant_entries_based_on_the_metadata # ===================================================================== # # Empty the status bar as well whenever a new file is assigned. # ===================================================================== # add_this_text_to_the_status_bar('') end end
#¶ ↑
do_perform_a_google_search
¶ ↑
This method will “perform” a browser search. We will simply open the browser; on linux this works fine. :-)
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/misc.rb, line 288 def do_perform_a_google_search( song_name = song_name?, artist_name = artist? ) unless Object.const_defined? :Open begin require 'open' rescue LoadError; end end _ = ''.dup _ << 'https://www.google.com/search?q=' _ << 'wikipedia+' # Preface with "wikipedia". _ << song_name.to_s.tr(' ','+')+'+' _ << artist_name.to_s.tr(' ','+') _ << '&ie=utf-8&oe=utf-8' Open.in_browser(_) end
#¶ ↑
do_popup_the_settings_widget
(settings tag)¶ ↑
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/misc.rb, line 458 def do_popup_the_settings_widget if @settings_popover.nil? @settings_popover = return_popover( '', header?, # This is the header bar actually. :default_padding, # This is the default padding to use. @settings_vbox ) end @settings_popover.popup end
#¶ ↑
do_show_information_about_this_application
(about tag)¶ ↑
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/misc.rb, line 1528 def do_show_information_about_this_application dialog = gtk_about_dialog authors = ['Robert A. Heiler'] documenters = ['Robert A. Heiler'] begin logo = GdkPixbuf::Pixbuf.new( pixbuf: return_pixbuf_based_on_the_default_icon_theme(:inode_directory) ) dialog.set_logo(logo) rescue Exception => error pp error end dialog.set_name('tag_mp3_files') dialog.set_version(::MultimediaParadise::VERSION) dialog.set_copyright("(C) 2022 Robert A. Heiler") dialog.set_comments( "This application can be used to rename the meta-tags "\ "of .mp3 files. It is recommended to install the "\ "taglib-ruby gem, in order to use this application." ) dialog.license = 'GPL-2.0' dialog.set_website( 'https://rubygems.org/gems/multimedia_paradise' ) dialog.set_website_label('https://rubygems.org/gems/multimedia_paradise') dialog.set_authors(authors) dialog.set_documenters(documenters) dialog.set_program_name('tag_mp3_files') dialog.signal_connect(:response) { dialog.destroy } dialog.run end
#¶ ↑
entry_for_the_title_of_the_song?¶ ↑
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/misc.rb, line 496 def entry_for_the_title_of_the_song? @entry_for_the_title_of_the_song end
#¶ ↑
entry_use_which_audio_file?¶ ↑
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/misc.rb, line 1661 def entry_use_which_audio_file? @entry_file_path end
#¶ ↑
genre?¶ ↑
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/misc.rb, line 857 def genre? @genre end
#¶ ↑
header_bar?¶ ↑
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/misc.rb, line 131 def header_bar? @header_bar end
#¶ ↑
instantiate_the_metadata_from_this_file
¶ ↑
This will set @metadata_for_the_song.
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/misc.rb, line 1110 def instantiate_the_metadata_from_this_file(this_file) # ======================================================================= # # === @metadata_for_the_song # ======================================================================= # @metadata_for_the_song = MultimediaParadise.analyse_tags_of_this_mp3_file(this_file) end
#¶ ↑
performer?¶ ↑
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/misc.rb, line 864 def performer? @performer end
#¶ ↑
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/gui/gtk3/tag_mp3_files/misc.rb, line 953 def report_everything report_title report_artist report_album report_year report_genre report_comment report_length_in_seconds end
#¶ ↑
require_the_appropriate_id_tagger
¶ ↑
This method will load the correct id-tagger for .mp3 files. We need to make this flexible, in the event that the user wants to use another id-tagger rather than the “default” one.
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/misc.rb, line 65 def require_the_appropriate_id_tagger( i = ID_TAGGER_TO_USE_FOR_THE_MP3_FILES ) case i # ======================================================================= # # === :taglib # # Note that since as of the year 2021, taglib is the default id3-tagger # that will be used by this application, thus replacing the older # id3lib code. The latter is still retained, though, in the event # we may have to switch again one day. But in my opinion taglib is # actually better than idlib. # ======================================================================= # when :taglib begin require 'taglib' rescue LoadError e "the taglib gem is not available. Please install it." e e ' gem install taglib-ruby # The github-page is at: '\ 'https://github.com/robinst/taglib-ruby' e if is_on_roebe? e 'As we are on roebe we will install the gem next.' e system 'gem install taglib-ruby' e begin require 'taglib' rescue LoadError; end end end # ======================================================================= # # === when :idlib # ======================================================================= # when :idlib begin require 'id3lib' rescue LoadError e "ruby-id3lib not available. Please install it." e e ' gem install id3lib-ruby' e end else e "Unknown ID-tagger #{i}" end end
#¶ ↑
reset (reset tag)¶ ↑
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/misc.rb, line 33 def reset reset_the_internal_variables infer_the_namespace # ======================================================================= # # === @configuration # ======================================================================= # @configuration = [true, __dir__, namespace?] title_width_height_font(TITLE, WIDTH, HEIGHT, USE_THIS_FONT) infer_the_size_automatically handle_CSS_rules # Should be called from the reset() method. # ======================================================================= # # === @information_about_a_mp3_file # ======================================================================= # @information_about_a_mp3_file = return_widget_information_about_a_mp3_file # ======================================================================= # # === @metadata_for_the_song # # This variable will change when the metadata of a song is analysed. # It will contain the dataset of that song, including the audio # tags, at a later point - whenever a .mp3 file is analysed. # ======================================================================= # @metadata_for_the_song = nil require_the_appropriate_id_tagger end
#¶ ↑
reset_all_main_entries
¶ ↑
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/misc.rb, line 160 def reset_all_main_entries @entry_for_the_title_of_the_song.set_text('') @entry_for_the_year.set_text('') @entry_for_the_artist.set_text('') @entry_for_the_genre.set_text('') @entry_for_the_comment.set_text('') end
#¶ ↑
return_all_entries_on_the_right_side_widget
¶ ↑
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/misc.rb, line 145 def return_all_entries_on_the_right_side_widget [ # Let's keep them ordered how we want to display them. @entry_for_the_artist, @entry_for_the_year, @entry_for_the_album, @entry_for_the_comment, @entry_for_the_track_number, @entry_for_the_genre, @entry_for_the_title_of_the_song ] end
#¶ ↑
return_entry_from_the_combo_box_entry_for_genre_select_or_from_the_entry_for_the_genre
¶ ↑
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/misc.rb, line 274 def return_entry_from_the_combo_box_entry_for_genre_select_or_from_the_entry_for_the_genre _ = @combo_box_entry_for_genre_select.active_text unless @entry_for_the_genre.text.to_s.empty? _ = @entry_for_the_genre.text.to_s end return _ end
#¶ ↑
return_event_box_for_opening_a_file
¶ ↑
The first two arguments can designate a certain width and height for the widget.
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/misc.rb, line 1308 def return_event_box_for_opening_a_file( width = 110, height = 65 ) event_box_open_file = gtk_event_box # ======================================================================= # # In April 2021 the code below this comment was changed to an image. # # Relying on an emoji is unfortunately not that reliable, because # we depend on the emojis available on the local computer. This # may not always work, whereas with an image we can depend on # more reliably so. # # event_box_open_file << emoji(:open_file) # # ======================================================================= # # event_box_open_file << gtk_image(:open_local_file) event_box_open_file << text('Open a local file') event_box_open_file.set_border_width(1) event_box_open_file.set_size_request(125, 68) event_box_open_file.css_class('button_class') event_box_open_file.pad5px event_box_open_file.on_clicked { do_look_for_a_local_file_and_then_analyse_the_audio_file_at_once } event_box_open_file.hint = 'Click on this button to open '\ '<b>a local .mp3 file</b>.' return event_box_open_file end
#¶ ↑
return_random_audio_file
¶ ↑
This method can be used to return a random audio file from a given (local) directory. This will only work, evidently, when the directory contains audio files.
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/misc.rb, line 322 def return_random_audio_file( from_this_directory = @entry_use_this_as_the_directory_to_the_local_songs.text? ) if File.directory? from_this_directory.delete('*') _ = from_this_directory.delete('*')+'*' this_file = Dir[_].select {|entry| entry.end_with?('.mp3') }.sample return this_file end return nil end
#¶ ↑
return_widget_information_about_a_mp3_file
¶ ↑
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/misc.rb, line 1148 def return_widget_information_about_a_mp3_file @information_about_a_mp3_file = MultimediaParadise::GUI::Gtk::InformationAboutAMp3File.new @information_about_a_mp3_file.set_parent_widget(self) return @information_about_a_mp3_file end
#¶ ↑
run (run tag)¶ ↑
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/misc.rb, line 1822 def run create_skeleton_then_connect_skeleton menu # Must come after the skeleton has been created. do_focus_on_the_entry_containing_the_title_of_the_song apply_the_CSS_rules end
#¶ ↑
set_a_uniform_background_for_the_entries_on_the_right_side_widget
¶ ↑
This is currently (August 2021) not in use. I realized that it actually rather distracts then enhances. I keep it here if we want to re-enable it again at one moment in time.
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/misc.rb, line 1649 def set_a_uniform_background_for_the_entries_on_the_right_side_widget( array = return_all_entries_on_the_right_side_widget ) array.each {|this_entry| this_entry.clear_background this_entry.very_light_yellowish_background } end
#¶ ↑
set_album
¶ ↑
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/misc.rb, line 892 def set_album(i) @album = i.to_s end
#¶ ↑
set_all_relevant_entries_based_on_the_metadata
(sync tag)¶ ↑
This method will sync all relevant entries into the corresponding gtk-entry at hand.
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/misc.rb, line 1781 def set_all_relevant_entries_based_on_the_metadata( this_file = main_file? ) # ======================================================================= # # First ensure that the file exists. # ======================================================================= # if this_file.nil? or !File.exist?(this_file) e "No file exists at `#{sfile(this_file)}`." _ = return_popover("No file exists at #{this_file}.", entry_on_top?) _.popup return end set_the_file_size_from_this_file # ======================================================================= # # Keep track of the song's duration as well. # ======================================================================= # sync_the_duration_of_the_file_onto_the_correct_entry sync_title_onto_entry sync_year_onto_entry sync_artist_onto_entry sync_genre_onto_entry sync_comment_onto_entry set_the_bitrate( MultimediaParadise.bitrate_of_this_song(this_file) ) set_the_samplerate( MultimediaParadise.samplerate_of_this_song(this_file) ) update_the_MPEG_entry(this_file) end
#¶ ↑
set_artist
¶ ↑
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/misc.rb, line 899 def set_artist(i) @artist = i.to_s end
#¶ ↑
set_comment
¶ ↑
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/misc.rb, line 906 def set_comment(i) @comment = i.to_s end
#¶ ↑
set_genre
¶ ↑
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/misc.rb, line 927 def set_genre(i) @genre = i.to_s end
#¶ ↑
set_the_file_size_from_this_file
¶ ↑
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/misc.rb, line 1618 def set_the_file_size_from_this_file( this_file = @entry_file_path.text? ) @information_about_a_mp3_file.label_file_size_content.set_text( "#{(File.size(this_file) / 1024.0 / 1000.0).round(2)} MB". rjust(8) ) end
#¶ ↑
set_title
¶ ↑
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/misc.rb, line 885 def set_title(i) @title = i.to_s end
#¶ ↑
set_track
¶ ↑
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/misc.rb, line 913 def set_track(i) @track = i.to_i # This must be an Integer. end
#¶ ↑
set_year
¶ ↑
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/misc.rb, line 920 def set_year(i) @year = i.to_i # This must be an Integer. end
#¶ ↑
sync_comment_onto_entry
¶ ↑
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/misc.rb, line 1630 def sync_comment_onto_entry dataset = dataset? if dataset _ = dataset.comment.to_s.dup # ===================================================================== # # We have to use the proper encoding for the comment-field. # ===================================================================== # _ = _.force_encoding(::MultimediaParadise::UTF_ENCODING) @entry_for_the_comment.set_text(_) end end
#¶ ↑
sync_the_duration_of_the_file_onto_the_correct_entry
¶ ↑
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/misc.rb, line 1128 def sync_the_duration_of_the_file_onto_the_correct_entry( _ = @metadata_for_the_song ) if _ use_this_duration = _.length_in_seconds?.round(5).to_s label_duration_content?.set_text(use_this_duration) label_duration_content?.make_bold end end
#¶ ↑
sync_this_text_onto_the_genre_entry
¶ ↑
This method can be used to “sync” onto the entry containing the genre tag. We won’t do any additional sanitizing or checks within this method, excluding .to_s, so you have to ensure that the given input is valid, as-is.
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/misc.rb, line 1519 def sync_this_text_onto_the_genre_entry(i) @entry_for_the_genre.set_text(i.to_s) @entry_for_the_genre.make_bold end
#¶ ↑
tag?¶ ↑
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/misc.rb, line 794 def tag? @tag end
#¶ ↑
this_file?¶ ↑
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/misc.rb, line 1008 def this_file? @this_file end
#¶ ↑
title?¶ ↑
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/misc.rb, line 801 def title? @title end
#¶ ↑
track?¶ ↑
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/misc.rb, line 878 def track? @track end
#¶ ↑
try_to_require_the_tablib_gem
¶ ↑
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/misc.rb, line 1040 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 method can be used to update the tags.
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/misc.rb, line 1056 def update!( this_file = @this_file ) 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
#¶ ↑
widget_left
¶ ↑
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/misc.rb, line 546 def widget_left _ = @widget_on_the_right_side_including_the_title_of_the_song = gtk_vbox _.set_border_width(2) # ======================================================================= # # === Title of the song # ======================================================================= # label_title = modify_bold_label( 'Title of the song:', 'black', :right ).center # align_left_and_center_in_the_middle # label_with_the_audio_symbol = gtk_label(:three_stars) # This used to be :audio3 another_tiny_hbox = gtk_hbox use_this_icon_name = 'audio-speakers' begin icon = icon_theme?.load_icon(use_this_icon_name, 32, 0) rescue ::Gtk::IconThemeError::NotFound => error e tomato('An error occurred:') e pp error e icon = icon_theme?.load_icon('audio-x-generic', 32, 0) end label_with_the_audio_symbol = gtk_image_pixbuf(icon) another_tiny_hbox.minimal(label_with_the_audio_symbol) another_tiny_hbox.maximal(label_title) mini_vbox = gtk_vbox # mini_vbox.pack_start(label_title) mini_vbox.maximal(another_tiny_hbox) arrow_to_the_right = gtk_label('→ ') tiny_hbox = gtk_hbox tiny_hbox.minimal(arrow_to_the_right) # ======================================================================= # # Add the entry for the title of the song next. # ======================================================================= # tiny_hbox.maximal(@entry_for_the_title_of_the_song) mini_vbox.maximal(tiny_hbox) _.minimal(mini_vbox, 0) # ======================================================================= # # Create the grid next that is situated on the right side. # ======================================================================= # @grid_on_the_right_side = gtk_grid @grid_on_the_right_side.set_column_spacing(1) @grid_on_the_right_side.set_row_spacing(1) _.minimal(@grid_on_the_right_side, 2) # ======================================================================= # # === Artist # ======================================================================= # label_the_artist = gtk_label('Artist: ').align_left_and_center_in_the_middle label_the_artist.make_bold # ======================================================================= # # === @entry_for_the_artist # ======================================================================= # @entry_for_the_artist = gtk_entry @entry_for_the_artist.set_max_length(40) @entry_for_the_artist.set_size_request(300, 40) @grid_on_the_right_side.attach(label_the_artist, 0, 0, 1, 1) # left, top, width, height @grid_on_the_right_side.attach(@entry_for_the_artist, 1, 0, 1, 1) # ======================================================================= # # === Year # ======================================================================= # label_for_the_year = gtk_label('Year: ').align_left_and_center_in_the_middle label_for_the_year.make_bold label_for_the_year.hint = 'The <b>Year</b> entry should ideally '\ 'indicate when a song was released officially. Some songs were '\ 'recorded in a year before, but the more relevant entry will '\ 'be the year in which that song was released.' # ======================================================================= # # === @entry_for_the_year # ======================================================================= # @entry_for_the_year = gtk_entry @entry_for_the_year.set_max_length(50) @entry_for_the_year.allow_only_numbers @entry_for_the_year.focus_on_click_event @grid_on_the_right_side.attach(label_for_the_year, 0, 1, 1, 1) # left, top, width, height hbox = gtk_hbox hbox.maximal(@entry_for_the_year, 1) combo_box_entry = gtk_combo_box_entry combo_box_entry.populate( (1960 .. 2050).to_a.map(&:to_s) ) combo_box_entry.this_entry_is_active(30) combo_box_entry.on_changed { @entry_for_the_year.set_text(combo_box_entry.text?) } hbox.minimal(combo_box_entry) @grid_on_the_right_side.attach(hbox, 1, 1, 1, 1) # ======================================================================= # # === Album # ======================================================================= # label_for_the_album = gtk_label('Album: ').align_left_and_center_in_the_middle label_for_the_album.make_bold # ======================================================================= # # === @entry_for_the_album # ======================================================================= # @entry_for_the_album = gtk_entry @entry_for_the_album.set_max_length(75) @grid_on_the_right_side.attach(label_for_the_album, 0, 2, 1, 1) # left, top, width, height @grid_on_the_right_side.attach(@entry_for_the_album, 1, 2, 1, 1) # ======================================================================= # # === Comment (comment tag) # # Personally I use this field as a placeholder for a remote URL, # to some of the .mp3 songs. This may be useful in other graphical # applications. # ======================================================================= # label_for_the_comment = gtk_label('Comment: ').align_left_and_center_in_the_middle label_for_the_comment.make_bold event_box_with_left_arrow = gtk_eventbox(emoji(:left_arrow)) event_box_with_left_arrow.hint = 'Click on this arrow '\ 'to open the URL (if there is one), via the browser.' event_box_with_left_arrow.on_clicked { require 'open' unless Object.const_defined? :Open Open.in_browser('"'+comment_entry?.text.to_s.strip+'"') unless comment_entry?.text.to_s.empty? } mini_hbox = gtk_hbox mini_hbox.maximal(@entry_for_the_comment) mini_hbox.minimal(event_box_with_left_arrow) @grid_on_the_right_side.attach(label_for_the_comment, 0, 3, 1, 1) # left, top, width, height @grid_on_the_right_side.attach(mini_hbox, 1, 3, 1, 1) # ======================================================================= # # === Track number # ======================================================================= # label_for_the_track_number = gtk_label('Track number: ').align_left_and_center_in_the_middle label_for_the_track_number.make_bold # ======================================================================= # # === @entry_for_the_track_number # ======================================================================= # @entry_for_the_track_number = gtk_entry @entry_for_the_track_number.set_max_length(3) @entry_for_the_track_number.set_size_request(50, -1) @entry_for_the_track_number.allow_only_numbers unless @dataset.nil? save_this = @dataset save_this = @dataset.track if @dataset.respond_to? :track @entry_for_the_track_number.set_text(save_this) do_activate_the_save_button end @grid_on_the_right_side.attach(label_for_the_track_number, 0, 4, 1, 1) # left, top, width, height @grid_on_the_right_side.attach(@entry_for_the_track_number, 1, 4, 1, 1) # ======================================================================= # # === Genre # ======================================================================= # label_for_the_genre = gtk_label('Genre: ').align_left_and_center_in_the_middle label_for_the_genre.make_bold label_for_the_genre.set_size_request(125, 40) @entry_for_the_genre = gtk_entry @entry_for_the_genre.set_size_request(125, 40) @entry_for_the_genre.make_bold @grid_on_the_right_side.attach(label_for_the_genre, 0, 5, 1, 1) # left, top, width, height @grid_on_the_right_side.attach(@entry_for_the_genre, 1, 5, 1, 1) # ======================================================================= # # === Genre (select) # # This will load the file called "music_genres.yml", which in turn # contains the most commonly used genre entries. Note that this file # will NOT contain all genres, as that would lead to a very long # dropdown listing. # ======================================================================= # label_for_the_genre_select = gtk_label('Genre (select): ').align_left_and_center_in_the_middle label_for_the_genre_select.make_bold create_the_combo_box_entry_for_genre_select # ======================================================================= # # Next build up the hbox that contains the label and the combo box: # ======================================================================= # hbox_for_the_genre_select_components = gtk_hbox( label_for_the_genre_select, @combo_box_entry_for_genre_select ) hbox_for_the_genre_select_components.pack_end( @button_assume, padding: 2 ) _.minimal( hbox_for_the_genre_select_components, 0 ) _.minimal(return_the_save_button, 2) return _ end
#¶ ↑
widget_right
¶ ↑
This is the large vbox that appears on the very left side, containing tons of buttons.
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/misc.rb, line 476 def widget_right vbox_containing_the_buttons = gtk_vbox vbox_containing_the_buttons.border_width = 6 vbox_containing_the_buttons.minimal(@button_debug, 1) vbox_containing_the_buttons.minimal(@box_for_the_button_analyse_the_mp3_file, 1) vbox_containing_the_buttons.minimal(@event_box_open_file, 1) vbox_containing_the_buttons.minimal(@button_perform_a_google_search, 1) vbox_containing_the_buttons.minimal(@button_open_a_random_audio_file, 1) vbox_containing_the_buttons.minimal(@button_delete_the_tags, 1) vbox_containing_the_buttons.minimal(@button_update, 1) vbox_containing_the_buttons.minimal(@button_play, 1) vbox_containing_the_buttons.minimal(@button_save, 1) vbox_containing_the_buttons.minimal(@button_close, 1) vbox_containing_the_buttons.use_this_font = slightly_smaller_font? return vbox_containing_the_buttons end
#¶ ↑
widget_second_row
¶ ↑
This widget contains the “File path: ” string.
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/misc.rb, line 426 def widget_second_row _ = gtk_hbox _.pad2px # ======================================================================= # # === The label containing "Input the path to a local .mp3 file: " # ======================================================================= # label = label('File path: ') label.align_to_the_left label.hint = 'To the right of this text you can designate the '\ 'path to the local .mp3 file.' _.minimal(label, 6) eventbox_arrow_right = gtk_eventbox(emoji(:arrow_right)) eventbox_arrow_right.on_clicked { do_open_a_local_file_and_then_set_the_proper_entry } _.minimal(eventbox_arrow_right, 2) _.maximal(entry_file_path?, 4) button_open_local_file = gtk_button('Open local file') button_open_local_file.use_this_font = slightly_smaller_font? button_open_local_file.hint = 'Click on this button to open a local file.' button_open_local_file.on_clicked { do_look_for_a_local_file_and_then_analyse_the_audio_file_at_once } _.minimal(button_open_local_file, 4) _.minimal(gtk_vspacer) _.minimal(gtk_vspacer, 1) return _ end
#¶ ↑
widget_top
¶ ↑
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/misc.rb, line 1397 def widget_top # ======================================================================= # # === @header_bar # # This is the widget that will be found on the very top of this # application. # ======================================================================= # _ = default_header_bar _.show_close_button = true _.has_close_button _.set_name('header_bar_on_top') _.set_custom_title(@label_description) _.spacing = 2 _.use_this_font = normal_font? button_open_a_random_audio_file = return_button_open_a_random_audio_file(:no_text) button_open_a_random_audio_file.hint = 'Click this button to <b>open and assign a random .mp3 file</b>.' _.pack_start(button_open_a_random_audio_file) # ======================================================================= # # === Open a local file, as part of the menu-interface # ======================================================================= # open_a_local_file = gtk_button('Open a local file') open_a_local_file.on_activate { do_open_a_local_file_and_then_set_the_proper_entry } _.pack_start(open_a_local_file) # ======================================================================= # # === Show about-information, as part of the top header-bar # # It will be appended, aka .pack_end() is used. # ======================================================================= # button_about = button('About') button_about.hint = 'This will display information about this '\ 'application.' button_about.on_clicked { do_show_information_about_this_application } _.pack_end(button_about) # ======================================================================= # # === button_show_the_settings # ======================================================================= # button_show_the_settings = gtk_button('Settings') button_show_the_settings.hint = 'This button allows you to change a few '\ 'settings of this application.' button_show_the_settings.on_clicked { do_popup_the_settings_widget } _.pack_start(button_show_the_settings) return _ end
#¶ ↑
work_on_this_file
¶ ↑
#¶ ↑
# File lib/multimedia_paradise/gui/gtk3/tag_mp3_files/misc.rb, line 966 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