smallmuou / xmlyfetcher

喜马拉雅音频下载工具
443 stars 84 forks source link

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

Open lgtice opened 1 year ago

lgtice commented 1 year ago

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

nick-ma commented 1 year ago

 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.