History

player: add `mpv://` protocol

This is useful to run mpv from URL handler. Can be used to start mpv from you web browser or anything that would trigger url handler for given protocol. Only safe protocols are allowed. Current solutions to run mpv in such context are to spawn IPC proxy and run mpv when requested, but this is in most cases not necessary. Currently the protocol is added in mpv.desktop. Windows related registration will follow in future changes.

Kacper Michajłow committed 1 year ago

Commit 93ea3df1 parent 9bc3aee8 files · +109 −3Browse files

Unified · Split

8 files
  1. DOCS/interface-changes/mpv-protocol.txt +1 −0
  2. DOCS/man/mpv.rst +6 −0
  3. demux/demux.c +4 −2
  4. demux/demux_mpv.c +45 −0
  5. etc/mpv.desktop +1 −1
  6. meson.build +2 −0
  7. stream/stream.c +2 −0
  8. stream/stream_mpv.c +48 −0
DOCS/interface-changes/mpv-protocol.txt+1−0
@@ -0,0 +1 @@
1+add `mpv://` protocol
DOCS/man/mpv.rst+6−0
@@ -1280,6 +1280,12 @@ More options to configure this functionality are listed in `Watch Later`_. · 1279 unmodified lines
12801280 PROTOCOLS
12811281 =========
12821282
1283+``mpv://...``
1284+
1285+ mpv protocol. This is used for starting mpv from URL handler. The protocol
1286+ is stripped and the rest is passed to the player as a normal open argument.
1287+ Only safe protocols are allowed to be opened this way.
1288+
12831289 ``http://...``, ``https://``, ...
12841290
12851291 Many network protocols are supported, but the protocol prefix must always
demux/demux.c+4−2
@@ -50,8 +50,9 @@ · 49 unmodified lines
5050 #include "cue.h"
5151
5252 // Demuxer list
53−extern const struct demuxer_desc demuxer_desc_edl;
54−extern const struct demuxer_desc demuxer_desc_cue;
53+extern const demuxer_desc_t demuxer_desc_mpv;
54+extern const demuxer_desc_t demuxer_desc_edl;
55+extern const demuxer_desc_t demuxer_desc_cue;
5556 extern const demuxer_desc_t demuxer_desc_rawaudio;
5657 extern const demuxer_desc_t demuxer_desc_rawvideo;
5758 extern const demuxer_desc_t demuxer_desc_mf;
@@ -80,6 +81,7 @@ static const demuxer_desc_t *const demuxer_list[] = { · 22 unmodified lines
8081 &demuxer_desc_mf,
8182 &demuxer_desc_playlist,
8283 &demuxer_desc_null,
84+ &demuxer_desc_mpv,
8385 NULL
8486 };
8587
demux/demux_mpv.c+45−0
@@ -0,0 +1,45 @@
1+/*
2+ * This file is part of mpv.
3+ *
4+ * mpv is free software; you can redistribute it and/or
5+ * modify it under the terms of the GNU Lesser General Public
6+ * License as published by the Free Software Foundation; either
7+ * version 2.1 of the License, or (at your option) any later version.
8+ *
9+ * mpv is distributed in the hope that it will be useful,
10+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+ * GNU Lesser General Public License for more details.
13+ *
14+ * You should have received a copy of the GNU Lesser General Public
15+ * License along with mpv. If not, see <http://www.gnu.org/licenses/>.
16+ */
17+
18+#include "demux.h"
19+
20+#include <common/playlist.h>
21+#include <stream/stream.h>
22+
23+static int open_mpv(struct demuxer *demuxer, enum demux_check check)
24+{
25+ if (check != DEMUX_CHECK_REQUEST)
26+ return -1;
27+
28+ struct stream *s = demuxer->stream;
29+ if (!s->info || strcmp(s->info->name, "mpv"))
30+ return -1;
31+
32+ demuxer->playlist = talloc_zero(demuxer, struct playlist);
33+ playlist_append_file(demuxer->playlist, s->path);
34+ playlist_set_stream_flags(demuxer->playlist, demuxer->stream_origin);
35+ demuxer->fully_read = true;
36+ demux_close_stream(demuxer);
37+
38+ return 0;
39+}
40+
41+const struct demuxer_desc demuxer_desc_mpv = {
42+ .name = "mpv",
43+ .desc = "mpv protocol",
44+ .open = open_mpv,
45+};
etc/mpv.desktop+1−1
@@ -45,7 +45,7 @@ Exec=mpv --player-operation-mode=pseudo-gui -- %U · 44 unmodified lines
4545 Terminal=false
4646 Categories=AudioVideo;Audio;Video;Player;TV;
4747 MimeType=application/ogg;application/x-ogg;application/mxf;application/sdp;application/smil;application/x-smil;application/streamingmedia;application/x-streamingmedia;application/vnd.rn-realmedia;application/vnd.rn-realmedia-vbr;audio/aac;audio/x-aac;audio/vnd.dolby.heaac.1;audio/vnd.dolby.heaac.2;audio/aiff;audio/x-aiff;audio/m4a;audio/x-m4a;application/x-extension-m4a;audio/mp1;audio/x-mp1;audio/mp2;audio/x-mp2;audio/mp3;audio/x-mp3;audio/mpeg;audio/mpeg2;audio/mpeg3;audio/mpegurl;audio/x-mpegurl;audio/mpg;audio/x-mpg;audio/rn-mpeg;audio/musepack;audio/x-musepack;audio/ogg;audio/scpls;audio/x-scpls;audio/vnd.rn-realaudio;audio/wav;audio/x-pn-wav;audio/x-pn-windows-pcm;audio/x-realaudio;audio/x-pn-realaudio;audio/x-ms-wma;audio/x-pls;audio/x-wav;video/mpeg;video/x-mpeg2;video/x-mpeg3;video/mp4v-es;video/x-m4v;video/mp4;application/x-extension-mp4;video/divx;video/vnd.divx;video/msvideo;video/x-msvideo;video/ogg;video/quicktime;video/vnd.rn-realvideo;video/x-ms-afs;video/x-ms-asf;audio/x-ms-asf;application/vnd.ms-asf;video/x-ms-wmv;video/x-ms-wmx;video/x-ms-wvxvideo;video/x-avi;video/avi;video/x-flic;video/fli;video/x-flc;video/flv;video/x-flv;video/x-theora;video/x-theora+ogg;video/x-matroska;video/mkv;audio/x-matroska;application/x-matroska;video/webm;audio/webm;audio/vorbis;audio/x-vorbis;audio/x-vorbis+ogg;video/x-ogm;video/x-ogm+ogg;application/x-ogm;application/x-ogm-audio;application/x-ogm-video;application/x-shorten;audio/x-shorten;audio/x-ape;audio/x-wavpack;audio/x-tta;audio/AMR;audio/ac3;audio/eac3;audio/amr-wb;video/mp2t;audio/flac;audio/mp4;application/x-mpegurl;video/vnd.mpegurl;application/vnd.apple.mpegurl;audio/x-pn-au;video/3gp;video/3gpp;video/3gpp2;audio/3gpp;audio/3gpp2;video/dv;audio/dv;audio/opus;audio/vnd.dts;audio/vnd.dts.hd;audio/x-adpcm;application/x-cue;audio/m3u;audio/vnd.wave;video/vnd.avi;
48−X-KDE-Protocols=appending,file,ftp,hls,http,https,mms,rist,rtmp,rtmps,rtmpt,rtmpts,rtp,rtsp,rtsps,sftp,smb,srt,srtp,webdav,webdavs
48+X-KDE-Protocols=appending,file,ftp,hls,http,https,mms,mpv,rist,rtmp,rtmps,rtmpt,rtmpts,rtp,rtsp,rtsps,sftp,smb,srt,srtp,webdav,webdavs
4949 StartupWMClass=mpv
5050 Keywords=mpv;media;player;video;audio;tv;
5151 Keywords[ar]=mpv;إم بي في;ام بي في;وسائط;مشغل;فيديو;مرئية;صوتي;تلفاز;
meson.build+2−0
@@ -100,6 +100,7 @@ sources = files( · 99 unmodified lines
100100 'demux/demux_mf.c',
101101 'demux/demux_mkv.c',
102102 'demux/demux_mkv_timeline.c',
103+ 'demux/demux_mpv.c',
103104 'demux/demux_null.c',
104105 'demux/demux_playlist.c',
105106 'demux/demux_raw.c',
@@ -189,6 +190,7 @@ sources = files( · 83 unmodified lines
189190 'stream/stream_lavf.c',
190191 'stream/stream_memory.c',
191192 'stream/stream_mf.c',
193+ 'stream/stream_mpv.c',
192194 'stream/stream_null.c',
193195 'stream/stream_slice.c',
194196
stream/stream.c+2−0
@@ -42,6 +42,7 @@ · 41 unmodified lines
4242 #include "options/m_option.h"
4343 #include "options/m_config.h"
4444
45+extern const stream_info_t stream_info_mpv;
4546 extern const stream_info_t stream_info_cdda;
4647 extern const stream_info_t stream_info_dvb;
4748 extern const stream_info_t stream_info_null;
@@ -63,6 +64,7 @@ extern const stream_info_t stream_info_libarchive; · 15 unmodified lines
6364 extern const stream_info_t stream_info_cb;
6465
6566 static const stream_info_t *const stream_list[] = {
67+ &stream_info_mpv,
6668 #if HAVE_CDDA
6769 &stream_info_cdda,
6870 #endif
stream/stream_mpv.c+48−0
@@ -0,0 +1,48 @@
1+/*
2+ * This file is part of mpv.
3+ *
4+ * mpv is free software; you can redistribute it and/or
5+ * modify it under the terms of the GNU Lesser General Public
6+ * License as published by the Free Software Foundation; either
7+ * version 2.1 of the License, or (at your option) any later version.
8+ *
9+ * mpv is distributed in the hope that it will be useful,
10+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+ * GNU Lesser General Public License for more details.
13+ *
14+ * You should have received a copy of the GNU Lesser General Public
15+ * License along with mpv. If not, see <http://www.gnu.org/licenses/>.
16+ */
17+
18+#include "stream.h"
19+
20+#include <misc/path_utils.h>
21+#include <player/core.h>
22+
23+static int open_mpv(stream_t *st)
24+{
25+ bstr proto = mp_split_proto(bstr0(st->path), NULL);
26+ if (proto.len) {
27+ if (!bstrcasecmp0(proto, "mpv")) {
28+ MP_ERR(st, "Nested mpv:// is not allowed.\n");
29+ return STREAM_NO_MATCH;
30+ }
31+ char **safe_protocols = stream_get_proto_list(true);
32+ bool safe = str_in_list(proto, safe_protocols);
33+ talloc_free(safe_protocols);
34+ if (!safe) {
35+ MP_ERR(st, "Unsafe protocol '%.*s' opened with mpv://.\n", BSTR_P(proto));
36+ return STREAM_NO_MATCH;
37+ }
38+ }
39+
40+ st->demuxer = "mpv";
41+ return STREAM_OK;
42+}
43+
44+const stream_info_t stream_info_mpv = {
45+ .name = "mpv",
46+ .open = open_mpv,
47+ .protocols = (const char*const[]){"mpv", NULL},
48+};

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t