Greasy Fork is available in English.

网易云音乐信息快速获取

解析下载链接

Autor
水煮木头
Installationen heute
0
Installationen gesamt
350
Bewertungen
0 0 0
Version
0.1.8
Erstellt am
02.05.2023
Letzte Aktualisierung
27.01.2024
Lizenz
MIT
Wird angewandt auf

网易云音乐相关信息的获取脚本

我想说的

我实际上并未学过JS,所以脚本写的比较烂,东西都是东抄西抄来的,比较拉,但起码有些最基础的功能。

功能介绍

这个脚本能够获取网易云音乐音乐详情页的信息并自动复制到剪贴板中。获取的信息包括下载链接、封面链接、标题、副标题、歌手、专辑。

使用

该脚本仅限在 https://music.163.com/#/song?id= 下的页面可以使用,即在歌曲的详情页。它可以获取网页中歌曲的标题、歌手、专辑和封面链接,同时通过查询网络请求获得下载链接,通过console控制台打印,同时按照一个特定的格式复制到剪贴板,同时再在左侧按钮的下方增加两个链接,分别是歌曲链接和封面链接。点击任意一个链接时都会复制歌手 - 歌名(副标题)为格式的文件名称,方便复制粘贴用于手动下载。

在歌曲页面下,左侧会有一个按钮(不能保证显示位置准确),点击它,将自动点击播放按钮,并在等待2秒后查询网络请求,再获取基本信息,最后复制内容到剪贴板。

额外一提,脚本的第116行是设置延迟的地方,有注释引导设置。可以通过修改116行的数值更改延迟时间

值得注意的是,这不是一个下载脚本,但是复制到剪贴板的内容确是为了适应一个zsh脚本的(Windows大都不能用)。这里附上脚本(用于拥有zsh的人复制使用):

(注:该脚本为整合后的,具有下载、转换、添加信息的全部功能,需要辅助ffmpegwgetsed等工具使用,否则脚本将无法正常运行)

#!/usr/bin/zsh

#================================================================
#   Copyright (C) 2023 YouLanjie
#   
#   文件名称:music_download.sh
#   创 建 者:水煮木头
#   创建日期:2023年06月09日
#   描    述:下载网易云音乐(一站式解决)
#
#================================================================

app_name="${0##*/}"

F_B='\033[1m'
F_I='\033[3m'
F_U='\033[4m'
F_S='\033[5m'
F_R='\033[7m'

F_black='\033[30m'
F_red='\033[31m'
F_green='\033[32m'
F_yellow='\033[33m'
F_blue='\033[34m'
F_purple='\033[35m'
F_cyan='\033[36m'
F_white='\033[37m'

F_C='\033[0m'

F_line="$F_B$F_red-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*$F_C"

# Show an INFO message
# $1: message string
# $2: style string
_msg_info() {
    local _msg="${1}"
    local _color="${2}"
    [[ "${quiet}" == "y" ]] || printf "$F_B${F_green}[%s] INFO:$F_cyan$F_I$_color %s$F_C\n" "${app_name}" "${_msg}"
}

# Show a WARNING message
# $1: message string
_msg_warning() {
    local _msg="${1}"
    printf "$F_B${F_yellow}[%s] WARNING:$F_I %s$F_C\n" "${app_name}" "${_msg}" >&2
}

# Show an ERROR message then exit with status
# $1: message string
# $2: exit code number (with 0 does not exit)
_msg_error() {
    local _msg="${1}"
    local _error=${2}
    printf "$F_B${F_red}[%s] ERROR:$F_I %s$F_C\n" "${app_name}" "${_msg}" >&2
    if (( _error > 0 )); then
        exit "${_error}"
    fi
}

usage() {
    echo "\
usage: $app_name [options]
  options:
     -i           设置备用输入文件夹
     -n           查找备用文件时使用通配符查找
     -h           帮助信息"
    exit $1
}

get_info() {
    # 获取音频信息
    _msg_info "没有的信息可不填空着"
    _msg_info "音频链接:" && read link
    _msg_info "封面链接:" && read img_link
    _msg_info "音乐名称:" && read title
    _msg_info "别称:" && read subtitle
    _msg_info "作者:" && read artist
    _msg_info "专辑:" && read album
    clear
    # 获取没有后缀的下载链接
    link=$(echo $link|sed "s/?authSecret=.*//")
    # 获取高清的封面链接
    img_link=$(echo "$img_link" |sed 's/\(^.*\.jpg\).*/\1/')
    # 获取文件后缀名
    extension=$(echo $link|sed "s/.*\.//")
    # 设置文件名(没有扩展名)
    format=$(printf "${artist} - ${title}(${subtitle})")
    if [[ $subtitle == "" ]] {
        format=$(printf "${artist} - ${title}")
    }
}

download() {
    get_info
    _msg_info "音频链接: $link"
    # 下载音频
    name_f="${format}.${extension}"
    if [[ $link != "" ]] {
        echo $F_line
        _msg_info "wget \"$link\" -O \"$name_f\""
        wget "$link" -O "$name_f"||(_msg_warning "错误!下载出错" && exit -1)
    } elif [[ $input_dir != "" ]] {
        [[ $flag_name == "true" ]] && name_f="*.${extension}"
        _msg_info "mv \""$input_dir/$name_f"\" -O \"$name_f\""
        [[ -f "$input_dir/$name_f" ]] && (mv "$input_dir/$name_f" "$name_f" || (_msg_warning "错误!移动文件出错" && exit -1))
    }
    # 下载封面
    name_f="${format}.jpg"
    _msg_info "wget \"$img_link\" -O \"$name_f\""
    wget "$img_link" -O "$name_f"
}

m4a_to_mp3() {
    # 输入文件
    input_f="${format}.m4a"
    # 输出文件
    out_f="${format}.mp3"

    # 检查
    if [[ -e $out_f ]] {
        _msg_info "$input_f"
        _msg_info "输出文件已存在,跳过" "$F_yellow"
        echo "$F_line"
            return 0
    }
    _msg_info "输入文件:'$input_f'"
    _msg_info "ffmpeg -i \"$input_f\" \"$out_f\""
    echo "$F_line"
    _msg_info "以下为程序输出:"
    (ffmpeg -i "$input_f" "$out_f" && rm "$input_f" && _msg_info "'$input_f' 完成转换!" "$F_yellow") || (_msg_warning "'$input_f' 转换出现问题!" && exit -1)
}

check_dir() {
    # 设置输出目录
    if [[ -e "./out" ]] {
        if [[ ! -d "./out" ]] {
            _msg_warning "存在输出目录同名文件,为防止出错,退出"
            exit -1
        }
    }
    if [[ ! -d "./out" ]] {
        _msg_info "不存在输出目录,将创建" "$F_yellow"
        mkdir "./out" || (_msg_warning "创建文件夹失败,退出" && exit -1)
    }
}

add_info() {
    # 输入文件
    input_f="${format}.mp3"
    # 输出文件
    out_f="./out/${format}.mp3"
    icon="${format}.jpg"

    [[ $album == "" ]] && album=$title

    # 检查
    check_dir
    if [[ -e $out ]] {
        _msg_info $i
        _msg_info "输出文件已存在,跳过" "$F_yellow"
        echo "$F_line"
        return 0
    }

    echo "$F_line"
    _msg_info "'$input_f'"
    _msg_info "$title"
    _msg_info "$artist"
    _msg_info "$icon"
    echo "$F_line"
    # 设置图标
    _msg_info "以下为程序输出:"
    if [[ -f "$icon" ]] {
        (ffmpeg\
                -i "$input_f"                                 \
                -i "$icon" -map 0:0 -map 1:0 -id3v2_version 3 \
                -c copy                                       \
                -metadata album="$album"                      \
                -metadata artist="$artist"                    \
                -metadata title="$title"                      \
                -metadata TIT3="$subtitle"                    \
                -metadata:s:v title='Album cover'             \
                -metadata:s:v comment='Cover (Front)'         \
                "$out_f" &&
                rm "$input_f" "$icon" &&
                _msg_info "'$input_f' 完成转换!" "$F_yellow"
            ) || _msg_warning "'$input_f' 转换出现问题!"
    } else {
        (ffmpeg\
            -i "$input_f"                                 \
            -c copy                                       \
            -metadata album="$album"                      \
            -metadata artist="$artist"                    \
            -metadata title="$title"                      \
                -metadata TIT3="$subtitle"                    \
            -metadata:s:v title='Album cover'             \
            -metadata:s:v comment='Cover (Front)'         \
            "$out_f" &&
            rm "$input_f" &&
            _msg_info "'$input_f' 完成转换!" "$F_yellow"
        ) || _msg_warning "'$input_f' 转换出现问题!"
    }
}

running() {
    for i ({1..100}) {
        echo $F_line
        download
        [[ $file_type != "mp3" ]] && echo "$F_line"
        [[ $file_type != "mp3" ]] && m4a_to_mp3
        echo "$F_line"
        add_info
    }
}

link=""
img_link=""
title=""
subtitle=""
artist=""
album=""

format=""
extension="m4a"

input_dir=""
flag_name="false"
while {getopts "i:nh" OPTION} {
    case $OPTION {
        i) input_dir=$OPTARG ;;
        n) flag_name="true" ;;
        h|?) usage ;;
        *) usage -1 ;;
    }
}

running