diff --git a/.gitignore b/.gitignore index 4b8343a9..b5b1247c 100644 --- a/.gitignore +++ b/.gitignore @@ -140,7 +140,6 @@ cython_debug/ # vscode .vscode/ -setup.cfg nemcache.sqlite #Jetbrains diff --git a/ChangeLog.md b/CHANGELOG.md similarity index 79% rename from ChangeLog.md rename to CHANGELOG.md index 1eafd92f..a3ec2e31 100644 --- a/ChangeLog.md +++ b/CHANGELOG.md @@ -1,4 +1,38 @@ -## 更新日志 +# 更新日志 + +2018-05-21 版本 0.2.4.3 更新依赖,错误修复 + +2017-11-28 版本 0.2.4.2 更新获取歌曲列表的api + +2017-06-03 版本 0.2.4.1 修正mpg123状态异常导致的cpu占用,增加歌词双行显示功能 + +2017-03-17 版本 0.2.4.0 修复通知可能造成的崩溃 + +2017-03-03 版本 0.2.3.9 邮箱用户登录修复 + +2017-03-02 版本 0.2.3.8 登录接口修复 + +2016-11-24 版本 0.2.3.7 新增背景色设置 + +2016-11-07 版本 0.2.3.6 已知错误修复 + +2016-10-16 版本 0.2.3.5 新增进入歌曲专辑功能 + +2016-10-13 版本 0.2.3.4 新增查看歌曲评论 + +2016-09-26 版本 0.2.3.3 keybinder 错误修复 + +2016-09-15 版本 0.2.3.2 已知错误修复 + +2016-09-12 版本 0.2.3.1 已知错误修复 + +2016-09-11 版本 0.2.3.0 Python 2 和 3 支持 + +2016-05-09 版本 0.2.2.10 修复最后一行歌名过长的问题 + +2016-05-08 版本 0.2.2.9 缓存问题修复 + +2016-05-07 版本 0.2.2.8 解决通知在Gnome桌面持续驻留(#303)的问题 2016-05-07 版本 0.2.2.6 已知错误修复 diff --git a/LICENSE.txt b/LICENSE similarity index 95% rename from LICENSE.txt rename to LICENSE index 23ccf7b8..494c571e 100644 --- a/LICENSE.txt +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2018 omi <4399.omi@gmail.com> +Copyright (c) 2020 omi <4399.omi@gmail.com> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/MANIFEST.in b/MANIFEST.in deleted file mode 100644 index 4fae9108..00000000 --- a/MANIFEST.in +++ /dev/null @@ -1,2 +0,0 @@ -include requirements.txt -include README.md diff --git a/NEMbox/__init__.py b/NEMbox/__init__.py index 0ef85b83..6a934b41 100644 --- a/NEMbox/__init__.py +++ b/NEMbox/__init__.py @@ -1,9 +1,28 @@ -from .const import Constant -from .utils import create_dir -from .utils import create_file - -create_dir(Constant.conf_dir) -create_dir(Constant.download_dir) -create_file(Constant.storage_path) -create_file(Constant.log_path, default="") -create_file(Constant.cookie_path, default="#LWP-Cookies-2.0\n") +r""" +__ ___________________________________________ +| \ ||______ | |______|_____||______|______ +| \_||______ | |______| |______||______ + +________ __________________________ _____ _ _ +| | || ||______ | | |_____]| | \___/ +| | ||_____|______|__|__|_____ |_____]|_____|_/ \_ + + ++ ------------------------------------------ + +| NetEase-MusicBox 320kbps | ++ ------------------------------------------ + +| | +| ++++++++++++++++++++++++++++++++++++++ | +| ++++++++++++++++++++++++++++++++++++++ | +| ++++++++++++++++++++++++++++++++++++++ | +| ++++++++++++++++++++++++++++++++++++++ | +| ++++++++++++++++++++++++++++++++++++++ | +| | +| A sexy cli musicbox based on Python | +| Music resource from music.163.com | +| | +| Built with love to music by omi | +| | ++ ------------------------------------------ + + +""" diff --git a/NEMbox/__main__.py b/NEMbox/__main__.py index 28470b6e..51dc0fc7 100644 --- a/NEMbox/__main__.py +++ b/NEMbox/__main__.py @@ -1,43 +1,38 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -""" -__ ___________________________________________ -| \ ||______ | |______|_____||______|______ -| \_||______ | |______| |______||______ - -________ __________________________ _____ _ _ -| | || ||______ | | |_____]| | \___/ -| | ||_____|______|__|__|_____ |_____]|_____|_/ \_ - - -+ ------------------------------------------ + -| NetEase-MusicBox 320kbps | -+ ------------------------------------------ + -| | -| ++++++++++++++++++++++++++++++++++++++ | -| ++++++++++++++++++++++++++++++++++++++ | -| ++++++++++++++++++++++++++++++++++++++ | -| ++++++++++++++++++++++++++++++++++++++ | -| ++++++++++++++++++++++++++++++++++++++ | -| | -| A sexy cli musicbox based on Python | -| Music resource from music.163.com | -| | -| Built with love to music by omi | -| | -+ ------------------------------------------ + - -""" import argparse import curses import sys import traceback +from pathlib import Path + +import toml -from .__version__ import __version__ as version +from .const import Constant from .menu import Menu +from .utils import create_dir +from .utils import create_file + + +def create_config(): + create_dir(Constant.conf_dir) + create_dir(Constant.download_dir) + create_file(Constant.storage_path) + create_file(Constant.log_path, default="") + create_file(Constant.cookie_path, default="#LWP-Cookies-2.0\n") + + +def get_current_version(): + path = Path(".").parent.parent / "pyproject.toml" + with path.open() as f: + config = toml.load(f) + return config["tool"]["poetry"]["version"] def start(): + create_config() + version = get_current_version() + parser = argparse.ArgumentParser() parser.add_argument( "-v", "--version", help="show this version and exit", action="store_true" diff --git a/NEMbox/__version__.py b/NEMbox/__version__.py deleted file mode 100644 index a4149f42..00000000 --- a/NEMbox/__version__.py +++ /dev/null @@ -1,17 +0,0 @@ -""" -__ ___________________________________________ -| \ ||______ | |______|_____||______|______ -| \_||______ | |______| |______||______ - -________ __________________________ _____ _ _ -| | || ||______ | | |_____]| | \___/ -| | ||_____|______|__|__|_____ |_____]|_____|_/ \_ - -""" -__title__ = "NetEase-MusicBox" -__version__ = "0.3.0" -__description__ = "A sexy command line interface musicbox" -__url__ = "https://github.com/darknessomi/musicbox" -__author__ = "omi" -__author_email__ = "4399.omi@gmail.com" -__license__ = "MIT" diff --git a/NEMbox/api.py b/NEMbox/api.py index 4abf37bc..38b409be 100644 --- a/NEMbox/api.py +++ b/NEMbox/api.py @@ -300,7 +300,7 @@ def __init__(self): @property def toplists(self): - return [l[0] for l in TOP_LIST_ALL.values()] + return [item[0] for item in TOP_LIST_ALL.values()] def logout(self): self.session.cookies.clear() @@ -314,6 +314,7 @@ def logout(self): self.storage.save() def _raw_request(self, method, endpoint, data=None): + resp = None if method == "GET": resp = self.session.get( endpoint, params=data, headers=self.header, timeout=DEFAULT_TIMEOUT @@ -360,12 +361,13 @@ def request(self, method, path, params={}, default={"code": -1}, custom_cookies= self.session.cookies.set_cookie(cookie) params = encrypted_request(params) + resp = None try: resp = self._raw_request(method, endpoint, params) data = resp.json() except requests.exceptions.RequestException as e: log.error(e) - except ValueError as e: + except ValueError: log.error("Path: {}, response: {}".format(path, resp.text[:200])) finally: return data diff --git a/NEMbox/menu.py b/NEMbox/menu.py index 367dff13..5f0000f8 100644 --- a/NEMbox/menu.py +++ b/NEMbox/menu.py @@ -279,7 +279,7 @@ def check_version(self): data = self.api.get_version() return data["info"]["version"] - except KeyError as e: + except KeyError: return 0 def start_fork(self, version): @@ -423,7 +423,7 @@ def enter_page_event(self): self.menu_starts = time.time() self.ui.build_loading() self.dispatch_enter(idx) - if self.enter_flag == True: + if self.enter_flag: self.index = 0 self.offset = 0 @@ -706,7 +706,7 @@ def start(self): # 模糊搜索 elif C.keyname(key).decode("utf-8") == keyMap["search"]: - if self.at_search_result == True: + if self.at_search_result: self.back_page_event() self.stack.append( [self.datatype, self.title, self.datalist, self.offset, self.index] @@ -1050,7 +1050,6 @@ def dispatch_enter(self, idx): # 子类别 data = self.datalist[idx] self.datatype = "top_playlists" - log.error(data) self.datalist = netease.dig_info(netease.top_playlists(data), self.datatype) self.title += " > " + data @@ -1127,7 +1126,7 @@ def show_playing_song(self): ) self.at_playing_list = True - if self.at_search_result == True: + if self.at_search_result: self.back_page_event() self.datatype = self.player.info["player_list_type"] diff --git a/NEMbox/terminalsize.py b/NEMbox/terminalsize.py deleted file mode 100644 index a4dd5312..00000000 --- a/NEMbox/terminalsize.py +++ /dev/null @@ -1,111 +0,0 @@ -#!/usr/bin/env python -import os -import platform -import shlex -import struct -import subprocess - -from . import logger - -log = logger.getLogger(__name__) - - -def get_terminal_size(): - """getTerminalSize() - - get width and height of console - - works on linux,os x,windows,cygwin(windows) - originally retrieved from: - http://stackoverflow.com/questions/566746/how-to-get-console-window-width-in-python - """ - current_os = platform.system() - tuple_xy = None - if current_os == "Windows": - tuple_xy = _get_terminal_size_windows() - if tuple_xy is None: - tuple_xy = _get_terminal_size_tput() - # needed for window's python in cygwin's xterm! - if current_os in ["Linux", "Darwin"] or current_os.startswith("CYGWIN"): - tuple_xy = _get_terminal_size_linux() - if tuple_xy is None: - # print('default') - tuple_xy = (80, 25) # default value - return tuple_xy - - -def _get_terminal_size_windows(): - try: - from ctypes import windll, create_string_buffer - - # stdin handle is -10 - # stdout handle is -11 - # stderr handle is -12 - h = windll.kernel32.GetStdHandle(-12) - csbi = create_string_buffer(22) - res = windll.kernel32.GetConsoleScreenBufferInfo(h, csbi) - if res: - ( - bufx, - bufy, - curx, - cury, - wattr, - left, - top, - right, - bottom, - maxx, - maxy, - ) = struct.unpack("hhhhHhhhhhh", csbi.raw) - sizex = right - left + 1 - sizey = bottom - top + 1 - return sizex, sizey - except Exception as e: - log.error(e) - pass - - -def _get_terminal_size_tput(): - # get terminal width - # src: http://stackoverflow.com/questions/263890/how-do-i-find-the-width-height-of-a-terminal-window - try: - cols = int(subprocess.check_call(shlex.split("tput cols"))) - rows = int(subprocess.check_call(shlex.split("tput lines"))) - return (cols, rows) - except Exception as e: - log.error(e) - pass - - -def _get_terminal_size_linux(): - def ioctl_GWINSZ(fd): - try: - import fcntl - import termios - - cr = struct.unpack("hh", fcntl.ioctl(fd, termios.TIOCGWINSZ, "1234")) - return cr - except Exception as e: - log.error(e) - pass - - cr = ioctl_GWINSZ(0) or ioctl_GWINSZ(1) or ioctl_GWINSZ(2) - if not cr: - try: - fd = os.open(os.ctermid(), os.O_RDONLY) - cr = ioctl_GWINSZ(fd) - os.close(fd) - except Exception as e: - log.error(e) - pass - if not cr: - try: - cr = (os.environ["LINES"], os.environ["COLUMNS"]) - except Exception as e: - log.error(e) - return None - return int(cr[1]), int(cr[0]) - - -if __name__ == "__main__": - sizex, sizey = get_terminal_size() - print("width =", sizex, "height =", sizey) diff --git a/NEMbox/ui.py b/NEMbox/ui.py index 5ac46a84..931f9a69 100644 --- a/NEMbox/ui.py +++ b/NEMbox/ui.py @@ -13,7 +13,6 @@ import hashlib import os import re -from curses import textpad from shutil import get_terminal_size from . import logger @@ -117,8 +116,7 @@ def addstr(self, *args): try: self.screen.addstr(args[0], args[1], args[2].encode("utf-8"), *args[3:]) except Exception as e: - # log.error(e, args) - pass + log.error(e) def update_margin(self): # Left margin diff --git a/README.md b/README.md index 0b7333f6..64602c1f 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,11 @@ 高品质网易云音乐命令行版本,简洁优雅,丝般顺滑,基于Python编写。 -[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg)](LICENSE.txt) +[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg)](LICENSE) [![versions](https://img.shields.io/pypi/v/NetEase-MusicBox.svg)](https://pypi.org/project/NetEase-MusicBox/) -[![platform](https://img.shields.io/badge/python-3.5-green.svg)](<>) +[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/NetEase-MusicBox.svg)](https://pypi.org/project/NetEase-MusicBox/) + +## Demo [![NetEase-MusicBox-GIF](https://qfile.aobeef.cn/3abba3b8a3994ee3d5cd.gif)](https://pypi.org/project/NetEase-MusicBox/) @@ -94,39 +96,53 @@ ### PyPi安装(*nix系统) - $ pip(3) install NetEase-MusicBox +```bash + pip3 install NetEase-MusicBox +``` ### Git clone安装master分支(*nix系统) - $ git clone https://github.com/darknessomi/musicbox.git && cd musicbox - $ python(3) setup.py install +```bash + git clone https://github.com/darknessomi/musicbox.git && cd musicbox + poetry build && poetry install +``` ### macOS安装 - $ pip(3) install NetEase-MusicBox - $ brew install mpg123 +```bash + pip3 install NetEase-MusicBox + brew install mpg123 +``` ### Linux安装 +**注意:通过以下方法安装可能仍然需要`pip3 install -U NetEase-MusicBox`更新到最新版**。 + #### Fedora -首先添加[FZUG](https://github.com/FZUG/repo/wiki)源,然后`sudo dnf install musicbox`(通过此方法安装可能仍然需要`pip install -U NetEase-MusicBox`更新到最新版)。 +首先添加[FZUG](https://github.com/FZUG/repo/wiki)源,然后`sudo dnf install musicbox`。 #### Ubuntu/Debian - $ (sudo) pip install NetEase-MusicBox +```bash + pip3 install NetEase-MusicBox - $ (sudo) apt-get install mpg123 + sudo apt-get install mpg123 +``` #### Arch Linux - $ pacaur -S netease-musicbox-git # or $ yaourt musicbox +```bash + pacaur -S netease-musicbox-git # or $ yaourt musicbox +``` #### Centos/Red Hat - $ (sudo) pip(3) install NetEase-MusicBox - $ (sudo) wget http://mirror.centos.org/centos/7/os/x86_64/Packages/mpg123-1.25.6-1.el7.x86_64.rpm - $ (sudo) yum install mpg123-1.25.6-1.el7.x86_64.rpm +```bash + pip3 install NetEase-MusicBox + wget http://mirror.centos.org/centos/7/os/x86_64/Packages/mpg123-1.25.6-1.el7.x86_64.rpm + sudo yum install -y mpg123-1.25.6-1.el7.x86_64.rpm +``` ## 配置和错误处理 @@ -166,7 +182,9 @@ mpg123 最新的版本可能会报找不到声音硬件的错误,测试了1.25 ## 使用 - $ musicbox +```bash + musicbox +``` Enjoy it ! @@ -180,60 +198,8 @@ Enjoy it ! 2018-06-05 版本 0.2.5.0 全部迁移到新版api,大量错误修复 -2018-05-21 版本 0.2.4.3 更新依赖,错误修复 - -2017-11-28 版本 0.2.4.2 更新获取歌曲列表的api - -2017-06-03 版本 0.2.4.1 修正mpg123状态异常导致的cpu占用,增加歌词双行显示功能 - -2017-03-17 版本 0.2.4.0 修复通知可能造成的崩溃 - -2017-03-03 版本 0.2.3.9 邮箱用户登录修复 - -2017-03-02 版本 0.2.3.8 登录接口修复 - -2016-11-24 版本 0.2.3.7 新增背景色设置 - -2016-11-07 版本 0.2.3.6 已知错误修复 - -2016-10-16 版本 0.2.3.5 新增进入歌曲专辑功能 - -2016-10-13 版本 0.2.3.4 新增查看歌曲评论 - -2016-09-26 版本 0.2.3.3 keybinder 错误修复 - -2016-09-15 版本 0.2.3.2 已知错误修复 - -2016-09-12 版本 0.2.3.1 已知错误修复 - -2016-09-11 版本 0.2.3.0 Python 2 和 3 支持 - -2016-05-09 版本 0.2.2.10 修复最后一行歌名过长的问题 - -2016-05-08 版本 0.2.2.9 缓存问题修复 - -2016-05-07 版本 0.2.2.8 解决通知在Gnome桌面持续驻留(#303)的问题 - -[更多>>](https://github.com/darknessomi/musicbox/blob/master/ChangeLog.md) - -## MIT License - -Copyright (c) 2018 omi - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: +[更多>>](https://github.com/darknessomi/musicbox/blob/master/CHANGELOG.md) -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. +## LICENSE -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +[MIT](LICENSE) diff --git a/poetry.lock b/poetry.lock index b03e3915..460188c3 100644 --- a/poetry.lock +++ b/poetry.lock @@ -333,7 +333,7 @@ python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*" name = "toml" version = "0.10.1" description = "Python Library for Tom's Obvious, Minimal Language" -category = "dev" +category = "main" optional = false python-versions = "*" @@ -381,7 +381,7 @@ testing = ["pytest (>=3.5,<3.7.3 || >3.7.3)", "pytest-checkdocs (>=1.2.3)", "pyt [metadata] lock-version = "1.1" python-versions = "^3.6" -content-hash = "04b1607acd9f0d41b120dfe28e8eaa7819f411ef4644da892f245a8789d21950" +content-hash = "9ae3b320388eff395a00da3a6ea679c3edef500c7f55a9edad408028e6d45d52" [metadata.files] appdirs = [ diff --git a/pyproject.toml b/pyproject.toml index 27458eda..2ad1760c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,19 +12,19 @@ authors = [ "omi <4399.omi@gmail.com>", "Weiliang Li " ] +maintainers = [ + "omi <4399.omi@gmail.com>", + "Weiliang Li " +] keywords = ["music", "netease", "cli", "player"] classifiers = [ - "Development Status :: 4 - Beta", - "Intended Audience :: Developers", - "Natural Language :: Chinese (Simplified)", - "Operating System :: OS Independent", - "Programming Language :: Python", - "Programming Language :: Python :: 3.5", - "Programming Language :: Python :: 3.6", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: Implementation :: CPython", - "Topic :: Multimedia :: Sound/Audio", - ] + "Development Status :: 4 - Beta", + "Intended Audience :: Developers", + "Natural Language :: Chinese (Simplified)", + "Operating System :: OS Independent", + "Programming Language :: Python :: Implementation :: CPython", + "Topic :: Multimedia :: Sound/Audio", +] [tool.poetry.dependencies] @@ -34,6 +34,7 @@ requests-cache = "^0.5.2" fuzzywuzzy = "^0.18.0" pycryptodomex = "^3.9.8" python-Levenshtein = "^0.12.0" +toml = "^0.10.1" [tool.poetry.dev-dependencies] mypy = "^0.782" diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 00000000..c566bae9 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,5 @@ +[flake8] +ignore = E501,E402,W503 +exclude = .git,__pycache__,docs/source/conf.py,old,build,dist,venv +max-complexity = 15 +max-line-length = 88 diff --git a/setup.py b/setup.py deleted file mode 100644 index 9b436d22..00000000 --- a/setup.py +++ /dev/null @@ -1,72 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -""" -__ ___________________________________________ -| \ ||______ | |______|_____||______|______ -| \_||______ | |______| |______||______ - -________ __________________________ _____ _ _ -| | || ||______ | | |_____]| | \___/ -| | ||_____|______|__|__|_____ |_____]|_____|_/ \_ - - -+ ------------------------------------------ + -| NetEase-MusicBox 320kbps | -+ ------------------------------------------ + -| | -| ++++++++++++++++++++++++++++++++++++++ | -| ++++++++++++++++++++++++++++++++++++++ | -| ++++++++++++++++++++++++++++++++++++++ | -| ++++++++++++++++++++++++++++++++++++++ | -| ++++++++++++++++++++++++++++++++++++++ | -| | -| A sexy cli musicbox based on Python | -| Music resource from music.163.com | -| | -| Built with love to music by omi | -| | -+ ------------------------------------------ + - -""" -import os -from pprint import pprint - -from setuptools import find_packages -from setuptools import setup - -here = os.path.abspath(os.path.dirname(__file__)) -about = {} # type: dict - -with open(os.path.join(here, "NEMbox", "__version__.py"), "r") as f: - exec(f.read(), about) - -with open("README.md", "r") as f: - long_description = f.read() -setup( - name=about["__title__"], - version=about["__version__"], - author=about["__author__"], - author_email=about["__author_email__"], - url=about["__url__"], - description=about["__description__"], - long_description=long_description, - long_description_content_type="text/markdown", - license=about["__license__"], - packages=find_packages(), - install_requires=["requests-cache", "pycryptodomex", "future", "fuzzywuzzy"], - entry_points={"console_scripts": ["musicbox = NEMbox.__main__:start"]}, - keywords=["music", "netease", "cli", "player"], - classifiers=[ - "Development Status :: 4 - Beta", - "Intended Audience :: Developers", - "License :: OSI Approved :: MIT License", - "Natural Language :: Chinese (Simplified)", - "Operating System :: OS Independent", - "Programming Language :: Python", - "Programming Language :: Python :: 3.5", - "Programming Language :: Python :: 3.6", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: Implementation :: CPython", - "Topic :: Multimedia :: Sound/Audio", - ], -)