I wrote this program a while ago... I thought it would br a good idea to share it
Please feel free to leave suggestions, improvements and bug corrections
#include <INet.au3> #include <GuiConstantsEx.au3> #include <StaticConstants.au3> #include <GuiTreeView.au3> #include <GuiStatusBar.au3> #include <File.au3> #include <iTunes.au3> $copyright = "Copyright © 2009 torels_ <http://torels.altervista.org>" $gui = GUICreate("Lyric Finder 2 - torels_", 600, 534) ;GUISetIcon("shell32.dll", -172) GUISetIcon("shell32.dll", "41") ;menu $menu = GUICtrlCreateMenu("File") $save = GUICtrlCreateMenuItem("&Save", $menu) $print = GUICtrlCreateMenuItem("&Print", $menu) GUICtrlCreateMenuItem("", $menu) $exit = GUICtrlCreateMenuItem("&Exit", $menu) $Discography_mnu = GUICtrlCreateMenu("Discography") $d_txt = GUICtrlCreateMenuItem("Export as &Text", $Discography_mnu) $d_xml = GUICtrlCreateMenuItem("Export as &Xml", $Discography_mnu) $d_html = GUICtrlCreateMenuItem("Export as &Html", $Discography_mnu) $itunes_int = GUICtrlCreateMenu("iTunes") $integrate = GUICtrlCreateMenuItem("iTunes integration", $itunes_int) $refresh = GUICtrlCreateMenuItem("Refresh", $itunes_int) $savelyr = GUICtrlCreateMenuItem("Save Lyric to iTunes", $itunes_int) $help_mnu = GUICtrlCreateMenu("?") $info = GUICtrlCreateMenuItem("Info", $help_mnu) GUICtrlCreateMenuItem("", $help_mnu) $help = GUICtrlCreateMenuItem("torels_", $help_mnu) ;controls $Edit = GUICtrlCreateEdit("", 0, 0, 601, 417) ControlHide($gui,"",$edit) $tv = GUICtrlCreateTreeView(0,0,601,417) $Discography = GUICtrlCreateButton("Discography", 464, 424, 105, 25, 0) $FindLyrics = GUICtrlCreateButton("Find Lyrics", 464, 456, 105, 25, 0) $ArtistInput = GUICtrlCreateInput("", 88, 427, 361, 21) $SongInput = GUICtrlCreateInput("", 88, 459, 361, 21) GUICtrlCreateLabel("Artist Name", 16, 432, 58, 17) GUICtrlCreateLabel("Song Title", 16, 464, 52, 17) $StatusBar = _GUICtrlStatusBar_Create($gui, Default, $copyright) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case -3 Exit Case $Discography _GUICtrlTreeView_DeleteAll($tv) ControlHide($gui,"",$edit) ControlShow($gui,"",$tv) _XML2TreeView(_Discography(StringReplace(GUICtrlRead($ArtistInput)," ","_"))) If _GUICtrlTreeView_GetCount($tv)<1 Then _GUICtrlTreeView_Add($tv, 0, "Nothing Found!", 2,2) _GUICtrlStatusBar_SetText($StatusBar, "Displaying " & GUICtrlRead($ArtistInput) & "'s Discography") Case $FindLyrics ControlHide($gui,"",$tv) ControlShow($gui,"",$edit) GUICtrlSetData($Edit, _FindLyrics(GUICtrlRead($ArtistInput), GUICtrlRead($SongInput))) _GUICtrlStatusBar_SetText($StatusBar, "Displaying " & GUICtrlRead($SongInput) & "'s Lyrics by " & GUICtrlRead($ArtistInput)) Case $print $printfile = _TempFile(@TempDir, GUICtrlRead($ArtistInput) & "-" & GUICtrlRead($SongInput), ".txt") $fh = FileOpen($printfile, 2) FileWrite($fh, GUICtrlRead($edit)) FileClose($fh) _FilePrint($printfile) Case $save $filename = FileSaveDialog("Save Lyric...", @MyDocumentsDir, "text file (*.txt)", 2 + 16, GUICtrlRead($ArtistInput) & " - " & GUICtrlRead($SongInput)) If Not StringRight($filename, 4) = ".txt" Then $filename &= ".txt" FileOpen($filename, 2) FileWrite($filename, GUICtrlRead($edit)) FileClose($filename) Case $savelyr If BitAND(GUICtrlRead($integrate), $GUI_CHECKED) = $GUI_CHECKED Then _iTunes_Current_LyricsSet(GUICtrlRead($edit)) Else _GUICtrlStatusBar_SetText($StatusBar, "You Must Enable iTunes Integration") EndIf Case $integrate If BitAND(GUICtrlRead($integrate), $GUI_CHECKED) = $GUI_CHECKED Then If ProcessExists("iTunes.exe") Then GUICtrlSetState($integrate, $GUI_UNCHECKED) EndIf Else GUICtrlSetState($integrate, $GUI_CHECKED) _iTunes_Start() $info = _iTunes_Current_GetInfo() GUICtrlSetData($ArtistInput, $info[1]) GUICtrlSetData($SongInput, $info[2]) $info="" EndIf Case $help ShellExecute("http://torels.altervista.org") Case $refresh If ProcessExists("iTunes.exe") Then $info = _iTunes_Current_GetInfo() GUICtrlSetData($ArtistInput, $info[1]) GUICtrlSetData($SongInput, $info[2]) $info="" Else _GUICtrlStatusBar_SetText($StatusBar, "You Must Enable iTunes Integration") EndIf Case $d_txt _Export("txt", GUICtrlRead($ArtistInput)) Case $d_xml _Export("xml", GUICtrlRead($ArtistInput)) Case $d_html _Export("html",GUICtrlRead($ArtistInput)) Case $info MsgBox(64, "Lyric Finder 2", "Lyric Finder 2 powered and developed by torels_"&@CRLF& _ $copyright & @CRLF & _ "Version 2.0.0.0" &@CRLF& _ "For info and/or support mail gab.torels@gmail.com or visit http://torels.altervista.org") Case $exit Exit EndSwitch $selP = _GUICtrlTreeView_GetParentHandle($tv,_GUICtrlTreeView_GetSelection($tv)) $sel = _GUICtrlTreeView_GetText($tv,_GUICtrlTreeView_GetSelection($tv)) If $sel <> GUICtrlRead($SongInput) and $selP<>"" then GUICtrlSetData($SongInput, $sel) EndIf WEnd Func _FindLyrics($artist, $song) If $song="" Then Return _Discography($artist) $out = _INetGetSource("http://lyricwiki.org/api.php?func=getSong&artist="&$artist&"&song="&$song&"&fmt=text") $out = StringReplace($out, @LF,@CRLF) Return $out EndFunc Func _Discography($artist) $xml = _INetGetSource("http://lyricwiki.org/api.php?func=getSong&artist="&StringReplace($artist, " ", "_")&"&song=&fmt=xml") Return _CleanXML($xml) EndFunc Func _CleanXML($xml) ;this removes useless tags $xml = StringReplace($xml, '<?xml version="1.0" encoding="UTF-8"?>'&@LF, "") $xml = StringReplace($xml, "</getArtistResponse>"&@LF,"") $xml = StringReplace($xml, "<getArtistResponse>"&@LF,"") $xml = StringReplace($xml, "<albums>"&@LF,"") $xml = StringReplace($xml, "</albums>"&@LF,"") $xml = StringReplace($xml, "<songs>"&@LF, "") $xml = StringReplace($xml, "</songs>"&@LF, "") $xml = StringRegExpReplace($xml, "<artist>(.*?)</artist>"&@LF,"") $xml = StringRegExpReplace($xml, "<amazonLink>(.*?)</amazonLink>"&@LF, "") $xml = StringReplace($xml, @TAB, "") Return $xml EndFunc Func _XML2TreeView($xmlData) $hImg = _GUIImageList_Create(16,16, 5) _GUIImageList_AddIcon($hImg, "shell32.dll", 157) _GUIImageList_AddIcon($hImg, "shell32.dll", 137) _GUIImageList_AddIcon($hImg, "shell32.dll", 27) _GUICtrlTreeView_SetNormalImageList($tv, $hImg) $split = StringSplit($xmlData, @LF) For $i = 1 to $split[0] If stringleft($split[$i], StringLen("<album>")) = "<album>" Then $itemtxt=StringRegExp($split[$i],'<album>(.*?)</album>',1) $item = _GUICtrlTreeView_Add($tv, 0, _Clean($itemtxt[0]),0,0) ElseIf StringLeft($split[$i], StringLen("<item>")) = "<item>" Then $itemtxt=StringRegExp($split[$i],'<item>(.*?)</item>',1) _GUICtrlTreeView_AddChild($tv, $item, _Clean($itemtxt[0]),1) EndIf Next EndFunc Func _Export($format, $artist) $dg = FileSaveDialog("Save Discography", @ScriptDir, $format&" Files (*."&$format&")",16, $artist & "'s discography."&$format) If not @error And $artist<> "" Then Switch $format Case "txt" $text = _Discography($artist) $text = StringReplace($text, "<album>",@CRLF&"+") $text = StringReplace($text, "<item>", @CRLF&@TAB&">") $text = StringReplace($text, "<year>", " - ") $text = StringRegExpReplace($text, "<(.*?)>", "") FileClose(FileOpen($dg,2)) FileWrite($dg, _Clean($text)) Case "xml" FileClose(FileOpen($dg,2)) FileWrite($dg, _Clean(StringReplace(_Discography($artist), @LF, @CRLF))) Case "html" FileClose(FileOpen($dg,2)) $text = _INetGetSource("http://lyricwiki.org/api.php?func=getSong&artist="&StringReplace($artist, " ", "_")&"&song=&fmt=html") FileWrite($dg, $text) EndSwitch EndIf EndFunc Func _Clean($string) $string = StringReplace($string, "à ", "à") $string = StringReplace($string, "è", "è") $string = StringReplace($string, "ì", "ì") $string = StringReplace($string, "é", "é") $string = StringReplace($string, "ù", "ù") $string = StringReplace($string, "ò", "ò") $string = StringReplace($string, "'", "'") $string = StringReplace($string, "&", "&") return $string EndFunc
Note: this script isn't in any way related to the other Lyric Finder on the forums
it requires the itunes udf that can be found here




