Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

对下载歌曲模块添加验证 #42

Merged
merged 1 commit into from
Dec 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions neteasemusic/neteasemusic.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/url"
"os"
"strconv"
"strings"

"github.com/FloatTech/floatbox/binary"
"github.com/FloatTech/floatbox/file"
Expand Down Expand Up @@ -138,6 +139,13 @@ func DownloadMusic(musicID int, musicName, pathOfMusic string) error {
if response.StatusCode != 200 {
return errors.Errorf("Status Code: %d", response.StatusCode)
}

// 检查 Content-Type 是否为 HTML
contentType := response.Header.Get("Content-Type")
if strings.HasPrefix(contentType, "text/html") {
return errors.New("URL points to an HTML page instead of an MP3 file")
}

// 下载歌曲
err = file.DownloadTo(musicURL, downMusic)
process.SleepAbout1sTo2s()
Expand Down
Loading