rcareno Posted February 13, 2017 Posted February 13, 2017 Hello All, I have a working script I use to load music into a website playlist togethertube.com. While not a perfect script, I'm hoping to get some feedback about how I could possibly clean up the code as if I expand my playlist to say 50 songs, the script is going to be very long. Here's the code: expandcollapse popup#include <Array.au3> sleep(5000) $z=0 Local $array[3] $array[0]= "slipknot wait and bleed" $array[1] = "Daft Punk - Harder, Better, Faster, Stronger" $array[2] = "Marilyn Manson - The Beautiful People" _ArrayShuffle($array) sleep(500) send($array[0]) sleep(3000) send ("{TAB}") sleep (200) send ("{TAB}") sleep (200) send ("{SPACE}") sleep (200) send ("{SHIFTDOWN}") sleep (200) send ("{TAB}") sleep (200) send ("{TAB}") sleep (200) send ("{SHIFTUP}") sleep (200) send ("{DELETE}") sleep(500) send($array[1]) sleep(3000) send ("{TAB}") sleep (200) send ("{TAB}") sleep (200) send ("{SPACE}") sleep (200) send ("{SHIFTDOWN}") sleep (200) send ("{TAB}") sleep (200) send ("{TAB}") sleep (200) send ("{SHIFTUP}") sleep (200) send ("{DELETE}") sleep(500) send($array[2]) sleep(3000) send ("{TAB}") sleep (200) send ("{TAB}") sleep (200) send ("{SPACE}") sleep (200) send ("{SHIFTDOWN}") sleep (200) send ("{TAB}") sleep (200) send ("{TAB}") sleep (200) send ("{SHIFTUP}") sleep (200) send ("{DELETE}") When you create a channel in togethertube, you have to start the script, then click into the "search box" and the script auto-fills the songs and adds them to the playlist. Any feedback welcome. I've used AutoIT a bit in the past, but I feel like my code is still "beginner" level. Thanks
david1337 Posted February 13, 2017 Posted February 13, 2017 (edited) Hi rcareno Instead of inserting the entire set of commands for every single array element, I would go through the array in a loop like this: #include <Array.au3> sleep(5000) $z=0 Local $array[3] $array[0]= "slipknot wait and bleed" $array[1] = "Daft Punk - Harder, Better, Faster, Stronger" $array[2] = "Marilyn Manson - The Beautiful People" _ArrayShuffle($array) For $i = 0 To UBound($array) -1 sleep(500) send($array[$i]) sleep(3000) send ("{TAB}") sleep (200) send ("{TAB}") sleep (200) send ("{SPACE}") sleep (200) send ("{SHIFTDOWN}") sleep (200) send ("{TAB}") sleep (200) send ("{TAB}") sleep (200) send ("{SHIFTUP}") sleep (200) send ("{DELETE}") Next Edited February 13, 2017 by david1337
rcareno Posted February 13, 2017 Author Posted February 13, 2017 David, Thanks so much for the feedback! Added the code and works like a charm, without having 300+ lines of code That's one thing I need to read more about is loop functions. rcareno
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now