diff options
Diffstat (limited to 'src/extractors/haokan.c')
-rw-r--r-- | src/extractors/haokan.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/extractors/haokan.c b/src/extractors/haokan.c new file mode 100644 index 0000000..d2d0379 --- /dev/null +++ b/src/extractors/haokan.c @@ -0,0 +1,46 @@ +#include "haokan.h" +#include "../logger.h" +#include "../process_url.h" +#include <limits.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +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); + + 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); + + end: + free_str_array(&results); + free_and_nullify(filename); + free_and_nullify(videoURL); + return; + } + LOG("haokan", "Download failed.\n"); + free_str_array(&results); +} |