Jump to content



Photo

Lyric Finder 2


  • Please log in to reply
3 replies to this topic

#1 torels

torels

    I Hacked 127.0.0.1! :D

  • Active Members
  • PipPipPipPipPipPip
  • 676 posts

Posted 25 March 2009 - 04:17 PM

Hi there
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 :D

AutoIt         
#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, "&amp;", "&")     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
Some Projects:indifference will ruin the world, but in the end... WHO CARES :P---------------http://torels.altervista.org







#2 ProgAndy

ProgAndy

    You need AutoItObject

  • MVPs
  • 2,508 posts

Posted 25 March 2009 - 05:14 PM

It looks really great.
And I have some imrovements for encoding issues:
AutoIt         
Func _FindLyrics($artist, $song)     If $song="" Then Return _Discography($artist)     $out = _INetGetSource("<a href='http://lyricwiki.org/api.php?func=getSong&artist=%22&$artist&%22&song=%22&$song&%22&fmt=text' class='bbc_url' title='External link' rel='nofollow external'>http://lyricwiki.org/api.php?func=getSong&artist="&$artist&"&song="&$song&"&fmt=text"</a>)     $out = StringReplace(_UTF8Decode($out), @LF,@CRLF)     Return $out EndFunc Func _Discography($artist)     $xml = _INetGetSource("<a href='http://lyricwiki.org/api.php?func=getSong&artist=%22&StringReplace($artist' class='bbc_url' title='External link' rel='nofollow external'>http://lyricwiki.org/api.php?func=getSong&artist="&StringReplace($artist</a>, " ", "_")&"&song=&fmt=xml")     Return _CleanXML($xml) EndFunc Func _CleanXML($xml)    ;this removes useless tags     $xml = _UTF8Decode($xml)     $xml = _HTMLDecode($xml)     $xml = StringReplace($xml, ... EndFunc Func _UTF8Decode($string)     ; Prog@ndy     Return BinaryToString(StringToBinary($string),4) EndFunc Func _HTMLDecode($string)     ; Prog@ndy     Local $data = StringRegExp($string,"&#(\d+);",3)     For $i = 1 To UBound($data)-1         $string = StringReplace($string,"&#" & $data[$i] & ";", Chr(Number($data[$i])),1)     Next     $string = StringReplace($string "&amp;", "&")     Return $string EndFunc

and remove you _Clean-Func
//Edit: if you won't use the iTunes-funcs it will work without itunes UDF.

Edited by ProgAndy, 25 March 2009 - 05:15 PM.

*GERMAN* Posted Image [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

#3 torels

torels

    I Hacked 127.0.0.1! :D

  • Active Members
  • PipPipPipPipPipPip
  • 676 posts

Posted 25 March 2009 - 07:00 PM

YES
I LIKE IT! :D

thanks alot

great functins
Some Projects:indifference will ruin the world, but in the end... WHO CARES :P---------------http://torels.altervista.org

#4 Beege

Beege

    Universalist

  • MVPs
  • 843 posts

Posted 05 September 2009 - 01:12 AM

Got some bad news. According to this letter, LyricWiki API is going away. Which makes this sweet script not work right anymore. :D




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users