Jump to content

Lyric Finder 2


torels
 Share

Recommended Posts

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

#include <INet.au3>
#include <GuiConstantsEx.au3>
#include <StaticConstants.au3>
#include <GuiTreeView.au3>
#include <GuiStatusBar.au3>
#include <File.au3>
#include <iTunes.au3>
$copyright = "Copyright (C) 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:[list][*]ZIP UDF using no external files[*]iPod Music Transfer [*]iTunes UDF - fully integrate iTunes with au3[*]iTunes info (taskbar player hover)[*]Instant Run - run scripts without saving them before :)[*]Get Tube - YouTube Downloader[*]Lyric Finder 2 - Find Lyrics to any of your song[*]DeskBox - A Desktop Extension Tool[/list]indifference will ruin the world, but in the end... WHO CARES :P---------------http://torels.altervista.org

Link to comment
Share on other sites

It looks really great.

And I have some imrovements for encoding issues:

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(_UTF8Decode($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 = _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

*GERMAN* [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

Link to comment
Share on other sites

YES

I LIKE IT! :D

thanks alot

great functins

Some Projects:[list][*]ZIP UDF using no external files[*]iPod Music Transfer [*]iTunes UDF - fully integrate iTunes with au3[*]iTunes info (taskbar player hover)[*]Instant Run - run scripts without saving them before :)[*]Get Tube - YouTube Downloader[*]Lyric Finder 2 - Find Lyrics to any of your song[*]DeskBox - A Desktop Extension Tool[/list]indifference will ruin the world, but in the end... WHO CARES :P---------------http://torels.altervista.org

Link to comment
Share on other sites

  • 5 months later...

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

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...