Download & Extend

Archive files are truncated / missing - StreamRipper fixes

Project:Station
Version:6.x-2.0-beta3
Component:Archive
Category:support request
Priority:normal
Assigned:Unassigned
Status:postponed (maintainer needs more info)

Issue Summary

Hi,

We have been running the drupal station radio module for several years and over the course of this have noticed that sometimes the archive files are either missing or truncated.

Issue number 1: Truncated archives

After some investigation, it looks like streamripper is to blame. Even though in ripper.php you specify "-a" which according to streamripper manpage means "Rip to single file" - if the stream source ever drops out (usually due to a flaky internet connection) it will cause streamripper to re-buffer and it will close and re-open the file pointer back at the beginning and everything it ripped so far will be lost!

You can see this in /lib/filelib.c:1029:

*fp = open (fn, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);

To fix this, we just patch streamripper to continue where it left off instead of zeroing out the file. Luckily, this is an easy fix, all you have to do is add the flag "O_APPEND" into the fopen statement.

Here is a patch that works on streamripper 1.62.0. I told the streamripper people about this, but they either didn't care or didn't notice, so I post this here in the hopes that it might help other people with their archiving issues.

--- streamripper-1.62.0.orig/lib/filelib.c   Sat May 19 10:03:13 2007
+++ streamripper-1.62.0.new/lib/filelib.c       Wed Mar 10 15:07:07 2010
@@ -1026,7 +1026,7 @@
     /* For unix, we need to convert to char, and just open.
        http://mail.nl.linux.org/linux-utf8/2001-02/msg00103.html
     */
-    *fp = open (fn, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+    *fp = open (fn, O_APPEND | O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
     if (*fp == INVALID_FHANDLE) {
        /* GCS FIX -- need error message here! */
        // printf ("ERROR creating file: %s\n",filename);

Issue #2: Lost archives

Another issue we had with streamripper is that if cron starts it up while there is NO source on the server it will get a 404 error and then fail out. To prevent lost archives due to our remote djs not streaming in on time, we made a little "check the ripper" script that runs every 5 minutes and starts up the ripper if it's not running.

#!/usr/local/bin/bash

isrunning=` ps -auxw | grep radio | grep -v grep | grep -c 'streamripper' `


if [ $isrunning -gt 0 ]
        then
        exit 0
        else
        echo restarting ripper..
        /home/radio/rip.sh >>/home/radio/rip.log 2>/dev/null
fi

Comments

#1

Title:Acrhive files are truncated / missing - FIX» Archive files are truncated / missing - StreamRipper fixes
Category:bug report» support request

Since I'm not supporting that code I'm going to re-categorize this as support. It's good info for anyone else, thanks for submitting it.

#2

Suggestion - put this in the documentation for the Archive module perhaps as a "trick" to get smoother archives?

Edit - posted it as a comment. I figure it'll get more visibility there.
http://drupal.org/node/85842#comment-3192848

#3

Status:active» postponed (maintainer needs more info)