ref: 976b2c3767f139177754bdc7ef7069d535ff7325
parent: d1d1267271f9f0bc6ad4a2a31ad7bc3b6125d820
author: Sigrid Solveig Haflínudóttir <[email protected]>
date: Fri Jul 23 03:34:23 EDT 2021
fix peertube links with no streaming playlists; make error reports better
--- a/peertube.c
+++ b/peertube.c
@@ -12,9 +12,10 @@
JSONEl *e;
int fd, n;
+ j = nil;
if((x = jfield(f, JSONString, "metadataUrl", nil)) == nil){
- werrstr("no url");
- return -1;
+ werrstr("no metadataUrl");
+ goto err;
}
j = nil;
if((fd = hget(jsonstr(x), -1)) >= 0){
@@ -25,15 +26,12 @@
close(fd);
}
procwait();
- if(j == nil){
- werrstr("peertube: %r");
- return -1;
- }
+ if(j == nil)
+ goto err;
if((x = jfield(f, JSONString, "fileDownloadUrl", nil)) == nil){
- werrstr("no url");
- jsonfree(j);
- return -1;
+ werrstr("no fileDownloadUrl");
+ goto err;
}
i->nfmt++;
if((i->fmt = realloc(i->fmt, i->nfmt * sizeof(*fmt))) == nil)
@@ -69,6 +67,9 @@
s = t;
}
}
+ }else{
+ werrstr("codec_type missing");
+ goto err;
}
}
}
@@ -82,6 +83,10 @@
}
return 0;
+err:
+ werrstr("addfmt: %r");
+ jsonfree(j);
+ return -1;
}
Info *
@@ -94,6 +99,7 @@
Info *i;
peertube = 0;
+ i = nil;
if((fd = hget(url, -1)) >= 0){
if((s = readall(fd)) != nil){
if((o = strstr(s, "property=\"og:platform\"")) != nil && strstr(o+23, "content=\"PeerTube\"") != nil)
@@ -126,10 +132,8 @@
close(fd);
}
procwait();
- if(j == nil){
- werrstr("peertube: %r");
- return nil;
- }
+ if(j == nil)
+ goto err;
if((i = calloc(1, sizeof(*i))) == nil)
sysfatal("memory");
@@ -141,11 +145,20 @@
if((s = jsonstr(jsonbyname(j, "publishedAt"))) != nil)
tmparse(&i->published, "YYYY-MM-DDThh:mm:ss.ttt", s, nil, nil);
+ if((z = jfield(j, JSONArray, "files", nil)) != nil){
+ for(f = z->first; f != nil; f = f->next){
+ if(addfmt(i, f->val) != 0)
+ goto err;
+ }
+ }
+
if((z = jfield(j, JSONArray, "streamingPlaylists", nil)) != nil){
for(e = z->first; e != nil; e = e->next){
if((z = jfield(e->val, JSONArray, "files", nil)) != nil){
- for(f = z->first; f != nil; f = f->next)
- addfmt(i, f->val);
+ for(f = z->first; f != nil; f = f->next){
+ if(addfmt(i, f->val) != 0)
+ goto err;
+ }
}
}
}
@@ -153,4 +166,8 @@
jsonfree(j);
return i;
+err:
+ werrstr("peertube: %r");
+ free(i);
+ return nil;
}
--- a/util.c
+++ b/util.c
@@ -100,6 +100,8 @@
char *argv[] = {"hget", url, nil};
int p[2];
+ if(debug)
+ fprint(2, "GET %s\n", url);
if(out >= 0){
p[0] = open("/dev/null", OREAD);
p[1] = out;
--- a/youtube.c
+++ b/youtube.c
@@ -54,6 +54,7 @@
int fd;
j = nil;
+ i = nil;
if((fd = hget(instlst, -1)) >= 0){
if((s = readall(fd)) != nil){
j = jsonparse(s);
@@ -64,7 +65,7 @@
procwait();
if(j == nil){
werrstr("instances: %r");
- return nil;
+ goto err;
}
for(e = j->first, i = nil; e != nil && i == nil; e = e->next){
@@ -100,10 +101,8 @@
tmtime(&i->published, jint(z, "published"), nil);
for(fmtname = fmtnames; *fmtname; fmtname++){
- if((x = jsonbyname(z, *fmtname)) == nil){
- if(debug) fprint(2, "%s: no streams\n", u);
+ if((x = jsonbyname(z, *fmtname)) == nil)
continue;
- }
for(f = x->first; f != nil; f = f->next)
addfmt(i, f->val);
@@ -127,4 +126,9 @@
jsonfree(j);
return i;
+err:
+ werrstr("youtube: %r");
+ free(i);
+ jsonfree(j);
+ return nil;
}