je conseille de les utiliser toutes les 2...
(sauvegardez le code avant de lancer la première fois) , sinon l'image risque de s'écrire dans le dossier compiler
cette procedure supprime automatiquement tout tag ID3V2 , et en refait un a neuf !
par la procedure d'ecriture de tag ID3V2 , si un tel tag existe dans le fichier..
Code : Tout sélectionner
; By Dobro
; créé en pure basic 4.51
;***********************************************
;Titre :*lecture_ecriture_tag_mp3
;Auteur : Dobro
;Date :19/08/2015
;Heure :20:13:41
;Version Purebasic : PureBasic 5.31 (Windows - x86)
;Version de l'editeur :EPB V2.62
; Libairies necessaire : Aucune
;***********************************************
Declare.S read_tag_mp3(file$)
Declare.S read_tag_mp3v2(file$)
Declare.l to_little_indian(valeur.l)
; ***** write_tag_mp3(file$,title$,interpret$,album$,year$,comment$,piste_number$,style_musical$) ****
Declare write_tag_mp3(file$,titre$,interprete$,album$,annee$,commentaire$,numero_piste$,genre_musical$)
; ********************************************************************************************************
; **** write_tag_mp3v2(file$,album$,composer$,interpret$,title$,copyright$,year$,piste_number$,lien$,comment$, style_music$, music_long$,path_image$)
Declare write_tag_mp3v2(file$,album$,composeur$,interprete$,titre$,copyright$,annee$,numero_piste$,lien$,commentaire$, genre$, longueur$,image$)
Declare delete_tagV1(file$)
Declare delete_tagV2(file$)
Declare to_little_indian_w(valeur.l)
Enumeration
; enumeration Tag MP3 ID3Vx
#file
#image_file
#file2
#file_image
EndEnumeration
file$=OpenFileRequester("ouvrir un mp3","C:\","*.mp3",1)
; **************** exemple d'ecriture ID3V1 ****************************²
;
; titre$="D'ont play that song"
; interprete$="Adriano Celentano"
; album$="Adriano Celentano"
; annee$="1975"²
; commentaire$="belle reprise"
; numero_piste$="1"
; genre_musical$="1"
; ;
; write_tag_mp3(file$,titre$,interprete$,album$,annee$,commentaire$,numero_piste$,genre_musical$)
; ********************************************************************
;;²
; ceci ouvre le Tag ID3 v1 en lecture
retour$=read_tag_mp3(file$)
Debug "************* ID3 V1 *********************"
Debug "titre= "+StringField(retour$,1,",")
Debug "interprete= "+StringField(retour$,2,",")
Debug "album= "+StringField(retour$,3,",")
Debug "année= "+StringField(retour$,4,",")
Debug "commentaires= "+StringField(retour$,5,",")
Debug "numero piste= "+StringField(retour$,6,",")
Debug "genre musical= "+StringField(retour$,7,",")
Debug ""
Debug ""
Debug ""
Debug ""
;******************************exemple ecriture Tag ID3 v2 *************************************
; ; ; ;
; album$="le bel Album"
; composeur$="le compositeur"
; interprete$="Mr l'interprete"
; titre$="Le titre qui tue sa race"
; copyright$="@ Dobro"
; annee$="2010"
; numero_piste$="8"
; lien$="Http://michel.dobro.free.fr/"
; commentaire$="un petit exemple fait en pure Basic"
; genre$="Country Music"
; longueur$="88888"
; image$="C:\Dobro\Mes_Photos\Sv101108.jpg" ; mettre ici le chemin vers une images valide !!!
; write_tag_mp3v2(file$,album$,composeur$,interprete$,titre$,copyright$,annee$,numero_piste$,lien$,commentaire$, genre$, longueur$,image$)
; ;
;**************************************************************************************²²²²²
; ceci ouvre le Tag ID3 v2 en lecture
retour$=read_tag_mp3v2(file$)
Debug "************* ID3 V2 *********************"
Debug "album= "+StringField(retour$,1,",")
Debug "compositeur= "+StringField(retour$,2,",")
Debug "interprete= "+StringField(retour$,3,",")
Debug "titre= "+StringField(retour$,4,",")
Debug "Copyright= "+StringField(retour$,5,",")
Debug "année= "+StringField(retour$,6,",")
Debug "numero piste= "+StringField(retour$,7,",")
Debug "Lien= "+StringField(retour$,8,",")
Debug "commentaires= "+StringField(retour$,9,",")
Debug "genre musical= "+StringField(retour$,10,",")
Debug "Longueur= "+StringField(retour$,11,",")
End
; ********************** Zone des Procedures ******************************************
Procedure.S read_tag_mp3(file$)
; By Dobro
; purebasic 4.51
; lecture des tag MP3 id3V1
If OpenFile(#file,file$)
FileSeek(#file, Lof(#file)-128) ; ruse de guerre , on saute a la fin du fichier , puis on recul de 128 octets !
For i=1 To 3
tag$= tag$+Chr(ReadCharacter(#file) )
Next i
; determine si le tag Mp3 existe
If tag$="TAG"
tag_present=#true
Debug "Le tag est présent"
Else
tag_present=#False
Debug "Le tag est absent"
Goto suite:
EndIf
; ********** recuperation du titre **************************** ; Grab Title
For i=1 To 30
titre$= titre$+Chr(ReadCharacter(#file) )
Next i
;*************************************************************
;**************** recperation de l'interprete ***************** ; Grab name of Singer
For i=1 To 30
interprete$= interprete$+Chr(ReadCharacter(#file) )
Next i
; ***********************************************************
; ****************** recuperation de l'album *********************** ; Grab name of Album
For i=1 To 30
album$= album$+Chr(ReadCharacter(#file) )
Next i
; *****************************************************************
;***************** recuperation de l'année ************************** ; Grab Year
For i=1 To 4
annee$= annee$+Chr(ReadCharacter(#file) )
Next i
; *****************************************************************
; ******************** recuperation des commentaires ***************** ; Grab Comment
For i=1 To 28
commentaire$= commentaire$+Chr(ReadCharacter(#file) )
Next i
; ********************************************************************
; ******************** recuperation octet nul *****************
For i=1 To 1
nul$= nul$+Chr(ReadCharacter(#file) )
Next i
; ********************************************************************
; ******************** recuperation numero de piste***************** ;Grab piste number
For i=1 To 1
numero_piste$= Str(ReadCharacter(#file) )
Next i
; ********************************************************************
; ************************ recuperation du genre musicale ****************** ; Grab Style Music (pop,rock,techno...etc)
For i=1 To 1
genre_musical$= Str(ReadCharacter(#file) )
Next i
; ***************************************************************************
suite:
CloseFile(#file)
Restore genre:
For i=0 To Val(genre_musical$)
Read.S genre.S
if genre.S="-1"
genre.S="UnNow"
break
endif
Next
Else
ProcedureReturn "Erreur"
EndIf
retour$=titre$+","+interprete$+","+album$+","+annee$+","+commentaire$+","+Str(Val( numero_piste$))+","+genre.S
ProcedureReturn retour$
DataSection
genre:
Data.S "Blues", "Classic Rock", "Country", "Dance", "Disco", "Funk", "Grunge", "Hip-Hop", "Jazz", "Metal"
Data.S "New Age", "Oldies", "Other", "Pop", "R&B", "Rap", "Reggae", "Rock", "Techno", "Industrial"
Data.S "Alternative", "Ska", "Death Metal", "Pranks", "Soundtrack", "Euro-Techno", "Ambient", "Trip-Hop", "Vocal", "Jazz+Funk"
Data.S "Fusion", "Trance", "Classical", "Instrumental", "Acid", "House", "Game", "Sound Clip", "Gospel", "Noise"
Data.S "AlternRock", "Bass", "Soul", "Punk", "Space", "Meditative", "Instrumental Pop", "Instrumental Rock", "Ethnic", "Gothic"
Data.S "Darkwave", "Techno-Industrial", "Electronic", "Pop-Folk", "Eurodance", "Dream", "Southern Rock", "Comedy", "Cult", "Gangsta"
Data.S "Top 40", "Christian Rap", "Pop/Funk", "Jungle", "Native American", "Cabaret", "New Wave", "Psychadelic", "Rave", "Showtunes"
Data.S "Trailer", "Lo-Fi", "Tribal", "Acid Punk", "Acid Jazz", "Polka", "Retro", "Musical", "Rock & Roll", "Hard Rock"
Data.S "Folk", "Folk-Rock", "National Folk", "Swing", "Fast Fusion", "Bebob", "Latin", "Revival", "Celtic", "Bluegrass"
Data.S "Avantgarde", "Gothic Rock", "Progressive Rock", "Psychedelic Rock", "Symphonic Rock", "Slow Rock", "Big Band", "Chorus", "Easy Listening", "Acoustic"
Data.S "Humour", "Speech", "Chanson", "Opera", "Chamber Music", "Sonata", "Symphony", "Booty Bass", "Primus", "Porn Groove"
Data.S "Satire", "Slow Jam", "Club", "Tango", "Samba", "Folklore", "Ballad", "Power Ballad", "Rhythmic Soul", "Freestyle"
Data.S "Duet", "Punk Rock", "Drum Solo", "Acapella", "Euro-House", "Dance Hall", "Goa", "Drum & Bass", "Club-House", "Hardcore", "Terror", "indie", "Brit Pop", "Negerpunk"
Data.S "Polsk Punk", "Beat", "Christian Gangsta Rap", "Heavy Metal", "Black Metal", "Crossover", "Comteporary Christian"
Data.S "Christian Rock", "Merengue", "Salsa", "Trash Metal", "Anime", "JPop", "Synth Pop" ,"-1"
EndDataSection
EndProcedure
Procedure.S read_tag_mp3v2(file$) ; Read Mp3Tag
; By Dobro
; purebasic 4.51
; lecture des tag MP3 id3V2
If OpenFile(#file,file$)
For i=0 To 2
tag$= tag$+Chr(ReadCharacter(#file) )
Next i
; determine si le tag Mp3 V2 existe
If tag$="ID3"
tag_present=#true
Debug "Le tag V2 est présent"
Else
tag_present=#False
Debug "Le tag V2 est absent"
CloseFile(#file)
ProcedureReturn ""
EndIf
version$= Str(ReadByte(#file) ) ;$03 majeur version
ReadByte(#file) ; mineure version
flag$= Str(ReadByte(#file) )
; x1=ReadByte(#file)
; x2=ReadByte(#file)
; x3=ReadByte(#file)
; x4=ReadByte(#file)
; long_id3=((x3 * Pow(128,3)) + (x2 *Pow(128,2)) + (x1 * Pow(128,1)) + (x0 * Pow(128,0)))-10
long_id3=ReadLong(#file)
long_id3= to_little_indian(long_id3)-10
Repeat
tag$=""
; Tag Frame
FileSeek(#file,Loc(#file)-3) ; ceci sert a ne pas louper de frames !! ne pas toucher !
For i=1 To 4
tag$=tag$+Chr(ReadCharacter(#file))
Next i
Select tag$
Case "TALB" ; Album ; Validé
long_frame=ReadLong(#file)
long_frame= to_little_indian(long_frame)-3
nul=ReadByte(#file)
fin_entete_frame=ReadLong(#file)
For i=1 To long_frame
album$=album$+Chr(ReadCharacter(#file))
Next i
Case "TCOM" ; compositeur
long_frame=ReadLong(#file)
long_frame= to_little_indian(long_frame)-3
nul=ReadByte(#file)
fin_entete_frame=ReadLong(#file)
For i=1 To long_frame
composeur$=composeur$+Chr(ReadCharacter(#file))
Next i
Case "TPE1" ; interprete ; Validé
; long_frame
long_frame=ReadLong(#file)
long_frame= to_little_indian(long_frame)-3
nul=ReadByte(#file)
fin_entete_frame=ReadLong(#file)
For i=1 To long_frame
interprete$=interprete$+Chr(ReadCharacter(#file))
Next i
Case "TIT2" ; titre ; Validé
; long_frame
long_frame=ReadLong(#file)
long_frame= to_little_indian(long_frame)-3
nul=ReadByte(#file)
fin_entete_frame=ReadLong(#file)
For i=1 To long_frame
titre$=titre$+Chr(ReadCharacter(#file))
Next i
Case "TCOP"
; long_frame
long_frame=ReadLong(#file)
long_frame= to_little_indian(long_frame)-3
nul=ReadByte(#file)
fin_entete_frame=ReadLong(#file)
For i=1 To long_frame
copyright$=copyright$+Chr(ReadCharacter(#file))
Next i
Case "TYER" ; Validé
; long_frame
long_frame=ReadLong(#file)
long_frame= to_little_indian(long_frame)-1
For i=1 To 3
nul=ReadByte(#file) ; 3Xnull
Next i
For i=1 To long_frame
annee$=annee$+Chr(ReadCharacter(#file))
Next i
Case "TRCK" ; Validé
For i=1 To 8
numero_piste$=Chr(ReadCharacter(#file))
Next i
Case "WXXX"
; long_frame
long_frame=ReadLong(#file)
long_frame= to_little_indian(long_frame)-3
nul=ReadByte(#file)
fin_entete_frame=ReadLong(#file)
For i=1 To long_frame
lien$=lien$+Chr(ReadCharacter(#file))
Next i
Case "COMM" ; Validé
; long_frame
long_frame=ReadLong(#file)
long_frame= to_little_indian(long_frame)-10
null=ReadLong(#file) ; ?
null=ReadLong(#file) ; ?
null=ReadLong(#file) ; ?
For i=1 To long_frame
commentaire$=commentaire$+Chr(ReadCharacter(#file))
Next i
Case "TCON"
; long_frame
long_frame=ReadLong(#file)
long_frame= to_little_indian(long_frame)-3
nul=ReadByte(#file)
fin_entete_frame=ReadLong(#file)
For i=1 To long_frame
genre$=genre$+Chr(ReadCharacter(#file))
Next i
Case "TLEN"
; long_frame
long_frame=ReadLong(#file)
long_frame= to_little_indian(long_frame)-3
nul=ReadByte(#file); null
fin_entete_frame=ReadLong(#file)
For i=1 To long_frame
longueur$=longueur$+Chr(ReadCharacter(#file))
Next i
Case "APIC" ; une image est presente
; long_frame
For i=1 To 13
ReadByte(#file)
Next i
; recupe le type d'image
For i=1 To 3
type_image$=type_image$+Chr(ReadCharacter(#file))
Next i
; saute 3 x0 avant debut image
For i=1 To 3
ReadByte(#file)
Next i
; ici debut image
If type_image$="jpg" Or type_image$="jpe"
;;;;;path$=PathRequester("ou mettre l'image ?",GetCurrentDirectory())
OpenFile(#image_file,path$+"temp.jpg")
While(tt.w <>$00D9) ;;;;;and (tt.w <>$00D8)
tt.w=ReadWord(#file)
WriteWord(#image_file,tt.w)
Wend
EndIf
Debug "une image du nom de (Temp.jpg) a été sauvée....."
RunProgram(path$+"temp.jpg")
CloseFile(#image_file)
EndSelect
pointeur.q=Loc(#file)
Until pointeur>long_id3
Else
ProcedureReturn "Erreur"
EndIf
retour$=album$+","+composeur$+","+interprete$+","+titre$+","+copyright$+","+annee$+","+numero_piste$+","+lien$+","+commentaire$+","+ genre$+","+ longueur$
ProcedureReturn retour$
EndProcedure
Procedure write_tag_mp3v2(file$,album$,composeur$,interprete$,titre$,copyright$,annee$,numero_piste$,lien$,commentaire$, genre$, longueur$,image$)
;
; By Dobro
; purebasic 4.51
; ecriture des tag MP3 id3V2
;
; **** efface le tag id3v2 s'il existe ********************
delete_tagV2(file$) ; efface l'ancien tag ID3V2
; *********************************************************
;
; OpenFile(#file2,file$)
If ReadFile(#file2, file$)<>0
Size = FileSize(file$)
*Buffer = AllocateMemory(Size)
If *Buffer
ReadData(#file2,*Buffer, Size)
CloseFile(#file2)
; le fichier est dans *Buffer
EndIf
EndIf
If OpenFile(#file,file$)
WriteByte(#file,Asc("I"))
WriteByte(#file,Asc("D"))
WriteByte(#file,Asc("3"))
WriteByte(#file,$03) ;$03
WriteLong(#file,$0) ; 0,0,0,0
WriteWord(#file,$0) ;ne pas oublier d'ajouter ça a la fin !!! (longueur de l'entete)
If album$<>""
tag_frame$="TALB" ; ici nikel !!
For i=1 To 4
car$=Mid(tag_frame$,i,1)
WriteByte(#file,Asc(car$))
Next i
long.l=(Len(album$)*2)+3 :compteur_long.l=compteur_long.l+long
to_little_indian_w(long.l)
;WriteLong(#file,long.l) ; long du champ
WriteByte(#file,$0) ; null
; ecriture fin champ
WriteByte(#file,$0)
WriteByte(#file,$1)
WriteByte(#file,$FF)
WriteByte(#file,$FE)
;
For i=1 To Len(album$)
car$=Mid(album$,i,1)
WriteUnicodeCharacter(#file,Asc(car$))
Next i
EndIf
If composeur$<>""
tag_frame$="TCOM" ; ici nikel !!
For i=1 To 4
car$=Mid(tag_frame$,i,1)
WriteByte(#file,Asc(car$))
Next i
long.l=(Len(composeur$)*2)+3:compteur_long.l=compteur_long.l+long
to_little_indian_w(long.l)
; WriteLong(#file,long.l) ; long du champ
WriteByte(#file,$0) ; null
; ecriture fin champ
WriteByte(#file,$0)
WriteByte(#file,$1)
WriteByte(#file,$FF)
WriteByte(#file,$FE)
;
For i=1 To Len(composeur$)
car$=Mid(composeur$,i,1)
WriteUnicodeCharacter(#file,Asc(car$))
Next i
EndIf
If interprete$<>""
tag_frame$="TPE1" ; ici nikel !!
For i=1 To 4
car$=Mid(tag_frame$,i,1)
WriteByte(#file,Asc(car$))
Next i
long.l=(Len(interprete$)*2)+3:compteur_long.l=compteur_long.l+long
to_little_indian_w(long.l)
; WriteLong(#file,long.l) ; long du champ
WriteByte(#file,$0) ; null
; ecriture fin champ
WriteByte(#file,$0)
WriteByte(#file,$1)
WriteByte(#file,$FF)
WriteByte(#file,$FE)
;
For i=1 To Len(interprete$)
car$=Mid(interprete$,i,1)
WriteUnicodeCharacter(#file,Asc(car$))
Next i
EndIf
If titre$<>""
tag_frame$="TIT2" ;
For i=1 To 4
car$=Mid(tag_frame$,i,1)
WriteByte(#file,Asc(car$))
Next i
long.l=(Len(titre$)*2)+3:compteur_long.l=compteur_long.l+long
to_little_indian_w(long.l)
WriteByte(#file,$0) ; null
; ecriture fin champ
WriteByte(#file,$0)
WriteByte(#file,$1)
WriteByte(#file,$FF)
WriteByte(#file,$FE)
For i=1 To Len(titre$)
car$=Mid(titre$,i,1)
WriteUnicodeCharacter(#file,Asc(car$))
Next i
EndIf
If copyright$<>""
tag_frame$="TCOP" ;
For i=1 To 4
car$=Mid(tag_frame$,i,1)
WriteByte(#file,Asc(car$))
Next i
long.l=(Len(copyright$)*2)+3:compteur_long.l=compteur_long.l+long
to_little_indian_w(long.l)
; WriteLong(#file,long.l) ; long du champ
WriteByte(#file,$0) ; null
; ecriture fin champ
WriteByte(#file,$0)
WriteByte(#file,$1)
WriteByte(#file,$FF)
WriteByte(#file,$FE)
;
For i=1 To Len(copyright$)
car$=Mid(copyright$,i,1)
WriteUnicodeCharacter(#file,Asc(car$))
Next i
EndIf
If annee$<>""
tag_frame$="TYER" ;
For i=1 To 4
car$=Mid(tag_frame$,i,1)
WriteByte(#file,Asc(car$))
Next i
long.l=5:compteur_long.l=compteur_long.l+long
WriteByte(#file,$0)
WriteByte(#file,$0)
WriteByte(#file,$0)
WriteByte(#file,$5)
For i=1 To 3
WriteByte(#file,$0) ; null
Next i
;
For i=1 To 4
car$=Mid(annee$,i,1)
WriteCharacter(#file,Asc(car$))
Next i
EndIf
If numero_piste$<>""
tag_frame$="TRCK" ;
For i=1 To 4
car$=Mid(tag_frame$,i,1)
WriteByte(#file,Asc(car$))
Next i
long.l=8:compteur_long.l=compteur_long.l+long
WriteLong(#file,$8)
If Len(numero_piste$)<4
numero_piste$=RSet(numero_piste$,4,"0")
EndIf
For i=1 To Len(numero_piste$)
car$=Mid(numero_piste$,i,1)
WriteCharacter(#file,Asc(car$))
Next i
EndIf
If commentaire$<>""
tag_frame$="COMM" ;
For i=1 To 4
car$=Mid(tag_frame$,i,1)
WriteByte(#file,Asc(car$))
Next i
long.l=(Len(commentaire$)*2)+10 :compteur_long.l=compteur_long.l+long
to_little_indian_w(long.l)
WriteLong(#file,$0) ; ?
WriteLong(#file,$0) ; ?
WriteLong(#file,$0) ; ?
;
For i=1 To Len(commentaire$)
car$=Mid(commentaire$,i,1)
WriteUnicodeCharacter(#file,Asc(car$))
Next i
EndIf
If lien$<>""
tag_frame$="WXXX" ;
For i=1 To 4
car$=Mid(tag_frame$,i,1)
WriteByte(#file,Asc(car$))
Next i
long.l=(Len(lien$)*2)+3:compteur_long.l=compteur_long.l+long
to_little_indian_w(long.l)
; WriteLong(#file,long.l) ; long du champ
WriteByte(#file,$0) ; null
; ecriture fin champ
WriteByte(#file,$0)
WriteByte(#file,$1)
WriteByte(#file,$FF)
WriteByte(#file,$FE)
;
For i=1 To Len(lien$)
car$=Mid(lien$,i,1)
WriteUnicodeCharacter(#file,Asc(car$))
Next i
EndIf
If genre$<>""
tag_frame$="TCON" ;
For i=1 To 4
car$=Mid(tag_frame$,i,1)
WriteByte(#file,Asc(car$))
Next i
long.l=(Len(genre$)*2)+3:compteur_long.l=compteur_long.l+long
to_little_indian_w(long.l)
; WriteLong(#file,long.l) ; long du champ
WriteByte(#file,$0) ; null
; ecriture fin champ
WriteByte(#file,$0)
WriteByte(#file,$1)
WriteByte(#file,$FF)
WriteByte(#file,$FE)
;
For i=1 To Len(genre$)
car$=Mid(genre$,i,1)
WriteUnicodeCharacter(#file,Asc(car$))
Next i
EndIf
If longueur$<>""
tag_frame$="TLEN"
For i=1 To 4
car$=Mid(tag_frame$,i,1)
WriteByte(#file,Asc(car$))
Next i
long.l=(Len(longueur$)*2)+3:compteur_long.l=compteur_long.l+long
total.S=Hex(long.l)
If Len(total.S)<8
total.S= RSet(total.S, 8,"0")
EndIf
octet1.S=Mid(total.S,1,2)
octet2.S=Mid(total.S,3,2)
octet3.S=Mid(total.S,5,2)
octet4.S=Mid(total.S,7,2)
WriteByte(#file,Val("$"+octet1.S))
WriteByte(#file,Val("$"+octet2.S))
WriteByte(#file,Val("$"+octet3.S))
WriteByte(#file,Val("$"+octet4.S))
WriteByte(#file,$0) ; null
; ecriture fin champ
WriteByte(#file,$0)
WriteByte(#file,$1)
WriteByte(#file,$FF)
WriteByte(#file,$FE)
;
For i=1 To Len(longueur$)
car$=Mid(longueur$,i,1)
WriteUnicodeCharacter(#file,Asc(car$))
Next i
EndIf
If image$<>""
If ReadFile(#file_image, image$)<>0
Size = FileSize(image$)
*Buffer_image = AllocateMemory(Size)
If *Buffer_image
ReadData(#file_image,*Buffer_image, Size)
CloseFile(#file_image)
; le fichier est dans *Buffer_image
EndIf
EndIf
tag_frame$="APIC"
For i=1 To 4
car$=Mid(tag_frame$,i,1)
WriteByte(#file,Asc(car$))
Next i
long.l=Size+3:compteur_long.l=compteur_long.l+long
total.S=Hex(long.l)
If Len(total.S)<8
total.S= RSet(total.S, 8,"0")
EndIf
octet1.S=Mid(total.S,1,2)
octet2.S=Mid(total.S,3,2)
octet3.S=Mid(total.S,5,2)
octet4.S=Mid(total.S,7,2)
WriteByte(#file,Val("$"+octet1.S))
WriteByte(#file,Val("$"+octet2.S))
WriteByte(#file,Val("$"+octet3.S))
WriteByte(#file,Val("$"+octet4.S))
WriteByte(#file,$0) ; null
WriteByte(#file,$0) ; null
WriteByte(#file,$0) ; null
For i=1 To Len("image/jpeg")
car$=Mid("image/jpeg",i,1)
WriteCharacter(#file,Asc(car$))
Next i
; ecriture fin champ
WriteByte(#file,$0) ; fin de chaine
WriteByte(#file,$03) ; type image ($12=illustration)
;{ type d'images possible
; $00 Other
; $01 32x32 pixels 'file icon' (PNG only)
; $02 Other file icon
; $03 Cover (front)
; $04 Cover (back)
; $05 Leaflet page
; $06 Media (e.g. label side of CD)
; $07 Lead artist/Lead performer/soloist
; $08 artist/performer
; $09 Conductor
; $0A Band/Orchestra
; $0B Composer
; $0C Lyricist/text writer
; $0D Recording Location
; $0E During Recording
; $0F During performance
; $10 Movie/video screen capture
; $11 A bright coloured fish
; $12 Illustration
; $13 Band/artist logotype
; $14 Publisher/Studio logotype
;}
WriteByte(#file,$0) ; encodage ?
;ajoute l'image
If *Buffer_image
WriteData(#file,*Buffer_image, Size)
FreeMemory(*Buffer_image)
EndIf
EndIf
; *********************************************************************
; *********************************************************************
; *********************************************************************
; *********************************************************************
; on ecrit le fichier a la suite de l'entete ID3
If *Buffer
WriteData(#file,*Buffer, Size)
FreeMemory(*Buffer)
EndIf
; ajoute la longueur du tag ID3 V2
FileSeek(#file,8)
total.S=Hex(compteur_long.l,#PB_Word)
If Len(total.S)<4
total.S="0"+total.S
EndIf
octet1.S=Mid(total.S,1,2)
octet2.S=Mid(total.S,3,2)
WriteByte(#file,Val("$"+octet2.S))
WriteByte(#file,Val("$"+octet1.S))
CloseFile(#file)
EndIf
EndProcedure
Procedure.l to_little_indian(valeur.l)
;by Dobro
total.S=Hex(valeur.l,#PB_Long)
If Len(total.S)<8
total.S="0"+total.S
EndIf
octet1.S=Mid(total.S,1,2)
octet2.S=Mid(total.S,3,2)
octet3.S=Mid(total.S,5,2)
octet4.S=Mid(total.S,7,2)
total.S="$"+octet4.S+octet3.S+octet2.S+octet1.S
sorti.l=Val(total.S)
ProcedureReturn sorti.l
EndProcedure
Procedure to_little_indian_w(valeur.l)
;by Dobro
total.S=Hex(valeur.l)
If Len(total.S)<8
total.S= LSet(total.S, 8,"0")
EndIf
octet1.S=Mid(total.S,1,2)
octet2.S=Mid(total.S,3,2)
octet3.S=Mid(total.S,5,2)
octet4.S=Mid(total.S,7,2)
WriteByte(#file,Val("$"+octet4.S))
WriteByte(#file,Val("$"+octet3.S))
WriteByte(#file,Val("$"+octet2.S))
WriteByte(#file,Val("$"+octet1.S))
EndProcedure
Procedure write_tag_mp3(file$,titre$,interprete$,album$,annee$,commentaire$,numero_piste$,genre_musical$)
; By Dobro
; purebasic 4.51
; ecriture des tag MP3 id3V1
delete_tagV1(file$) ; efface le Tag present
If OpenFile(#file,file$)
FileSeek(#file, Lof(#file)) ; on se place a la fin du fichier pour ajouter le tag ID3V1
WriteByte(#file,Asc("T"))
WriteByte(#file,Asc("A"))
WriteByte(#file,Asc("G"))
; ********** ecriture du titre ****************************
For i=1 To 30
car$=Mid(titre$,i,1)
WriteByte(#file,Asc(car$))
Next i
;*************************************************************
;**************** ecriture de l'interprete *****************
For i=1 To 30
car$=Mid(interprete$,i,1)
WriteByte(#file,Asc(car$))
Next i
; ***********************************************************
; ****************** ecriture de l'album ***********************
For i=1 To 30
car$=Mid(album$,i,1)
WriteByte(#file,Asc(car$))
Next i
; *****************************************************************
;***************** ecriture de l'année **************************
For i=1 To 4
car$=Mid(annee$,i,1)
WriteByte(#file,Asc(car$))
Next i
; *****************************************************************
; ******************** ecriture des commentaires *****************
For i=1 To 28
car$=Mid(commentaire$,i,1)
WriteByte(#file,Asc(car$))
Next i
; ********************************************************************
; ******************** ecriture octet nul *****************
WriteByte(#file,0)
; ********************************************************************
; ******************** ecriture numero de piste*****************
car$=Mid(numero_piste$,1,1)
WriteByte(#file,Val(car$))
; ********************************************************************
; ************************ ecriture du genre musicale ******************
car$=genre_musical$
WriteByte(#file,Val(car$))
; ***************************************************************************²
CloseFile(#file)
Else
ProcedureReturn 0
EndIf
EndProcedure
Procedure delete_tagV1(file$)
; by Dobro
; Purebasic 4.51
If OpenFile(#file,file$)
FileSeek(#file, Lof(#file)-128) ; ruse de guerre , on saute a la fin du fichier , puis on recul de 128 octets !
For i=1 To 3
tag$= tag$+Chr(ReadCharacter(#file) )
Next i
; determine si le tag Mp3 existe
If tag$="TAG"
tag_present=#true
FileSeek(#file,Lof(#file)-129)
TruncateFile(#file)
CloseFile(#file)
Debug "Tag V1 effacé"
Else
tag_present=#False
Debug "Le tag est absent , on ne peux l'effacer"
EndIf
EndIf
EndProcedure
Procedure delete_tagV2(file$)
; by Dobro
; Purebasic 4.51
If OpenFile(#file,file$)
tag$=""
For i=0 To 2
tag$= tag$+Chr(ReadCharacter(#file) )
Next i
; determine si le tag Mp3 V2 existe
If tag$="ID3"
tag_present=#true
Debug "Le tag V2 est présent, et va etre effacé"
Chemin$ = GetPathPart(file$)
nom$ = GetFilePart(file$)
nom$=Left(nom$,Len(nom$)-4)
Extension$ = GetExtensionPart(file$)
nom2$=Chemin$+nom$+"xx"+"."+Extension$
CloseFile(#file)
RenameFile(file$,nom2$)
OpenFile(#file,nom2$)
While Eof(#file)=0
test=ReadLong(#file)
test$=Hex(test,#PB_Long)
test$=RSet(test$,8,"0")
If test$="FBFF0000" ; recherche debut mp3
beep_(440,200)
pos=Loc(#file)-2 ; note la position du debut du mp3
ok=1
Break
Else
FileSeek(#file,Loc(#file)-3)
EndIf
Wend
CloseFile(#file)
If tag_present=#true And ok=1
OpenFile(#file,nom2$) ; origin
OpenFile(#file2,file$) ; destination
FileSeek(#file,pos)
While Eof(#file)=0
mot.l=ReadLong(#file)
WriteLong(#file2,mot.l)
Wend
CloseFile(#file2)
CloseFile(#file)
DeleteFile(nom2$)
Debug "Le Tag V2 est effacé !"
EndIf
Else
tag_present=#False
Debug "Le tag V2 est absent et ne sera donc pas effacé , cte bonne bague..."
EndIf
EndIf
EndProcedure
; Epb