aboutsummaryrefslogtreecommitdiffstats
path: root/media.erl
diff options
context:
space:
mode:
authorMarco Ziener <mziener@lavabit.com>2010-10-13 01:24:13 +0200
committerMarco Ziener <mziener@lavabit.com>2010-10-13 01:24:13 +0200
commit7ea56a60b730409a262eff6a753ab1c00c0373f0 (patch)
tree3cc6677331ae33f8f55c583a60f971b289b1f3ad /media.erl
parentbb8acbad83ebd98a9d43244b9b056de8a43de29c (diff)
downloaderlang-7ea56a60b730409a262eff6a753ab1c00c0373f0.tar.gz
erlang-7ea56a60b730409a262eff6a753ab1c00c0373f0.tar.xz
erlang-7ea56a60b730409a262eff6a753ab1c00c0373f0.zip
Audiofiles geadded && mediamodul angefangen zu schreiben
Diffstat (limited to 'media.erl')
-rw-r--r--media.erl49
1 files changed, 49 insertions, 0 deletions
diff --git a/media.erl b/media.erl
index e69de29..13e84c3 100644
--- a/media.erl
+++ b/media.erl
@@ -0,0 +1,49 @@
+-module(media).
+-export([init/0,insert/3, ask/2]).
+
+% 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.
+% Concerning the parsing of id3tags we use the library id3v2 by Brendon Hogger. For detailed information take a
+% look at the header of the library.
+
+% What is an entry in our database made of? By the way the filepath includes the filename.
+
+-record(track, {artist, title, votes, locked, filepath }).
+
+% With which application do we play mp3s?
+
+player(path) ->
+ {ok, ["/usr/bin/env", "mplayer", "-quiet", path]}.
+
+% Before this module becomes usable, we must initialize it with the following steps:
+% 1. Initialize the mnesiadatabase and create the table within it.
+% 2. Parse the mp3s in the working directory and add them to the database
+% 3. Get into a loop so the database can be actually queried and files can be played.
+
+init() ->
+ mnesia:create_schema([node()]),
+ mnesia:start(),
+ mnesia:create_table(track, [{attributes, record_info(fields, track)}]),
+ io:format("Initialisation of mnesia successful.\n").
+
+% Basic insertion of entrys into the database. Some entries are left out because they are 0 or false.
+
+insert(Artist, Title, Filepath) ->
+ F = fun() ->
+ mnesia:write(#track{artist = Artist, title = Title, votes = 0, locked = false, filepath = Filepath})
+ end,
+ mnesia:transaction(F).
+
+% We want to query in order to simplify the next calls.
+ask(Artist, Title) ->
+ F = fun() ->
+ mnesia:match_object({track, Artist, Title, '_', '_', '_'})
+ end,
+ {atomic, Results} = mnesia:transaction(F),
+ Results.
+
+% We want to play mp3s from our database.
+play(Artist, Title) -> io:format("blub").
+
+
+