summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMole Shang <[email protected]>2023-08-09 10:34:55 +0800
committerMole Shang <[email protected]>2023-08-09 10:34:55 +0800
commit9e733e6232d5047f08a3a9f5f4b7b5cbe2bf33d0 (patch)
treeab417f29de0d2d80fe960eed6577483f99be1104
parente1d3ac3c61283923095271bbbc73257f9e5ff83c (diff)
downloadhinata-9e733e6232d5047f08a3a9f5f4b7b5cbe2bf33d0.tar.gz
hinata-9e733e6232d5047f08a3a9f5f4b7b5cbe2bf33d0.tar.bz2
hinata-9e733e6232d5047f08a3a9f5f4b7b5cbe2bf33d0.zip
extractors/haokan: catch get errors
-rw-r--r--src/extractors/haokan.c59
1 files changed, 30 insertions, 29 deletions
diff --git a/src/extractors/haokan.c b/src/extractors/haokan.c
index d2d0379..204e539 100644
--- a/src/extractors/haokan.c
+++ b/src/extractors/haokan.c
@@ -8,39 +8,40 @@
void haokan_extract(Options *options) {
char *resp, *title, *videoURL;
- get(options->URL, &resp);
- const char *patterns_str[2] = {"<div class='ssr-video-title\'>(.*?)</div>",
- "\"playurl\":\"(http.+?)\""};
- const str_array_t patterns = {(char **)patterns_str, 2};
- str_array_t results = create_str_array(0);
- int r = regex_match(resp, patterns, &results);
- // Should match exactly two results in HTML, otherwise error out.
- if (!r && results.n == 2) {
- // for (unsigned short i = 0; i < results.n; i++) {
- // DEBUG_PRINT("%s\n", results.str[i]);
- // }
- title = results.str[0];
- substitute_str(results.str[1], "\\\\/", "/", &videoURL);
- DEBUG_PRINT("title: %s\n", title);
- DEBUG_PRINT("videoURL: %s\n", videoURL);
+ if (!get(options->URL, &resp)) {
+ const char *patterns_str[2] = {"<div class='ssr-video-title\'>(.*?)</div>",
+ "\"playurl\":\"(http.+?)\""};
+ const str_array_t patterns = {(char **)patterns_str, 2};
+ str_array_t results = create_str_array(0);
+ int r = regex_match(resp, patterns, &results);
+ // Should match exactly two results in HTML, otherwise error out.
+ if (!r && results.n == 2) {
+ // for (unsigned short i = 0; i < results.n; i++) {
+ // DEBUG_PRINT("%s\n", results.str[i]);
+ // }
+ title = results.str[0];
+ substitute_str(results.str[1], "\\\\/", "/", &videoURL);
+ DEBUG_PRINT("title: %s\n", title);
+ DEBUG_PRINT("videoURL: %s\n", videoURL);
- char *ct = NULL;
- get_info(videoURL, NULL, &ct);
- if (ct == NULL) {
- goto end;
- }
- const char *ext = mimeType2ext(ct);
- char *filename = malloc(strlen(title) + strlen(ct) + 2);
- sprintf(filename, "%s.%s", title, ext);
+ char *ct = NULL;
+ get_info(videoURL, NULL, &ct);
+ if (ct == NULL) {
+ goto end;
+ }
+ const char *ext = mimeType2ext(ct);
+ char *filename = malloc(strlen(title) + strlen(ct) + 2);
+ sprintf(filename, "%s.%s", title, ext);
- add_url(videoURL, NULL, filename, "https://haokan.baidu.com", NULL, NULL);
+ add_url(videoURL, NULL, filename, "https://haokan.baidu.com", NULL, NULL);
- end:
+ end:
+ free_str_array(&results);
+ free_and_nullify(filename);
+ free_and_nullify(videoURL);
+ return;
+ }
free_str_array(&results);
- free_and_nullify(filename);
- free_and_nullify(videoURL);
- return;
}
LOG("haokan", "Download failed.\n");
- free_str_array(&results);
}