Module: CultomePlayer::Media

Included in:
CultomePlayer
Defined in:
lib/cultome_player/media.rb

Instance Method Summary collapse

Instance Method Details

#extract_from_mp3(filepath, opc = {}) ⇒ Hash

Get information from ID3 tags in a mp3.

Parameters:

  • filepath (String)

    The absolute path to the mp3 file.

  • opc (Hash) (defaults to: {})

    Additional parameters. Actually only :library_path is supported.

Returns:

  • (Hash)

    With information extracted from ID3 tags.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/cultome_player/media.rb', line 11

def extract_from_mp3(filepath, opc={})
  info = nil
  TagLib::FileRef.open(filepath) do |mp3|
    unless mp3.nil?
      info = {
        # file information
        file_path: filepath,
        library_path: opc[:library_path],
        # song information
        album: mp3.tag.album,
        artist: mp3.tag.artist,
        genre: mp3.tag.genre,
        name: mp3.tag.title,
        track: mp3.tag.track,
        year: mp3.tag.year,
        duration: mp3.audio_properties.length,
      }
    end
  end
  # si no se encontro nombre de la cancion en las etiquestas, usamos el nombre del archivo
  info[:name] = filepath.split('/').last if info[:name].nil?
  # limpiamos la informacion un poco
  return polish_mp3_info(info)
end