[vlc-commits] ytdl: extract description, author and art URL
Rémi Denis-Courmont
git at videolan.org
Sun Sep 27 18:53:47 CEST 2020
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Sep 27 19:51:40 2020 +0300| [ac989930cb0aa41e28957cc3218d5f7a68b637ef] | committer: Rémi Denis-Courmont
ytdl: extract description, author and art URL
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=ac989930cb0aa41e28957cc3218d5f7a68b637ef
---
modules/demux/ytdl.c | 38 +++++++++++++++++++++++++++++++++-----
1 file changed, 33 insertions(+), 5 deletions(-)
diff --git a/modules/demux/ytdl.c b/modules/demux/ytdl.c
index 0fcd0a0c3c..0504516abc 100644
--- a/modules/demux/ytdl.c
+++ b/modules/demux/ytdl.c
@@ -117,6 +117,21 @@ static const struct json_object *PickFormat(stream_t *s,
return best_fmt;
}
+static const char *PickArt(const struct json_object *entry)
+{
+ const struct json_value *v = json_get(entry, "thumbnails");
+
+ if (v == NULL || v->type != JSON_ARRAY || v->array.size == 0)
+ return NULL;
+
+ v = &v->array.entries[0];
+
+ if (v->type != JSON_OBJECT)
+ return NULL;
+
+ return json_get_str(&v->object, "url");
+}
+
static int ReadItem(stream_t *s, input_item_node_t *node,
const struct json_object *json)
{
@@ -140,11 +155,24 @@ static int ReadItem(stream_t *s, input_item_node_t *node,
input_item_t *item = input_item_NewStream(url, title, ticks);
- if (likely(item != NULL)) {
- input_item_AddOption(item, "no-ytdl", 0);
- input_item_node_AppendItem(node, item);
- input_item_Release(item);
- }
+ if (unlikely(item == NULL))
+ return VLC_ENOMEM;
+
+ const char *desc = json_get_str(json, "description");
+ if (desc != NULL)
+ input_item_SetDescription(item, desc);
+
+ const char *author = json_get_str(json, "uploader");
+ if (author != NULL)
+ input_item_SetArtist(item, author);
+
+ const char *arturl = PickArt(json);
+ if (arturl != NULL)
+ input_item_SetArtURL(item, arturl);
+
+ input_item_AddOption(item, "no-ytdl", 0);
+ input_item_node_AppendItem(node, item);
+ input_item_Release(item);
return VLC_SUCCESS;
}
More information about the vlc-commits
mailing list