История изменений
Исправление
snoopcat,
(текущая версия)
:
#!/bin/bash
# VK scrobbler.
# by snoopcatt.
# token: https://oauth.vk.com/authorize?client_id=3723065&scope=audio,status,offline&redirect_uri=http://oauth.vk.com/blank.html&display=wap&response_type=token
VKAPI_TOKEN=''
SERVICE_NAME="$(qdbus org.mpris.MediaPlayer2* | head -n1)"
TIMEOUT=5s
IFS=$'\n'
[ -n $SERVICE_NAME ] && echo "[$(date +%k:%M:%S]) Connected to $SERVICE_NAME" || exit 1
trap shutdown INT TERM
get_song_info() {
wget --no-check-certificate "https://api.vk.com/method/audio.search.xml?q=$1&sort=2&lyrics=1&auto_complete=1&count=1&access_token=$VKAPI_TOKEN" -qO -
}
set_broadcast() {
wget --no-check-certificate "https://api.vk.com/method/audio.setBroadcast.xml?audio=${1}&access_token=$VKAPI_TOKEN" -qO /dev/null
}
shutdown() {
echo -e "\n[$(date +%k:%M:%S]) Exitting..."
#set_broadcast
rm /tmp/vkscrobble* 2>/dev/null
exit
}
first=1
while :; do
[ $first -eq 1 ] && first=0 || sleep $TIMEOUT # do-while workaround
if qdbus $SERVICE_NAME /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlaybackStatus|grep -q Playing; then
metadata=($(qdbus $SERVICE_NAME /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Metadata|grep -E ':artist|:title'|sed 's/xesam\:artist\:\ //; s/xesam\:title\:\ //'))
[ "${metadata[0]} - ${metadata[1]}" == "$(cat /tmp/vkscrobble_last_id 2>/dev/null)" ] && continue
vk_song_id=($(get_song_info "${metadata[0]} - ${metadata[1]}"|grep -E 'owner_id|aid'|grep -oE '[-0-9]{1,15}'))
#set_broadcast ${vk_song_id[1]}_${vk_song_id[0]}
echo "[$(date +%k:%M:%S]) Broadcast was set to: ${metadata[0]} - ${metadata[1]} (${vk_song_id[1]}_${vk_song_id[0]})"
echo -n "${metadata[0]} - ${metadata[1]}" > /tmp/vkscrobble_last_id
else
[ "null" == "$(cat /tmp/vkscrobble_last_id 2>/dev/null)" ] && continue
echo "[$(date +%k:%M:%S]) Broadcast removed."
#set_broadcast
echo null > /tmp/vkscrobble_last_id
fi
done
Исходная версия
snoopcat,
:
ага, пароли ворую
#!/bin/bash
# VK scrobbler.
# by snoopcatt.
# token: https://oauth.vk.com/authorize?client_id=3723065&scope=audio,status,offline&redirect_uri=http://oauth.vk.com/blank.html&display=wap&response_type=token
VKAPI_TOKEN=''
SERVICE_NAME="$(qdbus org.mpris.MediaPlayer2* | head -n1)"
TIMEOUT=5s
IFS=$'\n'
[ -n $SERVICE_NAME ] && echo "[$(date +%k:%M:%S]) Connected to $SERVICE_NAME" || exit 1
trap shutdown INT TERM
get_song_info() {
wget --no-check-certificate "https://api.vk.com/method/audio.search.xml?q=$1&sort=2&lyrics=1&auto_complete=1&count=1&access_token=$VKAPI_TOKEN" -qO - | tee /tmp/lol
}
set_broadcast() {
wget --no-check-certificate "https://api.vk.com/method/audio.setBroadcast.xml?audio=${1}&access_token=$VKAPI_TOKEN" -qO /dev/null
}
shutdown() {
echo -e "\n[$(date +%k:%M:%S]) Exitting..."
#set_broadcast
rm /tmp/vkscrobble* 2>/dev/null
exit
}
first=1
while :; do
[ $first -eq 1 ] && first=0 || sleep $TIMEOUT # do-while workaround
if qdbus $SERVICE_NAME /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlaybackStatus|grep -q Playing; then
metadata=($(qdbus $SERVICE_NAME /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Metadata|grep -E ':artist|:title'|sed 's/xesam\:artist\:\ //; s/xesam\:title\:\ //'))
[ "${metadata[0]} - ${metadata[1]}" == "$(cat /tmp/vkscrobble_last_id 2>/dev/null)" ] && continue
vk_song_id=($(get_song_info "${metadata[0]} - ${metadata[1]}"|grep -E 'owner_id|aid'|grep -oE '[-0-9]{1,15}'))
#set_broadcast ${vk_song_id[1]}_${vk_song_id[0]}
echo "[$(date +%k:%M:%S]) Broadcast was set to: ${metadata[0]} - ${metadata[1]} (${vk_song_id[1]}_${vk_song_id[0]})"
echo -n "${metadata[0]} - ${metadata[1]}" > /tmp/vkscrobble_last_id
else
[ "null" == "$(cat /tmp/vkscrobble_last_id 2>/dev/null)" ] && continue
echo "[$(date +%k:%M:%S]) Broadcast removed."
#set_broadcast
echo null > /tmp/vkscrobble_last_id
fi
done