markhuge

Queue Media in Mpv From Surf

Published by Mark on

Surf has an external media player function called clickexternplayer. This function invokes a macro called VIDEOPLAY that’s defined in the config.def.h file.

Here, I’ve edited the macro to use the mmq script from this post:

/* VIDEOPLAY(URI) */
#define VIDEOPLAY(u) {\
        .v = (const char *[]){ "/bin/sh", "-c", \
             "mmq \"$0\"", u, NULL \
        } \
}

By default this function is only called when you click on media with the OnMedia target in the button definitions. In this case I added a handler to send a link to the mpv queue when I Shift+click:

/* button definitions */
/* target can be OnDoc, OnLink, OnImg, OnMedia, OnEdit, OnBar, OnSel, OnAny */
static Button buttons[] = {
	/* target       event mask      button  function        argument        stop event */
	{ OnLink,       GDK_SHIFT_MASK, 1,      clickexternplayer, { 0 },       1 },

This is super handy for sites like YouTube, because I don’t need to go to each individual video page to queue the content. I can just shift click as I go through the feeds, and the videos are added to my playlist.

It also allows me to queue videos from multiple sources, YouTube, Vimeo, Twitch, etc. on the same playlist.