VLC:如何删除磁盘上的文件

VLC:如何删除磁盘上的文件

我从 Youtube 下载视频以便稍后观看。我使用 VLC 观看视频,看完视频后,我想直接从 VLC 中删除磁盘上的文件。

我找到了几个关于如何实现这一点的指南,但没有一个适合我:

https://forum.videolan.org/viewtopic.php?f=29&t=108811 https://forum.videolan.org/viewtopic.php?f=29&t=113813 http://addons.videolan.org/CONTENT/content-files/153041-Diskdelete.lua

如果我按照这些操作,什么也不会发生:没有按钮,而且如果有键盘快捷键,我也没有被告知。

那么如何在 VLC 中获取按钮/键盘快捷键来从磁盘中删除当前正在播放的视频文件?

我在 GNU/Linux Mint 上使用 VLC 2.0.8。

答案1

因此将文件放入 ~/.local/share/vlc/lua/extensions。我将其命名为 DeleteFile.lua。

启动 VLC 时,您会看到一个新菜单项:查看 > 检测文件。这是我遗漏的最后一步。

编辑 20200306

代码运行得不太好。我修改了它:

https://gitlab.com/ole.tange/tangetools/-/blob/master/wastebasket/dotlocal/share/vlc/lua/extensions/WasteBasket.lua

.waste它现在在文件目录和任何(祖父*)父目录中搜索名为 的目录,并将文件移动到那里。因此,您需要创建一个名为 的目录.waste

当您启动 VLC 时,您会看到一个新菜单项:查看 > 将当前播放的文件移至废纸篓。

答案2

https://gist.github.com/PAEz/d3a9be2471dbd39084136d974cdb9dd3

--[[
    Copyright 2015-2016 surrim
    https://gist.github.com/PAEz/d3a9be2471dbd39084136d974cdb9dd3
    https://forum.videolan.org/viewtopic.php?f=29&t=108811
    https://superuser.com/questions/721112/vlc-how-to-delete-file-on-disk#
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
]]--

function descriptor()
    return {
        title = "VLC Delete";
        version = "0.1";
        author = "surrim";
        url = "https://github.com/surrim/vlc-delete/";
        shortdesc = "Remove current file from playlist and disk";
        description = [[
<h1>vlc-delete</h1>"
When you're playing a file, use VLC Delete to
delete the current file from your playlist and <b>disk</b> with one click.<br>
This extension has been tested on GNU Linux with VLC 2.1.5.<br>
The author is not responsible for damage caused by this extension.
        ]];
   }
end


-- Windows - Check if file exists
function fileExists(file)
    return io.popen("if exist "..file.." (echo 1)"):read'*l'=='1'
end


function sleep(n)  -- seconds
  local t0 = os.clock()
  local tOriginal=t0
  while os.clock() - t0 <= n and os.clock()>=tOriginal do end
end


-- Windows - try and delete a file with multiple attempts and a pause between each try - waiting for the file to unlock
function windowsDelete(file,trys,pause)
    if not fileExists('"'..file..'"') then return nil,'File does not exist' end
    for i = trys,1,-1
    do
        retval, err = os.remove(file)
        --retval, err = os.execute('del ' .. file )
        if retval==true then
            return true
        end
        sleep(pause) -- wish i had a better timer than one second, want misc.mdate..could just bash it but you shouldnt ever wait more than one second so meh
    end
    return {nil,'Unable to delete file'}
end

function removeItem()
    local id = vlc.playlist.current()
    vlc.playlist.delete(id)
    vlc.playlist.gotoitem(id + 1)
    vlc.deactivate()
end

function activate()
    local item = vlc.input.item()
    local uri = item:uri()
    uri = string.gsub(uri, '^file:///', '')
    uri = vlc.strings.decode_uri(uri)
    vlc.msg.info("[vlc-delete] removing: " .. uri)
    -- check for non windows
    if (package.config:sub(1,1) == "/") then
        retval, err = os.execute("trash-put --help > /dev/null")
        if (retval ~= nil) then
            uri = "/" .. uri
            retval, err = os.execute("trash-put \"" .. uri .. "\"")
        else
            retval, err = os.execute("rm --help > /dev/null")
            if (retval ~= nil) then
                uri = "/" .. uri
                retval, err = os.execute("rm \"" .. uri .. "\"")
            end
        end
        if (retval ~= nil) then removeItem() end
    else
        --windows, remove from playlist first so the file isnt locked by vlc
        removeItem()
        uri = string.gsub(uri, "/", "\\")
        retval, err = windowsDelete(uri,3,1)
    end

    if (retval == nil) then
        vlc.msg.info("[vlc-delete] error: " .. err)
        d = vlc.dialog("VLC Delete")
        d:add_label("Could not remove \"" .. uri .. "\"", 1, 1, 1, 1)
        d:add_label(err, 1, 2, 1, 1)
        d:add_button("OK", click_ok, 1, 3, 1, 1)
        d:show()
    end
end

function click_ok()
    d:delete()
    vlc.deactivate()
end

function deactivate()
    vlc.deactivate()
end

function close()
    deactivate()
end

function meta_changed()
end

https://gitlab.com/ole.tange/tangetools/-/blob/master/wastebasket/dotlocal/share/vlc/lua/extensions/WasteBasket.lua

