Gambas France BETA


Pas de compte ? Incription

Tag Id3

Ce sujet est résolu.

1
AuteurMessages
xlab25#1 Posté le 17/4/2014 à 15:56:53
J'avais récupéré un code VB de Malibu23 pour Lire des Tag Id3 v2
Je souhaiterais le passer en Gambas, mais je coince un peu.
Si quelqu'un avait l'amabilité de m'aider, je pense que ce code pourrait servir à de nombreuses personnes.
Merci d'avance

' *********************************************
' Source Original Par Malibu23
' Id3 : Lecteur de Tag
' Sauvegarde de Tag
' Commencer 01/04/2003
' *********************************************

Public Type Tag1
Valide As Boolean
Titre As String
Artiste As String
Album As String
Annee As String
Commentaire As String
Piste As Integer
Genre As Integer
End Type

Public Type Tag2
Valide As Boolean
Titre As String
Artiste As String
Album As String
Annee As String
Commentaire As String
Piste As String
Genre As String
Compositeur As String
Original As String
Copyright As String
Url As String
Encode As String
End Type

Public Type Mpeg
Valide As Boolean
Deb_EnTete As Long
Mpeg As String
Layer As String
ProtectionBit As String
BitRate As Integer
Frequence As Long
Padded As String
PrivateBit As String
Mode As String
ModeExt As String
Copyright As String
Original As String
Emphasis As String
Taille As String
Duree As String
Vbr As String
End Type

Public Type Tag
Tag1 As Tag1
Tag2 As Tag2
Mpeg As Mpeg
End Type

Public Tab_BitRate(3 To 8) As Variant
Public Tab_Genre(-1 To 147) As String
Public Genre_Cpt As Integer

'Public Declare Sub Mp3_In Lib "in_mp3.dll" Alias "winampGetInModule2" ()
'Public Declare Sub Mp3_Out Lib "out_wave.dll" Alias "winampGetOutModule" ()

Public Id3_Tag As Tag

Public Function Recup_Tag(Fichier As String) As Tag

Dim I As Long
Dim Tampon As String
Dim Tmp1 As Byte
Dim Tmp2 As Byte
Dim Pointeur_Fichier As Integer
Dim Bin_Tmp As String

Dim Id3_Tmp As String * 3
Dim Id3_Info_Tag2(7) As Byte
Dim Id3_Taille As Long
Dim Id3_Cpt As Long

Dim Id_Nom As String * 4
Dim Id_Taille As Long
Dim Id_Taille_Tmp(4) As Byte
Dim Id_Flag As Integer

Dim Freq_Multiplicateur As Integer

Dim EnTete_Valide As Boolean
Dim EnTete_Deb As Byte
Dim EnTete_Info(2) As Byte
Dim EnTete_Mpeg As Integer
Dim EnTete_Layer As Integer

Dim Vrb_Deb As String * 4
Dim Vrb_Info(8) As Byte
Dim Duree_Vrb As Long

Dim TailleFichier As Long

Pointeur_Fichier = FreeFile

Recup_Tag.Tag1.Valide = False
Recup_Tag.Mpeg.Valide = False
Recup_Tag.Tag2.Valide = False

If Dir(Fichier) = "" Then Exit Function

' ************************
' Récuperation du Tag V2.1
' ************************

On Error GoTo Err_Tag2

Open Fichier For Binary As #Pointeur_Fichier
Get Pointeur_Fichier, 1, Id3_Tmp

If Id3_Tmp = "ID3" Then

Get Pointeur_Fichier, 3, Id3_Info_Tag2

If Id3_Info_Tag2(1) = 3 Then

For I = 4 To 7
Bin_Tmp = Bin_Tmp & DecToBin(Id3_Info_Tag2(I))
Next I

Id3_Taille = BinToDec(Bin_Tmp)

Id3_Cpt = 11
Do While Id3_Cpt < Id3_Taille
Get Pointeur_Fichier, Id3_Cpt, Id_Nom
Get Pointeur_Fichier, Id3_Cpt + 3, Id_Taille_Tmp

Id_Taille = 0
For I = 4 To 1 Step -1
Id_Taille = Id_Taille + Id_Taille_Tmp(I) * (256 ^ (4 - I))
Next I

Get Pointeur_Fichier, Id3_Cpt + 8, Id_Flag
Id3_Cpt = Id3_Cpt + 4 + 4 + 2

If Id_Nom <> String(4, Chr(0)) Then
Tampon = String(Id_Taille - 1, " ")
Get Pointeur_Fichier, Id3_Cpt + 1, Tampon

If Id_Nom = "COMM" Then
Tampon = Right(Tampon, InStr(StrReverse(Tampon), Chr(0)) - 1)
End If

Tampon = Trim(Replace(Tampon, Chr(0), ""))

Select Case Id_Nom
Case "TIT2"
Recup_Tag.Tag2.Titre = Tampon
Case "TPE1"
Recup_Tag.Tag2.Artiste = Tampon
Case "TALB"
Recup_Tag.Tag2.Album = Tampon
Case "TYER"
Recup_Tag.Tag2.Annee = Tampon
Case "COMM"
Recup_Tag.Tag2.Commentaire = Tampon
Case "TRCK"
Recup_Tag.Tag2.Piste = Tampon
Case "TCON"
Tampon = Right(Tampon, Len(Tampon) - InStr(Tampon, ")"))
Recup_Tag.Tag2.Genre = Tampon
Case "TCOM"
Recup_Tag.Tag2.Compositeur = Tampon
Case "TOPE"
Recup_Tag.Tag2.Original = Tampon
Case "TCOP"
Recup_Tag.Tag2.Copyright = Tampon
Case "WXXX"
Recup_Tag.Tag2.Url = Tampon
Case "TENC"
Recup_Tag.Tag2.Encode = Tampon
End Select
Id3_Cpt = Id3_Cpt + Id_Taille
End If
Loop
Else
GoTo Err_Tag2
End If
Else
GoTo Err_Tag2
End If

Recup_Tag.Tag2.Valide = True

Err_Tag2:

' ************************
' Récuperation de l'Entête
' ************************

On Error GoTo Err_EnTete

TailleFichier = LOF(Pointeur_Fichier)

If Id3_Cpt = 0 Then Id3_Cpt = 1

For I = Id3_Cpt To TailleFichier - 1
Get #Pointeur_Fichier, I, EnTete_Deb
If EnTete_Deb = &HFF Then
Get #Pointeur_Fichier, I + 1, EnTete_Info
If EnTete_Info(0) And &HE0 = &HE0 Then
EnTete_Valide = True
Exit For
End If
End If
Next

Recup_Tag.Mpeg.Deb_EnTete = I

If Not EnTete_Valide Then GoTo Err_EnTete

Get #Pointeur_Fichier, I + 36, Vrb_Deb
Get #Pointeur_Fichier, I + 40, Vrb_Info

Recup_Tag.Mpeg.Taille = Conversion_Taille(TailleFichier)

Select Case EnTete_Info(0) And 24
Case 0
Recup_Tag.Mpeg.Mpeg = "2.5"
EnTete_Mpeg = 2
Case 8
Recup_Tag.Mpeg.Mpeg = "Réservé"
EnTete_Mpeg = 0
Case 16
Recup_Tag.Mpeg.Mpeg = "2.0"
EnTete_Mpeg = 2
Freq_Multiplicateur = 2
Case 24
Recup_Tag.Mpeg.Mpeg = "1.0"
EnTete_Mpeg = 1
Freq_Multiplicateur = 4
End Select

Select Case EnTete_Info(0) And 6
Case 0
Recup_Tag.Mpeg.Layer = "Réservé"
EnTete_Layer = 0
Case 2
Recup_Tag.Mpeg.Layer = "III"
EnTete_Layer = 1
Case 4
Recup_Tag.Mpeg.Layer = "II"
EnTete_Layer = 2
Case 6
Recup_Tag.Mpeg.Layer = "I"
EnTete_Layer = 2
End Select

Select Case EnTete_Info(0) And 1
Case 0
Recup_Tag.Mpeg.ProtectionBit = "Oui"
Case 1
Recup_Tag.Mpeg.ProtectionBit = "Non"
End Select

If EnTete_Mpeg <> 0 And (Recup_Tag.Mpeg.Layer <> "Réservé" Or Recup_Tag.Mpeg.Layer <> "III") Then
Recup_Tag.Mpeg.BitRate = Tab_BitRate((EnTete_Info(0) And 6) + EnTete_Mpeg)((EnTete_Info(1) And 240) / 16)
Else
Recup_Tag.Mpeg.BitRate = 999
End If

Select Case EnTete_Info(1) And 12
Case 0
Recup_Tag.Mpeg.Frequence = 11025
Case 4
Recup_Tag.Mpeg.Frequence = 12000
Case 8
Recup_Tag.Mpeg.Frequence = 8000
End Select

Recup_Tag.Mpeg.Frequence = Recup_Tag.Mpeg.Frequence * Freq_Multiplicateur

Select Case EnTete_Info(1) And 2
Case 0
Recup_Tag.Mpeg.Padded = "Non"
Case 2
Recup_Tag.Mpeg.Padded = "Oui"
End Select

Select Case EnTete_Info(1) And 1
Case 0
Recup_Tag.Mpeg.PrivateBit = "Non"
Case 1
Recup_Tag.Mpeg.PrivateBit = "Oui"
End Select

Select Case EnTete_Info(2) And 192
Case 0
Recup_Tag.Mpeg.Mode = "Stereo"
Case 64
Recup_Tag.Mpeg.Mode = "Joint St"
Case 128
Recup_Tag.Mpeg.Mode = "Double Ch"
Case 192
Recup_Tag.Mpeg.Mode = "Mono"
End Select

Select Case EnTete_Layer
Case 0
Recup_Tag.Mpeg.ModeExt = "Erreur"
Case 1
Select Case EnTete_Info(2) And 48
Case 0
Recup_Tag.Mpeg.ModeExt = "Stereo : OFF - MS Stereo : OFF"
Case 16
Recup_Tag.Mpeg.ModeExt = "Stereo : ON - MS Stereo : OFF"
Case 32
Recup_Tag.Mpeg.ModeExt = "Stereo : OFF - MS Stereo : ON"
Case 48
Recup_Tag.Mpeg.ModeExt = "Stereo : ON - MS Stereo : ON"
End Select
Case 2
Recup_Tag.Mpeg.ModeExt = "Bandes " & 4 * (((EnTete_Info(2) And 48) / 16) + 1) & " à 31"
End Select

Select Case EnTete_Info(2) And 8
Case 0
Recup_Tag.Mpeg.Copyright = "Non"
Case 8
Recup_Tag.Mpeg.Copyright = "Oui"
End Select

Select Case EnTete_Info(2) And 4
Case 0
Recup_Tag.Mpeg.Original = "Non"
Case 4
Recup_Tag.Mpeg.Original = "Oui"
End Select

Select Case EnTete_Info(2) And 3
Case 0
Recup_Tag.Mpeg.Emphasis = "Sans"
Case 1
Recup_Tag.Mpeg.Emphasis = "50/15 ms"
Case 2
Recup_Tag.Mpeg.Emphasis = "Réservé"
Case 3
Recup_Tag.Mpeg.Emphasis = "CCITT j. 17"
End Select

Recup_Tag.Mpeg.Duree = Conversion_Duree(Int((TailleFichier - Recup_Tag.Mpeg.Deb_EnTete) * 8 / 1000) / Recup_Tag.Mpeg.BitRate)

