forked from smallmuou/xmlyfetcher
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit c25f39b
Showing
2 changed files
with
203 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# xmlyfetcher | ||
|
||
> 该工具用于下载喜马拉雅歌曲资源,可以下载单个音频资源,也可以下载整个专辑. 喜欢的请打个红心!!! | ||
## 安装 | ||
|
||
1. 安装jshon | ||
|
||
```bash | ||
wget http://kmkeen.com/jshon/jshon.tar.gz | ||
tar xzvf json.tar.gz | ||
cd jshon-20120914 | ||
make | ||
sudo make install | ||
``` | ||
PS: jshon下载地址可能会变更,请根据官网提示下载. | ||
|
||
2. 安装该工具 | ||
|
||
```bash | ||
git clone https://github.com/smallmuou/xmlyfetcher.git | ||
cd xmlyfetcher | ||
sudo cp xmlyfetcher /usr/local/bin/ | ||
sudo chmod +x /usr/local/bin/xmlyfetcher | ||
``` | ||
|
||
## 使用 | ||
|
||
```bash | ||
# 下载专辑 | ||
xmlyfetcher http://www.ximalaya.com/10553948/album/260744/ | ||
|
||
# 下载单个歌曲 | ||
xmlyfetcher 76515823 | ||
|
||
# 下载到指定目录 | ||
xmlyfetcher -o ~/Downloads http://www.ximalaya.com/10553948/album/260744/ | ||
``` | ||
PS: 可以使用`xmlyfetcher -h`查看更详细的帮助 | ||
|
||
## 许可 | ||
|
||
该开源工具具有MIT许可协议. 本工具仅限个人学习,不用于商业等用途. 所涉及的音视频资源版权归喜马拉雅所有. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
#!/bin/bash | ||
# | ||
# Copyright (C) 2014 Wenva <[email protected]> | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is furnished | ||
# to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in all | ||
# copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
# THE SOFTWARE. | ||
|
||
spushd() { | ||
pushd "$1" 2>&1> /dev/null | ||
} | ||
|
||
spopd() { | ||
popd 2>&1> /dev/null | ||
} | ||
|
||
info() { | ||
local green="\033[1;32m" | ||
local normal="\033[0m" | ||
echo -e "[${green}INFO${normal}] $1" | ||
} | ||
|
||
cmdcheck() { | ||
command -v $1>/dev/null 2>&1 || { error >&2 "Please install command $1 first."; exit 1; } | ||
} | ||
|
||
error() { | ||
local red="\033[1;31m" | ||
local normal="\033[0m" | ||
echo -e "[${red}ERROR${normal}] $1" | ||
} | ||
|
||
curdir() { | ||
if [ ${0:0:1} = '/' ] || [ ${0:0:1} = '~' ]; then | ||
echo "$(dirname $0)" | ||
elif [ -L $0 ];then | ||
name=`readlink $0` | ||
echo $(dirname $name) | ||
else | ||
echo "`pwd`/$(dirname $0)" | ||
fi | ||
} | ||
|
||
myos() { | ||
echo `uname|tr "[:upper:]" "[:lower:]"` | ||
} | ||
|
||
######################################### | ||
### GROBLE DEFINE ### | ||
######################################### | ||
|
||
VERSION=1.0.0 | ||
AUTHOR=smallmuou | ||
|
||
######################################### | ||
### ARG PARSER ### | ||
######################################### | ||
|
||
usage() { | ||
|
||
prog=`basename $0` | ||
|
||
cat << EOF | ||
$prog version $VERSION by $AUTHOR | ||
USAGE: $prog [OPTIONS] albumUrl / [trackId ... ] | ||
DESCRIPTION: | ||
This tool is used to download songs under ximalaya.com. It can download album or single song. | ||
1. How to get albumUrl? | ||
Go to http://www.ximalaya.com and click a album, it will appear at url address bar, | ||
like http://www.ximalaya.com/96246993/album/13774123/. | ||
2. How to get trackId? | ||
Go to http://www.ximalaya.com and click a song, it will appear at url address bar, | ||
like http://www.ximalaya.com/96246993/sound/76515823/. The 76515823 is the trackId. | ||
OPTIONS: | ||
-h Show this help message and exit. | ||
-o Assign output directory, if not assign, it will download current directory. | ||
EXAMPLES: | ||
$prog http://www.ximalaya.com/10553948/album/260744/ | ||
$prog 76515823 | ||
$prog -o ~/Downloads http://www.ximalaya.com/10553948/album/260744/ | ||
EOF | ||
exit 1 | ||
} | ||
|
||
# output set current directory | ||
dst_dir=. | ||
|
||
while getopts 'o:h' arg; do | ||
case $arg in | ||
h) | ||
usage | ||
;; | ||
o) | ||
dst_dir=$OPTARG | ||
;; | ||
?) | ||
usage | ||
;; | ||
esac | ||
done | ||
|
||
shift $(($OPTIND - 1)) | ||
|
||
[ ! -d $dst_dir ] && { error "The output directory $dst_dir does not exist."; exit -1; } | ||
|
||
######################################### | ||
### MAIN ENTRY ### | ||
######################################### | ||
|
||
cmdcheck jshon | ||
|
||
fetch() { | ||
result=`curl -s "http://mobile.ximalaya.com/v1/track/baseInfo?device=iPhone&trackId=$1"|grep title` | ||
if [ -n "$result" ];then | ||
uid=`echo $result|jshon -e uid|sed 's/\"//g'` | ||
title=`echo $result|jshon -e title|sed 's/\"//g'` | ||
id=`echo $result|jshon -e trackId|sed 's/\"//g'` | ||
url64=`echo $result|jshon -e playUrl64|sed 's/\"//g'|sed 's/\\\//g'` | ||
|
||
info "fetch $id $title ..." | ||
if [ -n "$url64" ];then | ||
wget "$url64" -O "$dst_dir/$title.mp3" | ||
fi | ||
else | ||
error "The albumUrl or trackId does not exist." | ||
fi | ||
} | ||
|
||
if [ "${1:0:4}" == "http" ];then | ||
ids=`curl -s $1 |awk -F\" '/sound_ids/{print $4}'|sed 's/,/ /g'` | ||
else | ||
[ $# -eq 0 ] && usage | ||
ids=$@ | ||
fi | ||
|
||
for id in $ids | ||
do | ||
fetch $id | ||
done | ||
|