Tuesday, 1 November 2011

Easy Ruby Media Player

I'm currently in the process of learning ruby due to a college module but one of the crap things about learning a new language is that most of the examples and short programs you write are so pointless. They don't really do anything or at least anything useful. So I decided to write something in ruby that I could actually use.

One of the local radio stations radio nova a rather awesome rock station just had a top 500 guitar songs of all time and published them on their website. Its a pretty good list of songs so I thought why not make a script to play a random song the list using ruby and youtube . Turns out its not that hard :


This just picks a random line in an inputed file searchs for it on youtube and opens the first link. I thought that was easy why not make something slight more useful lets give it the ability to to play multiple songs and skip songs. Another regex to get the length of the video and tell the thread to sleep for that length between songs. Then a second thread to take input from the command line and we are done :

There we have it my new media player at least until I get bored of the novelty of it and go back to a real one. Obviously this isn't the most advance ruby script ever but still it was nice to make my first multi-threaded ruby script and have it doing something relatively useful rather than turning on and off the light in an imaginary lighthouse. Hope this was helpful to others just starting off with ruby.






No comments:

Post a Comment