push stream to mp3

Guiserver, GTK-server, OpenGL, PostScript,
HTML 5, MIDI, IDE
Locked
newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

push stream to mp3

Post by newdep »

a very quick hack ... ;-) but it works...

#!/usr/bin/newlisp
;;
;; save streaming music to local file.mp3
;; enjoy nodep (2) 2006
;;


;; some playlist..raw hack..
(setq playlist (read-file "http://www.garnierstreamingmedia.com/asx/kinkfm.pls"))
;; returns -> "[playlist]\r\nNumberOfEntries=1\r\nFile1=http://81.173.3.20:80/\r\n"
(regex "=http://(.*):(.*)/\r\n" playlist)
(setq link (net-connect (string $1) (int $2) ))

;; any playlist, thisone have no additional path, else add PATH to the GET
(net-send link "GET / HTTP/1.0\r\n")

;; ICY
(net-send link "Icy-MetaData,1\r\n\r\n")

;; semi streaming !
(while (net-peek link)
(net-receive link 'buff 8192) (append-file "x.mp3" buff))

;; need to press ctrl-c to stop this
(exit)


now play with winamp or xmms the x.mp3 file... enjoy..

[edited] now its working ;-)
-- (define? (Cornflakes))

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

thanks for the edit/corrections, now it works ;-), I added a little progress indicator:

Code: Select all

;; semi streaming !
(while (net-peek link)
    (print ".")
    (net-receive link 'buff 8192)
    (append-file "x.mp3" buff))
you could plug in one of your curses routines to make that even nicer

Lutz

newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post by newdep »

..I always liked these kind of indicators, from the old "DOS' days..



(setq indicator '( {|} {/} {-} {\} ))

;; a very raw hack!
(setq playlist (read-file "http://www.garnierstreamingmedia.com/asx/kinkfm.pls"))
(regex "=http://(.*):(.*)/\r\n" playlist)
(setq link (net-connect (string $1) (int $2) ))
(net-send link "GET / HTTP/1.0\r\n")
(net-send link "Icy-MetaData,1\r\n\r\n")

(while (net-peek link)
(print (first (rotate indicator)) "\027[D")
(sleep 200)
(net-receive link 'buff 8192) (append-file "x.mp3" buff))

(exit)
-- (define? (Cornflakes))

Locked