-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathalbum_up.py
75 lines (67 loc) · 2.39 KB
/
album_up.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date : 2017-11-07 23:33:30
# @Author : Lewis Tian ([email protected])
# @GitHub : https://github.com/LewisTian
# @Version : Python3.5
import requests
from bs4 import BeautifulSoup as BS
import re
import os
from time import sleep
class Album(requests.Session):
def __init__(self):
super(Album, self).__init__()
self.api = 'http://api.vc.bilibili.com/link_draw/v1/doc/ones?poster_uid={uid}&page_size=20&next_offset={next_offset}'
self.album = []
def __del__(self):
self.close()
def update_uid(self, uid):
self.uid = uid
def run(self):
has_more = 1
next_offset = 0
self.headers.update({
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.79 Safari/537.36",
"Host":"api.vc.bilibili.com",
"Origin":"http://link.bilibili.com",
"Referer":"http://link.bilibili.com/p/center/index",
})
while has_more:
url = self.api.format(uid = self.uid, next_offset = next_offset)
r = self.get(url)
data = r.json()['data']
has_more = data['has_more']
next_offset = data['next_offset']
items = data['items']
for x in items:
upload_timestamp = x['upload_timestamp']
pics = x['pictures']
for i in pics:
self.album.append(i['img_src'])
self.download(self.album)
def download(self, pics):
'''推荐打印所有链接然后使用迅雷下载'''
for x in pics:
print(x)
'''
self.headers.update({
"Host":"i0.hdslb.com",
"Referer":"http://link.bilibili.com/p/world/index",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.79 Safari/537.36",
})
if not os.path.exists(self.uid):
os.mkdir(self.uid)
for x in pics:
name = x.split('/')[-1]
r = self.get(x)
with open(self.uid + '/' + name, 'wb') as f:
f.write(r.content)
sleep(5)
'''
if __name__ == '__main__':
a = Album()
with open('up.txt') as f:
for up in f.readlines():
a.update_uid(up)
a.run()