yutipy 1.4.0__py3-none-any.whl → 1.4.1__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 yutipy might be problematic. Click here for more details.

yutipy/__init__.py CHANGED
@@ -1,5 +1,6 @@
1
1
  from .deezer import Deezer
2
2
  from .itunes import Itunes
3
+ from .kkbox import KKBox
3
4
  from .models import MusicInfo
4
5
  from .musicyt import MusicYT
5
6
  from .spotify import Spotify
@@ -8,6 +9,7 @@ from .yutipy_music import YutipyMusic
8
9
  __all__ = [
9
10
  "Deezer",
10
11
  "Itunes",
12
+ "KKBox",
11
13
  "MusicInfo",
12
14
  "MusicYT",
13
15
  "Spotify",
yutipy/spotify.py CHANGED
@@ -16,6 +16,7 @@ from yutipy.exceptions import (
16
16
  )
17
17
  from yutipy.models import MusicInfo
18
18
  from yutipy.utils.cheap_utils import (
19
+ guess_album_type,
19
20
  are_strings_similar,
20
21
  is_valid_string,
21
22
  separate_artists,
@@ -175,6 +176,7 @@ class Spotify:
175
176
  self.normalize_non_english = normalize_non_english
176
177
 
177
178
  music_info = None
179
+ artist_ids = None
178
180
  queries = [
179
181
  f"?q=artist:{artist} track:{song}&type=track&limit={limit}",
180
182
  f"?q=artist:{artist} album:{song}&type=album&limit={limit}",
@@ -199,7 +201,7 @@ class Spotify:
199
201
  if response.status_code != 200:
200
202
  raise SpotifyException(f"Failed to search for music: {response.json()}")
201
203
 
202
- artist_ids = self._get_artists_ids(artist)
204
+ artist_ids = artist_ids if artist_ids else self._get_artists_ids(artist)
203
205
  music_info = self._find_music_info(
204
206
  artist, song, response.json(), artist_ids
205
207
  )
@@ -449,10 +451,15 @@ class Spotify:
449
451
  ]
450
452
 
451
453
  if matching_artists:
454
+ guess = guess_album_type(album.get("total_tracks", 1))
455
+ guessed_right = are_strings_similar(
456
+ album.get("album_type", "x"), guess, use_translation=False
457
+ )
458
+
452
459
  return MusicInfo(
453
460
  album_art=album["images"][0]["url"],
454
461
  album_title=album["name"],
455
- album_type=album["album_type"],
462
+ album_type=album.get("alnum_type") if guessed_right else guess,
456
463
  artists=", ".join(artists_name),
457
464
  genre=None,
458
465
  id=album["id"],
@@ -461,7 +468,7 @@ class Spotify:
461
468
  release_date=album["release_date"],
462
469
  tempo=None,
463
470
  title=album["name"],
464
- type="album",
471
+ type=album.get("type"),
465
472
  upc=None,
466
473
  url=album["external_urls"]["spotify"],
467
474
  )
yutipy/utils/__init__.py CHANGED
@@ -1,6 +1,12 @@
1
- from .cheap_utils import are_strings_similar, is_valid_string, separate_artists
1
+ from .cheap_utils import (
2
+ guess_album_type,
3
+ are_strings_similar,
4
+ is_valid_string,
5
+ separate_artists,
6
+ )
2
7
 
3
8
  __all__ = [
9
+ "guess_album_type",
4
10
  "are_strings_similar",
5
11
  "is_valid_string",
6
12
  "separate_artists",
@@ -117,5 +117,15 @@ def is_valid_string(string: str) -> bool:
117
117
  return bool(string and (string.isalnum() or not string.isspace()))
118
118
 
119
119
 
120
+ def guess_album_type(total_tracks: int):
121
+ """Just guessing the album type (i.e. single, ep or album) by total track counts."""
122
+ if total_tracks == 1:
123
+ return "single"
124
+ if 3 <= total_tracks <= 5:
125
+ return "ep"
126
+ if total_tracks >= 7:
127
+ return "album"
128
+
129
+
120
130
  if __name__ == "__main__":
121
131
  separate_artists("Artist A ft. Artist B")
yutipy/yutipy_music.py CHANGED
@@ -98,6 +98,20 @@ class YutipyMusic:
98
98
 
99
99
  self.normalize_non_english = normalize_non_english
100
100
 
101
+ attributes = [
102
+ "album_title",
103
+ "album_type",
104
+ "artists",
105
+ "genre",
106
+ "isrc",
107
+ "lyrics",
108
+ "release_date",
109
+ "tempo",
110
+ "title",
111
+ "type",
112
+ "upc",
113
+ ]
114
+
101
115
  with ThreadPoolExecutor() as executor:
102
116
  futures = {
103
117
  executor.submit(
@@ -113,14 +127,16 @@ class YutipyMusic:
113
127
  for future in as_completed(futures):
114
128
  service_name = futures[future]
115
129
  result = future.result()
116
- self._combine_results(result, service_name)
130
+ self._combine_results(result, service_name, attributes)
117
131
 
118
132
  if len(self.music_info.url) == 0:
119
133
  return None
120
134
 
121
135
  return self.music_info
122
136
 
123
- def _combine_results(self, result: Optional[MusicInfo], service_name: str) -> None:
137
+ def _combine_results(
138
+ self, result: Optional[MusicInfo], service_name: str, attributes: list
139
+ ) -> None:
124
140
  """
125
141
  Combines the results from different services.
126
142
 
@@ -134,25 +150,16 @@ class YutipyMusic:
134
150
  if not result:
135
151
  return
136
152
 
137
- attributes = [
138
- "album_title",
139
- "album_type",
140
- "artists",
141
- "genre",
142
- "isrc",
143
- "lyrics",
144
- "release_date",
145
- "tempo",
146
- "title",
147
- "type",
148
- "upc",
149
- ]
150
-
151
153
  for attr in attributes:
152
154
  if getattr(result, attr) and (
153
- not getattr(self.music_info, attr) or service_name == "spotify"
155
+ not getattr(self.music_info, attr)
156
+ or (attr in ["genre", "album_type"] and service_name == "itunes")
154
157
  ):
155
- setattr(self.music_info, attr, getattr(result, attr))
158
+ setattr(
159
+ self.music_info,
160
+ attr,
161
+ getattr(result, attributes.pop(attributes.index(attr))),
162
+ )
156
163
 
157
164
  if result.album_art:
158
165
  current_priority = self.album_art_priority.index(service_name)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: yutipy
3
- Version: 1.4.0
3
+ Version: 1.4.1
4
4
  Summary: A simple package for retrieving music information from various music platforms APIs.
5
5
  Author: Cheap Nightbot
6
6
  Author-email: Cheap Nightbot <hi@cheapnightbot.slmail.me>
@@ -33,7 +33,7 @@ Project-URL: Repository, https://github.com/CheapNightbot/yutipy.git
33
33
  Project-URL: Issues, https://github.com/CheapNightbot/yutipy/issues
34
34
  Project-URL: Changelog, https://github.com/CheapNightbot/yutipy/blob/master/CHANGELOG.md
35
35
  Project-URL: funding, https://ko-fi.com/cheapnightbot
36
- Keywords: music,API,Deezer,iTunes,Spotify,YouTube Music,search,retrieve,information,yutify
36
+ Keywords: music,API,Deezer,iTunes,Spotify,YouTube Music,search,retrieve,information,yutify,KKBox
37
37
  Classifier: Development Status :: 4 - Beta
38
38
  Classifier: Intended Audience :: Developers
39
39
  Classifier: Topic :: Software Development :: Libraries
@@ -0,0 +1,17 @@
1
+ yutipy/__init__.py,sha256=ucXbhRgNpLo-G0TeDGCaKyCK9Ftc13hUqB8POWdUY1c,327
2
+ yutipy/deezer.py,sha256=cTQpnOgS81mUw_EJ0b2Z1r9CG9ircHCxl9vL-oAJ9Lg,9622
3
+ yutipy/exceptions.py,sha256=4L0Oe1PwFP34LoFTy-Fruipk7uB-JkaackRmkjlaZJU,1138
4
+ yutipy/itunes.py,sha256=9VOcIfjezj8WAVpsne9bbBPoIUbn0GO0UWrCrXzbrE4,6758
5
+ yutipy/kkbox.py,sha256=V-A7nFa1oNrTBOEu7DFzMHAHFZ5cPz55GInEuYfTSfg,13466
6
+ yutipy/models.py,sha256=si_qgaApAYDfSyE8cl_Yg4IfWOtxk1I5JCT8bZsmV4U,1931
7
+ yutipy/musicyt.py,sha256=igqz99bJYGtUGyZAmEJoQbdGIF-1YFmeaV5HmlhwqkA,8441
8
+ yutipy/spotify.py,sha256=462mHo2GCurRNb0RKxu2ZlbmX9ZggPg_ZHN7fb0p9t4,15620
9
+ yutipy/yutipy_music.py,sha256=I4581MvcTTclSwVtAfMEsOujxmhZzqKyG7eX8zuEsEY,6424
10
+ yutipy/utils/__init__.py,sha256=o6lk01FHwhFmNHV0HjGG0qe2azTaQT_eviiLgNV5fHw,232
11
+ yutipy/utils/cheap_utils.py,sha256=MChJ29x-yj_LrdJfWu7qQT3-gSHDdPyPEGo5ITfbJSI,4824
12
+ yutipy/utils/logger.py,sha256=2_b2FlDwUVpdPdqiwweR8Xr2tZOq0qGUGcekC5lXq2M,130
13
+ yutipy-1.4.1.dist-info/licenses/LICENSE,sha256=_89JsS2QnBG8tAb5-VWbJDj_uJ002zPJAYBJJdh3DPY,1071
14
+ yutipy-1.4.1.dist-info/METADATA,sha256=-DlkGS8lGIpG7lSewxaOR6hxikj3VdfT1avz23o2YKM,6495
15
+ yutipy-1.4.1.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
16
+ yutipy-1.4.1.dist-info/top_level.txt,sha256=t2A5V2_mUcfnHkbCy6tAQlb3909jDYU5GQgXtA4756I,7
17
+ yutipy-1.4.1.dist-info/RECORD,,
@@ -1,17 +0,0 @@
1
- yutipy/__init__.py,sha256=UIymi9iT8s1nGuqcQcFudZYNsJDR4RzXe6LUaN9V8l0,289
2
- yutipy/deezer.py,sha256=cTQpnOgS81mUw_EJ0b2Z1r9CG9ircHCxl9vL-oAJ9Lg,9622
3
- yutipy/exceptions.py,sha256=4L0Oe1PwFP34LoFTy-Fruipk7uB-JkaackRmkjlaZJU,1138
4
- yutipy/itunes.py,sha256=9VOcIfjezj8WAVpsne9bbBPoIUbn0GO0UWrCrXzbrE4,6758
5
- yutipy/kkbox.py,sha256=V-A7nFa1oNrTBOEu7DFzMHAHFZ5cPz55GInEuYfTSfg,13466
6
- yutipy/models.py,sha256=si_qgaApAYDfSyE8cl_Yg4IfWOtxk1I5JCT8bZsmV4U,1931
7
- yutipy/musicyt.py,sha256=igqz99bJYGtUGyZAmEJoQbdGIF-1YFmeaV5HmlhwqkA,8441
8
- yutipy/spotify.py,sha256=IrtCtay8UWh8zsa7d1JKrDUuZLa-PDwh8zb3K629tLo,15294
9
- yutipy/yutipy_music.py,sha256=zwnJWKy6Kdh-ewz2jHzRSo4ntKoigJa7MMKMzwgcr7A,6214
10
- yutipy/utils/__init__.py,sha256=7UFcFZ7fBtNXOTngjnRD3MeobT3x5UT2Gag94TXVgLk,169
11
- yutipy/utils/cheap_utils.py,sha256=TMas4QwOXxdIZ0t3bxxvLAQdeFCGZyzuxicbpzWJ0a0,4542
12
- yutipy/utils/logger.py,sha256=2_b2FlDwUVpdPdqiwweR8Xr2tZOq0qGUGcekC5lXq2M,130
13
- yutipy-1.4.0.dist-info/licenses/LICENSE,sha256=_89JsS2QnBG8tAb5-VWbJDj_uJ002zPJAYBJJdh3DPY,1071
14
- yutipy-1.4.0.dist-info/METADATA,sha256=U9Zl_5_k8p7xkzDGlfHGEIJuh1vR_HsmHqDIC8O4qTo,6489
15
- yutipy-1.4.0.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
16
- yutipy-1.4.0.dist-info/top_level.txt,sha256=t2A5V2_mUcfnHkbCy6tAQlb3909jDYU5GQgXtA4756I,7
17
- yutipy-1.4.0.dist-info/RECORD,,
File without changes