From: <kro...@us...> - 2010-12-08 14:50:51
|
Revision: 4020 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=4020&view=rev Author: kroko_koenig Date: 2010-12-08 14:50:44 +0000 (Wed, 08 Dec 2010) Log Message: ----------- using mp3 shares, random.jpg for all dirs Modified Paths: -------------- trunk/plugins/AndroidRemote/Release/Android Server communication.docx trunk/plugins/AndroidRemote/Server/AndroidRemote/AndroidServer.cs trunk/plugins/AndroidRemote/Server/AndroidRemote/Request.cs trunk/plugins/AndroidRemote/Server/AndroidRemote.suo Modified: trunk/plugins/AndroidRemote/Release/Android Server communication.docx =================================================================== (Binary files differ) Modified: trunk/plugins/AndroidRemote/Server/AndroidRemote/AndroidServer.cs =================================================================== --- trunk/plugins/AndroidRemote/Server/AndroidRemote/AndroidServer.cs 2010-12-08 13:35:27 UTC (rev 4019) +++ trunk/plugins/AndroidRemote/Server/AndroidRemote/AndroidServer.cs 2010-12-08 14:50:44 UTC (rev 4020) @@ -44,8 +44,6 @@ public static string Server = string.Empty; public static string Port = string.Empty; - public static string PicturePath = string.Empty; - public static string MusicPath = string.Empty; public static string VideoPath = string.Empty; private Thread listen; @@ -73,10 +71,6 @@ Server = xmlreader.GetValueAsString("android", "server", "192.168.0.30"); Port = xmlreader.GetValueAsString("android", "port", "8200"); - PicturePath = xmlreader.GetValueAsString("android", "pictures", - Environment.GetFolderPath(Environment.SpecialFolder.MyPictures)); - MusicPath = xmlreader.GetValueAsString("android", "music", - Environment.GetFolderPath(Environment.SpecialFolder.MyMusic)); VideoPath = xmlreader.GetValueAsString("android", "videos", Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)); } Modified: trunk/plugins/AndroidRemote/Server/AndroidRemote/Request.cs =================================================================== --- trunk/plugins/AndroidRemote/Server/AndroidRemote/Request.cs 2010-12-08 13:35:27 UTC (rev 4019) +++ trunk/plugins/AndroidRemote/Server/AndroidRemote/Request.cs 2010-12-08 14:50:44 UTC (rev 4020) @@ -55,12 +55,13 @@ private byte[] buffer; private static Bitmap actualCover = null; - private static string[] listAllPictures = null; private SQLiteClient sqlClient; private VirtualDirectory virtualDirectory = new VirtualDirectory(); - private Dictionary<string, string> dirList = new Dictionary<string, string>(); + private Dictionary<string, string> directoryList = new Dictionary<string, string>(); + private static List<string> allPicturesList = null; + public Request(Socket Socket) { socket = Socket; @@ -227,13 +228,13 @@ else if (req.StartsWith("/music")) { // handle pictures - req = req.Replace("/music", ""); + req = req.Substring(6); if (req.StartsWith("/")) req = req.Substring(1); if (req == "") { // root - ReplyMusicDir(AndroidServer.MusicPath, "root"); + ReplyMusicDir(""); } else { @@ -241,12 +242,11 @@ if (req.EndsWith(".mp3")) { - string orgPath = AndroidServer.MusicPath + "\\" + req; - ReplyMusicFile(orgPath, msgTyp); + ReplyMusicFile(req, msgTyp); } else { - ReplyMusicDir(AndroidServer.MusicPath + "\\" + req, req); + ReplyMusicDir(req); } } } @@ -556,8 +556,8 @@ private void ReplyPictureDir(string Request) { - GetPictureShare(); - string dir = GetLocalDir(Request); + directoryList = GetMpShare("pictures"); + string dir = GetLocalDir(Request, directoryList); if (Request == string.Empty) { @@ -574,7 +574,7 @@ msg += "<Directory>\r\n"; // folder - foreach (string key in dirList.Keys) + foreach (string key in directoryList.Keys) { msg += "<Folder>" + HttpUtility.HtmlEncode(key) + "</Folder>\r\n"; } @@ -633,8 +633,8 @@ } private void ReplyPictureFile(string filePath) { - GetPictureShare(); - string dir = GetLocalDir(filePath); + directoryList = GetMpShare("pictures"); + string dir = GetLocalDir(filePath, directoryList); if (File.Exists(dir)) { @@ -681,8 +681,8 @@ { filePath = filePath.Replace(".thb", ""); - GetPictureShare(); - string dir = GetLocalDir(filePath); + directoryList = GetMpShare("pictures"); + string dir = GetLocalDir(filePath, directoryList); if (File.Exists(dir)) { @@ -739,7 +739,7 @@ if (year != string.Empty) { msg += "<Item>\r\n"; - msg += "<Year>" + HttpUtility.HtmlEncode(year).Replace(" ","%20") + "</Year>\r\n"; + msg += "<Year>" + HttpUtility.HtmlEncode(year).Replace(" ", "%20") + "</Year>\r\n"; msg += "</Item>\r\n"; } } @@ -941,10 +941,15 @@ } } - private void ReplyMusicDir(string dir, string request) + private void ReplyMusicDir(string Request) { - if (Directory.Exists(dir)) + directoryList = GetMpShare("music"); + string dir = GetLocalDir(Request, directoryList); + + if (Request == string.Empty) { + #region root shares + string msg = string.Empty; // header msg += "HTTP/1.0 200 Ok\r\n"; @@ -955,27 +960,61 @@ msg += "<?xml version=\"1.0\"?>\r\n"; msg += "<Directory>\r\n"; - string[] dirs = Directory.GetDirectories(dir, "*.*", SearchOption.TopDirectoryOnly); - foreach (string f in dirs) + // folder + foreach (string key in directoryList.Keys) { - msg += "<Folder>" + HttpUtility.HtmlEncode(Path.GetFileName(f)) + "</Folder>\r\n"; + msg += "<Folder>" + HttpUtility.HtmlEncode(key) + "</Folder>\r\n"; } - string[] files = Directory.GetFiles(dir, "*.mp3", SearchOption.TopDirectoryOnly); - foreach (string f in files) - { - string fName = Path.GetFileName(f); - if ((fName.ToLower() != "folder.jpg") && (fName.ToLower() != "folder.png")) - msg += "<File>" + HttpUtility.HtmlEncode(fName) + "</File>\r\n"; - } msg += "</Directory>\r\n"; // send sendMessage(socket, msg); - AndroidServer.logDebug("Reply music dir"); + AndroidServer.logDebug("Reply music root dir"); + + #endregion } else { - SendErrorURL(request); + #region reply dirs + + if (Directory.Exists(dir)) + { + string msg = string.Empty; + // header + msg += "HTTP/1.0 200 Ok\r\n"; + msg += "Content-Type: application/xml; charset=utf-8; filename=info.xml" + "\r\n"; + msg += "Proxy-Connection: close" + "\r\n"; + msg += "\r\n"; + // content + msg += "<?xml version=\"1.0\"?>\r\n"; + msg += "<Directory>\r\n"; + + // folder + string[] dirs = Directory.GetDirectories(dir, "*.*", SearchOption.TopDirectoryOnly); + foreach (string f in dirs) + { + msg += "<Folder>" + HttpUtility.HtmlEncode(Path.GetFileName(f)) + "</Folder>\r\n"; + } + + //files + string[] files = Directory.GetFiles(dir, "*.mp3", SearchOption.TopDirectoryOnly); + foreach (string f in files) + { + string fName = Path.GetFileName(f); + msg += "<File>" + HttpUtility.HtmlEncode(fName) + "</File>\r\n"; + } + msg += "</Directory>\r\n"; + // send + sendMessage(socket, msg); + AndroidServer.logDebug("Reply music dir"); + } + else + { + // dir does not exist + SendErrorURL(Request); + } + + #endregion } } private void ReplyMusicFile(string Filename, string Mode) @@ -1344,15 +1383,30 @@ private void ReplyRandomPicture() { - if (listAllPictures == null) - listAllPictures = Directory.GetFiles(AndroidServer.PicturePath, "*.jpg", SearchOption.AllDirectories); + if (allPicturesList == null) + { + allPicturesList = new List<string>(); + directoryList = GetMpShare("pictures"); - if (listAllPictures.Length > 0) + foreach (string key in directoryList.Values) + { + if (Directory.Exists(key)) + { + string[] files = Directory.GetFiles(key, "*.jpg", SearchOption.AllDirectories); + foreach(string f in files) + { + allPicturesList.Add(f); + } + } + } + } + + if (allPicturesList.Count > 0) { Random rnd = new Random(); - int x = rnd.Next(listAllPictures.Length); + int x = rnd.Next(allPicturesList.Count); - Bitmap bit = (Bitmap)Bitmap.FromFile(listAllPictures[x]); + Bitmap bit = (Bitmap)Bitmap.FromFile(allPicturesList[x]); byte[] b; if ((bit.Width > 600) || (bit.Height > 600)) @@ -1383,7 +1437,7 @@ } else { - SendServerError(listAllPictures[x], "ReplyRandomPictureFile"); + SendServerError(allPicturesList[x], "ReplyRandomPictureFile"); } } else @@ -1684,8 +1738,10 @@ } } - private void GetPictureShare() + private Dictionary<string, string> GetMpShare(string Share) { + Dictionary<string, string> list = new Dictionary<string, string>(); + #region read virtual dir using (MediaPortal.Profile.Settings xmlreader = new MediaPortal.Profile.MPSettings()) { @@ -1699,9 +1755,9 @@ string shareType = String.Format("sharetype{0}", i); Share share = new Share(); - share.Path = xmlreader.GetValueAsString("pictures", sharePath, string.Empty); - share.Name = xmlreader.GetValueAsString("pictures", shareName, string.Empty); - share.IsFtpShare = xmlreader.GetValueAsBool("pictures", shareType, false); + share.Path = xmlreader.GetValueAsString(Share, sharePath, string.Empty); + share.Name = xmlreader.GetValueAsString(Share, shareName, string.Empty); + share.IsFtpShare = xmlreader.GetValueAsBool(Share, shareType, false); if (share.Path.Length > 0) { @@ -1709,7 +1765,7 @@ { if (!share.IsFtpShare) { - dirList.Add(share.Name, share.Path); + list.Add(share.Name, share.Path); } } } @@ -1718,10 +1774,12 @@ break; } } + + return list; } #endregion } - private string GetLocalDir(string Request) + private string GetLocalDir(string Request, Dictionary<string, string> List) { string folder = string.Empty; string baseFolder = string.Empty; @@ -1738,7 +1796,7 @@ } string dir = string.Empty; - foreach (KeyValuePair<string, string> pair in dirList) + foreach (KeyValuePair<string, string> pair in List) { if (pair.Key.ToLower() == (baseFolder.ToLower())) { Modified: trunk/plugins/AndroidRemote/Server/AndroidRemote.suo =================================================================== (Binary files differ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |