Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect Directory Automatically ? #71

Closed
KAGEYAM4 opened this issue Oct 6, 2022 · 5 comments
Closed

Detect Directory Automatically ? #71

KAGEYAM4 opened this issue Oct 6, 2022 · 5 comments
Labels
enhancement New feature or request use-addons request should be completed with an addon

Comments

@KAGEYAM4
Copy link

KAGEYAM4 commented Oct 6, 2022

currently this has to be done root=~/,C:/,D:/,E:/ , is there a way to automatically detect directory, like if a plug in a usb drive or external HDD later , will i have to add that drive letter file_browser.conf ?

@CogentRedTester CogentRedTester added enhancement New feature or request use-addons request should be completed with an addon labels Oct 6, 2022
@CogentRedTester
Copy link
Owner

CogentRedTester commented Oct 6, 2022

Normally you would need to do it manually or use the mpv-user-input dialogue box to open the drive directly. But here is an addon I quickly wrote that will add drives to the root automatically:

--[[
    Automatically populates the root with windows drives on startup.
    Ctrl+r will add new drives mounted since startup.

    Drives will only be added if they are not already present in the root.
]]

local mp = require 'mp'
local msg = require 'mp.msg'
local fb = require 'file-browser'

local function get_drives()
    local result = mp.command_native({
        name = 'subprocess',
        playback_only = false,
        capture_stdout = true,
        args = {'wmic', 'logicaldisk', 'get', 'caption'}
    })
    if result.status ~= 0 then return msg.error('could not read windows root') end

    local root = {}
    for drive in result.stdout:gmatch("%a:") do
        table.insert(root, drive..'/')
    end
    return root
end

local function in_root(drive, root)
    for _, item in ipairs(root) do
        if item.name == drive then return true end
    end
    return false
end

local function import_drives()
    local drives = get_drives()
    local root = fb.get_root()

    for _, drive in ipairs(drives) do
        if not in_root(drive, root) then
            fb.insert_root_item({ name = drive })
        end
    end
end

local keybind = {
    key = 'Ctrl+r',
    name = 'import_root_drives',
    command = import_drives,
    parser = 'root',
    passthrough = true
}

return {
    version = '1.3.0', 
    setup = import_drives,
    keybinds = { keybind }
}

Edit: add API version for the addon

@KAGEYAM4
Copy link
Author

KAGEYAM4 commented Oct 6, 2022

Thank you, will you be adding this officially to as addons ?

@KAGEYAM4 KAGEYAM4 closed this as completed Oct 6, 2022
@CogentRedTester
Copy link
Owner

No guarantees, but this seems useful enough that there is a good chance I will tidy it up and add it, yes.

@dyphire
Copy link
Contributor

dyphire commented Oct 6, 2022

return {
    version = '1.3.0'
    setup = import_drives,
    keybinds = { keybind }
}

There is a small mistake. It should be:

return {
    version = '1.3.0',
    setup = import_drives,
    keybinds = { keybind }
}

@CogentRedTester
Copy link
Owner

return {
    version = '1.3.0'
    setup = import_drives,
    keybinds = { keybind }
}

There is a small mistake. It should be:

return {
    version = '1.3.0',
    setup = import_drives,
    keybinds = { keybind }
}

Fixed, thanks.

CogentRedTester added a commit that referenced this issue Oct 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request use-addons request should be completed with an addon
Projects
None yet
Development

No branches or pull requests

3 participants