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

强烈建议添加序号功能 #27

Open
lgtice opened this issue May 19, 2023 · 1 comment
Open

强烈建议添加序号功能 #27

lgtice opened this issue May 19, 2023 · 1 comment

Comments

@lgtice
Copy link

lgtice commented May 19, 2023

不添加序号的话,下载下来的顺序是乱的。按时间排序有时候都不是顺序的。

@nick-ma
Copy link

nick-ma commented Nov 25, 2023

 You can do it by adding just 3 lines of code.

  1. Add a counter in fetch_track_by_ids() and then pass the count to fetch_track_by_id()
  2. In fetch_track_by_id(), use $2 to get the count parameter and then apply the count to the saved filename.
  3. Done!
# param track_id track_id
fetch_track_by_ids() {
    local count=0
    for id in $@; do
        count=$((count + 1))
        fetch_track_by_id $id $count
    done
}
# param track_id
fetch_track_by_id() {
    count=$2
    result=`curl -s "http://mobile.ximalaya.com/v1/track/baseInfo?device=iPhone&trackId=$1"|grep title`
    if [ -n "$result" ];then
        uid=`echo $result|decode_json uid|sed 's/\"//g'`
        title=`echo $result|decode_json title|sed 's/\"//g'`
        url64=`echo $result|decode_json playUrl64|sed 's/\"//g'|sed 's/\\\//g'`

        if [ -n "$url64" ];then
            title=`echo $title|sed 's/\.//g'|sed 's/\///g'`
            echo "fetching $title ..."
            echo "$url64"
            # wget "$url64" -O "$dst_dir/$count-$title.mp3"
            curl -s "$url64" -o "$dst_dir/$count-$title.mp3"
        else
            error "Failed to fetch the track, may be a paid resource."
        fi
    else
        error "The trackId $1 does not exist."
    fi
}

You can still use wget, however, I don't have wget on my Mac, so I changed the download tool to curl.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants