Skip to content

Instantly share code, notes, and snippets.

@ninehills
Created September 13, 2013 08:35
Show Gist options
  • Save ninehills/6548121 to your computer and use it in GitHub Desktop.
Save ninehills/6548121 to your computer and use it in GitHub Desktop.
Submit offline download tasks to Baidu Pan.
#!/bin/sh
# by Jakukyo Friel <[email protected]>
# under Apache License, Version 2.0, <http://www.apache.org/licenses/LICENSE-2.0.html>
### Submit offline download tasks to Baidu Pan.
## Requires:
#
# - [jq](http://stedolan.github.io/jq/)
# - curl
## Usage:
#
# BaiduPanToken=1234aoeu BaiduPanPath='/apps/appname/your-dir' ./baidupan-offline-dl urls.list
#
# `urls.list` is a text file, containing urls to download. with one url per line.
# Note that `urls.list` will be modified by this script, so backup it first.
Baidupan_api_base='https://pcs.baidu.com/rest/2.0/pcs/services/cloud_dl?method='
URL_list=$1
# backup original url list file
cp $URL_list $URL_list.original
while true; do
current_downloads=`curl -s -X POST -k -L -d "" "${Baidupan_api_base}list_task&access_token=$BaiduPanToken" | jq '.total'`
if [ $current_downloads -lt 5 ] ; then
download_source=`head -1 $URL_list`
curl -X POST -k -L -d "" "${Baidupan_api_base}add_task&access_token=$BaiduPanToken&save_path=$BaiduPanPath/`basename $download_source`&source_url=$download_source" |
jq '.'
echo 'Downloading' `basename $download_source` 'to BaiduPan'
sed -i 1d $URL_list
else
sleep 6m
fi
done
@bobadilla2146
Copy link

How can I get my BaiduPanToken?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment