Skip to content

Commit

Permalink
some fixes, pulled the codename from the code
Browse files Browse the repository at this point in the history
  • Loading branch information
Filippo Valsorda committed Dec 30, 2012
1 parent 4e38899 commit f427df1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ youtube-dl.bash-completion: youtube_dl/*.py devscripts/bash-completion.in
python devscripts/bash-completion.py

youtube-dl.tar.gz: all
tar -czf youtube-dl.tar.gz -s "|^./|./youtube-dl/|" \
tar -czf youtube-dl.tar.gz -s "|^./|./youtube-dl/|" --exclude="updates_key.pem" \
--exclude="*.pyc" --exclude="*.pyo" --exclude="*~" --exclude="youtube-dl.exe" \
--exclude="wine-py2exe/" --exclude="py2exe.log" --exclude="*.kate-swp" \
--exclude="build/" --exclude="dist/" --exclude="MANIFEST" --exclude=".git/" .
21 changes: 11 additions & 10 deletions youtube_dl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import platform

from .utils import *
from .version import __version__, __version_codename__
from .version import __version__
from .FileDownloader import *
from .InfoExtractors import *
from .PostProcessor import *
Expand All @@ -62,7 +62,7 @@ def update_self(to_screen, verbose, filename):
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__:
Expand All @@ -74,7 +74,7 @@ def update_self(to_screen, verbose, filename):
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:
Expand Down Expand Up @@ -110,7 +110,7 @@ def update_self(to_screen, verbose, filename):
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

Expand All @@ -123,7 +123,7 @@ def update_self(to_screen, verbose, filename):
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

Expand All @@ -140,7 +140,7 @@ def update_self(to_screen, verbose, filename):

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

Expand All @@ -151,7 +151,7 @@ def update_self(to_screen, verbose, filename):
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

Expand All @@ -164,7 +164,7 @@ def update_self(to_screen, verbose, filename):
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

Expand Down Expand Up @@ -603,9 +603,10 @@ def _real_main():
})

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):
Expand Down
6 changes: 6 additions & 0 deletions youtube_dl/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ def compat_parse_qs(qs, keep_blank_values=False, strict_parsing=False,
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'en-us,en;q=0.5',
}

def preferredencoding():
"""Get preferred encoding.
Expand Down Expand Up @@ -187,6 +188,11 @@ def write_json_file(obj, fn):
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.
Expand Down
1 change: 0 additions & 1 deletion youtube_dl/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@

__version__ = '2012.12.11'
__version_codename__ = ''

0 comments on commit f427df1

Please sign in to comment.