Recup_Tag.Mpeg.Vbr = "Faux"

If Left(Vrb_Deb, 4) = "Xing" Then
Recup_Tag.Mpeg.Vbr = "Avec"

Duree_Vrb = 0
For I = 2 To 0 Step -1
Duree_Vrb = Duree_Vrb + Vrb_Info(7 - I) * (256 ^ I)
Next I

Duree_Vrb = Int(Duree_Vrb / 38) - 1

Recup_Tag.Mpeg.Duree = Conversion_Duree(Duree_Vrb)
Recup_Tag.Mpeg.BitRate = Int((TailleFichier - Recup_Tag.Mpeg.Deb_EnTete) * 8 / 1000 / Duree_Vrb)
End If

Recup_Tag.Mpeg.Valide = True

Err_EnTete:

' **********************
' Récuperation du Tag V1
' **********************

On Error GoTo Err_Tag1

Tampon = String(127, " ")
Recup_Tag.Tag1.Genre = -1

Get #Pointeur_Fichier, FileLen(Fichier) - 127, Tampon
Get #Pointeur_Fichier, FileLen(Fichier) - 1, Tmp1
Get #Pointeur_Fichier, FileLen(Fichier) - 0, Tmp2

Close #Pointeur_Fichier

If UCase(Left(Tampon, 3)) <> "TAG" Then Exit Function

Tampon = Recup_ID(Tampon, 3)
Tampon = Recup_ID(Tampon, 30, Recup_Tag.Tag1.Titre)
Tampon = Recup_ID(Tampon, 30, Recup_Tag.Tag1.Artiste)
Tampon = Recup_ID(Tampon, 30, Recup_Tag.Tag1.Album)
Tampon = Recup_ID(Tampon, 4, Recup_Tag.Tag1.Annee)
Tampon = Recup_ID(Tampon, 28, Recup_Tag.Tag1.Commentaire)
Recup_Tag.Tag1.Piste = Tmp1
If Tmp2 < 148 Then Recup_Tag.Tag1.Genre = Tmp2

Recup_Tag.Tag1.Valide = True

Err_Tag1:

End Function

Public Function Conversion_Taille(Taille As Long) As String
Dim I As Integer
Dim Tmp As String

On Error Resume Next

For I = 3 To 0 Step -1
If (Taille - 2 ^ (10 * I)) > 0 Then
Conversion_Taille = Format(Taille / 2 ^ (10 * I), "0.00")
Exit For
End If
Next I

Select Case I
Case 3
Tmp = "Go"
Case 2
Tmp = "Mo"
Case 1
Tmp = "Ko"
Case 0
Tmp = "O"
End Select

Conversion_Taille = Conversion_Taille & Tmp

End Function

Private Function Conversion_Duree(Duree As Long) As String

Dim Tmp As Long
Dim Heures As Long
Dim Minutes As Long
Dim Secondes As Long

On Error Resume Next

Tmp = Duree

Heures = Int(Tmp / 3600)
Tmp = Tmp - (Heures * 3600)

Minutes = Int(Tmp / 60)
Tmp = Tmp - (Minutes * 60)

Secondes = Tmp

Conversion_Duree = ""
If Heures > 0 Then Conversion_Duree = Format(Heures, "00") & ":"
If Minutes > 0 Then Conversion_Duree = Conversion_Duree & Format(Minutes, "00") & ":"
Conversion_Duree = Conversion_Duree & Format(Secondes, "00")

End Function

Function Ecris_Tag(Tag As Integer, Fichier As String, Id3_Tag As Tag)

Dim Taille_Fichier As Long
Dim Pointeur_Fichier As Integer
Dim Tampon As String
Dim Mp3 As String
Dim Deb_Msg As String
Dim Msg As String

Dim Bin_Tmp As String
Dim I, J As Integer
Dim Long_Entete As Long

Dim EnTete_Info(2) As Byte

Dim Id3_Tmp As String
Dim Id3_Taille As Long

Pointeur_Fichier = FreeFile

Open Fichier For Binary As #Pointeur_Fichier

TailleFichier = LOF(Pointeur_Fichier)

If Tag = 1 Then

Msg = "TAG"
Msg = Msg & Carac_Vide(Id3_Tag.Tag1.Titre, 30)
Msg = Msg & Carac_Vide(Id3_Tag.Tag1.Artiste, 30)
Msg = Msg & Carac_Vide(Id3_Tag.Tag1.Album, 30)
Msg = Msg & Carac_Vide(Id3_Tag.Tag1.Annee, 4)
Msg = Msg & Carac_Vide(Id3_Tag.Tag1.Commentaire, 28)

Msg = Msg & Chr(0)
Msg = Msg & Chr(Id3_Tag.Tag1.Piste)
Msg = Msg & Chr(Abs(Id3_Tag.Tag1.Genre))

Mp3 = String(TailleFichier - 128, " ")
Tampon = String(3, " ")

Get #Pointeur_Fichier, 1, Mp3

Get #Pointeur_Fichier, LOF(Pointeur_Fichier) - 127, Tampon

Close #Pointeur_Fichier

Pointeur_Fichier = FreeFile

Open Fichier For Output As #Pointeur_Fichier
Close #Pointeur_Fichier

Open Fichier For Binary As #Pointeur_Fichier

Put #Pointeur_Fichier, 1, Mp3

If Id3_Tag.Tag1.Valide = True Then
Put #Pointeur_Fichier, Len(Mp3), Msg
End If

ElseIf Tag = 2 Then

Mp3 = String(LOF(Pointeur_Fichier) - Id3_Tag.Mpeg.Deb_EnTete + 1, " ")

Get #Pointeur_Fichier, Id3_Tag.Mpeg.Deb_EnTete, Mp3
Close #Pointeur_Fichier

Pointeur_Fichier = FreeFile

Open Fichier For Output As #Pointeur_Fichier
Close #Pointeur_Fichier

Open Fichier For Binary As #Pointeur_Fichier

Msg = ""

For I = 1 To 12
Select Case I
Case 1
Msg = Msg & "TIT2"
Tampon = Id3_Tag.Tag2.Titre
Case 2
Msg = Msg & "TPE1"
Tampon = Id3_Tag.Tag2.Artiste
Case 3
Msg = Msg & "TALB"
Tampon = Id3_Tag.Tag2.Album
Case 4
Msg = Msg & "TYER"
Tampon = Id3_Tag.Tag2.Annee
Case 5
Msg = Msg & "COMM"
Tampon = "Jmp Encoding" & Chr(0) & Id3_Tag.Tag2.Commentaire
Case 6
Msg = Msg & "TRCK"
Tampon = Id3_Tag.Tag2.Piste
Case 7
Msg = Msg & "TCON"
Tampon = Id3_Tag.Tag2.Genre
Case 8
Msg = Msg & "TCOM"
Tampon = Id3_Tag.Tag2.Compositeur
Case 9
Msg = Msg & "TOPE"
Tampon = Id3_Tag.Tag2.Original
Case 10
Msg = Msg & "TCOP"
Tampon = Id3_Tag.Tag2.Copyright
Case 11
Msg = Msg & "WXXX"
Tampon = Chr(0) & Id3_Tag.Tag2.Url
Case 12
Msg = Msg & "TENC"
Tampon = Id3_Tag.Tag2.Encode
End Select

Tampon = Chr(0) & Tampon

Id3_Taille = Len(Tampon)

For J = 3 To 0 Step -1
If (Id3_Taille >= 256 ^ J) Then
Msg = Msg & Chr(Int(Id3_Taille / (256 ^ J)))
Id3_Taille = Id3_Taille - (Int(Id3_Taille / (256 ^ J)) * (256 ^ J))
Else
Msg = Msg & Chr(0)
End If
Next J

Msg = Msg & Chr(0) & Chr(0)
Msg = Msg & Tampon

Next I

Deb_Msg = "ID3"
Deb_Msg = Deb_Msg & Chr(3)
Deb_Msg = Deb_Msg & Chr(0) & Chr(0)

Id3_Tmp = DecToBin(Len(Msg) + 3 + 7, 28)

For I = 1 To 4
Deb_Msg = Deb_Msg & Chr(BinToDec(Mid(Id3_Tmp, I * 7 - 6, 7)))
Next I

If Id3_Tag.Tag2.Valide = True Then
Put #Pointeur_Fichier, 1, Deb_Msg & Msg
Put #Pointeur_Fichier, Len(Deb_Msg & Msg) + 1, Carac_Vide(Chr(0), 11)
Put #Pointeur_Fichier, Len(Deb_Msg & Msg) + 12, Mp3
Else
Put #Pointeur_Fichier, 1, Mp3
End If

End If

Close #Pointeur_Fichier

End Function

Function Carac_Vide(Str, Taille)

Dim Tmp
Tmp = ""

For I = 1 To Taille - Len(Str)
Tmp = Tmp & Chr(0)
Next

Carac_Vide = Str & Tmp

End Function

Private Sub Diver()

Dim filesys, filetxt

Const ForReading = 1, ForWriting = 2, ForAppending = 8

Set filesys = CreateObject("Scripting.FileSystemObject")

Set filetxt = filesys.OpenTextFile("1.mp3", ForAppending, TristateTrue)

Dim Titre, Artist, Album, Annee, Comment, Piste

Choix = MsgBox("Modifier ?", vbYesNo + vbQuestion, "Modifier")
If (Choix = 7) Then wscript.quit

Titre = InputBox("Choisir un Titre ?", "Titre", "Titre")
Artist = InputBox("Choisir un Artist ?", "Artist", "Artist")
Album = InputBox("Choisir un Album ?", "Album", "Album")
Annee = InputBox("Choisir un Annee ?", "Annee", 2000)
Comment = InputBox("Choisir un Comment ?", "Comment", "Comment")
Piste = InputBox("Choisir un Piste ?", "Piste", 1)

filetxt.Write (Msg)

filetxt.Close


End Sub

Function Recup_ID(ByVal Chaine As String, Nb As Integer, Optional Id) As String

Id = Left(Chaine, Nb)
Recup_ID = Right(Chaine, Len(Chaine) - Nb)

End Function

Public Function DecToBin(Dec, Optional Taille As Integer = 7) As String

Dim I As Integer
Dim Tmp_Dec As Integer

Tmp_Dec = Dec

If Tmp_Dec = 0 Then
DecToBin = ""
Exit Function
End If

For I = 1 To Taille
If Tmp_Dec > 0 Then
If (Tmp_Dec / 2) = Int(Tmp_Dec / 2) Then
DecToBin = "0" & DecToBin
Else
DecToBin = "1" & DecToBin
End If
Tmp_Dec = Int(Tmp_Dec / 2)
Else
DecToBin = "0" & DecToBin
End If
Next I

End Function

Public Function BinToDec(Bin As String) As Long

Dim Compteur As Integer

Bin = StrReverse(Bin)

For Compteur = 0 To Len(Bin) - 1
BinToDec = BinToDec + Mid(Bin, Compteur + 1, 1) * (2 ^ Compteur)
Next Compteur

End Function

Public Function Existe_Genre(Chaine As String) As Integer
Dim I As Integer

For I = 0 To 147
If Tab_Genre(I) = Chaine Then
Existe_Genre = I
Exit Function
End If
Next I

Existe_Genre = -1

End Function

Public Sub Initialise_Tab_BitRate()

Tab_BitRate(3) = Array(0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 999)
Tab_BitRate(4) = Array(0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160, 999)
Tab_BitRate(5) = Array(0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384, 999)
Tab_BitRate(6) = Array(0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160, 999)
Tab_BitRate(7) = Array(0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448, 999)
Tab_BitRate(8) = Array(0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256, 999)

