diff options
author | Jakob Pfender <jpfender@zedat.fu-berlin.de> | 2010-10-14 16:34:44 +0200 |
---|---|---|
committer | Jakob Pfender <jpfender@zedat.fu-berlin.de> | 2010-10-14 16:34:44 +0200 |
commit | a53e0ebbf1e466abd0fce29688eb4112e7e6bff5 (patch) | |
tree | 4bcb80aa32bec556d717e3338e6d96e32d4ba989 | |
parent | 83c76ed4f695dfd033308c663024f7a7e51c13e2 (diff) | |
parent | 3ab5da8355e114953c154114aa4c0c36b719e92e (diff) | |
download | erlang-a53e0ebbf1e466abd0fce29688eb4112e7e6bff5.tar.gz erlang-a53e0ebbf1e466abd0fce29688eb4112e7e6bff5.tar.xz erlang-a53e0ebbf1e466abd0fce29688eb4112e7e6bff5.zip |
documentation for media.erl
-rw-r--r-- | ac/allison crowe/01 - Northern Lights.mp3 | bin | 3644552 -> 0 bytes | |||
-rw-r--r-- | ac/allison crowe/02 - Angels.mp3 | bin | 4988418 -> 0 bytes | |||
-rw-r--r-- | ac/allison crowe/03 - Disease (08 03 08).mp3 | bin | 10424149 -> 0 bytes | |||
-rw-r--r-- | ac/allison crowe/04 - Little Light.mp3 | bin | 3990623 -> 0 bytes | |||
-rw-r--r-- | ac/allison crowe/05 - Happy People.mp3 | bin | 3760791 -> 0 bytes | |||
-rw-r--r-- | ac/allison crowe/06 - Hold Back.mp3 | bin | 3487965 -> 0 bytes | |||
-rw-r--r-- | ac/allison crowe/07 - Choose to Be.mp3 | bin | 4132180 -> 0 bytes | |||
-rw-r--r-- | ac/allison crowe/08 - Wedding Song.mp3 | bin | 3345972 -> 0 bytes | |||
-rw-r--r-- | ac/allison crowe/License.txt | 12 | ||||
-rw-r--r-- | ac/allison crowe/Readme - www.jamendo.com .txt | 254 | ||||
-rw-r--r-- | ac/allison crowe/[cover] Allison Crowe - Little Light (originals).jpg | bin | 3157 -> 0 bytes | |||
-rw-r--r-- | client/client.erl | 51 | ||||
-rw-r--r-- | server/cldb.erl | 47 | ||||
-rw-r--r-- | server/media.erl | 48 |
14 files changed, 104 insertions, 308 deletions
diff --git a/ac/allison crowe/01 - Northern Lights.mp3 b/ac/allison crowe/01 - Northern Lights.mp3 Binary files differdeleted file mode 100644 index fc79340..0000000 --- a/ac/allison crowe/01 - Northern Lights.mp3 +++ /dev/null diff --git a/ac/allison crowe/02 - Angels.mp3 b/ac/allison crowe/02 - Angels.mp3 Binary files differdeleted file mode 100644 index e1011b2..0000000 --- a/ac/allison crowe/02 - Angels.mp3 +++ /dev/null diff --git a/ac/allison crowe/03 - Disease (08 03 08).mp3 b/ac/allison crowe/03 - Disease (08 03 08).mp3 Binary files differdeleted file mode 100644 index 25886e2..0000000 --- a/ac/allison crowe/03 - Disease (08 03 08).mp3 +++ /dev/null diff --git a/ac/allison crowe/04 - Little Light.mp3 b/ac/allison crowe/04 - Little Light.mp3 Binary files differdeleted file mode 100644 index 2dd8cff..0000000 --- a/ac/allison crowe/04 - Little Light.mp3 +++ /dev/null diff --git a/ac/allison crowe/05 - Happy People.mp3 b/ac/allison crowe/05 - Happy People.mp3 Binary files differdeleted file mode 100644 index b379be5..0000000 --- a/ac/allison crowe/05 - Happy People.mp3 +++ /dev/null diff --git a/ac/allison crowe/06 - Hold Back.mp3 b/ac/allison crowe/06 - Hold Back.mp3 Binary files differdeleted file mode 100644 index f3c0697..0000000 --- a/ac/allison crowe/06 - Hold Back.mp3 +++ /dev/null diff --git a/ac/allison crowe/07 - Choose to Be.mp3 b/ac/allison crowe/07 - Choose to Be.mp3 Binary files differdeleted file mode 100644 index d9bd188..0000000 --- a/ac/allison crowe/07 - Choose to Be.mp3 +++ /dev/null diff --git a/ac/allison crowe/08 - Wedding Song.mp3 b/ac/allison crowe/08 - Wedding Song.mp3 Binary files differdeleted file mode 100644 index 017e2e0..0000000 --- a/ac/allison crowe/08 - Wedding Song.mp3 +++ /dev/null diff --git a/ac/allison crowe/License.txt b/ac/allison crowe/License.txt deleted file mode 100644 index 040e8da..0000000 --- a/ac/allison crowe/License.txt +++ /dev/null @@ -1,12 +0,0 @@ -
-Track | License URL
-----------------------------------------------
- 01 | http://creativecommons.org/licenses/by-nc-sa/3.0/
- 02 | http://creativecommons.org/licenses/by-nc-sa/3.0/
- 03 | http://creativecommons.org/licenses/by-nc-sa/3.0/
- 04 | http://creativecommons.org/licenses/by-nc-sa/3.0/
- 05 | http://creativecommons.org/licenses/by-nc-sa/3.0/
- 06 | http://creativecommons.org/licenses/by-nc-sa/3.0/
- 07 | http://creativecommons.org/licenses/by-nc-sa/3.0/
- 08 | http://creativecommons.org/licenses/by-nc-sa/3.0/
- artwork | http://creativecommons.org/licenses/by-nc-sa/3.0/
\ No newline at end of file diff --git a/ac/allison crowe/Readme - www.jamendo.com .txt b/ac/allison crowe/Readme - www.jamendo.com .txt deleted file mode 100644 index 8126e88..0000000 --- a/ac/allison crowe/Readme - www.jamendo.com .txt +++ /dev/null @@ -1,254 +0,0 @@ -This 'Readme' file is available below in: English, Français, Italiano, Español, Deutsch, Polski, Русский, Português. - - - - - -Thank you for downloading this album! - -It’s FREE and LEGAL distribution by Jamendo: - -http://www.jamendo.com/ - -On the website you'll be able to: - - - Write a review about the album and check out other reviews already written by members of our community. - - - Obtain more information about the artist and/or album. - - - Download other quality music for FREE. - - - Learn more about Jamendo. Sign up and post messages in our forums. - - - Make a donation to the artist to support them. - - -Visit Jamendo and help us promote FREE music! - -Thanks again, we hope you enjoy listening to this album. - ---- -The Jamendo team. - - - -------------------- - - - -Merci d'avoir téléchargé cet album ! - -Sa diffusion gratuite et légale est assurée par jamendo : - -http://www.jamendo.com/ - -Sur ce site, vous pourrez, entre autres : - - - Déposer une critique sur cet album, et consulter les nombreuses critiques déjà présentes. - - - Obtenir plus d'informations sur l'artiste auteur de cet album. - - - Télécharger d'autres albums de qualité, complets et gratuits. - - - Vous informer sur la contribution de jamendo en faveur d'une musique gratuite et légale, et participer au forum de jamendo. - - - Rejoindre son fan-club pour être tenu au courant des prochains concerts, sorties d'albums, ... c'est en même temps un petit geste de soutien ! - - -Alors n'hésitez pas à nous rendre visite, pour apporter votre soutien à notre action et nous aider à prouver qu'une autre musique est possible, une musique libre ! - - -Merci, et bonne écoute ! - ---- -L'équipe de jamendo. - - - -------------------- - - - -Grazie per avere scaricato questo album! - -La sua distribuzione legale e veloce è fatta da jamendo: - -http://www.jamendo.com/ - -Tramite questo sito sarai in grado di: - - - scrivere una recensione su questo album e leggere le altre recensioni già scritte dagli altri membri della nostra comunità; - - - ottenere maggiori informazioni su questo album/artista; - - - scaricare altri album interi di qualità, gratuitamente; - - - saperne di più su jamendo, registrarti, inserire messaggi nei nostri forum. - - - fare una donazione a questo artista per supportare il suo album. - -Quindi visita liberamente jamendo e aiutaci a promuovere la musica libera! Grazie ancora! - ----- -Il team di jamendo. - - - -------------------- - - - -Gracias por descargar este álbum ! - -Su distribución gratis y legal es realizada por jamendo : - -http://www.jamendo.com/ - -En el sitio web, podrás : - - - Escribir tu opinión sobre este álbum, y checar todas las opiniones ya escritas por miembros de la comunidad jamendo. - - - Obtener mayor información sobre este artista/álbum. - - - Descargar otros álbumes de calidad, gratis. - - - Aprender más sobre jamendo, escribir un mensaje en los foros. - - - Hacer una donación a este artista para apoyarlo. - - -No dudes en visitar jamendo, y ayúdanos a promover música gratis y de buena calidad ! - -Gracias otra vez, que pases un buen rato oyendo este álbum ! - ---- -El equipo de jamendo. - - - -------------------- - - - -Vielen Dank für den Download dieses Albums! - -Die freie und legale Distribution wird von Jamendo gewährleistet: - -http://www.jamendo.com - -Auf dieser Webseite kannst du auch: - - - eine Rezension zu diesem Album schreiben und die zahlreichen anderen Rezensionen lesen. - - - mehr Informationen zu diesem Album und dem/den Künstler/n einsehen. - - - kostenlos weitere komplette Alben herunterladen. - - - mehr über Jamendo und dessen Unterstützung einer kostenlosen und legalen Verbreitung von Musik erfahren und an unseren Foren teilnehmen. - - - dem Fanclub des Künstlers beitreten, um Infos über Konzerte und neue Alben zu erhalten - und ihn damit auch zu unterstützen! - - -Besuche Jamendo jederzeit und unterstütze unsere Aktion: Denn wir suchen nach einer anderen Musik, nämlich freie Musik! - -Nochmals vielen Dank und viel Spaß beim Hören dieses Albums! - ---- -Das Jamendo-Team - - - -------------------- - - - -Dziękujemy za pobranie tego albumu! - -Jego darmowa i legalna dystrybucja odbywa się przez jamendo: - -http://www.jamendo.com/ - -Na stronie tej możesz: - - - Napisać opinię o tym albumie oraz sprawdzić opinie napisane już przez innych użytkowników. - - - Zdobyć więcej informacji o tym artyście/albumie. - - - Pobrać inne albumy w dobrej jakości, za darmo. - - - Dowiedzieć się więcej o jamendo, zarejestrować, wysyłać wiadomości na nasze fora. - - - Wpłacić pieniądze dla artysty, aby go wesprzeć. - -Nie wahaj się więc odwiedzić jamendo i pomóż nam promować wolną muzykę! - -Jeszcze raz dzięki, życzymy miłego czasu spędzonego przy słuchaniu albumu! - ---- -Zespół jamendo. - - - -------------------- - - - -Спасибо за скачивание этого альбома! -Это бесплатно, и он легально распространяется Jamendo: - -http://www.jamendo.com/ - - -На этом сайте вы сможете: -- Написать рецензию на этот альбом, и просмотреть все остальные рецензии, уже написанные членами нашего сообщества. -- Получить больше информации о данном исполнителе/альбоме. -- Скачать бесплатно другие качественные полные альбомы. -- Узнать больше о Jamendo, зарегистрироваться, оставлять сообщения на наших форумах. -- Сделать пожертвование этому исполнителю для его поддержки - -Поэтому, не стесняйтесь, заходите на Jamendo и помогайте нам нести в массы бесплатную музыку! - -Еще раз спасибо, желаем Вам отличного прослушивания этого альбома! - --- -Команда Jamendo. - - - -------------------- - - - -Obrigado por baixar esta álbum! - -Sua distribuição gratuita e legal é assegurada pelo Jamendo: - -http://www.jamendo.com/ - -Sobre o site, você pode também: - - - Fazer críticas aos álbuns e consultas críticas já feitas. - - - Obter mais informações sobre o artista autor deste álbum. - - - Baixar outros álbuns de qualidade, completos e gratuitos. - - - Se informar sobre a contribuição do Jamendo em favor da música gratuita e legal, além de participar do fórum do Jamendo. - - - Participar de seu fã-club para ficar por dentro de seus shows, lançamento de álbuns, etc... E fazer doações ao artista! - - -Não deixe de nos fazer uma visita e ajudar a promover a música livre! - - -Obrigado, e boa música! - ---- -Equipe do Jamendo. - - - -------------------- - - - diff --git a/ac/allison crowe/[cover] Allison Crowe - Little Light (originals).jpg b/ac/allison crowe/[cover] Allison Crowe - Little Light (originals).jpg Binary files differdeleted file mode 100644 index 90091ae..0000000 --- a/ac/allison crowe/[cover] Allison Crowe - Little Light (originals).jpg +++ /dev/null diff --git a/client/client.erl b/client/client.erl index 46ef59f..0e2fada 100644 --- a/client/client.erl +++ b/client/client.erl @@ -1,19 +1,15 @@ -module(client). -export([register/3, login/3, list/0, handle/2, getVotes/0, vote/2, devote/2]). -contains([], _) -> - false; -contains([H|_], H) -> - true; -contains([_|T], Search) -> - contains(T, Search). - checkLogin(Value) -> - checkLogin(Value, contains(registered(), cli)). -checkLogin(Value, Value) -> - true; -checkLogin(_, _) -> - throw({error, login_state}). + %% check if user meets the requirements to be locked in or not by + %% locking in to the registered processes and check if the cli + %% process is registered + LoggedIn = lists:member(cli, registered()), + if LoggedIn == Value -> + true; + true -> throw({error, login_state}) + end. buildNode(Server) -> list_to_atom("distributed_music_system_main_node@" ++ Server). @@ -82,33 +78,26 @@ handle({change_state, NewState}, _) -> handle(Cmd, Server) -> {{error, {unknown_command, Cmd}}, Server}. -%queries the server for the current votes this client possesses -getVotes() -> +try_logged_in_rpc(Rpc) -> + %% tries to execute an rpc for logged in user and returns error + %% message if user is not logged in try checkLogin(true) of _ -> - server:rpc(cli, get_votes) + server:rpc(cli, Rpc) catch {error, login_state} -> {error, not_logged_in} end. -%positive vote, increments the votes for {Artist, Title} by one +getVotes() -> + %% queries the server for the current votes this client possesses + try_logged_in_rpc(get_votes). + vote(Artist, Title) -> - try checkLogin(true) of - _ -> - server:rpc(cli, {vote, Artist, Title}) - catch - {error, login_state} -> - {error, not_logged_in} - end. + %% positive vote, increments the votes for {Artist, Title} by one + try_logged_in_rpc({vote, Artist, Title}). -%negative vote, decrements the votes for {Artist, Title} by one devote(Artist, Title) -> - try checkLogin(true) of - _ -> - server:rpc(cli, {devote, Artist, Title}) - catch - {error, login_state} -> - {error, not_logged_in} - end. + %% negative vote, decrements the votes for {Artist, Title} by one + try_logged_in_rpc({devote, Artist, Title}). diff --git a/server/cldb.erl b/server/cldb.erl index 0f9f407..982aafc 100644 --- a/server/cldb.erl +++ b/server/cldb.erl @@ -1,12 +1,53 @@ % The clientdatabase -module(cldb). --export([init/0]). --record(user, {name, passwd, votes}). +-export([init/0, ask/2, login/2, decVote/2, incVote/2, register/3, check_rights/2]). +-record(user, {name, passwd, votes, rights}). init() -> mnesia:create_schema([node()]), mnesia:start(), - mnesia:create_table(track, [{attributes, record_info(fields, track)}]), + mnesia:create_table(user, [{attributes, record_info(fields, user)}]), io:format("Userdb up and running \n"). +ask(User, Pwd) -> + F = fun() -> + mnesia:match_object({user, User, Pwd, '_'}) + end, + mnesia:transaction(F). + + + +login(User, Pwd) -> + {_, Reason} = ask(User, Pwd), + Reason. + +register(User, Pwd, Root) -> + F = fun() -> + mnesia:write(#user{name = User, passwd = Pwd, votes = 5, rights = Root}) + end, + {_, Reason} = mnesia:transaction(F), + Reason. + +decVote(User, Pwd) -> + F = fun() -> + [Head|_] = ask(User, Pwd), + Votes = Head#user.votes - 1, + New = Head#user{votes = Votes}, + mnesia:write(New) + end, + mnesia:transaction(F). + +incVote(User, Pwd) -> + F = fun() -> + [Head|_] = ask(User, Pwd), + Votes = Head#user.votes + 1, + New = Head#user{votes = Votes}, + mnesia:write(New) + end, + mnesia:transaction(F). + +check_rights(User, Name) -> + {_, _, Rights} = ask(User, Name), + Rights. + diff --git a/server/media.erl b/server/media.erl index 0ef5a44..d6adc5b 100644 --- a/server/media.erl +++ b/server/media.erl @@ -1,5 +1,5 @@ -module(media). --export([init/0,insert/3, ask/2, all/0, play/3, vote/2, devote/2, lock_process/2]). +-export([init/0,insert/3, ask/2, all/0, play/2, vote/2, devote/2, lock_process/2]). -define(TESTPATTERN, "../ac/*.mp3"). -define(TIMEOUT, 100000000). @@ -59,7 +59,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 @@ -72,7 +76,7 @@ search_best([], _, Track) -> {Track#track.artist, Track#track.title}. % if nothing is playable anymore (because all songs are locked) just reset all songs and start playing again... -reset_all([Head|Rest) -> +reset_all([Head|Rest]) -> unlock(Head#track.artist, Head#track.title), reset_all(Rest); reset_all([]) -> ok. @@ -104,18 +108,22 @@ play(Artist, Title) -> {_, Title, Artist, _, _, Fp} = Head, Port = erlang:open_port({spawn_executable, "/usr/bin/mplayer"}, [{args, [Fp]}, exit_status]), reset_votes(Artist, Title), - lock_process(Artist, Title), + spawn(media, lock_process, [Artist, Title]), io:format("playing: ~s, Artist: ~s~n", [Title, Artist]), receive {Port, {exit_status, 0}} -> start_playing(); {Port, {exit_status, S}} -> throw({commandfailed, S}) end. +<<<<<<< HEAD % Of course we need a query to find out what the highest voted track is. % We accomplish this by requesting all the records from the database and then iterate over them, just taking a look at the vote % variable, so it is like a list of integers. In case no tracks were voted for we just take the first track we found and play it. Of course this song is locked afterwards so a different one will be chosen. +======= +%Increase the vote in the database so it will hopefully be played in the future +>>>>>>> 3ab5da8355e114953c154114aa4c0c36b719e92e %votes for a track, i.e. increases its vote count by one. vote(Artist, Title) -> @@ -127,7 +135,12 @@ vote(Artist, Title) -> end, mnesia:transaction(F). +<<<<<<< HEAD %votes against a track, i.e. decreases its vote count by one. +======= +% decrease votes in database + +>>>>>>> 3ab5da8355e114953c154114aa4c0c36b719e92e devote(Artist, Title) -> F = fun() -> [Head|_] = ask(Artist, Title), @@ -137,7 +150,12 @@ devote(Artist, Title) -> end, mnesia:transaction(F). +<<<<<<< HEAD %resets the vote count of selected track to 0 (this is called when the song is played). +======= +% Reset votes to zero in database + +>>>>>>> 3ab5da8355e114953c154114aa4c0c36b719e92e reset_votes(Artist, Title) -> F = fun() -> [Head|_] = ask(Artist, Title), @@ -146,28 +164,42 @@ reset_votes(Artist, Title) -> end, mnesia:transaction(F). +<<<<<<< HEAD %locks a song so it can't be played again or voted for for that time. +======= +% Lock a song + +>>>>>>> 3ab5da8355e114953c154114aa4c0c36b719e92e lock(Artist, Title) -> F = fun() -> [Head|_] = ask(Artist, Title), - Votes = Head#track.lock = true, - New = Head#track{lock = Votes}, + New = Head#track{locked = true}, mnesia:write(New) end, mnesia:transaction(F). +<<<<<<< HEAD %unlocks a song so it can be played and voted for again. +======= +% Unlock a song... + +>>>>>>> 3ab5da8355e114953c154114aa4c0c36b719e92e unlock(Artist, Title) -> F = fun() -> [Head|_] = ask(Artist, Title), - Votes = Head#track.lock = false, - New = Head#track{lock = Votes}, + New = Head#track{locked = false}, mnesia:write(New) end, mnesia:transaction(F). +<<<<<<< HEAD %locks a song and then waits for a specified amount of time before unlocking it again. %this is called when the song is played. +======= +% 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. + +>>>>>>> 3ab5da8355e114953c154114aa4c0c36b719e92e lock_process(Artist, Title) -> lock(Artist, Title), receive |