diff options
author | Marco Ziener <mziener@lavabit.com> | 2010-10-14 10:52:19 +0200 |
---|---|---|
committer | Marco Ziener <mziener@lavabit.com> | 2010-10-14 10:52:19 +0200 |
commit | 487a46b7a4407ac3612c840d9ead93d73c642d8a (patch) | |
tree | 59c727ffe4761a4d1f7e6e2ba6fc3d86d4318bed /server | |
parent | da9da98db8f80ce58383b1f9976da3ae5e813c5b (diff) | |
parent | 1b6c636b0584d1264209fab522c4476082f0e0fd (diff) | |
download | erlang-487a46b7a4407ac3612c840d9ead93d73c642d8a.tar.gz erlang-487a46b7a4407ac3612c840d9ead93d73c642d8a.tar.xz erlang-487a46b7a4407ac3612c840d9ead93d73c642d8a.zip |
merged
Diffstat (limited to 'server')
-rw-r--r-- | server/media.erl | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/server/media.erl b/server/media.erl index 1c41c89..851cc21 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, vote/2, devote/2]). +-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, [], {index, [y]}, {type, bag}, [{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) -> |