Use my own pictures in the Screen Saver

From LinuxMCE
Jump to: navigation, search

The photo screen saver does a great job and ensures that media is displayed all the time, even if you just happen to be listening to music. By default, the photos come from flickr and are downloaded regularly to your local drives.

But it would be nice to use your own photos in this screen saver, perhaps alongside the flickr ones or perhaps as a replacement.

Quick Update: In the current version it's possible to select photos for screensaver in much easier way. Goto the LinuxMCE Admin Website-->Files & Media -> Screensaver menu.


Background

All media on a LinuxMCE system is catalogued and stored in a database. The database allows for attributes to be stored for each media file.

One such attribute is "Screen Saver For MD". If this attribute is set for a picture, it will be used as one of the pictures for the Media Director Screen Saver. Pictures must be smaller than 1240x1240px.

Photos are selected by random from all the photos with the "Screen Saver For MD" attribute set.

There are a number of ways to set this attribute for individual files. They are;

  • Setting an attribute from the web admin screens
  • Setting an attribute from the command line
  • Assigning a picture to the screen saver from the Orbiter

Setting an attribute from the web admin screens

  • The left hand window frame gives a tree view into the directory structure of home/public/data.

Typically photos will be stored under the pictures sub-directory. The right hand window frame gives a view of the files found and their status with relation to linuxMCE's database.

  • Determine the pictures you wish to use, and locate them using the directory browser.
  • Ensure that the files are ticked to indicate that they exist in both the database and on the disk. If not, then choose the type as 'LinuxMCE Pictures' and press the 'Add to database' button.
  • Once they are added to the database you should be able to select them and see the details (metadata) that are associated with them.
  • Part of the details include any currently set attributes for the file, which you can choose to Edit or Remove.
  • There is also a section to Add Attributes. Only attributes that have been associated with the particular file type can be selected from the drop down box.
  • Note: If you do not see 'Screen Saver For MD,' then 'Associate the attribute.'
  • Select the attribute 'Screen Saver For MD' and enter or select the Attribute name value of '*'. Then press the Add button next to the box and your done.

A quick reload router should be enough to ensure that files are refreshed from the database. The selected picture should then be seen to be one of the screen saver files.

Associate the attribute

Unfortunately by default this attribute has not been associated with the picture media type. Perhaps a bug, who knows. Anyway, to associate it you will need to run the following piece of SQL to put the required association into the database.

You will need to get to the command prompt of your CORE machine and from the command prompt (your default user should be fine) run:

mysql -u root -D pluto_media -N -e "INSERT into MediaType_AttributeType(EK_MediaType, FK_AttributeType, Identifier, CombineAsOne) values(7,30,0,1)"

Do a quick reload router and then the attribute should show up in the dropdown box under add attributes

Note: If someone knows a better way to do this or can see some adverse side effects please update

Setting an attribute from the command line

There is functionality built into the system that allows an attribute to be set through a sequence of Command Messages sent to the right device. This is what the flickr.pl script uses to assign the downloaded files the right attributes. The commands can be executed from anything that can send linuxMCE messages (including the web admin screens) but this method will utilise the MessageSend utility available from the linux command line.

You will need to firstly determine the full filename and path for the file you wish to set the attribute for. This method assumes that the file has already been sync'd with linuxMCE and exists in the data base.

The first command queries the database for the file ID of a particular filename.

The second command assigns an attribute type/value to the returned file ID

  • Logon to your linuxMCE CORE and get to the linux command prompt
  • execute the following command
/usr/pluto/bin/MessageSend dcerouter -targetType template -r -o 0 2 1 819 13 <pathtofile>

Substituting your full path to the file where is says <pathtofile>

eg: /usr/pluto/bin/MessageSend dcerouter -targetType template -r -o 0 2 1 819 13 /home/public/data/pictures/sample.jpg

You should get a response something like this:

0:OK
145:11392

The number next to the '145:' is the important part. This is the fileID. If this is zero then your command has not found a match in the database and you may need to take other measures to ensure that the database is sync'd with your files.

  • Now execute the following command
/usr/pluto/bin/MessageSend dcerouter -targetType template -r -o 0 2 1 391 145 <fileID> 122 30 5 "*"

Substituting the fileID that you just discovered where it says <fileID>

eg: /usr/pluto/bin/MessageSend dcerouter -targetType template -r -o 0 2 1 391 145 11392 122 30 5 "*"

  • You can then repeat for any other files that you want to use

Below is a simple script which takes all the jpg files in the current directory, resizes them to a screensaver safe size, and then marks them as being usable by the screensaver. There is no error checking and it shrinks all the images in place, so make sure you make a copy of the images first and place them in another directory. Note: this would normally be run on a directory below /home/public/data/pictures.

#!/bin/bash

# Copyright 2008 (c) Daniel Kristjansson
# You may use this for any purpose whatsoever, so long as you preserve the copyright notice.
# You may relicense this and add your own contributions freely.
# Use this at your own risk.

MAX_SIZE=1024 #don't set it bigger than 1240

for FILE in `ls *.jpg *.JPG` ; do
    PWD=`pwd`
    FILEID=`/usr/pluto/bin/MessageSend dcerouter -targetType template -r -o 0 2 1 819 13 $PWD/$FILE | tail -n 1 | sed -e 's/^.*://g'`
    RES=`identify -verbose $FILE | head -n1 | awk '{ print $3 }'`
    WIDTH=`echo $RES | sed -e 's/x.*//g'`
    HEIGHT=`echo $RES | sed -e 's/.*x//g'`

    NEW_WIDTH=$WIDTH
    NEW_HEIGHT=$HEIGHT
    if [ $WIDTH -gt $MAX_SIZE -o $HEIGHT -gt $MAX_SIZE ] ; then
        if [ $WIDTH -gt $HEIGHT ] ; then
           NEW_WIDTH=$MAX_SIZE
           NEW_HEIGHT=`expr $NEW_WIDTH "*" $HEIGHT "/" $WIDTH`
        else
           NEW_HEIGHT=$MAX_SIZE
           NEW_WIDTH=`expr $NEW_HEIGHT "*" $WIDTH "/" $HEIGHT`
        fi
    fi


    if [ $WIDTH != $NEW_WIDTH -o $HEIGHT != $NEW_HEIGHT ] ; then
        echo file id: $FILEID old dim: $RES : w $WIDTH : h $HEIGHT \-\> new dim: $NEW_WIDTH $NEW_HEIGHT
        convert $FILE -resize ${NEW_WIDTH}x${NEW_HEIGHT}! resized_$FILE
        mv resized_$FILE $FILE
    else
        echo file id: $FILEID old dim: $RES : w $WIDTH : h $HEIGHT
    fi

    /usr/pluto/bin/MessageSend dcerouter -targetType template -r -o 0 2 1 391 145 ${FILEID} 122 30 5 "*"
done

Assigning a picture to the screen saver from the Orbiter

Sounds like a good idea??? Unfortunately it is not currently possible, but I thought that this sounded like a logical thing to do so have put this placeholder in.

Essentially, screens in the Orbiter have buttons that trigger message Command to be sent. So setting up a button in the Picture view screen "add to Screen Saver" should be quite straight forward.

If you feel like getting involved maybe this is somewhere you can start.....

NOTE: Pictures must be smaller than 1240 x 1240. Hope this saves some a bit of fustration.