Merge lp:~vikoadi/audience/fix-no-extensions into lp:~audience-members/audience/trunk

Proposed by Viko Adi Rahmawan
Status: Rejected
Rejected by: Cody Garver
Proposed branch: lp:~vikoadi/audience/fix-no-extensions
Merge into: lp:~audience-members/audience/trunk
Diff against target: 121 lines (+37/-33)
3 files modified
src/Audience.vala (+1/-1)
src/Utils.vala (+35/-31)
src/Widgets/Playlist.vala (+1/-1)
To merge this branch: bzr merge lp:~vikoadi/audience/fix-no-extensions
Reviewer Review Type Date Requested Status
xapantu (community) Disapprove
Avi Romanoff (community) Approve
Review via email: mp+237168@code.launchpad.net

Commit message

fix empty video title in playlist and welcome screen when opening video without .extension

Description of the change

fix empty video title in playlist and welcome screen when opening video without .extension

To post a comment you must log in.
Revision history for this message
Cody Garver (codygarver) wrote :

When I play a video without an extension (or any .'s in the filename), for example "#video", I get a blank window title. But "#video.mp4" or "#video.non-extension-text" display as expected.

408. By Viko Adi Rahmawan

rewrite string utils

409. By Viko Adi Rahmawan

assume extension is three character

410. By Viko Adi Rahmawan

merge trunk

Revision history for this message
Viko Adi Rahmawan (vikoadi) wrote :

I end up assuming extension is three character anyway, in case we have a dot char in the middle of no extension name

Revision history for this message
Robert Roth (evfool) wrote :

Assuming only three characters might not be the best, e.g. .mpeg won't be happy.

Revision history for this message
Viko Adi Rahmawan (vikoadi) wrote :

> Assuming only three characters might not be the best, e.g. .mpeg won't be
> happy.

I can't find a way to detect that after the dot is an extenstions or not unless we list all video extensions which supported by GStreamer. Any Idea?

Revision history for this message
Artem Anufrij (artem-anufrij) wrote :

See all possible video file extensions here:

http://en.wikipedia.org/wiki/Digital_container_format

Revision history for this message
Avi Romanoff (aroman) wrote :

I can confirm this fixes the issue. I agree that the solution proposed isn't perfect (assuming file extension length), but it definitely fixes most common instances of the related bug. I tried an mp4 without the .mp4 extension against trunk, and it had a blank title. I tried it against this branch, and the title showed as expected.

I propose we merge.

review: Approve
Revision history for this message
xapantu (xapantu) wrote :

No, that will not work with .mpeg for instance, or .webm.

Can we have a different behavior? I would like audience to check if there is a dot in the filename. If so, it just removes what follows (so, yes, if you have The.Filename.mp4 without an extension, you will just get The, but that does not really matter as in most cases there is an extension). If it does not find a dot, then it just uses the whole filename.

review: Disapprove

Unmerged revisions

410. By Viko Adi Rahmawan

merge trunk

409. By Viko Adi Rahmawan

assume extension is three character

408. By Viko Adi Rahmawan

rewrite string utils

407. By Viko Adi Rahmawan

fix empty playlist when opening video without extension

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Audience.vala'
2--- src/Audience.vala 2014-10-05 05:04:18 +0000
3+++ src/Audience.vala 2014-10-10 12:54:51 +0000
4@@ -333,7 +333,7 @@
5 //welcome.append ("internet-web-browser", _("Open a location"), _("Watch something from the infinity of the internet"));
6 var filename = settings.current_video;
7 var last_file = File.new_for_uri (filename);
8- welcome.append ("media-playback-start", _("Resume last video"), get_title (last_file.get_basename ()));
9+ welcome.append ("media-playback-start", _("Resume last video"), get_title (last_file.get_uri ()));
10 bool show_last_file = settings.current_video != "";
11 if (last_file.query_exists () == false) {
12 show_last_file = false;
13
14=== modified file 'src/Utils.vala'
15--- src/Utils.vala 2014-09-03 17:44:50 +0000
16+++ src/Utils.vala 2014-10-10 12:54:51 +0000
17@@ -16,6 +16,7 @@
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * Authored by: Tom Beckmann <tomjonabc@gmail.com>
21+ * Viko Adi Rahmawan <vikoadi@gmail.com>
22 */
23
24 [DBus (name = "org.gnome.SettingsDaemon.MediaKeys")]
25@@ -50,36 +51,39 @@
26 func (file_to_process);
27 }
28 }
29+
30+ // return title without extensions from an uri or basename
31 public static string get_title (string filename) {
32- var title = get_basename (filename);
33- title = Uri.unescape_string (title);
34- title = title.replace ("_", " ").replace (".", " ").replace (" ", " ");
35-
36- return title;
37- }
38-
39- public static string get_extension (string filename) {
40- for (uint i=filename.length; i!=0; i--) {
41- if (filename[i] == '.')
42- return filename.substring (i+1);
43- }
44-
45- return filename;
46- }
47-
48- public static string get_basename (string filename) {
49- uint end = 0;
50- for (uint start=filename.length; start != 0; start--) {
51- if (filename[start] == '/') {
52- start ++;
53- return filename.substring (start, end - start);
54- }
55-
56- if (filename[start] == '.' && end == 0)
57- end = start;
58- }
59-
60- return filename.substring (0, end);
61+ string basename = get_basename (filename);
62+ string ext = get_extension (basename);
63+
64+ if (ext != "") {
65+ basename = basename.slice (0, - (ext.length + 1));
66+ }
67+
68+ return basename.replace ("_", " ").replace (".", " ").replace (" ", " ");
69+ }
70+
71+ // return extension of a filename, return empty string if nothing found
72+ // extension keep original character case
73+ public static string get_extension (string uri) {
74+ if (uri.length > 4 && uri.get_char (uri.length - 4) == '.') {
75+ string ext = uri.substring (-3);
76+ if (!ext.contains ("/"))
77+ return ext;
78+ }
79+
80+ return "";
81+ }
82+
83+ // return filename without full path of an uri
84+ public static string get_basename (string uri) {
85+ string path = Uri.unescape_string (uri);
86+ int end = path.last_index_of_char ('/');
87+ if (end > -1)
88+ return path.substring (end + 1);
89+ else
90+ return path;
91 }
92
93 public static string seconds_to_time (int seconds) {
94@@ -111,7 +115,7 @@
95 var file = File.new_for_uri (uri);
96 return file.query_exists ();
97 }
98-
99+
100 /**
101 * Notifications
102 */
103@@ -153,4 +157,4 @@
104 }
105 #endif
106 }
107-}
108\ No newline at end of file
109+}
110
111=== modified file 'src/Widgets/Playlist.vala'
112--- src/Widgets/Playlist.vala 2014-10-03 23:49:32 +0000
113+++ src/Widgets/Playlist.vala 2014-10-10 12:54:51 +0000
114@@ -119,7 +119,7 @@
115
116 playlist.append (out iter);
117 playlist.set (iter, Columns.PLAYING, playing,
118- Columns.TITLE, Audience.get_title (path.get_basename ()),
119+ Columns.TITLE, Audience.get_title (path.get_uri ()),
120 Columns.FILENAME, path.get_uri ());
121 }
122

Subscribers

People subscribed via source and target branches