From 2a672cf96dc272213a36d15f78ec19b6579de4df Mon Sep 17 00:00:00 2001 From: Jakob Pfender Date: Thu, 14 Oct 2010 10:34:39 +0200 Subject: 'server is unboun' fixed --- client/client.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/client.erl b/client/client.erl index 85f0e9d..67be4ee 100644 --- a/client/client.erl +++ b/client/client.erl @@ -74,7 +74,7 @@ handle(Cmd, Server) -> {{error, {unknown_command, Cmd}}, Server}. %queries the server for the current votes this client possesses -getVotes() -> +getVotes(Server) -> rpc(Server, getVotes, self()), receive Msg -> -- cgit v1.2.3 From 0dc60dd485a35b2c2336cf56595c2731b4634877 Mon Sep 17 00:00:00 2001 From: micha Date: Thu, 14 Oct 2010 10:34:46 +0200 Subject: medaa server DB init --- server/media.erl | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/server/media.erl b/server/media.erl index 3897a6a..21c94a0 100644 --- a/server/media.erl +++ b/server/media.erl @@ -1,5 +1,6 @@ -module(media). -export([init/0,insert/3, ask/2, all/0, play/3]). +-define(TESTPATTERN, "../ac/*.mp3"). % Since we are not willing to calculate and deliver all the id3 tags everytime they are requested, % we try to get something persistent with mnesia. @@ -24,8 +25,20 @@ init() -> mnesia:create_schema([node()]), mnesia:start(), mnesia:create_table(track, [{attributes, record_info(fields, track)}]), + read_files(filelib:wildcard(?TESTPATTERN),0,0), io:format("Initialisation of mnesia successful.\n"). +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), + 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) + end; +read_files([],Total,Fail) -> io:format("Total: ~w, Failed: ~w~n", [Total, Fail]). + % Basic insertion of entrys into the database. Some entries are left out because they are 0 or false. insert(Artist, Title, Filepath) -> @@ -46,7 +59,7 @@ ask(Artist, Title) -> all() -> F = fun() -> - mnesia:match({track, '_','_','_','_','_'}) + mnesia:match_object({track, '_','_','_','_','_'}) end, {atomic, Results} = mnesia:transaction(F), Results. @@ -56,7 +69,6 @@ all() -> play(Artist, Title, Callback) -> [Head|_] = ask(Artist, Title), {_, _, _, _, _, Fp} = Head, -% Port = erlang:open_port({spawn, Cmd}, [exit_status]). Port = erlang:open_port({spawn_executable, "/usr/bin/mplayer"}, [{args, [Fp]}]). % We want to execute commands locally -- cgit v1.2.3