repo: music
action: commit
revision: 
path_from: 
revision_from: cc48cd51f726a5cf74db772a39fcb056168ca635:
path_to: 
revision_to: 
git.thebackupbox.net
music
git clone git://git.thebackupbox.net/music
commit cc48cd51f726a5cf74db772a39fcb056168ca635
Author: epoch 
Date:   Sat Dec 11 09:21:20 2021 +0000

    added a naive implementation of an lrc printer

diff --git a/Makefile b/Makefile
index 560491339d65987740fa4cd3ddf2521a75ac745f..
index ..ad547999dac848b774fb72e54d43e8760c124790 100644
--- a/Makefile
+++ b/Makefile
@@ -49,6 +49,7 @@ install: all
 	install music-push $(PREFIX)/bin/
 	install music-pushmeta $(PREFIX)/bin/
 	install music-updateplaying $(PREFIX)/bin/
+	install -t $(PREFIX)/bin/ lrc-print
 	install -t $(PREFIX)/bin/ music-pop
 	install -t $(PREFIX)/bin/ music-isonair
 	install -t $(PREFIX)/bin/ music-length
diff --git a/lrc-print.c b/lrc-print.c
new file mode 100644
index 0000000000000000000000000000000000000000..6ade7318589f6a830c9e180738b36196da76186b
--- /dev/null
+++ b/lrc-print.c
@@ -0,0 +1,41 @@
+#include 
+#include 
+#include 
+
+int main(int argc,char *argv[]) {
+  time_t start=time(0);
+  time_t timestamp_ms;
+  time_t tsm,tss,tsd;
+  time_t now;
+  time_t elapsed_ms;//miliseconds
+  char line[4096];
+  char *text,*timestamp;
+  char *stsm,*stss,*stsd;
+  while(fgets(line,sizeof(line)-1,stdin)) {
+    if(*line != '[') continue;//skip lines that don't have proper timestamps at the start.
+    if(*(line+1) < '0' || *(line+1) > '9') continue;
+    if(strchr(line,'\n')) *strchr(line,'\n')=0;
+    timestamp=line+1;
+    if(!strchr(timestamp,']')) continue; //invalid line
+    text=strchr(timestamp,']');
+    *text=0;//null out the timestamp ender
+    text++;
+    stsm=timestamp;//string versions
+    stss=strchr(stsm,':');
+    *stss=0;
+    stss++;
+    stsd=strchr(stss,'.');
+    *stsd=0;
+    stsd++;
+    tsm=atoi(stsm);//minutes
+    tss=atoi(stss);//seconds
+    tsd=atoi(stsd);//decimal. 100ths of a second
+    timestamp_ms=(tsd * 10) + (tss * 1000) + (tsm * 1000 * 60);
+    while(elapsed_ms < timestamp_ms) {
+      usleep(10000);//1000 of these 1 one milisecond.
+      elapsed_ms+=10;//there's a better way to do this. this method will drift. but not enough that I care right now.
+      fprintf(stderr," %d %d \r",time(0)%1000,elapsed_ms);
+    }
+    printf("%02d %02d %02d > %s\n",tsm,tss,tsd,text);
+  }
+}

-----END OF PAGE-----