Skip to content

Commit 06a83ec

Browse files
committed
update docstring for utils.py in apple-music-scraper
1 parent 648485e commit 06a83ec

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

Apple-Music-Scraper/utils.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,29 @@
77
def get_cover(url, width, height, format="jpg", crop_option=""):
88
"""
99
Generate a full Apple Music artwork URL with proper width, height, format, and crop settings.
10+
11+
Parameters
12+
----------
13+
url : str
14+
The original Apple Music artwork template URL containing `{w}`, `{h}`, `{f}`, `{c}`.
15+
width : int or str
16+
Target width of the image.
17+
height : int or str
18+
Target height of the image.
19+
format : str, optional
20+
Image format (jpg, png, etc.). Defaults to `"jpg"`.
21+
crop_option : str, optional
22+
Cropping mode used by Apple Music artwork URLs. Defaults to empty string.
23+
24+
Returns
25+
-------
26+
str
27+
Fully formatted artwork URL.
28+
29+
Notes
30+
-----
31+
Apple Music uses dynamic artwork URLs where dimensions and format are embedded
32+
in the URL as placeholders such as `{w}`, `{h}`, `{f}`, and `{c}`.
1033
"""
1134
if not isinstance(url, str):
1235
return url
@@ -26,6 +49,30 @@ def get_cover(url, width, height, format="jpg", crop_option=""):
2649
def convert_album_to_song_url(album_url):
2750
"""
2851
Convert an Apple Music album-track URL into a direct Apple Music song URL.
52+
53+
Parameters
54+
----------
55+
album_url : str
56+
Full Apple Music album URL that contains a track ID via the query parameter `?i=...`.
57+
58+
Returns
59+
-------
60+
str or None
61+
Direct Apple Music song URL if `i` parameter exists.
62+
Otherwise, returns `None`.
63+
64+
Examples
65+
--------
66+
Input:
67+
https://music.apple.com/us/album/song-name/12345?i=67890
68+
69+
Output:
70+
https://music.apple.com/us/song/song-name/67890
71+
72+
Notes
73+
-----
74+
Apple Music album pages embed individual song IDs through the query parameter `i`,
75+
which must be extracted and placed into a `/song/` URL.
2976
"""
3077
try:
3178
parsed = urllib.parse.urlparse(album_url)
@@ -51,6 +98,23 @@ def convert_album_to_song_url(album_url):
5198
def get_all_singles(url="https://music.apple.com/us/artist/king-princess/1349968534"):
5299
"""
53100
Fetch all singles & EP URLs from an Apple Music artist page.
101+
102+
Parameters
103+
----------
104+
url : str, optional
105+
Base artist page URL. Defaults to the sample King Princess artist link.
106+
107+
Returns
108+
-------
109+
list[str]
110+
A list of Apple Music URLs for all singles & EPs for the artist.
111+
112+
Notes
113+
-----
114+
- Apple Music loads singles under the `/see-all?section=singles` endpoint.
115+
- This function retrieves the serialized server data, parses the `items` section,
116+
and extracts the correct song/EP URLs.
117+
- Used internally by `artist_scrape()`.
54118
"""
55119
result = []
56120

0 commit comments

Comments
 (0)