End Sub

Public Sub Initialise_Genre()

Dim I As Integer

Tab_Genre(-1) = ""
Tab_Genre(0) = "Blues"
Tab_Genre(1) = "Classic Rock"
Tab_Genre(2) = "Country"
Tab_Genre(3) = "Dance"
Tab_Genre(4) = "Disco"
Tab_Genre(5) = "Funk"
Tab_Genre(6) = "Grunge"
Tab_Genre(7) = "Hip -Hop"
Tab_Genre(8) = "Jazz"
Tab_Genre(9) = "Metal"
Tab_Genre(10) = "New Age"
Tab_Genre(11) = "Oldies"
Tab_Genre(12) = "Other"
Tab_Genre(13) = "Pop"
Tab_Genre(14) = "R& B"
Tab_Genre(15) = "Rap"
Tab_Genre(16) = "Reggae"
Tab_Genre(17) = "Rock"
Tab_Genre(18) = "Techno"
Tab_Genre(19) = "Industrial"
Tab_Genre(20) = "Alternative"
Tab_Genre(21) = "Ska"
Tab_Genre(22) = "Death Metal"
Tab_Genre(23) = "Pranks"
Tab_Genre(24) = "Soundtrack"
Tab_Genre(25) = "Euro -Techno"
Tab_Genre(26) = "Ambient"
Tab_Genre(27) = "Trip Hop"
Tab_Genre(28) = "Vocal"
Tab_Genre(29) = "Jazz Funk"
Tab_Genre(30) = "Fusion"
Tab_Genre(31) = "Trance"
Tab_Genre(32) = "Classical"
Tab_Genre(33) = "Instrumental"
Tab_Genre(34) = "Acid"
Tab_Genre(35) = "House"
Tab_Genre(36) = "Game"
Tab_Genre(37) = "Sound Clip"
Tab_Genre(38) = "Gospel"
Tab_Genre(39) = "Noise"
Tab_Genre(40) = "Alt.Rock"
Tab_Genre(41) = "Bass"
Tab_Genre(42) = "Soul"
Tab_Genre(43) = "Punk"
Tab_Genre(44) = "Space"
Tab_Genre(45) = "Meditative"
Tab_Genre(46) = "Instrumental Pop"
Tab_Genre(47) = "Instrumental Rock"
Tab_Genre(48) = "Ethnic"
Tab_Genre(49) = "Gothic"
Tab_Genre(50) = "Darkwave"
Tab_Genre(51) = "Techno -Industrial"
Tab_Genre(52) = "Electronic"
Tab_Genre(53) = "Pop -Folk"
Tab_Genre(54) = "Eurodance"
Tab_Genre(55) = "Dream"
Tab_Genre(56) = "Southern Rock"
Tab_Genre(57) = "Comedy"
Tab_Genre(58) = "Cult"
Tab_Genre(59) = "Gangsta Rap"
Tab_Genre(60) = "Top 40"
Tab_Genre(61) = "Christian Rap"
Tab_Genre(62) = "Pop/Punk"
Tab_Genre(63) = "Jungle"
Tab_Genre(64) = "Native American"
Tab_Genre(65) = "Cabaret"
Tab_Genre(66) = "New Wave"
Tab_Genre(67) = "Phychedelic"
Tab_Genre(68) = "Rave"
Tab_Genre(69) = "Showtunes"
Tab_Genre(70) = "Trailer"
Tab_Genre(71) = "Lo -Fi"
Tab_Genre(72) = "Tribal"
Tab_Genre(73) = "Acid Punk"
Tab_Genre(74) = "Acid Jazz"
Tab_Genre(75) = "Polka"
Tab_Genre(76) = "Retro"
Tab_Genre(77) = "Musical"
Tab_Genre(78) = "Rock & Roll"
Tab_Genre(79) = "Hard Rock"
Tab_Genre(80) = "Folk"
Tab_Genre(81) = "Folk/Rock"
Tab_Genre(82) = "National Folk"
Tab_Genre(83) = "Swing"
Tab_Genre(84) = "Fast -Fusion"
Tab_Genre(85) = "Bebob"
Tab_Genre(86) = "Latin"
Tab_Genre(87) = "Revival"
Tab_Genre(88) = "Celtic"
Tab_Genre(89) = "Blue Grass"
Tab_Genre(90) = "Avantegarde"
Tab_Genre(91) = "Gothic Rock"
Tab_Genre(92) = "Progressive Rock"
Tab_Genre(93) = "Psychedelic Rock"
Tab_Genre(94) = "Symphonic Rock"
Tab_Genre(95) = "Slow Rock"
Tab_Genre(96) = "Big Band"
Tab_Genre(97) = "Chorus"
Tab_Genre(98) = "Easy Listening"
Tab_Genre(99) = "Acoustic"
Tab_Genre(100) = "Humour"
Tab_Genre(101) = "Speech"
Tab_Genre(102) = "Chanson"
Tab_Genre(103) = "Opera"
Tab_Genre(104) = "Chamber Music"
Tab_Genre(105) = "Sonata"
Tab_Genre(106) = "Symphony"
Tab_Genre(107) = "Booty Bass"
Tab_Genre(108) = "Primus"
Tab_Genre(109) = "Porn Groove"
Tab_Genre(110) = "Satire"
Tab_Genre(111) = "Slow Jam"
Tab_Genre(112) = "Club"
Tab_Genre(113) = "Tango"
Tab_Genre(114) = "Samba"
Tab_Genre(115) = "Folklore"
Tab_Genre(116) = "Ballad"
Tab_Genre(117) = "power Ballad"
Tab_Genre(118) = "Rhythmic Soul"
Tab_Genre(119) = "Freestyle"
Tab_Genre(120) = "Duet"
Tab_Genre(121) = "Punk Rock"
Tab_Genre(122) = "Drum Solo"
Tab_Genre(123) = "A Capella"
Tab_Genre(124) = "Euro -House"
Tab_Genre(125) = "Dance Hall"
Tab_Genre(126) = "Goa"
Tab_Genre(127) = "Drum & Bass"
Tab_Genre(128) = "Club -House"
Tab_Genre(129) = "Hardcore"
Tab_Genre(130) = "Terror"
Tab_Genre(131) = "indie"
Tab_Genre(132) = "Brit Pop"
Tab_Genre(133) = "Negerpunk"
Tab_Genre(134) = "Polsk Punk"
Tab_Genre(135) = "Beat"
Tab_Genre(136) = "Christian Gangsta Rap"
Tab_Genre(137) = "Heavy Metal"
Tab_Genre(138) = "Black Metal"
Tab_Genre(139) = "Crossover"
Tab_Genre(140) = "Comteporary Christian"
Tab_Genre(141) = "Christian Rock"
Tab_Genre(142) = "Merengue"
Tab_Genre(143) = "Salsa"
Tab_Genre(144) = "Trash Metal"
Tab_Genre(145) = "Anime"
Tab_Genre(146) = "JPop"
Tab_Genre(147) = "Synth Pop"

