[snappy] snappy: add subtitle auto detecting feature
- From: Luis de Bethencourt <luisbg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [snappy] snappy: add subtitle auto detecting feature
- Date: Sat, 10 Oct 2015 22:04:48 +0000 (UTC)
commit 166a980f20ef3a9c574a1b445db492b237068f78
Author: Felipe Martins <felipsmartins gmail com>
Date: Sat Oct 10 22:57:56 2015 +0100
snappy: add subtitle auto detecting feature
src/snappy.c | 14 +++++++++++++-
src/utils.c | 21 +++++++++++++++++++++
src/utils.h | 2 ++
3 files changed, 36 insertions(+), 1 deletions(-)
---
diff --git a/src/snappy.c b/src/snappy.c
index 94b6e5b..92c967e 100644
--- a/src/snappy.c
+++ b/src/snappy.c
@@ -248,8 +248,20 @@ main (int argc, char *argv[])
gst_object_unref (engine->bus);
/* Get uri to load */
- if (uri_list)
+ if (uri_list) {
uri = g_list_first (uri_list)->data;
+ /* based on video filename we can guess subtitle file (.srt files only) */
+ if (NULL == suburi) {
+ gchar suburi_path_guessing[1024]; //buffer
+ gchar *uri_no_extension = strip_filename_extension (uri);
+
+ sprintf (suburi_path_guessing, "%s.srt", uri_no_extension);
+ /* subtitle file exists, defaults for it */
+ if (g_file_test (g_filename_from_uri (suburi_path_guessing, NULL, NULL),
+ G_FILE_TEST_EXISTS))
+ suburi = suburi_path_guessing;
+ }
+ }
/* Load engine and start interface */
engine_load_uri (engine, uri);
diff --git a/src/utils.c b/src/utils.c
index d13b99a..5ba973a 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -89,3 +89,24 @@ clean_brackets_in_uri (gchar * uri)
return clean_uri;
}
+
+gchar *
+strip_filename_extension (gchar * filename)
+{
+ gchar *retstr;
+ gchar *lastdot;
+
+ if (NULL == filename)
+ return NULL;
+
+ if (NULL == (retstr = malloc (strlen (filename) + 1)))
+ return NULL;
+
+ strcpy (retstr, filename);
+ lastdot = strrchr (retstr, '.');
+
+ if (NULL != lastdot)
+ *lastdot = '\0';
+
+ return retstr;
+}
diff --git a/src/utils.h b/src/utils.h
index eb8c454..9f6922c 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -26,12 +26,14 @@
#include <glib.h>
#include <gio/gio.h>
#include <gst/gst.h>
+#include <string.h>
G_BEGIN_DECLS
gchar * cut_long_filename (gchar * filename, gint length);
gchar * clean_uri (gchar * input_arg);
gchar * clean_brackets_in_uri (gchar * uri);
+gchar * strip_filename_extension (gchar * filename);
G_END_DECLS
#endif /* __UTILS_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]