ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/DecentralizedMedia/DecentralizedMedia.cpp
(Generate patch)

Comparing DecentralizedMedia/DecentralizedMedia.cpp (file contents):
Revision 503 by douglas, 2005-06-18T01:34:41-07:00 vs.
Revision 507 by douglas, 2005-06-19T02:13:56-07:00

# Line 15 | Line 15
15   #include <menes-ios/helpers.hpp>
16   #include <menes-net/http/request.hpp>
17   #include <menes-net/http/response.hpp>
18 + #include <menes-xml/document.hpp>
19 + #include <menes-xml/parse.hpp>
20  
21   #include "DecentralizedMedia.hpp"
22  
# Line 52 | Line 54 | DecentralizedMedia::DecentralizedMedia(c
54   {
55          connection->Execute(_B("UPDATE files SET live = FALSE"));
56  
55        _foreach (const ext::RedBlackSet<ext::String>, local, locals)
56                MediaFolder(connection, *local, *local);
57
57          {
58 <                _L<ext::String> args(locals.Begin(), locals.End());
60 <
61 <                args.InsertLast(_B("-type"));
62 <                args.InsertLast(_B("d"));
58 >                _L<ext::String> args;
59  
60                  _foreach (const ext::RedBlackSet<ext::String>, extension, extensions)
61 <                {
62 <                        args.InsertLast(_B("-or"));
63 <                        args.InsertLast(_B("-iname"));
64 <                        args.InsertLast(_S<ios::String>() << _B("*.") << *extension);
65 <                }
66 <
67 <                _H<api::Process> find(new api::Process(_B("/usr/bin/find"), args));
68 <                ext::String file;
73 <                api::Path root;
74 <
75 <                while (ios::ReadLine(*find->GetReader(), file))
76 <                        if (locals.Contains(file))
77 <                                root = file;
78 <                        else
79 <                        {
80 <                                api::Path path(file);
81 <
82 <                                if (path.IsDirectory())
83 <                                        MediaFolder(connection, path, root);
84 <                                else
85 <                                        MediaFile(connection, path, ext::EmptyString, ext::EmptyString, ext::EmptyString, ext::EmptyString, root);
86 <                        }
61 >                        args.InsertLast(_S<ios::String>() << "-extension=" << *extension);
62 >
63 >                _foreach (const ext::RedBlackSet<ext::String>, local, locals)
64 >                        args.InsertLast(_S<ios::String>() << "-local=" << *local);
65 >
66 >                _H<api::Process> media(new api::Process(api::RealPath(_B("Util/media")), args));
67 >
68 >                Media(*media->GetReader());
69  
70 <                find->Join();
70 >                media->Join();
71          }
72  
73          AddPort(6996);
# Line 160 | Line 142 | _L<MediaFolder> DecentralizedMedia::GetF
142  
143   void DecentralizedMedia::Process(const net::Http::Request& request, net::Http::Response& response)
144   {
145 <        if (request.method_ == _B("EXTENSIONS"))
145 >        if (request.method_ == _B("EXTENSIONS") || request.method_ == _B("GET") && request.uri_.GetUri() == ext::EmptyString)
146          {
147 +                api::Cout << "EXTENSIONS" << ios::NewLine;
148 +
149                  response.SetStatus(200);
150  
151                  _foreach (const ext::RedBlackSet<ext::String>, extension, extensions)
152                          response << *extension << ios::NewLineNoFlush;
153          }
154 <        else if (request.method_ == _B("MEDIA"))
154 >        else if (request.method_ == _B("MEDIA") || request.method_ == _B("POST") && request.uri_.GetUri() == ext::EmptyString)
155          {
156 +                api::Cout << "MEDIA" << ios::NewLine;
157 +
158                  // XXX: implement
159          }
160          else
161                  waf::Server::Process(request, response);
162   }
163 +
164 + void DecentralizedMedia::Media(ios::Reader& media)
165 + {
166 +        _H<xml::Document> document(xml::Parse(media));
167 +        api::Pcre::RegEx share("^//(.+)/(.+)$");
168 +        
169 +        _foreach (const xml::NodeSet, folder, *document/"media"/"folder")
170 +        {
171 +                api::Pcre::RegEx::Match match;
172 +                ext::String path(**folder/"path");
173 +                // XXX: do something useful
174 +                api::Path root((match = share(path)) ? throw : path);
175 +
176 +                Media(*folder, root, root);
177 +        }
178 + }
179 +
180 + void DecentralizedMedia::Media(const _H<xml::Node>& folder, const api::Path& path, const api::Path& root)
181 + {
182 +        MediaFolder(connection, path, root);
183 +
184 +        _foreach (const xml::NodeSet, file, *folder/"file")
185 +                MediaFile(connection, path.GetChild(**file/"path"), **file/"artist", **file/"title", **file/"album", **file/"genre", root);
186 +
187 +        _foreach (const xml::NodeSet, folder_, *folder/"folder")
188 +                Media(*folder_, path.GetChild(**folder_/"path"), root);
189 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines