Skip to content

Commit

Permalink
🎰支持批量下载图集 #179
Browse files Browse the repository at this point in the history
  • Loading branch information
Johnserf-Seed committed Aug 30, 2022
1 parent ae2b0d6 commit 25d4f65
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions Util/Download.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
-------------------------------------------------
Change Log :
2022/08/11 22:02:49 : Init
2022/08/30 00:30:09 : Add ImageDownload()
-------------------------------------------------
'''

Expand Down Expand Up @@ -179,5 +180,52 @@ def VideoDownload(self, profileData):
print('[ 提示 ]:该页视频资源没有35个,已为您跳过!\r')
break

def ImageDownload(self, datas):
self.check = Util.CheckInfo()

for i in range(len(datas)):
self.nickname = datas[i][0]
self.desc = Util.replaceT(datas[i][1])
self.create_time = Util.time.strftime(
'%Y-%m-%d %H.%M.%S', Util.time.localtime(datas[i][2]))
self.position = datas[i][3]
self.number = datas[i][4]
self.images = datas[i][5]
self.sprit = Util.sprit

path = "Download" + self.sprit + "pic" + self.sprit + \
self.nickname + self.sprit + self.create_time + self.desc
# 检测下载目录是否存在
if not Util.os.path.exists(path):
Util.os.makedirs(path)
# 图片目录
p_url = 'Download' + self.sprit + 'pic' + self.sprit + self.nickname + self.sprit + \
self.create_time + self.desc + self.sprit + \
self.create_time + self.desc + \
'_' + str(i) + '.jpeg'

for i in range(self.number):
# 检查图片下载情况
if Util.os.path.exists(p_url):
print('[ 提示 ]: %s%s [文件已存在,为您跳过]' %
(self.create_time, self.create_time + self.desc + '_' + str(i) + '.jpeg'), end="")
Util.log.info('[ 提示 ]:%s[文件已存在,为您跳过]' % self.create_time + self.desc + '_' + str(i) + '.jpeg')
print('\r')
continue
else:
print('\r')

# 尝试下载图片
try:
picture = Util.requests.get(
url=self.images[i], headers=Util.headers)
with open(p_url, 'wb') as file:
file.write(picture.content)
print('[ 提示 ]: %s%s_%s.jpeg下载完毕!\r' %
(self.create_time, self.desc, str(i+1)))
except Exception as error:
print('[ 错误 ]:%s\r' % error)
print('[ 提示 ]:发生了点意外!\r')

if __name__ == '__main__':
Download()

0 comments on commit 25d4f65

Please sign in to comment.