Automation of music control in the office, any song to order via ICQ
I am an office employee. My workplace is an office, in which 6 people are sitting besides me. I have long been accustomed to the fact that music always plays in the background, with the exception of those work processes in which concentration is needed. Listening to music with headphones is somehow uncomfortable, and the head begins to hurt soon. Therefore, I always listened to her so that it was impossible for my "neighbors" not to hear her. They scolded me ... but scolded me not because I interfered with the music itself, but because I listened to the wrong music. Then I had a desire to please everyone so that everyone could, without getting up from their place, turn on any song, even one that is not on the computer.
Scheme
At first glance, automation should include the following features: the inclusion of any track from the network online, changing the track, adjusting the volume, the ability to pause playback and, accordingly, to pause, and it should also be possible to enable the track located locally on the computer. I am not really familiar with programming as such, except for reading the AutoIT manual (I always wanted to be able to automate any processes in Windows systems). A scheme immediately appeared in my head: AutoIT + ICQ + Foobar + Plugin for Foobar, which allows you to search and listen to music online from the VKontakte social network (its window is shown in the screenshot). The bottom line is simple: my colleagues send messages to a specific message, the AutoIT script picks them up and, in accordance with the message, performs manipulations with Foobar.
Implementation
Since when AutoIT is running, all the script manipulations are visible on the screen: opening windows, selecting a track, and so on, I initially planned to use a virtual machine for it, but, turning around, I saw an idle computer of a recently resigned employee and decided that there would be a “media center” for now he.
First of all, I registered a new ICQ account for the bot. Inventing a nickname for him did not take much time - "Remote". Then I installed QIP 8095 on the selected computer - I chose this client because the messages in it are stored as txt files. I set it up as follows: I turned off saving the history of service messages (that someone from the contact list entered the network or went out, etc.), also turned off all the sounds so that they would not distract colleagues from work. Then he installed Foobar with the necessary plugin and configured it to work with hot keys. And at the end he entered into the contact list of the bot himself and all the employees sitting with me in the office.
After completing all the preparatory work, I started writing the script itself. The principle of its operation is simple: every 2 seconds it must check the folder in which QIP stores the correspondence history for a txt file, if the file is located, it reads a message from it, deletes the history file itself and, in accordance with what was written in the message makes manipulations with Foobar'om.
What happened as a result
Script:
Func Terminate (); The function to turn off the script as it works in an endless loop
Exit 0
EndFunc
HotKeySet ("{ESC}", "Terminate"); Binds the shutdown function to the ESC keys
FileChangeDir ("C: Program FilesQIPUsersXXXXXXXXXHistory"); Changes the working directory
while 1; Begins an endless loop of script
$ Search = FileFindFirstFile ("*. Txt"); Searches for txt-files in the working directory and puts the return value of the search into the variable $ Search
if $ Search = -1 then; Checks for files by the contents of the variable
Sleep (1000); If no files are found, it waits a second and starts the
else loop first ; If a txt file is found, then ...
$ File = FileFindNextFile ($ Search);
$ Log = FileRead ($ File); Enters the contents of the file into the variable $ log
$ Log = StringSplit ($ Log, @LF); Since in QIP one message consists of three lines (marking the message as incoming or outgoing, author name / date / time of sending the message and the message itself), it makes an array from the variable in which each element is equal to one line
$ Mess = $ log [3]; The message itself enters into the variable $ Mess
FileDelete ($ File); Deletes the
MsgBox history file ("0", "", $ Mess, 1); For a second displays a message with the command that the script will now execute - this is implemented for debugging
WinActivate ('[REGEXPCLASS :(? I) {97E27FAA-C0B3-4b8e-A693-ED7881E99FC1}]'); It makes the Foobar window active, implemented by calling the class, since the player title changes depending on the composition
WinWaitActive ('[REGEXPCLASS :(? I) {97E27FAA-C0B3-4b8e-A693-ED7881E99FC1}]'); Waits for the Foobar window to become active
$ Check = StringInStr ($ Mess, "local"); Checks the occurrence of the word "local" in the message text
if $ Check = 1 then; If "local" is at the beginning of the message, then ...
$ Mess = StringTrimLeft ($ Mess, 6); "Cut off" the first 6 characters in the message (the word local and the subsequent space)
Send ("^ f"); Sends CTRL + F
WinWaitActive ('[REGEXPCLASS :(? I) {483DF8E3-09E3-40d2-BEB8-67284CE3559F}]'); We are waiting for the
Send track search window ($ Mess) to open ; Enters the contents of the
Sleep message (500) into the request ; Waits for half a second
Send ("{TAB}"); Sends a key press TAB
Sleep (500); Waiting for
Send ("{TAB}"); Sends a TAB key press (the window element in which the search result is displayed is made active)
Sleep (500); Waiting for
Send ("{DOWN}"); Sends a press of the DOWN key (the first track found by the search is highlighted)
Sleep (500); Waiting for
Send ("{ENTER}"); Includes the found track
Sleep (500); Waiting for
WinClose ('[REGEXPCLASS :(? I) {483DF8E3-09E3-40d2-BEB8-67284CE3559F}]'); Closes the search box.
continueloop; Returns to the beginning of the endless loop while
endif; If there is no word "local" at the beginning of the message, then the script continues reading from here ...
$ Stop = StringRegExp ($ Mess, "stop"); ... looks for the word "stop" in the message
$ VolUp = StringRegExp ($ Mess, "louder"); Searches for the occurrence of the word "louder" in the message
$ VolDown = StringRegExp ($ Mess, "quieter"); Searches for the occurrence of the word "quieter" in the message
$ VolMax = StringRegExp ($ Mess, "loud"); Searches for the occurrence of the word "loud" in the message
$ VolMin = StringRegExp ($ Mess, "quietly"); Searches for the word "quietly" in the message
if $ Stop = 1 then; If the word "stop" is sent, then ..
Send ("! X"); ...
continueloop; Returns to the beginning of the infinite loop while
endif
if $ VolUp = 1 then; If the word "louder" is sent, then ...
Send ("! {UP}"); ...
Send ("! {UP}"); ...
Send ("! {UP}"); ...
Send ("! {UP}"); ...
Send ("! {UP}"); 5 times presses the ALT + UP key combination, which slightly increases the volume of
continueloop; Returns to the beginning of the infinite loop while
endif
if $ VolDown = 1 then; If the word "louder" is sent, then ...
Send ("! {DOWN}"); ...
Send ("! {DOWN}"); ...
Send ("! {DOWN}"); ...
Send ("! {DOWN}"); ...
Send ("! {DOWN}");
continueloop; Returns to the beginning of the infinite loop while
endif
if $ VolMax = 1 then; If the word "loud" is sent, then ...
Send ("! C"); ... will send a key combination ALT + C, which turns on the maximum volume
continueloop; Returns to the beginning of the infinite loop while
endif
if $ VolMin = 1 then; If the word "quietly" is sent, then ...
Send ("! Z"); ... will send a key combination ALT + Z, which turns on the minimum volume (does not turn off completely)
continueloop; Returns to the beginning of the endless loop while
endif
; If not one of the standing ifs worked, then ...
Send ("^ q"); Sends the CTRL + Q keyboard shortcut, which is responsible for opening the Foobar plugin window, which searches for music in VKontakte
WinWaitActive ("vk.com audio Search"); Waits until the plug-in window becomes active
ControlCommand ("vk.com audio Search", "", "ComboBox1", "SetCurrentSelection", 6); From the drop-down list "In what services to look for" select vk.com (VK)
Sleep (500);
Waits for half a second ControlFocus ("vk.com audio Search", "", "Edit1"); Makes active the input line for the
Sleep request (500); Waiting for
Send ($ Mess); Sends the contents of the message from the QIP'a
Sleep (5000) to the input line ; It waits 5 seconds while the plugin searches for the track
while 1;
$ i = ControlListView ("vk.com audio Search", "", "SysListView321", "GetItemCount"); Enters into the variable $ i the number of tracks found
if $ i = 0 then; If no tracks are found (the plugin sometimes does not find results the first time)
ControlClick ("vk.com audio Search", "", "Button1"); Presses the button "Stop Search"
Sleep (500); Waiting for
ControlClick ("vk.com audio Search", "", "Button1"); Presses the button "Search"
Sleep (5000); Waiting for
exitloop; Exits the inner infinite while loop (always finds the second time)
else
exitloop; If you did not find it the first time, then most likely
ControlListView ("vk.com audio Search", "", "SysListView321", "Select", 1); Selects the second track from the search result (the first one often happens for some time 00:00 and does not play)
ControlClick ("vk.com audio Search", "", "Button3"); Adds a second
WinClose track to the playlist ("vk.com audio Search"); Closes the
WinWaitActive plug-in window ('[REGEXPCLASS :(? I) {97E27FAA-C0B3-4b8e-A693-ED7881E99FC1}]'); Waits until Foobar's window becomes active
Sleep (500); Waits for half a second
Send ("{END}"); Sends
Sleep (500); Waiting for
Send ("{ENTER}"); Sends a press of the ENTER key, which includes the
endif
wend track ;
How it works
Before you begin, you must add a local music library to Foobar’s playlist. If someone writes simply: “metallica fade to black”, then the script “finds” this song on VK and includes it. If someone wrote: “local joe satriani crowd chant”, then the script finds the track in its playlist, and then includes it. The following commands are also available: “quiet”, “loud”, “quieter”, “louder” and “stop”.
Conclusion
I did this for several hours and I know that the script is far from ideal, it has many flaws, for example: you should somehow shorten the code (you can probably replay command catching in the more correct way) or if a person with the word "local" asks for a track that if it’s not in the playlist, you need to look for it online and so on. I am not a programmer at all, so if it’s not difficult, write about errors in building the code, I will be grateful.