Je vous explique brièvement mon problème, Je veut récupéré le titre et l’interprète d'un morceau diffuser sur un site de radio sur le Web (smoothjazz.com)
et je l’écrit dans un fichier, texte mis a jour quand le tire change.
Pour l’afficher sur un afficheur. cela fonctionner plutôt bien mais a présent que le HTTPS est généralisé cela ne fonctionne plus!
Code : Tout sélectionner
Global site.s = "http://www.smoothjazz.com"
;-declaration
Declare ouvre_fenetre()
Declare.s SearchString(String.s,StartString.s,EndString.s)
Declare.s Url2Text2(Url.s, OpenType.b,ProxyAndPort.s)
Declare.s Url2Text(Url.s)
Declare.s filtre(Var.s)
;-initialisation
Enumeration ; fennetre
#window
EndEnumeration
Enumeration ; gadgets
#editeur
#timer
#editor
EndEnumeration
Enumeration ;Fichier
#file
EndEnumeration
ouvre_fenetre()
;-boucle
Repeat
Select WindowEvent()
Case #PB_Event_Timer
If EventTimer() = #timer
interpret.s= SearchString(Url2Text(Site.s),"<span class="+Chr(34)+"nowplaying_artist"+Chr(34)+">","<")
titre.s= SearchString(Url2Text(Site.s),Chr(34)+"nowplaying_song"+Chr(34)+">","<")
interpret.s=filtre(interpret.s)
titre.s=filtre(titre.s)
; Affichage Editeur
ClearGadgetItems(#editor)
AddGadgetItem(#editor, 0,"Titre :"+titre.s)
AddGadgetItem(#editor, 0, "Artist: "+interpret.s)
If interpret.s<>"" And titre.s<>""
If OpenFile(#file,"info.txt")
TruncateFile(#File)
WriteString(#file,interpret.s+"-")
WriteString(#file,titre.s)
CloseFile(#file)
EndIf
EndIf
EndIf
Case #PB_Event_CloseWindow
End
EndSelect
ForEver
; ********** Zone des Procedures **********************************
;- zone procedure
Procedure ouvre_fenetre()
OpenWindow(#window,10,10,320,100,"resultat",#PB_Window_SystemMenu )
EditorGadget(#editor,10,10,300,80)
AddWindowTimer(#window, #timer, 10000) ; toute les 10 secondes
EndProcedure
Procedure.s SearchString(String.s,StartString.s,EndString.s)
Global SearchStringIndex,SearchString.s
SearchStringIndex=1
SearchString=String
Start=FindString(SearchString,StartString,SearchStringIndex)
If Start
Start=Start+Len(StartString)
EndIndex=FindString(SearchString,EndString,Start)
If EndIndex
SearchStringIndex=EndIndex+Len(EndString)
ProcedureReturn Mid(SearchString,Start,EndIndex-Start)
Else
EndIndex=Len(SearchString)+1
SearchStringIndex=EndIndex+Len(EndString)
ProcedureReturn Mid(SearchString,Start,EndIndex-Start)
EndIf
Else
Start=1
EndIndex=FindString(SearchString,EndString,Start)
If EndIndex
SearchStringIndex=EndIndex+Len(EndString)
ProcedureReturn Mid(SearchString,Start,EndIndex-Start)
Else
EndIndex=Len(SearchString)+1
SearchStringIndex=EndIndex+Len(EndString)
ProcedureReturn Mid(SearchString,Start,EndIndex-Start)
EndIf
EndIf
EndProcedure
ProcedureDLL.s Url2Text2(Url.s, OpenType.b,ProxyAndPort.s)
; 1 INTERNET_OPEN_TYPE_DIRECT Resolves all host names locally.
; 0 INTERNET_OPEN_TYPE_PRECONFIG Retrieves the proxy Or direct configuration from the registry.
; 4 INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY Retrieves the proxy Or direct configuration from the registry And prevents the use of a startup Microsoft JScript Or Internet Setup (INS) file.
; 3 INTERNET_OPEN_TYPE_PROXY Passes requests To the proxy unless a proxy bypass list is supplied And the name To be resolved bypasses the proxy. In this Case, the function uses INTERNET_OPEN_TYPE_DIRECT.
isLoop.b=1
INET_RELOAD.l = $80000000
hInet.l=0
hURL.l=0
Bytes.l=0
Buffer.s=Space(2048)
res.s=""
hInet = InternetOpen_("", OpenType, ProxyAndPort, "", 0)
hURL = InternetOpenUrl_(hInet, Url, #Null, 0, INET_RELOAD, 0)
Repeat
InternetReadFile_(hURL,@Buffer, Len(Buffer), @Bytes)
If Bytes = 0
isLoop=0
Else
res = res + Left(Buffer, Bytes)
EndIf
Until isLoop=0
InternetCloseHandle_(hURL)
InternetCloseHandle_(hInet)
ProcedureReturn res
EndProcedure
ProcedureDLL.s Url2Text(Url.s)
ProcedureReturn Url2Text2(Url,1,"")
EndProcedure
; Procedure.s filtre(Var.s)
; ; By Dobro
; ; exemple de filtre
; For i=1 to len(var.s)
; extr.s=mid(var.s,i,1)
; If( asc(extr.s)>47 and asc(extr.s)<58) or (asc(extr.s)>64 and asc(extr.s)<91) or (asc(extr.s)>96 and asc(extr.s)<123) or asc(extr.s)=45
; sort.s=sort.s+extr.s
; Else
; sort.s=sort.s+""
; Endif
; Next i
; ProcedureReturn Sort.s
;
; Endprocedure
Procedure.s filtre(Var.s)
For i=32 To 255
If i<100
Var.s = ReplaceString(Var.s,"&#"+"0"+Str(i),Chr(i) )
Else
Var.s = ReplaceString(Var.s,"&#"+Str(i),Chr(i) )
EndIf
Next i
; By Dobro
; autre exemple de filtre qui a l'avantage que nous voyons directement les caracteres que nous désirons garder , il suffit de les ajouter dans la chaine Ref.s
ref.s="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-()[].' " ; << derniere caractere est un espace
For i=1 To Len(var.s)
ex.s=Mid(var.s,i,1)
If FindString(ref.s,ex.s)>0
sort.s=sort.s+ex.s
EndIf
Next i
ProcedureReturn Sort.s
EndProcedure
; EPB
; IDE Options = PureBasic 5.62 (Windows - x64)
; Folding = -
; EnableXP
; Executable = titreload.exe
Pouvez vous m'aider?
Merci.
Cordialement.