diff options
| author | rzhxeo <rzhxeo@users.noreply.github.com> | 2013-09-30 21:39:58 -0700 | 
|---|---|---|
| committer | rzhxeo <rzhxeo@users.noreply.github.com> | 2013-09-30 21:39:58 -0700 | 
| commit | c0de39e6d42d8de6a77768b2a96570fd8df8ad36 (patch) | |
| tree | ef10e4ee36c43121490ae5bf89275c1793a30f88 /youtube_dl/utils.py | |
| parent | a921f40799d2ecb4be53b3241d2dbfc80f804d73 (diff) | |
| parent | 722076a123c60ed6d5a978c4bc2609f46c8e3ee9 (diff) | |
Merge pull request #2 from rg3/master
Update
Diffstat (limited to 'youtube_dl/utils.py')
| -rw-r--r-- | youtube_dl/utils.py | 29 | 
1 files changed, 28 insertions, 1 deletions
diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index 768c6207d..201ed255d 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -67,6 +67,12 @@ except ImportError:  # Python 2      from urllib2 import HTTPError as compat_HTTPError  try: +    from urllib.request import urlretrieve as compat_urlretrieve +except ImportError:  # Python 2 +    from urllib import urlretrieve as compat_urlretrieve + + +try:      from subprocess import DEVNULL      compat_subprocess_get_DEVNULL = lambda: DEVNULL  except ImportError: @@ -700,7 +706,16 @@ def unified_strdate(date_str):      date_str = date_str.replace(',',' ')      # %z (UTC offset) is only supported in python>=3.2      date_str = re.sub(r' (\+|-)[\d]*$', '', date_str) -    format_expressions = ['%d %B %Y', '%B %d %Y', '%b %d %Y', '%Y-%m-%d', '%d/%m/%Y', '%Y/%m/%d %H:%M:%S', '%d.%m.%Y %H:%M'] +    format_expressions = [ +        '%d %B %Y', +        '%B %d %Y', +        '%b %d %Y', +        '%Y-%m-%d', +        '%d/%m/%Y', +        '%Y/%m/%d %H:%M:%S', +        '%d.%m.%Y %H:%M', +        '%Y-%m-%dT%H:%M:%SZ', +    ]      for expression in format_expressions:          try:              upload_date = datetime.datetime.strptime(date_str, expression).strftime('%Y%m%d') @@ -781,6 +796,18 @@ def platform_name():      return res +def write_string(s, out=None): +    if out is None: +        out = sys.stderr +    assert type(s) == type(u'') + +    if ('b' in getattr(out, 'mode', '') or +            sys.version_info[0] < 3):  # Python 2 lies about mode of sys.stderr +        s = s.encode(preferredencoding(), 'ignore') +    out.write(s) +    out.flush() + +  def bytes_to_intlist(bs):      if not bs:          return []  | 
