143 lines
4.5 KiB
Julia
143 lines
4.5 KiB
Julia
|
import Base.push!
|
||
|
|
||
|
function push!(root::XMLElement, p::Playlist)
|
||
|
playlistXML = new_child(root, "playlist")
|
||
|
set_attributes(playlistXML, [
|
||
|
("id", p.uuid),
|
||
|
("name", p.name),
|
||
|
("comment", p.comment),
|
||
|
("owner", p.owner),
|
||
|
("public", string(p.public)),
|
||
|
("songCount", string(length(p.songs))),
|
||
|
("duration", reduce(+, p.songs, init = 0.0) |> floor |> string),
|
||
|
("created", "FIXME"),
|
||
|
("coverArt", p.cover),
|
||
|
])
|
||
|
playlistXML
|
||
|
#=
|
||
|
<allowedUser>sindre</allowedUser>
|
||
|
<allowedUser>john</allowedUser>
|
||
|
=#
|
||
|
end
|
||
|
|
||
|
function append!(root::XMLElement, p::Playlist)
|
||
|
playlistXML = push!(root, p)
|
||
|
# FIXME: 1. allowed users
|
||
|
for song in p.songs
|
||
|
entry = new_child(playlistXML, "entry")
|
||
|
set_attributes(entry, props(song))
|
||
|
end
|
||
|
playlistXML
|
||
|
end
|
||
|
|
||
|
push!(p::Playlist, s::Song) = push!(p.songs, s)
|
||
|
|
||
|
function push!(root::XMLElement, album::Beets.Album)
|
||
|
albumXML = new_child(root, "album")
|
||
|
set_attributes(albumXML, [
|
||
|
("name", album.title),
|
||
|
("id", album.uuid),
|
||
|
("name", album.artist.name),
|
||
|
("artistId", album.artist.uuid),
|
||
|
("artist", album.artist.name),
|
||
|
# FIXME
|
||
|
("created", "0"),
|
||
|
("coverArt", album.uuid),
|
||
|
("songs", "FIXME"),
|
||
|
("songCount", string(length(album.songs))),
|
||
|
("duration", string(sum([t.length for t in album.songs])))
|
||
|
])
|
||
|
albumXML
|
||
|
end
|
||
|
|
||
|
function push!(root::XMLElement, artist::Beets.Artist)
|
||
|
artistXML = new_child(root, "artist")
|
||
|
set_attributes(artistXML, [
|
||
|
("id", artist.uuid),
|
||
|
("name", artist.name),
|
||
|
("coverArt", artist.uuid),
|
||
|
("albumCount", "0")
|
||
|
])
|
||
|
artistXML
|
||
|
end
|
||
|
|
||
|
function push!(root::XMLElement, song_album::Tuple{Beets.Song,Beets.Album})
|
||
|
songXML = new_child(root, "song")
|
||
|
song, album = song_album
|
||
|
set_attributes(songXML, [
|
||
|
("id", song.uuid),
|
||
|
# ("parent", album.artist.uuid), # Not clear
|
||
|
("title", song.title),
|
||
|
("album", album.title),
|
||
|
("artist", album.artist.name),
|
||
|
("isDir", "false"),
|
||
|
("coverArt", album.uuid),
|
||
|
("created", "FIXME"),
|
||
|
("duration", string(floor(song.length) |> Int)),
|
||
|
("bitrate", string(song.bitrate)),
|
||
|
("size", string(filesize(song.path))),
|
||
|
("suffix", lowercase(song.format)),
|
||
|
## FIXME
|
||
|
("contentType", "audio/flac"), # mpeg
|
||
|
("isVideo", "false"),
|
||
|
("path", relpath(song.path, Beets.musicdir())),
|
||
|
("albumId", album.uuid),
|
||
|
("artistId", album.artist.uuid),
|
||
|
("type", "music")
|
||
|
])
|
||
|
root
|
||
|
end
|
||
|
|
||
|
function props(song::Song)
|
||
|
[
|
||
|
("id", song.uuid),
|
||
|
# ("parent", album.artist.uuid), # Not clear
|
||
|
("title", song.title),
|
||
|
("album", song.title),
|
||
|
# ("artist", song.album.artist.name),
|
||
|
("isDir", "false"),
|
||
|
("coverArt", song.uuid),
|
||
|
("created", "FIXME"),
|
||
|
("duration", string(floor(song.length) |> Int)),
|
||
|
("bitrate", string(song.bitrate)),
|
||
|
("size", string(filesize(song.path))),
|
||
|
("suffix", lowercase(song.format)),
|
||
|
## FIXME
|
||
|
("contentType", "audio/flac"), # mpeg
|
||
|
("isVideo", "false"),
|
||
|
("path", relpath(song.path, Beets.musicdir())),
|
||
|
# ("albumId", song.album.uuid),
|
||
|
# ("artistId", song.album.artist.uuid),
|
||
|
("type", "music")
|
||
|
]
|
||
|
end
|
||
|
|
||
|
function push!(root::XMLElement, songs::Vector{Tuple{Beets.Song,Beets.Album}})
|
||
|
for (song, album) in songs
|
||
|
songXML = new_child(root, "song")
|
||
|
set_attributes(songXML, props(song))
|
||
|
end
|
||
|
root
|
||
|
end
|
||
|
|
||
|
function push!(root::XMLElement, user::User)
|
||
|
userXML = new_child(root, "user")
|
||
|
set_attributes(userXML,
|
||
|
[
|
||
|
("username", user.name)
|
||
|
("email", user.email)
|
||
|
("adminRole", string(user.admin))
|
||
|
("scrobblingEnabled", "false")
|
||
|
("settingsRole", string(user.settings))
|
||
|
("downloadRole", string(user.download))
|
||
|
("uploadRole", string(user.upload))
|
||
|
("playlistRole", string(user.playlist))
|
||
|
("coverArtRole", string(user.cover))
|
||
|
("commentRole", string(user.comment))
|
||
|
("podcastRole", "false")
|
||
|
("streamRole", string(user.stream))
|
||
|
("jukeboxRole", "false")
|
||
|
("shareRole", string(user.share))
|
||
|
])
|
||
|
end
|