From 0ee67bdd11d518c206cfb7fab92550e899fd6ddc Mon Sep 17 00:00:00 2001 From: yorks Date: Thu, 16 Aug 2018 17:01:05 +0800 Subject: [PATCH 1/3] solve cheating 460 return --- NEMbox/api.py | 3 ++- NEMbox/encrypt.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/NEMbox/api.py b/NEMbox/api.py index da4c0fbc..fb6eff17 100644 --- a/NEMbox/api.py +++ b/NEMbox/api.py @@ -18,7 +18,7 @@ from .config import Config from .storage import Storage -from .encrypt import encrypted_request +from .encrypt import encrypted_request, get_base_cookie from . import logger requests_cache.install_cache('nemcache', expire_after=3600) @@ -247,6 +247,7 @@ def _raw_request(self, method, endpoint, data=None): def request(self, method, path, params={}, default={'code': -1}): endpoint = '{}{}'.format(BASE_URL, path) csrf_token = '' + requests.utils.add_dict_to_cookiejar(self.session.cookies, get_base_cookie()) for cookie in self.session.cookies: if cookie.name == '__csrf': csrf_token = cookie.value diff --git a/NEMbox/encrypt.py b/NEMbox/encrypt.py index c08056c4..ea24ee06 100644 --- a/NEMbox/encrypt.py +++ b/NEMbox/encrypt.py @@ -8,6 +8,8 @@ import hashlib import json import os +import random +import time from Cryptodome.Cipher import AES from future.builtins import int, pow @@ -63,3 +65,29 @@ def rsa(text, pubkey, modulus): def create_key(size): return binascii.hexlify(os.urandom(size))[:16] + +def random_string(pattern, length): + rand = '' + while len(rand) <= length: + rand = rand + random.choice(pattern) + return rand + +def create_jsessionid(): + rand = random_string('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKMNOPQRSTUVWXYZ\\/+',176) + ts = int(time.time() * 1000) + return "%s:%d"% (rand, ts) + +def create_nuid(): + return random_string('0123456789abcdefghijklmnopqrstuvwxyz',32) + +# https://github.com/Binaryify/NeteaseCloudMusicApi/../util/init.js +def get_base_cookie(): + nuid = create_nuid() + ts = int(time.time() * 1000) + nnid = "%s,%d"% (nuid, ts) + c={} + c['JSESSIONID-WYYY'] = create_jsessionid() + c['_ntes_nuid'] = nuid + c['_ntes_nnid'] = nnid + c['_iuqxldmzr_'] = '32' + return c From a20e8bc309446ab653f892b3d7d9ad76a0f7212e Mon Sep 17 00:00:00 2001 From: yorks Date: Fri, 31 Aug 2018 13:28:59 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=AF=8F=E6=97=A5?= =?UTF-8?q?=E6=8E=A8=E8=8D=90=E6=AD=8C=E6=9B=B2=20=E6=94=BE=E5=9C=A8?= =?UTF-8?q?=E6=AF=8F=E6=97=A5=E6=8E=A8=E8=8D=90=E4=B8=8B=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- NEMbox/api.py | 6 ++++++ NEMbox/menu.py | 9 ++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/NEMbox/api.py b/NEMbox/api.py index fb6eff17..c8e5bd15 100644 --- a/NEMbox/api.py +++ b/NEMbox/api.py @@ -307,6 +307,12 @@ def user_playlist(self, uid, offset=0, limit=50): ) return self.request('POST', path, params).get('playlist', []) + # 每日推荐歌曲 + def recommend_resource(self): + path = '/weapi/v1/discovery/recommend/songs' + params = {'offset':0, 'total':True, 'limit':20} + return self.request('POST', path, params).get('recommend', []) + # 每日推荐歌单 def recommend_resource(self): path = '/weapi/v1/discovery/recommend/resource' diff --git a/NEMbox/menu.py b/NEMbox/menu.py index bcb716fd..80728f8d 100644 --- a/NEMbox/menu.py +++ b/NEMbox/menu.py @@ -678,7 +678,10 @@ def dispatch_enter(self, idx): # 全站置顶歌单包含的歌曲 elif datatype == 'top_playlists': playlist_id = datalist[idx]['playlist_id'] - songs = netease.playlist_detail(playlist_id) + if playlist_id == 0: + songs = netease.recommend_songs() + else: + songs = netease.playlist_detail(playlist_id) self.datatype = 'songs' self.datalist = netease.dig_info(songs, 'songs') self.title += ' > ' + datalist[idx]['playlist_name'] @@ -841,6 +844,10 @@ def choice_channel(self, idx): self.datatype = 'top_playlists' self.title += ' > 每日推荐' self.datalist = self.api.dig_info(myplaylist, self.datatype) + self.datalist = [{'playlist_id':0, + 'playlist_name':u'每日推荐歌曲', + 'creator_name':u'云音乐'}] + self.datalist + elif idx == 7: self.datatype = 'fmsongs' self.title += ' > 私人FM' From 234c4648af1c0b7b622d520c07498cf6a196be16 Mon Sep 17 00:00:00 2001 From: yorks Date: Tue, 4 Sep 2018 12:53:33 +0800 Subject: [PATCH 3/3] press i to open the selected song url not the playing song --- NEMbox/menu.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/NEMbox/menu.py b/NEMbox/menu.py index 80728f8d..419a4ab4 100644 --- a/NEMbox/menu.py +++ b/NEMbox/menu.py @@ -591,9 +591,13 @@ def start(self): cache_thread.start() elif key == ord('i'): - if self.player.playing_id != -1: + song_id = self.datalist[idx].get('song_id', -1) + if not song_id: + song_id = self.player.playing_id + + if song_id != -1: webbrowser.open_new_tab( - 'http://music.163.com/song?id={}'.format(self.player.playing_id) + 'http://music.163.com/song?id={}'.format(song_id) ) self.ui.build_process_bar(