Xfce Wiki

Sub domains
 

This is an old revision of the document!


Webmedia now-playing - Tutorial

This document is licensed under the LGPL 2.1.

What is Webmedia now-playing

Webmedia now-playing is a midori extension developed for using Dbus, this extension allow users to get the video title that midori play in youtube/ Vimeo/ Dailymention/Coup.
In this Tuto We are going to show you how to use it :-).

Using Shell script

Big thanks to meebey the owner of this script.

eval $(dbus-send --session --print-reply --dest=org.midori.mediaHerald /org/midori/mediaHerald org.freedesktop.DBus.Properties.GetAll string:"org.midori.mediaHerald" | awk '
    /string  *"VideoTitle/{
        while (1) {
            getline line
            if (line ~ /string "/)
                sub(/.*string /, "TITLE=", line)
                print line
                break
            }
        }
        /string  *"VideoUri/{
        while (1) {
            getline line
            if (line ~ /string "/)
                sub(/.*string /, "URI=", line)
                print line
                break
            }
        }
    ')
echo "You are now playing: $ARTIST - $TITLE"

As you see mediaHerald is a Dbus service that 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:

You are now playing:  - ‪Midori 0.5.8 : A Fast and Lightweight Web Browser For Linux Mint - YouTube

Enjoy baby :-D

Some examples

VALA

[DBus (name = "org.midori.mediaHerald")]
interface Demo : Object {
    public abstract string video_title {owned get; owned set;}
    public abstract string video_uri {owned get; owned set;}
}

void main () {
  try {
    Demo demo = Bus.get_proxy_sync (BusType.SESSION, "org.midori.mediaHerald",
                                    "/org/midori/mediaHerald");

    string title = demo.video_title;
    string uri = demo.video_uri;
    stdout.printf ("you are playing %s, follow me on %s\n", title, uri);

  } catch (IOError e) {
    stderr.printf ("%s\n", e.message);
  }
}

Result :

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

Python let's make more short 8-)

import dbus
bus = dbus.SessionBus()
service = bus.get_object('org.midori.mediaHerald','/org/midori/mediaHerald')
props_iface = dbus.Interface(service, 'org.freedesktop.DBus.Properties')
properties = props_iface.GetAll('org.midori.mediaHerald')
print "You are playing %s, follow me %s" %(properties.get("VideoTitle")[1:], properties.get("VideoUri")[1:])

Result:

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