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

增加当前列表模糊搜索,修复连续跳转Bug #858

Merged
merged 94 commits into from
Aug 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
94 commits
Select commit Hold shift + click to select a range
e59e25a
mac专用版本1.0
wangjianyuan10 Mar 10, 2020
799150c
mac专用版本1.0
wangjianyuan10 Mar 10, 2020
e44bd9f
1.0安装
wangjianyuan10 Mar 11, 2020
342420c
修复首次进评论的bug,提高主循环效率
wangjianyuan10 Mar 14, 2020
a829e67
修复快速按下一首多个子进程bug
wangjianyuan10 Mar 14, 2020
6494f2b
修复线程混乱问题增加数字跳转快捷键
wangjianyuan10 Mar 15, 2020
e154b2e
修复线程混乱问题增加数字跳转快捷键
wangjianyuan10 Mar 16, 2020
6a7018c
修复线程混乱问题增加数字跳转快捷键
wangjianyuan10 Mar 16, 2020
836aa83
修复线程混乱问题增加数字跳转快捷键
wangjianyuan10 Mar 16, 2020
0de73f1
修复线程混乱问题增加数字跳转快捷键
wangjianyuan10 Mar 16, 2020
483d391
修复线程混乱问题增加数字跳转快捷键
wangjianyuan10 Mar 17, 2020
842e8a8
修复线程混乱问题增加数字跳转快捷键
wangjianyuan10 Mar 17, 2020
f68f927
修复线程混乱问题增加数字跳转快捷键
wangjianyuan10 Mar 18, 2020
db7911e
修复线程混乱问题增加数字跳转快捷键
wangjianyuan10 Mar 18, 2020
097b31d
修复线程混乱问题增加数字跳转快捷键
wangjianyuan10 Mar 19, 2020
773b39c
修复线程混乱问题增加数字跳转快捷键
wangjianyuan10 Mar 21, 2020
a7e0ee6
增加显示颜色自定义,按键映射,使用定时器实现自动关闭功能;修复搜索按键功能映射错误;发现快速切换时会播放多首音乐
Ken-W-P-Huang Mar 29, 2020
90c7f6d
0.1
wangjianyuan10 Mar 30, 2020
58ebaa1
0.1
wangjianyuan10 Mar 30, 2020
ef4807a
0.2
wangjianyuan10 Mar 30, 2020
7ebeac4
0.2
wangjianyuan10 Mar 30, 2020
f182053
0.2
wangjianyuan10 Mar 30, 2020
c473439
Fix comments bug.
tonyfettes Jun 27, 2020
5c97a93
Fix comments bug.
tonyfettes Jun 27, 2020
f1a4017
Fix comments bug.
tonyfettes Jun 27, 2020
6f1b097
Fix comments bug.
tonyfettes Jun 27, 2020
c1b69c3
Optimize align of comments.
tonyfettes Jun 27, 2020
0513f48
Optimize align of comments.
tonyfettes Jun 27, 2020
aeb82fb
Optimize align of comments.
tonyfettes Jun 27, 2020
2397a66
Optimize for someone who write ':' in their comments.
tonyfettes Jun 27, 2020
457efaf
Fix comcomments.
tonyfettes Jun 27, 2020
1c9549a
Fix comcomments.
tonyfettes Jun 27, 2020
279064a
Fix comcomments.
tonyfettes Jun 27, 2020
d5cfd41
Merge pull request #1 from tonyfettes/test
tonyfettes Jun 27, 2020
1342039
Update README.md
tonyfettes Jun 27, 2020
dc6344c
Merge remote-tracking branch 'kwph/kenhuang' into kwph_test
tonyfettes Jun 27, 2020
dcd5df8
Remove DS_Store.
tonyfettes Jun 27, 2020
7370369
Fix keymap.
tonyfettes Jun 28, 2020
ee8df4a
Restore default key bindings.
tonyfettes Jun 28, 2020
e2be9fe
Resolve Conflists.
tonyfettes Jun 28, 2020
ca6be30
Restore osdlyrics.py
tonyfettes Jun 28, 2020
3808787
Remove fucking glyphs.
tonyfettes Jun 28, 2020
c647b13
Fix comments bug.
tonyfettes Jun 28, 2020
c615b2f
Merge.
tonyfettes Jul 2, 2020
7149527
Merge branch 'wjy_test' of github.com:tonyfettes/musicbox into wjy_test
tonyfettes Jul 2, 2020
fb8c267
Remove DS_Store.
tonyfettes Jul 2, 2020
f8485f7
Merge kwph and wjy.
tonyfettes Jul 2, 2020
4dc30f7
Merge kwph and wjy.
tonyfettes Jul 2, 2020
115bbb5
Change is to ==.
tonyfettes Jul 2, 2020
8ac9dac
Debug.
tonyfettes Jul 2, 2020
b7ae937
Fix bug: fast pressing [ ] will causing multiple play instance.
tonyfettes Jul 4, 2020
21165c7
Remove build_menu_progress.
tonyfettes Jul 4, 2020
152efcb
Optimize branches.
tonyfettes Jul 4, 2020
ee72efb
Merge pull request #2 from tonyfettes/remove_build_menu
tonyfettes Jul 4, 2020
ba183e7
Add a blank in song and fmsongs.
tonyfettes Jul 4, 2020
4e28562
Add mouse support.
tonyfettes Jul 4, 2020
d6f4da9
Change f to config_file to stop annoying pylint.
tonyfettes Jul 4, 2020
53a91a6
Fix notification on Linux.
tonyfettes Jul 4, 2020
3badd41
Move update api from macmusicbox to original one.
tonyfettes Jul 4, 2020
348afa7
Switch to timer.
tonyfettes Jul 4, 2020
e0f21b9
Fix display of help page.
tonyfettes Jul 4, 2020
b7f5a6a
Add fuzzy search.
tonyfettes Jul 4, 2020
bd3de28
Merge pull request #3 from tonyfettes/true_search
tonyfettes Jul 4, 2020
2dcff07
Clean code.
tonyfettes Jul 4, 2020
be713d2
Improve performance on urxvt.
tonyfettes Jul 5, 2020
a9e67c2
Optimize up down key logic.
tonyfettes Jul 5, 2020
30a2574
Merge pull request #4 from tonyfettes/performance
tonyfettes Jul 5, 2020
a0b776e
Format const.py
tonyfettes Jul 5, 2020
5a0ff33
Update README.md & reset to origin default keymap.
tonyfettes Jul 5, 2020
de159fb
Remove untested platform & add dependencies for fuzzy search.
tonyfettes Jul 5, 2020
5d520cc
Don't play music when press num keys.
tonyfettes Jul 6, 2020
b0ee59b
make num jump usable anywhere.
tonyfettes Jul 6, 2020
6c97569
Fix bug when mouse support is not enabled
tonyfettes Jul 6, 2020
2c9bcd1
Remove num jump when using mouse.
tonyfettes Jul 6, 2020
f26a900
Merge pull request #5 from tonyfettes/wjy_kwph_test
tonyfettes Jul 6, 2020
5bfad0d
Merge pull request #6 from tonyfettes/wjy_kwph
tonyfettes Jul 6, 2020
ecb42aa
Abitious plan.
tonyfettes Jul 6, 2020
d4a0eca
Configuration: curses timeout.
tonyfettes Jul 6, 2020
f3dd103
Try to optimize responsiveness.
tonyfettes Jul 6, 2020
a48080a
Remove yield latency (?).
tonyfettes Jul 6, 2020
f06dd0f
Partical plan.
tonyfettes Jul 6, 2020
c5fd3e3
Merge pull request #7 from tonyfettes/aggressive
tonyfettes Jul 6, 2020
e126bbf
Update README.md
tonyfettes Jul 6, 2020
edf929c
Merge pull request #8 from tonyfettes/master
tonyfettes Jul 6, 2020
3922d6a
Modifieable menu length
tonyfettes Aug 8, 2020
db5ab58
Probably fix of bug darknessomi #816
tonyfettes Aug 14, 2020
f275a60
Change plan. Mark fixed.
tonyfettes Aug 14, 2020
9f61b9b
Fix jump logical chaos in comment.
tonyfettes Aug 15, 2020
9565311
Fix the flash of color of lyrics when press j and k.
tonyfettes Aug 15, 2020
9d42870
Remove some targets & Use more accurate regex match to get timestap f…
tonyfettes Aug 16, 2020
44ace1c
Add auto adjust of page length according to terminal size.
tonyfettes Aug 17, 2020
c94ee04
Merge pull request #9 from tonyfettes/master
tonyfettes Aug 17, 2020
31a823c
Update README.md to keep consist of original one.
tonyfettes Aug 17, 2020
b65fd97
Use black to format code.
tonyfettes Aug 18, 2020
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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,8 @@ nemcache.sqlite

#Jetbrains
.idea

# Vim
.undodir
Session.vim
.vim
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include requirements.txt
include README.md
12 changes: 6 additions & 6 deletions NEMbox/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,10 @@ def make_cookie(self, name, value):
discard=False,
comment=None,
comment_url=None,
rest={},
rest=None,
)

def request(self, method, path, params={}, default={"code": -1}, custom_cookies={'os':'pc'}):
def request(self, method, path, params={}, default={"code": -1}, custom_cookies={}):
endpoint = "{}{}".format(BASE_URL, path)
csrf_token = ""
for cookie in self.session.cookies:
Expand Down Expand Up @@ -376,7 +376,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 Down Expand Up @@ -433,7 +433,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 @@ -445,7 +445,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 @@ -506,7 +506,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
2 changes: 1 addition & 1 deletion NEMbox/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def start_download(self):
url = data[3]
onExit = data[4]
output_path = Constant.download_dir
output_file = str(artist).replace('/', ' ') + " - " + str(song_name) + ".mp3"
output_file = str(artist) + " - " + str(song_name) + ".mp3"
full_path = os.path.join(output_path, output_file)

new_url = NetEase().songs_url([song_id])[0]["url"]
Expand Down
152 changes: 152 additions & 0 deletions NEMbox/cmd_parser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
#!/usr/bin/env python
# coding=utf-8
# __author__='walker'

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

