Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Some time ago in a sample code in the active state website i saw someone played and recorded a MP3 file using VLC using the vlc.py module. You can take a look at it's sample code to see how to duplicate a stream. I copied th code here for you (I copied it from <a href="http://code.activestate.com/recipes/577802-using-vlcpy-to-record-an-mp3-and-save-a-cue-file/" rel="nofollow">http://code.activestate.com/recipes/577802-using-vlcpy-to-record-an-mp3-and-save-a-cue-file/</a>):</p> <pre><code>import vlc import time import os def new_filename(ext = '.mp3'): "find a free filename in 00000000..99999999" D = set(x[:8] for x in os.listdir('.') if (x.endswith(ext) or x.endswith('.cue')) and len(x) == 12) for i in xrange(10**8): s = "%08i" %i if s not in D: return s def initialize_cue_file(name,instream,audiofile): "create a cue file and write some data, then return it" cueout = '%s.cue' %name outf = file(cueout,'w') outf.write('PERFORMER "%s"\n' %instream) outf.write('TITLE "%s"\n' %name) outf.write('FILE "%s" WAVE\n' %audiofile) outf.flush() return outf def initialize_player(instream, audiofile): "initialize a vlc player which plays locally and saves to an mp3file" inst = vlc.Instance() p = inst.media_player_new() cmd1 = "sout=#duplicate{dst=file{dst=%s},dst=display}" %audiofile cmd2 ="no-sout-rtp-sap" cmd3 = "no-sout-standard-sap" cmd4 ="sout-keep" med=inst.media_new(instream,cmd1,cmd2,cmd3,cmd4) med.get_mrl() p.set_media(med) return p, med def write_track_meta_to_cuefile(outf,instream,idx,meta,millisecs): "write the next track info to the cue file" outf.write(' TRACK %02i AUDIO\n' %idx) outf.write(' TITLE "%s"\n' %meta) outf.write(' PERFORMER "%s"\n' %instream) m = millisecs // 60000 s = (millisecs - (m*60000)) // 1000 hs = (millisecs - (m*60000) - (s*1000)) //10 ts = '%02i:%02i:%02i' %(m,s,hs) outf.write(' INDEX 01 %s\n' %ts) outf.flush() def test(): #some online audio stream for which this currently works .... instream = 'http://streamer-mtc-aa05.somafm.com:80/stream/1018' #if the output filename ends with mp3 vlc knows which mux to use ext = '.mp3' name = new_filename(ext) audiofile = '%s%s' %(name,ext) outf = initialize_cue_file(name,instream,audiofile) p,med = initialize_player(instream, audiofile) p.play() np = None i = 0 while 1: time.sleep(.1) new = med.get_meta(12) if new != np: i +=1 t = p.get_time() print "millisecs: %i" %t write_track_meta_to_cuefile(outf,instream,i,new,t) np = new print "now playing: %s" %np if __name__=='__main__': test() </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload