API: Parse title from URI when no title in tags

This commit is contained in:
Rafał Dzięgiel
2021-05-22 09:37:47 +02:00
parent 7535c4e598
commit edb799bafa
3 changed files with 40 additions and 6 deletions

View File

@@ -108,7 +108,7 @@ struct _GstClapperMediaInfo
GList *video_stream_list;
GList *subtitle_stream_list;
GstClockTime duration;
GstClockTime duration;
};
struct _GstClapperMediaInfoClass

View File

@@ -767,7 +767,8 @@ gst_clapper_media_info_get_toc (const GstClapperMediaInfo * info)
* gst_clapper_media_info_get_title:
* @info: a #GstClapperMediaInfo
*
* Returns: the media title.
* Returns: the media title. When metadata does not contain title,
* returns title parsed from URI.
*/
const gchar *
gst_clapper_media_info_get_title (const GstClapperMediaInfo * info)

View File

@@ -1804,8 +1804,12 @@ request_state_cb (G_GNUC_UNUSED GstBus * bus, GstMessage * msg,
static void
media_info_update (GstClapper * self, GstClapperMediaInfo * info)
{
g_free (info->title);
info->title = get_from_tags (self, info, get_title);
/* Update title from new tags or leave the title from URI */
gchar *tags_title = get_from_tags (self, info, get_title);
if (tags_title) {
g_free (info->title);
info->title = tags_title;
}
g_free (info->container);
info->container = get_from_tags (self, info, get_container_format);
@@ -2672,6 +2676,32 @@ subtitle_changed_cb (G_GNUC_UNUSED GObject * object, gpointer user_data)
g_mutex_unlock (&self->lock);
}
static gchar *
get_title_from_uri (const gchar * uri)
{
gchar *proto = gst_uri_get_protocol (uri);
gchar *title = NULL;
if (strcmp (proto, "file") == 0) {
const gchar *ext = strrchr (uri, '.');
if (ext && strlen (ext) < 8) {
gchar *filename = g_filename_from_uri (uri, NULL, NULL);
if (filename) {
gchar *base = g_path_get_basename (filename);
g_free (filename);
title = g_strndup (base, strlen (base) - strlen (ext));
g_free (base);
}
}
} else if (strcmp (proto, "dvb") == 0) {
const gchar *channel = strrchr (uri, '/') + 1;
title = g_strdup (channel);
}
g_free (proto);
return title;
}
static void *
get_title (GstTagList * tags)
{
@@ -2788,12 +2818,15 @@ gst_clapper_media_info_create (GstClapper * self)
}
media_info->title = get_from_tags (self, media_info, get_title);
if (!media_info->title)
media_info->title = get_title_from_uri (self->uri);
media_info->container =
get_from_tags (self, media_info, get_container_format);
media_info->image_sample = get_from_tags (self, media_info, get_cover_sample);
GST_DEBUG_OBJECT (self, "uri: %s title: %s duration: %" GST_TIME_FORMAT
" seekable: %s live: %s container: %s image_sample %p",
GST_DEBUG_OBJECT (self, "uri: %s, title: %s, duration: %" GST_TIME_FORMAT
", seekable: %s, live: %s, container: %s, image_sample %p",
media_info->uri, media_info->title, GST_TIME_ARGS (media_info->duration),
media_info->seekable ? "yes" : "no", media_info->is_live ? "yes" : "no",
media_info->container, media_info->image_sample);