Funktioniert bei mir bisher wunderbar, deshalb dachte ich mir poste ich meine Ergebnisse hier gleich mal für alle.
Glaube im Englischen Forum gabs das eh schon, aber was solls.
Download
Include
Code: Alles auswählen
EnableExplicit
; Current Version: 1.5 (http://developer.kde.org/~wheeler/taglib.html)
; LastEdit: Kai Gartenschläger, 07.06.2009
; PureBasic: 4.31 x86
ImportC "tag_c.lib"
taglib_audioproperties_bitrate(audioProperties.l) As "_taglib_audioproperties_bitrate"
; Returns the bitrate of the file in kb/s.
taglib_audioproperties_channels(audioProperties.l) As "_taglib_audioproperties_channels"
; Returns the number of channels in the audio stream.
taglib_audioproperties_length(audioProperties.l) As "_taglib_audioproperties_length"
; Returns the length of the file in seconds.
taglib_audioproperties_samplerate(audioProperties.l) As "_taglib_audioproperties_samplerate"
; Returns the sample rate of the file in Hz.
taglib_file_audioproperties(file.l) As "_taglib_file_audioproperties"
; Returns a pointer To the the audio properties associated With this file. This will be freed automatically when the file is freed.
taglib_file_free(file.l) As "_taglib_file_free"
; Frees And closes the file.
taglib_file_is_valid(file.l) As "_taglib_file_is_valid"
; Unknown
taglib_file_new(filename.s) As "_taglib_file_new"
; Creates a TagLib file based on \a filename. TagLib will try To guess the file type.
; \returns NULL If the file type cannot be determined Or the file cannot be opened.
taglib_file_new_type(filename.s,type.l) As "_taglib_file_new_type"
; Creates a TagLib file based on \a filename. Rather than attempting To guess the type, it will use the one specified by \a type.
taglib_file_save(file.l) As "_taglib_file_save"
; Saves the \a file To disk.
taglib_file_tag(file.l) As "_taglib_file_tag"
; Returns a pointer To the tag associated With this file. This will be freed automatically when the file is freed.
taglib_id3v2_set_default_text_encoding(encoding.l) As "_taglib_id3v2_set_default_text_encoding"
; This sets the Default encoding For ID3v2 frames that are written To tags.
taglib_set_string_management_enabled(management.b) As "_taglib_set_string_management_enabled"
; TagLib can keep track of strings that are created when outputting tag values And clear them using taglib_tag_clear_strings().
; This is enabled by Default.
; However If you wish To do more fine grained management of strings, you can do so by setting \a management To FALSE.
taglib_set_strings_unicode(unicode.b) As "_taglib_set_strings_unicode"
; By Default all strings coming into Or out of TagLib's C API are in UTF8.
; However, it may be desirable For TagLib To operate on Latin1 (ISO-8859-1) strings in which Case this should be set To FALSE.
taglib_tag_title(tag.l) As "_taglib_tag_title"
; Sets the tag's title.
; By Default this string should be UTF8 encoded.
taglib_tag_artist(tag.l) As "_taglib_tag_artist"
; Sets the tag's artist.
; By Default this string should be UTF8 encoded.
taglib_tag_album(tag.l) As "_taglib_tag_album"
; Sets the tag's album.
; By Default this string should be UTF8 encoded.
taglib_tag_comment(tag.l) As "_taglib_tag_comment"
; Sets the tag's comment.
; By Default this string should be UTF8 encoded.
taglib_tag_genre(tag.l) As "_taglib_tag_genre"
; Sets the tag's genre.
; By Default this string should be UTF8 encoded.
taglib_tag_year(tag.l) As "_taglib_tag_year"
; Sets the tag's year. 0 indicates that this field should be cleared.
taglib_tag_track(tag.l) As "_taglib_tag_track"
; Sets the tag's track number. 0 indicates that this field should be cleared.
taglib_tag_set_title(tag.l,title.s) As "_taglib_tag_set_title"
; Returns a string With this tag's title.
; By Default this string should be UTF8 encoded And its memory should be freed using taglib_tag_free_strings().
taglib_tag_set_artist(tag.l,artist.s) As "_taglib_tag_set_artist"
; Returns a string With this tag's artist.
; By Default this string should be UTF8 encoded And its memory should be freed using taglib_tag_free_strings().
taglib_tag_set_album(tag.l,album.s) As "_taglib_tag_set_album"
; Returns a string With this tag's album name.
; By Default this string should be UTF8 encoded And its memory should be freed using taglib_tag_free_strings().
taglib_tag_set_comment(tag.l,comment.s) As "_taglib_tag_set_comment"
; Returns a string With this tag's comment.
; By Default this string should be UTF8 encoded And its memory should be freed using taglib_tag_free_strings().
taglib_tag_set_genre(tag.l,genre.s) As "_taglib_tag_set_genre"
; Returns a string With this tag's genre.
; By Default this string should be UTF8 encoded And its memory should be freed using taglib_tag_free_strings().
taglib_tag_set_year(tag.l,year.l) As "_taglib_tag_set_year"
; Returns the tag's year or 0 if year is not set.
taglib_tag_set_track(tag.l,track.l) As "_taglib_tag_set_track"
; Returns the tag's track number or 0 if track number is not set.
taglib_tag_free_strings() As "_taglib_tag_free_strings"
; Frees all of the strings that have been created by the tag.
EndImport
Enumeration
#TagLib_File_MPEG
#TagLib_File_OggVorbis
#TagLib_File_FLAC
#TagLib_File_MPC
#TagLib_File_OggFlac
#TagLib_File_WavPack
#TagLib_File_Speex
#TagLib_File_TrueAudio
#TagLib_File_Type
EndEnumeration
Enumeration
#TagLib_ID3v2_Latin1
#TagLib_ID3v2_UTF16
#TagLib_ID3v2_UTF16BE
#TagLib_ID3v2_UTF8
#TagLib_ID3v2_Encoding
EndEnumeration
DisableExplicit
Code: Alles auswählen
EnableExplicit
; LastEdit: Kai Gartenschläger, 07.06.2009
; PureBasic: 4.31 x86
XIncludeFile #PB_Compiler_Home + "Include\taglib.pbi"
Procedure.s MyMusicDirectory()
Protected sPath.s = Space(#MAX_PATH)
SHGetSpecialFolderPath_(#Null, @sPath, #CSIDL_MYMUSIC, 0)
PathAddBackslash_(@sPath)
ProcedureReturn sPath
EndProcedure
Procedure.s TimeString(Time, Sep$ = ":")
If Time > 0
Protected sTimeString.s
Protected iHours.i, iMinutes.i, iSeconds.i
Time / 1000: iSeconds = Time % 60
Time / 60: iMinutes = Time % 60
Time / 60: iHours = Time % 60
sTimeString + RSet(Str(iHours), 2, "0") + Sep$ + RSet(Str(iMinutes), 2, "0") + Sep$ + RSet(Str(iSeconds), 2, "0")
ProcedureReturn sTimeString
Else
ProcedureReturn "00:00:00"
EndIf
EndProcedure
Structure _Tag
title.s
artist.s
album.s
year.i
comment.s
track.i
genre.s
bitrate.i
samplerate.i
channels.i
length.i
EndStructure
Global Tag._Tag
Procedure.i TagLib_ReadTag(File$)
Protected iResult.i
If Trim(File$) = "" Or FileSize(File$) < 1
iResult = 0
Else
Protected iFile.i
iFile = taglib_file_new(File$)
If iFile
Protected *Tag, *Proberties
*Tag = taglib_file_tag(iFile)
If *Tag
Tag\title = Trim(PeekS(taglib_tag_title(*Tag) ,-1, #PB_UTF8))
Tag\artist = Trim(PeekS(taglib_tag_artist(*Tag) ,-1, #PB_UTF8))
Tag\album = Trim(PeekS(taglib_tag_album(*Tag) ,-1, #PB_UTF8))
Tag\year = taglib_tag_year(*Tag)
Tag\comment = Trim(PeekS(taglib_tag_comment(*Tag), -1, #PB_UTF8))
Tag\track = taglib_tag_track(*Tag)
Tag\genre = Trim(PeekS(taglib_tag_genre(*Tag) ,-1, #PB_UTF8))
EndIf
*Proberties = taglib_file_audioproperties(iFile)
If *Proberties
Tag\bitrate = taglib_audioproperties_bitrate(*Proberties)
Tag\samplerate = taglib_audioproperties_samplerate(*Proberties)
Tag\channels = taglib_audioproperties_channels(*Proberties)
Tag\length = taglib_audioproperties_length(*Proberties)
EndIf
taglib_tag_free_strings()
taglib_file_free(iFile)
iResult = 1
EndIf
EndIf
ProcedureReturn iResult
EndProcedure
;Test
Define.s sFolder = PathRequester("Ordnerwahl", MyMusicDirectory())
If sFolder
If ExamineDirectory(0, sFolder, "*.*")
While NextDirectoryEntry(0)
If DirectoryEntryType(0) = #PB_DirectoryEntry_File
Debug "########" + DirectoryEntryName(0) + "########"
If TagLib_ReadTag(sFolder + DirectoryEntryName(0)) = 1
If Tag\title
Debug "Title: " + Tag\title
EndIf
If Tag\artist
Debug "Artist: " + Tag\artist
EndIf
If Tag\album
Debug "Album: " + Tag\album
EndIf
If Tag\year
Debug "Jahr: " + Str(Tag\year)
EndIf
If Tag\comment
Debug "Kommentar: " + Tag\comment
EndIf
If Tag\track
Debug "Track: " + Str(Tag\track)
EndIf
If Tag\genre
Debug "Genre: " + Tag\genre
EndIf
If Tag\bitrate
Debug "BitRate: " + Str(Tag\bitrate)
EndIf
If Tag\samplerate
Debug "SampleRate: " + Str(Tag\samplerate)
EndIf
If Tag\channels
Debug "Channels: " + Str(Tag\channels)
EndIf
If Tag\length
Debug "Length: " + TimeString(Tag\length * 1000)
EndIf
Else
Debug "Open Failed"
EndIf
EndIf
Wend
FinishDirectory(0)
EndIf
EndIf