Skip to content

Commit

Permalink
fix(music_new): PropertyRequestor.__call__ no longer accept additiona…
Browse files Browse the repository at this point in the history
…l params; make PropertyRequestor.invoke private
  • Loading branch information
LucunJi committed Jun 24, 2022
1 parent c39e11a commit 09aa32f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions app/music_new/music.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ def bind(self, music: 'MusicPiece'):
self.owner = music

@abstract
async def invoke(self, *args, **kwargs) -> any:
async def __invoke(self) -> any:
pass

async def __call__(self, *args, **kwargs) -> any:
async def __call__(self) -> any:
async with self.lock:
if time.time() - self.lastrun_sec > self.expiration_time_sec or self.__counter == 0:
self.__counter += 1
self.lastrun_sec = time.time()
self.result = await self.invoke(*args, **kwargs)
self.result = await self.invoke()
return self.result

def __repr__(self):
Expand Down
8 changes: 4 additions & 4 deletions app/music_new/netease/netease_music.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async def invoke(self, *args, **kwargs):
async with aiohttp.ClientSession() as sess:
async with sess.post('https://music.163.com/api/song/enhance/player/url/', params={
'br': '3200000',
'ids': f'[{self.song_id}]'
'Aids': f'[{self.song_id}]'
}) as resp:
text = await resp.text()
data = json.loads(text)
Expand All @@ -32,7 +32,7 @@ def __init__(self, song_id: int):
super(DetailRequestor, self).__init__()
self.song_id = song_id

async def invoke(self, *args, **kwargs):
async def __invoke(self):
async with aiohttp.ClientSession() as sess:
async with sess.post('https://music.163.com/api/song/detail/', params={
'ids': f'[{self.song_id}]'
Expand All @@ -58,14 +58,14 @@ def __init__(self, song_id):
@property
async def name(self) -> str:
if self.__name is None:
data = await self.requestors['DetailRequestor']('name')
data = await self.requestors['DetailRequestor']()
self.__name = data.get('songs', [{}])[0].get('name', 'N/A')
return self.__name

@property
async def artists(self) -> list[str]:
if self.artists is None:
data = await self.requestors['DetailRequestor']('name')
data = await self.requestors['DetailRequestor']()
artists = data.get('songs', [{}])[0].get('artists', [])
self.__artists = [artists.get('name', 'Unknown') for artist in artists]
return self.__artists
Expand Down

0 comments on commit 09aa32f

Please sign in to comment.