Esempio n. 1
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 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