import curses
from functools import wraps
from copy import deepcopy
from .config import Config

ERASE_SPEED = 5 # 屏幕5秒刷新一次 去除错误的显示

__all__ = ["cmd_parser", "parse_keylist", "coroutine", "erase_coroutine"]

keyMap = Config().get("keymap")


def coroutine(func):
@wraps(func)
def primer(*args, **kwargs):
gen = func(*args, **kwargs)
next(gen)
return gen

return primer


def _cmd_parser():
"""
A generator receive key value typed by user return constant keylist.
输入键盘输入流,输出指令流,以curses默认-1为信号终止.
"""
pre_key = -1
keylist = []
while 1:
key = yield
if key > 0 and pre_key == -1:
keylist.append(key)
elif key > 0 and pre_key > 0:
keylist.append(key)
elif curses.keyname(key).decode("utf-8") in keyMap.values() and pre_key > 0:
keylist.append(key)
return keylist
pre_key = key


def cmd_parser(results):
"""
A generator manager which can catch StopIteration and start a new Generator.
生成器管理对象,可以优雅地屏蔽生成器的终止信号,并重启生成器
"""
while 1:
results.clear()
results += yield from _cmd_parser()
yield results


def _erase_coroutine():
keylist = []
while 1:
key = yield
keylist.append(key)
if len(set(keylist)) > 1:
return keylist
elif len(keylist) >= ERASE_SPEED * 2:
return keylist


def erase_coroutine(erase_cmd_list):
while 1:
erase_cmd_list.clear()
erase_cmd_list += yield from _erase_coroutine()
yield erase_cmd_list


def parse_keylist(keylist):
"""
'2' '3' '4' 'j' ----> 234 j
supoort keys [ ] j k <KEY_UP> <KEY_DOWN>
"""
keylist = deepcopy(keylist)
if keylist == []:
return None
if (set(keylist) | {ord(keyMap["prevSong"]), ord(keyMap["nextSong"])}) == {
ord(keyMap["prevSong"]),
ord(keyMap["nextSong"]),
}:
delta_key = keylist.count(ord(keyMap["nextSong"])) - keylist.count(
ord(keyMap["prevSong"])
)
if delta_key < 0:
return (-delta_key, ord(keyMap["prevSong"]))
return (delta_key, ord(keyMap["nextSong"]))
tail_cmd = keylist.pop()
if tail_cmd in range(48, 58) and (set(keylist) | set(range(48, 58))) == set(
range(48, 58)
):
return int("".join([chr(i) for i in keylist] + [chr(tail_cmd)]))

if len(keylist) == 0:
return (0, tail_cmd)
if (
tail_cmd
in (
ord(keyMap["prevSong"]),
ord(keyMap["nextSong"]),
ord(keyMap["down"]),
ord(keyMap["up"]),
)
and max(keylist) <= 57
and min(keylist) >= 48
):
return (int("".join([chr(i) for i in keylist])), tail_cmd)
return None


def main(data):
"""
tset code
测试代码
"""
results = []
group = cmd_parser(results)
next(group)
for i in data:
group.send(i)
group.send(-1)
print(results)
next(group)
for i in data:
group.send(i)
group.send(-1)
print(results)
x = _cmd_parser()
print("-----------")
print(x.send(None))
print(x.send(1))
print(x.send(2))
print(x.send(3))
print(x.send(3))
print(x.send(3))
try:
print(x.send(-1))
except Exception as e:
print(e.value)


if __name__ == "__main__":
main(list(range(1, 12,)[::-1]))
91 changes: 84 additions & 7 deletions NEMbox/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
from __future__ import print_function, unicode_literals, division, absolute_import
import json
import os
from future.builtins import open

# from future.builtins import open

import sys
from .singleton import Singleton
from .const import Constant
from .utils import utf8_data_to_file
Expand All @@ -18,6 +20,13 @@ def __init__(self):
self.path = Constant.config_path
self.default_config = {
"version": 8,
"page_length": {
"value": 10,
"default": 10,
"describe": (
"Entries each page has. " "Set 0 to adjust automatically."
),
},
"cache": {
"value": False,
"default": False,
Expand Down Expand Up @@ -116,24 +125,92 @@ def __init__(self):
"default": False,
"describe": "Set true to make curses transparency.",
},
"mouse_movement": {
"value": False,
"default": False,
"describe": "Use mouse or touchpad to move.",
},
"input_timeout": {
"value": 500,
"default": 500,
"describe": "The time wait for the next key.",
},
"colors": {
"value": {
"pair1": [22, 148],
"pair2": [231, 24],
"pair3": [231, 9],
"pair4": [231, 14],
"pair5": [231, 237],
},
"default": {
"pair1": [22, 148],
"pair2": [231, 24],
"pair3": [231, 9],
"pair4": [231, 14],
"pair5": [231, 237],
},
"describe": "xterm-256color theme.",
},
"keymap": {
"value": {
"down": "j",
"up": "k",
"back": "h",
"forward": "l",
"prevPage": "u",
"nextPage": "d",
"search": "f",
"prevSong": "[",
"nextSong": "]",
"jumpIndex": "G",
"playPause": " ",
"shuffle": "?",
"volume+": "+",
"volume-": "-",
"menu": "m",
"presentHistory": "p",
"musicInfo": "i",
"playingMode": "P",
"enterAlbum": "A",
"add": "a",
"djList": "z",
"star": "s",
"collection": "c",
"remove": "r",
"moveDown": "J",
"moveUp": "K",
"like": ",",
"cache": "C",
"trashFM": ".",
"nextFM": "/",
"quit": "q",
"quitClear": "w",
"help": "y",
"top": "g",
"bottom": "G",
"countDown": "t",
},
"describe": "Keys and function.",
},
}
self.config = {}
if not os.path.isfile(self.path):
self.generate_config_file()

with open(self.path, "r") as f:
with open(self.path, "r") as config_file:
try:
self.config = json.load(f)
self.config = json.load(config_file)
except ValueError:
self.generate_config_file()

def generate_config_file(self):
with open(self.path, "w") as f:
utf8_data_to_file(f, json.dumps(self.default_config, indent=2))
with open(self.path, "w") as config_file:
utf8_data_to_file(config_file, json.dumps(self.default_config, indent=2))

def save_config_file(self):
with open(self.path, "w") as f:
utf8_data_to_file(f, json.dumps(self.config, indent=2))
with open(self.path, "w") as config_file:
utf8_data_to_file(config_file, json.dumps(self.config, indent=2))

def get(self, name):
if name not in self.config.keys():
Expand Down
31 changes: 25 additions & 6 deletions NEMbox/const.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
# encoding: UTF-8
# KenHuang: 使配置文件夹符合XDG标准
from __future__ import print_function, unicode_literals, division, absolute_import
import os


class Constant(object):
conf_dir = os.path.join(os.path.expanduser("~"), ".netease-musicbox")
download_dir = os.path.join(conf_dir, "cached")
if "XDG_CONFIG_HOME" in os.environ:
conf_dir = os.path.join(os.environ["XDG_CONFIG_HOME"], "netease-musicbox")
else:
conf_dir = os.path.join(os.path.expanduser("~"), ".netease-musicbox")
config_path = os.path.join(conf_dir, "config.json")
storage_path = os.path.join(conf_dir, "database.json")
cookie_path = os.path.join(conf_dir, "cookie")
log_path = os.path.join(conf_dir, "musicbox.log")
cache_path = os.path.join(conf_dir, "nemcache")
if "XDG_CACHE_HOME" in os.environ:
cacheDir = os.path.join(os.environ["XDG_CACHE_HOME"], "netease-musicbox")
if not os.path.exists(cacheDir):
os.mkdir(cacheDir)
download_dir = os.path.join(cacheDir, "cached")
cache_path = os.path.join(cacheDir, "nemcache")
else:
download_dir = os.path.join(conf_dir, "cached")
cache_path = os.path.join(conf_dir, "nemcache")
if "XDG_DATA_HOME" in os.environ:
dataDir = os.path.join(os.environ["XDG_DATA_HOME"], "netease-musicbox")
if not os.path.exists(dataDir):
os.mkdir(dataDir)
cookie_path = os.path.join(dataDir, "cookie")
log_path = os.path.join(dataDir, "musicbox.log")
storage_path = os.path.join(dataDir, "database.json")
else:
cookie_path = os.path.join(conf_dir, "cookie")
log_path = os.path.join(conf_dir, "musicbox.log")
storage_path = os.path.join(conf_dir, "database.json")
Loading