Is it possible to automatically save playlists (to files) in Rhythmbox

322 views Asked by At

Besides the question in the title I would like to explain my motivation, maybe there is another solution for my situation.

I work at different stations of a little local network, I usually work in station 3, where I listen to music while I work and where I add new songs to my playlists.

If, for a couple of days, I have to work at station 5, I would like to listen to music saved at one of my playlists. In order to do so, I have to save the playlist to a file in station 3, and then import it in station 5, but sometimes I forget to do it and when I'm already in station 5 I have to go back to station 3 and save the pl.

So, one part is the question asked in the title, and another would be how to automatically update or import the saved playlist (in station 5, or any other.)

Thanks.

3

There are 3 answers

0
Andrés Chandía On BEST ANSWER

I have implemented another user based solution. For this to work you need to log into the different workstations with the same user....

  1. Close Rhythmbox on the stations/users involved.

  2. In the user directory located on the file server create a new subdirectory, let's call it rhythmbox.

  3. Inside the newly created rhythmbox subdirectory, create two new subdirectories, cache and share.

  4. From the workstation where you usually manage Rhythmbox, that is, where you create and maintain playlists, move the Rhythmbox cache to the file server cache directory:

# mv $HOME/.cache/rhythmbox //file-server/home/USER/rhythmbox/cache/

  1. Move the Rhythmbox shared directory to the file server:

# mv $HOME/.local/share/rhythmbox //file-server/home/USER/rhythmbox/share/

  1. Where the original directories where, create symbolic links.

a1. # cd $HOME/.cache/

a2. # ln -s //file-server/home/USER/rhythmbox/cache/rhythmbox

b1. # cd $HOME/.local/share/

b2. # ln -s //file-server/home/USER/rhythmbox/rhythmbox/share/rhythmbox

  1. On the other stations remove the Rhythmbox cache and share directories and replace them with the symbolic links.

Then, the next time you open your Rhythmbox from any station logging in with the same user, your Music application will access the same data, so the settings and playlists will be the same on all stations.

0
Andrés Chandía On

I finally came out with a partial solution. It is partial because it covers only the "Automatically saving Rhythmbox playlists to files". I still don't know how to automatically load playlists from files into Rhythmbox... let's see the script I've created (which you can put either at starting or shutting down your system):

File: playlist.sh

#!/bin/sh
 #Variables [Replace USER by your Linux user and set the playlistDir where suits you the best]
 playlistXml="/home/USER/.local/share/rhythmbox/playlists.xml"
 playlistDir="/home/USER/musiclists"
 # Create a file per list
 xmlstarlet sel -t -v 'rhythmdb-playlists/playlist/@name' -nl "$playlistXml" |
 while read name; do
    xmlstarlet sel -t --var name="'$name'" -v 'rhythmdb-playlists/playlist[@name = $name]' "$playlistXml" > "$playlistDir/$name.pls"
 #Delete empty lines from generated files
    sed -i "/^$/d" "$playlistDir/$name.pls"
 #Add line numbers to define file number
    cat -n "$playlistDir/$name.pls" > tmp
    mv tmp "$playlistDir/$name.pls"
 #Add file headder
    songs=$(wc -l < "$playlistDir/$name.pls")
    sed -i "1i \[playlist\]\nX-GNOME-Title=$name\nNumberOfEntries=$songs" "$playlistDir/$name.pls"
done
#Format playlist
sed -i -r "s/^\s+([0-9]+)\s+file:(.*)$/File\1=file:\2\nTitle\1=/g" $playlistDir/*.pls

Set the file as executable: chmod +x playlist.sh

0
Andrés Chandía On

Ok, here it goes how I solved my issue. First I have to explain how my network is set:

5 computers in the network, Station 1 is the "File server" giving this service via NFS (all computers in the network are Linux). Stations 2 to 5 mount directories as set in the "/etc/fstab" file, for exemple:

# File server
fileserv:/home/REMOTEUSER/Documents /home/LOCALUSER/Documents   nfs4    rsize=8192,wsize=8192,timeo=14,intr,_netdev 0 0
fileserv:/home/REMOTEUSER/Music /home/LOCALUSER/Music   nfs4    rsize=8192,wsize=8192,timeo=14,intr,_netdev 0 0
fileserv:/home/REMOTEUSER/Video /home/LOCALUSER/Video   nfs4    rsize=8192,wsize=8192,timeo=14,intr,_netdev 0 0
fileserv:/home/REMOTEUSER/Downloads /home/LOCALUSER/Downloads   nfs4    rsize=8192,wsize=8192,timeo=14,intr,_netdev 0 0
fileserv:/home/REMOTEUSER/Images    /home/LOCALUSER/Images  nfs4    rsize=8192,wsize=8192,timeo=14,intr,_netdev 0 0

NOTE: if you don't have your server in the /etc/hosts file you can use the ip instead, like:

192.168.1.1:/home/REMOTEUSER/Documents  /home/LOCALUSER/Documents   nfs4    rsize=8192,wsize=8192,timeo=14,intr,_netdev 0 0
etc...

Having previous data in mind. In station 3 I have set an every hour cron job that runs the next command (I could find the way to execute a script on logout, but I usually only turnoff the machine which does not run the script. If I put the script in rc6.d the problem is that station 3 root user is not allowed in station 1 (file server), and the "local user" of station 3 is already logged out).

crontab -l
# m h  dom mon dow   command
0 * * * * cp /home/USER/.local/share/rhythmbox/playlists.xml /home/USER/Documents/USER/musiclists/

To recover music lists from station 3, I have created next script in station 5:

File: .RhythmboxPlaylists.sh

#!/bin/sh
### Modify variables as needed
REMUS="USER" #Remote user
LOCUS="USER" #Local user

### Rhythmbox play list location saved from station 3
ORIGPL="/home/$LOCUS/Documents/$LOCUS/musiclists/playlists.xml"

#### Local Rhythmbox play list location
DESTPL="/home/$LOCUS/.local/share/rhythmbox/playlists.xml"

### DO NOT MODIFY FROM THIS LINE DOWN
sed -i "s/home\/$REMUS\//home\/$LOCUS\//g" $ORIGPL
mv $ORIGPL $DESTPL

Set file as executable

chmod +X .RhythmboxPlaylists.sh

Add next line:

sh $HOME/.RhythmboxPlaylists.sh

at the end of file .bashrc to run it at user login (save .bashrc).

Then, when I open Rhythmbox in station 5 I have the same playlists with the same songs as in station 3.