aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/client.erl46
-rw-r--r--server/media.erl6
2 files changed, 36 insertions, 16 deletions
diff --git a/server/client.erl b/server/client.erl
index ce7c99b..333df4a 100644
--- a/server/client.erl
+++ b/server/client.erl
@@ -10,32 +10,52 @@ start(Node) ->
case server:rpc(Client, {change_state, Server}) of
{ok} ->
{ok, Client};
- _ ->
- {error, unknown_error}
+ Why ->
+ {error, {unknown_error, Why}}
end.
loop(Client) ->
receive
list ->
- Client ! {ok, {foo}},
- loop(Client);
+ try media:all() of
+ Result ->
+ Client ! {ok, Result}
+ catch
+ _: Why ->
+ Client ! {error, Why}
+ end;
get_votes ->
- Client ! {ok, media:getVotes(Client)},
- loop(Client);
+ try media:getVotes(Client) of
+ Result ->
+ Client ! {ok, Result}
+ catch
+ _: Why ->
+ Client ! {error, Why}
+ end;
{vote, Artist, Title} ->
- Client ! media:vote(Artist, Title),
- loop(Client);
+ try media:vote(Artist, Title) of
+ Result ->
+ Client ! {ok, Result}
+ catch
+ _: Why ->
+ Client ! {error, Why}
+ end;
{devote, Artist, Title} ->
- Client ! media:devote(Artist, Title),
- loop(Client);
+ try media:devote(Artist, Title) of
+ Result ->
+ Client ! {ok, Result}
+ catch
+ _: Why ->
+ Client ! {error, Why}
+ end;
Cmd ->
- Client ! {error, {unknown_command, Cmd}},
- loop(Client)
- end.
+ Client ! {error, {unknown_command, Cmd}}
+ end,
+ loop(Client).
register(Client, {Name, Password}) ->
dis ! {Client, {register, {Name, Password}}}.
diff --git a/server/media.erl b/server/media.erl
index 1463715..9d5bcb6 100644
--- a/server/media.erl
+++ b/server/media.erl
@@ -26,11 +26,11 @@ init() ->
start_playing(),
io:format("Starting to play music\n").
-read_files([FN|Rest],Total,Fail) ->
+read_files([FN|Rest],Total,Fail) ->
case id3v2:read_file(FN) of
{ok, Props} -> % insert entry into mnesia DB
Artist = proplists:get_value(tpe1, Props),
- Title = proplists:get_value(tit2, Props),
+ Title = proplists:get_value(tit2, Props),
insert(bitstring_to_list(Artist), bitstring_to_list(Title), FN),
read_files(Rest, Total+1, Fail);
not_found -> read_files(Rest, Total+1, Fail+1)
@@ -99,7 +99,7 @@ play(Artist, Title, Callback) ->
% Of course we need a query to find out whats actually the most wished for track.
% We will do it by requesting all the records from the database and then iteramte over just taking a look at the vote
-% variable, so it is like list of integers. In case no tracks were voted for we just take the first track we find and play it. Of course it is locked afterwards so another will be choosen.
+% variable, so it is like list of integers. In case no tracks were voted for we just take the first track we find and play it. Of course it is locked afterwards so another will be choosen.
vote(Artist, Title) ->
F = fun() ->