Repository: rossy/mpv-install Branch: master Commit: e495c73f0df4 Files: 5 Total size: 22.3 KB Directory structure: gitextract_9t9_5sjm/ ├── .gitattributes ├── COPYING ├── README.md ├── mpv-install.bat └── mpv-uninstall.bat ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitattributes ================================================ /.gitattributes export-ignore *.bat text eol=crlf *.ico -text ================================================ FILE: COPYING ================================================ Copyright © 2015, James Ross-Gowan Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ================================================ FILE: README.md ================================================ ``mpv-install.bat`` =================== This script sets up file associations for [mpv][1] on Windows. How to install -------------- 1. Make sure you have the latest build of mpv. Official builds are here: https://mpv.srsfckn.biz/ 2. Download the zip: https://github.com/rossy/mpv-install/archive/master.zip
**Note:** Make sure you use the above link. Don't use GitHub's "Raw" links on the files themselves, since these have incorrect line-endings, which cause the script to crash. (See [#7][2].) 3. Copy the .bat files and the .ico to the same directory as mpv.exe 4. Run ``mpv-install.bat`` as administrator. **Note:** For an unattended install, use the ``/u`` switch. 5. Use the _Default Programs_ and _AutoPlay_ control panels to make mpv the default player What it does ------------ - Creates file associations for several video and audio file types - Registers mpv with the _Default Programs_ control panel - Puts mpv in the "Open with" menu for all video and audio files - Registers mpv.exe so it can be used from the Run dialog and the Start Menu - Adds mpv as an AutoPlay handler for Blu-rays and DVDs - Works when reinstalled to a different folder than the one it was in previously. (File associations created by the "Open with" menu have trouble with this.) What it doesn't do ------------------ - Add mpv to the ``%PATH%`` - Enable thumbnails for all media types (use [Icaros][3] for this) - Allow multiple files to be selected and opened as a playlist. This is harder than it sounds and it can't be done with a simple script. As a workaround, you can create a shortcut to mpv.exe in the "Send to" menu. How to uninstall ---------------- To remove all traces of this script from your computer, run ``mpv-uninstall.bat`` as administrator. **Note:** This is not necessary if you want to reinstall mpv later (in a different folder, for example,) only if you want to remove it completely. To reinstall, just run ``mpv-install.bat`` again. Disclaimer ---------- Should work on Windows Vista and up, tested with Windows Vista, 7, 8.1 and 10. These scripts were written for personal use and released with the hope that they would be useful, but without any warranty. [1]: https://mpv.io/ [2]: https://github.com/rossy/mpv-install/issues/7 [3]: http://www.majorgeeks.com/files/details/icaros.html ================================================ FILE: mpv-install.bat ================================================ @echo off setlocal enableextensions enabledelayedexpansion path %SystemRoot%\System32;%SystemRoot%;%SystemRoot%\System32\Wbem :: Unattended install flag. When set, the script will not require user input. set unattended=no if "%1"=="/u" set unattended=yes :: Make sure this is Windows Vista or later call :ensure_vista :: Make sure the script is running as admin call :ensure_admin :: Command line arguments to use when launching mpv from a file association set mpv_args= :: Get mpv.exe location set mpv_path=%~dp0mpv.exe if not exist "%mpv_path%" call :die "mpv.exe not found" :: Get mpv-document.ico location set icon_path=%~dp0mpv-document.ico if not exist "%icon_path%" call :die "mpv-document.ico not found" :: Register mpv.exe under the "App Paths" key, so it can be found by :: ShellExecute, the run command, the start menu, etc. set app_paths_key=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\mpv.exe call :reg add "%app_paths_key%" /d "%mpv_path%" /f call :reg add "%app_paths_key%" /v "UseUrl" /t REG_DWORD /d 1 /f :: Register mpv.exe under the "Applications" key to add some default verbs for :: when mpv is used from the "Open with" menu set classes_root_key=HKLM\SOFTWARE\Classes set app_key=%classes_root_key%\Applications\mpv.exe call :reg add "%app_key%" /v "FriendlyAppName" /d "mpv" /f call :add_verbs "%app_key%" :: Add mpv to the "Open with" list for all video and audio file types call :reg add "%classes_root_key%\SystemFileAssociations\video\OpenWithList\mpv.exe" /d "" /f call :reg add "%classes_root_key%\SystemFileAssociations\audio\OpenWithList\mpv.exe" /d "" /f :: Add DVD AutoPlay handler set autoplay_key=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\AutoplayHandlers call :reg add "%classes_root_key%\io.mpv.dvd\shell\play" /d "&Play" /f call :reg add "%classes_root_key%\io.mpv.dvd\shell\play\command" /d "\"%mpv_path%\" %mpv_args% dvd:// --dvd-device=\"%%%%L" /f call :reg add "%autoplay_key%\Handlers\MpvPlayDVDMovieOnArrival" /v "Action" /d "Play DVD movie" /f call :reg add "%autoplay_key%\Handlers\MpvPlayDVDMovieOnArrival" /v "DefaultIcon" /d "%mpv_path%,0" /f call :reg add "%autoplay_key%\Handlers\MpvPlayDVDMovieOnArrival" /v "InvokeProgID" /d "io.mpv.dvd" /f call :reg add "%autoplay_key%\Handlers\MpvPlayDVDMovieOnArrival" /v "InvokeVerb" /d "play" /f call :reg add "%autoplay_key%\Handlers\MpvPlayDVDMovieOnArrival" /v "Provider" /d "mpv" /f call :reg add "%autoplay_key%\EventHandlers\PlayDVDMovieOnArrival" /v "MpvPlayDVDMovieOnArrival" /f :: Add Blu-ray AutoPlay handler call :reg add "%classes_root_key%\io.mpv.bluray\shell\play" /d "&Play" /f call :reg add "%classes_root_key%\io.mpv.bluray\shell\play\command" /d "\"%mpv_path%\" %mpv_args% bd:// --bluray-device=\"%%%%L" /f call :reg add "%autoplay_key%\Handlers\MpvPlayBluRayOnArrival" /v "Action" /d "Play Blu-ray movie" /f call :reg add "%autoplay_key%\Handlers\MpvPlayBluRayOnArrival" /v "DefaultIcon" /d "%mpv_path%,0" /f call :reg add "%autoplay_key%\Handlers\MpvPlayBluRayOnArrival" /v "InvokeProgID" /d "io.mpv.bluray" /f call :reg add "%autoplay_key%\Handlers\MpvPlayBluRayOnArrival" /v "InvokeVerb" /d "play" /f call :reg add "%autoplay_key%\Handlers\MpvPlayBluRayOnArrival" /v "Provider" /d "mpv" /f call :reg add "%autoplay_key%\EventHandlers\PlayBluRayOnArrival" /v "MpvPlayBluRayOnArrival" /f :: Add a capabilities key for mpv, which is registered later on for use in the :: "Default Programs" control panel set capabilities_key=HKLM\SOFTWARE\Clients\Media\mpv\Capabilities call :reg add "%capabilities_key%" /v "ApplicationName" /d "mpv" /f call :reg add "%capabilities_key%" /v "ApplicationDescription" /d "mpv media player" /f :: Add file types set supported_types_key=%app_key%\SupportedTypes set file_associations_key=%capabilities_key%\FileAssociations :: DVD/Blu-ray audio formats call :add_type "audio/ac3" "audio" "AC-3 Audio" ".ac3" ".a52" call :add_type "audio/eac3" "audio" "E-AC-3 Audio" ".eac3" call :add_type "audio/vnd.dolby.mlp" "audio" "MLP Audio" ".mlp" call :add_type "audio/vnd.dts" "audio" "DTS Audio" ".dts" call :add_type "audio/vnd.dts.hd" "audio" "DTS-HD Audio" ".dts-hd" ".dtshd" call :add_type "" "audio" "TrueHD Audio" ".true-hd" ".thd" ".truehd" ".thd+ac3" call :add_type "" "audio" "True Audio" ".tta" :: Uncompressed formats call :add_type "" "audio" "PCM Audio" ".pcm" call :add_type "audio/wav" "audio" "Wave Audio" ".wav" call :add_type "audio/aiff" "audio" "AIFF Audio" ".aiff" ".aif" ".aifc" call :add_type "audio/amr" "audio" "AMR Audio" ".amr" call :add_type "audio/amr-wb" "audio" "AMR-WB Audio" ".awb" call :add_type "audio/basic" "audio" "AU Audio" ".au" ".snd" call :add_type "" "audio" "Linear PCM Audio" ".lpcm" call :add_type "" "video" "Raw YUV Video" ".yuv" call :add_type "" "video" "YUV4MPEG2 Video" ".y4m" :: Free lossless formats call :add_type "audio/x-ape" "audio" "Monkey's Audio" ".ape" call :add_type "audio/x-wavpack" "audio" "WavPack Audio" ".wv" call :add_type "audio/x-shorten" "audio" "Shorten Audio" ".shn" :: MPEG formats call :add_type "video/vnd.dlna.mpeg-tts" "video" "MPEG-2 Transport Stream" ".m2ts" ".m2t" ".mts" ".mtv" ".ts" ".tsv" ".tsa" ".tts" ".trp" call :add_type "audio/vnd.dlna.adts" "audio" "ADTS Audio" ".adts" ".adt" call :add_type "audio/mpeg" "audio" "MPEG Audio" ".mpa" ".m1a" ".m2a" ".mp1" ".mp2" call :add_type "audio/mpeg" "audio" "MP3 Audio" ".mp3" call :add_type "video/mpeg" "video" "MPEG Video" ".mpeg" ".mpg" ".mpe" ".mpeg2" ".m1v" ".m2v" ".mp2v" ".mpv" ".mpv2" ".mod" ".tod" call :add_type "video/dvd" "video" "Video Object" ".vob" ".vro" call :add_type "" "video" "Enhanced VOB" ".evob" ".evo" call :add_type "video/mp4" "video" "MPEG-4 Video" ".mpeg4" ".m4v" ".mp4" ".mp4v" ".mpg4" call :add_type "audio/mp4" "audio" "MPEG-4 Audio" ".m4a" call :add_type "audio/aac" "audio" "Raw AAC Audio" ".aac" call :add_type "" "video" "Raw H.264/AVC Video" ".h264" ".avc" ".x264" ".264" call :add_type "" "video" "Raw H.265/HEVC Video" ".hevc" ".h265" ".x265" ".265" :: Xiph formats call :add_type "audio/flac" "audio" "FLAC Audio" ".flac" call :add_type "audio/ogg" "audio" "Ogg Audio" ".oga" ".ogg" call :add_type "audio/ogg" "audio" "Opus Audio" ".opus" call :add_type "audio/ogg" "audio" "Speex Audio" ".spx" call :add_type "video/ogg" "video" "Ogg Video" ".ogv" ".ogm" call :add_type "application/ogg" "video" "Ogg Video" ".ogx" :: Matroska formats call :add_type "video/x-matroska" "video" "Matroska Video" ".mkv" call :add_type "video/x-matroska" "video" "Matroska 3D Video" ".mk3d" call :add_type "audio/x-matroska" "audio" "Matroska Audio" ".mka" call :add_type "video/webm" "video" "WebM Video" ".webm" call :add_type "audio/webm" "audio" "WebM Audio" ".weba" :: Misc formats call :add_type "video/avi" "video" "Video Clip" ".avi" ".vfw" call :add_type "" "video" "DivX Video" ".divx" call :add_type "" "video" "3ivx Video" ".3iv" call :add_type "" "video" "XVID Video" ".xvid" call :add_type "" "video" "NUT Video" ".nut" call :add_type "video/flc" "video" "FLIC Video" ".flic" ".fli" ".flc" call :add_type "" "video" "Nullsoft Streaming Video" ".nsv" call :add_type "application/gxf" "video" "General Exchange Format" ".gxf" call :add_type "application/mxf" "video" "Material Exchange Format" ".mxf" :: Windows Media formats call :add_type "audio/x-ms-wma" "audio" "Windows Media Audio" ".wma" call :add_type "video/x-ms-wm" "video" "Windows Media Video" ".wm" call :add_type "video/x-ms-wmv" "video" "Windows Media Video" ".wmv" call :add_type "video/x-ms-asf" "video" "Windows Media Video" ".asf" call :add_type "" "video" "Microsoft Recorded TV Show" ".dvr-ms" ".dvr" call :add_type "" "video" "Windows Recorded TV Show" ".wtv" :: DV formats call :add_type "" "video" "DV Video" ".dv" ".hdv" :: Flash Video formats call :add_type "video/x-flv" "video" "Flash Video" ".flv" call :add_type "video/mp4" "video" "Flash Video" ".f4v" call :add_type "audio/mp4" "audio" "Flash Audio" ".f4a" :: QuickTime formats call :add_type "video/quicktime" "video" "QuickTime Video" ".qt" ".mov" call :add_type "video/quicktime" "video" "QuickTime HD Video" ".hdmov" :: Real Media formats call :add_type "application/vnd.rn-realmedia" "video" "Real Media Video" ".rm" call :add_type "application/vnd.rn-realmedia-vbr" "video" "Real Media Video" ".rmvb" call :add_type "audio/vnd.rn-realaudio" "audio" "Real Media Audio" ".ra" ".ram" :: 3GPP formats call :add_type "audio/3gpp" "audio" "3GPP Audio" ".3ga" call :add_type "audio/3gpp2" "audio" "3GPP Audio" ".3ga2" call :add_type "video/3gpp" "video" "3GPP Video" ".3gpp" ".3gp" call :add_type "video/3gpp2" "video" "3GPP Video" ".3gp2" ".3g2" :: Video game formats call :add_type "" "audio" "AY Audio" ".ay" call :add_type "" "audio" "GBS Audio" ".gbs" call :add_type "" "audio" "GYM Audio" ".gym" call :add_type "" "audio" "HES Audio" ".hes" call :add_type "" "audio" "KSS Audio" ".kss" call :add_type "" "audio" "NSF Audio" ".nsf" call :add_type "" "audio" "NSFE Audio" ".nsfe" call :add_type "" "audio" "SAP Audio" ".sap" call :add_type "" "audio" "SPC Audio" ".spc" call :add_type "" "audio" "VGM Audio" ".vgm" call :add_type "" "audio" "VGZ Audio" ".vgz" :: Playlist formats call :add_type "audio/x-mpegurl" "audio" "M3U Playlist" ".m3u" ".m3u8" call :add_type "audio/x-scpls" "audio" "PLS Playlist" ".pls" call :add_type "" "audio" "CUE Sheet" ".cue" :: Register "Default Programs" entry call :reg add "HKLM\SOFTWARE\RegisteredApplications" /v "mpv" /d "SOFTWARE\Clients\Media\mpv\Capabilities" /f echo. echo Installed successfully^^! You can now configure mpv's file associations in the echo Default Programs control panel. echo. if [%unattended%] == [yes] exit 0 nul control /name Microsoft.DefaultPrograms exit 0 :die if not [%1] == [] echo %~1 if [%unattended%] == [yes] exit 1 pause exit 1 :ensure_admin :: 'openfiles' is just a commmand that is present on all supported Windows :: versions, requires admin privileges and has no side effects, see: :: https://stackoverflow.com/questions/4051883/batch-script-how-to-check-for-admin-rights openfiles >nul 2>&1 if errorlevel 1 ( echo This batch script requires administrator privileges. Right-click on echo mpv-install.bat and select "Run as administrator". call :die ) goto :EOF :ensure_vista ver | find "XP" >nul if not errorlevel 1 ( echo This batch script only works on Windows Vista and later. To create file echo associations on Windows XP, right click on a video file and use "Open with...". call :die ) goto :EOF :reg :: Wrap the reg command to check for errors >nul reg %* if errorlevel 1 set error=yes if [%error%] == [yes] echo Error in command: reg %* if [%error%] == [yes] call :die goto :EOF :reg_set_opt :: Set a value in the registry if it doesn't already exist set key=%~1 set value=%~2 set data=%~3 reg query "%key%" /v "%value%" >nul 2>&1 if errorlevel 1 call :reg add "%key%" /v "%value%" /d "%data%" goto :EOF :add_verbs set key=%~1 :: Set the default verb to "play" call :reg add "%key%\shell" /d "play" /f :: Hide the "open" verb from the context menu, since it's the same as "play" call :reg add "%key%\shell\open" /v "LegacyDisable" /f :: Set open command call :reg add "%key%\shell\open\command" /d "\"%mpv_path%\" %mpv_args% -- \"%%%%L" /f :: Add "play" verb call :reg add "%key%\shell\play" /d "&Play" /f call :reg add "%key%\shell\play\command" /d "\"%mpv_path%\" %mpv_args% -- \"%%%%L" /f goto :EOF :add_progid set prog_id=%~1 set friendly_name=%~2 :: Add ProgId, edit flags are FTA_OpenIsSafe | FTA_AlwaysUseDirectInvoke set prog_id_key=%classes_root_key%\%prog_id% call :reg add "%prog_id_key%" /d "%friendly_name%" /f call :reg add "%prog_id_key%" /v "EditFlags" /t REG_DWORD /d 4259840 /f call :reg add "%prog_id_key%" /v "FriendlyTypeName" /d "%friendly_name%" /f call :reg add "%prog_id_key%\DefaultIcon" /d "%icon_path%" /f call :add_verbs "%prog_id_key%" goto :EOF :update_extension set extension=%~1 set prog_id=%~2 set mime_type=%~3 set perceived_type=%~4 :: Add information about the file extension, if not already present set extension_key=%classes_root_key%\%extension% if not [%mime_type%] == [] call :reg_set_opt "%extension_key%" "Content Type" "%mime_type%" if not [%perceived_type%] == [] call :reg_set_opt "%extension_key%" "PerceivedType" "%perceived_type%" call :reg add "%extension_key%\OpenWithProgIds" /v "%prog_id%" /f :: Add type to SupportedTypes call :reg add "%supported_types_key%" /v "%extension%" /f :: Add type to the Default Programs control panel call :reg add "%file_associations_key%" /v "%extension%" /d "%prog_id%" /f goto :EOF :add_type set mime_type=%~1 set perceived_type=%~2 set friendly_name=%~3 set extension=%~4 echo Adding "%extension%" file type :: Add ProgId set prog_id=io.mpv%extension% call :add_progid "%prog_id%" "%friendly_name%" :: Add extensions :extension_loop call :update_extension "%extension%" "%prog_id%" "%mime_type%" "%perceived_type%" :: Trailing parameters are additional extensions shift /4 set extension=%~4 if not [%extension%] == [] goto extension_loop goto :EOF ================================================ FILE: mpv-uninstall.bat ================================================ @echo off setlocal enableextensions enabledelayedexpansion path %SystemRoot%\System32;%SystemRoot%;%SystemRoot%\System32\Wbem :: Unattended install flag. When set, the script will not require user input. set unattended=no if "%1"=="/u" set unattended=yes :: Make sure the script is running as admin call :ensure_admin :: Delete "App Paths" entry reg delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\mpv.exe" /f >nul :: Delete HKCR subkeys set classes_root_key=HKLM\SOFTWARE\Classes reg delete "%classes_root_key%\Applications\mpv.exe" /f >nul reg delete "%classes_root_key%\SystemFileAssociations\video\OpenWithList\mpv.exe" /f >nul reg delete "%classes_root_key%\SystemFileAssociations\audio\OpenWithList\mpv.exe" /f >nul :: Delete AutoPlay handlers set autoplay_key=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\AutoplayHandlers reg delete "%autoplay_key%\Handlers\MpvPlayDVDMovieOnArrival" /f >nul reg delete "%autoplay_key%\EventHandlers\PlayDVDMovieOnArrival" /v "MpvPlayDVDMovieOnArrival" /f >nul reg delete "%autoplay_key%\Handlers\MpvPlayBluRayOnArrival" /f >nul reg delete "%autoplay_key%\EventHandlers\PlayBluRayOnArrival" /v "MpvPlayBluRayOnArrival" /f >nul :: Delete "Default Programs" entry reg delete "HKLM\SOFTWARE\RegisteredApplications" /v "mpv" /f >nul reg delete "HKLM\SOFTWARE\Clients\Media\mpv\Capabilities" /f >nul :: Delete all OpenWithProgIds referencing ProgIds that start with io.mpv. for /f "usebackq eol= delims=" %%k in (`reg query "%classes_root_key%" /f "io.mpv.*" /s /v /c`) do ( set "key=%%k" echo !key!| findstr /r /i "^HKEY_LOCAL_MACHINE\\SOFTWARE\\Classes\\\.[^\\][^\\]*\\OpenWithProgIds$" >nul if not errorlevel 1 ( for /f "usebackq eol= tokens=1" %%v in (`reg query "!key!" /f "io.mpv.*" /v /c`) do ( set "value=%%v" echo !value!| findstr /r /i "^io\.mpv\.[^\\][^\\]*$" >nul if not errorlevel 1 ( echo Deleting !key!\!value! reg delete "!key!" /v "!value!" /f >nul ) ) ) ) :: Delete all ProgIds starting with io.mpv. for /f "usebackq eol= delims=" %%k in (`reg query "%classes_root_key%" /f "io.mpv.*" /k /c`) do ( set "key=%%k" echo !key!| findstr /r /i "^HKEY_LOCAL_MACHINE\\SOFTWARE\\Classes\\io\.mpv\.[^\\][^\\]*$" >nul if not errorlevel 1 ( echo Deleting !key! reg delete "!key!" /f >nul ) ) echo Uninstalled successfully if [%unattended%] == [yes] exit 0 pause exit 0 :die if not [%1] == [] echo %~1 if [%unattended%] == [yes] exit 1 pause exit 1 :ensure_admin :: 'openfiles' is just a commmand that is present on all supported Windows :: versions, requires admin privileges and has no side effects, see: :: https://stackoverflow.com/questions/4051883/batch-script-how-to-check-for-admin-rights openfiles >nul 2>&1 if errorlevel 1 ( echo This batch script requires administrator privileges. Right-click on echo mpv-uninstall.bat and select "Run as administrator". call :die ) goto :EOF