Possibly not spam ramblings and links from the edge of the universe

15Nov/111

LadioCast automation (AppleScript)

Playing music is fun, LadioCast is an awesome tool that lets you broadcast ANY audio from your soundcard to an icecast server. It also lets you mix from multiple sources. Being a simple tool it doesn't grab it's own metadata info or anything fancy like that. There are several common ways to update this info and they're covered other places online. Below I've included my own ladiocast_update script that adds a bit extra to the metadata mix.

Sometimes you want to play a stream for a bit and then drop offline cleanly, but you don't want to hang around to wait for it to finish (sleep is awesome once or twice a month).

Through the magic of AppleScript you can do this. [We can have platform debates later, my whole broadcast kit is in osx right now, get over it.]

This script queries iTunes for the current state (playing, paused, stopped). If the stream is seen playing or paused it updates the metadata in ladiocast with the info from the currently playing track. If it finds that it has stopped it plays the "radio off" playlist (used to give a sign-off message), waits a little bit (for the message to finish) and then kills the stream.

ladiocast_update

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
set lastName to ""
set lastArtist to ""
set lastAlbum to ""
set currentState to ""
 
tell application "iTunes"
	repeat
		set currentState to player state
		if currentState is stopped then
			play playlist "radio off"
			delay 10
			tell application "LadioCast"
				disconnect 1
			end tell
			exit repeat
		else
			set trackName to name of current track
			set trackArtist to artist of current track
			set trackAlbum to album of current track
 
			if trackName is not lastName or trackArtist is not lastArtist or trackAlbum is not lastAlbum then
				set lastName to trackName
				set lastArtist to trackArtist
				set lastAlbum to trackAlbum
 
				tell application "LadioCast"
					set metadata song to trackArtist & " - " & trackName
				end tell
			end if
		end if
		delay 15
	end repeat
end tell

Posted by dracoling

Comments (1) Trackbacks (1)
  1. Hi there…

    I am trying to use the MegaSeg playout system with LadioCast but I know virtually nothing about AppleScript so hardly surprisingly I am having trouble scripting the necessary elements.

    MegaSeg places the now playing data in a continually-updated text file called "NowPlaying" which contains the required information prefixed by the field name and a colon. I am trying to read that data into the three required variables for Title, Artist and Album

    The following script seems to get the appropriate bits into the appropriate variables when I Run it in the Editor, but set in the LadioCast "Event Handler" it fails with an EOF -37 error. In addition as soon as you read the file it stops being updated – ever. I wonder if I am using the wrong method to read it and it becomes locked from the original application writing to it?

    I'd be very happy to pay someone to help sort this out, so if you have any suggestions, please drop me a line. Here's my current (fatally flawed) script:

    set lastName to ""
    set lastArtist to ""
    set lastAlbum to ""
    set lastTime to ""
    set trackName to ""
    set trackArtist to ""
    set trackAlbum to ""
    set sourcePath to ""

    repeat

    set sourcePath to open for access file "Library:MegaSeg User Data:Logs:Logs for MegaSeg System (4):NowPlaying"
    set thisText to read sourcePath as text
    close access sourcePath

    set the paragraphList to every paragraph of thisText

    repeat with i from 1 to number of items in paragraphList
    set thisItem to item i of paragraphList

    if thisItem starts with "Title:" then

    set x to the offset of "Title:" in thisItem
    set trackName to (text (x + 6) thru -1 of thisItem)

    else if thisItem starts with "Artist:" then
    set x to the offset of "Artist:" in thisItem
    set trackArtist to (text (x + 7) thru -1 of thisItem)

    else if thisItem starts with "Album:" then
    set x to the offset of "Album:" in thisItem
    set trackAlbum to (text (x + 6) thru -1 of thisItem)

    end if

    end repeat

    if trackName is not lastName and trackArtist is not lastArtist and trackAlbum is not lastAlbum then
    set lastName to trackName
    set lastArtist to trackArtist
    set lastAlbum to trackAlbum
    tell application "LadioCast"
    set metadata song to trackName & " – " & trackArtist & " – " & trackAlbum
    end tell
    end if
    delay 15

    end repeat


Leave a comment