From: <kro...@us...> - 2010-12-05 21:44:14
|
Revision: 4009 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=4009&view=rev Author: kroko_koenig Date: 2010-12-05 21:44:07 +0000 (Sun, 05 Dec 2010) Log Message: ----------- change to use shares of the mp for picture dirs Modified Paths: -------------- trunk/plugins/AndroidRemote/Server/AndroidRemote/Request.cs trunk/plugins/AndroidRemote/Server/AndroidRemote.suo Modified: trunk/plugins/AndroidRemote/Server/AndroidRemote/Request.cs =================================================================== --- trunk/plugins/AndroidRemote/Server/AndroidRemote/Request.cs 2010-12-05 19:33:12 UTC (rev 4008) +++ trunk/plugins/AndroidRemote/Server/AndroidRemote/Request.cs 2010-12-05 21:44:07 UTC (rev 4009) @@ -37,6 +37,7 @@ using MediaPortal.GUI.Library; using MediaPortal.Utils; +using MediaPortal.Util; using MediaPortal.Database; using MediaPortal.Configuration; @@ -57,6 +58,8 @@ private static string[] listAllPictures = null; private SQLiteClient sqlClient; + private VirtualDirectory virtualDirectory = new VirtualDirectory(); + private Dictionary<string, string> dirList = new Dictionary<string, string>(); public Request(Socket Socket) { @@ -125,13 +128,13 @@ else if (req.StartsWith("/pictures")) { // handle pictures - req = req.Replace("/pictures", ""); + req = req.Substring(9); if (req.StartsWith("/")) req = req.Substring(1); if (req == "") { // root - ReplyPictureDir(AndroidServer.PicturePath, "root"); + ReplyPictureDir(""); } else { @@ -139,17 +142,15 @@ if (req.EndsWith(".jpg")) { - string orgPath = AndroidServer.PicturePath + "\\" + req; - ReplyPictureFile(orgPath); + ReplyPictureFile(req); } else if (req.EndsWith(".thb")) { - string orgPath = AndroidServer.PicturePath + "\\" + req; - ReplyPictureThumbFile(orgPath); + ReplyPictureThumbFile(req); } else { - ReplyPictureDir(AndroidServer.PicturePath + "\\" + req, req); + ReplyPictureDir(req); } } } @@ -271,6 +272,16 @@ { ReplyMusicDbSongs(req); } + if (req.StartsWith("getfile")) + { + int pos = req.IndexOf("?"); + if (pos > 0) + { + string id = req.Substring(pos + 1); + id = id.Replace("id=", ""); + ReplyMusicDbFile(id, msgTyp); + } + } } #endregion @@ -543,10 +554,15 @@ AndroidServer.logDebug("Reply info server"); } - private void ReplyPictureDir(string dir, string request) + private void ReplyPictureDir(string Request) { - if (Directory.Exists(dir)) + GetPictureShare(); + string dir = GetLocalDir(Request); + + if (Request == string.Empty) { + #region root shares + string msg = string.Empty; // header msg += "HTTP/1.0 200 Ok\r\n"; @@ -556,36 +572,73 @@ // 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) + foreach (string key in dirList.Keys) { - msg += "<Folder>" + HttpUtility.HtmlEncode(Path.GetFileName(f)) + "</Folder>\r\n"; + msg += "<Folder>" + HttpUtility.HtmlEncode(key) + "</Folder>\r\n"; } - //files - string[] files = Directory.GetFiles(dir, "*.jpg", 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 picture dir"); + AndroidServer.logDebug("Reply picture root dir"); + + #endregion } else { - // dir does not exist - 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, "*.jpg", 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 picture dir"); + } + else + { + // dir does not exist + SendErrorURL(Request); + } + + #endregion } } private void ReplyPictureFile(string filePath) { - if (File.Exists(filePath)) + GetPictureShare(); + string dir = GetLocalDir(filePath); + + if (File.Exists(dir)) { - Bitmap bit = (Bitmap)Bitmap.FromFile(filePath); + Bitmap bit = (Bitmap)Bitmap.FromFile(dir); byte[] b; if ((bit.Width > 600) || (bit.Height > 600)) @@ -626,10 +679,14 @@ } private void ReplyPictureThumbFile(string filePath) { - filePath = filePath.Replace("thb", ""); - if (File.Exists(filePath)) + filePath = filePath.Replace(".thb", ""); + + GetPictureShare(); + string dir = GetLocalDir(filePath); + + if (File.Exists(dir)) { - Bitmap bit = (Bitmap)Bitmap.FromFile(filePath); + Bitmap bit = (Bitmap)Bitmap.FromFile(dir); byte[] b; Bitmap thumb = (Bitmap)bit.Clone(); @@ -797,7 +854,7 @@ sqlClient.BusyRetryDelay = 100; DatabaseUtility.SetPragmas(sqlClient); - string filePath = GetPathById(ID); + string filePath = GetPicturePathById(ID); if (File.Exists(filePath)) { @@ -847,7 +904,7 @@ sqlClient.BusyRetryDelay = 100; DatabaseUtility.SetPragmas(sqlClient); - string filePath = GetPathById(ID); + string filePath = GetPicturePathById(ID); if (File.Exists(filePath)) { @@ -1074,6 +1131,7 @@ { msg += "<Item>\r\n"; + msg += "<ID>" + HttpUtility.HtmlEncode(song.Id.ToString()) + "</ID>\r\n"; msg += "<Title>" + HttpUtility.HtmlEncode(song.Title) + "</Title>\r\n"; msg += "<Artist>" + HttpUtility.HtmlEncode(song.Artist) + "</Artist>\r\n"; msg += "<Album>" + HttpUtility.HtmlEncode(song.Artist) + "</Album>\r\n"; @@ -1081,7 +1139,6 @@ msg += "<Track>" + HttpUtility.HtmlEncode(song.Track.ToString()) + "</Track>\r\n"; msg += "<Duration>" + HttpUtility.HtmlEncode(song.Duration.ToString()) + "</Duration>\r\n"; msg += "<Rating>" + HttpUtility.HtmlEncode(song.Rating.ToString()) + "</Rating>\r\n"; - msg += "<Filename>" + HttpUtility.HtmlEncode(song.FileName) + "</Filename>\r\n"; msg += "</Item>\r\n"; } @@ -1092,7 +1149,41 @@ AndroidServer.logDebug("Reply music db artist"); } + private void ReplyMusicDbFile(string ID, string Mode) + { + sqlClient = new SQLiteClient(Config.GetFile(Config.Dir.Database, "MusicDatabaseV11.db3")); + sqlClient.BusyRetries = 10; + sqlClient.BusyRetryDelay = 100; + DatabaseUtility.SetPragmas(sqlClient); + string filePath = GetMusicPathById(ID); + + if (File.Exists(filePath)) + { + byte[] b = FileToByteArray(filePath); + + string msg = string.Empty; + // header + msg += "HTTP/1.0 200 Ok\r\n"; + msg += "Content-Type: audio/mpeg" + "\r\n"; + msg += "Content-Length: " + b.Length + "\r\n"; + msg += "Proxy-Connection: close" + "\r\n"; + msg += "\r\n"; + sendMessage(socket, msg); + + if (Mode != "HEAD") + { + // content + sendBytes(socket, b); + } + AndroidServer.logDebug("Reply music db file"); + } + else + { + SendErrorFile("ID=" + ID); + } + } + private void ReplyNowPlaying() { string title = GUIPropertyManager.GetProperty("#Play.Current.Title"); @@ -1532,7 +1623,7 @@ return Count; } } - public string GetPathById(string ID) + public string GetPicturePathById(string ID) { { if (sqlClient == null) @@ -1555,12 +1646,107 @@ } catch (Exception ex) { - Log.Error("MediaPortal.Picture.Database exception getting Picture by Date err:{0} stack:{1}", ex.Message, + Log.Error("MediaPortal.Picture.Database exception getting strFile by ID err:{0} stack:{1}", ex.Message, ex.StackTrace); //Open(); } return string.Empty; } } + public string GetMusicPathById(string ID) + { + { + if (sqlClient == null) + { + return string.Empty; + } + string strSQL = "SELECT strPath FROM tracks WHERE idTrack='" + ID + "'"; + SQLiteResultSet result; + try + { + result = sqlClient.Execute(strSQL); + if (result != null) + { + + if (result.Rows.Count == 1) + { + return DatabaseUtility.Get(result, 0, 0); + } + } + } + catch (Exception ex) + { + Log.Error("MediaPortal.Picture.Database exception getting strPath by ID err:{0} stack:{1}", ex.Message, + ex.StackTrace); + //Open(); + } + return string.Empty; + } + } + + private void GetPictureShare() + { + #region read virtual dir + using (MediaPortal.Profile.Settings xmlreader = new MediaPortal.Profile.MPSettings()) + { + VirtualDirectory virtualDirectory = new VirtualDirectory(); + virtualDirectory.Clear(); + + for (int i = 0; i < VirtualDirectory.MaxSharesCount; i++) + { + string sharePath = String.Format("sharepath{0}", i); + string shareName = String.Format("sharename{0}", i); + 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); + + if (share.Path.Length > 0) + { + if (share.Path != string.Empty) + { + if (!share.IsFtpShare) + { + dirList.Add(share.Name, share.Path); + } + } + } + else + { + break; + } + } + } + #endregion + } + private string GetLocalDir(string Request) + { + string folder = string.Empty; + string baseFolder = string.Empty; + + int x = Request.IndexOf("\\"); + if (x == -1) + { + baseFolder = Request; + } + else + { + baseFolder = Request.Substring(0, x); + folder = Request.Substring(x); + } + + string dir = string.Empty; + foreach (KeyValuePair<string, string> pair in dirList) + { + if (pair.Key.ToLower() == (baseFolder.ToLower())) + { + dir = pair.Value + folder; + return dir; + } + } + return string.Empty; + } } } 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. |