my blog
Posts: 网易云音乐歌单批连下载歌曲(python)
网易云音乐歌单批连下载歌曲
使用 metting api 批量下载网易云音乐歌曲
最新版:v.24-07-19
Github Rope: https://github.com/God-2077/python-code/blob/main/网易云音乐歌单批量下载歌曲/
说明
下载最新版
安装第三方库
pip install -r requirements.txt
requirements.txt
quote
requests
tabulate
mutagen
运行
python ***.py
源码
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import os
import requests
from mutagen.mp3 import MP3
import time
import signal
import sys
import re
from tabulate import tabulate
def download_file(url, file_path, file_type, index, total_files, timeout=10):
try:
response = requests.get(url, stream=True, timeout=timeout)
response.raise_for_status()
total_size = int(response.headers.get('content-length', 0))
downloaded_size = 0
with open(file_path, "wb") as file:
for data in response.iter_content(chunk_size=4096):
downloaded_size += len(data)
file.write(data)
progress = downloaded_size / total_size * 100 if total_size > 0 else 0
print(f"正在下载 [{
index}/{
total_files}][{
file_type}] {
file_path},进度:{
progress:.2f}%\r", end="")
print(f"下载完成 [{
index}/{
total_files}][{
file_type}] {
file_path}")
return True
except requests.exceptions.RequestException as e:
print(f"下载 [{
index}/{
total_files}][{
file_type}] {
file_path} 失败:{
e}")
return False
def download_lyrics(url, lrc_path, song_index, total_songs):
try:
response = requests.get(url, timeout=10)
response.raise_for_status()
with open(lrc_path, "w", encoding="utf-8") as lrc_file:
lrc_file.write(response.content.decode('utf-8'))
print(f"下载完成 [{
song_index}/{
total_songs}][LRC] {
lrc_path}")
return

最低0.47元/天 解锁文章
2601

被折叠的 条评论
为什么被折叠?



