Created
December 21, 2011 16:51
-
-
Save tadzik/1506741 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use NativeCall; | |
class Tag is repr('CPointer') { | |
class TagFile is repr('CPointer') {} | |
sub taglib_tag_title(Tag) returns Str is native('libtag_c.so') {} | |
sub taglib_tag_artist(Tag) returns Str is native('libtag_c.so') {} | |
sub taglib_tag_album(Tag) returns Str is native('libtag_c.so') {} | |
sub taglib_tag_genre(Tag) returns Str is native('libtag_c.so') {} | |
sub taglib_tag_year(Tag) returns Int is native('libtag_c.so') {} | |
sub taglib_tag_track(Tag) returns Int is native('libtag_c.so') {} | |
sub taglib_tag_free_strings(Tag) is native('libtag_c.so') {} | |
method title { taglib_tag_title(self) } | |
method artist { taglib_tag_artist(self) } | |
method album { taglib_tag_album(self) } | |
method genre { taglib_tag_genre(self) } | |
method year { taglib_tag_year(self) } | |
method track { taglib_tag_track(self) } | |
method free { taglib_tag_free_strings(self) } | |
} | |
class TagFile is repr('CPointer') { | |
sub taglib_file_new(Str) returns TagFile is native('libtag_c.so') {} | |
sub taglib_file_free(TagFile) is native('libtag_c.so') {} | |
sub taglib_file_tag(TagFile) returns Tag is native('libtag_c.so') {} | |
sub taglib_file_is_valid(TagFile) returns Int | |
is native('libtag_c.so') {} | |
method new(Str $filename) { | |
unless $filename.IO.e { | |
die "File '$filename' not found" | |
} | |
my $self = self.bless(taglib_file_new($filename)); | |
unless taglib_file_is_valid($self) { | |
die "'$filename' is invalid" | |
} | |
return $self; | |
} | |
method tag { taglib_file_tag(self) } | |
method free { taglib_file_free(self) } | |
} | |
sub MAIN($file) { | |
my $f = TagFile.new($file); | |
my $t = $f.tag; | |
say 'Artist: ', $t.artist; | |
say 'Title: ', $t.title; | |
say 'Album: ', $t.album; | |
say 'Genre: ', $t.genre; | |
say 'Year: ', $t.year; | |
$t.free; | |
$f.free; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment