๐ I made a script to track what music player (vlc) is playing and not play it next time
๐ก Newskategorie: Linux Tipps
๐ Quelle: reddit.com
Hello everyone! I have made a lot of weird but useful scripts over the years I am using linux and I don't really know where to share them so I'll start posting them here. I am waiting feedback if this is a good place to share them or not and how can I improve them. I think github is not a good option really as they are quite simple but I might use it. Anyway
this bash script checks what vlc is playing every 10 seconds (can be changed at line 9) checks if that song exists in the playlist file and removes it from the playlist file (if it does exist). Next time I open the playlist.m3u with vlc it won't have the songs it played the previous time.
I needed to make this because I have a huge library playing in shuffle all the time. But I always end up listening to the same songs over and over again cause the playlist will reload each time I open it. So I have a backup playlist which has all the songs, a playlist with the played songs removed and I always open that one with vlc. Here is the bash script:
#!/usr/bin/bash #usage: progname /path/to/playlist-file.m3u filename="$1" vlc $filename &>/dev/null & sleep 3 pid=$(pidof -s vlc) while [[ $pid ]]; do sleep 10 pid=$(pidof -s vlc) if [[ ! $pid ]]; then break fi songname=$(lsof -p `pidof -s vlc` | grep -o "/.*\.mp3" | sed -E "s/.+Music\/(.+)\.mp3/\1/") deletioncheck=$(grep -o "$songname" $filename) if [[ $songname = $deletioncheck ]]; then linenumber=$(grep -n "$songname" $filename | sed -E "s/^([0-9]+):.+$/\1/g") nextlinenumber=$((linenumber+1)) thed="d" sed -i "$linenumber$thed;$nextlinenumber$thed" $filename fi done
Of course it can be used with other music players (line 5,7,10,14). In line 14 you can change the path to where your songs are. Unfortunately it assumes they are all in the same directory. But that is no problem as I made a script where it autosorts and moves files in the correct directories as well as moving them out of directories! But I will post that another time if you want of course. :)
What do you think?
[link] [comments] ...