shithub: nvi

Download patch

ref: 49ae1aed99f40ded9df16dd5f1d4a2ead34142a2
parent: 363cece770538993225a06ac468443b7b2dd777d
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Sun Jun 20 14:52:58 EDT 2021

print more metadata with -i

--- a/nvi.c
+++ b/nvi.c
@@ -34,8 +34,11 @@
 	Info *(*fun)(char *), *info;
 	int i, j, nida, nidv;
 	int afd, vfd;
+	Tm tm;
 
+	fmtinstall('P', Pfmt);
 	fmtinstall('Z', Zfmt);
+	tmfmtinstall();
 
 	fun = youtube;
 	nida = 0;
@@ -87,6 +90,11 @@
 	if(cmd == Cinfo){
 		for(i = 0, f = info->fmt; i < info->nfmt; i++, f++)
 			print("%d\t%s\t%Z\t%s\n", f->id, f->quality, f->sz, f->type);
+		print("author: %s\n", info->author);
+		print("title: %s\n", info->title);
+		print("description: %s\n", info->title);
+		print("duration: %P\n", info->duration);
+		print("published: %τ\n", tmfmt(tmtime(&tm, info->published, nil), "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
@@ -16,8 +16,8 @@
 	char *author;
 	char *title;
 	char *description;
-	vlong published;
-	vlong length;
+	uvlong published;
+	uvlong duration;
 	Format *fmt;
 	int nfmt;
 };
@@ -44,3 +44,6 @@
 
 #pragma varargck type "Z" vlong
 int Zfmt(Fmt *f);
+
+#pragma varargck type "P" uvlong
+int Pfmt(Fmt *f);
--- a/util.c
+++ b/util.c
@@ -149,3 +149,22 @@
 
 	return fmtprint(f, "%lld", z);
 }
+
+int
+Pfmt(Fmt *f)
+{
+	char *s, tmp[16];
+	u64int sec;
+
+	s = tmp;
+	sec = va_arg(f->args, uvlong);
+	if(sec >= 3600){
+		s = seprint(s, tmp+sizeof(tmp), "%02lld:", sec/3600);
+		sec %= 3600;
+	}
+	s = seprint(s, tmp+sizeof(tmp), "%02lld:", sec/60);
+	sec %= 60;
+	seprint(s, tmp+sizeof(tmp), "%02lld", sec);
+
+	return fmtstrcpy(f, tmp);
+}
--- a/youtube.c
+++ b/youtube.c
@@ -103,7 +103,7 @@
 			i->author = estrdup(jsonstr(jsonbyname(z, "author")));
 			i->title = estrdup(jsonstr(jsonbyname(z, "title")));
 			i->description = estrdup(jsonstr(jsonbyname(z, "description")));
-			i->length = jsonbyname(z, "lengthSeconds")->n;
+			i->duration = jsonbyname(z, "lengthSeconds")->n;
 			i->published = jsonbyname(z, "published")->n;
 
 			for(fmtname = fmtnames; *fmtname; fmtname++){