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.
Unified · Split
| @@ -0,0 +1 @@ | |||
| 1 | add `mpv://` protocol | ||
| @@ -1280,6 +1280,12 @@ More options to configure this functionality are listed in `Watch Later`_. · 1279 unmodified lines | |||
| 1280 | PROTOCOLS | 1280 | PROTOCOLS |
| 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 always | 1291 | Many network protocols are supported, but the protocol prefix must always |
| @@ -50,8 +50,9 @@ · 49 unmodified lines | |||
| 50 | #include "cue.h" | 50 | #include "cue.h" |
| 51 | 51 | ||
| 52 | // Demuxer list | 52 | // Demuxer list |
| 53 | extern const struct demuxer_desc demuxer_desc_edl; | 53 | extern const demuxer_desc_t demuxer_desc_mpv; |
| 54 | extern const struct demuxer_desc demuxer_desc_cue; | 54 | extern const demuxer_desc_t demuxer_desc_edl; |
| 55 | extern const demuxer_desc_t demuxer_desc_cue; | ||
| 55 | extern const demuxer_desc_t demuxer_desc_rawaudio; | 56 | extern const demuxer_desc_t demuxer_desc_rawaudio; |
| 56 | extern const demuxer_desc_t demuxer_desc_rawvideo; | 57 | extern const demuxer_desc_t demuxer_desc_rawvideo; |
| 57 | extern const demuxer_desc_t demuxer_desc_mf; | 58 | extern 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 | NULL | 85 | NULL |
| 84 | }; | 86 | }; |
| 85 | 87 | ||
| @@ -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 | }; | ||
| @@ -45,7 +45,7 @@ Exec=mpv --player-operation-mode=pseudo-gui -- %U · 44 unmodified lines | |||
| 45 | Terminal=false | 45 | Terminal=false |
| 46 | Categories=AudioVideo;Audio;Video;Player;TV; | 46 | Categories=AudioVideo;Audio;Video;Player;TV; |
| 47 | 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; | 47 | 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 |
| 49 | StartupWMClass=mpv | 49 | StartupWMClass=mpv |
| 50 | Keywords=mpv;media;player;video;audio;tv; | 50 | Keywords=mpv;media;player;video;audio;tv; |
| 51 | Keywords[ar]=mpv;إم بي في;ام بي في;وسائط;مشغل;فيديو;مرئية;صوتي;تلفاز; | 51 | Keywords[ar]=mpv;إم بي في;ام بي في;وسائط;مشغل;فيديو;مرئية;صوتي;تلفاز; |
| @@ -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 | ||
| @@ -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 | ||
| 45 | extern const stream_info_t stream_info_mpv; | ||
| 45 | extern const stream_info_t stream_info_cdda; | 46 | extern const stream_info_t stream_info_cdda; |
| 46 | extern const stream_info_t stream_info_dvb; | 47 | extern const stream_info_t stream_info_dvb; |
| 47 | extern const stream_info_t stream_info_null; | 48 | extern const stream_info_t stream_info_null; |
| @@ -63,6 +64,7 @@ extern const stream_info_t stream_info_libarchive; · 15 unmodified lines | |||
| 63 | extern const stream_info_t stream_info_cb; | 64 | extern const stream_info_t stream_info_cb; |
| 64 | 65 | ||
| 65 | static const stream_info_t *const stream_list[] = { | 66 | static const stream_info_t *const stream_list[] = { |
| 67 | &stream_info_mpv, | ||
| 66 | #if HAVE_CDDA | 68 | #if HAVE_CDDA |
| 67 | &stream_info_cdda, | 69 | &stream_info_cdda, |
| 68 | #endif | 70 | #endif |
| @@ -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 | }; | ||