#include "haokan.h" #include "../logger.h" #include "../process_url.h" #include #include #include #include void haokan_extract(Options *options) { char *resp, *title, *videoURL; if (!get(options->URL, &resp)) { const char *patterns_str[2] = {"
(.*?)
", "\"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, NULL); if (ct == NULL) { goto end; } const char *ext = mimeType2ext(ct); char *filename = malloc(strlen(title) + strlen(ct) + 2); sprintf(filename, "%s.%s", title, ext); set_referer("https://haokan.baidu.com"); add_url(videoURL, NULL, filename, NULL, NULL); end: free_str_array(&results); FREE_AND_NULLIFY(filename); FREE_AND_NULLIFY(videoURL); return; } free_str_array(&results); } LOG("haokan", "Download failed.\n"); }