Packages

Gleam SDK for Rockbox Zig — pipe-friendly client for the rockboxd GraphQL API

Current section

Files

Jump to
rockbox src rockbox@smart_playlists.erl
Raw

src/rockbox@smart_playlists.erl

-module(rockbox@smart_playlists).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/rockbox/smart_playlists.gleam").
-export([new/2, with_description/2, with_image/2, with_folder/2, update/2, update_description/2, update_image/2, update_folder/2, list/1, get/2, track_ids/2, create/2, save/3, delete/2, play/2, track_stats/2, record_played/2, record_skipped/2]).
-export_type([create_input/0, update_input/0]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(" Rule-based \"smart\" playlists that auto-update from listening stats.\n").
-opaque create_input() :: {create_input,
binary(),
binary(),
gleam@option:option(binary()),
gleam@option:option(binary()),
gleam@option:option(binary())}.
-opaque update_input() :: {update_input,
binary(),
binary(),
gleam@option:option(binary()),
gleam@option:option(binary()),
gleam@option:option(binary())}.
-file("src/rockbox/smart_playlists.gleam", 27).
?DOC(
" `rules` is the JSON-encoded smart-playlist rule set. The format matches\n"
" the rockboxd schema — see the project README for details.\n"
).
-spec new(binary(), binary()) -> create_input().
new(Name, Rules) ->
{create_input, Name, Rules, none, none, none}.
-file("src/rockbox/smart_playlists.gleam", 37).
-spec with_description(create_input(), binary()) -> create_input().
with_description(Input, Value) ->
{create_input,
erlang:element(2, Input),
erlang:element(3, Input),
{some, Value},
erlang:element(5, Input),
erlang:element(6, Input)}.
-file("src/rockbox/smart_playlists.gleam", 41).
-spec with_image(create_input(), binary()) -> create_input().
with_image(Input, Value) ->
{create_input,
erlang:element(2, Input),
erlang:element(3, Input),
erlang:element(4, Input),
{some, Value},
erlang:element(6, Input)}.
-file("src/rockbox/smart_playlists.gleam", 45).
-spec with_folder(create_input(), binary()) -> create_input().
with_folder(Input, Folder_id) ->
{create_input,
erlang:element(2, Input),
erlang:element(3, Input),
erlang:element(4, Input),
erlang:element(5, Input),
{some, Folder_id}}.
-file("src/rockbox/smart_playlists.gleam", 59).
-spec update(binary(), binary()) -> update_input().
update(Name, Rules) ->
{update_input, Name, Rules, none, none, none}.
-file("src/rockbox/smart_playlists.gleam", 69).
-spec update_description(update_input(), binary()) -> update_input().
update_description(Input, Value) ->
{update_input,
erlang:element(2, Input),
erlang:element(3, Input),
{some, Value},
erlang:element(5, Input),
erlang:element(6, Input)}.
-file("src/rockbox/smart_playlists.gleam", 73).
-spec update_image(update_input(), binary()) -> update_input().
update_image(Input, Value) ->
{update_input,
erlang:element(2, Input),
erlang:element(3, Input),
erlang:element(4, Input),
{some, Value},
erlang:element(6, Input)}.
-file("src/rockbox/smart_playlists.gleam", 77).
-spec update_folder(update_input(), binary()) -> update_input().
update_folder(Input, Folder_id) ->
{update_input,
erlang:element(2, Input),
erlang:element(3, Input),
erlang:element(4, Input),
erlang:element(5, Input),
{some, Folder_id}}.
-file("src/rockbox/smart_playlists.gleam", 85).
-spec list(rockbox:client()) -> {ok, list(rockbox@types:smart_playlist())} |
{error, rockbox@error:error()}.
list(Client) ->
Decoder = begin
gleam@dynamic@decode:field(
<<"smartPlaylists"/utf8>>,
gleam@dynamic@decode:list(rockbox@types:smart_playlist_decoder()),
fun(Playlists) -> gleam@dynamic@decode:success(Playlists) end
)
end,
rockbox:'query'(
Client,
<<"query SmartPlaylists {
smartPlaylists {
id name description image folderId isSystem rules createdAt updatedAt
}
}"/utf8>>,
gleam@json:object([]),
Decoder
).
-file("src/rockbox/smart_playlists.gleam", 105).
-spec get(rockbox:client(), binary()) -> {ok,
gleam@option:option(rockbox@types:smart_playlist())} |
{error, rockbox@error:error()}.
get(Client, Id) ->
Decoder = begin
gleam@dynamic@decode:field(
<<"smartPlaylist"/utf8>>,
gleam@dynamic@decode:optional(
rockbox@types:smart_playlist_decoder()
),
fun(Playlist) -> gleam@dynamic@decode:success(Playlist) end
)
end,
rockbox:'query'(
Client,
<<"query SmartPlaylist($id: String!) {
smartPlaylist(id: $id) {
id name description image folderId isSystem rules createdAt updatedAt
}
}"/utf8>>,
gleam@json:object([{<<"id"/utf8>>, gleam@json:string(Id)}]),
Decoder
).
-file("src/rockbox/smart_playlists.gleam", 125).
-spec track_ids(rockbox:client(), binary()) -> {ok, list(binary())} |
{error, rockbox@error:error()}.
track_ids(Client, Id) ->
Decoder = begin
gleam@dynamic@decode:field(
<<"smartPlaylistTrackIds"/utf8>>,
gleam@dynamic@decode:list(
{decoder, fun gleam@dynamic@decode:decode_string/1}
),
fun(Ids) -> gleam@dynamic@decode:success(Ids) end
)
end,
rockbox:'query'(
Client,
<<"query SmartPlaylistTrackIds($id: String!) { smartPlaylistTrackIds(id: $id) }"/utf8>>,
gleam@json:object([{<<"id"/utf8>>, gleam@json:string(Id)}]),
Decoder
).
-file("src/rockbox/smart_playlists.gleam", 142).
-spec create(rockbox:client(), create_input()) -> {ok,
rockbox@types:smart_playlist()} |
{error, rockbox@error:error()}.
create(Client, Input) ->
Vars = rockbox@internal@transport:variables(
[{<<"name"/utf8>>, {some, gleam@json:string(erlang:element(2, Input))}},
{<<"rules"/utf8>>,
{some, gleam@json:string(erlang:element(3, Input))}},
{<<"description"/utf8>>,
gleam@option:map(
erlang:element(4, Input),
fun gleam@json:string/1
)},
{<<"image"/utf8>>,
gleam@option:map(
erlang:element(5, Input),
fun gleam@json:string/1
)},
{<<"folderId"/utf8>>,
gleam@option:map(
erlang:element(6, Input),
fun gleam@json:string/1
)}]
),
Decoder = begin
gleam@dynamic@decode:field(
<<"createSmartPlaylist"/utf8>>,
rockbox@types:smart_playlist_decoder(),
fun(Playlist) -> gleam@dynamic@decode:success(Playlist) end
)
end,
rockbox:'query'(
Client,
<<"mutation CreateSmartPlaylist(
$name: String!, $rules: String!, $description: String,
$image: String, $folderId: String
) {
createSmartPlaylist(
name: $name, rules: $rules, description: $description,
image: $image, folderId: $folderId
) {
id name description image folderId isSystem rules createdAt updatedAt
}
}"/utf8>>,
Vars,
Decoder
).
-file("src/rockbox/smart_playlists.gleam", 179).
-spec save(rockbox:client(), binary(), update_input()) -> {ok, nil} |
{error, rockbox@error:error()}.
save(Client, Id, Input) ->
Vars = rockbox@internal@transport:variables(
[{<<"id"/utf8>>, {some, gleam@json:string(Id)}},
{<<"name"/utf8>>,
{some, gleam@json:string(erlang:element(2, Input))}},
{<<"rules"/utf8>>,
{some, gleam@json:string(erlang:element(3, Input))}},
{<<"description"/utf8>>,
gleam@option:map(
erlang:element(4, Input),
fun gleam@json:string/1
)},
{<<"image"/utf8>>,
gleam@option:map(
erlang:element(5, Input),
fun gleam@json:string/1
)},
{<<"folderId"/utf8>>,
gleam@option:map(
erlang:element(6, Input),
fun gleam@json:string/1
)}]
),
rockbox:execute(
Client,
<<"mutation UpdateSmartPlaylist(
$id: String!, $name: String!, $rules: String!,
$description: String, $image: String, $folderId: String
) {
updateSmartPlaylist(
id: $id, name: $name, rules: $rules, description: $description,
image: $image, folderId: $folderId
)
}"/utf8>>,
Vars
).
-file("src/rockbox/smart_playlists.gleam", 208).
-spec delete(rockbox:client(), binary()) -> {ok, nil} |
{error, rockbox@error:error()}.
delete(Client, Id) ->
rockbox:execute(
Client,
<<"mutation DeleteSmartPlaylist($id: String!) { deleteSmartPlaylist(id: $id) }"/utf8>>,
gleam@json:object([{<<"id"/utf8>>, gleam@json:string(Id)}])
).
-file("src/rockbox/smart_playlists.gleam", 216).
-spec play(rockbox:client(), binary()) -> {ok, nil} |
{error, rockbox@error:error()}.
play(Client, Id) ->
rockbox:execute(
Client,
<<"mutation PlaySmartPlaylist($id: String!) { playSmartPlaylist(id: $id) }"/utf8>>,
gleam@json:object([{<<"id"/utf8>>, gleam@json:string(Id)}])
).
-file("src/rockbox/smart_playlists.gleam", 228).
-spec track_stats(rockbox:client(), binary()) -> {ok,
gleam@option:option(rockbox@types:track_stats())} |
{error, rockbox@error:error()}.
track_stats(Client, Track_id) ->
Decoder = begin
gleam@dynamic@decode:field(
<<"trackStats"/utf8>>,
gleam@dynamic@decode:optional(rockbox@types:track_stats_decoder()),
fun(Stats) -> gleam@dynamic@decode:success(Stats) end
)
end,
rockbox:'query'(
Client,
<<"query TrackStats($trackId: String!) {
trackStats(trackId: $trackId) {
trackId playCount skipCount lastPlayed lastSkipped updatedAt
}
}"/utf8>>,
gleam@json:object([{<<"trackId"/utf8>>, gleam@json:string(Track_id)}]),
Decoder
).
-file("src/rockbox/smart_playlists.gleam", 251).
-spec record_played(rockbox:client(), binary()) -> {ok, nil} |
{error, rockbox@error:error()}.
record_played(Client, Track_id) ->
rockbox:execute(
Client,
<<"mutation RecordTrackPlayed($trackId: String!) { recordTrackPlayed(trackId: $trackId) }"/utf8>>,
gleam@json:object([{<<"trackId"/utf8>>, gleam@json:string(Track_id)}])
).
-file("src/rockbox/smart_playlists.gleam", 259).
-spec record_skipped(rockbox:client(), binary()) -> {ok, nil} |
{error, rockbox@error:error()}.
record_skipped(Client, Track_id) ->
rockbox:execute(
Client,
<<"mutation RecordTrackSkipped($trackId: String!) { recordTrackSkipped(trackId: $trackId) }"/utf8>>,
gleam@json:object([{<<"trackId"/utf8>>, gleam@json:string(Track_id)}])
).