X-url: http://www.isi.edu/~johnh/ To: streamripper-general@lists.sourceforge.net Subject: patch to segment long streams MIME-Version: 1.0 (generated by SEMI 1.14.3 - "Ushinoya") Date: Sat, 09 Mar 2002 20:04:05 -0800 From: John Heidemann First, thanks for streamripper. It was exactly what I wanted to replace my old task of cassette-based radio recording. Attached is a patch for streamripper-1.0.5 adds a -S option to segment a stream into separate mp3's of a fixed length. This is very useful for streams that don't have embedded id3 tags. An example stream that lacks id3 tags is at http://www.kcrw.org/ (go to the simulcast in shoutcast format). Any chance of getting this patch in to the next release? -John Heidemann --- console/streamripper.c- Mon Aug 6 08:09:53 2001 +++ console/streamripper.c Thu Mar 7 13:16:42 2002 @@ -46,6 +46,8 @@ static BOOL m_dont_print = FALSE; RIP_MANAGER_OPTIONS m_opt; time_t m_stop_time = 0; +time_t m_segment_stop_time = 0; +time_t m_segment_count = 0; /* main() * parse the aguments, tell the rip_mananger to start, we get in rip @@ -84,8 +86,16 @@ if (m_stop_time && (temp_time >= m_stop_time)) { fprintf(stderr, "\nTime to stop is here, bailing\n"); + if (m_opt.segment_duration) + rip_manager_segment(m_segment_count, 0); break; } + if (m_opt.segment_duration && (temp_time >= m_segment_stop_time)) { + /* set up next timer */ + m_segment_stop_time = temp_time + m_opt.segment_duration; + rip_manager_segment(m_segment_count, m_segment_count+1); + m_segment_count++; + }; } m_dont_print = TRUE; @@ -226,7 +236,7 @@ fprintf(stderr, " -l - number of seconds to run, otherwise runs forever\n"); fprintf(stderr, " -q - add sequence number to output file\n"); fprintf(stderr, " -i - dont add ID3V1 Tags to output file\n"); - + fprintf(stderr, " -S - segment the stream into chunks of SECONDS\n"); } /* @@ -319,6 +329,10 @@ time(&m_stop_time); m_stop_time += atoi(argv[i]); break; + case 'S': + i++; + m_opt.segment_duration = atoi(argv[i]); + break; } } } --- lib/rip_manager.c- Thu Mar 7 11:40:13 2002 +++ lib/rip_manager.c Thu Mar 7 13:18:32 2002 @@ -57,6 +57,7 @@ * Public functions *****************************************************************************/ error_code rip_manager_start(void (*status_callback)(int message, void *data), RIP_MANAGER_OPTIONS *options); +void rip_manager_segment(int old, int new); void rip_manager_stop(); /****************************************************************************** @@ -272,6 +273,28 @@ debug_printf("done with ripthread()\n"); } +/* + * rip_manager_segment: + * terminate the current piece and put it in a segment + */ +void rip_manager_segment(int old, int new) +{ + char segment_name[MAX_TRACK_LEN]; + /* + * xxx: Note that the first time through end_track() + * actually fails (because we have the name wrong). + * We don't care. + * (IMHO the naming/layering here is not very clean... + * too many people know too much.) + */ + sprintf(segment_name, "%d", old); + end_track(segment_name); + if (new != 0) { + sprintf(segment_name, "%d", new); + start_track(segment_name); + }; +} + void rip_manager_stop() { debug_printf("just entered rip_manager_stop()\n"); --- lib/rip_manager.h- Thu Mar 7 11:28:03 2002 +++ lib/rip_manager.h Thu Mar 7 13:13:38 2002 @@ -57,6 +57,7 @@ u_short max_port; u_long maxMB_rip_size; u_short flags; + int segment_duration; } RIP_MANAGER_OPTIONS; typedef struct ERROR_INFOst @@ -67,6 +68,7 @@ extern error_code rip_manager_start(void (*status_callback)(int message, void *data), RIP_MANAGER_OPTIONS *options); +void rip_manager_segment(int old, int new); extern void rip_manager_stop(); extern char *rip_manager_get_error_str(int code); --- README- Sat Mar 9 19:59:11 2002 +++ README Sat Mar 9 20:00:41 2002 @@ -76,6 +76,12 @@ Once again, not sure why you wouldn't want this. Normally streamripper will be very aggressive and try to re-connect to a dropped stream, this disables that. +-l - Optional: how long to rip + +-S - optional: how long segements should be + +For flows without id tags (for example, see http://www.kcrw.org/'s simulcast), you can split it into seperate mp3 segments of a fixed length. + Bugs ~~~~ * mpglib has the annoying habit of calling exit(1) in the middle of code i don't understand. this will kill streamripper, this happens (rarely) usually on low bitrate streams.