Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop Python 2.7 #877

Merged
merged 3 commits into from
Oct 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 36 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
Expand All @@ -38,14 +39,17 @@ pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
Expand All @@ -55,6 +59,7 @@ coverage.xml
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
Expand All @@ -67,16 +72,34 @@ instance/
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# celery beat schedule file
# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py
Expand All @@ -89,8 +112,6 @@ venv/
ENV/
env.bak/
venv.bak/
venv2/
venv3/

# Spyder project settings
.spyderproject
Expand All @@ -104,6 +125,17 @@ venv3/

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# vscode
.vscode/
Expand Down
33 changes: 33 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
repos:
- repo: https://github.com/ambv/black
rev: stable
hooks:
- id: black
exclude: venv

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: trailing-whitespace
- id: check-yaml

- repo: https://github.com/asottile/reorder_python_imports
rev: v2.3.5
hooks:
- id: reorder-python-imports
args: ["--py3-plus"]

- repo: https://gitlab.com/pycqa/flake8
rev: 3.8.3
hooks:
- id: flake8
# allow "imported but unused" for pre-commit, forbid it elsewhere e.g. in vscode
args: ["--config=setup.cfg", "--ignore=E402,F401"]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.782
hooks:
- id: mypy
exclude: "migrations"
additional_dependencies:
["git+https://github.com/typeddjango/django-stubs.git"]
3 changes: 2 additions & 1 deletion NEMbox/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from .utils import create_dir, create_file
from .const import Constant
from .utils import create_dir
from .utils import create_file

create_dir(Constant.conf_dir)
create_dir(Constant.download_dir)
Expand Down
36 changes: 29 additions & 7 deletions NEMbox/__main__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,40 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
网易云音乐 Entry
__ ___________________________________________
| \ ||______ | |______|_____||______|______
| \_||______ | |______| |______||______

________ __________________________ _____ _ _
| | || ||______ | | |_____]| | \___/
| | ||_____|______|__|__|_____ |_____]|_____|_/ \_


+ ------------------------------------------ +
| NetEase-MusicBox 320kbps |
+ ------------------------------------------ +
| |
| ++++++++++++++++++++++++++++++++++++++ |
| ++++++++++++++++++++++++++++++++++++++ |
| ++++++++++++++++++++++++++++++++++++++ |
| ++++++++++++++++++++++++++++++++++++++ |
| ++++++++++++++++++++++++++++++++++++++ |
| |
| A sexy cli musicbox based on Python |
| Music resource from music.163.com |
| |
| Built with love to music by omi |
| |
+ ------------------------------------------ +

"""
from __future__ import print_function, unicode_literals, division, absolute_import
import curses
import traceback
import argparse
import curses
import sys
import traceback

from future.builtins import str

from .menu import Menu
from .__version__ import __version__ as version
from .menu import Menu


def start():
Expand Down
2 changes: 1 addition & 1 deletion NEMbox/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

"""
__title__ = "NetEase-MusicBox"
__version__ = "0.2.5.4"
__version__ = "0.3.0"
__description__ = "A sexy command line interface musicbox"
__url__ = "https://github.com/darknessomi/musicbox"
__author__ = "omi"
Expand Down
22 changes: 10 additions & 12 deletions NEMbox/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,21 @@
"""
网易云音乐 Api
"""
from __future__ import print_function, unicode_literals, division, absolute_import

import json
import platform
import time
from collections import OrderedDict
from http.cookiejar import LWPCookieJar
from http.cookiejar import Cookie
from http.cookiejar import LWPCookieJar

import platform
import time
import requests
import requests_cache

from . import logger
from .config import Config
from .const import Constant
from .storage import Storage
from .encrypt import encrypted_request
from . import logger
from .storage import Storage

requests_cache.install_cache(Constant.cache_path, expire_after=3600)

Expand Down Expand Up @@ -376,7 +374,7 @@ def login(self, username, password):
self.session.cookies.load()
if username.isdigit():
path = "/weapi/login/cellphone"
params = dict(phone=username, password=password, rememberLogin="true",)
params = dict(phone=username, password=password, rememberLogin="true")
else:
# magic token for login
# see https://github.com/Binaryify/NeteaseCloudMusicApi/blob/master/router/login.js#L15
Expand All @@ -387,7 +385,7 @@ def login(self, username, password):
params = dict(
username=username,
password=password,
countrycode='86',
countrycode="86",
rememberLogin="true",
clientToken=client_token,
)
Expand Down Expand Up @@ -434,7 +432,7 @@ def fm_like(self, songid, like=True, time=25, alg="itembased"):
# FM trash
def fm_trash(self, songid, time=25, alg="RT"):
path = "/weapi/radio/trash/add"
params = dict(songId=songid, alg=alg, time=time,)
params = dict(songId=songid, alg=alg, time=time)
return self.request("POST", path, params)["code"] == 200

# 搜索单曲(1),歌手(100),专辑(10),歌单(1000),用户(1002) *(type)*
Expand All @@ -446,7 +444,7 @@ def search(self, keywords, stype=1, offset=0, total="true", limit=50):
# 新碟上架
def new_albums(self, offset=0, limit=50):
path = "/weapi/album/new"
params = dict(area="ALL", offset=offset, total=True, limit=limit,)
params = dict(area="ALL", offset=offset, total=True, limit=limit)
return self.request("POST", path, params).get("albums", [])

# 歌单(网友精选碟) hot||new http://music.163.com/#/discover/playlist/
Expand Down Expand Up @@ -507,7 +505,7 @@ def song_comments(self, music_id, offset=0, total="false", limit=100):
# song ids --> song urls ( details )
def songs_detail(self, ids):
path = "/weapi/v3/song/detail"
params = dict(c=json.dumps([{"id": _id} for _id in ids]), ids=json.dumps(ids),)
params = dict(c=json.dumps([{"id": _id} for _id in ids]), ids=json.dumps(ids))
return self.request("POST", path, params).get("songs", [])

def songs_url(self, ids):
Expand Down
13 changes: 5 additions & 8 deletions NEMbox/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,16 @@
"""
Class to cache songs into local storage.
"""
from __future__ import print_function, unicode_literals, division, absolute_import
import threading
import subprocess
import os
import signal
import subprocess
import threading

from future.builtins import str

from .const import Constant
from . import logger
from .api import NetEase
from .config import Config
from .const import Constant
from .singleton import Singleton
from .api import NetEase
from . import logger

log = logger.getLogger(__name__)

Expand Down
7 changes: 3 additions & 4 deletions NEMbox/cmd_parser.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
#!/usr/bin/env python
# coding=utf-8
# __author__='walker'

"""
捕获类似curses键盘输入流,生成指令流
"""

import curses
from functools import wraps
from copy import deepcopy
from functools import wraps

from .config import Config

ERASE_SPEED = 5 # 屏幕5秒刷新一次 去除错误的显示
Expand Down Expand Up @@ -149,4 +148,4 @@ def main(data):


if __name__ == "__main__":
main(list(range(1, 12,)[::-1]))
main(list(range(1, 12)[::-1]))
12 changes: 1 addition & 11 deletions NEMbox/config.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
# encoding: UTF-8
from __future__ import print_function, unicode_literals, division, absolute_import
import json
import os

# from future.builtins import open

import sys
from .singleton import Singleton
from .const import Constant
from .singleton import Singleton
from .utils import utf8_data_to_file


Expand Down Expand Up @@ -229,12 +225,6 @@ def save_config_file(self):
utf8_data_to_file(config_file, json.dumps(self.config, indent=2))

def get(self, name):
if name == "keymap":
for key in self.default_config[name]["value"].keys():
if key not in self.config[name]["value"].keys():
self.config[name]["value"][key] = self.default_config[name][
"value"
][key]
if name not in self.config.keys():
self.config[name] = self.default_config[name]
return self.default_config[name]["value"]
Expand Down
1 change: 0 additions & 1 deletion NEMbox/const.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# encoding: UTF-8
# KenHuang: 使配置文件夹符合XDG标准
from __future__ import print_function, unicode_literals, division, absolute_import
import os


Expand Down
2 changes: 0 additions & 2 deletions NEMbox/encrypt.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function, unicode_literals, division, absolute_import
import base64
import binascii
import hashlib
import json
import os

from Cryptodome.Cipher import AES
from future.builtins import int, pow

__all__ = ["encrypted_id", "encrypted_request"]

Expand Down
4 changes: 2 additions & 2 deletions NEMbox/kill_thread.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ctypes
import inspect
import threading
import time
import inspect
import ctypes

__all__ = ["stop_thread"]

Expand Down
3 changes: 0 additions & 3 deletions NEMbox/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@
# -*- coding: utf-8 -*-
# @Author: omi
# @Date: 2014-08-24 21:51:57
from __future__ import print_function, unicode_literals, division, absolute_import
import logging

from future.builtins import open

from . import const

FILE_NAME = const.Constant.log_path
Expand Down
Loading