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 |
+ |
args.InsertLast(_B("-name")); |
52 |
+ |
args.InsertLast(_S<ios::String>() << _B("*.") << *extension); |
53 |
+ |
} |
54 |
+ |
|
55 |
+ |
_H<api::Process> find(new api::Process(_B("/usr/bin/find"), args)); |
56 |
+ |
ext::String file; |
57 |
+ |
|
58 |
+ |
while (ios::ReadLine(*find->GetReader(), file)) |
59 |
+ |
media.Insert(file); |
60 |
+ |
|
61 |
+ |
find->Join(); |
62 |
+ |
} |
63 |
+ |
|
64 |
|
AddPort(6996); |
65 |
|
} |
66 |
|
|
78 |
|
|
79 |
|
void DecentralizedMedia::Process(const net::Http::Request& request, net::Http::Response& response) |
80 |
|
{ |
81 |
< |
if (request.method_ == "PLAY") |
82 |
< |
api::Cout << "PLAY" << ios::NewLine; |
83 |
< |
else if (request.method_ == "PAUSE") |
84 |
< |
api::Cout << "PAUSE" << ios::NewLine; |
81 |
> |
if (request.method_ == _B("EXTENSIONS")) |
82 |
> |
{ |
83 |
> |
response.SetStatus(200); |
84 |
> |
|
85 |
> |
_foreach (const _L<ext::String>, extension, extensions) |
86 |
> |
response << *extension << "\r\n"; |
87 |
> |
|
88 |
> |
response << ios::Flush; |
89 |
> |
} |
90 |
> |
else if (request.method_ == _B("MEDIA")) |
91 |
> |
{ |
92 |
> |
// XXX: implement |
93 |
> |
} |
94 |
|
else |
95 |
|
waf::Server::Process(request, response); |
96 |
|
} |