Genre_Cpt = 147

For I = 0 To Genre_Cpt
Id3.Genre(1).AddItem Tab_Genre(I)
Id3.Genre(2).AddItem Tab_Genre(I)
Next I

End Sub
vuott#2 Posté le 17/4/2014 à 20:42:17
Ne cedere ineluctabili possimusHello,

where have you blocked? Which line gives you problem?
« Vita non suavis esse potest, nec Mors amara. »
xlab25#3 Posté le 18/4/2014 à 15:32:16
pb avec la fonction Public Function Recup_Tag(Fichier As String) As Tag
xlab25#4 Posté le 18/4/2014 à 15:32:56
et strreverse
xlab25#5 Posté le 18/4/2014 à 15:48:14
voici mon code gambas pour l'instant, il ne marche qu'avec du ID tag v2 et bug quelques fois :
' Gambas module file

Public Struct Tag2
Valide As Boolean
Titre As String
Artiste As String
Album As String
Annee As String
Commentaire As String
Piste As String
Genre As String
Compositeur As String
Original As String
Copyright As String
Url As String
Encode As String
End Struct

Public Id3_Tag As New Tag2

Public Sub Recup_Tag(fichier As String)

Dim i As Byte
Dim hfile As File
Dim Id3_id As String
Dim Id3_ver As New String[2]
Dim Id3_flag As String
Dim Id3_size_temp As New String[4]
Dim Id3_size_bin As String
Dim Id3_size As Long
Dim Id3_cpt As Long
Dim Id_nom As String
Dim Id_size_temp As New String[4]
Dim Id_size_bin As String
Dim Id_size As Long
Dim Id_flag As String
Dim Id_tampon As String


If Exist(fichier) = False Then Return

' Lecture de l'entete
hFile = Open Fichier For Input

'file identifier "ID3"
Id3_id = Read #hfile, 3
If Id3_id = "ID3" Then Id3_Tag.Valide = True

'version $03 00
For i = 0 To 1
Id3_ver = Read #hfile, 1
Next

'flags %abc00000
Id3_flag = Read #hfile, 1

'size 4 * %0xxxxxxx
For i = 0 To 3
Id3_size_temp = Read #hfile, 1
Next
Id3_size_bin = Bin$(Asc(Id3_size_temp[0]), 7) & Bin$(Asc(Id3_size_temp[1]), 7) & Bin$(Asc(Id3_size_temp[2]), 7) & Bin$(Asc(Id3_size_temp[3]), 7)
Id3_size = 0
For i = 1 To 28
Id3_size = Id3_size + 2 ^ (28 - i) * Mid$(Id3_size_bin, i, 1)
Next

'lecture des frames
Id3_Cpt = 0
Do
'frameID $xx xx xx xx
Id_nom = Read #hfile, 4

'Size $xx xx xx xx
For i = 0 To 3
Id_size_temp = Read #hfile, 1
Next
Id_size = Asc(Id_size_temp[0]) * 256 ^ 3 + Asc(Id_size_temp[1]) * 256 ^ 2 + Asc(Id_size_temp[2]) * 256 + Asc(Id_size_temp[3])

'Flags $xx xx
Id_flag = Read #hfile, 2
Id3_cpt = Id3_cpt + 4 + 4 + 2

'Frame
Id_tampon = Read #hfile, Id_size
If Id_nom = "COMM" Then
Id_tampon = Right$(Id_tampon, 1)
Debug "Commentaire"
Debug Id_tampon
Else
Id_tampon = Trim(Replace(Id_tampon, Chr(0), ""))
End If

Id3_cpt = Id3_cpt + Id_size

Select Case Id_nom
Case "TIT2"
Id3_Tag.Titre = Id_tampon
Case "TPE1"
Id3_Tag.Artiste = Id_tampon
Case "TALB"
Id3_Tag.Album = Id_tampon
End Select


Loop While Id3_Cpt <> Id3_size

Close #hfile
End Sub
vuott#6 Posté le 18/4/2014 à 19:19:26
Ne cedere ineluctabili possimus
et strreverse
strreverse is a VB function to reverse the character order of a specified string.
In Gambas you could use an autonomous function, based on this abstract code, which uses the method. Reverse () of array:
Public Sub Main()

Dim s As String = "abcdefgh"
Dim bb As Byte[]

bb = Byte[].FromString(s)
bb.Reverse()
s = bb.ToString(0, bb.Count)

Print s

End

