I tend to listen to music on the radio while I am at my desk on the computer, so I have been working on this script to download the Now Playing information from the
YES.com API, and display it in a nice way (GUI) so that I know what is on the radio. Should I like the song, I can actually know what it is.
Script Functions:
Code:
*Can enter own station in edit box
*downloads all needed files. (or are #included in the case of xpath
*ability to search for song on IMEEM
*GUI, ability to hide and show it, via tray Menu
*other GUI tab shows the last three songs that were played
*IMEEM is opened in default browser to find more info about song or download
*clicking on the picture will open up a SplashImage letting you see it bigger.(for ~5 seconds)
*creates a _RadioCache directory in the %A_ScriptDir% to store the album art it downloads.
*tray menu:
* Refresh Data
* Hide GUI
* Show Gui
* Find Station (finds the first 5 local radio stations within 60 miles)
* Exit Program
Requires:
Titan's xpath for reading XML found
HERE put in as an #Include
I am not that good at AHK, so the main thing I would like to do with this script is to speed it up a bit. I know it is limited by the UrlDownloadToFiles and all the XML reads from Titan's xpath.
Source:
Code:
;-------------------------------------------------------
; Version: 1.0.47.6
; Language: English
; Platform: Windows XP (SP3)
; Author: Mark Repka {repkam09@gmail.com}
;-------------------------------------------------------------
#Include xpath.ahk ;thanks to Titan for this!
#NoEnv
#SingleInstance FORCE
SendMode Input
CoordMode, Mouse, Screen
CoordMode, Pixel, Screen
;create the scripts directory to store stuff.
IfNotExist, %A_ScriptDir%\_RadioCache\
{
FileCreateDir,%A_ScriptDir%\_RadioCache\
}
IfExist, %A_ScriptDir%\_RadioCache\
;Script GUI and startup stuff.
GUISizeW := A_ScreenWidth-280
GUISizeH := A_ScreenHeight-300
StationNameShort = WZNE
;create menu
Menu,Tray, NoStandard
Menu, Tray, add, Refresh Data, GetInfo
Menu, Tray, add, Find a Station, FindStation
Menu, Tray, add,
Menu, Tray, add, Hide GUI, HideGUI
Menu, Tray, add, Show GUI, GUICreate
Menu, Tray, add,
Menu, Tray, add, Exit Program, ExitProgram
;main info download and parse routine.
GetInfo:
UrlDownloadToFile,http://api.yes.com/1/station?name=%StationNameShort%&type=xml, B.xml
xpath_load(xmlfile, "B.xml")
SongName_Before := xpath(xmlfile, "/api/array/song/text()")
StationNameLong_Before := xpath(xmlfile, "/api/desc/text()")
StationNameShort := xpath(xmlfile, "/api/name/text()")
ArtistName := xpath(xmlfile, "/api/array/artist/text()")
GenreInfo := xpath(xmlfile, "/api/genre/text()")
FileDelete, B.xml
UrlDownloadToFile,http://api.yes.com/1/recent?name=%StationNameShort%&max=3&type=xml,A.xml
xpath_load(xmlfile, "A.xml")
play1 := xpath(xmlfile, "/api/array/songs[1]/title/text()")
StringReplace, play1, play1,',',All
play2 := xpath(xmlfile, "/api/array/songs[2]/title/text()")
StringReplace, play2, play2,',',All
play3 := xpath(xmlfile, "/api/array/songs[3]/title/text()")
StringReplace, play3, play3,',',All
artist1 := xpath(xmlfile, "/api/array/songs[1]/by/text()")
artist2 := xpath(xmlfile, "/api/array/songs[2]/by/text()")
artist3 := xpath(xmlfile, "/api/array/songs[3]/by/text()")
art1 := xpath(xmlfile, "/api/array/songs[1]/cover/text()")
art2 := xpath(xmlfile, "/api/array/songs[2]/cover/text()")
art3 := xpath(xmlfile, "/api/array/songs[3]/cover/text()")
FileDelete, A.xml
UrlDownloadToFile,%art1%,%A_ScriptDir%\_RadioCache\song1.jpg
UrlDownloadToFile,%art2%,%A_ScriptDir%\_RadioCache\song2.jpg
UrlDownloadToFile,%art3%,%A_ScriptDir%\_RadioCache\song3.jpg
StringReplace, SongName, SongName_Before,',',All
StringReplace, StationNameLong, StationNameLong_Before,',',All
;create the actual GUI
GUICreate:
GUI, 1:Destroy ;destroy it if refreshing data.
GUI, +ToolWindow ;smaller title bar and no tastkbar button thing
Gui, Font, s10 bold, Verdana
Gui, 1:Add, Tab, x-4 y-3 w300 h270 , Now Playing|Recent Songs ;create tabs
Gui, 1:Add, Edit, x6 y27 w140 h30 , %StationNameShort%
Gui, 1:Add, Button, x156 y27 w100 h30 gButtonPress , Get Info
Gui, 1:Add, Text, x6 y67 w260 h130 , Station: %StationNameLong% (%StationNameShort%)`nNow Playing:`n`nSong: %SongName%`nArtist: %ArtistName%`n`nGenre: %GenreInfo%
Gui, 1:Add, Button, x6 y207 w130 h30 gIMEEM , Search On Web
Gui, 1:Add, Picture, x176 y157 w90 h90 gClickOnPic, %A_ScriptDir%\_RadioCache\song1.jpg ;picture on first tab, click to view large
Gui, Tab, Recent Songs
Gui, 1:Add, Picture, x6 y27 w70 h70 , %A_ScriptDir%\_RadioCache\song1.jpg
Gui, 1:Add, Text, x86 y27 w180 h70 , Song: %play1%`nArtist: %Artist1%
Gui, 1:Add, Picture, x6 y107 w70 h70 , %A_ScriptDir%\_RadioCache\song2.jpg
Gui, 1:Add, Text, x86 y107 w180 h70 , Song: %play2%`nArtist: %Artist2%
Gui, Tab, Recent Songs
Gui, 1:Add, Picture, x6 y187 w70 h70 , %A_ScriptDir%\_RadioCache\song3.jpg
Gui, Tab, Recent Songs
Gui, 1:Add, Text, x86 y187 w180 h70 , Song: %play3%`nArtist: %Artist3%
Gui, 1:Show, x%GUISizeW% y%GUISizeH% h260 w278, %StationNameLong%
Return
1GuiClose:
GuiClose:
GUI, Destroy
Return
;you pressed the button....
ButtonPress:
ControlGetText, StationNameShort, Edit1, %StationNameLong%
WinGetPos,XVar, YVar
Goto, GetInfo
IMEEM:
MsgBox,36,Are You Sure?, Are you sure you want to open a web browser`nand search for the song `"%SongName%`"`n on Imeem?
IfMsgBox, No
{
Return
}
IfMsgBox, Yes
String1 = artist:%ArtistName%title:%SongName%
StringReplace,String1,String1,%A_Space%,`%20,all
run, http://www.imeem.com/tag/?f=music&q=%String1%
HideGUI:
IfWinExist,%StationNameLong%
{
GUI, Destroy
Return
}
Else
Return
ExitProgram:
GUI, Destroy
FileRemoveDir, %A_ScriptDir%\_RadioCache\, 1
ExitApp
FindStation:
GUI, Destroy
InputBox, ZipCode, Search for a Station:, Zip Code:,,200, 120,,
URLDownloadToFile,http://api.yes.com/1/stations?loc=%ZipCode%&type=xml,local.xml
sleep, 400
xpath_load(xmlfile, "local.xml")
;-----------------------------------------
Station_Short_1 := xpath(xmlfile, "/api/array/stations[1]/name/text()")
Station_Long_1 := xpath(xmlfile, "/api/array/stations[1]/desc/text()")
StringReplace, Station_Long_1,Station_Long_1,apos;,`,all
;-----------------------------------------
Station_Short_2 := xpath(xmlfile, "/api/array/stations[2]/name/text()")
Station_Long_2 := xpath(xmlfile, "/api/array/stations[2]/desc/text()")
StringReplace, Station_Long_2,Station_Long_2,apos;,`,all
;-----------------------------------------
Station_Short_3 := xpath(xmlfile, "/api/array/stations[3]/name/text()")
Station_Long_3 := xpath(xmlfile, "/api/array/stations[3]/desc/text()")
StringReplace, Station_Long_3,Station_Long_3,apos;,`,all
;-----------------------------------------
Station_Short_4 := xpath(xmlfile, "/api/array/stations[4]/name/text()")
Station_Long_4 := xpath(xmlfile, "/api/array/stations[4]/desc/text()")
StringReplace, Station_Long_4,Station_Long_4,apos;,`,all
;-----------------------------------------
Station_Short_5 := xpath(xmlfile, "/api/array/stations[5]/name/text()")
Station_Long_5 := xpath(xmlfile, "/api/array/stations[5]/desc/text()")
StringReplace, Station_Long_5,Station_Long_5,apos;,`,all
;-----------------------------------------
FileDelete, local.xml
MsgBox, Local Stations within 60 miles of %ZipCode%`n`nName: %Station_Long_1%`nCode: %Station_Short_1%`n`nName: %Station_Long_2%`nCode: %Station_Short_2%`n`nName: %Station_Long_3%`nCode: %Station_Short_3%`n`nName: %Station_Long_4%`nCode: %Station_Short_4%`n`nName: %Station_Long_5%`nCode: %Station_Short_5%
Goto, GUICreate
ClickOnPic: ;opens the album art in a larger version in a splashtext window for 5 seconds.
SplashImage,%A_ScriptDir%\_RadioCache\song1.jpg,ZH300 ZW300,(Window will close in 5 seconds)
Sleep, 5555
SplashImage, off
return
Hope someone can find this useful or interesting! I learned a lot making it. This is the most complex script I have ever made, thats for sure!
Comments and suggestions are always nice!
