Skip to content

Commit

Permalink
try to fix speed of downloading, using -t fs
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterDing committed Apr 20, 2015
1 parent 72befef commit 6413e87
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 12 deletions.
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ shadowsocks # 用于加密上传。
https://github.com/PeterDing/iScript/wiki/%E6%89%8B%E5%8A%A8%E8%A7%A3%E5%86%B3pan.baidu.com.py%E4%BE%9D%E8%B5%96%E5%8C%85
```

#### other

[解决百度网盘下载速度问题](https://github.com/PeterDing/iScript/wiki/解决百度网盘下载速度问题)

#### 2. 使用说明

pan.baidu.com.py 是一个百度网盘的命令行客户端。
Expand Down Expand Up @@ -406,6 +410,8 @@ jca 或 jobclearall # 清除 *全部任务*
-f number, --from_ number 从第几个开始(用于download, play),eg: p /video -f 42
-t ext, --type_ ext 类型参数, 用 “,” 分隔
eg:
-t fs # 换用下载服务器,用于下载、播放
# 如果wiki中的速度解决方法不管用,可以试试加该参数
d -t dc # 下载并解密,覆盖加密文件(默认)
d -t dc,no # 下载并解密,不覆盖加密文件
dc -t no # 解密,不覆盖加密文件
Expand All @@ -428,11 +434,11 @@ jca 或 jobclearall # 清除 *全部任务*
-l amount, --limit amount 下载速度限制,eg: -l 100k
-m {o,c}, --mode {o,c} 模式: o # 重新上传. c # 连续上传.
加密方法: https://github.com/shadowsocks/shadowsocks/wiki/Encryption
-R, --recursive 递归, 用于download, play, ls, find, rmre, rnre, rmre, cpre
-R, --recursive 递归, 用于download, play, upload, ls, find, rmre, rnre, rmre, cpre
-H HEADS, --head HEADS 匹配开头的字符,eg: -H Head1 Head2
-T TAILS, --tail TAILS 匹配结尾的字符,eg: -T Tail1 Tail2
-I INCLUDES, --include INCLUDES 不排除匹配到表达的文件名, 可以是正则表达式,eg: -I "*.mp3" "*.avi"
-E EXCLUDES, --exclude EXCLUDES 排除匹配到表达的文件名, 可以是正则表达式,eg: -E "*.html" "*.jpg"
-I INCLUDES, --include INCLUDES 不排除匹配到表达的文件名, 可以是正则表达式,eg: -I ".*.mp3" ".*.avi"
-E EXCLUDES, --exclude EXCLUDES 排除匹配到表达的文件名, 可以是正则表达式,eg: -E ".*.html" ".*.jpg"
-c {on, off}, --ls_color {on, off} ls 颜色,默认是on
# -t, -H, -T, -I, -E 都能用于 download, play, ls, find, rnre, rmre, cpre, mvre
Expand Down Expand Up @@ -491,6 +497,9 @@ bp cd ...
#### 下载:

```
## 下载、播放速度慢?
如果wiki中的速度解决方法不管用,可以试试加该参数 -t fs
# 下载当前工作目录 (递归)
bp d . -R
Expand Down
41 changes: 32 additions & 9 deletions pan.baidu.com.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,30 @@ def cd(cwd, part):
cwd = os.path.join(cwd, part)
return cwd

if path[0] == '/':
if not path or path[0] == '/':
return path
else:
parts = path.split('/')
for p in parts:
cwd = cd(cwd, p)
return cwd

def fast_pcs_server(j):
if 'fs' not in args.type_:
return j

do = lambda dlink: \
re.sub(r'://[^/]+?/', '://www.baidupcs.com/', dlink)
#re.sub(r'://[^/]+?/', '://c.pcs.baidu.com/', dlink)

if isinstance(j, dict) and j.get('info') and len(j['info']) > 0:
for i in xrange(len(j['info'])):
if j['info'][i].get('dlink'):
j['info'][i]['dlink'] = do(j['info'][i]['dlink'])
else:
j = do(j)
return j

# https://stackoverflow.com/questions/1094841/reusable-library-to-get-human-readable-version-of-file-size
def sizeof_fmt(num):
for x in ['B','KB','MB','GB']:
Expand Down Expand Up @@ -374,8 +390,9 @@ def login(self, username, password):
def save_cookies(self, username=None, on=0, tocwd=False):
if not username: username = self.user
accounts = self.accounts
accounts[username] = {}
accounts[username]['cookies'] = ss.cookies.get_dict()
accounts[username] = accounts.get(username, {})
accounts[username]['cookies'] = \
accounts[username].get('cookies', ss.cookies.get_dict())
accounts[username]['on'] = on
quota = self._get_quota()
capacity = '%s/%s' % (sizeof_fmt(quota['used']), sizeof_fmt(quota['total']))
Expand Down Expand Up @@ -818,6 +835,7 @@ def _download_do(infos):
print '\n ++ download: #', s % (1, 97, infos['nn']), '/', \
s % (1, 97, infos['total_file']), '#', col

#cookie = 'BDUSS=%s' % ss.cookies.get('BDUSS')
if args.aria2c:
quiet = ' --quiet=true' if args.quiet else ''
taria2c = ' -x %s -s %s' % (args.aria2c, args.aria2c)
Expand Down Expand Up @@ -944,8 +962,12 @@ def _meta(self, file_list, dlink=0):
r = ss.post(url, params=p, data=data)
js = r.json()
if js['errno'] == 0 and i == 0:
if dlink:
js = fast_pcs_server(js)
j = js
elif js['errno'] == 0:
if dlink:
js = fast_pcs_server(js)
j['info'].append(js['info'])
else:
return False
Expand Down Expand Up @@ -1930,7 +1952,7 @@ def _filemanager(self, opera, data):
elif j['errno'] == 12:
print s % (1, 91, ' !! Error at filemanager:'), "部分文件已存在于目标文件夹中"
else:
print s % (1, 91, ' !! Error at filemanager')
print s % (1, 91, ' !! Error at filemanager'), j

def move(self, paths, remotepath, check=True):
paths = [ make_server_path(self.cwd, path) for path in paths ]
Expand Down Expand Up @@ -2023,7 +2045,7 @@ def rename(self, path, remotepath):
s % (1, 91, 'is existed.')
sys.exit(1)

base_dir = os.path.split(remotepath)[0]
base_dir, newname = os.path.split(remotepath)
meta = self._meta([base_dir])
if not meta:
self._make_dir(base_dir)
Expand All @@ -2035,7 +2057,7 @@ def rename(self, path, remotepath):
t = [{
'path': path,
'dest': base_dir,
'newname': os.path.basename(remotepath)
'newname': newname
}]
data = 'filelist=' + urllib.quote_plus(json.dumps(t))
self._filemanager('move', data)
Expand Down Expand Up @@ -2793,7 +2815,8 @@ def get_infos(self):
r = ss.post(url, data=data, params=self.params)
j = r.json()
if not j['errno']:
self.infos['dlink'] = j['dlink'].encode('utf8')
dlink = fast_pcs_server(j['dlink'].encode('utf8'))
self.infos['dlink'] = dlink
if args.play:
panbaiducom_HOME._play_do(self.infos)
else:
Expand All @@ -2815,7 +2838,7 @@ def get_infos2(self, path):
'name': name,
'file': os.path.join(os.getcwd(), name),
'dir_': os.getcwd(),
'dlink': dlink.group(1)
'dlink': fast_pcs_server(dlink.group(1))
}
if args.play:
panbaiducom_HOME._play_do(self.infos)
Expand Down Expand Up @@ -2846,7 +2869,7 @@ def do4(self, paths):
'name': name,
'file': os.path.join(os.getcwd(), name),
'dir_': os.getcwd(),
'dlink': path
'dlink': fast_pcs_server(path)
}

if args.play:
Expand Down

0 comments on commit 6413e87

Please sign in to comment.