-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.in
766 lines (752 loc) · 22.7 KB
/
player.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
#!/bin/bash
#
#
# $Id: player.in,v 1.54 2024-12-23 19:08:35+05:30 Cprogrammer Exp mbhangui $
#
get_mpd_conf_value()
{
grep "^$1" @sysconfdir@/mpd.conf|awk '{print $2}' | \
sed -e 's{"{{g'
}
get_mpd_rating()
{
turi=`echo $1|sed -e "s{'{''{g"`
sqlite3 -noheader -batch $sticker_file "SELECT value FROM sticker WHERE type='song' AND uri='$turi';"
if [ $? -ne 0 ] ; then
echo "ERROR: SELECT value FROM sticker WHERE type='song' AND uri=\"$turi\";" 1>&2
return 1
fi
return 0
}
get_stats_rating()
{
turi=`echo $1|sed -e "s{'{''{g"`
sqlite3 -noheader -batch $stats_file "SELECT rating FROM song WHERE uri='$turi';"
if [ $? -ne 0 ] ; then
echo "ERROR: SELECT rating FROM song WHERE uri='$turi';" 1>&2
return 1
fi
return 0
}
get_stats_last_played()
{
turi=`echo $1|sed -e "s{'{''{g"`
sqlite3 -noheader -batch $stats_file "SELECT last_played FROM song WHERE uri='$turi';"
if [ $? -ne 0 ] ; then
echo "ERROR: SELECT last_played FROM song WHERE uri='$turi';" 1>&2
return 1
fi
return 0
}
get_stats_playcount()
{
turi=`echo "$1" | sed -e "s{'{''{g"`
sqlite3 -noheader -batch $stats_file "SELECT play_count from song WHERE uri='$turi';"
if [ $? -ne 0 ] ; then
echo "ERROR: SELECT play_count from song WHERE uri='$turi';" 1>&2
return 1
fi
return 0
}
sticker_db_insert()
{
if [ -n "$NO_DB_UPDATE" ] ; then
if [ $NO_DB_UPDATE -ne 0 ] ; then
return 0
fi
fi
turi=`echo $1|sed -e "s{'{''{g"`
tmprate=$2
sqlite3 -batch $sticker_file "INSERT or IGNORE into sticker \
(type, uri, name, value) values ('song', '$turi', 'rating', $tmprate);"
if [ $? -ne 0 ] ; then
echo "ERROR: INSERT or IGNORE into sticker (type, uri, name, value) into sticker values ('song', '$turi', 'rating', $tmprate);" 1>&2
return 1
fi
return 0
}
sticker_db_update()
{
if [ -n "$NO_DB_UPDATE" ] ; then
if [ $NO_DB_UPDATE -ne 0 ] ; then
return 0
fi
fi
turi=`echo $1|sed -e "s{'{''{g"`
tmprate=$2
sqlite3 -batch $sticker_file "UPDATE sticker SET value=$tmprate WHERE type='song' AND uri='$turi';"
if [ $? -ne 0 ] ; then
echo "ERROR: UPDATE sticker SET value=$tmprate WHERE type='song' AND uri='$turi';" 1>&2
return 1
fi
}
stats_db_insert()
{
# SONG_LAST_MODIFIED: last_modified
# SONG_ALBUM: album
# SONG_ARTIST: artist
# SONG_DATE: date
# SONG_GENRE: genre
# SONG_TITLE: title
# SONG_TRACK: track
# SONG_DURATION: duration
if [ -n "$NO_DB_UPDATE" ] ; then
if [ $NO_DB_UPDATE -ne 0 ] ; then
return 0
fi
fi
turi=`echo "$1" | sed -e "s{'{''{g"`
ARTIST=`echo "$SONG_ARTIST" | sed -e "s{'{''{g"`
ALBUM=`echo "$SONG_ALBUM" | sed -e "s{'{''{g"`
TITLE=`echo "$SONG_TITLE" | sed -e "s{'{''{g"`
tmprate=$2
sqlite3 -batch $stats_file "INSERT or IGNORE into \
song (uri, play_count, last_played, rating, duration,last_modified,artist,album,title,track,genre,date) \
values ('$turi',0,0,$tmprate,$SONG_DURATION,$SONG_LAST_MODIFIED,'$ARTIST','$ALBUM','$TITLE','$SONG_TRACK','$SONG_GENRE','$SONG_DATE');"
if [ $? -ne 0 ] ; then
(
echo -n "INSERT or IGNORE into song "
echo -n "(uri, play_count, last_played, rating, duration,"
echo -n "last_modified,artist,album,title,track,genre,date)"
echo -n "values ('$turi',0,0,$tmprate,$SONG_DURATION,"
echo -n "$SONG_LAST_MODIFIED,'$ARTIST','$ALBUM','$TITLE',"
echo -n "'$SONG_TRACK','$SONG_GENRE','$SONG_DATE');"
echo
) 1>&2
return 1
fi
return 0
}
stats_db_update()
{
if [ -n "$NO_DB_UPDATE" ] ; then
if [ $NO_DB_UPDATE -ne 0 ] ; then
return 0
fi
fi
turi=`echo "$1" | sed -e "s{'{''{g"`
tmprate=$2
last_played=$3
update_playcount=$4
if [ $update_playcount -eq 1 ] ; then
if [ -n "$prev_last_played" ] ; then
days_back=$(expr \( $last_played - $prev_last_played \) / 86400)
if [ $days_back -lt 1 ] ; then
kval=4
elif [ $days_back -lt 7 ] ; then
kval=3
elif [ $days_back -lt 14 ] ; then
kval=2
elif [ $days_back -lt 28 ] ; then
kval=1
else
kval=0
fi
else
kval=0
fi
if [ $kval -gt 0 ] ; then
if [ $VERBOSE -gt 0 ] ; then
echo "UPDATE stats upgrade KARMA += $kval"
fi
sqlite3 -batch $stats_file \
"UPDATE song SET last_played=$last_played, play_count=play_count+1, rating=$tmprate, karma=karma+$kval WHERE uri='$turi';"
else
sqlite3 -batch $stats_file \
"UPDATE song SET last_played=$last_played, play_count=play_count+1, rating=$tmprate WHERE uri='$turi';"
fi
else
sqlite3 -batch $stats_file \
"UPDATE song SET last_played=$last_played, rating=$tmprate WHERE uri='$turi';"
fi
if [ $? -ne 0 ] ; then
if [ $update_playcount -eq 1 ] ; then
if [ $kval -gt 0 ] ; then
echo "ERROR: UPDATE song SET last_played=$last_played, play_count=play_count+1, rating=$tmprate, karma=karma+$kval WHERE uri='$turi';"
else
echo "ERROR: UPDATE song SET last_played=$last_played, play_count=play_count+1, rating=$tmprate WHERE uri='$turi';" 1>&2
fi
else
echo "ERROR: UPDATE song SET last_played=$last_played, rating=$tmprate WHERE uri='$turi';" 1>&2
fi
return 1
fi
return 0
}
downgrade_karma()
{
if [ -n "$NO_DB_UPDATE" ] ; then
if [ $NO_DB_UPDATE -ne 0 ] ; then
return 0
fi
fi
turi=`echo "$1" | sed -e "s{'{''{g"`
sqlite3 -batch $stats_file \
"UPDATE song SET karma=karma-1 WHERE uri='$turi' AND karma>0 AND karma<60 AND rating<6 AND play_count<=5;"
if [ $? -ne 0 ] ; then
"ERROR: UPDATE song SET karma=karma-1 WHERE uri='$turi' AND karma>0 AND karma<60 AND rating<6 AND play_count<=5;" 1>&2
return 1
fi
return 0
}
scrobble()
{
S_TITLE=$(echo $SONG_TITLE|tr \` \')
S_ARTIST=$(echo $SONG_ARTIST|tr \` \')
S_ALBUM=$(echo $SONG_ALBUM|tr \` \')
if [ -n "$SCROBBLE_LASTFM" ] ; then
if [ $VERBOSE -eq 1 ] ; then
echo lastfm-scrobbler --update --artist=\""$S_ARTIST"\" --album=\""$S_ALBUM"\" --track=\""$S_TITLE"\" --duration=\""$SONG_DURATION"\"
fi
if [ $VERBOSE -eq 0 -o $VERBOSE -eq 1 ] ; then
lastfm-scrobbler --update --artist="$S_ARTIST" \
--album="$S_ALBUM" --track="$S_TITLE" \
--duration="$SONG_DURATION" > /dev/null
else
lastfm-scrobbler --update --artist="$S_ARTIST" \
--album="$S_ALBUM" --track="$S_TITLE" \
--duration="$SONG_DURATION"
fi
fi
if [ -n "$SCROBBLE_LIBREFM" ] ; then
if [ $VERBOSE -eq 1 ] ; then
echo librefm-scrobbler --update --artist=\""$S_ARTIST"\" --album=\""$S_ALBUM"\" --track=\""$S_TITLE"\" --duration=\""$SONG_DURATION"\"
fi
if [ $VERBOSE -eq 0 -o $VERBOSE -eq 1 ] ; then
librefm-scrobbler --update --artist="$S_ARTIST" \
--album="$S_ALBUM" --track="$S_TITLE" \
--duration="$SONG_DURATION" > /dev/null
else
librefm-scrobbler --update --artist="$S_ARTIST" \
--album="$S_ALBUM" --track="$S_TITLE" \
--duration="$SONG_DURATION"
fi
fi
}
update_song()
{
state="$1"
uri="$2"
echo $uri|grep -E "^http:|^https:" > /dev/null
no_db_update=0
csum=`echo "$uri"|cksum|awk '{print $1}'`
if [ -n "$NO_DB_UPDATE" ] ; then
if [ $NO_DB_UPDATE -ne 0 ] ; then
no_db_update=1
fi
fi
if [ "$state" = "now-playing" ] ; then
if [ -f $MPDEV_TMPDIR/start_time.$csum ] ; then
START_TIME=`cat $MPDEV_TMPDIR/start_time.$csum`
fi
# This is set by mpdev when setting initial_state
# With the help pf PLAYER_STATE we know the state that
# the player was in when mpdev was started
# If the song was already playing, we should create
# files related to the song in MPDEV_TMPDIR. If not,
# we should delete files related to the song.
if [ "$PLAYER_STATE" = "pause" ] ; then
if [ ! -f $MPDEV_TMPDIR/rating.$csum ] ; then
if [ $sticker_enabled -eq 1 ] ; then
rating=`get_mpd_rating "$uri"`
elif [ $stats_enabled -eq 1 ] ; then
rating=`get_stats_rating "$uri"`
else
echo "Nothing to do"
exit 0
fi
fi
# Do not treat current song as New Song
for i in sticker stats scrobble
do
if [ ! -f $MPDEV_TMPDIR/$i.$csum ] ; then
if [ ! -f $MPDEV_TMPDIR/$i.$csum ] ; then
if [ $VERBOSE -gt 0 ] ; then
echo "creating $MPDEV_TMPDIR/$i.$csum"
fi
touch $MPDEV_TMPDIR/$i.$csum
fi
fi
done
return 0
elif [ "$PLAYER_STATE" = "stop" ] ; then
for i in sticker stats scrobble start_time rating pcount
do
if [ -f $MPDEV_TMPDIR/$i.$csum ] ; then
if [ $VERBOSE -gt 0 ] ; then
echo "removing $MPDEV_TMPDIR/$i.$csum"
fi
/bin/rm -f $MPDEV_TMPDIR/$i.$csum
fi
done
return 0
fi
fi
inserted=0
# presence of rating.$csum indicates that
# the script was run when a song started
# we are being called again
if [ -f $MPDEV_TMPDIR/rating.$csum ] ; then
rating=`cat $MPDEV_TMPDIR/rating.$csum`
else
# you can have ratings maintained in sticker or stats or both
if [ $sticker_enabled -eq 1 ] ; then
rating=`get_mpd_rating "$uri"`
elif [ $stats_enabled -eq 1 ] ; then
rating=`get_stats_rating "$uri"`
else
echo "Nothing to do"
exit 0
fi
if [ -z "$rating" ] ; then
if [ -f $HOME/.mpdev/AUTO_RATING ] ; then
rating=`cat $HOME/.mpdev/AUTO_RATING`
elif [ -n "$AUTO_RATING" ] ; then
rating=$AUTO_RATING # assign average rating of 3 for unrated music
else
rating=0
fi
inserted=1
if [ $sticker_enabled -eq 1 ] ; then
if [ ! -f $MPDEV_TMPDIR/sticker.$csum ] ; then
sticker_db_insert "$uri" "$rating"
touch $MPDEV_TMPDIR/sticker.$csum
fi
elif [ $stats_enabled -eq 1 ] ; then
if [ ! -f $MPDEV_TMPDIR/stats.$csum ] ; then
stats_db_insert "$uri" "$rating"
touch $MPDEV_TMPDIR/stats.$csum
fi
fi
elif [ $rating -eq 0 ] ; then
if [ -f $HOME/.mpdev/AUTO_RATING ] ; then
rating=`cat $HOME/.mpdev/AUTO_RATING`
elif [ -n "$AUTO_RATING" ] ; then
rating=$AUTO_RATING # assign default rating as per value of AUTO_RATING
else
rating=0
fi
if [ $rating -gt 0 ] ; then
inserted=2
if [ $sticker_enabled -eq 1 ] ; then
if [ ! -f $MPDEV_TMPDIR/sticker.$csum ] ; then
sticker_db_update "$uri" "$rating"
touch $MPDEV_TMPDIR/sticker.$csum
fi
elif [ $stats_enabled -eq 1 ] ; then
if [ ! -f $MPDEV_TMPDIR/stats.$csum ] ; then
# update rating
stats_db_update "$uri" "$rating" "$START_TIME" 0
touch $MPDEV_TMPDIR/stats.$csum
fi
fi
fi
else
inserted=0
fi
fi
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
echo -n "NewSong [$csum] Start=$START_TIME [`date +"%Y-%m-%d %H:%M:%S" --date=@"$START_TIME"`] "
else
echo -n "NewSong [$csum] Start=$START_TIME [`date -r "$START_TIME" +"%Y-%m-%d %H:%M:%S"`] "
fi
echo "duration=$SONG_DURATION rating=[$rating]"
if [ -n "$prev_last_played" ] ; then
days_back=$(expr \( $START_TIME - $prev_last_played \) / 86400)
pcount_s=$(get_stats_playcount "$uri")
if [ -z "$pcount_s" ] ; then
pcount_s="0"
fi
if [ $gnu_date -eq 1 ] ; then
echo -n " LAST PLAYED=$days_back days back [`date +"%Y-%m-%d %H:%M:%S" --date=@"$prev_last_played"`] Plays: $pcount_s"
else
echo -n " LAST PLAYED=$days_back days back [`date -r "$prev_last_played" +"%Y-%m-%d %H:%M:%S"`] Plays: $pcount_s"
fi
else
pcount_s=0
echo -n " LAST PLAYED=never Plays: $pcount_s"
fi
if [ -n "$SONG_PLAYED_DURATION" ] ; then
echo ", song pos=$SONG_PLAYED_DURATION"
else
echo ""
fi
echo $pcount_s > $MPDEV_TMPDIR/pcount.$csum
echo "uri=[$uri]"
if [ $no_db_update -eq 0 ] ; then
if [ $inserted -eq 1 ] ; then
if [ $sticker_enabled -eq 1 ] ; then
echo "INSERT stker rating=$rating"
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 [ $stats_enabled -eq 1 ] ; then
echo "UPDATE stats rating=$rating"
fi
fi
fi
fi
fi
if [ ! "$state" = "end-song" -a ! -f $MPDEV_TMPDIR/rating.$csum ] ; then
echo $rating > $MPDEV_TMPDIR/rating.$csum
fi
case "$state" in
"now-playing")
if [ ! -f $MPDEV_TMPDIR/start_time.$csum ] ; then
if [ -n "$START_TIME" ] ; then
echo $START_TIME > $MPDEV_TMPDIR/start_time.$csum
fi
else
START_TIME=`cat $MPDEV_TMPDIR/start_time.$csum`
fi
if [ $stats_enabled -eq 1 -a ! -f $MPDEV_TMPDIR/stats.$csum ] ; then
stats_db_insert "$uri" "$rating"
if [ $VERBOSE -gt 0 -a $no_db_update -eq 0 ] ; then
echo "INSERT stats rating=$rating Start=$START_TIME"
fi
touch $MPDEV_TMPDIR/stats.$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
scrobble
touch $MPDEV_TMPDIR/scrobble.$csum
fi
fi
fi
;;
"end-song"|"pause-song")
if [ "$state" = "end-song" ] ; then
if [ -z "$END_TIME" ] ; then
exit 0
fi
if [ -f $MPDEV_TMPDIR/end.$csum ] ; then
/bin/rm -f $MPDEV_TMPDIR/end.$csum
exit 0
else
touch $MPDEV_TMPDIR/end.$csum
fi
fi
if [ -f $MPDEV_TMPDIR/start_time.$csum ] ; then
START_TIME=`cat $MPDEV_TMPDIR/start_time.$csum`
fi
# Update Rating / Play Counts
if [ -z "$MIN_PLAY_PERCENT" ] ; then
MIN_PLAY_PERCENT=75
fi
if [ -n "$SONG_PLAYED_DURATION" ] ; then
percent=$(awk "BEGIN { pc=100*${SONG_PLAYED_DURATION}/${SONG_DURATION}; i=int(pc); print (pc-i<0.5)?i:i+1 }")
if [ "$percent" = "0.0" ] ; then
percent=0
fi
var=$(awk 'BEGIN {print ('$percent\>=$MIN_PLAY_PERCENT')}')
else
var=0
fi
if [ $stats_enabled -eq 1 ] ; then
# update rating + playcount
if [ -f $MPDEV_TMPDIR/stats_playcount.$csum ] ; then
stats_db_update "$uri" "$rating" "$START_TIME" 0
if [ $VERBOSE -gt 0 -a $no_db_update -eq 0 ] ; then
echo "UPDATE stats Start=$START_TIME End=$END_TIME rating=[$rating]"
fi
else
if [ -n "$SONG_PLAYED_DURATION" ] ; then
if [ $var -eq 0 ] ; then
if [ "$state" = "end-song" ] ; then
downgrade_karma "$uri"
fi
echo "SONG [$csum] "$percent"% played duration=$SONG_PLAYED_DURATION secs (partial)"
else
echo "SONG [$csum] "$percent"% played duration=$SONG_PLAYED_DURATION secs (full)"
fi
fi
if [ $var -eq 1 ] ; then
if [ -f $MPDEV_TMPDIR/pcount.$csum ] ; then
pcount_s=$(cat $MPDEV_TMPDIR/pcount.$csum)
else
pcount_s=$(get_stats_playcount "$uri")
fi
if [ -n "$pcount_s" ] ; then
pcount_s=$(expr $pcount_s + 1)
fi
if [ $VERBOSE -gt 0 -a $no_db_update -eq 0 ] ; then
if [ -z "$pcount_s" ] ; then
echo "UPDATE stats Playcount rating=[$rating] Start=$START_TIME End=$END_TIME"
else
echo "UPDATE stats Playcount Playcount=$pcount_s, rating=[$rating] Start=$START_TIME End=$END_TIME"
fi
fi
stats_db_update "$uri" "$rating" "$START_TIME" 1
touch $MPDEV_TMPDIR/stats_playcount.$csum
else
pcount_s=""
fi
fi
fi
if [ "$state" = "end-song" ] ; then
if [ $VERBOSE -gt 0 ] ; then
if [ -n "$END_TIME" ] ; then
if [ $gnu_date -eq 1 ] ; then
echo -n "EndSong [$csum] Start=$START_TIME [`date +"%Y-%m-%d %H:%M:%S" --date=@"$START_TIME"`] "
echo "End=$END_TIME [`date +"%Y-%m-%d %H:%M:%S" --date=@"$END_TIME"`]"
else
echo -n "EndSong [$csum] Start=$START_TIME [`date -r "$START_TIME" +"%Y-%m-%d %H:%M:%S"`] "
echo "End=$END_TIME [`date -r "$END_TIME" +"%Y-%m-%d %H:%M:%S"`]"
fi
echo
fi
fi
/bin/rm -f $MPDEV_TMPDIR/stats.$csum $MPDEV_TMPDIR/scrobble.$csum \
$MPDEV_TMPDIR/sticker.$csum \
$MPDEV_TMPDIR/start_time.$csum $MPDEV_TMPDIR/rating.$csum \
$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
if [ $gnu_date -eq 1 ] ; then
echo -n "PauseSong [$csum] Start=$START_TIME [`date +"%Y-%m-%d %H:%M:%S" --date=@"$START_TIME"`] "
echo "End=$END_TIME [`date +"%Y-%m-%d %H:%M:%S" --date=@"$END_TIME"`]"
else
echo -n "PauseSong [$csum] Start=$START_TIME [`date -r "$START_TIME" +"%Y-%m-%d %H:%M:%S"`] "
echo "End=$END_TIME [`date -r "$END_TIME" +"%Y-%m-%d %H:%M:%S"`]"
fi
fi
fi
fi
;; # end-song|pause-song
esac
}
if [ -z "$VERBOSE" ] ; then
VERBOSE=0
fi
SYSTEM=$(uname -s)
case "$SYSTEM" in
Linux)
gnu_date=1
;;
*)
gnu_date=0
;;
esac
# we don't handle stream uri currently
echo $SONG_URI|grep -E "^http:|^https:" > /dev/null
if [ $? -eq 0 ] ; then
echo "Streaming $SONG_URI"
exit 0
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
sticker_enabled=0
else
if [ -f $sticker_file ] ; then
sticker_enabled=1
else
sticker_enabled=0
fi
fi
stats_dir=$(dirname $sticker_file)
stats_file=$stats_dir/stats.db
if [ -f $stats_file ] ; then
stats_enabled=1
else
stats_enabled=0
fi
if [ -z "$MPDEV_TMPDIR" ] ; then
MPDEV_TMPDIR=/tmp/mpdev
fi
mkdir -p $MPDEV_TMPDIR
if [ $VERBOSE -eq 2 ] ; then
env > $MPDEV_TMPDIR/.env.log
fi
update_song "$1" "$SONG_URI"
if ( test -n "$LCD_HOST" && test -n "$LCD_PORT" ) || ( test -n "$LCD_FIFO" ) ; then
if [ -z "$pcount_s" ] ; then
pcount_s=0
fi
if [ -x $HOME/.mpdev/lcd_display ] ; then
env RATING=$rating PLAYCOUNT=$pcount_s $HOME/.mpdev/lcd_display "$1"
elif [ -x @libexecdir@/mpdev/lcd_display ] ; then
env RATING=$rating PLAYCOUNT=$pcount_s @libexecdir@/mpdev/lcd_display "$1"
fi
fi
exit 0
# $Log: player.in,v $
# Revision 1.54 2024-12-23 19:08:35+05:30 Cprogrammer
# do now downgrade karma on pause-song
#
# 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
#
# Revision 1.51 2023-06-30 10:17:29+05:30 Cprogrammer
# added use of fifo for accessing LCD display
#
# Revision 1.50 2023-06-29 10:36:28+05:30 Cprogrammer
# use $HOME/.mpdev/lcd_display or libexec/mpdev/lcd_display
#
# Revision 1.49 2023-06-26 23:18:17+05:30 Cprogrammer
# set song rating as env variable for lcd_display
#
# Revision 1.48 2023-06-25 11:18:38+05:30 Cprogrammer
# run lcd_display script
#
# Revision 1.47 2022-06-26 23:15:35+05:30 Cprogrammer
# use variables from ./configure
#
# Revision 1.46 2022-01-17 19:09:28+05:30 Cprogrammer
# fixed scrobbling getting skipped
#
# Revision 1.45 2022-01-16 22:30:28+05:30 Cprogrammer
# scrobble only when PLAYER_STATE is play
#
# Revision 1.44 2021-11-18 23:50:09+05:30 Cprogrammer
# display mysql error
#
# Revision 1.43 2021-10-10 21:59:30+05:30 Cprogrammer
# fixed non-skipping of db update for streams
#
# Revision 1.42 2021-09-30 20:31:49+05:30 Cprogrammer
# use -noheader option to prevent .sqlitrc settings messing with results
#
# Revision 1.41 2021-09-28 16:23:39+05:30 Cprogrammer
# fix INSERT statement for extra (last_modified) field added to sticker table
# skip db_update for streams
#
# Revision 1.40 2021-09-16 22:17:40+05:30 Cprogrammer
# sanitize shell input for scrobble
#
# Revision 1.39 2021-09-16 21:03:02+05:30 Cprogrammer
# disable UPDATE/INSERT echo statements when NO_DB_UPDATE is set
#
# Revision 1.38 2021-09-08 15:06:28+05:30 Cprogrammer
# rating shouldn't be created on end-song
#
# Revision 1.37 2021-04-26 20:56:27+05:30 Cprogrammer
# skip RompR playcount update when song is not fully heard
#
# Revision 1.36 2021-04-26 09:24:13+05:30 Cprogrammer
# display initial song position in NewSong
#
# Revision 1.35 2021-04-25 20:27:54+05:30 Cprogrammer
# fixed value of play counts in logs and RompR update
#
# Revision 1.34 2021-04-25 18:07:03+05:30 Cprogrammer
# refactored update of rompr playcounts
#
# Revision 1.33 2021-04-25 15:50:05+05:30 Cprogrammer
# skip update of last_played when paused to avoid karma getting increased
#
# Revision 1.32 2021-04-25 13:35:56+05:30 Cprogrammer
# sync RompR playcounts from stats.db
#
# Revision 1.31 2021-04-25 10:32:07+05:30 Cprogrammer
# added log output for scrobbling
#
# Revision 1.30 2021-04-25 10:10:07+05:30 Cprogrammer
# added code comments
#
# Revision 1.29 2021-04-24 22:13:54+05:30 Cprogrammer
# removed redundant code
#
# Revision 1.28 2021-04-24 20:48:30+05:30 Cprogrammer
# prevent end-song getting executed twice when playlist ends
#
# Revision 1.27 2021-04-24 14:51:52+05:30 Cprogrammer
# skip percentage calculation when SONG_PLAYED_DURATION is not set
#
# Revision 1.26 2021-04-23 16:46:08+05:30 Cprogrammer
# renamed SONG_PLAYED to SONG_PLAYED_DURATION
#
# Revision 1.25 2021-04-23 16:44:05+05:30 Cprogrammer
# fixed song played duration
#
# Revision 1.24 2021-04-22 20:15:53+05:30 Cprogrammer
# display correct playcount in rompr table
#
# Revision 1.23 2021-04-22 19:18:44+05:30 Cprogrammer
# skip update of play_count when song is skipped
#
# Revision 1.22 2021-04-16 21:11:02+05:30 Cprogrammer
# added upgrade karma logic
#
# Revision 1.21 2021-04-15 20:06:06+05:30 Cprogrammer
# skip db update if NO_DB_UPDATE is defined and non-zero
#
# Revision 1.20 2021-04-15 11:55:19+05:30 Cprogrammer
# downgrade karma of a song if skipped
#
# Revision 1.19 2021-04-14 21:50:55+05:30 Cprogrammer
# display song played duration
#
# Revision 1.18 2020-08-27 14:29:29+05:30 Cprogrammer
# auto rate if $HOME/.mpdev/AUTO_RATING file is present
# fixed path of stats.db
#
# Revision 1.17 2020-08-18 08:15:56+05:30 Cprogrammer
# minor fixes
#
# Revision 1.16 2020-08-17 22:17:19+05:30 Cprogrammer
# added playpause
#
# Revision 1.15 2020-08-10 20:35:40+05:30 Cprogrammer
# fixed debug message call
#
# Revision 1.14 2020-08-10 17:25:14+05:30 Cprogrammer
# replaced /tmp/mpdev with MPDEV_TMPDIR
# exit now-playing when in pause or stop state
#
# Revision 1.13 2020-08-10 11:54:38+05:30 Cprogrammer
# skip http urls
#
# Revision 1.12 2020-08-09 20:50:50+05:30 Cprogrammer
# use unix domain socket if MYSQL_SOCKET env variable is defined
#
# Revision 1.11 2020-07-28 12:47:21+05:30 Cprogrammer
# added zztimestamp filed to Ratingtable
# fixed typo UNIX_TIMESTAMP
#
# Revision 1.10 2020-07-24 21:48:34+05:30 Cprogrammer
# for song-end exit if END_TIME is not set
#
# Revision 1.9 2020-07-22 15:51:33+05:30 Cprogrammer
# use AUTO_RATING env variable
#
# Revision 1.8 2020-07-21 22:28:19+05:30 Cprogrammer
# display rating for RompR in logs in RompR scale
#
# Revision 1.7 2020-07-21 19:20:29+05:30 Cprogrammer
# BUG. fixed rating tmp filename
#
# Revision 1.6 2020-07-21 18:31:38+05:30 Cprogrammer
# added error condition for getting rating from Ratingtable.
#
# Revision 1.5 2020-07-21 18:02:29+05:30 Cprogrammer
# create temp file for recording original start time
#
# Revision 1.4 2020-07-21 17:04:02+05:30 Cprogrammer
# option to run without sticker or stats db enabled
#
# Revision 1.3 2020-07-21 12:25:20+05:30 Cprogrammer
# added get_rompr_playcount_ts() function to get playcount and timestamp from Playcounttable
#
# Revision 1.2 2020-07-20 15:58:32+05:30 Cprogrammer
# multiple fixes to work properly with rompr
#
# Revision 1.1 2020-07-19 18:14:10+05:30 Cprogrammer
# Initial revision
#