taglib.cr
taglib.cr
Some spicy read-only (for now?) bindings to the C++ TagLib library. There be dragons.
Tested only on 64-bit architectures (amd64, aarch64).
Installation
- Install taglib on your system
- Add the dependency to your
shard.yml
:
dependencies:
taglib:
github: nilsding/taglib.cr
- Run
shards install
Usage
require "taglib"
fileref = TagLib::FileRef.new("Hubba Hubba Zoot Zoot.ogg")
# Get basic tag info
tags = fileref.tag.not_nil!
puts tags.artist # => Caramba
puts tags.album # => Så svenskt!
puts tags.year # => 2002
# Get additional tags
properties = fileref.file.not_nil!.properties
pp properties # => {"ALBUM" => ["Så svenskt!"],
# "ARTIST" => ["Caramba"],
# "DATE" => ["2002-06-18"],
# "TITLE" => ["Hubba Hubba Zoot Zoot"],
# "TRACKNUMBER" => ["2"],
# "TRACKTOTAL" => ["20"]}
# Get the audio properties of the given file
audio_properties = fileref.audio_properties.not_nil!
puts audio_properties.sample_rate # => 44100
puts audio_properties.length_in_seconds # => 117
# Extract all pictures from a FLAC file
fileref = TagLib::FileRef.new("SomeFile.flac")
if fileref.file.is_a?(TagLib::FLAC::File)
file = fileref.file.not_nil!.as(TagLib::FLAC::File)
file.pictures.each_with_index do |pic, i|
file_name = "#{i + 1}_#{pic.type}." + pic.mime_type.split("/").last
puts "Saving picture ##{i + 1} as #{file_name}"
File.open(file_name, "wb") do |f|
f.write pic.data
end
end
end
# => Saving picture #1 as 1_FrontCover.png
# => Saving picture #2 as 2_ColouredFish.png
# => Saving picture #3 as 3_LeadArtist.jpeg
Development
TODO: Write development instructions here
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
Contributors
- Georg Gadinger - creator and maintainer
Repository
taglib.cr
Owner
Statistic
- 0
- 0
- 0
- 0
- 0
- over 4 years ago
- March 27, 2020
License
MIT License
Links
Synced at
Thu, 07 Nov 2024 19:15:07 GMT
Languages