User Tools

Site Tools


howto:vlc-playlist-from-file

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
howto:vlc-playlist-from-file [2022/01/01 16:35] Wulf Rajekhowto:vlc-playlist-from-file [2023/05/29 11:55] (current) – external edit 127.0.0.1
Line 1: Line 1:
 +====== VLC ======
 +
 +====== VLC no audio ======
 +
 +Change output module in Tools -> Preferences -> Audio from Auto to Pulseaudio or Alsa.
 +
 +alternative edit config file:
 +<code>
 +vi ~/.config/vlc/vlcrc
 +</code>
 +<code>
 +# Audio output module (string)
 +aout=pulse
 +</code>
 +
 +====== Associate VLC to webm videos ======
 +Gnome uses two lists to register applications to file types located in:
 +  * /usr/share/applications/mimeinfo.cache
 +  * /usr/share/applications/defaults.list
 +  * ~/.local/share/applications/mimeinfo.cache
 +<code>
 +#manually
 +sudo vi /usr/share/applications/mimeinfo.cache
 +sudo vi /usr/share/applications/defaults.list
 +vi ~/.local/share/applications/mimeinfo.cache
 +
 +#or via sed:
 +sudo sed -i 's#video/webm=#video/webm=vlc.desktop;#' /usr/share/applications/defaults.list
 +sudo sed -i 's#video/webm=#video/webm=vlc.desktop;#' /usr/share/applications/meminfo.cache
 +sudo sed -i 's#audio/webm=#audio/webm=vlc.desktop;#' /usr/share/applications/meminfo.cache
 +sed -i 's#video/webm=#video/webm=vlc.desktop;#' ~/.local/share/applications/meminfo.cache
 +sed -i 's#audio/webm=#audio/webm=vlc.desktop;#' ~/.local/share/applications/meminfo.cache
 +</code>
 +
 +
 ====== VLC Playlist from file ====== ====== VLC Playlist from file ======
  
Line 11: Line 46:
  
 You may want to activate the loop option in VLC preferences if VLC is configured to play the next track automatically. (Tools -> Preferences -> Show all settings -> Playlist -> Repeat current item) You may want to activate the loop option in VLC preferences if VLC is configured to play the next track automatically. (Tools -> Preferences -> Show all settings -> Playlist -> Repeat current item)
 +
 +or edit ~/.config/vlc/vlcrc:
 +<code>
 +vi ~/.config/vlc/vlcrc
 +</code>
 +<code>
 +# Repeat current item (boolean)
 +repeat=1
 +</code>
  
 ==== Linux ==== ==== Linux ====
 Copy vlc.sh in ~/.local/bin directory and mark it executable, then copy the desktop file of VLC /usr/share/applications/vlc.desktop to ~/.local/share/applications/vlc.desktop and change the field Exec to the path of vlc.sh (remove argument --started-from-file %U). Known extensions are stocked in variable $extensions. Copy vlc.sh in ~/.local/bin directory and mark it executable, then copy the desktop file of VLC /usr/share/applications/vlc.desktop to ~/.local/share/applications/vlc.desktop and change the field Exec to the path of vlc.sh (remove argument --started-from-file %U). Known extensions are stocked in variable $extensions.
 +<code>
 +sed -i 's#Exec=/usr/bin/vlc --started-from-file %U#Exec=/home/'$USER'/.local/bin/vlc.sh#' /usr/share/applications/vlc.desktop > ~/.local/share/applications/vlc.desktop
 +</code>
  
- +note: source from github adjusted to sort numbers as Versions like nemo file manager does. 
-<code ~/.local/bin/vlc.sh>+<code bash ~/.local/bin/vlc.sh>
 #!/bin/bash #!/bin/bash
  
 +shopt -s nocaseglob
 shopt -s extglob shopt -s extglob
-extensions='@(avi|mp4|mkv|m4v|mov|mpg|mpeg|wmv|ogg|flac|m4a|mp3|wav)'  # list of extensions for searching in current directory+extensions='@(avi|mp4|mkv|m4v|mov|mpg|mpeg|wmv|ogg|flac|m4a|mp3|wav|webm|rmvb|asf|flv)'  # list of extensions for searching in current directory
  
 # kill other instances of vlc to keep playlist clean (one-instance mode) # kill other instances of vlc to keep playlist clean (one-instance mode)
Line 27: Line 75:
 # launch empty vlc if no argument provided # launch empty vlc if no argument provided
 if [ -z "$1" ]; then if [ -z "$1" ]; then
- vlc; exit+    vlc; exit
 fi fi
  
