Posts tagged ‘Amarok’

I recently discovered how easy it is to write scripts for Amarok.

I listen to an online radio show daily and, because my operating system is Ubuntu and I want to use Amarok to play the Real Audio streams for the radio show, I have to download a file called stream.cgi daily which contains the stream URLs for the show and then add them manually to Amarok.

I was getting tired of continually having to manually add the stream URLs to Amarok each day when wanting to listen so I wrote a Python script to parse the stream.cgi file and add the stream URLs to Amarok. I then created a launcher for the script so now I can just drag the stream.cgi file onto the launcher and it spawns the script which parses the file and adds the streams to Amarok. Yay.

Script (Python 2.5.2) for Amarok 1.4:

#! /usr/bin/env python
# Description:
# 	Script to parse an input file full of stream URLs, typically named "stream.cgi", and
#	add all those URLs from the input file to the Amarok playlist
# Author:	Patrick O'Leary AKA Mulchman
# Date:	March 5, 2009

import os, sys

print("#\n# Amarok Stream Import Script\n#\n")

# Strip off script name
args = sys.argv[1:]

# Verify there are some input files
if (len(args) < 1):
	sys.exit("Error: no input files supplied!")

# Loop through list of input files and pull out the URLs and send them to Amarok
for arg in args:
	if (os.path.exists(arg)):
		infile = open(arg, "r")
			for line in infile.readlines():
				stripLine = line.strip()
				if (len(stripLine) > 0):
					execute = "dcop amarok playlist addMedia \"%s\"" % stripLine
		print("Warning: Skipping invalid input file: \"%s\"" % arg)