Mercurial > codedump
annotate decodeurl.c @ 133:0d8eabdd12ab default tip
create: write H:MM:SS timestamps, add option to fill with gaussian-blur instead of black
many albums are longer than one hour so writing H:MM:SS is a
necessity. if anything there will just be verbose info that
isn't important for my use-case.
however the gaussian-blur is simply broken. It works, and it plays
locally just fine, but YouTube in particular elongates the video
to fit the full width. I'm not entirely sure why it does this, but
it makes it useless and ugly.
| author | Paper <paper@tflc.us> |
|---|---|
| date | Sat, 03 Jan 2026 20:25:38 -0500 |
| parents | 23d0073daa79 |
| children |
| rev | line source |
|---|---|
|
72
23d0073daa79
Create decodeurl.c
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff
changeset
|
1 // C port of decodeurl.cpp |
|
23d0073daa79
Create decodeurl.c
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff
changeset
|
2 #include <curl/curl.h> |
|
23d0073daa79
Create decodeurl.c
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff
changeset
|
3 #include <string.h> |
|
23d0073daa79
Create decodeurl.c
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff
changeset
|
4 #include <stdio.h> |
|
23d0073daa79
Create decodeurl.c
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff
changeset
|
5 #include <stdlib.h> |
|
23d0073daa79
Create decodeurl.c
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff
changeset
|
6 |
|
23d0073daa79
Create decodeurl.c
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff
changeset
|
7 #define ENCODED_SIZE 8192 |
|
23d0073daa79
Create decodeurl.c
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff
changeset
|
8 |
|
23d0073daa79
Create decodeurl.c
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff
changeset
|
9 int main(int argc, char* argv[]) { |
|
23d0073daa79
Create decodeurl.c
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff
changeset
|
10 int c; |
|
23d0073daa79
Create decodeurl.c
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff
changeset
|
11 if (argc != 3) { |
|
23d0073daa79
Create decodeurl.c
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff
changeset
|
12 printf("usage: %s <input> <output>\n", argv[0]); |
|
23d0073daa79
Create decodeurl.c
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff
changeset
|
13 return 1; |
|
23d0073daa79
Create decodeurl.c
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff
changeset
|
14 } |
|
23d0073daa79
Create decodeurl.c
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff
changeset
|
15 char encoded[ENCODED_SIZE] = {'\0'}; |
|
23d0073daa79
Create decodeurl.c
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff
changeset
|
16 CURL* curl = curl_easy_init(); |
|
23d0073daa79
Create decodeurl.c
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff
changeset
|
17 char data[256]; |
|
23d0073daa79
Create decodeurl.c
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff
changeset
|
18 FILE* in = fopen(argv[1], "r"); // this is unsafe, but meh |
|
23d0073daa79
Create decodeurl.c
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff
changeset
|
19 FILE* out = fopen(argv[2], "w"); |
|
23d0073daa79
Create decodeurl.c
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff
changeset
|
20 if (in == NULL || out == NULL) { |
|
23d0073daa79
Create decodeurl.c
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff
changeset
|
21 printf("Failed to open file(s)!\n"); |
|
23d0073daa79
Create decodeurl.c
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff
changeset
|
22 return 1; |
|
23d0073daa79
Create decodeurl.c
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff
changeset
|
23 } |
|
23d0073daa79
Create decodeurl.c
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff
changeset
|
24 char* p = &encoded[strlen(encoded)]; |
|
23d0073daa79
Create decodeurl.c
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff
changeset
|
25 while ((c = fgetc(in)) != EOF) { |
|
23d0073daa79
Create decodeurl.c
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff
changeset
|
26 *p++ = c; |
|
23d0073daa79
Create decodeurl.c
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff
changeset
|
27 if (p == &encoded[ENCODED_SIZE-1]) break; |
|
23d0073daa79
Create decodeurl.c
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff
changeset
|
28 } |
|
23d0073daa79
Create decodeurl.c
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff
changeset
|
29 *p = '\0'; |
|
23d0073daa79
Create decodeurl.c
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff
changeset
|
30 rewind(in); // we probably don't need this!! |
|
23d0073daa79
Create decodeurl.c
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff
changeset
|
31 char* decoded = curl_easy_unescape(curl, encoded, 0, NULL); |
|
23d0073daa79
Create decodeurl.c
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff
changeset
|
32 fprintf(out, "%s", decoded); |
|
23d0073daa79
Create decodeurl.c
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff
changeset
|
33 // fwrite(decoded, sizeof(char), sizeof(decoded), in); |
|
23d0073daa79
Create decodeurl.c
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff
changeset
|
34 curl_easy_cleanup(curl); |
|
23d0073daa79
Create decodeurl.c
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff
changeset
|
35 fclose(in); |
|
23d0073daa79
Create decodeurl.c
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff
changeset
|
36 fclose(out); |
|
23d0073daa79
Create decodeurl.c
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff
changeset
|
37 return 0; |
|
23d0073daa79
Create decodeurl.c
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff
changeset
|
38 } |
