Last active
August 29, 2015 14:01
-
-
Save dawehner/99e1e2190445efa3e1bb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import random | |
import os | |
import argparse | |
import requests | |
import xml.etree.ElementTree as ET | |
def get_all_songs(): | |
result = requests.get("http://www.musicforprogramming.net/rss.php") | |
songs = [] | |
for item in ET.fromstring(result.content).find('channel').findall('item'): | |
songs.append(item.find('guid').text) | |
return list(reversed(songs)) | |
parser = argparse.ArgumentParser() | |
parser.add_argument('--init_song', dest='song', type=int, default=None, ) | |
args = parser.parse_args() | |
# Let the songs begin! | |
songs = get_all_songs() | |
song = songs[args.song-1] if args.song is not None else random.choice(songs) | |
while True: | |
print "Playing {}".format(song) | |
# TODO: Allow to break the script using ctrl+c | |
os.system("mplayer {} 1>/dev/null 2>/dev/null".format(song)) | |
song = random.choice(songs) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment