Apple Music Search

by RFour · Jul 9, 2026 ·javascript

You can Search music's and more stuff from this Apple Music Search

AppleMusicSearchJS
main.jsjavascript
1const axios = require('axios');
2const cheerio = require('cheerio');
3
4async function applemusicsearch(search) {
5    const { data: html } = await axios.get(`https://music.apple.com/us/search?term=${encodeURIComponent(search)}`, {
6        headers: {
7            'accept-language': 'en-US,en;q=0.9',
8            'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'
9        }
10    });
11
12    const $ = cheerio.load(html);
13    const results = {
14        topResults: [],
15        songs: [],
16        albums: [],
17        artists: [],
18        playlists: [],
19        radioEpisodes: [],
20        stations: [],
21        musicVideos: [],
22        videoExtras: []
23    };
24
25    const getImage = (srcset) => {
26        if (!srcset) return null;
27        const match = srcset.split(',')[0].match(/(https:\/\/[^\s]+)/);
28        return match && match[1].includes('mzstatic.com') ? match[1] : null;
29    };
30
31    const cleanText = (text) => text ? text.replace(/[ ·\s]+/g, ' ').trim() : '';
32
33    $('div[aria-label="Top Results"] .top-search-lockup').each((_, el) => {
34        const title = cleanText($(el).find('.top-search-lockup__primary__title').text());
35        const subtitle = cleanText($(el).find('.top-search-lockup__secondary').text());
36        const url = $(el).find('.click-action').attr('href') || null;
37        const image = getImage($(el).find('.artwork-component picture source[type="image/webp"]').attr('srcset'));
38        const explicit = $(el).find('[data-testid="explicit-badge"]').length > 0;
39        if (title) results.topResults.push({ title, subtitle: subtitle || null, url, image, explicit });
40    });
41
42    $('div[aria-label="Songs"] .track-lockup').each((_, el) => {
43        const title = cleanText($(el).find('.track-lockup__title a').text());
44        const artist = cleanText($(el).find('.track-lockup__subtitle a').text());
45        const url = $(el).find('.track-lockup__title a').attr('href') || null;
46        const image = getImage($(el).find('.artwork-component picture source[type="image/webp"]').attr('srcset'));
47        const explicit = $(el).find('[data-testid="explicit-badge"]').length > 0;
48        if (title) results.songs.push({ title, artist: artist || null, url, image, explicit });
49    });
50
51    $('div[aria-label="Artists"] .ellipse-lockup').each((_, el) => {
52        const name = cleanText($(el).find('.title').text());
53        const url = $(el).closest('a').attr('href') || null;
54        const image = getImage($(el).find('.artwork-component picture source[type="image/webp"]').attr('srcset'));
55        if (name) results.artists.push({ name, url, image });
56    });
57
58    $('div[aria-label="Albums"] .product-lockup').each((_, el) => {
59        const title = cleanText($(el).find('.product-lockup__title').text());
60        const artist = cleanText($(el).find('.product-lockup__subtitle').text());
61        const url = $(el).find('.product-lockup__link').attr('href') || null;
62        const image = getImage($(el).find('.artwork-component picture source[type="image/webp"]').attr('srcset'));
63        const explicit = $(el).find('[data-testid="explicit-badge"]').length > 0;
64        if (title) results.albums.push({ title, artist: artist || null, url, image, explicit });
65    });
66
67    $('div[aria-label="Playlists"] .product-lockup').each((_, el) => {
68        const title = cleanText($(el).find('.product-lockup__title').text());
69        const curator = cleanText($(el).find('.product-lockup__subtitle').text());
70        const url = $(el).find('.product-lockup__link').attr('href') || null;
71        const image = getImage($(el).find('.artwork-component picture source[type="image/webp"]').attr('srcset'));
72        if (title) results.playlists.push({ title, curator: curator || 'Apple Music', url, image });
73    });
74
75    $('div[aria-label="Radio Episodes"] .product-lockup').each((_, el) => {
76        const title = cleanText($(el).find('.product-lockup__title').text());
77        const show = cleanText($(el).find('.product-lockup__subtitle').text()) || cleanText($(el).find('.lockup-column__secondary-headline').text());
78        const url = $(el).find('.product-lockup__link').attr('href') || null;
79        const image = getImage($(el).find('.artwork-component picture source[type="image/webp"]').attr('srcset'));
80        if (title) results.radioEpisodes.push({ title, show: show || null, url, image });
81    });
82
83    $('div[aria-label="Stations"] .product-lockup').each((_, el) => {
84        const title = cleanText($(el).find('.product-lockup__title').text());
85        const url = $(el).find('.product-lockup__link').attr('href') || null;
86        const image = getImage($(el).find('.artwork-component picture source[type="image/webp"]').attr('srcset'));
87        if (title) results.stations.push({ title, url, image });
88    });
89
90    $('div[aria-label="Music Videos"] .vertical-video').each((_, el) => {
91        const titleEl = $(el).find('.vertical-video__title a');
92        const title = cleanText(titleEl.text());
93        const url = titleEl.attr('href') || null;
94        const allText = cleanText($(el).text());
95        const artist = allText.replace(title, '').trim().split('\n')[0] || null;
96        const image = getImage($(el).find('.artwork-component picture source[type="image/webp"]').attr('srcset'));
97        const explicit = $(el).find('[data-testid="explicit-badge"]').length > 0;
98        if (title) results.musicVideos.push({ title, artist: artist || null, url, image, explicit });
99    });
100
101    $('div[aria-label="Video Extras"] .vertical-video').each((_, el) => {
102        const titleEl = $(el).find('.vertical-video__title a');
103        const title = cleanText(titleEl.text());
104        const url = titleEl.attr('href') || null;
105        const allText = cleanText($(el).text());
106        const artist = allText.replace(title, '').trim().split('\n')[0] || null;
107        const image = getImage($(el).find('.artwork-component picture source[type="image/webp"]').attr('srcset'));
108        if (title) results.videoExtras.push({ title, artist: artist || null, url, image });
109    });
110
111    return results;
112}
113
114async function applemusic(search) {
115    return applemusicsearch(search);
116}
117
118applemusic('miguel phonk').then(console.log);
raw