-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
40 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from .http import HttpFD | ||
|
||
import urllib.request as compat_urllib_request | ||
import threading | ||
|
||
|
||
class HttpHB(HttpFD): | ||
def real_download(self, filename, info_dict): | ||
result = False | ||
if 'heartbeat_url'in info_dict: | ||
def heart_beat(): | ||
try: | ||
data = info_dict['heartbeat_data'].encode("utf-8") | ||
compat_urllib_request.urlopen(url=info_dict['heartbeat_url'], data=data) | ||
print('heart beat!') | ||
except Exception as ex: | ||
print('heart beat fail: ' + ex.message) | ||
pass | ||
|
||
if not result: | ||
timer = threading.Timer(25, heart_beat) | ||
timer.start() | ||
|
||
heart_beat() | ||
|
||
result = super(HttpHB, self).real_download(filename, info_dict) | ||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters