summaryrefslogtreecommitdiff
path: root/src/process_url.c
diff options
context:
space:
mode:
authorMole Shang <[email protected]>2023-08-07 15:31:11 +0800
committerMole Shang <[email protected]>2023-08-07 15:31:45 +0800
commit51747e102ba304304a683ec93b2f62caccbead58 (patch)
tree023c64e68ad8be2f40493c505a7bbf9714fc11c7 /src/process_url.c
parent189fba5a4b63706575f9287cd0b1760a331d636e (diff)
downloadhinata-51747e102ba304304a683ec93b2f62caccbead58.tar.gz
hinata-51747e102ba304304a683ec93b2f62caccbead58.tar.bz2
hinata-51747e102ba304304a683ec93b2f62caccbead58.zip
extractors/bilibili: use ffmpeg to merge files once downloaded
Diffstat (limited to 'src/process_url.c')
-rw-r--r--src/process_url.c46
1 files changed, 33 insertions, 13 deletions
diff --git a/src/process_url.c b/src/process_url.c
index 1b391f2..881375f 100644
--- a/src/process_url.c
+++ b/src/process_url.c
@@ -1,3 +1,4 @@
+#include "utils.h"
#include <curl/curl.h>
#include <curl/easy.h>
#include <curl/header.h>
@@ -136,6 +137,12 @@ static size_t write2str(void *ptr, size_t size, size_t nmemb, str_data_t *s) {
return size * nmemb;
}
+static void gen_fullpathfn(char *fullpathfn, const char *outdir,
+ const char *fn) {
+ sprintf(fullpathfn, "%s%s%s", outdir,
+ outdir[strlen(outdir) - 1] == SPLITTER_CHAR ? "" : SPLITTER_STR, fn);
+}
+
static int parse_url(const char *URL, const char *outdir, char *fn) {
CURLUcode ue = logerr(curl_url_set(h, CURLUPART_URL, URL, 0));
if (ue && ue != CURLUE_NO_QUERY) {
@@ -203,9 +210,7 @@ static int parse_url(const char *URL, const char *outdir, char *fn) {
for (unsigned short i = 0; i < results.n; i++) {
if (results.str[i]) {
DEBUG_PRINT("[%d] %s\n", i, results.str[i]);
- sprintf(curl_c->outfn, "%s%s%s", outdir,
- outdir[strlen(outdir) - 1] == SPLITTER_CHAR ? "" : SPLITTER_STR,
- results.str[i]);
+ gen_fullpathfn(curl_c->outfn, outdir, results.str[i]);
}
}
free_str_array(&results);
@@ -422,6 +427,14 @@ static void replace_illegal_char(char *str) {
}
}
+static char *callback_struct_convert_fullpath(char *filename) {
+ char *tmp = malloc(strlen(outdir_g) + strlen(filename) + 2);
+ replace_illegal_char(filename);
+ gen_fullpathfn(tmp, outdir_g, filename);
+ free_and_nullify(filename);
+ return tmp;
+}
+
void curl_init(curl_conf_t *curl) {
curl_global_init(CURL_GLOBAL_ALL);
h = curl_url();
@@ -521,6 +534,16 @@ int get(const char *URL, char **pdstr) {
void add_url(const char *URL, const char *outdir, const char *fn,
const char *referer, callback_t callback,
callback_struct_t *p_callback_struct) {
+
+ char *filename;
+ if (fn == NULL || fn[0] == '\0') {
+ filename = NULL;
+ } else {
+ filename = malloc(strlen(fn) + 1);
+ strcpy(filename, fn);
+ replace_illegal_char(filename);
+ }
+
if (outdir && outdir[0] != '\0') {
outdir_g = outdir;
}
@@ -529,19 +552,16 @@ void add_url(const char *URL, const char *outdir, const char *fn,
referer_g = NULL;
}
DEBUG_PRINT("referer_g: %s\n", referer_g);
+
callback_g = callback;
if (p_callback_struct) {
+ p_callback_struct->videofn =
+ callback_struct_convert_fullpath(p_callback_struct->videofn);
+ p_callback_struct->audiofn =
+ callback_struct_convert_fullpath(p_callback_struct->audiofn);
+ p_callback_struct->filename =
+ callback_struct_convert_fullpath(p_callback_struct->filename);
p_callback_struct_g = p_callback_struct;
- replace_illegal_char(p_callback_struct_g->title);
- }
-
- char *filename;
- if (fn == NULL || fn[0] == '\0') {
- filename = NULL;
- } else {
- filename = malloc(strlen(fn) + 1);
- strcpy(filename, fn);
- replace_illegal_char(filename);
}
// Pass our cache (outdir_g) to parse_url()