defgetcover(): #avnum=input("please input the av number of your video:") #url="https://www.bilibili.com/video/av"+avnum headers={ 'Host':'www.bilibili.com', 'User-Agent': 'Chrome/73.0.3683.103' } text=requests.get(url,headers=headers).text#解决反爬虫问题 a = text.find('"pic":"') b = text.find('.jpg"') need_image = text[a+7:b+4].encode("utf-8").decode("unicode_escape") cover = str(need_image) print("Cover:"+cover)
#add video info video = MP4('D:\\music\\'+title+'.m4a') withopen('D:\\music\\' + title + ".jpg", "rb") as f: video["covr"] = [ MP4Cover(f.read(), imageformat=MP4Cover.FORMAT_JPEG) ] video["\xa9nam"] = title video["\xa9ART"] = artist video["\xa9alb"] = album video.save()
#get cover from Bilibili defgetcover(): #avnum=input("please input the av number of your video:") #url="https://www.bilibili.com/video/av"+avnum headers={ 'Host':'www.bilibili.com', 'User-Agent': 'Chrome/73.0.3683.103' } text=requests.get(url,headers=headers).text#解决反爬虫问题 a = text.find('"pic":"') b = text.find('.jpg"') need_image = text[a+7:b+4].encode("utf-8").decode("unicode_escape") cover = str(need_image) print("Cover:"+cover) photo = requests.get(cover) if photo.status_code == 200: withopen('D:\\music\\' + title + ".jpg", 'wb') as f: f.write(photo.content) getcover()
#add video info video = MP4('D:\\music\\'+title+'.m4a') withopen('D:\\music\\' + title + ".jpg", "rb") as f: video["covr"] = [ MP4Cover(f.read(), imageformat=MP4Cover.FORMAT_JPEG) ] video["\xa9nam"] = title video["\xa9ART"] = artist video["\xa9alb"] = album video.save()
os.remove('D:\\music\\' + title + ".jpg") print("------------- Done -------------")