Created
November 23, 2018 15:29
-
-
Save lxfly2000/c57edfaae6e5f24eadf912175a134e9b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#coding=utf-8 | |
#Python 3.7 | |
#运行时将此文件放在Bilibili下载目录中 | |
#对目录中所有文件夹,若发现文件夹含有同名的.dvi文件且没有cover图片,则下载文件中CoverURL的图片到cover.[CoverURL的扩展名] | |
import os | |
import json | |
from urllib import request | |
def downloadFromURL(src_url,save_name): | |
print("下载\"%s\"到\"%s\"…"%(src_url,save_name)) | |
url_file=request.urlopen(src_url) | |
save_file=open(save_name,"wb").write(url_file.read()) | |
for video_dir in os.listdir(): | |
#对目录中所有文件夹 | |
if os.path.isdir(video_dir): | |
#若发现dvi文件 | |
if os.path.exists(os.path.join(video_dir,video_dir+".dvi")): | |
#获取CoverURL | |
jsonFile=open(os.path.join(video_dir,video_dir+".dvi"),encoding="utf-8") | |
try: | |
jsonStr=jsonFile.read() | |
finally: | |
jsonFile.close() | |
cover_url=json.loads(jsonStr)["CoverURL"] | |
cover_path=os.path.join(video_dir,"cover"+cover_url[cover_url.rfind("."):]) | |
#若发现没有cover文件 | |
if not os.path.exists(cover_path): | |
downloadFromURL(cover_url,cover_path) | |
else: | |
print("\"%s\"已经存在。"%(cover_path)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment