Xfce Wiki

Sub domains
 

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
midori:webmedia_now-playing [2015/01/05 22:37] – [Some examples] jamesaxlmidori:webmedia_now-playing [2015/02/01 13:44] (current) – [BIG THanks] jamesaxl
Line 29: Line 29:
         }         }
     ')     ')
-echo "You are now playing: $ARTIST - $TITLE"+echo "You are now playing: $VideoTitle - $VideoUri"
 </code> </code>
-As you see **mediaHerald** is a Dbus service that extension created to store video's title and uri.\\ +As you see **mediaHerald** is a Dbus service that our extension created to store video's title and uri.\\ 
-Let's do an example you first open [[https://www.youtube.com/watch?v=O2cebaY5Wlc]] and run our script shell, the result is:+Let's do an example you should first open [[https://www.youtube.com/watch?v=O2cebaY5Wlc]] and run our shell script, the result is:
 <code> <code>
 You are now playing:  - ‪Midori 0.5.8 : A Fast and Lightweight Web Browser For Linux Mint - YouTube You are now playing:  - ‪Midori 0.5.8 : A Fast and Lightweight Web Browser For Linux Mint - YouTube
Line 60: Line 60:
 } }
 </code> </code>
-Result :\\+**Result:**\\
 <code> <code>
 you are playing ‪Midori 0.5.8 : A Fast and Lightweight Web Browser For Linux Mint - YouTube, follow me on https://www.youtube.com/watch?v=O2cebaY5Wlc you are playing ‪Midori 0.5.8 : A Fast and Lightweight Web Browser For Linux Mint - YouTube, follow me on https://www.youtube.com/watch?v=O2cebaY5Wlc
 </code> </code>
-**Python let's make more short 8-)**+**Python let's make it more short 8-)**
 <code> <code>
 import dbus import dbus
Line 71: Line 71:
 props_iface = dbus.Interface(service, 'org.freedesktop.DBus.Properties') props_iface = dbus.Interface(service, 'org.freedesktop.DBus.Properties')
 properties = props_iface.GetAll('org.midori.mediaHerald') properties = props_iface.GetAll('org.midori.mediaHerald')
-print "You are playing %s, follow me %s" %(properties.get("VideoTitle")[1:], properties.get("VideoUri")[1:])+print "You are playing %s, follow me %s" %(properties.get("VideoTitle")[1:], properties.get("VideoUri")[0:])
 </code> </code>
 **Result:**\\ **Result:**\\
Line 77: Line 77:
 You are playing Midori 0.5.8 : A Fast and Lightweight Web Browser For Linux Mint - YouTube, follow me https://www.youtube.com/watch?v=O2cebaY5Wlc You are playing Midori 0.5.8 : A Fast and Lightweight Web Browser For Linux Mint - YouTube, follow me https://www.youtube.com/watch?v=O2cebaY5Wlc
 </code> </code>
 +**C with Glib and Gio Headache Please LOL**
 +<code>
 +#include <glib.h>
 +#include <gio/gio.h>
 +
 +gchar* get_video_title(GDBusProxy *proxy) {
 + GVariant *_inner_reply;
 + _inner_reply = g_dbus_proxy_get_cached_property (proxy, "VideoTitle");
 + gchar* _result;
 + if (!_inner_reply) {
 + GVariant *_arguments;
 + GVariant *_reply;
 + GVariantBuilder _arguments_builder;
 + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE);
 + g_variant_builder_add_value (&_arguments_builder, g_variant_new_string ("org.midori.mediaHerald"));
 + g_variant_builder_add_value (&_arguments_builder, g_variant_new_string ("VideoTitle"));
 + _arguments = g_variant_builder_end (&_arguments_builder);
 + _reply = g_dbus_proxy_call_sync (proxy, "org.freedesktop.DBus.Properties.Get", _arguments, G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL);
 + if (!_reply) {
 + return NULL;
 + }
 + g_variant_get (_reply, "(v)", &_inner_reply);
 + g_variant_unref (_reply);
 + }
 + _result = g_variant_dup_string (_inner_reply, NULL);
 + g_variant_unref (_inner_reply);
 + return _result;
 +
 +}
 +
 +gchar* get_video_uri(GDBusProxy *proxy) {
 + GVariant *_inner_reply;
 + _inner_reply = g_dbus_proxy_get_cached_property (proxy, "VideoUri");
 + gchar* _result;
 + if (!_inner_reply) {
 + GVariant *_arguments;
 + GVariant *_reply;
 + GVariantBuilder _arguments_builder;
 + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE);
 + g_variant_builder_add_value (&_arguments_builder, g_variant_new_string ("org.midori.mediaHerald"));
 + g_variant_builder_add_value (&_arguments_builder, g_variant_new_string ("VideoUri"));
 + _arguments = g_variant_builder_end (&_arguments_builder);
 + _reply = g_dbus_proxy_call_sync (proxy, "org.freedesktop.DBus.Properties.Get", _arguments, G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL);
 + if (!_reply) {
 + return NULL;
 + }
 + g_variant_get (_reply, "(v)", &_inner_reply);
 + g_variant_unref (_reply);
 + }
 + _result = g_variant_dup_string (_inner_reply, NULL);
 + g_variant_unref (_inner_reply);
 + return _result;
 +}
 +
 +
 +int main(void) {
 + GError *error = NULL;
 + GDBusConnection *bus;
 + GDBusProxy *proxy;
 + bus = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
 + if (!bus) {
 + g_warning("Failed to connect to session bus: %s", error->message);
 + g_error_free(error);
 + return 1;
 + }
 + proxy  = g_dbus_proxy_new_sync (bus,
 +                       G_DBUS_PROXY_FLAGS_NONE,
 +                       NULL,
 +                       "org.midori.mediaHerald",
 +                       "/org/midori/mediaHerald",
 +                       "org.freedesktop.DBus.Properties",
 +                       NULL,
 +                       &error);
 +    gchar* title = get_video_title(proxy);
 +    gchar* uri = get_video_uri(proxy);
 + g_printf("you are now watching  %s - %s\n", title, uri);
 + return 0;
 +}
 +
 +</code>
 +
 +MakeFile
 +<code>
 +pkg_packages := glib-2.0 gio-2.0
 +CC=gcc
 +PKG_CFLAGS  := $(shell pkg-config --cflags $(pkg_packages))
 +PKG_LDFLAGS := $(shell pkg-config --libs $(pkg_packages))
 +
 +CFLAGS  := $(PKG_CFLAGS) $(ADD_CFLAGS) $(CFLAGS)
 +LDFLAGS := $(PKG_LDFLAGS) $(LDFLAGS)
 +
 +targets = midori-example
 +
 +.PHONY: all clean
 +all: $(targets)
 +
 +dbus-example: midori-example.c
 + $(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
 +
 +clean:
 + $(RM) $(targets)
 +</code>
 +
 +**Result:**\\
 +<code>
 +you are now watching  ‪Installing Linux on Tegra TK1 - http://coub.com/view/44obz
 +</code>
 +
 +====== BIG THanks ======
 +**kalikiana **: The developer of MIDORI, code helper.\\
 +**pfor**: Code helper.\\
 +**A.R**(owner of the quote): Earth and all that is in it, with knowledge we protect it. And the best of mankind knowledge makes him and he makes it.
 +