예제 #1
0
 def download_dm(self, cid, filepath):
     request = BilibiliApi.build_dm_api_request(cid)
     response = RequestUtil.do_request(request, load_json=False)
     self.before_response(response)
     SaveTool.saveText(response.raw_response.text,
                       f'{filepath}.xml',
                       encoding=response.raw_response.encoding)
예제 #2
0
 def test_bilibili_aid_api(self, aid):
     request = BilibiliApi.build_aid_api_request(aid)
     data = self.do_request_and_check_response(request)
     assert 'title' in data
     assert 'owner' in data
     assert 'pages' in data
     assert isinstance(data['pages'], list)
예제 #3
0
 def get_oid_info_by_page(self, page):
     request = BilibiliApi.build_oid_api_request(self.up_id,
                                                 page,
                                                 order=self.order,
                                                 keyword=self.keyword)
     response = RequestUtil.do_request(request)
     self.before_response(response)
     return self._decode_oid_info(response.data)
예제 #4
0
 def test_bilibili_cid_api(self, aid, cid):
     request = BilibiliApi.build_cid_api_request(aid, cid)
     data = self.do_request_and_check_response(request)
     assert 'quality' in data
     assert 'format' in data
     if 'durl' in data:
         assert isinstance(data['durl'], list)
     elif 'dash' in data:
         assert isinstance(data['dash'], dict)
     else:
         assert False
예제 #5
0
 def download_video(self, url, filename):
     final_filename = PathUtil.join_path(CONFIG['DOWNLOAD_PATH'], filename)
     if PathUtil.check_path(final_filename):
         print(f'{final_filename} exists, stop downloading')
         return final_filename
     print(f'{filename} download start')
     request = BilibiliApi.build_video_download_request(url)
     response = RequestUtil.do_request(request, load_json=False)
     self.before_response(response)
     self.save_video(response.raw_response, final_filename)
     return final_filename
예제 #6
0
 def test_bilibili_archive_api(self, aid):
     request = BilibiliApi.build_archive_api_request(aid)
     data = self.do_request_and_check_response(request)
     assert 'view' in data
     assert 'danmaku' in data
     assert 'reply' in data
     assert 'favorite' in data
     assert 'coin' in data
     assert 'share' in data
     assert 'like' in data
     assert 'now_rank' in data
     assert 'his_rank' in data
 def test_bilibili_sign_cid_api(self, cid):
     request = BilibiliApi.build_sign_cid_api_request(cid)
     response = RequestUtil.do_request(request)
     assert response.status_code == 200
     data = response.json
     assert 'quality' in data
     assert 'format' in data
     if 'durl' in data:
         assert isinstance(data['durl'], list)
     elif 'dash' in data:
         assert isinstance(data['dash'], dict)
     else:
         assert False
예제 #8
0
 def download_video(self, url, filename):
     if PathUtil.check_path(filename):
         PathUtil.remove(filename)
     retry_times = 2
     while retry_times > 0:
         try:
             request = BilibiliApi.build_video_download_request(url)
             response = RequestUtil.do_request(request,
                                               load_json=False,
                                               stream=True)
             self.before_response(response)
             self.save_video(response.raw_response, filename)
             break
         except:
             print(
                 f'{filename} download fail, retry times = {retry_times}, restart...'
             )
             retry_times -= 1
             if retry_times == 0:
                 raise Exception('retry times exceed, stop downloading...')
             continue
예제 #9
0
 def test_bilibili_archive_api(self, cid):
     request = BilibiliApi.build_dm_api_request(cid)
     response = RequestUtil.do_request(request, load_json=False)
     assert response.status_code == 200
예제 #10
0
 def test_bilibili_oid_api(self, oid):
     request = BilibiliApi.build_oid_api_request(oid)
     data = self.do_request_and_check_response(request)
     assert 'list' in data
     assert 'vlist' in data['list']
예제 #11
0
 def get_sign_video_download_info(self, cid):
     request = BilibiliApi.build_sign_cid_api_request(cid)
     response = RequestUtil.do_request(request)
     self.before_response(response)
     return self._decode_video_download_info(response.json)
예제 #12
0
 def get_video_info(self):
     request = BilibiliApi.build_aid_api_request(self.aid)
     response = RequestUtil.do_request(request)
     self.before_response(response)
     return self._decode_video_info(response.data)