| const axios = require('axios'); | |
| const cookieString = "_ga=GA1.1.206983766.1756790346; PHPSESSID=jomn6brkleb5969a3opposidru; quality=m4a; dcount=2; _ga_382FSD5=GS2.1.s1756858170$o3$g1$t1756858172$j58$l0$h0"; | |
| const axiosInstance = axios.create({ | |
| headers: { | |
| 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36', | |
| 'Cookie': cookieString | |
| } | |
| }); | |
| function encodeDownloadUrl(url) { | |
| if (!url) return url; | |
| return url.replace(/ /g, '%20'); | |
| } | |
| function detectUrlType(url) { | |
| if (url.includes('/song/')) { | |
| return 'song'; | |
| } else if (url.includes('/album/') && url.includes('?i=')) { | |
| return 'song'; | |
| } else if (url.includes('/album/') && !url.includes('?i=')) { | |
| return 'album'; | |
| } else { | |
| return 'song'; | |
| } | |
| } | |
| async function apple(url) { | |
| try { | |
| const urlType = detectUrlType(url); | |
| if (urlType === 'album') { | |
| return await downloadAlbum(url); | |
| } else { | |
| return await downloadSong(url); | |
| } | |
| } catch (error) { | |
| return { | |
| author: "Herza", | |
| status: 500, | |
| source: "error", | |
| data: { | |
| error: error.message, | |
| message: 'Download gagal dari aaplmusicdownloader' | |
| } | |
| }; | |
| } | |
| } | |
| async function downloadSong(url) { | |
| await axiosInstance.get('https://aaplmusicdownloader.com/ifCaptcha.php'); | |
| const endpoint = url.includes('/song/') | |
| ? 'https://aaplmusicdownloader.com/api/song_url.php' | |
| : 'https://aaplmusicdownloader.com/api/applesearch.php'; | |
| const searchResponse = await axiosInstance.get(`${endpoint}?url=${encodeURIComponent(url)}`, { | |
| headers: { | |
| 'Accept': 'application/json, text/javascript, */*; q=0.01', | |
| 'X-Requested-With': 'XMLHttpRequest', | |
| 'Referer': 'https://aaplmusicdownloader.com/' | |
| } | |
| }); | |
| const searchData = searchResponse.data; | |
| await axiosInstance.get('https://aaplmusicdownloader.com/song.php', { | |
| headers: { | |
| 'Referer': 'https://aaplmusicdownloader.com/' | |
| } | |
| }); | |
| await axiosInstance.get('https://aaplmusicdownloader.com/ifCaptcha.php', { | |
| headers: { | |
| 'Referer': 'https://aaplmusicdownloader.com/song.php' | |
| } | |
| }); | |
| const formData = `song_name=${encodeURIComponent(searchData.name)}&artist_name=${encodeURIComponent(searchData.artist)}&url=${encodeURIComponent(url)}&token=none&zip_download=false&quality=m4a`; | |
| const downloadResponse = await axiosInstance.post('https://aaplmusicdownloader.com/api/composer/swd.php', formData, { | |
| headers: { | |
| 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', | |
| 'Accept': 'application/json, text/javascript, */*; q=0.01', | |
| 'X-Requested-With': 'XMLHttpRequest', | |
| 'Referer': 'https://aaplmusicdownloader.com/song.php' | |
| } | |
| }); | |
| const downloadData = downloadResponse.data; | |
| const downloadLink = downloadData.dlink || downloadData.wmcode; | |
| return { | |
| author: "Herza", | |
| status: 200, | |
| source: "aaplmusicdownloader", | |
| type: "song", | |
| data: { | |
| name: searchData.name, | |
| albumname: searchData.albumname, | |
| artist: searchData.artist, | |
| thumb: searchData.thumb, | |
| duration: searchData.duration, | |
| downloadLink: encodeDownloadUrl(downloadLink), | |
| status: downloadData.status | |
| } | |
| }; | |
| } | |
| async function downloadAlbum(url) { | |
| await axiosInstance.get('https://aaplmusicdownloader.com/ifCaptcha.php'); | |
| const playlistResponse = await axiosInstance.get(`https://aaplmusicdownloader.com/api/pl.php?url=${encodeURIComponent(url)}`, { | |
| headers: { | |
| 'Accept': 'application/json, text/javascript, */*; q=0.01', | |
| 'X-Requested-With': 'XMLHttpRequest', | |
| 'Referer': 'https://aaplmusicdownloader.com/' | |
| } | |
| }); | |
| const albumData = playlistResponse.data.album_details; | |
| const firstSong = albumData[0]; | |
| await axiosInstance.get('https://aaplmusicdownloader.com/album.php', { | |
| headers: { | |
| 'Referer': 'https://aaplmusicdownloader.com/' | |
| } | |
| }); | |
| await axiosInstance.get('https://aaplmusicdownloader.com/ifCaptcha.php', { | |
| headers: { | |
| 'Referer': 'https://aaplmusicdownloader.com/album.php' | |
| } | |
| }); | |
| const formData = `song_name=${encodeURIComponent(firstSong.name)}&artist_name=${encodeURIComponent(firstSong.artist.replace(/&/g, '&'))}&url=${encodeURIComponent(firstSong.link)}&token=na&zip_download=false&quality=m4a`; | |
| const downloadResponse = await axiosInstance.post('https://aaplmusicdownloader.com/api/composer/swd.php', formData, { | |
| headers: { | |
| 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', | |
| 'Accept': 'application/json, text/javascript, */*; q=0.01', | |
| 'X-Requested-With': 'XMLHttpRequest', | |
| 'Referer': 'https://aaplmusicdownloader.com/album.php' | |
| } | |
| }); | |
| const downloadData = downloadResponse.data; | |
| const downloadLink = downloadData.dlink || downloadData.wmcode; | |
| return { | |
| author: "Herza", | |
| status: 200, | |
| source: "aaplmusicdownloader", | |
| type: "album", | |
| data: { | |
| name: firstSong.name, | |
| albumname: firstSong.album, | |
| artist: firstSong.artist.replace(/&/g, '&'), | |
| thumb: firstSong.thumb, | |
| duration: firstSong.duration, | |
| downloadLink: encodeDownloadUrl(downloadLink), | |
| status: downloadData.status | |
| } | |
| }; | |
| } | |
| const handler = async (req, res) => { | |
| try { | |
| const { url } = req.query; | |
| if (!url) { | |
| return res.status(400).json({ | |
| success: false, | |
| error: 'Missing required parameter: url' | |
| }); | |
| } | |
| const result = await apple(url); | |
| if (result.status === 500) { | |
| return res.status(500).json({ | |
| success: false, | |
| error: result.data.error, | |
| message: result.data.message | |
| }); | |
| } | |
| res.json({ | |
| author: "Herza", | |
| success: true, | |
| msg: result.data | |
| }); | |
| } catch (error) { | |
| res.status(500).json({ | |
| success: false, | |
| error: error.message | |
| }); | |
| } | |
| }; | |
| module.exports = { | |
| name: 'Apple Music DL', | |
| description: 'Download Apple Music Song or Album', | |
| type: 'GET', | |
| routes: ['api/download/applemusic'], | |
| tags: ['downloader', 'tools', 'misc'], | |
| parameters: ['url', 'key'], | |
| enabled: true, | |
| main: ['Downloader'], | |
| handler | |
| } |