Ticket #225: emulator_screenshots30.sh

File emulator_screenshots30.sh, 4.2 KB (added by jochen, 16 years ago)

Version 3.0

Line 
1#!/bin/sh
2
3DBUSER=root;
4DBPWD=
5DBNAME=mythconverg
6
7PAUSETIME=10 #so long is waited after running the emulator until the screenshot is taken
8
9TMPFILE=/tmp/tmp.png
10
11case "$1" in
12
13 start)
14
15  WERTE=`echo "SELECT playername FROM gameplayers" | mysql -B --database=$DBNAME --password=$DBPWD --user=$DBUSER -N`;
16
17  for player in $WERTE
18   do
19 
20    ROMPATH=`echo "SELECT rompath FROM gameplayers WHERE playername = '$player'" | mysql -B --database=$DBNAME --password=$DBPWD --user=$DBUSER -N`
21    COMMANDLINE=`echo "SELECT commandline FROM gameplayers WHERE playername = '$player'" | mysql -B --database=$DBNAME --password=$DBPWD --user=$DBUSER -N`
22    EXTENSIONS=`echo "SELECT extensions FROM gameplayers WHERE playername = '$player'" | mysql -B --database=$DBNAME --password=$DBPWD --user=$DBUSER -N`
23    SCREENSHOTS=`echo "SELECT screenshots FROM gameplayers WHERE playername = '$player'" | mysql -B --database=$DBNAME --password=$DBPWD --user=$DBUSER -N`
24   
25    cmdpfad=$(dirname "$(echo $COMMANDLINE | cut -d "-" -f 1)")
26    cmdprgname=$(basename "$(echo $COMMANDLINE | cut -d "-" -f 1)")
27    cmdparameter=${COMMANDLINE:$((`echo "$cmdpfad" | wc -m`+`echo "$cmdprgname" | wc -m`-1)):`echo "$COMMANDLINE" | wc -m`}
28    cmdrun=`echo "$cmdpfad/$cmdprgname"`
29   
30    extens2=${EXTENSIONS//,/ }
31
32    if [ -z "$extens2" ]; then
33       echo "no Extensions, searching for *.*"
34          if [ "$ROMPATH" ]; then
35          if [ "$SCREENSHOTS" ]; then
36             #if [ "$player" = "GBA" ]; then
37             for i in $ROMPATH/*.*
38             do
39                path="`expr "$i" : '\(.*\)/'`"                  # get file path (if any)
40                name="`expr "//$i" : '.*/\([^/]*\)'`"           # remove path to file
41                suffix="`expr "$name" : '.*\.\([^./]*\)$'`"     # extract last suffix
42                name="`expr "$name" : '\(.*\)\.[^.]*$'`"        # remove last suffix
43                picname=$name.png
44                picpfd=`echo "$SCREENSHOTS/$picname"`
45                if [ -e "$picpfd" ]; then
46                   echo "Screenshot exists: $picpfd"
47                else
48                   echo "Screenshot $picpfd is being generated"
49                   COMMAND="start-stop-daemon --exec $cmdrun --start --background -- $cmdparameter"
50                   $COMMAND "$i"     
51                   sleep $PAUSETIME
52                   scrot --quality 1 $TMPFILE
53                   mv $TMPFILE "$picpfd"
54                   killall -9 $cmdrun
55                   sleep 1
56                fi
57             done
58             #fi
59          fi
60          fi
61       else
62          for p in $extens2
63          do
64             echo "searching for *.$p"
65             if [ "$ROMPATH" ]; then
66             if [ "$SCREENSHOTS" ]; then
67                #if [ "$player" = "GBA" ]; then
68                for i in $ROMPATH/*.$p
69                do
70                   path="`expr "$i" : '\(.*\)/'`"                  # get file path (if any)
71                   name="`expr "//$i" : '.*/\([^/]*\)'`"           # remove path to file
72                   suffix="`expr "$name" : '.*\.\([^./]*\)$'`"     # extract last suffix
73                   name="`expr "$name" : '\(.*\)\.[^.]*$'`"        # remove last suffix
74                   picname=$name.png
75                   picpfd=`echo "$SCREENSHOTS/$picname"`
76                   if [ -e "$picpfd" ]; then
77                      echo "Screenshot exists: $picpfd"
78                   else
79                      echo "Screenshot $picpfd is being generated"
80                      COMMAND="start-stop-daemon --exec $cmdrun --start --background -- $cmdparameter"
81                      $COMMAND "$i"     
82                      sleep $PAUSETIME
83                      scrot --quality 1 $TMPFILE
84                      mv $TMPFILE "$picpfd"
85                      killall -9 $cmdrun
86                      sleep 1
87                   fi
88                done
89                #fi
90             fi
91             fi
92          done
93       fi
94    done
95  ;;
96 
97  *)
98  echo ""
99  echo "This is a Script to generate Screenshots for your Emulators, wich"
100  echo "you have set up in MythTV automaticaly. It uses the program scrot"
101  echo "to generate the screenshot."
102  echo ""
103  echo "To run you had to enter: emulator_screenshots start"
104  echo "Bevor running, check the username and passwort in the script"
105  echo "Also the timeout until the screenshot is taken can be adjusted"
106  ;;
107esac