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 75 76 77
| def request_info(resp):
bili_json1 = [] for a in resp['data']['medias']: # 视频搜索id av_id = a['id'] # 视频搜索av_id链接 av_id_link = a['link'] # 播放时长 n = int(a['duration']) m = int(n / 60) s = n - m * 60 # print(f"可以换算成 {m}分钟 {s}秒。") duration = f"时长:{m}分钟{s}秒"
# 类型 type = a['type'] # 标题 title = a['title']
# 去除格式和特殊符号 re_exp = u"([^\u4e00-\u9fa5\u0030-\u0039\u0041-\u005a\u0061-\u007a\’!\"#$%&\'()*+,-./:;<=>?@,。?、…【】《》?“”‘’!["u"\\]^_`{|}~\s])" video_title = str(title).strip(re_exp) # 对一些格式的保留和替换 video_name = "".join(video_title.split()) video_name = (((video_name.replace("/", "-")).replace("】", "-")).replace("[", "-")).replace("【", "-") video_name = (((video_name.replace(";", "-")).replace("\n", "")).replace("]", "-")).replace("r&b", "") video_name = (((video_name.replace("(", "-")).replace(")", "")).replace(" ", "")).replace("&", "与") video_name = (((video_name.replace("--", "-")).replace("(", "")).replace(")", "")).replace("&","") video_name = (((video_name.replace("amp;", "")).replace("|", "-")).replace("《", "")).replace("》", "") # 图片链接 cover = a['cover'] # 摘要 intro = a['intro'] # 页数 page = a['page'] # up主个人id up_mid = a['upper']['mid'] # up主昵称 up_name = a['upper']['name'] # up主头像 up_face = a['upper']['face'] # 视频id bv_id = a['bv_id'] # 视频链接 bv_link = "https://www.bilibili.com/video/" + a['bv_id'] # 该视频收藏人数 bv_collect = a['cnt_info']['collect'] # 该视频播放次数 bv_play = a['cnt_info']['play'] # 当前观看人数 bv_danmaku = a['cnt_info']['danmaku']
bili_json = { 'title': video_name, 'intro': intro, 'cover': cover, 'bv_id': bv_id, 'bv_link': bv_link, 'page': page, 'av_id': av_id, 'av_id_link': av_id_link, 'type': type, 'duration': duration, 'bv_collect': bv_collect, 'bv_play': bv_play, 'bv_danmaku': bv_danmaku, 'up_mid': up_mid, 'up_name': up_name, 'up_face': up_face, 'is_Download': 0 } bili_json1.append(bili_json)
return bili_json1
|