--[[
https://gitlab.com/ole.tange/tangetools/-/blob/master/wastebasket/dotlocal/share/vlc/lua/extensions/WasteBasket.lua
https://forum.videolan.org/viewtopic.php?f=29&t=108811
https://superuser.com/questions/721112/vlc-how-to-delete-file-on-disk#
INSTALLATION (create directories if they donot exist):
- put the file in the VLC subdir /lua/extensions, by default:
* Windows (all users): %ProgramFiles%\VideoLAN\VLC\lua\extensions\
* Windows (current user): %APPDATA%\VLC\lua\extensions\
* Linux (all users): /usr/share/vlc/lua/extensions/
* Linux (current user): ~/.local/share/vlc/lua/extensions/
* Mac OS X (all users): /Applications/VLC.app/Contents/MacOS/share/lua/extensions/
- Restart VLC.
- The extension can then be found in the menu:
    View > Move current playing file into wastebasket
]]--

--[[ Extension description ]]

function descriptor()
  return { title = "Wastebasket" ;
    version = "0.9" ;
    author = "Mark Morschhäuser/Ole Tange" ;
    shortdesc = "Move current playing file into wastebasket";
    description = "<h1>Wastebasket</h1>"
    .. "When you're playing a file, use Wastebasket to "
    .. "easily move this file to a .waste-dir with one click. "
    .. "<br>This will NOT change your playlist, it will move the file itself. "
    .. "<br>Wastebasket will search for a dir called .waste "
    .. "in the dir of the file and all parent dirs of that.";
    url = "https://gitlab.com/ole.tange/tangetools/tree/master/wastebasket"
  }
end

--[[ Hooks ]]

-- Activation hook
function activate()
  local filename,dst,wdir = filename_dst_wastedir()
  if(directory_exists(wdir)) then
    d = vlc.dialog("Wastebasket")
    d:add_label("Move <b>".. filename .. "</b> to <b>" .. wdir .. "</b>?")
    d:add_button("Move", delete)
    d:add_button("Cancel", close)
    d:show()
  else
    d = vlc.dialog("Wastebasket - no dir found")
    d:add_label(".waste is not found anywhere in parent dirs")
    d:add_button("Cancel", close)
    d:show()
  end
  vlc.msg.dbg("[Wastebasket] Activated")
end

function filename_dst_wastedir()
  -- get the current playing file
  local item = vlc.input.item()
  -- extract its URI
  local uri = item:uri()
  -- decode %foo stuff from the URI
  local filename = vlc.strings.decode_uri(uri)
  -- remove 'file://' prefix which is 7 chars long
  filename = string.sub(filename,8)

  -- find .waste in parent dirs
  local wdir = wastedir(dirname(filename))
  return filename,wdir .. "/" .. basename(filename),wdir
end

function wastedir(dir)
  -- recursively search for .waste in parent dir

  vlc.msg.dbg("[Wastebasket/wastedir] Looking at " .. dir)
  local wdir = dir .. "/" .. ".waste"
  if directory_exists(wdir) then
     vlc.msg.dbg("[Wastebasket/wastedir] Found wastedir: " .. wdir)
     return wdir
  end
  -- try the parent dir
  local parent = dirname(dir)
  if(parent == dir) then
    -- we have reached root (/)
    -- return wdir (which does not exist)
    return wdir
  end
  vlc.msg.dbg("[Wastebasket/wastedir] parent " .. parent)
  if directory_exists(parent) then
    return wastedir(parent)
  else
    return parent
  end
end

function directory_exists(dir)
  -- Simple checker if dir exists
  -- shell quote the dirname
  dir, _ = dir:gsub("([\002-\009\011-\026\\#?`(){}%[%]^*<>=~|; \"!$&'\130-\255])", "\\%1")
  dir, _ = dir:gsub("\n", "'\n'")
  return os.execute("cd " .. dir)
end

function deactivate()
  -- Deactivation hook
  vlc.msg.dbg("[Wastebasket] Deactivated")
  vlc.deactivate()
end

function close()
  deactivate()
end

--- Function equivalent to basename in POSIX systems
--@param str the path string
function basename(str)
  local name = string.gsub(str, "(.*/)(.*)", "%2")
  return name
end

function dirname(str)
  local name = string.gsub(str, "(.*)/(.*)", "%1")
  return name
end

function delete()
  local filename,dst,wdir = filename_dst_wastedir()
  if(directory_exists(wdir)) then
    vlc.msg.dbg("[Wastebasket]: Move to " .. dst)
    local retval, err = os.rename(filename,dst)
    if(retval == nil) then
      -- error handling; if moving failed, print why
      vlc.msg.dbg("[Wastebasket] error: " .. err)
    end
  else
    d = vlc.dialog("Wastebasket - no dir found")
    d:add_label(".waste is not found anywhere in parent dirs")
    d:add_button("Cancel", close)
    d:show()
  end
  close()
end

-- This empty function is there, because vlc pested me otherwise
function meta_changed()
end

答案3

这些都不适合我所以我修改为:https://gist.github.com/e-desouza/9c340a5373492befb1203428e458bbf5。请注意,这仅适用于 OSX,删除前没有任何警告等。要使其成为快捷方式:

OSX 系统偏好设置->键盘->应用程序快捷方式 > +(单击加号按钮并选择 VLC 应用程序)

菜单标题为“VLC Delete OSX”(减去引号)并使用所需的快捷方式。(在我的情况下,我选择 Ctrl+D)

相关内容