Tag Archive for mpd

Twilio, Debian Packaging, Community Driven Radio, Pastebin Messaging, Python sh module, and more

The Dead Coder Society had its first meeting with our newest members. This meeting’s content was provided solely by the new members.

Peter Sandin was up first with his Debian Packaging presentation. He overviewed the process of packaging software in Debian and the various ways it can be done.

Tim Heckman followed Pete with two presentations. He discussed using Twilio, Python’s Flask web framework, and Python’s Paramiko library to interact with his network remotely from his cell phone. He also went over his IRC-related project to use Twilio to inform him of chat lines that interest him from irssi.

Nick Pegg continued the presentations by going over NickFM, a community-driven web radio project he has been working on. He combined Icecast, MPD, and custom Python code in order to create a digital station that allows for multiple remote DJs. Dead Coder Society member Brian O’Keefe posted a series on using Icecast for projects in the past as well: http://www.deadcodersociety.org/blog/building-a-streaming-radio-station-part-1-icecast-mpd-and-python/

Trevor Parker presented his idea of a pastebin-based system for decentralized, encrypted, and persistent message storing.

Les Aker brought the talks to a close with a presentation on Python’s sh module, which allows for system commands to be run in a pythonic fashion. The sh module integrates nicely with his soon-to-be finished automatic deployment system, Archer.

Cheers to the Dead Coder Society!

 

Building a Streaming Radio Station, Part 1: Icecast, MPD, and Python

I run an anonymous message board for Stockton College – stkbuzz.com. It’s fairly active, and due to the nature of the site, it gets some pretty amazing posts. I had the idea of recording dramatic readings of some select posts, but the problem was that I didn’t have a good way of delivering audio content to my audience. After bouncing some ideas off of my co-workers, I decided that the best way of doing so would be via an online streaming radio station, accessible from a player embedded into the bottom of the website – enter stk.fm, the Buzz.

Icecast and MPD

I researched my options for streaming audio in a radio-like fashion, and it seemed like Shoutcast and Icecast were the two most popular. After previously having a less-than-stellar experience with Shoutcast, I decided to give Icecast a shot. I’m happy to report that so far, it’s working great – I haven’t had a single problem with it yet.

I planned the “structure” of the content that would be played fairly early on. The structure looked something like this:

  • An intro segment (sometimes known as a radio bump)
  • A talk segment (such as a dramatic reading)
  • Another bump
  • Either one or two songs
  • Repeat!

This would obviously require a rather fine-grained level of control. The nice thing about Icecast is that it can use MPD as an audio source. MPD (Music Player Daemon) is, as the name might suggest, simply a daemon that plays music from a library. It doesn’t play music directly, however; it acts as a server which requires a client. In this case, Icecast is our client (this was incredibly easy to configure). Icecast streams whatever the source gives it, and since we can control MPD directly, we can essentially control Icecast directly.

Serving Content

The next step was to automate adding tracks to the MPD playlist. I wrote a Python script that acts as a DJ, playing tracks in the structure I originally settled on. The script does the following:

  • First, it looks at a set of directories that I’ve specified and generates a “segment” for each MP3 it finds – a segment simply being an ordered list of MP3s that will be added to the MPD playlist. Typically, a segment will consist of a randomly chosen bump, followed by the content. However, I built in a simple regex check that looks at the filename of the content and can prepend or append specific bumps (for example, any filename that begins with the string “read_” is a dramatic reading, and should therefore always be prepended by the bump that says “and now, a dramatic reading…”).
  • After the segments are generated, they are dumped into a pool with segments of their own type (talk or music) to be later pulled out and copied into the MPD playlist when MPD is playing the last song in the list (from within Python, I used MPC to interact with MPD). At that point, the segment is put into a queue and will be placed back into the pool of playable content after a certain number of other segments have been played (this allows for the content to be continuously shuffled).

 

Part 2 of this blog post will cover the client side player as well as streaming analytics. For now, you can check out stk.fm on stkbuzz.com!