-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement --custom-hooks so that users can modify wpull_hook
- Loading branch information
Showing
6 changed files
with
91 additions
and
16 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
root = true | ||
|
||
[*] | ||
indent_style = tab | ||
indent_size = 4 |
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,31 @@ | ||
""" | ||
This is a sample script that can be passed to grab-site --custom-hooks=. | ||
It drops http:// URLs before they can be queued, and it aborts responses | ||
that have a Content-Type: that starts with 'audio/' | ||
""" | ||
|
||
accept_url_grabsite = wpull_hook.callbacks.accept_url | ||
def accept_url(url_info, record_info, verdict, reasons): | ||
url = url_info['url'] | ||
if url.startswith("http://"): | ||
print("Dropping insecure URL %s" % url) | ||
return False | ||
return accept_url_grabsite(url_info, record_info, verdict, reasons) | ||
|
||
def has_content_type_audio(response_info): | ||
try: | ||
t = list(p for p in response_info["fields"] if p[0] == "Content-Type")[0][1] | ||
return t.lower().startswith("audio/") | ||
except (IndexError, ValueError): | ||
return False | ||
|
||
handle_pre_response_grabsite = wpull_hook.callbacks.handle_pre_response | ||
def handle_pre_response(url_info, url_record, response_info): | ||
url = url_info['url'] | ||
if has_content_type_audio(response_info): | ||
print("Dropping %s because it has audio mime type" % url) | ||
return wpull_hook.actions.FINISH | ||
return handle_pre_response_grabsite(url_info, url_record, response_info) | ||
|
||
wpull_hook.callbacks.accept_url = accept_url | ||
wpull_hook.callbacks.handle_pre_response = handle_pre_response |
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 |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = '0.9.19' | ||
__version__ = '0.10' |
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