Skip to content

Commit

Permalink
added --info option for lastfm/librefm scrobbler command
Browse files Browse the repository at this point in the history
1. karma: display command if running on tty
2. moc-scrobbler: added --info option to get track info
  • Loading branch information
mbhangui committed Apr 9, 2024
1 parent d243f48 commit 5ebee69
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 12 deletions.
31 changes: 26 additions & 5 deletions karma.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/bin/sh
#
# $Log: karma.in,v $
# Revision 1.13 2024-04-09 23:24:45+05:30 Cprogrammer
# display scrobble command if running with a tty
#
# Revision 1.12 2024-04-08 22:49:51+05:30 Cprogrammer
# added unlove function
#
Expand Down Expand Up @@ -38,7 +41,7 @@
# Initial revision
#
#
# $Id: karma.in,v 1.12 2024-04-08 22:49:51+05:30 Cprogrammer Exp mbhangui $
# $Id: karma.in,v 1.13 2024-04-09 23:24:45+05:30 Cprogrammer Exp mbhangui $

get_mpd_conf_value()
{
Expand Down Expand Up @@ -222,16 +225,34 @@ if [ $scrobble_love -eq 1 -o $scrobble_unlove -eq 1 ] ; then
sql_query_s="SELECT title, artist, album FROM song WHERE uri='${song_uri}'"
sqlite3 -noheader -batch $stats_file "$sql_query_s" | while IFS='|' read track artist album
do
tty -s
ret=$?
if [ $scrobble_love -eq 1 ] ; then
echo "marking scrobble as loved on lastfm"
lastfm-scrobbler --love --artist="$artist" --track="$track" --album="$album" > /dev/null
if [ $ret -eq 0 ] ; then
lastfm-scrobbler --love --artist="$artist" --track="$track" --album="$album"
else
lastfm-scrobbler --love --artist="$artist" --track="$track" --album="$album" > /dev/null
fi
echo "marking scrobble as loved on librefm"
librefm-scrobbler --love --artist="$artist" --track="$track" --album="$album" > /dev/null
if [ $ret -eq 0 ] ; then
librefm-scrobbler --love --artist="$artist" --track="$track" --album="$album"
else
librefm-scrobbler --love --artist="$artist" --track="$track" --album="$album" > /dev/null
fi
else
echo "marking scrobble as unloved on lastfm"
lastfm-scrobbler --unlove --artist="$artist" --track="$track" --album="$album" > /dev/null
if [ $ret -eq 0 ] ; then
lastfm-scrobbler --unlove --artist="$artist" --track="$track" --album="$album"
else
lastfm-scrobbler --unlove --artist="$artist" --track="$track" --album="$album" > /dev/null
fi
echo "marking scrobble as unloved on librefm"
librefm-scrobbler --unlove --artist="$artist" --track="$track" --album="$album" > /dev/null
if [ $ret -eq 0 ] ; then
librefm-scrobbler --unlove --artist="$artist" --track="$track" --album="$album"
else
librefm-scrobbler --unlove --artist="$artist" --track="$track" --album="$album" > /dev/null
fi
fi
done
exit 0
Expand Down
6 changes: 6 additions & 0 deletions lastfm-scrobbler.1
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,15 @@ Connecting:
Scrobbling:
--artist --track --duration
Trackinfo
--info --artist --track
Love:
--love --artist --track --duration
UnLove:
--unlove --artist --track --duration
Update Current Song:
--update --artist --track --duration
Expand Down
6 changes: 6 additions & 0 deletions librefm-scrobbler.1
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,15 @@ Connecting:
Scrobbling:
--artist --track --duration
Trackinfo
--info --artist --track
Love:
--love --artist --track --duration
UnLove:
--unlove --artist --track --duration
Update Current Song:
--update --artist --track --duration
Expand Down
46 changes: 39 additions & 7 deletions moc-scrobbler.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh
#
# $Id: moc-scrobbler.in,v 1.7 2024-04-08 22:50:05+05:30 Cprogrammer Exp mbhangui $
# $Id: moc-scrobbler.in,v 1.8 2024-04-09 23:25:09+05:30 Cprogrammer Exp mbhangui $
#

################################################################
Expand Down Expand Up @@ -60,8 +60,12 @@ usage_all() {
echo " --artist --track --album --duration"
echo "Update Current Song (\"Now scrobbling\"):"
echo " --update --artist --track --album --duration"
echo "info:"
echo " --info --track --artist"
echo "Love:"
echo " --love --artist --track --album"
echo "UnLove:"
echo " --unlove --artist --track --album"
echo "Stop:"
echo " --stop"
echo "Debug:"
Expand All @@ -80,9 +84,15 @@ usage_scrobble() {
echo "Scrobble: Will directly scrobble the current song."
echo " --artist=\"etc\" --title=\"etc\" --album=\"etc\" --duration=\"123\""
echo ""
echo "Info: will get track information"
echo " --info --artist=\"etc\" --title=\"etc\""
echo ""
echo "Love: Will mark the track as loved"
echo " --love --artist=\"etc\" --title=\"etc\" --album=\"etc\""
echo ""
echo "UnLove: Will mark the track as unloved"
echo " --unlove --artist=\"etc\" --title=\"etc\" --album=\"etc\""
echo ""
echo "Stop: Will delete the current and last songs saved for scrobbling."
echo " --stop"
echo ""
Expand Down Expand Up @@ -242,7 +252,7 @@ scrobble() {
fi
# Collect track data
# Check for minimum arguments to scrobble
if [ "$LOVE" = true -o "$UNLOVE" = true ] ; then
if [ "$LOVE" = true -o "$UNLOVE" = true -o "$GETINFO" = true ] ; then
if [ -z "$artist" ] || [ -z "$track" ] ; then
echo "--artist and --track options are required" 1>&2
ERR=true
Expand Down Expand Up @@ -340,6 +350,17 @@ scrobble() {
--data "sk=$SESSION_KEY" \
--data "timestamp=$TS" \
--data-urlencode "track=$track" | tr '\n' ' ')
elif [ "$GETINFO" = true ] ; then
echo "Getting info for track=[$track], artist=[$artist] ..."
curl -s "$SCHEMA://$API_URL/" \
--data "method=track.getinfo" \
--data "api_key=$API_KEY" \
--data "sk=$SESSION_KEY" \
--data-urlencode "track=$track" \
--data-urlencode "artist=$artist" \
--data "autocorrect=1" \
--data "format=xml" > $CONF_DIR/track.xml
RESPONSE_XML=$(cat $CONF_DIR/track.xml | tr '\n' ' ')
else
echo "Scrobbling $track $album $artist"
RESPONSE_XML=$(curl -sX POST "$SCHEMA://$API_URL/" \
Expand All @@ -361,13 +382,17 @@ scrobble() {
if [ $DEBUG = true ] ; then
echo "Success!"
fi
log_scrobble "Scrobbled $track - $artist"
if [ "$LOVE" != true -a "$UNLOVE" != true -a "$GETINFO" != true ] ; then
log_scrobble "Scrobbled $track - $artist"
fi
else
echo "Error scrobbling $artist - $track: $RESPONSE_XML"
log_scrobble "Error scrobbling $artist - $track - $RESPONSE_XML"
if [ "$LOVE" != true -a "$UNLOVE" != true -a "$GETINFO" != true ] ; then
echo "Error scrobbling $artist - $track: $RESPONSE_XML"
log_scrobble "Error scrobbling $artist - $track - $RESPONSE_XML"
fi
return 1
fi
if [ "$LOVE" = true -o "$UNLOVE" = true -o "$UPDATE" != true ] ; then
if [ "$LOVE" = true -o "$UNLOVE" = true -o "$GETINFO" = true -o "$UPDATE" != true ] ; then
return 0
fi
# DO NOW LISTENING POST
Expand Down Expand Up @@ -485,6 +510,7 @@ API_SEC=false
UPDATE=false
LOVE=false
UNLOVE=false
GETINFO=false
STOP=false
DEBUG=false

Expand Down Expand Up @@ -512,6 +538,9 @@ while test $# -gt 0; do
UNLOVE=true
LOVE=false
;;
--info)
GETINFO=true
;;
--stop)
STOP=true
;;
Expand Down Expand Up @@ -565,7 +594,7 @@ while test $# -gt 0; do
exit 0
;;
--version)
echo "$Id: moc-scrobbler.in,v 1.7 2024-04-08 22:50:05+05:30 Cprogrammer Exp mbhangui $"
echo "$Id: moc-scrobbler.in,v 1.8 2024-04-09 23:25:09+05:30 Cprogrammer Exp mbhangui $"
echo $AUTHOR
exit 0
;;
Expand All @@ -592,6 +621,9 @@ exit $?

#
# $Log: moc-scrobbler.in,v $
# Revision 1.8 2024-04-09 23:25:09+05:30 Cprogrammer
# added --info option to get track info
#
# Revision 1.7 2024-04-08 22:50:05+05:30 Cprogrammer
# added unlove function
#
Expand Down

0 comments on commit 5ebee69

Please sign in to comment.