aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2020-10-24 19:57:53 +0200
committerJohn Ankarström <john@ankarstrom.se>2020-10-24 19:57:53 +0200
commitb1567ce864cc9a33a1837359cd1cebcb8de79613 (patch)
treeae952222d55e524bba7ca65be53302dc0ec13744
parent47ced886fbd41a35d275526e18164aaa71202bef (diff)
downloadwatch-b1567ce864cc9a33a1837359cd1cebcb8de79613.tar.gz
release 2.1
-rw-r--r--CHANGELOG.txt12
-rw-r--r--watch.c39
-rw-r--r--watch.exebin69120 -> 69632 bytes
-rw-r--r--watch.objbin4196 -> 4739 bytes
4 files changed, 33 insertions, 18 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index 24c31de..92a1801 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -1,8 +1,6 @@
-CHANGELOG ----------------------- 2.0 ---------------------- 2020-06-03
+CHANGELOG ----------------------- 2.1 ---------------------- 2020-06-13
-NEW: Rewrote main program in C.
-NEW: Playlist support.
-FIX: Removed requirement for separate video and audio streams. As such,
- most sites are now supported, although some YouTube videos still
- fail.
-NEW: Rewrote bookmarklet (see watch.js). \ No newline at end of file
+NEW: Video title support.
+NEW: Now handles Ctrl-Break signal by interrupting youtube-dl and
+ launching MPC-HC immediately. Ctrl-C still interrupts youtube-dl
+ without launching MPC-HC.
diff --git a/watch.c b/watch.c
index 9d9169c..b731062 100644
--- a/watch.c
+++ b/watch.c
@@ -3,6 +3,8 @@
#endif
#include <windows.h>
+#include <signal.h>
+
#include <shellapi.h>
#pragma comment(lib, "Shell32")
#include <shlwapi.h>
@@ -20,14 +22,25 @@
#define SR_ERR_NOASSOC (HINSTANCE)31
#define USAGE "usage: %s URL\n", argv[0]
+char out[MAX_PATH];
+
+void sigbreak(int sig) {
+ /* open playlist */
+ if (ShellExecute(NULL, "open", out, NULL, NULL, 5) <= (HINSTANCE)32)
+ die("failed to open %s\n", out);
+ exit(0);
+}
+
int main(int argc, char *argv[]) {
- bool new;
- char *cmd, out[MAX_PATH], temp[MAX_PATH];
+ bool new, title;
+ char *cmd, temp[MAX_PATH];
FILE *f, *p;
HINSTANCE r;
int c, i, linecount;
ULONGLONG last;
+ signal(SIGBREAK, sigbreak);
+
/* construct temporary playlist file path */
if (GetTempPath(1 + MAX_PATH, temp) > 0 && strlen(temp) + 1 + 16 <= MAX_PATH) {
@@ -47,9 +60,9 @@ int main(int argc, char *argv[]) {
/* start youtube-dl */
- cmd = malloc(sizeof("youtube-dl -g \"\"") + strlen(argv[1]) * sizeof(char));
+ cmd = malloc(sizeof("youtube-dl -eg \"\"") + strlen(argv[1]) * sizeof(char));
if (cmd == NULL) err(1, "malloc");
- if (sprintf(cmd, "youtube-dl -g \"%s\"", argv[1]) < 0) err(1, "sprintf");
+ if (sprintf(cmd, "youtube-dl -eg \"%s\"", argv[1]) < 0) err(1, "sprintf");
p = _popen(cmd, "r");
if (p == NULL) err(1, "popen");
@@ -63,6 +76,7 @@ int main(int argc, char *argv[]) {
linecount = 0;
new = true;
+ title = false;
last = GetTickCount();
c = fgetc(p);
@@ -73,14 +87,16 @@ int main(int argc, char *argv[]) {
while ((c = fgetc(p)) != EOF) {
loop:
if (new) {
- /* if new line immediately follows last one, it is only audio */
- if (GetTickCount() - last > 20) {
- fprintf(stderr, "Retrieved video #%d\n", linecount);
+ new = false;
+ /* if new line immediately follows last one, it belongs to the same video */
+ if (GetTickCount() - last > 20) { /* new video */
+ title = true;
linecount++;
+ fprintf(stderr, "Retrieving video #%d\n", linecount);
fprintf(f, "%d,type,0\n", linecount);
- }
- fprintf(f, "%d,filename,", linecount, linecount);
- new = false;
+ fprintf(f, "%d,label,", linecount);
+ } else
+ fprintf(f, "%d,filename,", linecount);
}
fputc(c, f);
if (c == '\n') {
@@ -91,7 +107,8 @@ loop:
end:
if (i = _pclose(p))
- die("youtube-dl exited with %d\n", i);
+ if (i != -1073741510) /* Ctrl-Break */
+ die("youtube-dl exited with %d\n", i);
/* open playlist */
open:
diff --git a/watch.exe b/watch.exe
index d5de636..0222d3d 100644
--- a/watch.exe
+++ b/watch.exe
Binary files differ
diff --git a/watch.obj b/watch.obj
index 2f5208c..3bea372 100644
--- a/watch.obj
+++ b/watch.obj
Binary files differ