annotate kmbscreens/randfile.c @ 115:f10492e8720b

kemonopartydownloader.py: add youtube downloader stubs and dump json to disk
author Paper <mrpapersonic@gmail.com>
date Mon, 23 Jan 2023 23:58:22 -0500
parents e5ea19b94639
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
93
e5ea19b94639 add kmb screens bot stuff
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
1 #include <stdio.h>
e5ea19b94639 add kmb screens bot stuff
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
2 #include <dirent.h>
e5ea19b94639 add kmb screens bot stuff
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
3 #include <stdlib.h>
e5ea19b94639 add kmb screens bot stuff
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
4 #include <time.h>
e5ea19b94639 add kmb screens bot stuff
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
5
e5ea19b94639 add kmb screens bot stuff
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
6 int main(void) {
e5ea19b94639 add kmb screens bot stuff
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
7 srand((unsigned)time(NULL));
e5ea19b94639 add kmb screens bot stuff
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
8 DIR *d;
e5ea19b94639 add kmb screens bot stuff
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
9 struct dirent *dir;
e5ea19b94639 add kmb screens bot stuff
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
10 d = opendir("E:\\Movies\\Anime\\Kill Me Baby");
e5ea19b94639 add kmb screens bot stuff
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
11 int count = 0;
e5ea19b94639 add kmb screens bot stuff
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
12 char** ret = NULL;
e5ea19b94639 add kmb screens bot stuff
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
13 if (d) {
e5ea19b94639 add kmb screens bot stuff
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
14 while ((dir = readdir(d)) != NULL) {
e5ea19b94639 add kmb screens bot stuff
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
15 char* dot = strrchr(dir->d_name, '.');
e5ea19b94639 add kmb screens bot stuff
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
16 if (dot && !strcmp(dot, ".mkv")) {
e5ea19b94639 add kmb screens bot stuff
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
17 ret = realloc(ret, (count+1)*sizeof(char*));
e5ea19b94639 add kmb screens bot stuff
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
18 if (ret == NULL) return 1;
e5ea19b94639 add kmb screens bot stuff
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
19 ret[count] = calloc(strlen(dir->d_name), sizeof(char));
e5ea19b94639 add kmb screens bot stuff
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
20 if (ret[count] == NULL) { free(ret); return 2; }
e5ea19b94639 add kmb screens bot stuff
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
21 strncpy(ret[count], dir->d_name, strlen(dir->d_name)*sizeof(char));
e5ea19b94639 add kmb screens bot stuff
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
22 ret[count][strlen(dir->d_name)] = '\0';
e5ea19b94639 add kmb screens bot stuff
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
23 count++;
e5ea19b94639 add kmb screens bot stuff
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
24 }
e5ea19b94639 add kmb screens bot stuff
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
25 }
e5ea19b94639 add kmb screens bot stuff
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
26 closedir(d);
e5ea19b94639 add kmb screens bot stuff
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
27 }
e5ea19b94639 add kmb screens bot stuff
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
28 printf("%s\n", ret[rand() % count]);
e5ea19b94639 add kmb screens bot stuff
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
29 for (int i = 0; i < count; i++)
e5ea19b94639 add kmb screens bot stuff
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
30 free(ret[i]);
e5ea19b94639 add kmb screens bot stuff
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
31 free(ret);
e5ea19b94639 add kmb screens bot stuff
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
32 return 0;
e5ea19b94639 add kmb screens bot stuff
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
diff changeset
33 }