diff --git a/Makefile.am b/Makefile.am index 655f0e7..4f30f29 100644 --- a/Makefile.am +++ b/Makefile.am @@ -17,21 +17,21 @@ mpdevlibexecdir=@libexecdir@/mpdev mpdevsysconfdir=@sysconfdir@/mpdev mpdevbin_PROGRAMS = mpdev -mpdevbin_SCRIPTS = librefm-scrobbler lastfm-scrobbler mpdplaylist romprhist \ +mpdevbin_SCRIPTS = librefm-scrobbler lastfm-scrobbler mpdplaylist \ transfer_play karma songi mpdhist mpdevlibexec_PROGRAMS = mpdev_cleanup mpdev_update mpdevlibexec_SCRIPTS = player playpause mpdev_rename output mixer create_service \ lcd_display noinst_DATA = mpdev.spec PKGBUILD man_MANS = mpdplaylist.1 mpdev.1 lastfm-scrobbler.1 librefm-scrobbler.1 \ - mpdev_update.1 mpdev_cleanup.1 transfer_play.1 romprhist.1 \ + mpdev_update.1 mpdev_cleanup.1 transfer_play.1 \ mpdev_rename.1 karma.1 songi.1 mpdhist.1 mpdevsysconf_DATA=mpdev-release mpd_local.te doc_DATA=LICENSE moc-scrobbler-license mpdev.changes README.md MOSTLYCLEANFILES = mpdev player playpause librefm-scrobbler \ lastfm-scrobbler mpdplaylist choose \ - create_service romprhist karma output mixer \ + create_service karma output mixer \ songi mpdhist lcd_display mpdev_SOURCES = mpdev.c @@ -89,10 +89,6 @@ songi: songi.in $(edit) $@.in > $@ chmod +x $@ -romprhist: romprhist.in - $(edit) $@.in > $@ - chmod +x $@ - mpdhist: mpdhist.in $(edit) $@.in > $@ chmod +x $@ diff --git a/README.md b/README.md index 11c4f8a..b6cea5d 100644 --- a/README.md +++ b/README.md @@ -7,11 +7,11 @@ mpdev helps in bulding a database of your played tracks. Along with a script `mpdplaylist`, it can generate a playlist for mpd as per your taste and mood. -You can create scripts in $HOME/.mpdev directory. The default installation installs two scripts player and playpause in $HOME/.mpdev directory for uid 1000. The scripts are adequate for most use cases. The player script can additionally be configured to update [RompЯ](https://fatg3erman.github.io/RompR/) database. The player script does the following +You can create scripts in $HOME/.mpdev directory. The default installation installs two scripts player and playpause in $HOME/.mpdev directory for uid 1000. The scripts are adequate for most use cases. The player script does the following 1. scrobbles titles to last.fm and libre.fm. You have to create API keys by running lastfm-scrobbler and librefm-scrobbler one time. You can disable scrobbling by setting DISABLE\_SCROBBLE environment variable. -2. updates play counts in the sqlite stats.db. You could write your own script and update any external database. The player script can also update the Playcounttable for [RompЯ](https://fatg3erman.github.io/RompR/) if few environment variables MYSQL\_HOST, MYSQL\_USER, MYSQL\_PASS and MYSQL\_DATABASE are configured. -3. Synchronizes the ratings in the sticker (sqlite). You could write your own script and update any external database. The player script can also update the Ratingtable for [RompЯ](https://fatg3erman.github.io/RompR/) if few environment variables MYSQL\_HOST, MYSQL\_USER, MYSQL\_PASS and MYSQL\_DATABASE are configured. You can also do automatic rating to some default value by setting an environment variable AUTO\_RATING by creating a file $HOME/.mpdev/AUTO\_RATING. If you are using supervise from deamontools (more on that below), creating an environment variable is very easy. e.g. To have an environment variable AUTO\_RATING with value 6, you just need to have a file name AUTO\_RATING in /service/mpdev/variables. The file should just have 6 as the content. +2. updates play counts in the sqlite stats.db. You could write your own script and update any external database. +3. Synchronizes the ratings in the sticker (sqlite). You could write your own script and update any external database. You can also automatically rate songs to some default value by setting an environment variable AUTO\_RATING by creating a file $HOME/.mpdev/AUTO\_RATING. If you are using supervise from deamontools (more on that below), creating an environment variable is very easy. e.g. To have an environment variable AUTO\_RATING with value 6, you just need to have a file name AUTO\_RATING in /service/mpdev/variables. The file should just have 6 as the content. 4. Update the song's karma. Karma is a number ranging from 0 to 100. If a song is skipped, it's karma is downgraded by 1. Karma can be downgraded only for songs rated less than 6 and played 5 times or less and whose karma is 50 or less. If a song is played twice within a day, it's karma is upgraded by 4. If a song is played twice within a week, it's karma is upgraded by 3. If a song is played twice within 14 days, its karma is upgraded by 2. If a song is played twice within a month, it's karma is upgraded by 1. All songs start with a default karma of 50. A song earns a permanent karma if any of the below happen * it's karma becomes 60 or more. @@ -114,7 +114,7 @@ OUTPUT_2_NAME=Scarlett 2i2 USB OUTPUT_2_STATE=disabled ``` -If you create the `stats` database, mpdev will update the last\_played field, play\_count fields in stats db. It will also update the song rating that you choose for the song. The ability to rate songs in mpd can be enabled by having the `sticker_file` keyword uncommented in `/etc/mpd.conf`. You will also need a mpd client that uses the mpd sticker command. One such player is `cantata`, which is available for all linux distros and Mac OSX. mpdev can also update [RompЯ](https://fatg3erman.github.io/RompR/) ratings and play counts and synchronize the ratings between [RompЯ](https://fatg3erman.github.io/RompR/) MySQL and sticker sqlite databases. Since mpdev runs in the background, it can keep updating [RompЯ](https://fatg3erman.github.io/RompR/), stats db play counts and history without you having to keep [RompЯ Web Frontend](https://fatg3erman.github.io/RompR/) running. +If you create the `stats` database, mpdev will update the last\_played field, play\_count fields in stats db. It will also update the song rating that you choose for the song. The ability to rate songs in mpd can be enabled by having the `sticker_file` keyword uncommented in `/etc/mpd.conf`. You will also need a mpd client that uses the mpd sticker command. One such player is `cantata`, which is available for all linux distros and Mac OSX. The sticker database can be enabled by having the followinng entry in `/etc/mpd.conf` @@ -127,33 +127,7 @@ sticker_file "/var/lib/mpd/sticker.db" # ``` -If you want to use mpdev to update the [RompЯ](https://fatg3erman.github.io/RompR/) db, you need to set the following variables - -``` -ROMPR - set this to any non-empty string (e.g. rompr) -MYSQL_HOST - set this to the host on which rompr's MySQL database is running -MYSQL_PORT - Port on which MySQL is running (usually 3306) -MYSQL_USER - User for connecting to MySQL (e.g. rompr) -MYSQL_PASS - Password for MYSQL_USER (e.g. romprdbpass) -MYSQL_DATABASE - Database name for rompr db (e.g. romprdb) -``` - -One can use [supervise](https://en.wikipedia.org/wiki/Daemontools) from the indimail-mta package to run this. The default rpm/debian installation of mpdev will do that for you. But it will not enable RompЯ. In case you are using RompЯ, you need to run the following commands to create the above environment variables - -``` -$ sudo /bin/bash -# echo rompr > /service/mpdev/variables/ROMPR -# echo 192.168.1.100 > /service/mpdev/variables/MYSQL_HOST # assuming you have MySQL database installed on 191.168.1.100 -# echo 3306 > /service/mpdev/variables/MYSQL_PORT -# echo rompr > /service/mpdev/variables/MYSQL_USER -# echo romprdbpas > /service/mpdev/variables/MYSQL_PASS -# echo romprdb > /service/mpdev/variables/MYSQL_DATABASE -# echo /home/pi > /service/mpdev/variables/HOME -# echo /bin:/usr/bin > /service/mpdev/variables/PATH -# echo 6 > /service/mpdev/variables/AUTO_RATING -``` - -You need to restart mpdev for the new environment variables to be available to mpdev. To restart the mpdev daemon, you then just need to run the following command. `svc -d` stops the daemon, `svc -u` starts the daemon. +You need to restart mpdev for the new environment variables to be available to mpdev. To restart the mpdev daemon, you then just need to run the following command `svc -r /service/mpdev`. Below are few operations to stop, start and restart mpdev. ``` $ sudo svc -d /service/mpdev # this stops the mpdev daemon @@ -180,13 +154,7 @@ If you want to do a source install and not have the supervise to run mpdev daemo #!/bin/sh while true do - env ROMPR=rompr \ - MYSQL_HOST=192.168.1.100 - MYSQL_PORT=3306 - MYSQL_USER=rompr - MYSQL_PASS=romprdbpass - MYSQL_DATABASE=romprdb \ - HOME=/home/pi \ + env HOME=/home/pi \ MPDEV_TMPDIR=/tmp/mpdev \ XDG_RUNTIME_DIR=/home/pi \ PATH=\$PATH:/usr/bin:/bin \ diff --git a/mpdev.1 b/mpdev.1 index e772bc5..f13fcdf 100644 --- a/mpdev.1 +++ b/mpdev.1 @@ -59,18 +59,13 @@ running lastfm-scrobbler and librefm-scrobbler one time. You can disable scrobbling by setting DISABLE_SCROBBLE environment variable .sp -1 .IP \[bu] -updates play counts in the sqlite stats.db and -[RompR](https://fatg3erman.github.io/RompR/) db. RompR db update gets -enabled only when you set the \fBROMPR\fR environment variable. All db -updates get disabled if you set \fBNO_DB_UPDATE\fR environment variable. +updates play counts in the sqlite stats.db. All db updates get disabled if +you set \fBNO_DB_UPDATE\fR environment variable. .sp -1 .IP \[bu] -Synchronizes the ratings in the sticker (sqlite), -[RompR](https://fatg3erman.github.io/RompR/) (MySQL) and the stats (sqlite) -databases. It also initializes the rating to 3 when you play an unrated -song. RompR db update gets enabled only when you set the \fBROMPR\fR -environment variable. All db updates get disabled if you set -\fBNO_DB_UPDATE\fR environment variable. +Synchronizes the ratings in the sticker (sqlite). It also initializes the +rating to 3 when you play an unrated song. All db updates get disabled if +you set \fBNO_DB_UPDATE\fR environment variable. .PP You can put your own script named `player` in this directory. In fact @@ -219,7 +214,6 @@ OUTPUT_2_STATE=disabled \f[B]mpdev_rename\f[](1), \f[B]mpdev_update\f[](1), \f[B]mpdplaylist\f[](1), -\f[B]romprhist\f[](1), \f[B]transfer_play\f[](1) .IP \[bu] 2 https://github.com/mbhangui/mpdev/ diff --git a/mpdev.spec.in b/mpdev.spec.in index 04491ca..f308972 100644 --- a/mpdev.spec.in +++ b/mpdev.spec.in @@ -63,7 +63,7 @@ using mpd's idle command and execs user defined script on event changes. + tracks play count of songs, artist, albums and genres. + helps chose songs based on listening habits using mpdplaylist playlist generator - + synchronizes rompr, stats and mpd's sticker db + + synchronizes stats and mpd's sticker db %prep %autosetup @@ -98,7 +98,6 @@ install -m 0644 %{name}-rpm.info %{buildroot}%{sysconfdir}/mpdev/%{name}-rpm.inf %attr(755,root,root) %{_prefix}/bin/karma %attr(755,root,root) %{_prefix}/bin/songi %attr(755,root,root) %{_prefix}/bin/mpdhist -%attr(755,root,root) %{_prefix}/bin/romprhist %attr(755,root,root) %{_prefix}/bin/transfer_play %attr(755,root,root) %{_prefix}/bin/lastfm-scrobbler %attr(755,root,root) %{_prefix}/bin/librefm-scrobbler @@ -124,7 +123,6 @@ install -m 0644 %{name}-rpm.info %{buildroot}%{sysconfdir}/mpdev/%{name}-rpm.inf %attr(644,root,root) %{_prefix}/share/man/man1/karma.1.gz %attr(644,root,root) %{_prefix}/share/man/man1/mpdhist.1.gz %attr(644,root,root) %{_prefix}/share/man/man1/transfer_play.1.gz -%attr(644,root,root) %{_prefix}/share/man/man1/romprhist.1.gz %attr(644,root,root) %{_prefix}/share/man/man1/lastfm-scrobbler.1.gz %attr(644,root,root) %{_prefix}/share/man/man1/librefm-scrobbler.1.gz diff --git a/mpdhist.1 b/mpdhist.1 index 54dee55..1553499 100644 --- a/mpdhist.1 +++ b/mpdhist.1 @@ -29,5 +29,4 @@ Known values for OPTION are: .EE .SH "SEE ALSO" -romprhist(1), mpdev(1) diff --git a/mpdhist.in b/mpdhist.in index 56cb5e2..375a2c9 100644 --- a/mpdhist.in +++ b/mpdhist.in @@ -1,6 +1,6 @@ #!/bin/sh # -# $Id: mpdhist.in,v 1.4 2022-09-26 21:15:59+05:30 Cprogrammer Exp mbhangui $ +# $Id: mpdhist.in,v 1.5 2024-03-11 16:47:12+05:30 Cprogrammer Exp mbhangui $ # usage() @@ -83,10 +83,6 @@ if [ $? -ne 0 ] ; then fi stats_dir=$(dirname $sticker_file) stats_file=$stats_dir/stats.db -if [ ! -f $HOME/.mpdev/rompr.conf ] ; then - echo "$HOME/.mpdev/rompr.conf missing" 1>&2 - exit 1 -fi stmt="" stmt="$stmt select id, title, artist, album, play_count, rating, " stmt="$stmt strftime('%d-%m-%Y %H:%M:%S', datetime(last_played, 'unixepoch', 'localtime')) " @@ -104,6 +100,9 @@ sqlite3 -header -batch -column $stats_file "$stmt" | \ # # $Log: mpdhist.in,v $ +# Revision 1.5 2024-03-11 16:47:12+05:30 Cprogrammer +# removed rompr +# # Revision 1.4 2022-09-26 21:15:59+05:30 Cprogrammer # removed debug statement # diff --git a/player.in b/player.in index 91eb59b..ac29620 100644 --- a/player.in +++ b/player.in @@ -1,7 +1,7 @@ #!/bin/bash # # -# $Id: player.in,v 1.52 2023-06-30 20:28:38+05:30 Cprogrammer Exp mbhangui $ +# $Id: player.in,v 1.53 2024-03-11 16:47:18+05:30 Cprogrammer Exp mbhangui $ # get_mpd_conf_value() { @@ -9,60 +9,6 @@ get_mpd_conf_value() sed -e 's{"{{g' } -get_TTindex() -{ - uri="$1" - if [ -n "$MYSQL_SOCKET" ] ; then - echo "SELECT TTindex FROM Tracktable WHERE Uri='$uri';" \ - | mysql -s -u "$MYSQL_USER" -p"$MYSQL_PASS" "$MYSQL_DATABASE" 2>$MPDEV_TMPDIR/mysql.err - else - echo "SELECT TTindex FROM Tracktable WHERE Uri='$uri';" \ - | mysql -s -u "$MYSQL_USER" -p"$MYSQL_PASS" -h $MYSQL_HOST "$MYSQL_DATABASE" 2>$MPDEV_TMPDIR/mysql.err - fi - if [ $? -ne 0 ] ; then - echo "ERROR: SELECT TTindex FROM Tracktable WHERE Uri='$uri';" 1>&2 - cat $MPDEV_TMPDIR/mysql.err - return 1 - fi - return 0 -} - -get_rompr_rating() -{ - if [ -n "$MYSQL_SOCKET" ] ; then - echo "SELECT Rating, UNIX_TIMESTAMP(zztimestamp) FROM Ratingtable WHERE TTindex=$1;" \ - | mysql -s -u "$MYSQL_USER" -p"$MYSQL_PASS" "$MYSQL_DATABASE" 2>$MPDEV_TMPDIR/mysql.err - else - echo "SELECT Rating, UNIX_TIMESTAMP(zztimestamp) FROM Ratingtable WHERE TTindex=$1;" \ - | mysql -s -u "$MYSQL_USER" -p"$MYSQL_PASS" -h $MYSQL_HOST "$MYSQL_DATABASE" 2>$MPDEV_TMPDIR/mysql.err - fi - if [ $? -ne 0 ] ; then - if [ -n "$MYSQL_SOCKET" ] ; then - ( - echo -n "ALTER TABLE Ratingtable ADD COLUMN zztimestamp TIMESTAMP DEFAULT " - echo -n "CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP not null;" - echo - ) | mysql -s -u "$MYSQL_USER" -p"$MYSQL_PASS" "$MYSQL_DATABASE" 2>$MPDEV_TMPDIR/mysql.err - echo "SELECT Rating, UNIX_TIMESTAMP(zztimestamp) FROM Ratingtable WHERE TTindex=$1;" \ - | mysql -s -u "$MYSQL_USER" -p"$MYSQL_PASS" "$MYSQL_DATABASE" 2>$MPDEV_TMPDIR/mysql.err - else - ( - echo -n "ALTER TABLE Ratingtable ADD COLUMN zztimestamp TIMESTAMP DEFAULT " - echo -n "CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP not null;" - echo - ) | mysql -s -u "$MYSQL_USER" -p"$MYSQL_PASS" -h $MYSQL_HOST "$MYSQL_DATABASE" 2>$MPDEV_TMPDIR/mysql.err - echo "SELECT Rating, UNIX_TIMESTAMP(zztimestamp) FROM Ratingtable WHERE TTindex=$1;" \ - | mysql -s -u "$MYSQL_USER" -p"$MYSQL_PASS" -h $MYSQL_HOST "$MYSQL_DATABASE" 2>$MPDEV_TMPDIR/mysql.err - fi - if [ $? -ne 0 ] ; then - echo "ERROR: SELECT Rating, UNIX_TIMESTAMP(zztimestamp) FROM Ratingtable WHERE TTindex=$1;" 1>&2 - cat $MPDEV_TMPDIR/mysql.err - return 1 - fi - fi - return 0 -} - get_mpd_rating() { turi=`echo $1|sed -e "s{'{''{g"` @@ -74,7 +20,7 @@ get_mpd_rating() return 0 } -get_stat_rating() +get_stats_rating() { turi=`echo $1|sed -e "s{'{''{g"` sqlite3 -noheader -batch $stats_file "SELECT rating FROM song WHERE uri='$turi';" @@ -85,7 +31,7 @@ get_stat_rating() return 0 } -get_stat_last_played() +get_stats_last_played() { turi=`echo $1|sed -e "s{'{''{g"` sqlite3 -noheader -batch $stats_file "SELECT last_played FROM song WHERE uri='$turi';" @@ -96,7 +42,7 @@ get_stat_last_played() return 0 } -get_stat_playcount() +get_stats_playcount() { turi=`echo "$1" | sed -e "s{'{''{g"` sqlite3 -noheader -batch $stats_file "SELECT play_count from song WHERE uri='$turi';" @@ -254,196 +200,6 @@ downgrade_karma() return 0 } -rompr_update_playcount() -{ - if [ -n "$NO_DB_UPDATE" ] ; then - if [ $NO_DB_UPDATE -ne 0 ] ; then - return 0 - fi - fi - turi="$1" - tm="$2" - pcount=$3 - if [ $# -eq 4 ] ; then - TTidx=$4 - else - TTidx=`get_TTindex "$turi"` - fi - if [ -n "$TTidx" ] ; then - if [ -n "$MYSQL_SOCKET" ] ; then - ( - # update Playcount only when it is not being updated by RompR - if [ -n "$pcount" ] ; then - echo -n "UPDATE Playcounttable SET Playcount=$pcount, LastPlayed=FROM_UNIXTIME($tm) " - else - echo -n "UPDATE Playcounttable SET Playcount=Playcount+1, LastPlayed=FROM_UNIXTIME($tm) " - fi - echo -n "WHERE TTindex=$TTidx AND UNIX_TIMESTAMP(LastPlayed) < $tm;" - echo - # insert when the above update returns 0 rows - echo -n "INSERT IGNORE into Playcounttable (TTindex,Playcount,Lastplayed) " - if [ -n "$pcount" ] ; then - echo -n "VALUES ($TTidx, $pcount, FROM_UNIXTIME($tm));" - else - echo -n "VALUES ($TTidx, 1, FROM_UNIXTIME($tm));" - fi - echo - ) | mysql -s -u "$MYSQL_USER" -p"$MYSQL_PASS" "$MYSQL_DATABASE" 2>$MPDEV_TMPDIR/mysql.err - else - ( - # update Playcount only when it is not being updated by RompR - if [ -n "$pcount" ] ; then - echo -n "UPDATE Playcounttable SET Playcount=$pcount, LastPlayed=FROM_UNIXTIME($tm) " - else - echo -n "UPDATE Playcounttable SET Playcount=Playcount+1, LastPlayed=FROM_UNIXTIME($tm) " - fi - echo -n "WHERE TTindex=$TTidx AND UNIX_TIMESTAMP(LastPlayed) < $tm;" - echo - # insert when the above update returns 0 rows - echo -n "INSERT IGNORE into Playcounttable (TTindex,Playcount,Lastplayed) " - if [ -n "$pcount" ] ; then - echo -n "VALUES ($TTidx, $pcount, FROM_UNIXTIME($tm));" - else - echo -n "VALUES ($TTidx, 1, FROM_UNIXTIME($tm));" - fi - echo - ) | mysql -s -u "$MYSQL_USER" -p"$MYSQL_PASS" -h $MYSQL_HOST "$MYSQL_DATABASE" 2>$MPDEV_TMPDIR/mysql.err - fi - if [ $? -ne 0 ] ; then - ( - echo "ERROR: " - if [ -n "$pcount" ] ; then - echo -n "UPDATE Playcounttable SET Playcount=$pcount, LastPlayed=FROM_UNIXTIME($tm) " - else - echo -n "UPDATE Playcounttable SET Playcount=Playcount+1, LastPlayed=FROM_UNIXTIME($tm) " - fi - echo -n "WHERE TTindex=$TTidx AND UNIX_TIMESTAMP(LastPlayed) < $tm;" - echo - echo -n "INSERT IGNORE into Playcounttable (TTindex,Playcount,Lastplayed) " - if [ -n "$pcount" ] ; then - echo -n "VALUES ($TTidx, $pcount, FROM_UNIXTIME($tm));" - else - echo -n "VALUES ($TTidx, 1, FROM_UNIXTIME($tm));" - fi - echo - ) 1>&2 - cat $MPDEV_TMPDIR/mysql.err - return 1 - fi - fi - return 0 -} - -rompr_rating_update() -{ - if [ -n "$NO_DB_UPDATE" ] ; then - if [ $NO_DB_UPDATE -ne 0 ] ; then - return 0 - fi - fi - turi=$(echo "$1" | sed s/"'"/"\\\'"/g) - tstamp="$2" - rompr_rating=`expr "$3" / 2` - if [ $# -eq 4 ] ; then - TTidx=$4 - else - TTidx=`get_TTindex "$turi"` - fi - if [ -n "$TTidx" ] ; then - if [ -n "$MYSQL_SOCKET" ] ; then - ( - echo -n "INSERT INTO Ratingtable (TTindex, Rating, zztimestamp) " - echo -n "VALUES ($TTidx, $rompr_rating, FROM_UNIXTIME($tstamp)) " - echo -n "ON DUPLICATE KEY UPDATE Rating = $rompr_rating, " - echo -n "zztimestamp=FROM_UNIXTIME($tstamp);" - echo - ) | mysql -s -u "$MYSQL_USER" -p"$MYSQL_PASS" "$MYSQL_DATABASE" 2>$MPDEV_TMPDIR/mysql.err - else - ( - echo -n "INSERT INTO Ratingtable (TTindex, Rating, zztimestamp) " - echo -n "VALUES ($TTidx, $rompr_rating, FROM_UNIXTIME($tstamp)) " - echo -n "ON DUPLICATE KEY UPDATE Rating = $rompr_rating, " - echo -n "zztimestamp=FROM_UNIXTIME($tstamp);" - echo - ) | mysql -s -u "$MYSQL_USER" -p"$MYSQL_PASS" -h $MYSQL_HOST "$MYSQL_DATABASE" 2>$MPDEV_TMPDIR/mysql.err - fi - if [ $? -ne 0 ] ; then - if [ -n "$MYSQL_SOCKET" ] ; then - ( - echo -n "ALTER TABLE Ratingtable ADD COLUMN zztimestamp TIMESTAMP DEFAULT " - echo -n "CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP not null;" - echo - ) | mysql -s -u "$MYSQL_USER" -p"$MYSQL_PASS" "$MYSQL_DATABASE" 2>$MPDEV_TMPDIR/mysql.err - else - ( - echo -n "ALTER TABLE Ratingtable ADD COLUMN zztimestamp TIMESTAMP DEFAULT " - echo -n "CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP not null;" - echo - ) | mysql -s -u "$MYSQL_USER" -p"$MYSQL_PASS" -h $MYSQL_HOST "$MYSQL_DATABASE" 2>$MPDEV_TMPDIR/mysql.err - fi - if [ $? -ne 0 ] ; then - ( - echo "ERROR: " - echo -n "INSERT INTO Ratingtable (TTindex, Rating, zztimestamp) " - echo -n "VALUES ($TTidx, $rompr_rating, FROM_UNIXTIME($tstamp)) " - echo -n "ON DUPLICATE KEY UPDATE Rating = $rompr_rating, " - echo -n "zztimestamp=FROM_UNIXTIME($tstamp);" - echo - ) 1>&2 - cat $MPDEV_TMPDIR/mysql.err - fi - if [ -n "$MYSQL_SOCKET" ] ; then - ( - echo -n "INSERT INTO Ratingtable (TTindex, Rating, zztimestamp) " - echo -n "VALUES ($TTidx, $rompr_rating, FROM_UNIXTIME($tstamp)) " - echo -n "ON DUPLICATE KEY UPDATE Rating = $rompr_rating, " - echo -n "zztimestamp=FROM_UNIXTIME($tstamp);" - echo - ) | mysql -s -u "$MYSQL_USER" -p"$MYSQL_PASS" "$MYSQL_DATABASE" 2>$MPDEV_TMPDIR/mysql.err - else - ( - echo -n "INSERT INTO Ratingtable (TTindex, Rating, zztimestamp) " - echo -n "VALUES ($TTidx, $rompr_rating, FROM_UNIXTIME($tstamp)) " - echo -n "ON DUPLICATE KEY UPDATE Rating = $rompr_rating, " - echo -n "zztimestamp=FROM_UNIXTIME($tstamp);" - echo - ) | mysql -s -u "$MYSQL_USER" -p"$MYSQL_PASS" -h $MYSQL_HOST "$MYSQL_DATABASE" 2>$MPDEV_TMPDIR/mysql.err - fi - if [ $? -ne 0 ] ; then - ( - echo "ERROR: " - echo -n "INSERT INTO Ratingtable (TTindex, Rating, zztimestamp) " - echo -n "VALUES ($TTidx, $rompr_rating, FROM_UNIXTIME($tstamp)) " - echo -n "ON DUPLICATE KEY UPDATE Rating = $rompr_rating, " - echo -n "zztimestamp=FROM_UNIXTIME($tstamp);" - echo - ) 1>&2 - cat $MPDEV_TMPDIR/mysql.err - return 1 - fi - fi - fi - return 0 -} - -get_rompr_playcount_ts() -{ - ts=$1 - if [ -n "$MYSQL_SOCKET" ] ; then - echo "SELECT Playcount,UNIX_TIMESTAMP(LastPlayed) FROM Playcounttable WHERE TTindex=$ts;" \ - | mysql -s -u "$MYSQL_USER" -p"$MYSQL_PASS" "$MYSQL_DATABASE" 2>$MPDEV_TMPDIR/mysql.err - else - echo "SELECT Playcount,UNIX_TIMESTAMP(LastPlayed) FROM Playcounttable WHERE TTindex=$ts;" \ - | mysql -s -u "$MYSQL_USER" -p"$MYSQL_PASS" -h $MYSQL_HOST "$MYSQL_DATABASE" 2>$MPDEV_TMPDIR/mysql.err - fi - if [ $? -ne 0 ] ; then - echo "ERROR: select Playcount,UNIX_TIMESTAMP(LastPlayed) FROM Playcounttable WHERE TTindex=$ts;" 1>&2 - cat $MPDEV_TMPDIR/mysql.err - return 1 - fi - return 0 -} - scrobble() { S_TITLE=$(echo $SONG_TITLE|tr \` \') @@ -505,9 +261,6 @@ update_song() if [ ! -f $MPDEV_TMPDIR/rating.$csum ] ; then if [ $sticker_enabled -eq 1 ] ; then rating=`get_mpd_rating "$uri"` - elif [ -n "$ROMPR" ] ; then - tmp=`get_rompr_rating "$uri" | awk '{print $1}'` - rating=`expr $tmp \* 2` elif [ $stats_enabled -eq 1 ] ; then rating=`get_stats_rating "$uri"` else @@ -516,7 +269,7 @@ update_song() fi fi # Do not treat current song as New Song - for i in sticker rompr stats scrobble + for i in sticker stats scrobble do if [ ! -f $MPDEV_TMPDIR/$i.$csum ] ; then if [ ! -f $MPDEV_TMPDIR/$i.$csum ] ; then @@ -529,7 +282,7 @@ update_song() done return 0 elif [ "$PLAYER_STATE" = "stop" ] ; then - for i in sticker rompr stats scrobble start_time rating pcount + for i in sticker stats scrobble start_time rating pcount do if [ -f $MPDEV_TMPDIR/$i.$csum ] ; then if [ $VERBOSE -gt 0 ] ; then @@ -548,16 +301,9 @@ update_song() if [ -f $MPDEV_TMPDIR/rating.$csum ] ; then rating=`cat $MPDEV_TMPDIR/rating.$csum` else - # you can have ratings maintained in sticker, rompr or both - # prefer the sticker value as I use cantata more than rompr - # at the moment, because I started using cantata much - # before rompr. You may alter the script if you want - # but remember this script synchronizes both values + # you can have ratings maintained in sticker or stats or both if [ $sticker_enabled -eq 1 ] ; then rating=`get_mpd_rating "$uri"` - elif [ -n "$ROMPR" ] ; then - tmp=`get_rompr_rating "$uri" | awk '{print $1}'` - rating=`expr $tmp \* 2` elif [ $stats_enabled -eq 1 ] ; then rating=`get_stats_rating "$uri"` else @@ -578,11 +324,6 @@ update_song() sticker_db_insert "$uri" "$rating" touch $MPDEV_TMPDIR/sticker.$csum fi - elif [ -n "$ROMPR" ] ; then - if [ ! -f $MPDEV_TMPDIR/rompr.$csum ] ; then - rompr_rating_update "$uri" "$START_TIME" "$rating" - touch $MPDEV_TMPDIR/rompr.$csumA - fi elif [ $stats_enabled -eq 1 ] ; then if [ ! -f $MPDEV_TMPDIR/stats.$csum ] ; then stats_db_insert "$uri" "$rating" @@ -604,11 +345,6 @@ update_song() sticker_db_update "$uri" "$rating" touch $MPDEV_TMPDIR/sticker.$csum fi - elif [ -n "$ROMPR" ] ; then - if [ ! -f $MPDEV_TMPDIR/rompr.$csum ] ; then - rompr_rating_update "$uri" "$START_TIME" "$rating" - touch $MPDEV_TMPDIR/rompr.$csum - fi elif [ $stats_enabled -eq 1 ] ; then if [ ! -f $MPDEV_TMPDIR/stats.$csum ] ; then # update rating @@ -621,7 +357,7 @@ update_song() inserted=0 fi fi - prev_last_played=$(get_stat_last_played "$uri") + prev_last_played=$(get_stats_last_played "$uri") if [ $VERBOSE -gt 0 ] ; then if [ ! -f $MPDEV_TMPDIR/rating.$csum -a " $state" = " now-playing" ] ; then if [ $gnu_date -eq 1 ] ; then @@ -632,7 +368,7 @@ update_song() echo "duration=$SONG_DURATION rating=[$rating]" if [ -n "$prev_last_played" ] ; then days_back=$(expr \( $START_TIME - $prev_last_played \) / 86400) - pcount_s=$(get_stat_playcount "$uri") + pcount_s=$(get_stats_playcount "$uri") if [ -z "$pcount_s" ] ; then pcount_s="0" fi @@ -656,16 +392,12 @@ update_song() if [ $inserted -eq 1 ] ; then if [ $sticker_enabled -eq 1 ] ; then echo "INSERT stker rating=$rating" - elif [ -n "$ROMPR" ] ; then - echo "INSERT RompR rating=$rating Start=$START_TIME" elif [ $stats_enabled -eq 1 ] ; then echo "INSERT stats rating=$rating" fi elif [ $inserted -eq 2 ] ; then if [ $sticker_enabled -eq 1 ] ; then echo "UPDATE stker rating=$rating" - elif [ -n "$ROMPR" ] ; then - echo "UPDATE RompR rating=$rating Start=$START_TIME" elif [ $stats_enabled -eq 1 ] ; then echo "UPDATE stats rating=$rating" fi @@ -692,14 +424,6 @@ update_song() fi touch $MPDEV_TMPDIR/stats.$csum fi - if [ $sticker_enabled -eq 1 -a -n "$ROMPR" -a ! -f $MPDEV_TMPDIR/rompr.$csum ] ; then - rompr_rating_update "$uri" "$START_TIME" "$rating" - if [ $VERBOSE -gt 0 -a $no_db_update -eq 0 ] ; then - tmp1=`expr "$rating" / 2` - echo "UPDATE RompR rating=$tmp1 Start=$START_TIME" - fi - touch $MPDEV_TMPDIR/rompr.$csum - fi if [ -n "$SCROBBLE_LIBREFM" -o -n "$SCROBBLE_LASTFM" ] ; then if [ ! -f $MPDEV_TMPDIR/scrobble.$csum ] ; then if [ ! " $PLAYER_STATE" = " pause" -a ! " $PLAYER_STATE" = " stop" ] ; then @@ -724,61 +448,6 @@ update_song() if [ -f $MPDEV_TMPDIR/start_time.$csum ] ; then START_TIME=`cat $MPDEV_TMPDIR/start_time.$csum` fi - if [ -n "$ROMPR" ] ; then - rompr_uri=$(echo "$uri" | sed s/"'"/"\\\'"/g) - TTindex=`get_TTindex "$rompr_uri"` - fi - # sync rating between sticker and rompr - if [ $sticker_enabled -eq 1 -a -n "$ROMPR" ] ; then - rating=`get_mpd_rating "$uri"` - if [ -f $MPDEV_TMPDIR/rating.$csum ] ; then - old_rating=`cat $MPDEV_TMPDIR/rating.$csum` - else - old_rating=`get_stat_rating $uri` - fi - if [ -z "$old_rating" ] ; then - old_rating=0 - fi - if [ -n "$TTindex" ] ; then - # we get the timestamp for the rating entry from Ratingtable - line=`get_rompr_rating $TTindex` - if [ -n "$line" ] ; then - set $line - rompr_rating=$1 - tstamp=$2 - else - rompr_rating=-1 - tstamp=-1 - fi - # - # check of rompr Rating table has newer entry. If yes update sticker and stats - # check of sticker has a rating different rating than rompr. If yes, update rompr - # - if [ -n "$line" ] && [ $tstamp -gt $START_TIME ] && [ $rompr_rating -gt 0 ] ; then - # rompr Rating table has a newer entry - tmp=`expr $rompr_rating \* 2` - if [ $tmp -ne $rating ] ; then - rating=$tmp - # update sticker with rating from rompr - sticker_db_update "$uri" $rating - if [ $VERBOSE -gt 0 -a $no_db_update -eq 0 ] ; then - echo "UPDATE stker from RompR new=$tmp old=$rating, TTindex=$TTindex, Times=old[$START_TIME], new[$tstamp]" - fi - echo $rating > $MPDEV_TMPDIR/rating.$csum - fi - elif [ $old_rating -gt 0 ] && [ $old_rating -ne $rating ] ; then # sticker table has a newer entry - # sticker table has a newer entry - echo $rating > $MPDEV_TMPDIR/rating.$csum - # update rompr with rating from sticker - rompr_rating_update "$uri" "$START_TIME" "$rating" "$TTindex" - if [ $VERBOSE -gt 0 -a $no_db_update -eq 0 ] ; then - tmp1=`expr "$rating" / 2` - tmp2=`expr "$old_rating" / 2` - echo "UPDATE RompR from stker new=$tmp1 old=$tmp2, TTindex=$TTindex, Times=old[$START_TIME], new[$START_TIME]" - fi - fi - fi - fi # Update Rating / Play Counts if [ -z "$MIN_PLAY_PERCENT" ] ; then MIN_PLAY_PERCENT=75 @@ -814,7 +483,7 @@ update_song() if [ -f $MPDEV_TMPDIR/pcount.$csum ] ; then pcount_s=$(cat $MPDEV_TMPDIR/pcount.$csum) else - pcount_s=$(get_stat_playcount "$uri") + pcount_s=$(get_stats_playcount "$uri") fi if [ -n "$pcount_s" ] ; then pcount_s=$(expr $pcount_s + 1) @@ -833,49 +502,6 @@ update_song() fi fi fi - # Update Play Counts in rompr Playcounttable - if [ -n "$ROMPR" -a $var -eq 1 -a -n "$TTindex" -a ! -f $MPDEV_TMPDIR/rompr_playcount.$csum ] ; then - if [ -n "$pcount_s" ] ; then - if [ $VERBOSE -gt 0 -a $no_db_update -eq 0 ] ; then - echo -n "UPDATE RompR Playcount Playcount=$pcount_s, TTindex=$TTindex " - if [ $gnu_date -eq 1 ] ; then - echo "[ts=$END_TIME][`date +"%Y-%m-%d %H:%M:%S" --date=@"$END_TIME"`] mpdev" - else - echo "[ts=$END_TIME][`date -r "$END_TIME" +"%Y-%m-%d %H:%M:%S"`] mpdev" - fi - fi - rompr_update_playcount "$rompr_uri" "$START_TIME" "$pcount_s" "$TTindex" - else - #hopefully update will be successfull - line=`get_rompr_playcount_ts "$TTindex"` - if [ -z "$line" ] ; then - pcount_r="1" - ts=$START_TIME - else - set $line - pcount_r=$(expr $1 + 1) - ts=$2 - fi - if [ $VERBOSE -gt 0 -a $no_db_update -eq 0 ] ; then - echo -n "UPDATE RompR Playcount Playcount=$pcount_r, TTindex=$TTindex " - if [ -n "$ts" ] && [ $ts -gt $START_TIME ] && [ $ts -lt $END_TIME ] ; then - if [ $gnu_date -eq 1 ] ; then - echo "[ts=$ts][`date +"%Y-%m-%d %H:%M:%S" --date=@"$ts"`] RompR" - else - echo "[ts=$ts][`date -r "$ts" +"%Y-%m-%d %H:%M:%S"`] RompR" - fi - else - if [ $gnu_date -eq 1 ] ; then - echo "[ts=$END_TIME][`date +"%Y-%m-%d %H:%M:%S" --date=@"$END_TIME"`] mpdev/RompR" - else - echo "[ts=$END_TIME][`date -r "$END_TIME" +"%Y-%m-%d %H:%M:%S"`] mpdev/RompR" - fi - fi - fi - rompr_update_playcount "$rompr_uri" "$START_TIME" "$pcount_r" "$TTindex" - fi - touch $MPDEV_TMPDIR/rompr_playcount.$csum - fi if [ " $state" = " end-song" ] ; then if [ $VERBOSE -gt 0 ] ; then if [ -n "$END_TIME" ] ; then @@ -890,11 +516,10 @@ update_song() fi fi /bin/rm -f $MPDEV_TMPDIR/stats.$csum $MPDEV_TMPDIR/scrobble.$csum \ - $MPDEV_TMPDIR/rompr.$csum $MPDEV_TMPDIR/sticker.$csum \ + $MPDEV_TMPDIR/sticker.$csum \ $MPDEV_TMPDIR/start_time.$csum $MPDEV_TMPDIR/rating.$csum \ - $MPDEV_TMPDIR/stats_playcount.$csum $MPDEV_TMPDIR/rompr_playcount.$csum \ - $MPDEV_TMPDIR/percent_played $MPDEV_TMPDIR/pcount.$csum $MPDEV_TMPDIR/end.$csum \ - $MPDEV_TMPDIR/mysql.err + $MPDEV_TMPDIR/stats_playcount.$csum \ + $MPDEV_TMPDIR/percent_played $MPDEV_TMPDIR/pcount.$csum $MPDEV_TMPDIR/end.$csum elif [ " $state" = " pause-song" ] ; then if [ $VERBOSE -gt 0 ] ; then if [ -n "$END_TIME" ] ; then @@ -973,6 +598,9 @@ fi exit 0 # $Log: player.in,v $ +# Revision 1.53 2024-03-11 16:47:18+05:30 Cprogrammer +# removed rompr +# # Revision 1.52 2023-06-30 20:28:38+05:30 Cprogrammer # set PLAYCOUNT env variable for lcd_display # diff --git a/romprhist.1 b/romprhist.1 deleted file mode 100644 index 21b726a..0000000 --- a/romprhist.1 +++ /dev/null @@ -1,54 +0,0 @@ -.TH romprhist 1 -.SH NAME -romprhist \- update ratings in stats,, sticker db or both from RompR player - -.SH SYNOPSYS -.B romprhist \fIoptions\fR - -.SH DESCRIPTION -romprhist displays history of songs plays since the last checkpoint. You can -create a checkpoing by using the --update-chkpoint option. With the ---update-stats or the --update-sticker option, romprhist will obtain the rating -from RompR MySQL database and update the value in stats.db or sticker.db database -used my mpdev(1), mpdplaylist(1). - -\fBromprhist\fR is no longer needed for updating stats.db or sticker.db if you are -running mpdev(1). - -.SH OPTIONS -.TP 3 -.B --verbose -Set verbose output. You can increase verbosity by specifying it multiple times -.RS -.RE - -.TP 3 -.B --sql -generate sql statements in /tmp/stats.sql, /tmp/sticker.sql -.RS -.RE - -.TP 3 -.B --update-chkpoint -reset checkpoint -.RS -.RE - -.TP 3 -.B --update-stats -updates stats sqlite db -.RS -.RE - -.TP 3 -.B --update-sticker -updates sticker sqlite db -.RS -.RE - - -.SH SEE ALSO -mpdev(1), -mpdplaylist(1), -mpd(1), -mpd.conf(5) diff --git a/romprhist.in b/romprhist.in deleted file mode 100644 index 44e704e..0000000 --- a/romprhist.in +++ /dev/null @@ -1,257 +0,0 @@ -#!/bin/sh -# -# $Log: romprhist.in,v $ -# Revision 1.8 2022-06-20 01:07:05+05:30 Cprogrammer -# use directories set in ./configure -# -# Revision 1.7 2021-04-11 15:00:46+05:30 Cprogrammer -# refactored code -# -# Revision 1.6 2020-08-30 11:35:06+05:30 Cprogrammer -# fixed stats.db path -# -# Revision 1.5 2020-07-22 15:51:43+05:30 Cprogrammer -# removed unused function -# -# Revision 1.4 2020-07-21 15:36:14+05:30 Cprogrammer -# renamed Rate field to Starts -# -# Revision 1.3 2020-07-21 12:33:29+05:30 Cprogrammer -# fixed minor formatting issue with output -# -# Revision 1.2 2020-07-20 22:15:18+05:30 Cprogrammer -# warn if rompr.conf is missing -# -# Revision 1.1 2020-07-20 21:45:03+05:30 Cprogrammer -# Initial revision -# -# -# utility to update -# -# $Id: romprhist.in,v 1.8 2022-06-20 01:07:05+05:30 Cprogrammer Exp mbhangui $ -# -usage() -{ - ( - echo "rompr: incorrect usage" - echo "USAGE: romprhist [--update-stats] [--update-sticker] [--sql] [--update-checkpoint]" - echo "options" - echo " --update-stats - updates stats sqlite db" - echo " --update-sticker - updates sticker sqlite db" - echo " --update-chkpoint - reset checkpoint" - echo " --sql - generate sql statements in /tmp/stats.sql, /tmp/sticker.sql" - ) 1>&2 - exit 1 -} - -get_mpd_conf_value() -{ - grep "^$1" @sysconfdir@/mpd.conf|awk '{print $2}' | \ - sed -e 's{"{{g' -} - -init_rompr() -{ - ( - echo -n "CREATE TABLE IF NOT EXISTS ratingchkpoint " - echo -n "(id INT NOT NULL PRIMARY KEY, zztimestamp INT NOT NULL);" - echo -n "INSERT INTO ratingchkpoint (id,zztimestamp) values (1, UNIX_TIMESTAMP(now()))" - echo -n " ON DUPLICATE KEY UPDATE zztimestamp=UNIX_TIMESTAMP(now());" - echo - echo -n "ALTER TABLE Ratingtable ADD COLUMN zztimestamp TIMESTAMP DEFAULT " - echo -n "CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP not null;" - echo - ) | mysql -s -u $MYSQL_USER -p$MYSQL_PASS -h $MYSQL_HOST $MYSQL_DATABASE 2>/dev/null - if [ $? -ne 0 ] ; then - exit 1 - fi -} - -chk_ratingchkpoint() -{ - echo "SELECT COUNT(*) from ratingchkpoint;" | mysql -s -u $MYSQL_USER -p$MYSQL_PASS -h $MYSQL_HOST $MYSQL_DATABASE > /dev/null 2>&1 - if [ $? -ne 0 ] ; then - echo "initializing" - init_rompr - fi -} - -update_chkpoint() -{ - ( - if [ $# -eq 1 ] ; then - echo -n "INSERT INTO ratingchkpoint (id, zztimestamp) VALUES (1, $1)" - echo " ON DUPLICATE KEY UPDATE zztimestamp=$1;" - else - echo -n "INSERT INTO ratingchkpoint (id, zztimestamp) VALUES (1, UNIX_TIMESTAMP(now()))" - echo " ON DUPLICATE KEY UPDATE zztimestamp=UNIX_TIMESTAMP(now());" - fi - ) | mysql -s -u $MYSQL_USER -p$MYSQL_PASS -h $MYSQL_HOST $MYSQL_DATABASE 2>/dev/null - if [ $? -ne 0 ] ; then - ( - if [ $# -eq 1 ] ; then - echo -n "ERROR1: INSERT INTO ratingchkpoint (id, zztimestamp) VALUES (1, $1)" - echo " ON DUPLICATE KEY UPDATE zztimestamp=$1;" - else - echo -n "ERROR2: INSERT INTO ratingchkpoint (id, zztimestamp) VALUES (1, now())" - echo " ON DUPLICATE KEY UPDATE zztimestamp=UNIX_TIMESTAMP(now());" - fi - ) 1>&2 - fi -} - -get_rompr() -{ - ( - echo "SELECT r.TTindex, p.Lastplayed, p.Playcount, r.Rating, t.Uri FROM Ratingtable r, Tracktable t, Playcounttable p, " - echo " ratingchkpoint u WHERE r.TTindex = t.TTindex and p.TTindex = t.TTindex AND UNIX_TIMESTAMP(r.zztimestamp) > u.zztimestamp" - echo " ORDER BY r.zztimestamp asc;" - ) | mysql -s -u $MYSQL_USER -p$MYSQL_PASS -h $MYSQL_HOST $MYSQL_DATABASE 2>/dev/null - if [ $? -ne 0 ] ; then - ( - echo "SELECT r.TTindex, r.Rating, t.Uri from Ratingtable r, Tracktable t," - echo " ratingchkpoint u WHERE r.TTindex = t.TTindex AND UNIX_TIMESTAMP(r.zztimestamp) > u.zztimestamp" - echo " ORDER BY r.zztimestamp asc;" - ) 1>&2 - fi -} - -update_stats() -{ - uri=`echo "$1" | sed -e "s{'{''{g"` - if [ $sql_mode -eq 1 ] ; then - echo "UPDATE song SET rating=$2 WHERE uri='$uri';" - else - echo "UPDATE song SET rating=$2 WHERE uri='$uri';" | sqlite3 $stats_file - if [ $? -ne 0 ] ; then - echo "error: UPDATE song SET rating=$2 WHERE uri='$uri';" 1>&2 - return 1 - fi - fi -} - -update_sticker() -{ - uri=`echo "$1" | sed -e "s{'{''{g"` - if [ $sql_mode -eq 1 ] ; then - echo "UPDATE sticker SET value=$2 WHERE uri='$uri';" - else - echo "UPDATE sticker SET value=$2 WHERE uri='$uri';" | sqlite3 $sticker_file - if [ $? -ne 0 ] ; then - echo "UPDATE sticker SET value=$2 WHERE uri='$uri';" 1>&2 - return 1 - fi - fi -} - -music_dir=`get_mpd_conf_value music_directory` -if [ $? -ne 0 ] ; then - echo "could not get music directory from mpd.conf" 1>&2 - exit 1 -fi -sticker_file=`get_mpd_conf_value sticker_file` -if [ $? -ne 0 ] ; then - echo "could not get sticker database from mpd.conf" 1>&2 - exit 1 -fi -stats_dir=$(dirname $sticker_file) -stats_file=$stats_dir/stats.db -if [ ! -f $HOME/.mpdev/rompr.conf ] ; then - echo "$HOME/.mpdev/rompr.conf missing" 1>&2 - exit 1 -fi -MYSQL_HOST=`grep MYSQL_HOST $HOME/.mpdev/rompr.conf |awk '{print $2}'` -MYSQL_USER=`grep MYSQL_USER $HOME/.mpdev/rompr.conf |awk '{print $2}'` -MYSQL_PASS=`grep MYSQL_PASS $HOME/.mpdev/rompr.conf |awk '{print $2}'` -MYSQL_DATABASE=`grep MYSQL_DATABASE $HOME/.mpdev/rompr.conf |awk '{print $2}'` - -update_stats_table=0 -update_sticker_table=0 -sql_mode=0 -chkpoint=0 -verbose=0 -while test $# -gt 0; do - case "$1" in - -*=*) - optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` - optval=`echo "$1" | cut -d'=' -f1` - ;; - *) - optarg= - ;; - esac - - case "$1" in - --sql) - sql_mode=1 - ;; - --update-stats) - update_stats_table=1 - sql_mode=1 - ;; - --update-sticker) - update_sticker_table=1 - sql_mode=1 - ;; - --update-chkpoint) - chkpoint=1 - ;; - --verbose) - verbose=1 - ;; - *) - usage - ;; - esac - shift -done - -if [ $update_stats_table -eq 0 -a $update_sticker_table -eq 0 ] ; then - verbose=1 -fi - -chk_ratingchkpoint -if [ $sql_mode -eq 1 ] ; then - if [ $update_stats_table -eq 1 ] ; then - /bin/rm -f /tmp/stats.sql - fi - if [ $update_sticker_table -eq 1 ] ; then - /bin/rm -f /tmp/sticker.sql - fi -fi -status1=1 -status2=1 -printf "%-6s %-19s %s %s %s\n" "Index" "End Time" "Count" "Stars" "Filename" -get_rompr | while read line -do - set $line - TTindex=$1 - pdate=$2 - ptime=$3 - pcount=$4 - rating=$5 - shift 5 - uri="$*" - if [ $verbose -eq 1 ] ; then - printf "%06d %s %s %02d %d %s\n" $TTindex $pdate $ptime $pcount $rating "$uri" - fi - rating=`expr $rating \* 2` - if [ $sql_mode -eq 1 ] ; then - update_stats "$uri" $rating >> /tmp/stats.sql - status1=$? - update_sticker "$uri" $rating >> /tmp/sticker.sql - status2=$? - fi - if [ $chkpoint -eq 1 -a $status1 -eq 0 -a $status2 -eq 0 ] ; then - update_chkpoint $tmval - fi -done -if [ $update_stats_table -eq 1 ] ; then - sqlite3 $stats_file < /tmp/stats.sql -fi -if [ $update_sticker_table -eq 1 ] ; then - sqlite3 $sticker_file < /tmp/sticker.sql -fi -if [ $chkpoint -eq 1 ] ; then - update_chkpoint -fi