023/Cloud-Music-Downloader
/README.md
# Cloud Music Downloader
Cloud Music Downloader is a simple tool for downloading audio and lyrics of songs from cloud music platforms.
Features
- Multi-threaded downloading: Download in parallel to accelerate the process.
- Customizable download path: Define a custom download folder.
- Search and download: Search songs by title, artist, or album, and download them directly.
- Lyrics downloading: Download lyrics for each song automatically.
- Language selection: Choose between Chinese, English, and Japanese lyrics.
- Audio format selection: Select the audio format (MP3, AAC, etc.) you need for download.
Requirements
- Python 3.x
- Libraries: `requests`, `beautifulsoup4`, `os`, `threading`
Installation
1. Clone the repository: ```bash git clone https://github.com/qwen2023/Cloud-Music-Downloader.git ```2. Install the required Python libraries:
```bash
pip install requests beautifulsoup4
```
3. Download the `cloudmusic.css` and `cloudmusic.js` files and place them in the `static` directory.
4. Run the script:
```bash
python download_music.py
```
Usage
1. Run the script. 2. The script will prompt you to choose the language for lyrics download. 3. Enter the search query to find the song(s) you want to download. 4. Select the audio format and download path. 5. Start the download process.Example
```bash python download_music.py ```- Choose the language for lyrics download.
- Enter the search query.
- Select the audio format and download path.
- Start the download process.
License
This project is licensed under the MIT License./download_music.py
import os
import re
import requests
import threading
from bs4 import BeautifulSoup
# Global variables
download_path = os.path.expanduser('~')
download_path += '/Downloads/CMD/'
download_path = os.path.abspath(download_path)
os.makedirs(download_path, exist_ok=True)
thread_pool = [] # For multi-threaded downloading
search_count = 0
def search_song(query, language, format, download_path):
global search_count
search_count += 1
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36'
}
url = f'https://music.163.com/api/search/get/web?csrf_token='
data = {
's': query,
'type': 1,
'limit': 10,
'offset': 0
}
response = requests.post(url, headers=headers, data=data)
response.encoding = 'utf-8'
soup = BeautifulSoup(response.text, 'lxml')
search_results = soup.select('.result-list li')
song_info = []
for result in search_results:
song_name = result.select_one('.songName').text
artist = result.select_one('.s-fc7').text
album = result.select_one('.s-fc7').text
song_url = result.select_one('.songName a')['href']
song_url = 'https://music.163.com' + song_url
song_info.append((song_name, artist, album, song_url))
if search_count == 1:
print(f'Search result: {search_count}')
for idx, info in enumerate(song_info):
print(f'{idx + 1}. {info[0]} - {info[1]} / {info[2]}')
print('Please enter the number of the song you want to download:')
else:
print(f'Search result: {search_count}')
for idx, info in enumerate(song_info):
print(f'{idx + 1}. {info[0]} - {info[1]} / {info[2]}')
selected_song = input('Please enter the number of the song you want to download:')
if selected_song.isdigit():
selected_song = int(selected_song)
if 1 <= selected_song <= len(song_info):
selected_song = song_info[selected_song - 1]
print(f'Selected song: {selected_song[0]} - {selected_song[1]} / {selected_song[2]}')
download_song(selected_song[3], language, format, download_path)
else:
print('Invalid input, please enter a number between 1 and', len(song_info))
else:
print('Invalid input, please enter a number between 1 and', len(song_info))
def download_song(song_url, language, format, download_path):
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36'
}
response = requests.get(song_url, headers=headers)
response.encoding = 'utf-8'
soup = BeautifulSoup(response.text, 'lxml')
song_name = soup.select_one('#detail-title').text
artist = soup.select_one('#artist .s-fc7').text
album = soup.select_one('#album .s-fc7').text
song_id = re.search(r'/(\d+)/