m13253 / BiliDan

Play videos on Bilibili.com with MPV and Danmaku2ASS
http://m13253.blogspot.com/2014/06/watch-bilibili-with-biligrab-danmaku2ass.html
Other
513 stars 69 forks source link

Python version check code not run on Python 2 #44

Closed grenadn closed 8 years ago

grenadn commented 8 years ago

Hello,

I noticed some code snippets like this:

def biligrab(url, *, debug=False, verbose=False, …):
    pass

But the interpreter(python2 on OS X) shows syntax error(caused by asterisk) and will also trigger

File "bilidan.py", line 14
SyntaxError: Non-ASCII character '\xe2' in file bilidan.py on line 14, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

thus,

if sys.version_info < (3, 0):
    sys.stderr.write('ERROR: Python 3.0 or newer version is required.\n')
    sys.exit(1)

will never run Insignificant minor bug :-)

cnbeining commented 8 years ago

Unlike the original Biligrab, BiliDan is Python 3 only.

grenadn commented 8 years ago

haha, that code just a bit redundant 😄

在 2015年12月21日,上午12:21,David Zhuang notifications@github.com 写道:

Unlike the original Biligrab, BiliDan is Python 3 only.

— Reply to this email directly or view it on GitHub https://github.com/m13253/BiliDan/issues/44#issuecomment-166133362.

m13253 commented 8 years ago

SyntaxError: Non-ASCII character '\xe2' in file bilidan.py on line 14, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

I fixed this by adding a charset declaration in e806ec11b61877e6aaf8e3dd6d15395e71fe2e7b. But there is still an exception:

  File "bilidan.py", line 61
    def biligrab(url, *, debug=False, verbose=False, media=None, cookie=None, quality=None, source=None, keep_fps=False, mpvflags=[], d2aflags={}, fakeip=None):
                       ^
SyntaxError: invalid syntax

I really don't know how to make the version check work. :joy:

acgtyrant commented 8 years ago

Add #!/usr/bin/env python3 in the code, and point out the correct version is Python 3 in the main document and comments.

There is a another stupid solution: you write spilit the code into two parts: one for Python version check and the other for the main code. If the former find that the version is correct, execute the later, like subprocess.run('main.py') while main.py has the correct shebang #!/usr/bin/env python3, or complain the user is using wrong Python.

m13253 commented 8 years ago

Okay. I already have the shebang. Since there is no other way to solve it without introducing a seperate launcher, I will close it for now until I find a solution.