[ Swingley Development ] [ Jump to Content ]
animals baseball beer blog books bookbinding bread me other weather woodworking

Major League Baseball on Linux (or not. . .)

Christopher Swingley

2009 Regular Season: More hassles, good news

8-Apr-2009: Looks like MLB.com has upgraded their service and are no longer using the protocols that mlbviewer understands (they’re switching from JSP / JSON to XML / SOAP) so we’re presently out of luck for the 2009 season (just when I was really enjoying the DVR option for Gameday Audio…). The developers are working furiously on it, but the discussion so far doesn’t sound all that promising. There’s some serious reverse engineering required.

The good news is that MLB.com is abandoning Silverlight and Windows Media Format and have focused development on a better Flash player that does sound and video. I can't comment on the video part, but I had no trouble listening to yesterday's Giants game on Linux with the Flash player. I had to install the alpha Flash player (it's an x86_64 computer), but didn't have any issues. It's probably worth installing the Flashblock add-on to Firefox so the instability of the Flash player doesn't take down the browser serving up some stupid advertising. Maybe in another four years Adobe will release a stable version of Flash for 64-bit Linux.

A 2008 Solution

5-May-2008: Now there's a Linux (and OS X!) solution that doesn't require all the hacking of the previous attempts. Head over to the mlbviewer site and download the program. It's a python script that does everything you need in order to actually use the baseball subscription you've purchased from MLB.com. No browser hacks, no cutting and pasting long URLs. It's fantastic. A mini-HOWTO and some screenshots are at one of the developer's pages at: MLB.TV on Linux Mini Howto.

Many thanks to the developers for coming up with a nice, terminal based solution!

2008 Regular Season: Major hassles

3-Apr-2008: Well, that didn't take long. Christer Watson wrote a Greasemonkey script to automate the Firebug hack. You can find it at userscripts.org (if that link doesn't work, search for “MLB Linux” on the site). Thanks Christer!

1-Apr-2008: There's a work-around, which I heard about from Seth and Mike. Thanks guys! The page is: here. Basically, you install the firebug plugin, reload the MLB page (audio or video) and look for o.mURL=. The URL that shows up is passed to VLC and the stream will play. Dunno how hard it would be to write some sort of Greasemonkey script or full-on plugin, but it certainly seems possible.

31-Mar-2008: It looks like we're completely out of luck now. On my OS X laptop, the Flash plugin you get to when clicking on Gameday audio or MLB.tv link still offers the old Flash interface, as well as the new Silverlight version, and clicking on Flash does get you baseball. It appears that under Linux, the Flash page that starts up doesn't offer any options at all, and doesn't play the stream either. I'm fairly certain that this is due to Flash; either the page is doing something that Flash under Linux doesn't support (and we get a blank section, rather than the choices I saw on my Mac), or the Linux Flash player is identifying itself as a Linux player to MLB and they're rejecting us. I tried changing the User Agent to pretend my browser was IE 7 under Vista (shudder), but that had no effect.

2008 Spring Training Update: Silverlight!

It's only spring training, but it looks like Major League Baseball has really messed things up this year. When I clicked on an audio link in Firefox, I got a page explaining that my browser may not be supported by Microsoft Silverlight. Indeed…

For awhile I thought I was going to be out of luck. But if you click on the "Use old player" link, you get the Adobe Flash player from last year. Currently, on my AMD64 Linux system, I'm using a 32-bit browser (downloaded directly from Mozilla), with Adobe's Flash plugin, and the MediaPlayerConnectivity extension. That spawns VLC when it encounters Windows Media (which mlb.com uses), Real or Quicktime content.

Update for 2006

Well, as usual, the new season starts and Major League Baseball does it's best to keep me from listening to baseball despite paying for the priviledge. This year they've started requiring the Adobe Flash plug-in, and there is no Flash plug-in for Linux running on x86_64 systems. Not to mention all the other unsupported operating system and architecture combinations out there. They have also dropped Real Audio format, and only offer the games in Windows Media Format, further reducing their potential fan base.

The Flash plugin is available for Linux on i386 systems, and it does work with this configuration (see the April 3rd update below). You will probably want the flashblock Mozilla extension since Flash is used to deliver advertising on many web sites. Not only are all the noisy, animated ads annoying, but Flash can be unstable and inefficient, potentially crippling or killing your browser.

Mon Apr 3 13:13:01 AKDT 2006 -- Several people have reported success with i386 based Linux computers using the Flash and mplayerplug-ins. The trick is to log in to the MLB.com web site using the 'Register | Log In' link that appears at the top and bottom of the MLB.com pages. Once you've logged in, then click the audio stream links. A new page should pop up, Flash should load, and eventually the stream will start to play. One hint if you're still having trouble is to add debug=2 to your mplayerplug-in config file (/etc/mplayerplug-in.conf or ~/.mplayer/mplayerplug-in.conf). Then start up firefox from the command line and you can see what MPlayer is doing. This may help you diagnose potential problems. If the streams are taking a really long time to start playing, reduce the buffer cache size by adding cache=128 to the same file.

Thanks to Mike (K. and D.) and Jonathan for this information!

Tue Apr 4 06:49:37 AKDT 2006 -- OK, I've gotten everything working on my Debian AMD64 system by running a 32-bit Firefox in a chroot environment. The same techniques should work on other Linux distributions where you can't mix 32 and 64 bit packages on the same system (like Ubuntu). Here's how I did it:

Using this setup, here's how you listen to baseball.

Introduction

All Major League Baseball games can be listened to on the Internet by subscribing to MLB.com's Gameday Audio service. It's a bargain at $14.95. You get all the home and away broadcasts for all the games, and can listen to archived games from the past as well. There's only one problem with the service: the system requirements are restrictive. They only support Windows and Macintosh operating systems, and you need Flash 7.0 or higher. I run Linux on AMD64 so I've got two strikes against me. Hopefully Macromedia, err, Adobe, will release a Flash player for 64-bit Linux at some point.

Luckily, Linux is an open system and it isn't afraid to tell you what it's doing. With some open source software, and a little shell script hackery, it's possible to listen to baseball games on Linux. It's even possible to record games on your local system so you can listen to them however you want to listen to them. Here's how.

Listening to games

The first thing you'll need is the software to get to the games, and play the audio feeds. I'm running the Debian distribution of Linux, so you'll need the firefox, mplayer and mozilla-mplayer packages (on i386 the mozilla-mplayer package doesn't seem to exist anymore, so just install it manually according to the directions given above). If you're running Linux on a 32-bit platform, RealPlayer 10 may be the simplest solution [Update 2006 -- Not anymore] because it claims to have a mozilla compatible plug-in. But it only appears to be available for i386 platforms, so other architectures on Linux are out of luck.

After you've gotten your browser and mplayer working together, go to the MLB.com web page and click on the 'Register | Log in' link on the top (or bottom) and log in. Then go to the schedule, Multimedia guide or any of the other places audio streams appear on the site and click on a game link.

If you haven't already logged in, you'll have to sign in with your user name and password in the pop-up window. [Update 2006 -- the log in is reported not to work anymore from the pop-up window, so log in first if it doesn't work] After a few moments, you should see a little linescore for the game you have chosen, and on the left side of the pop-up is the media player, which should be spawning MPlayer in the background. If you wait long enough, the game will eventually start playing through this window.

There are a couple problems with playing the game through this pop-up. Browser plug-ins are children of the browser, so if anything happens to the browser, the children also disappear, interrupting your game. Also, when mplayer is running inside Firefox, you don't get the feedback that you get when it's running in a console window. But it is easy, so if that's what you're looking for, you're done!

What I do instead is wait until the URL appears in the pop-up window. Then run a very simple shell script, which finds the mplayer process from the process list, extracts the command from the /proc tree, and prints a reformatted command to standard output. Highlight, and then execute (middle mouse button) the command in a terminal window. Finally, close the pop-up window from Gameday Audio. Note: the Flash player is not very stable under Linux, and as I mentioned earlier, when it crashes, it has a tendency to take the browser down with it. Make sure you don't have anything vital in a browser window or tab before starting all of this because your browser instance may be murdered by Adobe Flash.

If you've enabled debugging in your mplayerplug-in, you can watch MPlayer load and connect to the stream. Look for the mms:// URL in the terminal window you used to start Firefox. As soon as you see MPlayer filling it's buffer (Cache fill: is what you're looking for) it's safe to grab the stream yourself, and then close the pop-up window.

The script is three lines:

You can also download a more sophisticated version that extracts the URL and asks you if you want to play the stream. Thanks to Reid R. for this enhancement! Just download or cut and paste these lines into a file, put it into your path, and make it executable (chmod 755 mlb_play.sh).

The second line is where the work is done. It reads the entire process list using the ps command. Then it looks for an mplayer process which is playing a mms:// URL. It grabs this process id, and examines the cmdline file from the process tree in the /proc directory. Finally, it does a few character replacements using tr and sed and prints the revised command.

At this point, your browser is back to normal (if it wasn't killed by Flash), and the terminal should be showing a whole bunch of mplayer output. At the bottom, you should see the audio stream being played, with various statistics about the stream.

I know it sounds more complicated that just relying on the mplayerplug-in for your platform, but being able to monitor the stream is useful, and getting this to work has other advantages, such as "recording" games.

Recording games for later listening

Another advantage of the command-line mplayer method for listening to baseball is that you can record games and listen to them later, or on a different device. I sometimes do this when I want to listen to a game at home, where I used to have a very slow dial-up connection. I can record a game at work, store it on a flash drive, and then play the game at home from the flash drive instead of tying up my telephone line for three hours. Podcast baseball to yourself!

Note: Recording games in this way may be a violation of the user agreement you clicked through when you signed up to Gameday Audio. Major League Baseball owns the accounts and descriptions of the games, and you certainly cannot retransmit, sell, or your recordings publically. It looks like MLB.com will be "selling" games in the future for $3.95 per game ("Don't just watch the game, Own It!"), so the ability to record games in the manner I'm describing appears to conflict with this new revenue stream. Welcome to the future, folks!

To record a game, you follow the same procedure as above, clicking on a game, waiting for the mms:// to appear in the terminal, running the shell script, and then closing the pop-up window.

But instead of running the command that's printed, which will play the stream using mplayer, cut the mms:// URL from the command, and use the following command instead:

Paste the URL where it says "mms://...", and you probably want to change the name of the file at the end of the command to reflect the game you're recording.

We're not downloading the game (even for archived games), we're "playing" the game into a file. So this process will take however long the game takes. When the game is over, the command will exit and you'll have a WAV file that contains the game. I prefer to encode this as an OGG file, which will reduce it's size significantly. You could also convert the game into an MP3 and play it on a portable MP3 player. Just remember that MP3 is a patented format, and you are only allowed to generate MP3 files with a licensed MP3 encoder. OGG has no such limitations.

I use this command to downmix, resample, and convert the WAV file:

The --downmix option reduces the two-channel file into a mono recording. The games I've listened to aren't in stereo anyway, so we're not losing anything by doing this. The --resample 6000 will resample the file to further reduce the size. The quality of the recording is also reduced, so you may want to try other values for this parameter, or omit it altogether. A value of 6000 reduces the quality to what a bad AM radio sounds like -- you can easily understand everything, but it doesn't sound very good.

Fellow baseball listener and Linux user Jacob Heider put all of this together into a script that will grab the stream from the MLB pop-up window, record and encode the game, and send you email when it is finished. It's a nice piece of work. Download mlb_record.sh and replace email address on line 11 with your email address. To use it, click on a game, and wait for the mms:// to appear in the terminal window. Then run the script as follows (substituing whatever name you want for the output file):

When the script finishes (several hours later) it'll convert ana_oak_11_aug_05.wav to ana_oak_11_aug_05.ogg and send you an email message to tell you it's finished.

Thanks Jacob!

Video

I don't have the bandwidth at home to try MLB TV, but I have figured out how to get video highlights to play under Linux. If MLB TV uses the same delivery method, this might allow you to watch video of the games (with a subscription, of course). [Update 2006 -- These same methods do work for MLB TV. Several people have written me to say they have gotten it to work on their Linux systems.]

We're using the same setup I discussed earlier, which involves getting the Flash plugin running, and installing and configuring the mplayerplug-in to play content through MPlayer. Once you have that all set up and working for the audio streams, make the following changes to your ~/.mplayer/mplayerplug-in.conf to try out video:

The videos require a lot more buffering, and they will barely be watchable if you leave the cachsize setting at 128. The noembed=1 tells MPlayer not to try to embed the video into the pop-up, but play it in it's own window. Something about the MLB.com pop-up window confuses MPlayer, but it plays outside of the window just fine.

Once the video is loading, you can use the same command-line techniques that I've shown for the audio streams. You can use the same mlb_play.sh script to grab the stream URL and play the stream from the command line (although you should change the -cache 128 setting to -cache 8192), and you can even "record" the video onto your hard drive. Note that if you're running an AMD64 system, you will need to enter the i386 chroot before playing or recording the video stream from the command line. The video codec MLB.com uses isn't available in the 64-bit version of MPlayer.

I used the following command to "record" one of the post-game video clips from an April 6, 2006 game:

replacing the mms://. . . with the actual URL harvested from the process tree. The quality of this particular encoding isn't all that great, but there are a lot of different video codecs to choose from with mencoder and I'll bet some of them will produce video at the same quality that you watch it directly from MLB.com.

Conclusion

If you have more information about playing Gameday Audio under Linux on your system, please drop me a line and let me know how you do it. I would be happy to include your comments and experiences on this page so Linux users can enjoy baseball just like everyone else.

Enjoy the games!

[ Page last updated 4-Apr-2009 ]