Line 36: Line 84:
  
 # count files with matching extension, and get position of filename in current directory # count files with matching extension, and get position of filename in current directory
-n=$(ls "${dirname}"/*.${extensions} -1 2>/dev/null | wc -l) +n=$(ls "${dirname}"/*.${extensions} -1 2>/dev/null | sort -f -V | wc -l) 
-pos=$(ls "${dirname}"/*.${extensions} -1 2>/dev/null | grep -n -F -- "${basename}" | cut -d: -f1)+pos=$(ls "${dirname}"/*.${extensions} -1 2>/dev/null | sort -f -V | grep -n -F -- "${basename}" | cut -d: -f1)
  
 # if the filename does not have one of the extension above, launch vlc with provided filename # if the filename does not have one of the extension above, launch vlc with provided filename
 if [ -z "$pos" ]; then if [ -z "$pos" ]; then
- vlc -- "${filename}" +    vlc -- "${filename}" 
- exit+    exit
 fi fi
  
 # change positions in playlist such as the first element is the opened file # change positions in playlist such as the first element is the opened file
-ls "${dirname}"/*.${extensions} -1 | tail -n$(($n-$pos+1)) >  /tmp/vlc.m3u +ls "${dirname}"/*.${extensions} -1 | sort -f -V | tail -n$(($n-$pos+1)) >  /tmp/vlc.m3u 
-ls "${dirname}"/*.${extensions} -1 | head -n$(($pos-1))    >> /tmp/vlc.m3u+ls "${dirname}"/*.${extensions} -1 | sort -f -V | head -n$(($pos-1))    >> /tmp/vlc.m3u
  
 # launch playlist # launch playlist
-IFS=$'\n'; read -d '' -r -a files < /tmp/vlc.m3u; vlc "${files[@]}"+IFS=$'\n'; read -d '' -r -a files < /tmp/vlc.m3u; vlc --norandom "${files[@]}"
 </code> </code>
  
Line 73: Line 121:
 powershell -File %USERPROFILE%\vlc.ps1 %1 powershell -File %USERPROFILE%\vlc.ps1 %1
 </code> </code>
-<code vlc.ps1>+<code powershell vlc.ps1>
 Param([string]$filename) Param([string]$filename)
  
Line 116: Line 164:
 When you start VLC you get a new menu item: View > Move currently playing file into wastebasket. When you start VLC you get a new menu item: View > Move currently playing file into wastebasket.
  
-<code WasteBasket.lua>+<code lua WasteBasket.lua>
 --[[ --[[
 INSTALLATION (create directories if they do not exist): INSTALLATION (create directories if they do not exist):
Line 154: Line 202:
   -- create waste directory if it doesn't exist   -- create waste directory if it doesn't exist
   if(not directory_exists(wdir)) then   if(not directory_exists(wdir)) then
-    os.execute("mkdir " .. dirname(filename) .. wdir)+    -- escaping single quote while surrounding dir in single quotes for dirs with spaces 
 +    os.execute("mkdir '" .. string.gsub(dirname(filename) .. wdir, "\'", "\\\\'" ) .. "'")
     wdir = dirname(filename) .. wdir     wdir = dirname(filename) .. wdir
   end   end
Line 265: Line 314:
 </code> </code>
  
- +https://github.com/surrim/vlc-delete/ 
-<code delete.lua>+<code lua delete.lua>
 --[[ --[[
-    Copyright 2015-2016 surrim + Copyright 2015-2019 surrim 
-    https://gist.github.com/PAEz/d3a9be2471dbd39084136d974cdb9dd3 + 
-    https://forum.videolan.org/viewtopic.php?f=29&t=108811 + This program is free software: you can redistribute it and/or modify 
-    https://superuser.com/questions/721112/vlc-how-to-delete-file-on-disk# + it under the terms of the GNU General Public License as published by 
-    This program is free software: you can redistribute it and/or modify + the Free Software Foundation, either version 3 of the License, or 
-    it under the terms of the GNU General Public License as published by + (at your option) any later version. 
-    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, 
-    This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of 
-    but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + GNU General Public License for more details. 
-    GNU General Public License for more details. + 
-    You should have received a copy of the GNU General Public License + You should have received a copy of the GNU General Public License 
-    along with this program.  If not, see <http://www.gnu.org/licenses/>.+ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ]]-- ]]--
  
 function descriptor() function descriptor()
-    return { + return { 
-        title = "VLC Delete"; + title = "VLC Delete"; 
-        version = "0.1"; + version = "0.1"; 
-        author = "surrim"; + author = "surrim"; 
-        url = "https://github.com/surrim/vlc-delete/"; + url = "https://github.com/surrim/vlc-delete/"; 
-        shortdesc = "Remove current file from playlist and disk"; + shortdesc = "&Remove current file from playlist and disk"; 
-        description = [[+ description = [[
 <h1>vlc-delete</h1>" <h1>vlc-delete</h1>"
 When you're playing a file, use VLC Delete to When you're playing a file, use VLC Delete to
Line 297: Line 346:
 This extension has been tested on GNU Linux with VLC 2.1.5.<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. The author is not responsible for damage caused by this extension.
-        ]]; + ]]; 
-   }+ }
 end end
  
- 
--- Windows - Check if file exists 
 function fileExists(file) function fileExists(file)
-    return io.popen("if exist "..file.." (echo 1)"):read'*l'=='1'+ return io.popen("if exist " .. file .. " (echo 1)") : read "*l== "1"
 end end
  
- +function sleep(seconds
-function sleep(n -- seconds + local t0 = os.clock() 
-  local t0 = os.clock() + local tOriginal = t0 
-  local tOriginal=t0 + while os.clock() - t0 <= seconds and os.clock() >= tOriginal do end
-  while os.clock() - t0 <= and os.clock()>=tOriginal do end+
 end end
  
- +function windowsDelete(file, trys, pause) 
--- Windows - try and delete a file with multiple attempts and a pause between each try - waiting for the file to unlock + if not fileExists("\"" .. file .. "\"") then return nil, "File does not existend 
-function windowsDelete(file,trys,pause) + for i = trys, 1, -1 
-    if not fileExists('"'..file..'"') then return nil,'File does not existend + do 
-    for i = trys,1,-1 + retval, err = os.remove(file) 
-    do + --retval, err = os.execute("del .. file ) 
-        retval, err = os.remove(file) + if retval == true then 
-        --retval, err = os.execute('del .. file ) + return true 
-        if retval==true then + end 
-            return true + sleep(pause) 
-        end + 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 + return {nil, "Unable to delete file"}
-    end +
-    return {nil,'Unable to delete file'}+
 end end
  
 function removeItem() function removeItem()
-    local id = vlc.playlist.current() + local id = vlc.playlist.current() 
-    vlc.playlist.delete(id) + vlc.playlist.delete(id) 
-    vlc.playlist.gotoitem(id + 1) + vlc.playlist.gotoitem(id + 1) 
-    vlc.deactivate()+ vlc.deactivate()
 end end
  
 function activate() function activate()
-    local item = vlc.input.item() + local item = vlc.input.item() 
-    local uri = item:uri() + local uri = item:uri() 
-    uri = string.gsub(uri, '^file:///'''+ uri = string.gsub(uri, "^file:///"""
-    uri = vlc.strings.decode_uri(uri) + uri = vlc.strings.decode_uri(uri) 
-    vlc.msg.info("[vlc-delete] removing: " .. 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 + if (package.config:sub(1, 1) == "/") then -- not windows 
-        vlc.msg.info("[vlc-delete] error: " .. err) + retval, err = os.execute("trash-put --help > /dev/null"
-        d = vlc.dialog("VLC Delete"+ if (retval ~= nil) then 
-        d:add_label("Could not remove \"" .. uri .. "\"", 1, 1, 1, 1) + uri = "/" .. uri 
-        d:add_label(err, 1, 2, 1, 1) + retval, err = os.execute("trash-put \"" .. uri .. "\""
-        d:add_button("OK", click_ok, 1, 3, 1, 1) + else 
-        d:show() + retval, err = os.execute("rm --help > /dev/null"
-    end+ if (retval ~= nil) then 
 + uri = "/" .. uri 
 + retval, err = os.execute("rm \"" .. uri .. "\""
 + end 
 + end 
 + if (retval ~= nil) then removeItem() end 
 + else -- windows 
 + removeItem() -- remove from playlist first so the file isnt locked by vlc 
 + 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 end
  
 function click_ok() function click_ok()
-    d:delete() + d:delete() 
-    vlc.deactivate()+ vlc.deactivate()
 end end
  
 function deactivate() function deactivate()
-    vlc.deactivate()+ vlc.deactivate()
 end end
  
 function close() function close()
-    deactivate()+ deactivate()
 end end
  
Line 392: Line 435:
  
 https://superuser.com/questions/721112/vlc-how-to-delete-file-on-disk https://superuser.com/questions/721112/vlc-how-to-delete-file-on-disk
 +
 +
 +
howto/vlc-playlist-from-file.1641054919.txt.gz · Last modified: 2023/05/29 11:53 (external edit)