personant Posted May 30, 2011 Share Posted May 30, 2011 (edited) I am trying to create a lyric grabber... the script will get the source from a webpage and display it in an edit box. but I am stuck at removing the <br>, <i> and </i> tags... I had tried replacing the tags with @crlf but it would end up displaying a tiny square box in the edit box. Below is the current script expandcollapse popupOnAutoItExitRegister("_exit") #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <INet.au3> #include <IE.au3> Global $file, $txt Global $lyricData[2],$lyricOBJ $Form1 = GUICreate("Lyric Finder", 625, 443, 294, 186) $Edit1 = GUICtrlCreateEdit("", 50, 96, 500, 289,BitOR($ES_CENTER,$ES_WANTRETURN,$WS_VSCROLL)) GUICtrlSetFont(-1, 13, 800, 0, "vernada") GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlSetBkColor(-1, 0x000000) GUICtrlSetLimit(-1, 35) GUICtrlSetResizing(-1, $GUI_DOCKWIDTH) GUICtrlSetData(-1, "") $Pic1 = GUICtrlCreatePic("", 8, 96, 249, 289, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS)) $Label2 = GUICtrlCreateLabel("Song name:", 28, 32, 61, 17) $Label3 = GUICtrlCreateLabel("Artist name:", 28, 56, 56, 17) $songInput = GUICtrlCreateInput("", 88, 32, 249, 21) $ArtistInput = GUICtrlCreateInput("", 88, 56, 249, 21) $Button1 = GUICtrlCreateButton("Search", 344, 24, 105, 57, $WS_GROUP) $Button2 = GUICtrlCreateButton("Exit", 464, 24, 105, 57, $WS_GROUP) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button2 Exit Case $Button1 $a= GUICtrlRead($ArtistInput) $s= GUICtrlRead($songInput) $result = getLyrics($a,$s) GUICtrlSetData($Edit1, $result) EndSwitch WEnd Func getLyrics($a="",$s="") $x = StringReplace($a, " ", "") $y = StringReplace($s, " ", "") $lyricURL = "http://www.azlyrics.com/lyrics/" & $x & "/" & $y & ".html" $String = BinaryToString(InetRead($lyricURL, 1)) $lyricData = _StringBetween2($String,"<!-- start of lyrics -->","<!-- end of lyrics -->") $String = StringReplace($lyricData, '<br>', @crlf) $String= StringReplace($String, '<i>', "") $String= StringReplace($String, '</i>', "") if StringLen($String) == 0 Then $String = @crlf & "Lyrics not found." Return ($String) EndFunc Func _StringBetween2($s, $from, $to) $x = StringInStr($s, $from) + StringLen($from) $y = StringInStr(StringTrimLeft($s, $x), $to) Return StringMid($s, $x, $y) EndFunc Func _exit() Exit EndFunc Hope the masters can help me... Edited May 30, 2011 by personant Link to comment Share on other sites More sharing options...
personant Posted May 30, 2011 Author Share Posted May 30, 2011 please someone help me Link to comment Share on other sites More sharing options...
Zedna Posted May 30, 2011 Share Posted May 30, 2011 Don't bump your topic within 24 hours! Resources UDF Â ResourcesEx UDF Â AutoIt Forum Search Link to comment Share on other sites More sharing options...
personant Posted May 30, 2011 Author Share Posted May 30, 2011 Don't bump your topic within 24 hours!Sorry... I'm new Link to comment Share on other sites More sharing options...
jaberwacky Posted May 30, 2011 Share Posted May 30, 2011 (edited) Ok, only because you said 'masters' ;P expandcollapse popup#AutoIt3Wrapper_Au3Check_Parameters=-w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 -d OnAutoItExitRegister("_exit") #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <String.au3> #region ;### Koda GUI section ### GUICreate("Lyric Finder", 625, 443, 294, 186) Global Const $Edit1 = GUICtrlCreateEdit('', 50, 96, 500, 289, BitOR($ES_CENTER, $ES_WANTRETURN, $WS_VSCROLL)) GUICtrlSetFont($Edit1, 13, 60, 0, "Verdana") GUICtrlSetColor($Edit1, 0xFFFFFF) GUICtrlSetBkColor($Edit1, 0x000000) GUICtrlSetLimit($Edit1, 35) GUICtrlSetResizing($Edit1, $GUI_DOCKWIDTH) Global Const $Pic1 = GUICtrlCreatePic('', 8, 96, 249, 289, BitOR($SS_NOTIFY, $WS_GROUP, $WS_CLIPSIBLINGS)) GUICtrlCreateLabel("Song name:", 28, 32, 61, 17) Global Const $songInput = GUICtrlCreateInput('numb', 88, 32, 249, 21) GUICtrlCreateLabel("Artist name:", 28, 56, 56, 17) Global Const $ArtistInput = GUICtrlCreateInput('linkin park', 88, 56, 249, 21) Global Const $search_btn = GUICtrlCreateButton("Search", 344, 24, 105, 57, $WS_GROUP) Global Const $exit_btn = GUICtrlCreateButton("Exit", 464, 24, 105, 57, $WS_GROUP) GUISetState(@SW_SHOWNORMAL) #endregion Global $result While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $exit_btn Exit Case $search_btn $result = getLyrics() GUICtrlSetData($Edit1, $result) EndSwitch WEnd Func getLyrics() Local Const $artist = StringStripWS(GUICtrlRead($ArtistInput), 8) Local Const $song = StringStripWS(GUICtrlRead($songInput), 8) Local Const $lyricURL = StringLower("http://www.azlyrics.com/lyrics/" & $artist & '/' & $song & ".html") Local Const $lyrics = BinaryToString(InetRead($lyricURL, 1)) If @error = 1 Then Return "Lyrics not found." & @CRLF EndIf Local $lyricData = _StringBetween($lyrics, "<!-- start of lyrics -->", "<!-- end of lyrics -->") $lyricData = StringStripWS($lyricData[0], 7) $lyricData = StringReplace($lyricData, "<br>", @CRLF) $lyricData = StringReplace($lyricData, "<i>", '') Return StringReplace($lyricData, "</i>", '') EndFunc Func _exit() Exit EndFunc Edited May 30, 2011 by LaCastiglione Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
personant Posted May 30, 2011 Author Share Posted May 30, 2011 Ok, only because you said 'masters' ;P expandcollapse popup#AutoIt3Wrapper_Au3Check_Parameters=-w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 -d OnAutoItExitRegister("_exit") #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <String.au3> #region ;### Koda GUI section ### GUICreate("Lyric Finder", 625, 443, 294, 186) Global Const $Edit1 = GUICtrlCreateEdit('', 50, 96, 500, 289, BitOR($ES_CENTER, $ES_WANTRETURN, $WS_VSCROLL)) GUICtrlSetFont($Edit1, 13, 800, 0, "Verdana") GUICtrlSetColor($Edit1, 0xFFFFFF) GUICtrlSetBkColor($Edit1, 0x000000) GUICtrlSetLimit($Edit1, 35) GUICtrlSetResizing($Edit1, $GUI_DOCKWIDTH) Global Const $Pic1 = GUICtrlCreatePic('', 8, 96, 249, 289, BitOR($SS_NOTIFY, $WS_GROUP, $WS_CLIPSIBLINGS)) GUICtrlCreateLabel("Song name:", 28, 32, 61, 17) Global Const $songInput = GUICtrlCreateInput('', 88, 32, 249, 21) GUICtrlCreateLabel("Artist name:", 28, 56, 56, 17) Global Const $ArtistInput = GUICtrlCreateInput('', 88, 56, 249, 21) Global Const $search_btn = GUICtrlCreateButton("Search", 344, 24, 105, 57, $WS_GROUP) Global Const $exit_btn = GUICtrlCreateButton("Exit", 464, 24, 105, 57, $WS_GROUP) GUISetState(@SW_SHOWNORMAL) #endregion Global $result While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $exit_btn Exit Case $search_btn $result = getLyrics() GUICtrlSetData($Edit1, $result) EndSwitch WEnd Func getLyrics() Local Const $artist = StringStripWS(GUICtrlRead($ArtistInput), 8) Local Const $song = StringStripWS(GUICtrlRead($songInput), 8) Local Const $lyricURL = StringLower("http://www.azlyrics.com/lyrics/" & $artist & '/' & $song & ".html") Local Const $lyrics = BinaryToString(InetRead($lyricURL, 1)) If @error = 1 Then Return @CRLF & "Lyrics not found." EndIf Local $lyricData = _StringBetween($lyrics, "<!-- start of lyrics -->", "<!-- end of lyrics -->") $lyricData = StringReplace($lyricData[0], "<br>", @CRLF) $lyricData = StringReplace($lyricData, "<i>", '') $lyricData = StringReplace($lyricData, "</i>", '') Return StringStripWS($lyricData, 3) EndFunc Func _exit() Exit EndFunc ;==>_exit still getting those square boxes.... Link to comment Share on other sites More sharing options...
jaberwacky Posted May 30, 2011 Share Posted May 30, 2011 Strange, when I use the same song I don't get those square boxes. Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
personant Posted May 30, 2011 Author Share Posted May 30, 2011 (edited) founded a way to remove those boxes...but the lyrics will mess up.. is there anyone who can make the lyrics line up again...pleaseexpandcollapse popup#AutoIt3Wrapper_Au3Check_Parameters=-w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 -d OnAutoItExitRegister("_exit") #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <String.au3> #region ;### Koda GUI section ### GUICreate("Lyric Finder", 625, 443, 294, 186) Global Const $Edit1 = GUICtrlCreateEdit('', 50, 96, 500, 289, BitOR($ES_CENTER, $ES_WANTRETURN, $WS_VSCROLL)) GUICtrlSetFont($Edit1, 10, 800, 0, "arial") GUICtrlSetColor($Edit1, 0xFFFFFF) GUICtrlSetBkColor($Edit1, 0x000000) GUICtrlSetLimit($Edit1, 35) GUICtrlSetResizing($Edit1, $GUI_DOCKWIDTH) Global Const $Pic1 = GUICtrlCreatePic('', 8, 96, 249, 289, BitOR($SS_NOTIFY, $WS_GROUP, $WS_CLIPSIBLINGS)) GUICtrlCreateLabel("Song name:", 28, 32, 61, 17) Global Const $songInput = GUICtrlCreateInput('', 88, 32, 249, 21) GUICtrlCreateLabel("Artist name:", 28, 56, 56, 17) Global Const $ArtistInput = GUICtrlCreateInput('', 88, 56, 249, 21) Global Const $search_btn = GUICtrlCreateButton("Search", 344, 24, 105, 57, $WS_GROUP) Global Const $exit_btn = GUICtrlCreateButton("Exit", 464, 24, 105, 57, $WS_GROUP) GUISetState(@SW_SHOWNORMAL) #endregion Global $result While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $exit_btn Exit Case $search_btn $result = getLyrics() GUICtrlSetData($Edit1, $result) EndSwitch WEnd Func getLyrics() Local Const $artist = StringStripWS(GUICtrlRead($ArtistInput), 8) Local Const $song = StringStripWS(GUICtrlRead($songInput), 8) Local Const $lyricURL = StringLower("http://www.azlyrics.com/lyrics/" & $artist & '/' & $song & ".html") Local Const $lyrics = BinaryToString(InetRead($lyricURL, 1)) If @error = 1 Then Return @CRLF & "Lyrics not found." EndIf Local $lyricData = _StringBetween($lyrics, "<!-- start of lyrics -->", "<!-- end of lyrics -->") $lyricData = StringReplace($lyricData[0], "<br>", @CRLF) $lyricData = StringReplace($lyricData, "<i>", @cr) $lyricData = StringReplace($lyricData, "</i>", @cr) $lyricData = StringReplace($lyricData, @cr, "") $lyricData = StringReplace($lyricData, @lf, "") Return StringStripWS($lyricData, 3) EndFunc Func _exit() Exit EndFunc ;==>_exit#AutoIt3Wrapper_Au3Check_Parameters=-w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 -d OnAutoItExitRegister("_exit") #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <String.au3> #region ;### Koda GUI section ### GUICreate("Lyric Finder", 625, 443, 294, 186) Global Const $Edit1 = GUICtrlCreateEdit('', 50, 96, 500, 289, BitOR($ES_CENTER, $ES_WANTRETURN, $WS_VSCROLL)) GUICtrlSetFont($Edit1, 10, 800, 0, "arial") GUICtrlSetColor($Edit1, 0xFFFFFF) GUICtrlSetBkColor($Edit1, 0x000000) GUICtrlSetLimit($Edit1, 35) GUICtrlSetResizing($Edit1, $GUI_DOCKWIDTH) Global Const $Pic1 = GUICtrlCreatePic('', 8, 96, 249, 289, BitOR($SS_NOTIFY, $WS_GROUP, $WS_CLIPSIBLINGS)) GUICtrlCreateLabel("Song name:", 28, 32, 61, 17) Global Const $songInput = GUICtrlCreateInput('', 88, 32, 249, 21) GUICtrlCreateLabel("Artist name:", 28, 56, 56, 17) Global Const $ArtistInput = GUICtrlCreateInput('', 88, 56, 249, 21) Global Const $search_btn = GUICtrlCreateButton("Search", 344, 24, 105, 57, $WS_GROUP) Global Const $exit_btn = GUICtrlCreateButton("Exit", 464, 24, 105, 57, $WS_GROUP) GUISetState(@SW_SHOWNORMAL) #endregion Global $result While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $exit_btn Exit Case $search_btn $result = getLyrics() GUICtrlSetData($Edit1, $result) EndSwitch WEnd Func getLyrics() Local Const $artist = StringStripWS(GUICtrlRead($ArtistInput), 8) Local Const $song = StringStripWS(GUICtrlRead($songInput), 8) Local Const $lyricURL = StringLower("http://www.azlyrics.com/lyrics/" & $artist & '/' & $song & ".html") Local Const $lyrics = BinaryToString(InetRead($lyricURL, 1)) If @error = 1 Then Return @CRLF & "Lyrics not found." EndIf Local $lyricData = _StringBetween($lyrics, "<!-- start of lyrics -->", "<!-- end of lyrics -->") $lyricData = StringReplace($lyricData[0], "<br>", @CRLF) $lyricData = StringReplace($lyricData, "<i>", @cr) $lyricData = StringReplace($lyricData, "</i>", @cr) $lyricData = StringReplace($lyricData, @cr, "") $lyricData = StringReplace($lyricData, @lf, "") Return StringStripWS($lyricData, 3) EndFunc Func _exit() Exit EndFunc ;==>_exit Edited May 30, 2011 by personant Link to comment Share on other sites More sharing options...
Zedna Posted May 30, 2011 Share Posted May 30, 2011 Try this Func getLyrics($a="",$s="") $x = StringReplace($a, " ", "") $y = StringReplace($s, " ", "") $lyricURL = "http://www.azlyrics.com/lyrics/" & $x & "/" & $y & ".html" $String = BinaryToString(InetRead($lyricURL, 1)) $lyricData = _StringBetween2($String,"<!-- start of lyrics -->","<!-- end of lyrics -->") $String = StringReplace($lyricData, '<br>', @cr) ; or second variant: $String = StringReplace($lyricData, '<br>', @lf) $String= StringReplace($String, '<i>', "") $String= StringReplace($String, '</i>', "") if StringLen($String) == 0 Then $String = @crlf & "Lyrics not found." Return ($String) EndFunc Resources UDF Â ResourcesEx UDF Â AutoIt Forum Search Link to comment Share on other sites More sharing options...
GEOSoft Posted May 30, 2011 Share Posted May 30, 2011 Another thing you might want to look at is your use of Verdana font in that Edit control. Try either the Default or another common one like Arial. <i> and </> refer to italics so that doesn't mean they should be replaced with line feeds or CRs anyway. $sString = BinaryToString(InetRead(<Some URL>)) $sString = StringRegExpReplace($sString, "<.*?br>", @CRLF) $sString = StringRegExpReplace($sString, "<.+?>", "") George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
personant Posted May 30, 2011 Author Share Posted May 30, 2011 (edited) Try this Func getLyrics($a="",$s="") $x = StringReplace($a, " ", "") $y = StringReplace($s, " ", "") $lyricURL = "http://www.azlyrics.com/lyrics/" & $x & "/" & $y & ".html" $String = BinaryToString(InetRead($lyricURL, 1)) $lyricData = _StringBetween2($String,"<!-- start of lyrics -->","<!-- end of lyrics -->") $String = StringReplace($lyricData, '<br>', @cr) ; or second variant: $String = StringReplace($lyricData, '<br>', @lf) $String= StringReplace($String, '<i>', "") $String= StringReplace($String, '</i>', "") if StringLen($String) == 0 Then $String = @crlf & "Lyrics not found." Return ($String) EndFunc Thanxx... It works! thanks to all of you for helping me out.... Now I can start working on the interface Edited May 30, 2011 by personant Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now