testing some scrobbling features in Pleroma.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
2.0 KiB

require 'httparty'
require 'http'
require 'http/request'
require 'ruby-mpd'
$instance_url = "" # add your instance here. example: https://freecumextremist.com
$bearer_token = "" # add bearer token here. you may need to generate one. I suggest using https://github.com/animeavi/fedi_ebooks/blob/master/auth_helper.rb to do this
$id = "" # set to what your username is. example: lain
def currently_playing
mpd = MPD.new
mpd.connect
song = mpd.current_song
album = song.album
title = song.title
artist = song.artist
create_scrobble(album, artist, title)
mpd.disconnect
end
def create_scrobble(album, artist, title)
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer #{$bearer_token}"
}
body = {}
body["album"] = album
body["artist"] = artist
body["title"] = title
body["visibility"] = "public"
puts $id
response = HTTParty.post("#{$instance_url}/api/v1/pleroma/scrobble",
body: JSON.dump(body), headers: headers)
puts response.code
end
def get_scrobble()
title = {}
headers = {
"Content-Type": "application/json",
}
body = {}
body["limit"] = 1
url = HTTParty.get("#{$instance_url}/api/v1/pleroma/accounts/#{$id}/scrobbles",
body: JSON.dump(body), headers: headers, format: :plain)
output = JSON.parse(url)[0]
puts "Album title: " + output["album"]
puts "Artist: " + output["artist"]
puts "Song Title: " + output["title"]
post_scrobble(output)
end
def post_scrobble(output)
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer #{$bearer_token}"
}
body = {}
body["visibility"] = "public"
body["status"] = "Now Playing: #{output["title"]} by #{output["artist"]} on #{output["album"]}"
scrobble = HTTParty.post("#{$instance_url}/api/v1/statuses",
body: JSON.dump(body), headers: headers)
code = scrobble.code.to_s
puts "#{code} OK. Status posted with id: " + scrobble["id"] + " at " + scrobble["created_at"]
end
currently_playing
get_scrobble