summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMole Shang <[email protected]>2023-08-09 17:29:15 +0800
committerMole Shang <[email protected]>2023-08-09 17:30:30 +0800
commitc636d2e78e464246b3dd7bc8ce0b8e5d8a5bf7a6 (patch)
tree3ca0539da181565257d41259cc8e539c469fe847
parentc952d1663bf8d7e54926faab23ed2291c68b73f2 (diff)
downloadhinata-c636d2e78e464246b3dd7bc8ce0b8e5d8a5bf7a6.tar.gz
hinata-c636d2e78e464246b3dd7bc8ce0b8e5d8a5bf7a6.tar.bz2
hinata-c636d2e78e464246b3dd7bc8ce0b8e5d8a5bf7a6.zip
process_url: set referer in the separate function
-rw-r--r--src/extractors/bilibili.c8
-rw-r--r--src/extractors/haokan.c3
-rw-r--r--src/process_url.c11
-rw-r--r--src/process_url.h5
-rw-r--r--src/ui.c2
5 files changed, 12 insertions, 17 deletions
diff --git a/src/extractors/bilibili.c b/src/extractors/bilibili.c
index aa3fc4e..5b98f26 100644
--- a/src/extractors/bilibili.c
+++ b/src/extractors/bilibili.c
@@ -404,16 +404,16 @@ static int download(Bilibili_options *bilibili_options) {
callback_struct.videofn = malloc(strlen(callback_struct.filename) + 6);
sprintf(callback_struct.videofn, "%s[%s]-%s.%s", bilibili_options->title,
quality_desc, "video", ext);
- add_url(video->baseUrl, NULL, callback_struct.videofn,
- "https://www.bilibili.com", NULL, NULL);
+ set_referer("https://www.bilibili.com");
+ add_url(video->baseUrl, NULL, callback_struct.videofn, NULL, NULL);
}
{
callback_struct.audiofn = malloc(strlen(callback_struct.filename) + 6);
sprintf(callback_struct.audiofn, "%s[%s]-%s.%s", bilibili_options->title,
quality_desc, "audio", mimeType2ext(audio->mimeType));
- add_url(audio->baseUrl, NULL, callback_struct.audiofn,
- "https://www.bilibili.com", &bilibili_merge, &callback_struct);
+ add_url(audio->baseUrl, NULL, callback_struct.audiofn, &bilibili_merge,
+ &callback_struct);
}
free_and_nullify(resp);
dash_cleanup(&dash);
diff --git a/src/extractors/haokan.c b/src/extractors/haokan.c
index 5659018..f289c3e 100644
--- a/src/extractors/haokan.c
+++ b/src/extractors/haokan.c
@@ -33,7 +33,8 @@ void haokan_extract(Options *options) {
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);
+ set_referer("https://haokan.baidu.com");
+ add_url(videoURL, NULL, filename, NULL, NULL);
end:
free_str_array(&results);
diff --git a/src/process_url.c b/src/process_url.c
index dae6db3..c20b3eb 100644
--- a/src/process_url.c
+++ b/src/process_url.c
@@ -278,7 +278,7 @@ bool get_info(const char *URL, long *psize, char **p_content_type,
*p_cookie = malloc(strlen(pch->value) + 1);
strcpy(*p_cookie, pch->value);
- if (psize){
+ if (psize) {
r = curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD_T,
(curl_off_t *)psize);
if (logerr(r)) {
@@ -570,13 +570,11 @@ int get(const char *URL, char **pdstr) {
* - If outdir is NULL or a empty string, reuse the cached outdir_g
* - If fn is NULL or a empty string, infer the filename from URL (otherwise
* fail and quit')
- * - If referer is NULL or a empty string, uses NULL
* - If callback || callback_struct is valid, execute the callback function
* after download
*/
void add_url(const char *URL, const char *outdir, const char *fn,
- const char *referer, callback_t callback,
- callback_struct_t *p_callback_struct) {
+ callback_t callback, callback_struct_t *p_callback_struct) {
char *filename;
if (fn == NULL || fn[0] == '\0') {
@@ -590,11 +588,6 @@ void add_url(const char *URL, const char *outdir, const char *fn,
if (outdir && outdir[0] != '\0') {
outdir_g = outdir;
}
- referer_g = referer;
- if (referer && referer[0] == '\0') {
- referer_g = NULL;
- }
- DEBUG_PRINT("referer_g: %s\n", referer_g);
callback_g = callback;
if (p_callback_struct) {
diff --git a/src/process_url.h b/src/process_url.h
index 00f7a74..005cfcf 100644
--- a/src/process_url.h
+++ b/src/process_url.h
@@ -64,9 +64,10 @@ void set_referer(char *referer);
int get(const char *, char **);
-bool get_info(const char *URL, long *psize, char **p_content_type, char **p_cookie);
+bool get_info(const char *URL, long *psize, char **p_content_type,
+ char **p_cookie);
-void add_url(const char *, const char *, const char *, const char *, callback_t,
+void add_url(const char *, const char *, const char *, callback_t,
callback_struct_t *);
#endif
diff --git a/src/ui.c b/src/ui.c
index 2c1ab15..a54c9aa 100644
--- a/src/ui.c
+++ b/src/ui.c
@@ -92,7 +92,7 @@ void load_ui(struct ui_struct *ui) {
if (outPath) {
DEBUG_PRINT("tinyfd gets outPath: %s\n", outPath);
append_log("Got URL: %s\n", text);
- add_url(text, outPath, NULL, NULL, NULL, NULL);
+ add_url(text, outPath, NULL, NULL, NULL);
} else {
LOG("NFD", "Please specify a valid file PATH to write to!\n");
}