Merge lp:~midori/midori/webmedia-now-playing into lp:midori

Proposed by axlrose112
Status: Merged
Approved by: Cris Dywan
Approved revision: 6603
Merged at revision: 6668
Proposed branch: lp:~midori/midori/webmedia-now-playing
Merge into: lp:midori
Diff against target: 151 lines (+147/-0)
1 file modified
extensions/webmedia-now-playing.vala (+147/-0)
To merge this branch: bzr merge lp:~midori/midori/webmedia-now-playing
Reviewer Review Type Date Requested Status
Cris Dywan Approve
Review via email: mp+212320@code.launchpad.net

Commit message

Share 'youtube, vimeo, dailymotion' that you are playing in Midori using org.midori.mediaHerald

To post a comment you must log in.
6601. By axlrose112

Add Desktop notification

Revision history for this message
Cris Dywan (kalikiana) wrote :

I'm getting like 10 notifications for the same video. Might be good to save the last video or similar to avoid this.

review: Needs Fixing
6602. By axlrose112

Disbale more than one notify when playing video

6603. By axlrose112

webmedia-now-playing: fix some browser uri issues

Revision history for this message
Cris Dywan (kalikiana) wrote :

Works like a charm now. Thanks a lot for the fixes!

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

your so welcome i ma just going to add now notify that midori.App has, and ifdefs for WIN

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'extensions/webmedia-now-playing.vala'
2--- extensions/webmedia-now-playing.vala 1970-01-01 00:00:00 +0000
3+++ extensions/webmedia-now-playing.vala 2014-04-07 21:40:13 +0000
4@@ -0,0 +1,147 @@
5+/*
6+ Copyright (C) 2014 James Axl <axlrose112@gmail.com>
7+
8+ This library is free software; you can redistribute it and/or
9+ modify it under the terms of the GNU Lesser General Public
10+ License as published by the Free Software Foundation; either
11+ version 2.1 of the License, or (at your option) any later version.
12+
13+ See the file COPYING for the full license text.
14+*/
15+
16+namespace Sandcat {
17+
18+ private class Manager : Midori.Extension {
19+ DbusService dbus_service { get; set; }
20+ WebMediaNotify web_media_notify { get; set; }
21+ string web_media_uri { get; set; }
22+ string web_media_title { get; set; }
23+ internal Manager () {
24+ GLib.Object (name: _("Webmedia now-playing"),
25+ description: _("Share 'youtube, vimeo, dailymotion' that you are playing in Midori using org.midori.mediaHerald"),
26+ version: "0.1" + Midori.VERSION_SUFFIX,
27+ authors: "James Axl <axlrose112@gmail.com>");
28+ activate.connect (this.activated);
29+ deactivate.connect (this.deactivated);
30+ }
31+
32+ void youtube_validation (string title, string uri) {
33+
34+ /* FIXED ME, i used this way because broweser notify send
35+ many request and when can not check the right title and also
36+ to have one notify*/
37+ if(uri == title || uri.contains(title)) return;
38+ if (web_media_uri == uri) return;
39+ if (web_media_title == title) return;
40+ web_media_uri = uri;
41+ web_media_title = title;
42+ try {
43+ var youtube = new Regex("""(http|https)://www.youtube.com/watch\?v=[&=_\-A-Za-z0-9.]+""");
44+ var vimeo = new Regex("""(http|https)://vimeo.com/[0-9]+""");
45+ var dailymotion = new Regex("""(http|https)://www.dailymotion.com/video/[_\-A-Za-z0-9]+""");
46+ string website = null;
47+ if (web_media_uri.contains("youtube") || uri.contains("vimeo") || uri.contains ("dailymotion")) {
48+ if (youtube.match(web_media_uri))
49+ website = "Youtube";
50+ else if (vimeo.match(web_media_uri))
51+ website = "Vimeo";
52+ else if (dailymotion.match(web_media_uri))
53+ website = "Dailymotion";
54+
55+ if (website != null) {
56+ dbus_service.video_title = web_media_title;
57+ web_media_notify.notify_media = website;
58+ web_media_notify.notify_video_title = web_media_title;
59+ dbus_service.video_uri = web_media_uri;
60+ web_media_notify.show_notify();
61+ }
62+ } else {
63+ dbus_service.dbus_empty();
64+ web_media_title = null;
65+ web_media_uri = null;
66+ }
67+ } catch(RegexError e) {
68+ warning ("%s", e.message);
69+ }
70+ }
71+
72+ void browser_added (Midori.Browser browser) {
73+ browser.notify["title"].connect (() => {
74+ youtube_validation(browser.title, browser.uri);
75+ });
76+ }
77+
78+ void activated (Midori.App app) {
79+ dbus_service = new DbusService();
80+ web_media_notify = new WebMediaNotify();
81+ foreach (var browser in app.get_browsers ())
82+ browser_added (browser);
83+ app.add_browser.connect (browser_added);
84+ dbus_service.register_service();
85+ }
86+
87+ void deactivated () {
88+ var app = get_app ();
89+ app.add_browser.disconnect (browser_added);
90+ dbus_service.unregister_service();
91+ }
92+ }
93+
94+ [DBus (name = "org.midori.mediaHerald")]
95+ public class DbusService : Object {
96+ uint service { get; set; }
97+ uint own_name_id { get; set; }
98+ DBusConnection dbus_service_connection { get; set; }
99+ public string video_title { get; set; }
100+ public string video_uri { get; set; }
101+
102+ public DbusService() {
103+ dbus_empty();
104+ }
105+
106+ public void dbus_empty() {
107+ video_title = null;
108+ video_uri = null;
109+ }
110+
111+ public void register_service() {
112+ own_name_id = Bus.own_name (BusType.SESSION, "org.midori.mediaHerald", BusNameOwnerFlags.NONE,
113+ on_bus_aquired,
114+ () => {},
115+ () => stderr.printf ("Could not acquire name\n"));
116+ }
117+
118+ public void unregister_service() {
119+ Bus.unown_name(own_name_id);
120+ dbus_service_connection.unregister_object (service);
121+ }
122+
123+ void on_bus_aquired (DBusConnection connection) {
124+ try {
125+ dbus_service_connection = connection;
126+ service = connection.register_object ("/org/midori/mediaHerald", this);
127+ } catch (IOError e) {
128+ stderr.printf ("Could not register service\n");
129+ }
130+ }
131+ }
132+
133+ public class WebMediaNotify {
134+ public string notify_video_title { get; set; }
135+ public string notify_media { get; set; }
136+
137+ public void show_notify () {
138+ try {
139+ Notify.init ("Midori");
140+ var notify = new Notify.Notification("Midori is playing in " + notify_media, notify_video_title, "midori");
141+ notify.show();
142+ } catch (Error e) {
143+ error ("Error: %s", e.message);
144+ }
145+ }
146+ }
147+}
148+
149+public Midori.Extension extension_init () {
150+ return new Sandcat.Manager ();
151+}

Subscribers

People subscribed via source and target branches

to all changes: