by Paul Arnote (parnote)
Anyone who hasn't heard of VLC by now has either been living under a rock, or stranded for the past 20 years on a deserted island. VLC is a premiere, multiplatform multimedia player. The open source VLC is available for Linux, Unix, Windows, MacOS, iOS, Android, Tizen and BeOS. There's not much that VLC can't do or play. For me, it's my "go to" video player. Unless I'm playing a whole list of songs, I usually opt for a simpler, lighter program to playback sound files.
Just two years ago, Jean-Baptiste Kempf, the project lead for VLC since 2007 and the creator of the VideoLAN non-profit, refused 10's of millions of Euros to keep VLC ads-free. You have to applaud and admire him for sticking to his principles. There are a LOT of people out there who would have caved in a heartbeat to have access to that kind of wealth.
As I've mentioned, VLC is the program I use as my default video player. And, as I mentioned last month, I have a computer hooked to my HDTV in the living room, serving as a player for digital video files to that TV.
Most anyone who has played music knows about *.m3u files. For those who may not know, m3u files are playlists for (typically) music files. M3u files, in their simplest iteration, are text files containing the paths (optional) and filenames (required) of the digital sound files you want to play, in the order you want to play them.
Here is one for my daughter's favorite pop songs (I wonder if you can tell who she likes):
And, VLC (as well as just about every other audio player on the planet) will read m3u files just fine to playback your custom playlist.
But, when it comes to videos, m3u files don't always "make the grade."
VLC supports another playlist format, and from what I can tell, it's "unique" to VLC. It's a bit more complex than a m3u playlist. Its file extension is *.xspf. You can create the xspf playlist from within VLC by building it in VLC's playlist window, then saving the resulting playlist to your hard drive. Go ahead. Create one in VLC and then open it up in a simple text editor. You will see how much more complex a xspf file is than a m3u file.
Except I needed a better, easier way. I wanted a way to build the VLC playlist from within my file manager. I didn't want to open VLC every time I wanted/needed to create a video playlist. Since I'm a devout Xfce user, that file manager is Thunar. I wanted to create a way to build the VLC playlist by way of a Thunar Custom Action. Because of the increased "complexity" of the xspf playlist file (compared to a m3u file), I wouldn't be able to just enter a few commands and have the playlist created. The xspf file creation would have to be controlled by a bash script. Because I'm ultimately calling a bash script from a Thunar Custom Action, I'm certain that the process should be repeatable from KDE and Dolphin, Mate and Caja, and several other file managers with a minimum of extra effort. It will also work from the command line, too.
I'm not the only person who has wondered about creating a xspf playlist file from the command line either, gauging by the number of inquiries I found when seeking out a solution. None of the touted "solutions" worked consistently -- if at all -- for me. So, I set out to create my own solution.
After intensely studying the format of a xspf playlist file actually created by VLC, and applying some "tips" I picked up looking at other "solutions" that didn't fully work out for my use, I was able to duplicate the VLC xspf playlist output accurately via a bash script. You would be hard pressed to differentiate the file list my bash script produces from the one that VLC produces.
I've numbered the lines so you can more easily see what's on each line, since some lines get "wrapped" due to their length.
I've saved the bash file in my $HOME/bin directory, which is in my PATH statement so that it can be easily called into action without having to type in the full path to the bash script every time I need to use it. I called the script make-vlc-xspf-playlist.sh.
To use it from the command line, I first move to directory containing the video files I want to include in my playlist, then execute the command as follows:
make-vlc-xspf-playlist.sh [list of video files with full path and filename]
Or, you can do it more easily, by using wildcards, like the command below, instead of listing the full path and filename of the movies in your playlist individually.
Here is a sample VLC xspf video playlist produced by the script:
Again, I've applied line numbers to help compensate for the word wrapping, so that it's more intelligible.
Integrating Into Thunar, Via Thunar Custom Action
Once you get into Thunar's "Edit" menu, choose the "Configure Custom Actions…" menu item. Then, fill in the fields of the first tab (Basic) as in the image above. I named it "Make VLC XSPF Playlist," and gave it a description of "Make playlist for VLC video files." Under the command entry, I entered make-vlc-xspf-playlist.sh %F as the command to execute. Click on the "No Icon" button to select an icon to use in Thunar's right-click context menu next to the name.
Switch to the "Appearance Conditions" tab of the dialog box. Enter a single wildcard * in the file pattern, and check the box next to "Video Files." Then, click on OK to save the new Thunar Custom Action.
Now, travel in Thunar to a directory holding the video files you want to place into a VLC xspf playlist. Select the ones you want to add to your video playlist, then right click on them. If you did everything correctly, you should see something like in the image above. Select "Make VLC XSPF Video Playlist" from the right-click context menu.
You should see the image above. Just enter the name for your video playlist, without a file extension. The xspf file extension will be added for you automatically. Your new playlist will be placed in the directory with your videos. When you want to view the videos in that playlist, just double-click on the playlist in Thunar, and VLC should open with the playlist preloaded. In VLC, right click on the video you want to start with (it may not always be the first one listed ... you may be coming back to finish viewing a previous playlist that you didn't complete), and select "Play" from VLC's right-click context menu.
I'm no bash guru. That is an absolute. I'm more of a bash basher. I have a LOT more room for "growth" when it comes to my bash scripting skills. I can mostly get things done by bashing around in bash. I also have pretty good luck finding code snippets here and there, and then customize them to better fit the task I'm trying to accomplish. So, there may be other ways to achieve what I did in my bash script. But at the end of the day, it works. It works well, in fact. Not too bad for 41 lines of actual code (subtracting the nine blank lines inserted to promote readability), if I do say so myself.
Now, when my son wants to watch a bunch of his animated Transformers episodes (each only about 24 minutes long), I can just load up a whole season at a time by double clicking on the premade VLC video playlist. Then, they play one after another, until the playlist is exhausted.
To make it easier, I've got a copy of the script you can download from the magazine's website. It'll save you a lot of typing, and a lot of possible errors. Just remove the ".txt" file extension, and allow the file to be executed. The download is only 1.6 KiB, so it should download rather quickly.