Example #1
0
def extractAudioTrack (device, track_number, sink, extra = None):
    """
    Exctracts an audio track from a certain device. The 'extra' field is used
    to send extra properties to the 'cdparanoia' element.
    """
    
    bin = gst.parse_launch ("cdparanoia ! wavenc")
    bin.set_state (gst.STATE_PAUSED)
    
    TRACK_FORMAT = gst.format_get_by_nick ("track")
    assert TRACK_FORMAT != 0
    PLAY_TRACK = TRACK_FORMAT | gst.SEEK_METHOD_SET | gst.SEEK_FLAG_FLUSH

    
    elements = bin.get_list ()
    cdparanoia = elements[0]
    wavenc = elements[-1]
    
    cdparanoia.set_property ("device", device)
    
    if extra is not None:
        for key, value in extra.iteritems ():
            cdparanoia.set_property (key, value)
            
    src = cdparanoia.get_pad ("src")
    evt = gst.event_new_segment_seek (PLAY_TRACK, track_number, track_number + 1)
    src.send_event (evt)
    
    bin.add (sink)
    wavenc.link (sink)
    
    return GstOperation(sink, bin)
Example #2
0
def extractAudioTrack (device, track_number, sink, extra = None):
	"""
	Exctracts an audio track from a certain device. The 'extra' field is used
	to send extra properties to the 'cdparanoia' element.
	"""
	
	bin = gst.parse_launch ("cdparanoia ! wavenc")
	bin.set_state (gst.STATE_PAUSED)
	
	TRACK_FORMAT = gst.format_get_by_nick ("track")
	assert TRACK_FORMAT != 0
	PLAY_TRACK = TRACK_FORMAT | gst.SEEK_METHOD_SET | gst.SEEK_FLAG_FLUSH

	
	elements = bin.get_list ()
	cdparanoia = elements[0]
	wavenc = elements[-1]
	
	cdparanoia.set_property ("device", device)
	
	if extra is not None:
		for key, value in extra.iteritems ():
			cdparanoia.set_property (key, value)
			
	src = cdparanoia.get_pad ("src")
	evt = gst.event_new_segment_seek (PLAY_TRACK, track_number, track_number + 1)
	src.send_event (evt)
	
	bin.add (sink)
	wavenc.link (sink)
	
	return GstOperation(sink, bin)
Example #3
0
def ripTrack(device, trackNo, filename, callbackProgress, callbackComplete):
    cdp = gst.element_factory_make("cdparanoia", "ripper")
    cdp.set_property("device", device)
    cdp.set_property("paranoia-mode", 4)
    cdp.set_property("abort-on-skip", True)
    track_format = gst.format_get_by_nick("track")
    src_pad = cdp.get_pad("src")

    flac = gst.element_factory_make("flacenc", "encoder")

    sink = gst.element_factory_make("filesink", "sink")
    sink.set_property("location", filename)

    bin = gst.Pipeline()
    bin.add_many(cdp, flac, sink)
    gst.element_link_many(cdp, flac, sink)

    bin.set_state(gst.STATE_PAUSED)

    seek = gst.event_new_segment_seek(
        track_format | gst.SEEK_METHOD_SET | gst.SEEK_FLAG_FLUSH, trackNo - 1,
        trackNo)
    src_pad.send_event(seek)

    res = bin.set_state(gst.STATE_PLAYING)

    lastsecs = -1
    while bin.iterate():
        nanos = src_pad.query(gst.QUERY_POSITION, gst.FORMAT_TIME)
        length = src_pad.query(gst.QUERY_TOTAL, gst.FORMAT_TIME)
        secs = nanos / gst.SECOND
        lensecs = length / gst.SECOND
        if secs <> lastsecs and secs > 0:
            #print "secs %d, lensecs %d, rate %f" % (secs,lensecs, rate)
            callbackProgress(trackNo, secs, lensecs)
            lastsecs = secs

    res = bin.set_state(gst.STATE_NULL)
    callbackComplete(trackNo)
Example #4
0
def ripTrack(device, trackNo, filename, callbackProgress, callbackComplete):
    cdp = gst.element_factory_make("cdparanoia", "ripper")
    cdp.set_property("device", device)
    cdp.set_property("paranoia-mode", 4)
    cdp.set_property("abort-on-skip", True)
    track_format = gst.format_get_by_nick("track")
    src_pad = cdp.get_pad("src")

    flac = gst.element_factory_make("flacenc", "encoder")
       
    sink = gst.element_factory_make("filesink", "sink")
    sink.set_property("location", filename)

    bin = gst.Pipeline()
    bin.add_many(cdp, flac, sink)
    gst.element_link_many(cdp, flac, sink)
    
    bin.set_state(gst.STATE_PAUSED)
    
    seek = gst.event_new_segment_seek(track_format | gst.SEEK_METHOD_SET | gst.SEEK_FLAG_FLUSH,
                                      trackNo - 1, trackNo)
    src_pad.send_event(seek)
    
    res = bin.set_state(gst.STATE_PLAYING);
    
    lastsecs = -1
    while bin.iterate():
        nanos = src_pad.query(gst.QUERY_POSITION, gst.FORMAT_TIME)
        length = src_pad.query(gst.QUERY_TOTAL, gst.FORMAT_TIME)
        secs = nanos / gst.SECOND
        lensecs = length / gst.SECOND
        if secs <> lastsecs and secs > 0:
            #print "secs %d, lensecs %d, rate %f" % (secs,lensecs, rate)
            callbackProgress(trackNo, secs, lensecs)
            lastsecs = secs

    res = bin.set_state(gst.STATE_NULL)
    callbackComplete(trackNo)