aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorMarco Ziener <mziener@lavabit.com>2010-10-14 16:03:22 +0200
committerMarco Ziener <mziener@lavabit.com>2010-10-14 16:03:22 +0200
commit693e7c44bb65db596606a16e1fbce338a09b9af4 (patch)
tree7867bf5c1289db42faef6c933b284ea7d86b89b7 /server
parentd4974ca3ef2f4e664a78912837989762997d14dd (diff)
parent4ce4e290a0557e616650ddb004f70cff2082e757 (diff)
downloaderlang-693e7c44bb65db596606a16e1fbce338a09b9af4.tar.gz
erlang-693e7c44bb65db596606a16e1fbce338a09b9af4.tar.xz
erlang-693e7c44bb65db596606a16e1fbce338a09b9af4.zip
Merge branch 'master' of ssh://git.animux.de/erlang
Diffstat (limited to 'server')
-rw-r--r--server/media.erl22
1 files changed, 16 insertions, 6 deletions
diff --git a/server/media.erl b/server/media.erl
index 561a2c7..165338b 100644
--- a/server/media.erl
+++ b/server/media.erl
@@ -55,7 +55,11 @@ insert(Artist, Title, Filepath) ->
end,
mnesia:transaction(F).
-% search the track with the highest votes and return {Artist, Title}
+% 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.
+
search_best([Head|Rest], Max_Votes, Track) ->
if
@@ -107,11 +111,7 @@ play(Artist, Title) ->
{Port, {exit_status, 0}} -> start_playing();
{Port, {exit_status, S}} -> throw({commandfailed, S})
end.
-
-
-% 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.
+%Increase the vote in the database so it will hopefully be played in the future
vote(Artist, Title) ->
F = fun() ->
@@ -122,6 +122,8 @@ vote(Artist, Title) ->
end,
mnesia:transaction(F).
+% decrease votes in database
+
devote(Artist, Title) ->
F = fun() ->
[Head|_] = ask(Artist, Title),
@@ -131,6 +133,8 @@ devote(Artist, Title) ->
end,
mnesia:transaction(F).
+% Reset votes to zero in database
+
reset_votes(Artist, Title) ->
F = fun() ->
[Head|_] = ask(Artist, Title),
@@ -139,6 +143,7 @@ reset_votes(Artist, Title) ->
end,
mnesia:transaction(F).
+% Lock a song
lock(Artist, Title) ->
F = fun() ->
@@ -148,6 +153,8 @@ lock(Artist, Title) ->
end,
mnesia:transaction(F).
+% Unlock a song...
+
unlock(Artist, Title) ->
F = fun() ->
[Head|_] = ask(Artist, Title),
@@ -156,6 +163,9 @@ unlock(Artist, Title) ->
end,
mnesia:transaction(F).
+% Lock a song if it was just played, after a Timeout it will be unlocked automaticly
+% If all songs are locked, all will be unlocked.
+
lock_process(Artist, Title) ->
lock(Artist, Title),
receive