Automatically log all your played songs, with a time stamp
Alternatively, without changing anything to your .desktop file or having to manually log your songs, you can run the background script below. It will create a log file, named played_songs, in your home directory:

Advantages are:
- Fully automatically logs all your played songs
- No need to change your
.desktopfile, which means it also works when you start VLC from the command line.
Disadvantages are:
- Although I couldn't measure or see any additional processor load, theoretically it adds some activity. This is practically none though, even on stone-age boxes.
- From time to (long) time, you will need to "empty" or remove the log file, since (currently) it has no limit in size. This can be easily fixed though if you like.
The script
#!/usr/bin/env python3
import subprocess
import os
import time
home = os.environ["HOME"]
log = os.path.join(home, "played_songs")
def_name = "VLC media player"
def get(cmd):
try:
return subprocess.check_output(cmd).decode("utf-8").strip()
except subprocess.CalledProcessError:
pass
song1 = None
while True:
time.sleep(2)
pid = get(["pgrep", "vlc"])
if not pid:
song = None
else:
# only do anything at all if vlc runs
wins = get(["wmctrl", "-lp"])
if wins:
wins = wins.splitlines()
try:
# check if any of the windows belongs to vlc
# this will not if it is closed in the meantime
match = [w.split()[0] for w in wins if pid in w][0]
except IndexError:
pass
else:
# ...if so, retrieve the song name, only log if there is a new song
song2 = get(["xdotool", "getwindowname", match])
if all([song2, song2 != song1, song2 != def_name]):
open(log, "a+").write(
time.strftime("%H:%M:%S_%d-%m-%Y")+"\n "+\
song2.replace(def_name, "").rstrip(" - ")+"\n"
)
song1 = song2
How to use
The script needs both xdotool and wmctrl:
sudo apt-get install xdotool wmctrl
Copy the script into an empty file, save it as log_vlc.py
Test- run it from a terminal by the command:
python3 /path/to/log_vlc.py
Open any song in VLC in either way (cli, gui), the log file should be created and show the logged songs.
If all works fine, add ity to Startup Applications: Dash > Startup Applications > Add. Add the command:
python3 /path/to/log_vlc.py
Explanation
Once per two seconds, the script:
checks if VLC is running at all, does nothing if not
pid = get(["pgrep", "vlc"])
if pid:
# only do anything at all if vlc runs
if VLC is running, it finds its window and parses out the song title
wins = get(["wmctrl", "-lp"])
if wins:
wins = wins.splitlines()
try:
# check if any of the windows belongs to vlc
# this will not be the case if it is closed in the meantime
match = [w.split()[0] for w in wins if pid in w][0]
except IndexError:
pass
else:
# ...if so, retrieve the song name, only log if there is a new song
song2 = get(["xdotool", "getwindowname", match])
(only) if the song title changes, obviously a new song is played, then the song name is logged into the log file, time stamped.
if all([song2, song2 != song1, song2 != def_name]):
open(log, "a+").write(
time.strftime("%H:%M:%S_%d-%m-%Y")+"\n "+\
song2.replace(def_name, "").rstrip(" - ")+"\n"
)
print(song2)
song1 = song2