from __future__ import with_statement
## Standard Python libraries.
-import sys as SYS
-import os as OS
import errno as E
-import time as T
-import unicodedata as UD
import fnmatch as FN
+import locale as LC
+import optparse as OP
+import os as OS
import re as RX
+import sys as SYS
+import time as T
+import shlex as L
import shutil as SH
-import optparse as OP
import threading as TH
-import shlex as L
+import unicodedata as UD
from math import sqrt, ceil
from contextlib import contextmanager
###--------------------------------------------------------------------------
### Eyecandy progress reports.
+DEFAULT_ENCODING = None
+
def charwidth(s):
"""
Return the width of S, in characters.
None of this handles tab characters in any kind of useful way. Sorry.
"""
- ## If there's no encoding for stdout then we're doing something stupid.
- if SYS.stdout.encoding is None: return len(s)
+ global DEFAULT_ENCODING
+
+ ## Figure out the default encoding.
+ if DEFAULT_ENCODING is None: DEFAULT_ENCODING = LC.getpreferredencoding()
## Turn the string into Unicode so we can hack on it properly. Maybe that
## won't work out, in which case fall back to being stupid.
- try: u = s.decode(SYS.stdout.encoding)
+ try: u = s.decode(DEFAULT_ENCODING)
except UnicodeError: return len(s)
## Our main problem is combining characters, but we should also try to
elif 'bitrate' in tags and tags['bitrate'] >= 80000:
me._bitrate = tags['bitrate']/1000
else:
- me._bitrate = None
+ ok, n = pipe.query_duration(GS.Format.BYTES)
+ if ok: ok, t = pipe.query_duration(GS.Format.TIME)
+ if ok: me._bitrate = int((8e6*n)/t)
+ else: me._bitrate = None
pipe.set_state(GS.State.NULL)
@property