import optparse as OP
import threading as TH
import shlex as L
-from math import sqrt
+from math import sqrt, ceil
from contextlib import contextmanager
## eyeD3 tag fettling.
## Work out -- well, guess -- the time remaining.
if cur:
t = T.time()
- eta = me._fmt_time((t - me._start)*(max - cur)/cur)
+ eta = me._fmt_time(ceil((t - me._start)*(max - cur)/cur))
else:
eta = '???'
named format and its superclasses.
"""
+ name = 'format-spec'
+
## We cache the parser elements we generate to avoid enormous consing.
CACHE = {}
elt.set_properties(**props)
return elt
+def link_elements(elts):
+ "Link the elements ELTS together, in order."
+ GS.element_link_many(*elts)
+
+def bin_children(bin):
+ "Iterate over the (direct) children of a BIN."
+ for elt in bin.elements(): yield elt
+
class GStreamerProgressEyecandy (ProgressEyecandy):
"""
Provide amusement while GStreamer is busy doing something.
if pad.get_caps()[0].get_name().startswith('audio/'):
elt.link_pads(pad.get_name(), sink, 'sink')
dpaid = decoder.connect('pad-added', decoder_pad_arrived)
- me._pipe.add(source, decoder, sink)
- GS.element_link_many(source, decoder)
+ for i in [source, decoder, sink]: me._pipe.add(i)
+ link_elements([source, decoder])
## Arrange to collect tags from the pipeline's bus as they're reported.
## If we reuse the pipeline later, we'll want different bus-message
## things from being too awful.)
me.cap = None
me.dcap = None
- for e in decoder.elements():
+ for e in bin_children(decoder):
if e.get_factory().get_name() == 'typefind':
tfelt = e
break
"""
elts = me.encoder_chain()
bin = GS.Bin()
- bin.add(*elts)
- GS.element_link_many(*elts)
+ for i in elts: bin.add(i)
+ link_elements(elts)
bin.add_pad(GS.GhostPad('sink', elts[0].get_pad('sink')))
bin.add_pad(GS.GhostPad('src', elts[-1].get_pad('src')))
return bin
convert = make_element('audioconvert', 'convert')
encoder = me.encoder()
sink = make_element('filesink', 'sink', location = new)
- pipe.add(source, decoder, convert, encoder, sink)
- GS.element_link_many(source, decoder)
- GS.element_link_many(convert, encoder, sink)
+ for i in [source, decoder, convert, encoder, sink]: pipe.add(i)
+ link_elements([source, decoder])
+ link_elements([convert, encoder, sink])
## Some decoders (e.g., the AC3 decoder) include channel-position
## indicators in their output caps. The Vorbis encoder interferes with
for q, br in me.QMAP:
if br >= me.bitrate:
break
- else:
- raise ValueError, 'no suitable quality setting found'
+ else:
+ raise ValueError, 'no suitable quality setting found'
encprops['quality'] = q/10.0
return [make_element('vorbisenc', **encprops),
make_element('oggmux')]
## the appropriate categories. Later, we'll apply policy to the
## files, by category, and work out what to do with them all.
else:
- gf = GIO.File(masterfile)
- mime = gf.query_info('standard::content-type').get_content_type()
+ mime = GIO.File(masterfile) \
+ .query_info('standard::content-type') \
+ .get_content_type()
cats = []
for cat in pmap.iterkeys():
id = cat.identify(masterfile, mime)