« Vita non suavis esse potest, nec Mors amara. »
vuott#7 Posté le 18/4/2014 à 20:44:32
Ne cedere ineluctabili possimus
voici mon code gambas pour l'instan...

Is it satisfactory now ?

Public Struct Tag2
Valide As Boolean
Titre As String
Artiste As String
Album As String
Annee As String
Commentaire As String
Piste As String
Genre As String
Compositeur As String
Original As String
Copyright As String
Url As String
Encode As String
End Struct

Public Id3_Tag As New Tag2

Public Sub Recup_Tag(fichier As String)

Dim i As Byte
Dim hfile As File
Dim Id3_id As String
Dim Id3_ver As New String[2]
Dim Id3_flag As String
Dim Id3_size_temp As New String[4]
Dim Id3_size_bin As String
Dim Id3_size As Long
Dim Id3_cpt As Long
Dim Id_nom As String
Dim Id_size_temp As New String[4]
Dim Id_size_bin As String
Dim Id_size As Long
Dim Id_flag As String
Dim Id_tampon As String

If Exist(fichier) = False Then Return

' Lecture de l'entete
hFile = Open Fichier For Read

'file identifier "ID3"
Id3_id = Read #hfile, 3
Print Id3_id
If Id3_id = "ID3" Then Id3_Tag.Valide = True

'version $03 00
For i = 0 To 1
Read #hfile, Id3_ver, 1
Next
Print "Version = "; Asc(Id3_ver[0])

'flags %abc00000
Id3_flag = Read #hfile, 1

'size 4 * %0xxxxxxx
For i = 0 To 3
Id3_size_temp = Read #hfile, 1
Next
Id3_size_bin = Bin$(Asc(Id3_size_temp[0]), 7) & Bin$(Asc(Id3_size_temp[1]), 7) & Bin$(Asc(Id3_size_temp[2]), 7) & Bin$(Asc(Id3_size_temp[3]), 7)
Id3_size = 0
For i = 1 To 28
Id3_size = Id3_size + 2 ^ (28 - i) * Mid$(Id3_size_bin, i, 1)
Next

'lecture des frames
Id3_Cpt = 0

While Id3_Cpt <= Id3_size
'frameID $xx xx xx xx
Id_nom = Read #hfile, 4

'Size $xx xx xx xx
For i = 0 To 3
Id_size_temp = Read #hfile, 1
Next
Id_size = Asc(Id_size_temp[0]) * 256 ^ 3 + Asc(Id_size_temp[1]) * 256 ^ 2 + Asc(Id_size_temp[2]) * 256 + Asc(Id_size_temp[3])

'Flags $xx xx
Id_flag = Read #hfile, 2
Id3_cpt = Id3_cpt + 4 + 4 + 2

'Frame
Id_tampon = Read #hfile, Id_size
If Id_nom = "COMM" Then
Id_tampon = Right$(Id_tampon, 1)
Debug "Commentaire"
Debug Id_tampon
Else
Id_tampon = Trim(Replace(Id_tampon, Chr(0), ""))
End If

Id3_cpt = Id3_cpt + Id_size

Select Case Id_nom
Case "TIT2"
Id3_Tag.Titre = Id_tampon
Print Id3_Tag.Titre
Case "TPE1"
Id3_Tag.Artiste = Id_tampon
Case "TALB"
Id3_Tag.Album = Id_tampon
Print Id3_Tag.Album
End Select
Wend
Close #hfile

End
« Vita non suavis esse potest, nec Mors amara. »
xlab25#8 Posté le 22/4/2014 à 17:53:07
Comme ça, c'est ok

Public Struct Tag2
Valide As Boolean
Titre As String
Artiste As String
Album As String
Annee As String
Commentaire As String
Piste As String
Genre As String
Compositeur As String
Original As String
Copyright As String
Url As String
Encode As String
End Struct

Public Id3_Tag As New Tag2

Public Sub Recup_Tag(fichier As String)

Dim i As Byte
Dim hfile As File
Dim Id3_id As String
Dim Id3_ver As New String[2]
Dim Id3_flag As String
Dim Id3_size_temp As New String[4]
Dim Id3_size_bin As String
Dim Id3_size As Long
Dim Id3_cpt As Long
Dim Id_nom As String
Dim Id_size_temp As New String[4]
Dim Id_size_bin As String
Dim Id_size As Long
Dim Id_flag As String
Dim Id_tampon As String


If Exist(fichier) = False Then Return

' Lecture de l'entete
hFile = Open Fichier For Input

'file identifier "ID3"
Id3_id = Read #hfile, 3
If Id3_id = "ID3" Then
Id3_Tag.Valide = True

'version $03 00
For i = 0 To 1
Id3_ver = Read #hfile, 1
Next

'flags %abc00000
Id3_flag = Read #hfile, 1

'size 4 * %0xxxxxxx
For i = 0 To 3
Id3_size_temp = Read #hfile, 1
Next
Id3_size_bin = Bin$(Asc(Id3_size_temp[0]), 7) & Bin$(Asc(Id3_size_temp[1]), 7) & Bin$(Asc(Id3_size_temp[2]), 7) & Bin$(Asc(Id3_size_temp[3]), 7)
Id3_size = 0
For i = 1 To 28
Id3_size = Id3_size + 2 ^ (28 - i) * Mid$(Id3_size_bin, i, 1)
Next

'lecture des frames
Id3_Cpt = 11
While Id3_Cpt < Id3_size
'frameID $xx xx xx xx
Id_nom = Read #hfile, 4

'Size $xx xx xx xx
For i = 0 To 3
Id_size_temp = Read #hfile, 1
Next
Id_size = Asc(Id_size_temp[0]) * 256 ^ 3 + Asc(Id_size_temp[1]) * 256 ^ 2 + Asc(Id_size_temp[2]) * 256 + Asc(Id_size_temp[3])

'Flags $xx xx
Id_flag = Read #hfile, 2
Id3_cpt = Id3_cpt + 4 + 4 + 2

If Id_nom <> String(4, Chr(0))
'Frame
Id_tampon = Read #hfile, Id_size
If Id_nom = "COMM" Then
Id_tampon = Right$(Id_tampon, 1)
Id3_Tag.Commentaire = Id_tampon
End If

Id_tampon = Trim(Replace(Id_tampon, Chr(0), ""))

Select Case Id_nom
Case "TIT2"
Id3_Tag.Titre = Id_tampon
Case "TPE1"
Id3_Tag.Artiste = Id_tampon
Case "TALB"
Id3_Tag.Album = Id_tampon
End Select
Id3_cpt = Id3_cpt + Id_size
End If
Wend
Close #hfile
End If
End Sub
xlab25#9 Posté le 22/4/2014 à 17:55:13
bug avec les caractères spéciaux français

Pango-WARNING **: pango_layout_set_markup_with_accel: Error on line 1 char 59: Invalid UTF-8 encoded text in name - not valid '?L'enl\xe8vement"
au lieu de L'enlèvement
xlab25#10 Posté le 25/4/2014 à 12:32:24
Je pense que la solution est l'utilisation de gb.media et de mediataglist, mais je ne comprends pas comment fonctionne cette fonction et mediaplayer. SI quelqu'un pouvais me donner un exemple pour lire un mp3 et les tag associés, je lui en serais très reconnaissant
merci
Reivillo#11 Posté le 25/4/2014 à 17:36:49
C' est ici, et nul part ailleurs. « Et pis c'est tout ! »Bonsoir xlab25.

Installe < médiainfo >,
cré un nouveau Projet, avec un Control < TextAréa >
Peut-être se Méfier,
des Espace dans le Chemin, et nom de Fichier.
Puis Test ce Code.

Reivillo.
1
2
3
4
5
PUBLIC SUB Form_Open()

SHELL "mediainfo " & User.home & "/01.mp3" TO TextArea1.text

END

Version LinuxMint 13 (1.6.1-1+maya-mate(32-bit)) LTS Noyau 3.14.33-031433-generic (27-02-2015)
LinuxMint 13 Mate Fr ICI, LinuxMint 17 Mate Fr .
Programmation Gambas3 Installé depuis la Console Terminal avec successivement: Les 3 Lignes sudo en Gras ci-dessous...
sudo add-apt-repository ppa:gambas-team/gambas3
sudo apt-get update
sudo apt-get install gambas3 -y
Gambas3.8.4-57.47 (Mise à Jour Auto via mintupdate le 28-01-2016)
Pour la Doc, c'est vers là: Documentation Gambas3 FR
vuott#12 Posté le 25/4/2014 à 19:50:13
Ne cedere ineluctabili possimus
Je pense que la solution est l'utilisation ......

There are various solutions to extract the tags from an MP3 file ... even the one with the only functions of Gambas, if you know the structure of the '"header" of an MP3 file.
Anyway you can find something in the pages of the forum WIKI gambas-it.org:

http://www.gambas-it.org/wiki/index.php?title=Guide_della_comunit%C3%A0#Gestione_dei_dati_audio_e_dei_file_audio

(Obviously you'll have to translate from italian language)
« Vita non suavis esse potest, nec Mors amara. »
xlab25#13 Posté le 29/4/2014 à 15:28:42
Bonjour

merci pour vos réponses,

- J'ai essayé avec mediainfo mais j'ai un message d'erreur (M:4267): Gtk-CRITICAL **: IA__gtk_text_buffer_set_text: assertion 'text != NULL' failed

- Avec le code "Estrarre informazioni e TAG da un file OggVorbis con le sole funzioni di Gambas", j'ai toujours les pb d'accents français qui n'apparaissent pas

- En ce qui concerne mediaplayer, j'ai trouvé ou je commettais une erreur, j'avais oublié de mettre file:// devant le chemin de mes fichiers mp3

- Pour mediataglist, je parviens à obtenir les infos grâce à "Public Sub MediaPlayer_Tag(TagList As MediaTagList)" avec les bons accent mais je suis obligé de lancer la lecture du mp3 pour les obtenir. Hors j'aimerais les avoir avant.
xlab25#14 Posté le 29/4/2014 à 16:11:10
J'ai enfin trouvé, il suffisait de mettre dans mon code :

Select Case Id_nom
Case "TIT2"
Id3_Tag.Titre = Conv(Id_tampon, "ISO-8859-1", "UTF-8")
Case "TPE1"
Id3_Tag.Artiste = Conv(Id_tampon, "ISO-8859-1", "UTF-8")
Case "TALB"
Id3_Tag.Album = Conv(Id_tampon, "ISO-8859-1", "UTF-8")
End Select
merci
Reivillo#15 Posté le 7/5/2014 à 13:01:11
C' est ici, et nul part ailleurs. « Et pis c'est tout ! »Re xlab25.

Je viens de voir ton message de Succès.(Félicitations)
Merci, au nom de Toutes & Tous, pour le Retour.(Avec ta Solution)
Il serait bien que tu mettes ton Sujet en Résolu.

Amicalement.
Reivillo.
Version LinuxMint 13 (1.6.1-1+maya-mate(32-bit)) LTS Noyau 3.14.33-031433-generic (27-02-2015)
LinuxMint 13 Mate Fr ICI, LinuxMint 17 Mate Fr .
Programmation Gambas3 Installé depuis la Console Terminal avec successivement: Les 3 Lignes sudo en Gras ci-dessous...
sudo add-apt-repository ppa:gambas-team/gambas3
sudo apt-get update
sudo apt-get install gambas3 -y
Gambas3.8.4-57.47 (Mise à Jour Auto via mintupdate le 28-01-2016)
Pour la Doc, c'est vers là: Documentation Gambas3 FR
1