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

solve cheating 460 return #746

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
9 changes: 8 additions & 1 deletion NEMbox/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -306,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'
Expand Down
28 changes: 28 additions & 0 deletions NEMbox/encrypt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
17 changes: 14 additions & 3 deletions NEMbox/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -678,7 +682,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']
Expand Down Expand Up @@ -841,6 +848,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'
Expand Down