Skip to content

Commit 3507da0

Browse files
committed
add an option to run mpvacious from the project root
1 parent 7f8e093 commit 3507da0

File tree

5 files changed

+55
-8
lines changed

5 files changed

+55
-8
lines changed

README.md

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,23 +140,42 @@ it'll install there instead of `AppData`.
140140
Installing Mpvacious in development mode allows contributors to easily test their changes.
141141
With this setup, any changes made to the *.lua files will be applied immediately after restarting mpv.
142142

143+
#### First approach
144+
143145
Clone the repository, then create a symlink from the `mpvacious` directory to the mpv config directory.
144146

145147
Commands for GNU/Linux:
146148

147-
```
149+
```bash
148150
git clone 'https://github.com/Ajatt-Tools/mpvacious.git'
149151
mkdir -p ~/.config/mpv/scripts/
150152
cd mpvacious
151153
bash scripts/symlink.sh
152154
```
153155

154-
To update existing installation, use `git`.
156+
To update an existing installation, use `git` in the project folder.
155157

156-
```
158+
```bash
157159
git pull
158160
```
159161

162+
#### Second approach
163+
164+
Clone the repo directly into the `mpv/scripts` directory.
165+
166+
Commands for GNU/Linux:
167+
168+
```bash
169+
mkdir -p ~/.config/mpv/scripts/
170+
git clone 'https://github.com/Ajatt-Tools/mpvacious.git' ~/.config/mpv/scripts/mpvacious
171+
```
172+
173+
To update an existing installation, use `git`.
174+
175+
```
176+
cd ~/.config/mpv/scripts/mpvacious && git pull
177+
```
178+
160179
### Manually
161180

162181
This way is not recommended because it's easy to make a mistake during the process

main.lua

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
-- For compatibility, allow running mpvacious
2+
-- by placing the project folder in mpv's scripts directory (e.g. ~/.config/mpv/scripts).
3+
-- Recommended only for mpvacious contributors.
4+
5+
local mp = require('mp')
6+
local utils = require('mp.utils')
7+
local mpvacious_root = utils.join_path(mp.get_script_directory(), "mpvacious")
8+
9+
-- Add mpvacious subfolder to Lua search path
10+
package.path = string.format("%s/?.lua;%s", mpvacious_root, package.path)
11+
print("new package path", package.path)
12+
13+
-- Run the main script
14+
dofile(utils.join_path(mpvacious_root, "main.lua"))

mpvacious/config/utils.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ local function create_config_file(default_profile_name)
1515
local name = default_profile_name
1616
-- ~/.config/mpv/script-opts/subs2srs.conf
1717
local config_filepath = utils.join_path(h.find_mpv_script_opts_directory(), string.format('%s.conf', name))
18-
local example_config_filepath = utils.join_path(mp.get_script_directory(), "mpvacious/config/default_config.conf")
18+
local example_config_filepath = utils.join_path(h.find_mpvacious_dir(), "config/default_config.conf")
1919

2020
local file_info = utils.file_info(config_filepath)
2121
if file_info and file_info.is_file then

mpvacious/helpers.lua

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,20 @@ function this.str_limit(str, n_chars)
546546
return table.concat(ret)
547547
end
548548

549+
function this.find_mpvacious_dir()
550+
-- The fallback path will be valid if the project folder is placed
551+
-- in mpv's scripts directory (e.g. ~/.config/mpv/scripts).
552+
-- This does not apply to normal installations of mpvacious.
553+
-- https://github.com/mpv-player/mpv/blob/master/DOCS/man/lua.rst#mputils-functions
554+
local default_path = mp.get_script_directory()
555+
-- test if version file is present
556+
local info = utils.file_info(utils.join_path(default_path, "version.json"))
557+
if info and info.is_file then
558+
return default_path
559+
end
560+
return utils.join_path(mp.get_script_directory(), "mpvacious")
561+
end
562+
549563
--- Like pathlib.Path.read_text() but doesn't throw.
550564
--- Returns tuple[text, error].
551565
function this.read_text(file_path)

mpvacious/utils/release_checker.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ local function make_release_checker()
1414
local private = {}
1515
local public = {}
1616

17-
private.repo="Ajatt-Tools/mpvacious"
18-
private.max_time_sec=20
19-
private.check_delay_sec=5
17+
private.repo = "Ajatt-Tools/mpvacious"
18+
private.max_time_sec = 20
19+
private.check_delay_sec = 5
2020
private.api_check_url = "https://api.github.com/repos/" .. private.repo .. "/releases/latest"
2121
private.curl_args = { "-sL", "--max-time", tostring(private.max_time_sec), private.api_check_url }
2222
private.is_new_version_available = false
2323
private.latest_version = nil
2424
private.installed_version = nil
2525

2626
local function read_installed_version_file()
27-
local version_file_path = utils.join_path(mp.get_script_directory(), "version.json")
27+
local version_file_path = utils.join_path(h.find_mpvacious_dir(), "version.json")
2828
local version_text, error = h.read_text(version_file_path)
2929
if error then
3030
mp.msg.error(error)

0 commit comments

Comments
 (0)