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 @@
1add `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
1280PROTOCOLS1280PROTOCOLS
1281=========1281=========
1282 1282
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
1283``http://...``, ``https://``, ...1289``http://...``, ``https://``, ...
1284 1290
1285 Many network protocols are supported, but the protocol prefix must always1291 Many network protocols are supported, but the protocol prefix must always
demux/demux.c+4−2
@@ -50,8 +50,9 @@ · 49 unmodified lines
50#include "cue.h"50#include "cue.h"
51 51
52// Demuxer list52// Demuxer list
53extern const struct demuxer_desc demuxer_desc_edl;53extern const demuxer_desc_t demuxer_desc_mpv;
54extern const struct demuxer_desc demuxer_desc_cue;54extern const demuxer_desc_t demuxer_desc_edl;
55extern const demuxer_desc_t demuxer_desc_cue;
55extern const demuxer_desc_t demuxer_desc_rawaudio;56extern const demuxer_desc_t demuxer_desc_rawaudio;
56extern const demuxer_desc_t demuxer_desc_rawvideo;57extern const demuxer_desc_t demuxer_desc_rawvideo;
57extern const demuxer_desc_t demuxer_desc_mf;58extern const demuxer_desc_t demuxer_desc_mf;
@@ -80,6 +81,7 @@ static const demuxer_desc_t *const demuxer_list[] = { · 22 unmodified lines
80 &demuxer_desc_mf,81 &demuxer_desc_mf,
81 &demuxer_desc_playlist,82 &demuxer_desc_playlist,
82 &demuxer_desc_null,83 &demuxer_desc_null,
84 &demuxer_desc_mpv,
83 NULL85 NULL
84};86};
85 87
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
23static 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
41const 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
45Terminal=false45Terminal=false
46Categories=AudioVideo;Audio;Video;Player;TV;46Categories=AudioVideo;Audio;Video;Player;TV;
47MimeType=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;47MimeType=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;
48X-KDE-Protocols=appending,file,ftp,hls,http,https,mms,rist,rtmp,rtmps,rtmpt,rtmpts,rtp,rtsp,rtsps,sftp,smb,srt,srtp,webdav,webdavs48X-KDE-Protocols=appending,file,ftp,hls,http,https,mms,mpv,rist,rtmp,rtmps,rtmpt,rtmpts,rtp,rtsp,rtsps,sftp,smb,srt,srtp,webdav,webdavs
49StartupWMClass=mpv49StartupWMClass=mpv
50Keywords=mpv;media;player;video;audio;tv;50Keywords=mpv;media;player;video;audio;tv;
51Keywords[ar]=mpv;إم بي في;ام بي في;وسائط;مشغل;فيديو;مرئية;صوتي;تلفاز;51Keywords[ar]=mpv;إم بي في;ام بي في;وسائط;مشغل;فيديو;مرئية;صوتي;تلفاز;
meson.build+2−0
@@ -100,6 +100,7 @@ sources = files( · 99 unmodified lines
100 'demux/demux_mf.c',100 'demux/demux_mf.c',
101 'demux/demux_mkv.c',101 'demux/demux_mkv.c',
102 'demux/demux_mkv_timeline.c',102 'demux/demux_mkv_timeline.c',
103 'demux/demux_mpv.c',
103 'demux/demux_null.c',104 'demux/demux_null.c',
104 'demux/demux_playlist.c',105 'demux/demux_playlist.c',
105 'demux/demux_raw.c',106 'demux/demux_raw.c',
@@ -189,6 +190,7 @@ sources = files( · 83 unmodified lines
189 'stream/stream_lavf.c',190 'stream/stream_lavf.c',
190 'stream/stream_memory.c',191 'stream/stream_memory.c',
191 'stream/stream_mf.c',192 'stream/stream_mf.c',
193 'stream/stream_mpv.c',
192 'stream/stream_null.c',194 'stream/stream_null.c',
193 'stream/stream_slice.c',195 'stream/stream_slice.c',
194 196
stream/stream.c+2−0
@@ -42,6 +42,7 @@ · 41 unmodified lines
42#include "options/m_option.h"42#include "options/m_option.h"
43#include "options/m_config.h"43#include "options/m_config.h"
44 44
45extern const stream_info_t stream_info_mpv;
45extern const stream_info_t stream_info_cdda;46extern const stream_info_t stream_info_cdda;
46extern const stream_info_t stream_info_dvb;47extern const stream_info_t stream_info_dvb;
47extern const stream_info_t stream_info_null;48extern const stream_info_t stream_info_null;
@@ -63,6 +64,7 @@ extern const stream_info_t stream_info_libarchive; · 15 unmodified lines
63extern const stream_info_t stream_info_cb;64extern const stream_info_t stream_info_cb;
64 65
65static const stream_info_t *const stream_list[] = {66static const stream_info_t *const stream_list[] = {
67 &stream_info_mpv,
66#if HAVE_CDDA68#if HAVE_CDDA
67 &stream_info_cdda,69 &stream_info_cdda,
68#endif70#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
23static 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
44const 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