fuo-qqmusic 1.0.5__py3-none-any.whl → 1.0.7__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of fuo-qqmusic might be problematic. Click here for more details.

fuo_qqmusic/api.py CHANGED
@@ -8,6 +8,7 @@ import math
8
8
  import json
9
9
  import random
10
10
  import time
11
+ from enum import Enum
11
12
 
12
13
  import requests
13
14
  from .excs import QQIOError
@@ -518,6 +519,33 @@ class API(object):
518
519
  js = self.rpc(payload)
519
520
  return js['songlist']['data']['tracks']
520
521
 
522
+ def get_diss_info(self, dissid, offset=0, limit=50):
523
+ """获取歌单的详情
524
+
525
+ 这是一种特殊的歌单,它的内容是动态的,由官方生成。比如“百万收藏”。
526
+
527
+ :param dissid: int, 举个例子 211111 是百万收藏。
528
+ :return: 参考 fixtures/get_diss_info.json
529
+ """
530
+ payload = {
531
+ 'req': {
532
+ "module": "music.srfDissInfo.aiDissInfo",
533
+ "method":"uniform_get_Dissinfo",
534
+ "param": {
535
+ "disstid":dissid,
536
+ "userinfo":1, # 不懂啥意思
537
+ "tag":1, # 不懂啥意思
538
+ "orderlist":1,
539
+ "song_begin": offset,
540
+ "song_num": limit,
541
+ "onlysonglist":0,
542
+ "enc_host_uin":"" # 注:即使登录了,这个也是空
543
+ }
544
+ }
545
+ }
546
+ js = self.rpc(payload)
547
+ return js['req']['data']
548
+
521
549
  def get_song_url(self, song_mid):
522
550
  uin = self._uin
523
551
  songvkey = str(random.random()).replace("0.", "")
@@ -690,5 +718,85 @@ class API(object):
690
718
  return 'http://isure.stream.qqmusic.qq.com/{}'.format(midurlinfo[0]['purl'])
691
719
  return ''
692
720
 
721
+ class DislikeListType(Enum):
722
+ singer = 2
723
+ song = 3
724
+ _style_unsupported = 4 # TODO: 这是什么?似乎是不喜欢的风格列表,不确定,暂时不支持
725
+
726
+ def get_dislike_list(self, page=1, type_=DislikeListType.song, last_id=0):
727
+ payload = {
728
+ "req_0": {
729
+ "module": "music.feedback.FeedbackBlack",
730
+ "method": "GetDislikeList",
731
+ "param": {
732
+ "Cmd": type_.value,
733
+ "Page": page,
734
+ "SongLastid": last_id if type_ == API.DislikeListType.song else 0,
735
+ "SingersLastid": (
736
+ last_id if type_ == API.DislikeListType.singer else 0
737
+ ),
738
+ },
739
+ },
740
+ }
741
+ js = self.rpc(payload)
742
+ if type_ == API.DislikeListType.song:
743
+ return js["req_0"]["data"]["Songs"]
744
+ elif type_ == API.DislikeListType.singer:
745
+ return js["req_0"]["data"]["Singers"]
746
+ else:
747
+ raise QQIOError(f"Unknown dislike list type: {type_}")
748
+
749
+ def add_to_dislike_list(self, items, type_=DislikeListType.song):
750
+ req_param = {
751
+ "Singers": [],
752
+ "Songs": [],
753
+ "Styles": [],
754
+ "OnlyAdd": 1,
755
+ }
756
+ if type_ == API.DislikeListType.song:
757
+ req_param["Songs"] = items
758
+ elif type_ == API.DislikeListType.singer:
759
+ req_param["Singers"] = items
760
+ else:
761
+ raise QQIOError(f"Unknown dislike list type: {type_}")
762
+
763
+ payload = {
764
+ "req_0": {
765
+ "module": "music.feedback.FeedbackBlack",
766
+ "method": "AddDislike",
767
+ "param": req_param,
768
+ },
769
+ }
770
+ js = self.rpc(payload)
771
+ # Response example, {'code': 0, 'data': {'Retcode': 0, 'Msg': '', 'Token': ''}}
772
+ CodeShouldBe0.check(js['req_0'])
773
+ return js['req_0']['data']
774
+
775
+ def remove_from_dislike_list(self, items, type_=DislikeListType.song):
776
+ req_param = {
777
+ "Singers": [],
778
+ "Songs": [],
779
+ "Styles": [],
780
+ "OnlyAdd": 0,
781
+ }
782
+ if type_ == API.DislikeListType.song:
783
+ req_param["Songs"] = items
784
+ elif type_ == API.DislikeListType.singer:
785
+ req_param["Singers"] = items
786
+ else:
787
+ raise QQIOError(f"Unknown dislike list type: {type_}")
788
+
789
+ payload = {
790
+ "req_0": {
791
+ "module": "music.feedback.FeedbackBlack",
792
+ "method": "CancelDislike",
793
+ "param": req_param,
794
+ },
795
+ }
796
+ js = self.rpc(payload)
797
+ CodeShouldBe0.check(js)
798
+ CodeShouldBe0.check(js['req_0'])
799
+ return js['req_0']['data']
800
+
693
801
 
694
802
  api = API()
fuo_qqmusic/login.py ADDED
@@ -0,0 +1,24 @@
1
+ import json
2
+ import os
3
+
4
+ from feeluown.consts import DATA_DIR
5
+
6
+ USER_INFO_FILE = DATA_DIR + '/qqmusic_user_info.json'
7
+
8
+
9
+ def read_cookies():
10
+ if os.path.exists(USER_INFO_FILE):
11
+ # if the file is broken, just raise error
12
+ with open(USER_INFO_FILE) as f:
13
+ return json.load(f).get('cookies', None)
14
+
15
+
16
+ def write_cookies(user, cookies):
17
+ js = {
18
+ 'identifier': user.identifier,
19
+ 'name': user.name,
20
+ 'cookies': cookies
21
+ }
22
+ with open(USER_INFO_FILE, 'w') as f:
23
+ json.dump(js, f, indent=2)
24
+
fuo_qqmusic/provider.py CHANGED
@@ -1,5 +1,5 @@
1
1
  import logging
2
- from typing import List, Optional, Protocol
2
+ from typing import List, Optional, Protocol, Tuple
3
3
  from feeluown.excs import ModelNotFound
4
4
  from feeluown.library import (
5
5
  AbstractProvider,
@@ -23,13 +23,21 @@ from feeluown.library import (
23
23
  SupportsPlaylistGet,
24
24
  SupportsPlaylistSongsReader,
25
25
  SupportsRecACollectionOfSongs,
26
+ SupportsCurrentUserDislikeSongsReader,
27
+ SupportsCurrentUserDislikeAddSong,
28
+ SupportsCurrentUserDislikeRemoveSong,
29
+ SupportsCurrentUserChanged,
26
30
  SimpleSearchResult,
27
31
  SearchType,
28
32
  ModelType,
33
+ UserModel,
29
34
  )
30
35
  from feeluown.media import Media, Quality
36
+ from feeluown.utils.dispatch import Signal
31
37
  from feeluown.utils.reader import create_reader, SequentialReader
32
38
  from .api import API
39
+ from .login import read_cookies
40
+ from .excs import QQIOError
33
41
 
34
42
 
35
43
  logger = logging.getLogger(__name__)
@@ -50,6 +58,9 @@ class Supports(
50
58
  SupportsPlaylistSongsReader,
51
59
  SupportsRecACollectionOfSongs,
52
60
  SupportsAlbumSongsReader,
61
+ SupportsCurrentUserDislikeSongsReader,
62
+ SupportsCurrentUserDislikeAddSong,
63
+ SupportsCurrentUserDislikeRemoveSong,
53
64
  Protocol,
54
65
  ):
55
66
  pass
@@ -67,6 +78,7 @@ class QQProvider(AbstractProvider, ProviderV2):
67
78
  def __init__(self):
68
79
  super().__init__()
69
80
  self.api = API()
81
+ self.current_user_changed = Signal()
70
82
 
71
83
  def _(self) -> Supports:
72
84
  return self
@@ -79,6 +91,32 @@ class QQProvider(AbstractProvider, ProviderV2):
79
91
  def name(self):
80
92
  return "QQ 音乐"
81
93
 
94
+ def auto_login(self):
95
+ cookies = read_cookies()
96
+ user, err = self.try_get_user_from_cookies(cookies)
97
+ if user:
98
+ self.auth(user)
99
+ else:
100
+ logger.info(f'Auto login failed: {err}')
101
+ self.current_user_changed.emit(user)
102
+
103
+ def try_get_user_from_cookies(self, cookies) -> Tuple[Optional[UserModel], str]:
104
+ if not cookies: # is None or empty
105
+ return None, 'empty cookies'
106
+
107
+ uin = provider.api.get_uin_from_cookies(cookies)
108
+ if uin is None:
109
+ return None, "can't extract user info from cookies"
110
+
111
+ provider.api.set_cookies(cookies)
112
+ # try to extract current user
113
+ try:
114
+ user = provider.user_get(uin)
115
+ except QQIOError:
116
+ provider.api.set_cookies(None)
117
+ return None, 'get user info with cookies failed, expired cookies?'
118
+ return user, ''
119
+
82
120
  def use_model_v2(self, mtype):
83
121
  return mtype in (
84
122
  ModelType.song,
@@ -259,6 +297,27 @@ class QQProvider(AbstractProvider, ProviderV2):
259
297
  pl["logo"] = pl["cover"]
260
298
  return [_deserialize(playlist, QQPlaylistSchema) for playlist in playlists]
261
299
 
300
+ def rec_list_daily_songs(self):
301
+ # TODO: cache API result
302
+ feed = self.api.get_recommend_feed()
303
+ card = None
304
+ for shelf_ in feed['v_shelf']:
305
+ if 'moduleID' not in shelf_['extra_info']:
306
+ for batch in shelf_['v_niche']:
307
+ for card in batch['v_card']:
308
+ if (
309
+ card['extra_info'].get('moduleID', '').startswith('recforyou')
310
+ and card['jumptype'] == 10014 # 10014->playlist
311
+ ):
312
+ card = card
313
+ break
314
+ if card is None:
315
+ logger.warning("No daily songs found")
316
+ return []
317
+ playlist_id = card['id']
318
+ playlist = self.playlist_get(playlist_id)
319
+ return self.playlist_create_songs_rd(playlist).readall()
320
+
262
321
  def rec_list_daily_playlists(self):
263
322
  # TODO: cache API result
264
323
  feed = self.api.get_recommend_feed()
@@ -368,6 +427,35 @@ class QQProvider(AbstractProvider, ProviderV2):
368
427
  data_songs = self.api.song_similar(int(song.identifier))
369
428
  return [_deserialize(data_song, QQSongSchema) for data_song in data_songs]
370
429
 
430
+ def current_user_dislike_create_songs_rd(self):
431
+ user = self.get_current_user()
432
+ if user is None:
433
+ return create_reader([])
434
+ # FIXME: 如果用户的黑名单歌曲数量较多的话,这样处理则是不够的
435
+ items = self.api.get_dislike_list(1, API.DislikeListType.song, 0)
436
+ songs = []
437
+ for item in items:
438
+ name = item['Name']
439
+ title, artists_name = name.split(' - ')
440
+ song = BriefSongModel(
441
+ source=SOURCE,
442
+ identifier=item['ID'],
443
+ title=title,
444
+ artists_name=artists_name,
445
+ )
446
+ songs.append(song)
447
+ return create_reader(songs)
448
+
449
+ def current_user_dislike_add_song(self, song):
450
+ items = [{'ID': song.identifier}]
451
+ js = self.api.add_to_dislike_list(items, API.DislikeListType.song)
452
+ return js.get('Retcode') == 0
453
+
454
+ def current_user_dislike_remove_song(self, song):
455
+ items = [{'ID': song.identifier}]
456
+ js = self.api.remove_from_dislike_list(items, API.DislikeListType.song)
457
+ return js.get('Retcode') == 0
458
+
371
459
 
372
460
  def _deserialize(data, schema_cls):
373
461
  schema = schema_cls()
@@ -11,20 +11,11 @@ from feeluown.app.gui_app import GuiApp
11
11
 
12
12
  from .provider import provider
13
13
  from .excs import QQIOError
14
+ from .login import read_cookies, write_cookies
14
15
 
15
16
  logger = logging.getLogger(__name__)
16
17
 
17
18
 
18
- USER_INFO_FILE = DATA_DIR + '/qqmusic_user_info.json'
19
-
20
-
21
- def read_cookies():
22
- if os.path.exists(USER_INFO_FILE):
23
- # if the file is broken, just raise error
24
- with open(USER_INFO_FILE) as f:
25
- return json.load(f).get('cookies', None)
26
-
27
-
28
19
  class ProviderUI(AbstractProviderUi):
29
20
  def __init__(self, app: GuiApp):
30
21
  self._app = app
@@ -72,31 +63,13 @@ class LoginDialog(CookiesLoginDialog):
72
63
  provider._user = user
73
64
 
74
65
  async def user_from_cookies(self, cookies):
75
- if not cookies: # is None or empty
76
- raise InvalidCookies('empty cookies')
77
-
78
- uin = provider.api.get_uin_from_cookies(cookies)
79
- if uin is None:
80
- raise InvalidCookies("can't extract user info from cookies")
81
-
82
- provider.api.set_cookies(cookies)
83
- # try to extract current user
84
- try:
85
- user = await run_fn(provider.user_get, uin)
86
- except QQIOError:
87
- provider.api.set_cookies(None)
88
- raise InvalidCookies('get user info with cookies failed, expired cookies?')
89
- else:
66
+ user, err = await run_fn(provider.try_get_user_from_cookies, cookies)
67
+ if user:
90
68
  return user
69
+ raise InvalidCookies(err)
91
70
 
92
71
  def load_user_cookies(self):
93
72
  return read_cookies()
94
73
 
95
74
  def dump_user_cookies(self, user, cookies):
96
- js = {
97
- 'identifier': user.identifier,
98
- 'name': user.name,
99
- 'cookies': cookies
100
- }
101
- with open(USER_INFO_FILE, 'w') as f:
102
- json.dump(js, f, indent=2)
75
+ write_cookies(user, cookies)
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: fuo_qqmusic
3
- Version: 1.0.5
3
+ Version: 1.0.7
4
4
  Summary: feeluown qqmusic plugin
5
5
  Home-page: https://github.com/feeluown/feeluown-qqmusic
6
6
  Author: Cosven
@@ -13,7 +13,13 @@ Classifier: Programming Language :: Python :: 3.7
13
13
  Classifier: Programming Language :: Python :: 3.8
14
14
  Classifier: Programming Language :: Python :: 3.9
15
15
  Classifier: Programming Language :: Python :: 3 :: Only
16
- Requires-Dist: feeluown (>=4.1.3)
16
+ Requires-Dist: feeluown>=4.1.3
17
17
  Requires-Dist: requests
18
- Requires-Dist: marshmallow (>=3.0)
19
-
18
+ Requires-Dist: marshmallow<4.0.0,>=3.0
19
+ Dynamic: author
20
+ Dynamic: author-email
21
+ Dynamic: classifier
22
+ Dynamic: home-page
23
+ Dynamic: keywords
24
+ Dynamic: requires-dist
25
+ Dynamic: summary
@@ -0,0 +1,14 @@
1
+ fuo_qqmusic/__init__.py,sha256=YxZHAp5Qaye5B5V8GBPyxqnEUe-FcwUv6TiF_29qBEs,537
2
+ fuo_qqmusic/api.py,sha256=yDT6iyq9ZdkRQkqDI96uFE3ctbh7HseUU8NVsuu3jBM,27381
3
+ fuo_qqmusic/consts.py,sha256=9VFc9yE6z6c0IzK03PQTEO0JqgXi37RahEvZRP-A4Dk,185
4
+ fuo_qqmusic/excs.py,sha256=SBcER_wESjvui6a0Li1dX5utep4ouDS7HaTXqXPOQiA,160
5
+ fuo_qqmusic/login.py,sha256=zNPPncKl1Pr8uYBbLrdPlVJyKBsNfS2FotRfn9l3LEA,542
6
+ fuo_qqmusic/provider.py,sha256=QUw5VvLaKodVVaKp2lPuSm8z1edXy5qUdmlzpE5Ldds,19025
7
+ fuo_qqmusic/provider_ui.py,sha256=K70BjKvlx4h6gVYqeHOZhP68nnUWH2_mFbUK3jjvJ5U,2366
8
+ fuo_qqmusic/schemas.py,sha256=Sbka-YuK3UTn26CbfwOb0ZfB6XmiJHW-ibCLThj49VQ,12128
9
+ fuo_qqmusic/assets/icon.svg,sha256=o48VTiHroJU6S2g8LbxfnK25G2QW3d1XtQZKoL3ZMGA,1216
10
+ fuo_qqmusic-1.0.7.dist-info/METADATA,sha256=U6tM7hrztEL-AjtHR_R2U-MkOrPauHrgc54LemZGj8g,810
11
+ fuo_qqmusic-1.0.7.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
12
+ fuo_qqmusic-1.0.7.dist-info/entry_points.txt,sha256=XUL7UwcsLZEuEbBJIcsFemC3BiYb7dSTiXB9r6SJ5zY,39
13
+ fuo_qqmusic-1.0.7.dist-info/top_level.txt,sha256=Qn_g3dRwtoVZgVPZ9uRehspXi62T-E1x9_kLIdYFic4,12
14
+ fuo_qqmusic-1.0.7.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (72.1.0)
2
+ Generator: setuptools (80.9.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,13 +0,0 @@
1
- fuo_qqmusic/__init__.py,sha256=YxZHAp5Qaye5B5V8GBPyxqnEUe-FcwUv6TiF_29qBEs,537
2
- fuo_qqmusic/api.py,sha256=w_anRMxAqL9FaMJVRmZ3A_uV4rzr7_S_1xMjZf-uovY,23597
3
- fuo_qqmusic/consts.py,sha256=9VFc9yE6z6c0IzK03PQTEO0JqgXi37RahEvZRP-A4Dk,185
4
- fuo_qqmusic/excs.py,sha256=SBcER_wESjvui6a0Li1dX5utep4ouDS7HaTXqXPOQiA,160
5
- fuo_qqmusic/provider.py,sha256=JmQtjPVPsaZ1n12phJDd_Ll3Y83RfaHb5S6i0d1xrjw,15669
6
- fuo_qqmusic/provider_ui.py,sha256=UKmzK6SImyWZe_wtkjcfXH_gy2XXbcnnI4Er0fICM6I,3197
7
- fuo_qqmusic/schemas.py,sha256=Sbka-YuK3UTn26CbfwOb0ZfB6XmiJHW-ibCLThj49VQ,12128
8
- fuo_qqmusic/assets/icon.svg,sha256=o48VTiHroJU6S2g8LbxfnK25G2QW3d1XtQZKoL3ZMGA,1216
9
- fuo_qqmusic-1.0.5.dist-info/METADATA,sha256=EgB-48xvBBqTnxxGYFAjK3rqBpaYK6hS5Csvdx5ubAM,675
10
- fuo_qqmusic-1.0.5.dist-info/WHEEL,sha256=R0nc6qTxuoLk7ShA2_Y-UWkN8ZdfDBG2B6Eqpz2WXbs,91
11
- fuo_qqmusic-1.0.5.dist-info/entry_points.txt,sha256=XUL7UwcsLZEuEbBJIcsFemC3BiYb7dSTiXB9r6SJ5zY,39
12
- fuo_qqmusic-1.0.5.dist-info/top_level.txt,sha256=Qn_g3dRwtoVZgVPZ9uRehspXi62T-E1x9_kLIdYFic4,12
13
- fuo_qqmusic-1.0.5.dist-info/RECORD,,