Created
May 13, 2020 16:41
-
-
Save cosven/577e97c8caf71514e4585fcd4fd771b5 to your computer and use it in GitHub Desktop.
example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- mode: Python; -*- | |
# vi: ft=python | |
import json | |
import os | |
import threading | |
from functools import partial | |
config.AUDIO_SELECT_POLICY = 'sq>>>' | |
netease_log_song = None | |
def netease_log_on_song_changed(song): | |
global app, netease_log_song | |
if song is None or song.source != 'netease': | |
netease_log_song = None | |
return | |
netease_log_song = song | |
threading.Thread(target=partial(netease_log_send_request, song)).start() | |
def netease_log_on_media_finished(*args): | |
global netease_log_song | |
if netease_log_song is None: | |
return | |
song = netease_log_song | |
threading.Thread( | |
target=partial(netease_log_send_request, song, end=True)).start() | |
netease_log_song = None | |
def netease_log_send_request(song, end=False): | |
provider = app.library.get('netease') | |
# TODO: provider should provide a interface to check the current user | |
if provider is None or provider._user is None: | |
return | |
url = 'https://music.163.com/weapi/feedback/weblog' | |
json_ = { | |
'id': str(song.identifier), | |
'source': 'album', # TODO: use correct type | |
'sourceid': str(song.album.identifier), | |
'type': 'song', | |
} | |
if end is True: | |
sourceid = json_.pop('sourceid') | |
json_['sourceId'] = sourceid | |
json_['id'] = int(json_['id']) | |
json_['download'] = 0 | |
json_['end'] = "ui" | |
json_['wifi'] = 0 | |
json_['time'] = int(song.duration//1000) | |
data = { | |
'logs': json.dumps([{ | |
'action': 'play', | |
'json': json_ | |
}]) | |
} | |
payload = provider.api.encrypt_request(data) | |
result = provider.api.request('POST', url, payload) | |
print(f'send log:{data} to netease: {result}') | |
when('app.player.playlist.song_changed', netease_log_on_song_changed, use_symbol=True) | |
when('app.player.media_finished', netease_log_on_media_finished, use_symbol=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment