import platform
from .utils import *
-from .version import __version__, __version_codename__
+from .version import __version__
from .FileDownloader import *
from .InfoExtractors import *
from .PostProcessor import *
try:
newversion = compat_urllib_request.urlopen(VERSION_URL).read().decode('utf-8').strip()
except:
- if verbose: to_screen(traceback.format_exc().decode())
+ if verbose: to_screen(enforce_unicode(traceback.format_exc()))
to_screen(u'ERROR: can\'t find the current version. Please try again later.')
return
if newversion == __version__:
versions_info = compat_urllib_request.urlopen(JSON_URL).read().decode('utf-8')
versions_info = json.loads(versions_info)
except:
- if verbose: to_screen(traceback.format_exc().decode())
+ if verbose: to_screen(enforce_unicode(traceback.format_exc()))
to_screen(u'ERROR: can\'t obtain versions info. Please try again later.')
return
if not 'signature' in versions_info:
newcontent = urlh.read()
urlh.close()
except (IOError, OSError) as err:
- if verbose: to_screen(traceback.format_exc().decode())
+ if verbose: to_screen(enforce_unicode(traceback.format_exc()))
to_screen(u'ERROR: unable to download latest version')
return
with open(exe + '.new', 'wb') as outf:
outf.write(newcontent)
except (IOError, OSError) as err:
- if verbose: to_screen(traceback.format_exc().decode())
+ if verbose: to_screen(enforce_unicode(traceback.format_exc()))
to_screen(u'ERROR: unable to write the new version')
return
os.startfile(bat)
except (IOError, OSError) as err:
- if verbose: to_screen(traceback.format_exc().decode())
+ if verbose: to_screen(enforce_unicode(traceback.format_exc()))
to_screen(u'ERROR: unable to overwrite current version')
return
newcontent = urlh.read()
urlh.close()
except (IOError, OSError) as err:
- if verbose: to_screen(traceback.format_exc().decode())
+ if verbose: to_screen(enforce_unicode(traceback.format_exc()))
to_screen(u'ERROR: unable to download latest version')
return
with open(filename, 'wb') as outf:
outf.write(newcontent)
except (IOError, OSError) as err:
- if verbose: to_screen(traceback.format_exc().decode())
+ if verbose: to_screen(enforce_unicode(traceback.format_exc()))
to_screen(u'ERROR: unable to overwrite current version')
return
})
if opts.verbose:
- fd.to_screen(u'[debug] youtube-dl version %s - %s' %(__version__, __version_codename__))
+ fd.to_screen(u'[debug] youtube-dl version ' + __version__)
try:
- sp = subprocess.Popen(['git', 'rev-parse', '--short', 'HEAD'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ sp = subprocess.Popen(['git', 'rev-parse', '--short', 'HEAD'], stdout=subprocess.PIPE, stderr=subprocess.PIPE,
+ cwd=os.path.dirname(os.path.abspath(__file__)))
out, err = sp.communicate()
out = out.decode().strip()
if re.match('[0-9a-f]+', out):
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'en-us,en;q=0.5',
}
+
def preferredencoding():
"""Get preferred encoding.
with open(fn, 'w', encoding='utf-8') as f:
json.dump(obj, f)
+# Some library functions return bytestring on 2.X and unicode on 3.X
+def enforce_unicode(s, encoding='utf-8'):
+ if type(s) != type(u''):
+ return s.decode(encoding)
+ return s
def htmlentity_transform(matchobj):
"""Transforms an HTML entity to a character.