Play videoclip for currently playing song in mpv

Have you ever wanted to quickly find a videoclip of currently playing song?

Tuber
Tuber

Short demo:

Requirements

You’ll need:

System packages

Once you have your player & MPRIS2 installed & configured, install:

sudo dnf install dbus-devel dbus-python-devel dbus-glib-devel ddgr

Python packages

Next step is to install python packages. We’ll use a virtualenv:

mkvirtualenv -p python3.6 mpris2yt2mpv
pip install dbus-python mpris2

Getting artist & song title from D-Bus

Below is a simple script that will connect to the current mpris2 player.

import mpris2
from mpris2 import Player
from mpris2 import get_players_uri

uri = next(get_players_uri())
player = Player(dbus_interface_info={'dbus_uri': uri})

artist = str(player.Metadata["xesam:artist"][0])
title = str(player.Metadata["xesam:title"])

print("{} - {}".format(artist, title))

Save this script somewhere, for example in: mpris2title.py

When you run it, it will simply print:

$ python mpris2title.py 
Glass Animals - Gooey

Alias

Finally, create an alias like below:

alias vid='BROWSER=mpv ddgr -j -w youtube.com `python mpris2title.py`'

This command will search youtube for the song you’re currently playing using ddgr and open the first result in mpv (as it’s set as the default BROWSER for ddgr).

Usage

Now, siply run vid in your terminal an (if you’re lucky) you’ll see videoclip for the currently playing song played in mpv.

Ta-da! you can now quicky find videclips from the comfort of your terminal.