Пример #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 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)
Пример #3
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
 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
Пример #5
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
Пример #6
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
Пример #7
0
 def do_request_and_check_response(request):
     response = RequestUtil.do_request(request)
     assert response.status_code == 200
     assert response.code == 0
     assert isinstance(response.data, dict)
     return response.data
Пример #8
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)
Пример #9
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)