aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2010-10-14 15:19:47 +0200
committerAlexander Sulfrian <alexander@sulfrian.net>2010-10-14 15:19:47 +0200
commit4cf29d9ea1d52f2fb16634d65c2c0808e20a94b5 (patch)
treeb0305358b92586dfccc702a111cea9f6dbd8257b /server
parent7cd7907b9a4437c364200c0b455d753887080227 (diff)
parent6fbd6d9be211e1dae9a4ba003cefb2eb34c05c4c (diff)
downloaderlang-4cf29d9ea1d52f2fb16634d65c2c0808e20a94b5.tar.gz
erlang-4cf29d9ea1d52f2fb16634d65c2c0808e20a94b5.tar.xz
erlang-4cf29d9ea1d52f2fb16634d65c2c0808e20a94b5.zip
Merge branch 'master' of ssh://git.animux.de/erlang
Diffstat (limited to 'server')
-rw-r--r--server/cldb.erl12
-rw-r--r--server/media.erl23
2 files changed, 21 insertions, 14 deletions
diff --git a/server/cldb.erl b/server/cldb.erl
new file mode 100644
index 0000000..0f9f407
--- /dev/null
+++ b/server/cldb.erl
@@ -0,0 +1,12 @@
+% The clientdatabase
+
+-module(cldb).
+-export([init/0]).
+-record(user, {name, passwd, votes}).
+
+init() ->
+ mnesia:create_schema([node()]),
+ mnesia:start(),
+ mnesia:create_table(track, [{attributes, record_info(fields, track)}]),
+ io:format("Userdb up and running \n").
+
diff --git a/server/media.erl b/server/media.erl
index b3b8e0f..10fed99 100644
--- a/server/media.erl
+++ b/server/media.erl
@@ -43,7 +43,7 @@ read_files([],Total,Fail) -> io:format("Total: ~w, Failed: ~w~n", [Total, Fail])
start_playing() ->
{Artist, Title} = search_best(media:all(), 0,0),
- play(Artist, Title, "muh").
+ play(Artist, Title).
% Basic insertion of entrys into the database. Some entries are left out because they are 0 or false.
@@ -87,18 +87,13 @@ all() ->
% In practice we are going to set their locked variable to true and spawn a process which will unlock them after a certain time.
% Well this could be considered abuse.
-play(Artist, Title, Callback) ->
+play(Artist, Title) ->
[Head|_] = ask(Artist, Title),
{_, Title, Artist, _, _, Fp} = Head,
Port = erlang:open_port({spawn_executable, "/usr/bin/mplayer"}, [{args, [Fp]}, exit_status]),
-
- % lock the song
- F = fun() ->
- New = Head#track{locked = 1},
- mnesia:write(New)
- end,
- mnesia:transaction(F),
-
+ reset_votes(Artist, Title),
+ lock_process(Artist, Title),
+
io:format("playing: ~s, Artist: ~s~n", [Title, Artist]),
receive
{Port, {exit_status, 0}} -> start_playing();
@@ -140,8 +135,8 @@ reset_votes(Artist, Title) ->
lock(Artist, Title) ->
F = fun() ->
[Head|_] = ask(Artist, Title),
- Votes = Head#track.votes - 1,
- New = Head#track{votes = Votes},
+ Votes = Head#track.lock = true,
+ New = Head#track{lock = Votes},
mnesia:write(New)
end,
mnesia:transaction(F).
@@ -149,8 +144,8 @@ lock(Artist, Title) ->
unlock(Artist, Title) ->
F = fun() ->
[Head|_] = ask(Artist, Title),
- Votes = Head#track.votes -1,
- New = Head#track{votes = Votes},
+ Votes = Head#track.lock = false,
+ New = Head#track{lock = Votes},
mnesia:write(New)
end,
mnesia:transaction(F).