6 |
|
|
7 |
|
#include <menes/standard.hh> |
8 |
|
|
9 |
+ |
#include <menes-api/pcre/regex.hpp> |
10 |
|
#include <menes-app/simple.hpp> |
11 |
|
#include <menes-etl/fnbind.hpp> |
12 |
+ |
#include <menes-ios/helpers.hpp> |
13 |
|
#include <menes-net/http/request.hpp> |
14 |
|
#include <menes-net/http/response.hpp> |
15 |
|
|
17 |
|
|
18 |
|
int Main(const app::Options& options) |
19 |
|
{ |
20 |
< |
DecentralizedMedia media; |
20 |
> |
_L<ext::String> extensions, locals; |
21 |
> |
api::Pcre::RegEx extension(_B("^-extension=(.+)$")), local(_B("^-local=(.+)$")); |
22 |
> |
|
23 |
> |
_foreach (const app::ArgumentList, arg, app::GetArguments()) |
24 |
> |
{ |
25 |
> |
api::Pcre::RegEx::Match match; |
26 |
> |
|
27 |
> |
if (match = extension(*arg)) |
28 |
> |
extensions.InsertLast(match[1]); |
29 |
> |
else if (match = local(*arg)) |
30 |
> |
locals.InsertLast(match[1]); |
31 |
> |
} |
32 |
> |
|
33 |
> |
if (extensions.IsEmpty()) |
34 |
> |
extensions.InsertLast(_B("mp3")); |
35 |
> |
|
36 |
> |
DecentralizedMedia media(extensions, locals); |
37 |
|
|
38 |
|
media.Block(); |
39 |
|
|
40 |
|
return 0; |
41 |
|
} |
42 |
|
|
43 |
< |
DecentralizedMedia::DecentralizedMedia() : waf::Server("Web"), process(bmp.IsRunning() ? NULL : new api::Process("/usr/X11R6/bin/beep-media-player")) |
43 |
> |
DecentralizedMedia::DecentralizedMedia(const _L<ext::String>& extensions, const _L<ext::String>& locals) : waf::Server(_B("Web")), process(bmp.IsRunning() ? NULL : new api::Process(_B("/usr/X11R6/bin/beep-media-player"))), extensions(extensions) |
44 |
|
{ |
45 |
+ |
if (!locals.IsEmpty()) |
46 |
+ |
{ |
47 |
+ |
_L<ext::String> args(locals); |
48 |
+ |
|
49 |
+ |
_foreach (const _L<ext::String>, extension, extensions) |
50 |
+ |
{ |
51 |
+ |
if (extension != _set.Begin()) |
52 |
+ |
args.InsertLast(_B("-or")); |
53 |
+ |
|
54 |
+ |
args.InsertLast(_B("-name")); |
55 |
+ |
args.InsertLast(_S<ios::String>() << _B("*.") << *extension); |
56 |
+ |
} |
57 |
+ |
|
58 |
+ |
_H<api::Process> find(new api::Process(_B("/usr/bin/find"), args)); |
59 |
+ |
ext::String file; |
60 |
+ |
|
61 |
+ |
while (ios::ReadLine(*find->GetReader(), file)) |
62 |
+ |
/*media.Insert(file)*/; |
63 |
+ |
|
64 |
+ |
find->Join(); |
65 |
+ |
} |
66 |
+ |
|
67 |
|
AddPort(6996); |
68 |
|
} |
69 |
|
|
81 |
|
|
82 |
|
void DecentralizedMedia::Process(const net::Http::Request& request, net::Http::Response& response) |
83 |
|
{ |
84 |
< |
if (request.method_ == "PLAY") |
85 |
< |
api::Cout << "PLAY" << ios::NewLine; |
86 |
< |
else if (request.method_ == "PAUSE") |
87 |
< |
api::Cout << "PAUSE" << ios::NewLine; |
84 |
> |
if (request.method_ == _B("EXTENSIONS")) |
85 |
> |
{ |
86 |
> |
response.SetStatus(200); |
87 |
> |
|
88 |
> |
_foreach (const _L<ext::String>, extension, extensions) |
89 |
> |
response << *extension << ios::NewLineNoFlush; |
90 |
> |
} |
91 |
> |
else if (request.method_ == _B("MEDIA")) |
92 |
> |
{ |
93 |
> |
// XXX: implement |
94 |
> |
} |
95 |
|
else |
96 |
|
waf::Server::Process(request, response); |
97 |
|
} |