shithub: nvi

Download patch

ref: 64feeb1dc00e4293221873af8b99dc90768a0c2d
parent: 076ca403567c3a605ebb0d4c8b963c699025bf17
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Wed Jun 23 04:17:26 EDT 2021

better handling of "published" timestamp. make it work for PeerTube as well

--- a/nvi.c
+++ b/nvi.c
@@ -34,7 +34,6 @@
 	Info *(*fun)(char *), *info;
 	int i, j, nida, nidv;
 	int afd, vfd;
-	Tm tm;
 
 	fmtinstall('P', Pfmt);
 	fmtinstall('Z', Zfmt);
@@ -101,8 +100,8 @@
 			print("description: %s\n", info->description);
 		if(info->duration != 0)
 			print("duration: %P\n", info->duration);
-		if(info->published != 0)
-			print("published: %τ\n", tmfmt(tmtime(&tm, info->published, nil), "YYYY/MM/DD"));
+		if(tmnorm(&info->published) != 0)
+			print("published: %τ\n", tmfmt(&info->published, "YYYY/MM/DD"));
 	}else if(cmd == Cdownload){
 		for(j = 0, fa = nil, f = info->fmt; j < info->nfmt && fa == nil; j++, f++){
 			if((f->included == Iaudio) == 0)
--- a/nvi.h
+++ b/nvi.h
@@ -15,7 +15,7 @@
 	char *author;
 	char *title;
 	char *description;
-	uvlong published;
+	Tm published;
 	uvlong duration;
 	Format *fmt;
 	int nfmt;
--- a/peertube.c
+++ b/peertube.c
@@ -81,8 +81,8 @@
 {
 	int fd, peertube;
 	char *s, *o, *id;
-	JSON *j, *z;
 	JSONEl *e, *f;
+	JSON *j, *z;
 	Info *i;
 
 	peertube = 0;
@@ -131,7 +131,8 @@
 	i->title = estrdup(jsonstr(jsonbyname(j, "name")));
 	i->description = estrdup(jsonstr(jsonbyname(j, "description")));
 	i->duration = jsonbyname(j, "duration")->n;
-	// FIXME i->published = jsonstr(jsonbyname(z, "published"));
+	if((s = jsonstr(jsonbyname(j, "publishedAt"))) != nil)
+		tmparse(&i->published, "YYYY-MM-DDThh:mm:ss.ttt", s, nil, nil);
 
 	if((z = jsonbyname(j, "streamingPlaylists")) != nil && z->t == JSONArray){
 		for(e = z->first; e != nil; e = e->next){
--- a/youtube.c
+++ b/youtube.c
@@ -101,7 +101,7 @@
 			i->title = estrdup(jsonstr(jsonbyname(z, "title")));
 			i->description = estrdup(jsonstr(jsonbyname(z, "description")));
 			i->duration = jsonbyname(z, "lengthSeconds")->n;
-			i->published = jsonbyname(z, "published")->n;
+			tmtime(&i->published, jsonbyname(z, "published")->n, nil);
 
 			for(fmtname = fmtnames; *fmtname; fmtname++){
 				if((x = jsonbyname(z, *fmtname)) == nil){