changeset 93:e5ea19b94639

add kmb screens bot stuff committer: GitHub <noreply@github.com>
author Paper <37962225+mrpapersonic@users.noreply.github.com>
date Thu, 04 Aug 2022 05:26:54 -0400
parents 96b9e046f45d
children 14c64e2a9842
files kmbscreens/kmbscreens.bat kmbscreens/randfile.c
diffstat 2 files changed, 53 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/kmbscreens/kmbscreens.bat	Thu Aug 04 05:26:54 2022 -0400
@@ -0,0 +1,20 @@
+if [%~1] == [--debug] goto skip
+@echo off
+:skip
+SETLOCAL EnableDelayedExpansion
+REM for the Kill Me Baby Screens Bot twitter account
+
+for /F "delims=" %%a in ('randfile.exe') do set "episode=%%a"
+for /F "tokens=1 delims=." %%a in ('ffprobe -v quiet -of csv^=p^=0 -show_entries format^=duration "E:\Movies\Anime\Kill Me Baby\%episode%"') do set "length=%%a"
+
+echo %episode%
+echo %length%
+
+SET /A test=%RANDOM% * !length! / 32768 + 1
+
+echo %test%
+
+ffmpeg.exe -hide_banner -loglevel warning -i "E:\Movies\Anime\Kill Me Baby\%episode%" -y -frames:v 1 -ss %test% screencap.jpg
+
+for /F "usebackq tokens=1 delims=" %%a in (`twurl -H "upload.twitter.com" -X POST "/1.1/media/upload.json" --file "screencap.jpg" --file-field "media" ^| jq -r .media_id_string `) do set "media_id=%%a"
+twurl "/1.1/statuses/update.json" -d "media_ids=%media_id%"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/kmbscreens/randfile.c	Thu Aug 04 05:26:54 2022 -0400
@@ -0,0 +1,33 @@
+#include <stdio.h>
+#include <dirent.h>
+#include <stdlib.h>
+#include <time.h>
+
+int main(void) {
+	srand((unsigned)time(NULL));
+	DIR *d;
+	struct dirent *dir;
+	d = opendir("E:\\Movies\\Anime\\Kill Me Baby");
+	int count = 0;
+	char** ret = NULL;
+	if (d) {
+		while ((dir = readdir(d)) != NULL) {
+			char* dot = strrchr(dir->d_name, '.');
+			if (dot && !strcmp(dot, ".mkv")) {
+				ret = realloc(ret, (count+1)*sizeof(char*));
+				if (ret == NULL) return 1;
+				ret[count] = calloc(strlen(dir->d_name), sizeof(char));
+				if (ret[count] == NULL) { free(ret); return 2; }
+				strncpy(ret[count], dir->d_name, strlen(dir->d_name)*sizeof(char));
+				ret[count][strlen(dir->d_name)] = '\0';
+				count++;
+			}
+		}
+		closedir(d);
+	}
+	printf("%s\n", ret[rand() % count]);
+	for (int i = 0; i < count; i++)
+		free(ret[i]);
+	free(ret);
+	return 0;
+}
\ No newline at end of file