From: <sam...@us...> - 2006-06-19 12:31:24
|
Revision: 16 Author: samuel337 Date: 2006-06-19 05:31:08 -0700 (Mon, 19 Jun 2006) ViewCVS: http://svn.sourceforge.net/mp-webinterface/?rev=16&view=rev Log Message: ----------- implemented AddTVNotify, DeleteTVNotify, GetTVNotify, GetTVNotifies, GetTVGroups, GetTVGroup, GetProgramsByGenre, GetChannelsByGroupID, GetProgramsBySearch functions. TVNotify/TVGroup functions will not work until required MP changes are made and committed. LaunchMP has also been recoded. Modified Paths: -------------- trunk/source/ECP2Assembly/clsMPHandler.cs trunk/source/ECP2WebService/App_Code/Service.cs Modified: trunk/source/ECP2Assembly/clsMPHandler.cs =================================================================== --- trunk/source/ECP2Assembly/clsMPHandler.cs 2006-06-18 15:07:25 UTC (rev 15) +++ trunk/source/ECP2Assembly/clsMPHandler.cs 2006-06-19 12:31:08 UTC (rev 16) @@ -348,7 +348,7 @@ return MediaPortal.Player.g_Player.Playing; case "Speed": - return MediaPortal.Player.g_Player.Speed; + return MediaPortal.Player.g_Player.Speed; case "Stopped": return MediaPortal.Player.g_Player.Stopped; @@ -430,62 +430,17 @@ return recList; } - public bool AddRecording(string Title, string Channel, DateTime StartTime, DateTime EndTime, string RecType) - { - try - { - MediaPortal.TV.Database.TVRecording rec = new MediaPortal.TV.Database.TVRecording(); - string strRecType; - Array arrRecType; - bool recTypeFound = false; - - rec.Channel = Channel; - rec.Title = Title; - rec.Start = DateToLong(StartTime); - rec.End = DateToLong(EndTime); - - //resolve recording type string into the correct enum - arrRecType = Enum.GetValues(typeof(MediaPortal.TV.Database.TVRecording.RecordingType)); - - for (int i = arrRecType.GetLowerBound(0); i <= arrRecType.GetUpperBound(0); i++) - { - strRecType = Enum.GetName(typeof(MediaPortal.TV.Database.TVRecording.RecordingType), arrRecType.GetValue(i)); - if (strRecType == RecType) - { - rec.RecType = (MediaPortal.TV.Database.TVRecording.RecordingType)arrRecType.GetValue(i); - recTypeFound = true; - break; - } - } - - //if the specified rec-type string does not match one of the enum values, then set rectype to Once - if (recTypeFound == false) - { - rec.RecType = MediaPortal.TV.Database.TVRecording.RecordingType.Once; - } - - MediaPortal.TV.Database.TVDatabase.AddRecording(ref rec); - MediaPortal.GUI.Library.Log.Write("ECP2 - AddRecording: recording added."); - return true; - } - catch (Exception ex) - { - MediaPortal.GUI.Library.Log.Write("ECP2 Error: " + ex.ToString()); - return false; - } - } - public bool AddRecording(MediaPortal.TV.Database.TVRecording rec) { try { MediaPortal.TV.Database.TVDatabase.AddRecording(ref rec); - MediaPortal.GUI.Library.Log.Write("ECP2 - AddRecording: recording added."); + MediaPortal.GUI.Library.Log.Write("ECP2 - AddRecording: recording ({0}, {1}, {2}) added.", rec.Title, rec.Channel, rec.StartTime.ToString()); return true; } catch (Exception ex) { - MediaPortal.GUI.Library.Log.Write("ECP2 Error: " + ex.ToString()); + MediaPortal.GUI.Library.Log.Write("ECP2 - AddRecording: " + ex.ToString()); return false; } } @@ -495,12 +450,12 @@ try { MediaPortal.TV.Database.TVDatabase.UpdateRecording(rec, changeReason); - MediaPortal.GUI.Library.Log.Write("ECP2 - UpdateRecording: recording updated."); + MediaPortal.GUI.Library.Log.Write("ECP2 - UpdateRecording: recording ({0}, {1}, {2}) updated.", rec.Title, rec.Channel, rec.StartTime.ToString()); return true; } catch (Exception ex) { - MediaPortal.GUI.Library.Log.Write("ECP2 Error: " + ex.ToString()); + MediaPortal.GUI.Library.Log.Write("ECP2 - UpdateRecording: " + ex.ToString()); return false; } } @@ -529,12 +484,13 @@ if (ScheduleToDel ==true) { MediaPortal.TV.Database.TVDatabase.RemoveRecording(rec); + MediaPortal.GUI.Library.Log.Write("ECP2 - DelRecording: recording ({0}, {1}, {2}) deleted.", rec.Title, rec.Channel, rec.StartTime.ToString()); return true; } } catch (Exception ex) { - MediaPortal.GUI.Library.Log.WriteFile(Log.LogType.Log, "ECP2 - DelRecording: exception - " + ex.ToString()); + MediaPortal.GUI.Library.Log.WriteFile(Log.LogType.Log, "ECP2 - DelRecording: " + ex.ToString()); } return false; @@ -565,13 +521,14 @@ if (ScheduleToDel==true) { MediaPortal.TV.Database.TVDatabase.RemoveRecording(rec); + MediaPortal.GUI.Library.Log.Write("ECP2 - DelRecording: recording ({0}, {1}, {2}) deleted.", rec.Title, rec.Channel, rec.StartTime.ToString()); return true; } } catch (Exception ex) { - MediaPortal.GUI.Library.Log.WriteFile(Log.LogType.Log, "ECP2 - DelRecording: exception - " + ex.ToString()); + MediaPortal.GUI.Library.Log.WriteFile(Log.LogType.Log, "ECP2 - DelRecording: " + ex.ToString()); } return false; @@ -637,6 +594,14 @@ return chnList; } + public List<MediaPortal.TV.Database.TVChannel> GetChannels(int GroupID) + { + List<MediaPortal.TV.Database.TVChannel> chanList = new List<MediaPortal.TV.Database.TVChannel>(); + MediaPortal.TV.Database.TVDatabase.GetTVChannelsForGroup(GroupID, chanList); + + return chanList; + } + public MediaPortal.TV.Database.TVChannel GetChannel(int ChannelID) { return MediaPortal.TV.Database.TVDatabase.GetChannelById(ChannelID); @@ -658,6 +623,14 @@ return progList; } + public List<MediaPortal.TV.Database.TVProgram> GetPrograms(string GenreName) + { + List<MediaPortal.TV.Database.TVProgram> progList = new List<MediaPortal.TV.Database.TVProgram>(); + MediaPortal.TV.Database.TVDatabase.GetProgramsPerGenre(GenreName, progList); + + return progList; + } + public List<MediaPortal.TV.Database.TVProgram> GetPrograms(DateTime StartDateTime, DateTime EndDateTime) { List<MediaPortal.TV.Database.TVProgram> progList = new List<MediaPortal.TV.Database.TVProgram>(); @@ -666,6 +639,48 @@ return progList; } + public List<MediaPortal.TV.Database.TVProgram> GetPrograms(DateTime StartDateTime, DateTime EndDateTime, string SearchField, string SearchType, string SearchCriteria, string ChannelName) + { + int SearchKind; + + //convert SearchType to SearchKind + switch (SearchType.ToLower()) + { + case "wildcardatend": + SearchKind = 0; + break; + + case "wildcardatstartend": + SearchKind = 1; + break; + + case "wildcardatstart": + SearchKind = 2; + break; + + case "exact": + SearchKind = 3; + break; + + default: + SearchKind = 0; + break; + } + + List<MediaPortal.TV.Database.TVProgram> progList = new List<MediaPortal.TV.Database.TVProgram>(); + + if (SearchField.ToLower() == "description") + { + MediaPortal.TV.Database.TVDatabase.SearchProgramsByDescription(DateToLong(StartDateTime), DateToLong(EndDateTime), ref progList, SearchKind, SearchCriteria); + } + else //title + { + MediaPortal.TV.Database.TVDatabase.SearchPrograms(DateToLong(StartDateTime), DateToLong(EndDateTime), ref progList, SearchKind, SearchCriteria, ChannelName); + } + + return progList; + } + public List<MediaPortal.TV.Database.TVProgram> GetPrograms() { List<MediaPortal.TV.Database.TVProgram> progList = new List<MediaPortal.TV.Database.TVProgram>(); @@ -688,6 +703,216 @@ { return GetChannel(ChannelID).Name ; } + + public bool AddTVNotify(string ChannelName, DateTime StartDateTime) + { + try + { + MediaPortal.TV.Database.TVNotify notify = new MediaPortal.TV.Database.TVNotify(); + notify.Program = MediaPortal.TV.Database.TVDatabase.GetProgramByTime(ChannelName, StartDateTime); + + if (notify.Program == null) + { + throw new Exception("Could not locate a program matching the parameters given."); + } + + MediaPortal.TV.Database.TVDatabase.AddNotify(notify); + MediaPortal.GUI.Library.Log.Write("ECP2 - AddTVNotify: TVNotify ({0}, {1}) added.",notify.Program.Title,notify.Program.StartTime.ToString()); + return true; + } + catch (Exception ex) + { + MediaPortal.GUI.Library.Log.Write("ECP2 - AddTVNotify: " + ex.ToString()); + return false; + } + } + + public bool DeleteTVNotify(string ChannelName, DateTime StartDateTime) + { + try + { + MediaPortal.TV.Database.TVNotify notify = GetTVNotify(ChannelName, StartDateTime); + + if (notify == null) + { + return false; + } + + MediaPortal.TV.Database.TVDatabase.DeleteNotify(notify); + MediaPortal.GUI.Library.Log.Write("ECP2 - DeleteTVNotify: TVNotify ({0}, {1}) deleted.", notify.Program.Title, notify.Program.StartTime.ToString()); + return true; + } + catch (Exception ex) + { + MediaPortal.GUI.Library.Log.Write("ECP2 - DeleteTVNotify: " + ex.ToString()); + return false; + } + } + + public bool DeleteTVNotify(int TVNotifyID) + { + try + { + MediaPortal.TV.Database.TVNotify notify = GetTVNotify(TVNotifyID); + + if (notify == null) + { + return false; + } + + MediaPortal.TV.Database.TVDatabase.DeleteNotify(notify); + MediaPortal.GUI.Library.Log.Write("ECP2 - DeleteTVNotify: TVNotify ({0}, {1}) deleted.", notify.Program.Title, notify.Program.StartTime.ToString()); + return true; + } + catch (Exception ex) + { + MediaPortal.GUI.Library.Log.Write("ECP2 - DeleteTVNotify: " + ex.ToString()); + return false; + } + } + + public MediaPortal.TV.Database.TVNotify GetTVNotify(string ChannelName, DateTime StartDateTime) + { + try + { + MediaPortal.TV.Database.TVNotify notify = new MediaPortal.TV.Database.TVNotify(); + notify.Program = MediaPortal.TV.Database.TVDatabase.GetProgramByTime(ChannelName, StartDateTime); + + if (notify.Program == null) + { + throw new Exception("Could not locate a program matching the parameters given."); + } + + MediaPortal.TV.Database.TVDatabase.GetNotify(notify); + return notify; + } + catch (Exception ex) + { + MediaPortal.GUI.Library.Log.Write("ECP2 - GetNotify: " + ex.ToString()); + return null; + } + } + + public MediaPortal.TV.Database.TVNotify GetTVNotify(int TVNotifyID) + { + try + { + bool NotifyToDel = false; + + MediaPortal.TV.Database.TVNotify notify = new MediaPortal.TV.Database.TVNotify(); + List<MediaPortal.TV.Database.TVNotify> TVNotifyList = GetTVNotifies(); + + for (int i = 0; i < TVNotifyList.Count; i++) + { + notify = (MediaPortal.TV.Database.TVNotify)TVNotifyList[i]; + if (notify.ID == TVNotifyID) + { + NotifyToDel = true; + break; + } + } + + if (NotifyToDel == true) + { + return notify; + } + else + { + return null; + } + } + catch (Exception ex) + { + MediaPortal.GUI.Library.Log.WriteFile(Log.LogType.Log, "ECP2 - GetTVNotify: " + ex.ToString()); + return null; + } + } + + public List<MediaPortal.TV.Database.TVNotify> GetTVNotifies() + { + List<MediaPortal.TV.Database.TVNotify> TVNotifyList = new List<MediaPortal.TV.Database.TVNotify>(); + MediaPortal.TV.Database.TVDatabase.GetNotifies(TVNotifyList, true); + + return TVNotifyList; + } + + public List<MediaPortal.TV.Database.TVGroup> GetTVGroups() + { + List<MediaPortal.TV.Database.TVGroup> TVGroupList = new List<MediaPortal.TV.Database.TVGroup>(); + MediaPortal.TV.Database.TVDatabase.GetGroups(ref TVGroupList); + + return TVGroupList; + } + + public MediaPortal.TV.Database.TVGroup GetTVGroup(string GroupName) + { + try + { + bool foundTVGroup = false; + + MediaPortal.TV.Database.TVGroup group = new MediaPortal.TV.Database.TVGroup(); + List<MediaPortal.TV.Database.TVGroup> TVGroupList = GetTVGroups(); + + for (int i = 0; i < TVGroupList.Count; i++) + { + group = (MediaPortal.TV.Database.TVGroup)TVGroupList[i]; + if (group.GroupName == GroupName) + { + foundTVGroup = true; + break; + } + } + + if (foundTVGroup == true) + { + return group; + } + else + { + return null; + } + } + catch (Exception ex) + { + MediaPortal.GUI.Library.Log.WriteFile(Log.LogType.Log, "ECP2 - GetTVGroup: " + ex.ToString()); + return null; + } + } + + public MediaPortal.TV.Database.TVGroup GetTVGroup(int GroupID) + { + try + { + bool foundTVGroup=false; + + MediaPortal.TV.Database.TVGroup group = new MediaPortal.TV.Database.TVGroup(); + List<MediaPortal.TV.Database.TVGroup> TVGroupList = GetTVGroups(); + + for (int i = 0; i < TVGroupList.Count; i++) + { + group = (MediaPortal.TV.Database.TVGroup)TVGroupList[i]; + if (group.ID == GroupID) + { + foundTVGroup = true; + break; + } + } + + if (foundTVGroup == true) + { + return group; + } + else + { + return null; + } + } + catch (Exception ex) + { + MediaPortal.GUI.Library.Log.WriteFile(Log.LogType.Log, "ECP2 - GetTVGroup: " + ex.ToString()); + return null; + } + } #endregion #region Recorded TV commands @@ -828,6 +1053,8 @@ { return false; } + + break; } } Modified: trunk/source/ECP2WebService/App_Code/Service.cs =================================================================== --- trunk/source/ECP2WebService/App_Code/Service.cs 2006-06-18 15:07:25 UTC (rev 15) +++ trunk/source/ECP2WebService/App_Code/Service.cs 2006-06-19 12:31:08 UTC (rev 16) @@ -7,7 +7,7 @@ namespace ECP2WebService { - [WebService(Name = "MediaPortal External Control II Web Service", Description = "This web service allows you to communicate and control MediaPortal. You will need to have MediaPortal running, and the External Control II plugin needs to be loaded.", Namespace = "http://www.team-mediaportal.com/ECP2WebService/")] + [WebService(Name = "MediaPortal External Control II Web Service", Description = "This web service allows you to communicate and control MediaPortal. You will need to have MediaPortal running, and the External Control II plugin needs to be loaded.<br><br>For all fields requiring date/time entry, use this format: yyyy-mm-ddThh:mm:ss.sssssss+tz:tz, e.g. 2006-06-19T21:40:00.0000000+10:00 for 19th June 2006 9:40:00.0000000 PM +10:00.", Namespace = "http://www.team-mediaportal.com/ECP2WebService/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] public class Service : System.Web.Services.WebService @@ -31,10 +31,9 @@ { string appPath = ""; - if (!System.IO.File.Exists(ECP2Assembly.MPHandler.ConfigFileName)) + if (!System.IO.File.Exists(Server.MapPath(@"config/ECP2Assembly.dll.config"))) { - throw new Exception(@"Could not access ECP2Assembly's config file expected at (" + ECP2Assembly.MPHandler.ConfigFileName + @") to get MP path."); - return false; + throw new Exception(@"Could not access ECP2Assembly's config file expected at (" + Server.MapPath(@"config/ECP2Assembly.dll.config") + @") to get MP path."); } System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument(); @@ -42,7 +41,7 @@ try { xmlDoc.Load(ECP2Assembly.MPHandler.ConfigFileName); - System.Xml.XmlNodeList xmlNodeList = xmlDoc.SelectNodes("configuration/appSettings/add[@key='MPPath']"); + System.Xml.XmlNodeList xmlNodeList = xmlDoc.SelectNodes(@"configuration/appSettings/add[@key='MPDirectory']"); if (xmlNodeList.Count > 0) { @@ -53,19 +52,16 @@ else { throw new Exception(@"MPPath could not be located in the ECP2Assembly config file located at: " + ECP2Assembly.MPHandler.ConfigFileName); - return false; } if (!System.IO.File.Exists(appPath)) { - throw new Exception(@"Could not located MediaPortal.exe based on MP path from ECP2Assembly's config file located at: " + ECP2Assembly.MPHandler.ConfigFileName); - return false; + throw new Exception(@"Could not locate MediaPortal.exe based on MP path from ECP2Assembly's config file located at: " + ECP2Assembly.MPHandler.ConfigFileName); } } catch (Exception ex) { throw new Exception(@"ECP2 Web Service error: could not locate MediaPortal.exe; inner exception: " + ex.ToString()); - return false; } string folder = appPath.Substring(0, appPath.LastIndexOf(@"\")); @@ -82,7 +78,6 @@ catch (Exception ex) { throw new Exception(@"ECP2 Web Service error: could not execute MediaPortal; inner exception: " + ex.ToString()); - return false; } } @@ -99,7 +94,7 @@ xwSettings.Indent = true; xwSettings.OmitXmlDeclaration = false; xwSettings.ConformanceLevel = System.Xml.ConformanceLevel.Auto; - + return xwSettings; } #endregion @@ -325,10 +320,10 @@ rec.Channel = channelName; rec.Start = DateToLong(startDateTime); rec.End = DateToLong(endDateTime); - rec.RecType = Enum.Parse(GetType(MediaPortal.TV.Database.TVRecording.RecordingType), recType, true); - rec.KeepRecordingMethod = Enum.Parse(GetType(MediaPortal.TV.Database.TVRecorded.KeepMethod), keepMethod, true); + rec.RecType = (MediaPortal.TV.Database.TVRecording.RecordingType)Enum.Parse(typeof(MediaPortal.TV.Database.TVRecording.RecordingType), recType, true); + rec.KeepRecordingMethod = (MediaPortal.TV.Database.TVRecorded.KeepMethod)Enum.Parse(typeof(MediaPortal.TV.Database.TVRecorded.KeepMethod), keepMethod, true); - return GetEMPH().AddRecording(ref rec); + return GetEMPH().AddRecording(rec); } [WebMethod(Description = "This command tells MediaPortal to delete a particular recording by ID.")] @@ -442,12 +437,62 @@ return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); } + [WebMethod(Description = "This command retrieves all the channels in the specified group ID in XML format.")] + public string GetChannelsByGroupID(int GroupID) + { + List<MediaPortal.TV.Database.TVChannel> chnList; + chnList = GetEMPH().GetChannels(GroupID); + + if (chnList.Count == 0) return ""; + + // As CurrentProgram is not necessary, set its XMLIgnore attribute to true + System.Xml.Serialization.XmlAttributeOverrides xmlOverrides = new System.Xml.Serialization.XmlAttributeOverrides(); + System.Xml.Serialization.XmlAttributes xmlAttributes; + + xmlAttributes = new System.Xml.Serialization.XmlAttributes(); + xmlAttributes.XmlIgnore = true; + xmlOverrides.Add(typeof(MediaPortal.TV.Database.TVChannel), "CurrentProgram", xmlAttributes); + + System.IO.MemoryStream xwMem = new System.IO.MemoryStream(); + System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(xwMem, GetXMLDocWriterSettings()); + System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(MediaPortal.TV.Database.TVChannel), xmlOverrides); + MediaPortal.TV.Database.TVChannel chn; + + try + { + xw.WriteStartDocument(); + xw.WriteStartElement("MPData"); + xw.WriteStartElement("TVChannels"); + + for (int i = 0; i <= chnList.Count - 1; i++) + { + chn = (MediaPortal.TV.Database.TVChannel)chnList[i]; + + xs.Serialize(xw, chn); + } + + xw.WriteEndElement(); + xw.WriteEndElement(); + xw.WriteEndDocument(); + + xw.Flush(); + } + catch (Exception ex) + { + return ex.ToString(); + } + + return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); + } + [WebMethod(Description = "This command retrieves the specified channel from MP in XML format.")] public string GetChannel(int channelID) { MediaPortal.TV.Database.TVChannel chn; chn = GetEMPH().GetChannel(channelID); + if (chn == null) return ""; + // As CurrentProgram is not necessary, set its XMLIgnore attribute to true System.Xml.Serialization.XmlAttributeOverrides xmlOverrides = new System.Xml.Serialization.XmlAttributeOverrides(); System.Xml.Serialization.XmlAttributes xmlAttributes; @@ -500,6 +545,8 @@ List<string> genresList; genresList = GetEMPH().GetGenres(); + if (genresList.Count == 0) return ""; + System.IO.MemoryStream xwMem = new System.IO.MemoryStream(); System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(xwMem, GetXMLDocWriterSettings()); @@ -526,12 +573,14 @@ return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); } - [WebMethod(Description="This command returns the list of TV programs within the given date in XML format.")] + [WebMethod(Description="This command returns the list of TV programs within the given date boundaries in XML format.")] public string GetProgramsByDate(DateTime startDateTime, DateTime endDateTime) { List<MediaPortal.TV.Database.TVProgram> progList; progList = GetEMPH().GetPrograms(startDateTime,endDateTime); + if (progList.Count == 0) return ""; + System.IO.MemoryStream xwMem = new System.IO.MemoryStream(); System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(xwMem, GetXMLDocWriterSettings()); System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(MediaPortal.TV.Database.TVProgram )); @@ -563,12 +612,53 @@ return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); } + [WebMethod(Description = "This command returns the list of TV programs matching the specified genre in XML format.")] + public string GetProgramsByGenre(string GenreName) + { + List<MediaPortal.TV.Database.TVProgram> progList; + progList = GetEMPH().GetPrograms(GenreName); + + if (progList.Count == 0) return ""; + + System.IO.MemoryStream xwMem = new System.IO.MemoryStream(); + System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(xwMem, GetXMLDocWriterSettings()); + System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(MediaPortal.TV.Database.TVProgram)); + MediaPortal.TV.Database.TVProgram prog; + + try + { + xw.WriteStartDocument(); + xw.WriteStartElement("MPData"); + xw.WriteStartElement("TVPrograms"); + + for (int i = 0; i <= progList.Count - 1; i++) + { + prog = (MediaPortal.TV.Database.TVProgram)progList[i]; + xs.Serialize(xw, prog); + } + + xw.WriteEndElement(); + xw.WriteEndElement(); + xw.WriteEndDocument(); + + xw.Flush(); + } + catch (Exception ex) + { + return ex.ToString(); + } + + return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); + } + [WebMethod(Description="This command returns a list of all the TV programs in XML format.")] public string GetAllPrograms() { List<MediaPortal.TV.Database.TVProgram> progList; progList = GetEMPH().GetPrograms(); + if (progList.Count == 0) return ""; + System.IO.MemoryStream xwMem = new System.IO.MemoryStream(); System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(xwMem, GetXMLDocWriterSettings()); System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(MediaPortal.TV.Database.TVProgram )); @@ -600,12 +690,14 @@ return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); } - [WebMethod(Description="This command returns the list of TV program genres in XML format.")] + [WebMethod(Description="This command returns the list of TV programs on the specified channel and date/time boundaries in XML format.")] public string GetProgramsByChannel(int channelID, DateTime startDateTime, DateTime endDateTime) { List<MediaPortal.TV.Database.TVProgram> progList; progList = GetEMPH().GetPrograms(GetChannelName(channelID),startDateTime,endDateTime); + if (progList.Count == 0) return ""; + System.IO.MemoryStream xwMem = new System.IO.MemoryStream(); System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(xwMem, GetXMLDocWriterSettings()); System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(MediaPortal.TV.Database.TVProgram )); @@ -636,6 +728,322 @@ return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); } + + [WebMethod(Description = "This command searches and returns the list of matching TV programs in XML format. The SearchField parameter can take: title, or description. The SearchType parameter can take: wildcardatend, wildcardatstartend, wildcardatstart, or exact. ChannelName can be left blank to search all channels.")] + public string GetProgramsBySearch(DateTime StartDateTime, DateTime EndDateTime, string SearchField, string SearchType, string SearchCriteria, string ChannelName) + { + List<MediaPortal.TV.Database.TVProgram> progList; + progList = GetEMPH().GetPrograms(StartDateTime, EndDateTime, SearchField, SearchType, SearchCriteria, ChannelName); + + if (progList.Count == 0) return ""; + + System.IO.MemoryStream xwMem = new System.IO.MemoryStream(); + System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(xwMem, GetXMLDocWriterSettings()); + System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(MediaPortal.TV.Database.TVProgram)); + MediaPortal.TV.Database.TVProgram prog; + + try + { + xw.WriteStartDocument(); + xw.WriteStartElement("MPData"); + xw.WriteStartElement("TVPrograms"); + + for (int i = 0; i <= progList.Count - 1; i++) + { + prog = (MediaPortal.TV.Database.TVProgram)progList[i]; + xs.Serialize(xw, prog); + } + + xw.WriteEndElement(); + xw.WriteEndElement(); + xw.WriteEndDocument(); + + xw.Flush(); + } + catch (Exception ex) + { + return ex.ToString(); + } + + return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); + } + + [WebMethod(Description = "This command adds a notification to the program matching the specified channel and start date/time.")] + public bool AddTVNotify(string ChannelName, DateTime StartDateTime) + { + if (ChannelName == null) + { + return false; + } + + if (ChannelName == "") + { + return false; + } + + return GetEMPH().AddTVNotify(ChannelName, StartDateTime); + } + + [WebMethod(Description = "This command deletes a notification to the program matching the specified channel and start date/time.")] + public bool DeleteTVNotifyByChannelNameAndStartDateTime(string ChannelName, DateTime StartDateTime) + { + if (ChannelName == null) + { + return false; + } + + if (ChannelName == "") + { + return false; + } + + return GetEMPH().DeleteTVNotify(ChannelName, StartDateTime); + } + + [WebMethod(Description = "This command deletes a notification to the program matching the specified notification ID.")] + public bool DeleteTVNotifyByID(int TVNotifyID) + { + return GetEMPH().DeleteTVNotify(TVNotifyID); + } + + [WebMethod(Description = "This command returns a list of all the program notifications in XML format.")] + public string GetAllTVNotifies() + { + List<MediaPortal.TV.Database.TVNotify> TVNotifyList; + TVNotifyList = GetEMPH().GetTVNotifies(); + + if (TVNotifyList.Count == 0) return ""; + + System.IO.MemoryStream xwMem = new System.IO.MemoryStream(); + System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(xwMem, GetXMLDocWriterSettings()); + System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(MediaPortal.TV.Database.TVNotify)); + MediaPortal.TV.Database.TVNotify notify; + + try + { + xw.WriteStartDocument(); + xw.WriteStartElement("MPData"); + xw.WriteStartElement("TVNotifies"); + + for (int i = 0; i <= TVNotifyList.Count - 1; i++) + { + notify = (MediaPortal.TV.Database.TVNotify)TVNotifyList[i]; + xs.Serialize(xw, notify); + } + + xw.WriteEndElement(); + xw.WriteEndElement(); + xw.WriteEndDocument(); + + xw.Flush(); + } + catch (Exception ex) + { + return ex.ToString(); + } + + return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); + } + + [WebMethod(Description = "This command retrieves the specified program notification by TVNotifyID in XML format.")] + public string GetTVNotifyByTVNotifyID(int TVNotifyID) + { + MediaPortal.TV.Database.TVNotify notify; + notify = GetEMPH().GetTVNotify(TVNotifyID); + + if (notify == null) return ""; + + System.IO.MemoryStream xwMem = new System.IO.MemoryStream(); + System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(xwMem, GetXMLDocWriterSettings()); + System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(MediaPortal.TV.Database.TVNotify)); + + try + { + xw.WriteStartDocument(); + xw.WriteStartElement("MPData"); + xw.WriteStartElement("TVNotifies"); + + xs.Serialize(xw, notify); + + xw.WriteEndElement(); + xw.WriteEndElement(); + xw.WriteEndDocument(); + + xw.Flush(); + } + catch (Exception ex) + { + return ex.ToString(); + } + + return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); + } + + [WebMethod(Description = "This command retrieves the specified program notification by channel name and start date/time in XML format.")] + public string GetTVNotifyByChannelNameAndStartDateTime(string ChannelName, DateTime StartDateTime) + { + MediaPortal.TV.Database.TVNotify notify; + notify = GetEMPH().GetTVNotify(ChannelName,StartDateTime); + + if (notify == null) return ""; + + System.IO.MemoryStream xwMem = new System.IO.MemoryStream(); + System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(xwMem, GetXMLDocWriterSettings()); + System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(MediaPortal.TV.Database.TVNotify)); + + try + { + xw.WriteStartDocument(); + xw.WriteStartElement("MPData"); + xw.WriteStartElement("TVNotifies"); + + xs.Serialize(xw, notify); + + xw.WriteEndElement(); + xw.WriteEndElement(); + xw.WriteEndDocument(); + + xw.Flush(); + } + catch (Exception ex) + { + return ex.ToString(); + } + + return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); + } + + [WebMethod(Description = "This command retrieves all the TV channel groups in XML format.")] + public string GetTVGroups() + { + List<MediaPortal.TV.Database.TVGroup> TVGroupList; + TVGroupList = GetEMPH().GetTVGroups(); + + if (TVGroupList.Count == 0) return ""; + + // As channels is not wanted (too much info - can use GetChannels function for channels), set its XMLIgnore attribute to true + System.Xml.Serialization.XmlAttributeOverrides xmlOverrides = new System.Xml.Serialization.XmlAttributeOverrides(); + System.Xml.Serialization.XmlAttributes xmlAttributes; + + xmlAttributes = new System.Xml.Serialization.XmlAttributes(); + xmlAttributes.XmlIgnore = true; + xmlOverrides.Add(typeof(MediaPortal.TV.Database.TVGroup), "TvChannels", xmlAttributes); + + System.IO.MemoryStream xwMem = new System.IO.MemoryStream(); + System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(xwMem, GetXMLDocWriterSettings()); + System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(MediaPortal.TV.Database.TVGroup), xmlOverrides); + MediaPortal.TV.Database.TVGroup group; + + try + { + xw.WriteStartDocument(); + xw.WriteStartElement("MPData"); + xw.WriteStartElement("TVGroups"); + + for (int i = 0; i <= TVGroupList.Count - 1; i++) + { + group = (MediaPortal.TV.Database.TVGroup)TVGroupList[i]; + xs.Serialize(xw, group); + } + + xw.WriteEndElement(); + xw.WriteEndElement(); + xw.WriteEndDocument(); + + xw.Flush(); + } + catch (Exception ex) + { + return ex.ToString(); + } + + return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); + } + + [WebMethod(Description = "This command retrieves the specified TV channel group by group ID in XML format.")] + public string GetTVGroupByGroupID(int GroupID) + { + MediaPortal.TV.Database.TVGroup group; + group = GetEMPH().GetTVGroup(GroupID); + + if (group == null) return ""; + + // As channels is not wanted (too much info - can use GetChannels function for channels), set its XMLIgnore attribute to true + System.Xml.Serialization.XmlAttributeOverrides xmlOverrides = new System.Xml.Serialization.XmlAttributeOverrides(); + System.Xml.Serialization.XmlAttributes xmlAttributes; + + xmlAttributes = new System.Xml.Serialization.XmlAttributes(); + xmlAttributes.XmlIgnore = true; + xmlOverrides.Add(typeof(MediaPortal.TV.Database.TVGroup), "TvChannels", xmlAttributes); + + System.IO.MemoryStream xwMem = new System.IO.MemoryStream(); + System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(xwMem, GetXMLDocWriterSettings()); + System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(MediaPortal.TV.Database.TVGroup), xmlOverrides); + + try + { + xw.WriteStartDocument(); + xw.WriteStartElement("MPData"); + xw.WriteStartElement("TVGroups"); + + xs.Serialize(xw, group); + + xw.WriteEndElement(); + xw.WriteEndElement(); + xw.WriteEndDocument(); + + xw.Flush(); + } + catch (Exception ex) + { + return ex.ToString(); + } + + return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); + } + + [WebMethod(Description = "This command retrieves the specified TV channel group by group name in XML format.")] + public string GetTVGroupByGroupName(string GroupName) + { + MediaPortal.TV.Database.TVGroup group; + group = GetEMPH().GetTVGroup(GroupName); + + if (group == null) return ""; + + // As channels is not wanted (too much info - can use GetChannels function for channels), set its XMLIgnore attribute to true + System.Xml.Serialization.XmlAttributeOverrides xmlOverrides = new System.Xml.Serialization.XmlAttributeOverrides(); + System.Xml.Serialization.XmlAttributes xmlAttributes; + + xmlAttributes = new System.Xml.Serialization.XmlAttributes(); + xmlAttributes.XmlIgnore = true; + xmlOverrides.Add(typeof(MediaPortal.TV.Database.TVGroup), "TvChannels", xmlAttributes); + + System.IO.MemoryStream xwMem = new System.IO.MemoryStream(); + System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(xwMem, GetXMLDocWriterSettings()); + System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(MediaPortal.TV.Database.TVGroup), xmlOverrides); + + try + { + xw.WriteStartDocument(); + xw.WriteStartElement("MPData"); + xw.WriteStartElement("TVGroups"); + + xs.Serialize(xw, group); + + xw.WriteEndElement(); + xw.WriteEndElement(); + xw.WriteEndDocument(); + + xw.Flush(); + } + catch (Exception ex) + { + return ex.ToString(); + } + + return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); + } + #endregion #region recorded TV commands This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sam...@us...> - 2006-08-19 17:27:44
|
Revision: 18 Author: samuel337 Date: 2006-08-19 10:27:28 -0700 (Sat, 19 Aug 2006) ViewCVS: http://svn.sourceforge.net/mp-webinterface/?rev=18&view=rev Log Message: ----------- implemented music DB functions, fixed GetPlaylist function, added volume and player seek functions. Modified Paths: -------------- trunk/source/ECP2Assembly/clsMPHandler.cs trunk/source/ECP2WebService/App_Code/Service.cs Modified: trunk/source/ECP2Assembly/clsMPHandler.cs =================================================================== --- trunk/source/ECP2Assembly/clsMPHandler.cs 2006-08-13 12:40:07 UTC (rev 17) +++ trunk/source/ECP2Assembly/clsMPHandler.cs 2006-08-19 17:27:28 UTC (rev 18) @@ -385,6 +385,58 @@ } } + public bool gPlayerSeekAbsolute(double TimePosition) + { + try + { + MediaPortal.Player.g_Player.SeekAbsolute(TimePosition); + return true; + } + catch + { + return false; + } + } + + public bool gPlayerSeekAbsolutePercentage(int TimePositionPercentage) + { + try + { + MediaPortal.Player.g_Player.SeekAsolutePercentage(TimePositionPercentage); + return true; + } + catch + { + return false; + } + } + + public bool gPlayerSeekRelative(double RelativeTimePosition) + { + try + { + MediaPortal.Player.g_Player.SeekRelative(RelativeTimePosition); + return true; + } + catch + { + return false; + } + } + + public bool gPlayerSeekRelativePercentage(int RelativeTimePositionPercentage) + { + try + { + MediaPortal.Player.g_Player.SeekRelativePercentage(RelativeTimePositionPercentage); + return true; + } + catch + { + return false; + } + } + #endregion private long DateToLong(DateTime date) @@ -987,7 +1039,6 @@ } } - public MediaPortal.Playlists.PlayListItem CurrentPlaylistItem { get @@ -996,12 +1047,21 @@ } } - public MediaPortal.Playlists.PlayList GetPlaylist(MediaPortal.Playlists.PlayListType playlistType) + public ECP2Assembly.CustomMPObjects.PlayList GetPlaylist(MediaPortal.Playlists.PlayListType playlistType) { MediaPortal.Playlists.PlayList pl; pl = MediaPortal.Playlists.PlayListPlayer.SingletonPlayer.GetPlaylist(playlistType); - return pl; + //morph into ECP2CustomObject + ECP2Assembly.CustomMPObjects.PlayList ECP2PlayList = new ECP2Assembly.CustomMPObjects.PlayList(); + ECP2PlayList.PlayListName = pl.Name; + + for (int i = 0; i < pl.Count; i++) + { + ECP2PlayList.PlayListItems.Add(pl[i]); + } + + return ECP2PlayList; } public bool AddPlaylistItem(MediaPortal.Playlists.PlayListType playlistType, string fileName, string description, int duration, MediaPortal.Playlists.PlayListItem.PlayListItemType itemType) @@ -1065,7 +1125,7 @@ public bool RemovePlaylistItem(MediaPortal.Playlists.PlayListType playlistType, string fileName) { - MediaPortal.Playlists.PlayList pl = GetPlaylist(playlistType); + MediaPortal.Playlists.PlayList pl = MediaPortal.Playlists.PlayListPlayer.SingletonPlayer.GetPlaylist(playlistType); if (pl==null) {return false;} @@ -1092,7 +1152,7 @@ public bool ClearPlaylist(MediaPortal.Playlists.PlayListType playlistType) { - MediaPortal.Playlists.PlayList pl = GetPlaylist(playlistType); + MediaPortal.Playlists.PlayList pl = MediaPortal.Playlists.PlayListPlayer.SingletonPlayer.GetPlaylist(playlistType); try { @@ -1108,7 +1168,697 @@ #endregion -#region ECP2 Version commands +#region Music commands + //public MediaPortal.Music.Database.AlbumInfo GetAlbumInfo(int albumID) + //{ + // MediaPortal.Music.Database.AlbumInfo albumInfo; + + // MediaPortal.Music.Database.MusicDatabase m_db = new MediaPortal.Music.Database.MusicDatabase(); + // m_db.GetAlbumInfo(albumID, ref albumInfo); + + // return albumInfo; + //} + + //public MediaPortal.Music.Database.AlbumInfo GetAlbumInfo(string albumName, string albumPath) + //{ + // MediaPortal.Music.Database.AlbumInfo albumInfo; + + // MediaPortal.Music.Database.MusicDatabase m_db = new MediaPortal.Music.Database.MusicDatabase(); + // m_db.GetAlbumInfo(albumName, albumPath, ref albumInfo); + + // return albumInfo; + //} + + public List<ECP2Assembly.CustomMPObjects.MusicAlbum> GetAlbums() + { + List<ECP2Assembly.CustomMPObjects.MusicAlbum> albumList = new List<ECP2Assembly.CustomMPObjects.MusicAlbum>(); + + string strSQL = string.Empty ; + strSQL = "SELECT idAlbum, strAlbum, idArtist, iNumArtists FROM album"; + + SQLite.NET.SQLiteResultSet results; + results = MediaPortal.Music.Database.MusicDatabase.m_db.Execute(strSQL); + + for (int i = 0; i < results.Rows.Count; ++i) + { + ECP2Assembly.CustomMPObjects.MusicAlbum album = new ECP2Assembly.CustomMPObjects.MusicAlbum(); + + album.AlbumID = MediaPortal.Database.DatabaseUtility.GetAsInt(results, i, "album.idAlbum"); + album.AlbumName = MediaPortal.Database.DatabaseUtility.Get(results, i, "album.strAlbum"); + album.ArtistID = MediaPortal.Database.DatabaseUtility.GetAsInt(results, i, "album.idArtist"); + album.NumOfArtists = MediaPortal.Database.DatabaseUtility.GetAsInt(results, i, "album.iNumArtists"); + + albumList.Add(album); + } + + return albumList; + } + + public List<ECP2Assembly.CustomMPObjects.MusicAlbum> GetAlbums(string SearchType, string AlbumTitle) + { + int SearchKind; + + //convert SearchType to SearchKind + switch (SearchType.ToLower()) + { + case "wildcardatend": + SearchKind = 0; + break; + + case "wildcardatstartend": + SearchKind = 1; + break; + + case "wildcardatstart": + SearchKind = 2; + break; + + case "exact": + SearchKind = 3; + break; + + default: + SearchKind = 0; + break; + } + + string strSQL = string.Empty; + + switch (SearchKind) + { + case 0: + strSQL = String.Format("SELECT idAlbum, strAlbum, idArtist, iNumArtists FROM album WHERE album.strAlbum like '{0}%'", AlbumTitle); + break; + case 1: + strSQL = String.Format("SELECT idAlbum, strAlbum, idArtist, iNumArtists FROM album WHERE album.strAlbum like '%{0}%'", AlbumTitle); + break; + case 2: + strSQL = String.Format("SELECT idAlbum, strAlbum, idArtist, iNumArtists FROM album WHERE album.strAlbum like '%{0}'", AlbumTitle); + break; + case 3: + strSQL = String.Format("SELECT idAlbum, strAlbum, idArtist, iNumArtists FROM album WHERE album.strAlbum like '{0}'", AlbumTitle); + break; + } + + List<ECP2Assembly.CustomMPObjects.MusicAlbum> albumList = new List<ECP2Assembly.CustomMPObjects.MusicAlbum>(); + + SQLite.NET.SQLiteResultSet results; + results = MediaPortal.Music.Database.MusicDatabase.m_db.Execute(strSQL); + + for (int i = 0; i < results.Rows.Count; ++i) + { + ECP2Assembly.CustomMPObjects.MusicAlbum album = new ECP2Assembly.CustomMPObjects.MusicAlbum(); + + album.AlbumID = MediaPortal.Database.DatabaseUtility.GetAsInt(results, i, "album.idAlbum"); + album.AlbumName = MediaPortal.Database.DatabaseUtility.Get(results, i, "album.strAlbum"); + album.ArtistID = MediaPortal.Database.DatabaseUtility.GetAsInt(results, i, "album.idArtist"); + album.NumOfArtists = MediaPortal.Database.DatabaseUtility.GetAsInt(results, i, "album.iNumArtists"); + + albumList.Add(album); + } + + return albumList; + } + + //public MediaPortal.Music.Database.ArtistInfo GetArtistInfo(string artistName) + //{ + // MediaPortal.Music.Database.ArtistInfo artistInfo; + + // MediaPortal.Music.Database.MusicDatabase m_db = new MediaPortal.Music.Database.MusicDatabase(); + // m_db.GetArtistInfo(artistName, ref artistInfo); + + // return artistInfo; + //} + + public List<ECP2Assembly.CustomMPObjects.MusicArtist> GetArtists() + { + List<ECP2Assembly.CustomMPObjects.MusicArtist> artistList = new List<ECP2Assembly.CustomMPObjects.MusicArtist>(); + + string strSQL = string.Empty; + strSQL = "SELECT idArtist, strArtist FROM artist"; + + SQLite.NET.SQLiteResultSet results; + results = MediaPortal.Music.Database.MusicDatabase.m_db.Execute(strSQL); + + for (int i = 0; i < results.Rows.Count; ++i) + { + ECP2Assembly.CustomMPObjects.MusicArtist artist = new ECP2Assembly.CustomMPObjects.MusicArtist(); + + artist.ArtistID = MediaPortal.Database.DatabaseUtility.GetAsInt(results, i, "artist.idArtist"); + artist.ArtistName = MediaPortal.Database.DatabaseUtility.Get(results, i, "artist.strArtist"); + + artistList.Add(artist); + } + + return artistList; + } + + public List<ECP2Assembly.CustomMPObjects.MusicArtist> GetArtists(string SearchType, string ArtistName) + { + int SearchKind; + + //convert SearchType to SearchKind + switch (SearchType.ToLower()) + { + case "wildcardatend": + SearchKind = 0; + break; + + case "wildcardatstartend": + SearchKind = 1; + break; + + case "wildcardatstart": + SearchKind = 2; + break; + + case "exact": + SearchKind = 3; + break; + + default: + SearchKind = 0; + break; + } + + List<ECP2Assembly.CustomMPObjects.MusicArtist> artistList = new List<ECP2Assembly.CustomMPObjects.MusicArtist>(); + + string strSQL = string.Empty; + + switch (SearchKind) + { + case 0: + strSQL = String.Format("SELECT idArtist, strArtist FROM artist WHERE strArtist like '{0}%' ", ArtistName); + break; + case 1: + strSQL = String.Format("SELECT idArtist, strArtist FROM artist WHERE strArtist like '%{0}%' ", ArtistName); + break; + case 2: + strSQL = String.Format("SELECT idArtist, strArtist FROM artist WHERE strArtist like '%{0}' ", ArtistName); + break; + case 3: + strSQL = String.Format("SELECT idArtist, strArtist FROM artist WHERE strArtist like '{0}' ", ArtistName); + break; + } + + SQLite.NET.SQLiteResultSet results; + results = MediaPortal.Music.Database.MusicDatabase.m_db.Execute(strSQL); + + for (int i = 0; i < results.Rows.Count; ++i) + { + ECP2Assembly.CustomMPObjects.MusicArtist artist = new ECP2Assembly.CustomMPObjects.MusicArtist(); + + artist.ArtistID = MediaPortal.Database.DatabaseUtility.GetAsInt(results, i, "artist.idArtist"); + artist.ArtistName = MediaPortal.Database.DatabaseUtility.Get(results, i, "artist.strArtist"); + + artistList.Add(artist); + } + + return artistList; + } + + public List<ECP2Assembly.CustomMPObjects.MusicGenre> GetMusicGenres() + { + List<ECP2Assembly.CustomMPObjects.MusicGenre> genreList = new List<ECP2Assembly.CustomMPObjects.MusicGenre>(); + + string strSQL = string.Empty; + strSQL = "SELECT idGenre, strGenre FROM genre"; + + SQLite.NET.SQLiteResultSet results; + results = MediaPortal.Music.Database.MusicDatabase.m_db.Execute(strSQL); + + for (int i = 0; i < results.Rows.Count; ++i) + { + ECP2Assembly.CustomMPObjects.MusicGenre genre = new ECP2Assembly.CustomMPObjects.MusicGenre(); + + genre.GenreID = MediaPortal.Database.DatabaseUtility.GetAsInt(results, i, "genre.idGenre"); + genre.GenreName = MediaPortal.Database.DatabaseUtility.Get(results, i, "genre.strGenre"); + + genreList.Add(genre); + } + + return genreList; + } + + public List<ECP2Assembly.CustomMPObjects.MusicGenre> GetMusicGenres(string SearchType, string GenreName) + { + int SearchKind; + + //convert SearchType to SearchKind + switch (SearchType.ToLower()) + { + case "wildcardatend": + SearchKind = 0; + break; + + case "wildcardatstartend": + SearchKind = 1; + break; + + case "wildcardatstart": + SearchKind = 2; + break; + + case "exact": + SearchKind = 3; + break; + + default: + SearchKind = 0; + break; + } + + List<ECP2Assembly.CustomMPObjects.MusicGenre> genreList = new List<ECP2Assembly.CustomMPObjects.MusicGenre>(); + + string strSQL = string.Empty; + + switch (SearchKind) + { + case 0: + strSQL = String.Format("SELECT idGenre, strGenre FROM genre WHERE strGenre like '{0}%'", GenreName ); + break; + case 1: + strSQL = String.Format("SELECT idGenre, strGenre FROM genre WHERE strGenre like '%{0}%'", GenreName); + break; + case 2: + strSQL = String.Format("SELECT idGenre, strGenre FROM genre WHERE strGenre like '%{0}'", GenreName); + break; + case 3: + strSQL = String.Format("SELECT idGenre, strGenre FROM genre WHERE strGenre like '{0}'", GenreName); + break; + } + + SQLite.NET.SQLiteResultSet results; + results = MediaPortal.Music.Database.MusicDatabase.m_db.Execute(strSQL); + + for (int i = 0; i < results.Rows.Count; ++i) + { + ECP2Assembly.CustomMPObjects.MusicGenre genre = new ECP2Assembly.CustomMPObjects.MusicGenre(); + + genre.GenreID = MediaPortal.Database.DatabaseUtility.GetAsInt(results, i, "genre.idGenre"); + genre.GenreName = MediaPortal.Database.DatabaseUtility.Get(results, i, "genre.strGenre"); + + genreList.Add(genre); + } + + return genreList; + } + + public int GetNumOfSongs() + { + MediaPortal.Music.Database.MusicDatabase m_db = new MediaPortal.Music.Database.MusicDatabase(); + return m_db.GetNumOfSongs(); + } + + public MediaPortal.Music.Database.Song GetRandomSong() + { + MediaPortal.Music.Database.Song song = new MediaPortal.Music.Database.Song(); + + MediaPortal.Music.Database.MusicDatabase m_db = new MediaPortal.Music.Database.MusicDatabase(); + m_db.GetRandomSong(ref song); + + return song; + } + + //public List<MediaPortal.Music.Database.AlbumInfo> GetRecentlyPlayedAlbums() + //{ + // List<MediaPortal.Music.Database.AlbumInfo> albumList = new List<MediaPortal.Music.Database.AlbumInfo>(); + // System.Collections.ArrayList albumArrList = new System.Collections.ArrayList(); + + // MediaPortal.Music.Database.MusicDatabase m_db = new MediaPortal.Music.Database.MusicDatabase(); + // m_db.GetRecentlyPlayedAlbums(ref albumArrList); + + // for (int i = 0; i < albumArrList.Count - 1; i++) + // { + // albumList.Add((MediaPortal.Music.Database.AlbumInfo)albumArrList[i]); + // } + + // return albumList; + //} + + public MediaPortal.Music.Database.Song GetSong(int SongID) + { + MediaPortal.Music.Database.Song song = new MediaPortal.Music.Database.Song(); + + string strSQL = string.Empty; + strSQL = String.Format("SELECT song.idSong, song.idArtist, artist.strArtist, song.idAlbum, album.strAlbum, song.idGenre, genre.strGenre, song.idPath, path.strPath, song.strTitle, song.iTrack, song.iDuration, song.iYear, song.strFileName, song.iTimesPlayed, song.iRating, song.favorite FROM song, album, artist, genre, path WHERE song.idPath=path.idPath AND song.idAlbum=album.idAlbum AND song.idGenre=genre.idGenre AND song.idArtist=artist.idArtist AND song.idSong={0}", SongID ); + + SQLite.NET.SQLiteResultSet results; + results = MediaPortal.Music.Database.MusicDatabase.m_db.Execute(strSQL); + + if (results.Rows.Count<1) + { + return null; + } + + song.songId = MediaPortal.Database.DatabaseUtility.GetAsInt(results, 0, "song.idSong"); + song.artistId = MediaPortal.Database.DatabaseUtility.GetAsInt(results, 0, "song.idArtist"); + song.Artist = MediaPortal.Database.DatabaseUtility.Get(results, 0, "artist.strArtist"); + song.albumId = MediaPortal.Database.DatabaseUtility.GetAsInt(results, 0, "song.idAlbum"); + song.Album = MediaPortal.Database.DatabaseUtility.Get(results, 0, "album.strAlbum"); + song.genreId = MediaPortal.Database.DatabaseUtility.GetAsInt(results, 0, "song.idGenre"); + song.Genre = MediaPortal.Database.DatabaseUtility.Get(results, 0, "genre.strGenre"); + song.Title = MediaPortal.Database.DatabaseUtility.Get(results, 0, "song.strTitle"); + song.Track = MediaPortal.Database.DatabaseUtility.GetAsInt(results, 0, "song.iTrack"); + song.Duration = MediaPortal.Database.DatabaseUtility.GetAsInt(results, 0, "song.iDuration"); + song.Year = MediaPortal.Database.DatabaseUtility.GetAsInt(results, 0, "song.iYear"); + + string strFileName = MediaPortal.Database.DatabaseUtility.Get(results, 0, "path.strPath"); + strFileName += MediaPortal.Database.DatabaseUtility.Get(results, 0, "song.strFileName"); + song.FileName = strFileName; + + song.TimesPlayed = MediaPortal.Database.DatabaseUtility.GetAsInt(results, 0, "song.iTimesPlayed"); + song.Rating = MediaPortal.Database.DatabaseUtility.GetAsInt(results, 0, "song.iRating"); + song.Favorite = (int)Math.Floor(0.5d + Double.Parse(MediaPortal.Database.DatabaseUtility.Get(results, 0, "song.favorite"))) != 0; ; + + return song; + } + + public MediaPortal.Music.Database.Song GetSong(string songTitle) + { + MediaPortal.Music.Database.Song song = new MediaPortal.Music.Database.Song(); + + MediaPortal.Music.Database.MusicDatabase m_db = new MediaPortal.Music.Database.MusicDatabase(); + m_db.GetSong(songTitle, ref song); + + return song; + } + + public MediaPortal.Music.Database.Song GetSongByFileName(string songFileName) + { + MediaPortal.Music.Database.Song song = new MediaPortal.Music.Database.Song(); + + MediaPortal.Music.Database.MusicDatabase m_db = new MediaPortal.Music.Database.MusicDatabase(); + m_db.GetSongByFileName(songFileName, ref song); + + return song; + } + + public List<MediaPortal.Music.Database.Song> GetSongs(string SearchType, string SongTitle) + { + int SearchKind; + + //convert SearchType to SearchKind + switch (SearchType.ToLower()) + { + case "wildcardatend": + SearchKind = 0; + break; + + case "wildcardatstartend": + SearchKind = 1; + break; + + case "wildcardatstart": + SearchKind = 2; + break; + + case "exact": + SearchKind = 3; + break; + + default: + SearchKind = 0; + break; + } + + List<MediaPortal.Music.Database.Song> songList = new List<MediaPortal.Music.Database.Song>(); + + string strSQL = string.Empty; + + switch (SearchKind) + { + case 0: + strSQL = String.Format("SELECT song.idSong, song.idArtist, artist.strArtist, song.idAlbum, album.strAlbum, song.idGenre, genre.strGenre, song.idPath, path.strPath, song.strTitle, song.iTrack, song.iDuration, song.iYear, song.strFileName, song.iTimesPlayed, song.iRating, song.favorite FROM song, album, artist, genre, path WHERE song.idPath=path.idPath AND song.idAlbum=album.idAlbum AND song.idGenre=genre.idGenre AND song.idArtist=artist.idArtist AND strTitle LIKE '{0}%'", SongTitle); + break; + case 1: + strSQL = String.Format("SELECT song.idSong, song.idArtist, artist.strArtist, song.idAlbum, album.strAlbum, song.idGenre, genre.strGenre, song.idPath, path.strPath, song.strTitle, song.iTrack, song.iDuration, song.iYear, song.strFileName, song.iTimesPlayed, song.iRating, song.favorite FROM song, album, artist, genre, path WHERE song.idPath=path.idPath AND song.idAlbum=album.idAlbum AND song.idGenre=genre.idGenre AND song.idArtist=artist.idArtist AND strTitle like '%{0}%'", SongTitle); + break; + case 2: + strSQL = String.Format("SELECT song.idSong, song.idArtist, artist.strArtist, song.idAlbum, album.strAlbum, song.idGenre, genre.strGenre, song.idPath, path.strPath, song.strTitle, song.iTrack, song.iDuration, song.iYear, song.strFileName, song.iTimesPlayed, song.iRating, song.favorite FROM song, album, artist, genre, path WHERE song.idPath=path.idPath AND song.idAlbum=album.idAlbum AND song.idGenre=genre.idGenre AND song.idArtist=artist.idArtist AND strTitle like '%{0}'", SongTitle); + break; + case 3: + strSQL = String.Format("SELECT song.idSong, song.idArtist, artist.strArtist, song.idAlbum, album.strAlbum, song.idGenre, genre.strGenre, song.idPath, path.strPath, song.strTitle, song.iTrack, song.iDuration, song.iYear, song.strFileName, song.iTimesPlayed, song.iRating, song.favorite FROM song, album, artist, genre, path WHERE song.idPath=path.idPath AND song.idAlbum=album.idAlbum AND song.idGenre=genre.idGenre AND song.idArtist=artist.idArtist AND strTitle like '{0}'", SongTitle); + break; + } + + SQLite.NET.SQLiteResultSet results; + results = MediaPortal.Music.Database.MusicDatabase.m_db.Execute(strSQL); + + for (int i = 0; i < results.Rows.Count; ++i) + { + MediaPortal.Music.Database.Song song = new MediaPortal.Music.Database.Song(); + + song.songId = MediaPortal.Database.DatabaseUtility.GetAsInt(results, i, "song.idSong"); + song.artistId = MediaPortal.Database.DatabaseUtility.GetAsInt(results, i, "song.idArtist"); + song.Artist = MediaPortal.Database.DatabaseUtility.Get(results, i, "artist.strArtist"); + song.albumId = MediaPortal.Database.DatabaseUtility.GetAsInt(results, i, "song.idAlbum"); + song.Album = MediaPortal.Database.DatabaseUtility.Get(results, i, "album.strAlbum"); + song.genreId = MediaPortal.Database.DatabaseUtility.GetAsInt(results, i, "song.idGenre"); + song.Genre = MediaPortal.Database.DatabaseUtility.Get(results, i, "genre.strGenre"); + song.Title = MediaPortal.Database.DatabaseUtility.Get(results, i, "song.strTitle"); + song.Track = MediaPortal.Database.DatabaseUtility.GetAsInt(results, i, "song.iTrack"); + song.Duration = MediaPortal.Database.DatabaseUtility.GetAsInt(results, i, "song.iDuration"); + song.Year = MediaPortal.Database.DatabaseUtility.GetAsInt(results, i, "song.iYear"); + + string strFileName = MediaPortal.Database.DatabaseUtility.Get(results, i, "path.strPath"); + strFileName += MediaPortal.Database.DatabaseUtility.Get(results, i, "song.strFileName"); + song.FileName = strFileName; + + song.TimesPlayed = MediaPortal.Database.DatabaseUtility.GetAsInt(results, i, "song.iTimesPlayed"); + song.Rating = MediaPortal.Database.DatabaseUtility.GetAsInt(results, i, "song.iRating"); + song.Favorite = (int)Math.Floor(0.5d + Double.Parse(MediaPortal.Database.DatabaseUtility.Get(results, i, "song.favorite"))) != 0; ; + + songList.Add(song); + } + + return songList; + } + + public List<MediaPortal.Music.Database.Song> GetSongsByAlbum(int AlbumID) + { + //custom SQL as in-built function does not return songID + List<MediaPortal.Music.Database.Song> songList = new List<MediaPortal.Music.Database.Song>(); + + string strSQL = string.Empty; + strSQL = String.Format("SELECT song.idSong, song.idArtist, artist.strArtist, song.idAlbum, album.strAlbum, song.idGenre, genre.strGenre, song.idPath, path.strPath, song.strTitle, song.iTrack, song.iDuration, song.iYear, song.strFileName, song.iTimesPlayed, song.iRating, song.favorite FROM song, album, artist, genre, path WHERE song.idPath=path.idPath AND song.idAlbum=album.idAlbum AND song.idGenre=genre.idGenre AND song.idArtist=artist.idArtist AND song.idAlbum={0}", AlbumID); + + SQLite.NET.SQLiteResultSet results; + results = MediaPortal.Music.Database.MusicDatabase.m_db.Execute(strSQL); + + for (int i = 0; i < results.Rows.Count; ++i) + { + MediaPortal.Music.Database.Song song = new MediaPortal.Music.Database.Song(); + + song.songId = MediaPortal.Database.DatabaseUtility.GetAsInt(results, i, "song.idSong"); + song.artistId = MediaPortal.Database.DatabaseUtility.GetAsInt(results, i, "song.idArtist"); + song.Artist = MediaPortal.Database.DatabaseUtility.Get(results, i, "artist.strArtist"); + song.albumId = MediaPortal.Database.DatabaseUtility.GetAsInt(results, i, "song.idAlbum"); + song.Album = MediaPortal.Database.DatabaseUtility.Get(results, i, "album.strAlbum"); + song.genreId = MediaPortal.Database.DatabaseUtility.GetAsInt(results, i, "song.idGenre"); + song.Genre = MediaPortal.Database.DatabaseUtility.Get(results, i, "genre.strGenre"); + song.Title = MediaPortal.Database.DatabaseUtility.Get(results, i, "song.strTitle"); + song.Track = MediaPortal.Database.DatabaseUtility.GetAsInt(results, i, "song.iTrack"); + song.Duration = MediaPortal.Database.DatabaseUtility.GetAsInt(results, i, "song.iDuration"); + song.Year = MediaPortal.Database.DatabaseUtility.GetAsInt(results, i, "song.iYear"); + + string strFileName = MediaPortal.Database.DatabaseUtility.Get(results, i, "path.strPath"); + strFileName += MediaPortal.Database.DatabaseUtility.Get(results, i, "song.strFileName"); + song.FileName = strFileName; + + song.TimesPlayed = MediaPortal.Database.DatabaseUtility.GetAsInt(results, i, "song.iTimesPlayed"); + song.Rating = MediaPortal.Database.DatabaseUtility.GetAsInt(results, i, "song.iRating"); + song.Favorite = (int)Math.Floor(0.5d + Double.Parse(MediaPortal.Database.DatabaseUtility.Get(results, i, "song.favorite"))) != 0; ; + + songList.Add(song); + } + + return songList; + } + + public List<MediaPortal.Music.Database.Song> GetSongsByArtist(int ArtistID) + { + List<MediaPortal.Music.Database.Song> songList = new List<MediaPortal.Music.Database.Song>(); + + string strSQL = string.Empty; + strSQL = String.Format("SELECT song.idSong, song.idArtist, artist.strArtist, song.idAlbum, album.strAlbum, song.idGenre, genre.strGenre, song.idPath, path.strPath, song.strTitle, song.iTrack, song.iDuration, song.iYear, song.strFileName, song.iTimesPlayed, song.iRating, song.favorite FROM song, album, artist, genre, path WHERE song.idPath=path.idPath AND song.idAlbum=album.idAlbum AND song.idGenre=genre.idGenre AND song.idArtist=artist.idArtist AND song.idArtist={0}", ArtistID); + + SQLite.NET.SQLiteResultSet results; + results = MediaPortal.Music.Database.MusicDatabase.m_db.Execute(strSQL); + + for (int i = 0; i < results.Rows.Count; ++i) + { + MediaPortal.Music.Database.Song song = new MediaPortal.Music.Database.Song(); + + song.songId = MediaPortal.Database.DatabaseUtility.GetAsInt(results, i, "song.idSong"); + song.artistId = MediaPortal.Database.DatabaseUtility.GetAsInt(results, i, "song.idArtist"); + song.Artist = MediaPortal.Database.DatabaseUtility.Get(results, i, "artist.strArtist"); + song.albumId = MediaPortal.Database.DatabaseUtility.GetAsInt(results, i, "song.idAlbum"); + song.Album = MediaPortal.Database.DatabaseUtility.Get(results, i, "album.strAlbum"); + song.genreId = MediaPortal.Database.DatabaseUtility.GetAsInt(results, i, "song.idGenre"); + song.Genre = MediaPortal.Database.DatabaseUtility.Get(results, i, "genre.strGenre"); + song.Title = MediaPortal.Database.DatabaseUtility.Get(results, i, "song.strTitle"); + song.Track = MediaPortal.Database.DatabaseUtility.GetAsInt(results, i, "song.iTrack"); + song.Duration = MediaPortal.Database.DatabaseUtility.GetAsInt(results, i, "song.iDuration"); + song.Year = MediaPortal.Database.DatabaseUtility.GetAsInt(results, i, "song.iYear"); + + string strFileName = MediaPortal.Database.DatabaseUtility.Get(results, i, "path.strPath"); + strFileName += MediaPortal.Database.DatabaseUtility.Get(results, i, "song.strFileName"); + song.FileName = strFileName; + + song.TimesPlayed = MediaPortal.Database.DatabaseUtility.GetAsInt(results, i, "song.iTimesPlayed"); + song.Rating = MediaPortal.Database.DatabaseUtility.GetAsInt(results, i, "song.iRating"); + song.Favorite = (int)Math.Floor(0.5d + Double.Parse(MediaPortal.Database.DatabaseUtility.Get(results, i, "song.favorite"))) != 0; ; + + songList.Add(song); + } + + return songList; + } + + public List<MediaPortal.Music.Database.Song> GetSongsByGenre(int GenreID) + { + List<MediaPortal.Music.Database.Song> songList = new List<MediaPortal.Music.Database.Song>(); + + string strSQL = string.Empty; + strSQL = String.Format("SELECT song.idSong, song.idArtist, artist.strArtist, song.idAlbum, album.strAlbum, song.idGenre, genre.strGenre, song.idPath, path.strPath, song.strTitle, song.iTrack, song.iDuration, song.iYear, song.strFileName, song.iTimesPlayed, song.iRating, song.favorite FROM song, album, artist, genre, path WHERE song.idPath=path.idPath AND song.idAlbum=album.idAlbum AND song.idGenre=genre.idGenre AND song.idArtist=artist.idArtist AND song.idGenre={0}", GenreID); + + SQLite.NET.SQLiteResultSet results; + results = MediaPortal.Music.Database.MusicDatabase.m_db.Execute(strSQL); + + for (int i = 0; i < results.Rows.Count; ++i) + { + MediaPortal.Music.Database.Song song = new MediaPortal.Music.Database.Song(); + + song.songId = MediaPortal.Database.DatabaseUtility.GetAsInt(results, i, "song.idSong"); + song.artistId = MediaPortal.Database.DatabaseUtility.GetAsInt(results, i, "song.idArtist"); + song.Artist = MediaPortal.Database.DatabaseUtility.Get(results, i, "artist.strArtist"); + song.albumId = MediaPortal.Database.DatabaseUtility.GetAsInt(results, i, "song.idAlbum"); + song.Album = MediaPortal.Database.DatabaseUtility.Get(results, i, "album.strAlbum"); + song.genreId = MediaPortal.Database.DatabaseUtility.GetAsInt(results, i, "song.idGenre"); + song.Genre = MediaPortal.Database.DatabaseUtility.Get(results, i, "genre.strGenre"); + song.Title = MediaPortal.Database.DatabaseUtility.Get(results, i, "song.strTitle"); + song.Track = MediaPortal.Database.DatabaseUtility.GetAsInt(results, i, "song.iTrack"); + song.Duration = MediaPortal.Database.DatabaseUtility.GetAsInt(results, i, "song.iDuration"); + song.Year = MediaPortal.Database.DatabaseUtility.GetAsInt(results, i, "song.iYear"); + + string strFileName = MediaPortal.Database.DatabaseUtility.Get(results, i, "path.strPath"); + strFileName += MediaPortal.Database.DatabaseUtility.Get(results, i, "song.strFileName"); + song.FileName = strFileName; + + song.TimesPlayed = MediaPortal.Database.DatabaseUtility.GetAsInt(results, i, "song.iTimesPlayed"); + song.Rating = MediaPortal.Database.DatabaseUtility.GetAsInt(results, i, "song.iRating"); + song.Favorite = (int)Math.Floor(0.5d + Double.Parse(MediaPortal.Database.DatabaseUtility.Get(results, i, "song.favorite"))) != 0; ; + + songList.Add(song); + } + + return songList; + } + + public List<MediaPortal.Music.Database.Song> GetSongsByYear(int Year) + { + List<MediaPortal.Music.Database.Song> songList = new List<MediaPortal.Music.Database.Song>(); + + string strSQL = string.Empty; + strSQL = String.Format("SELECT song.idSong, song.idArtist, artist.strArtist, song.idAlbum, album.strAlbum, song.idGenre, genre.strGenre, song.idPath, path.strPath, song.strTitle, song.iTrack, song.iDuration, song.iYear, song.strFileName, song.iTimesPlayed, song.iRating, song.favorite FROM song, album, artist, genre, path WHERE song.idPath=path.idPath AND song.idAlbum=album.idAlbum AND song.idGenre=genre.idGenre AND song.idArtist=artist.idArtist AND song.iYear={0}", Year); + + SQLite.NET.SQLiteResultSet results; + results = MediaPortal.Music.Database.MusicDatabase.m_db.Execute(strSQL); + + for (int i = 0; i < results.Rows.Count; ++i) + { + MediaPortal.Music.Database.Song song = new MediaPortal.Music.Database.Song(); + + song.songId = MediaPortal.Database.DatabaseUtility.GetAsInt(results, i, "song.idSong"); + song.artistId = MediaPortal.Database.DatabaseUtility.GetAsInt(results, i, "song.idArtist"); + song.Artist = MediaPortal.Database.DatabaseUtility.Get(results, i, "artist.strArtist"); + song.albumId = MediaPortal.Database.DatabaseUtility.GetAsInt(results, i, "song.idAlbum"); + song.Album = MediaPortal.Database.DatabaseUtility.Get(results, i, "album.strAlbum"); + song.genreId = MediaPortal.Database.DatabaseUtility.GetAsInt(results, i, "song.idGenre"); + song.Genre = MediaPortal.Database.DatabaseUtility.Get(results, i, "genre.strGenre"); + song.Title = MediaPortal.Database.DatabaseUtility.Get(results, i, "song.strTitle"); + song.Track = MediaPortal.Database.DatabaseUtility.GetAsInt(results, i, "song.iTrack"); + song.Duration = MediaPortal.Database.DatabaseUtility.GetAsInt(results, i, "song.iDuration"); + song.Year = MediaPortal.Database.DatabaseUtility.GetAsInt(results, i, "song.iYear"); + + string strFileName = MediaPortal.Database.DatabaseUtility.Get(results, i, "path.strPath"); + strFileName += MediaPortal.Database.DatabaseUtility.Get(results, i, "song.strFileName"); + song.FileName = strFileName; + + song.TimesPlayed = MediaPortal.Database.DatabaseUtility.GetAsInt(results, i, "song.iTimesPlayed"); + song.Rating = MediaPortal.Database.DatabaseUtility.GetAsInt(results, i, "song.iRating"); + song.Favorite = (int)Math.Floor(0.5d + Double.Parse(MediaPortal.Database.DatabaseUtility.Get(results, i, "song.favorite"))) != 0; ; + + songList.Add(song); + } + + return songList; + } + + public List<ECP2Assembly.CustomMPObjects.MusicAlbum> GetAlbumsByArtist(int ArtistID) + { + List<ECP2Assembly.CustomMPObjects.MusicAlbum> albumList = new List<ECP2Assembly.CustomMPObjects.MusicAlbum>(); + + string strSQL = string.Empty; + strSQL = "SELECT DISTINCT idAlbum, strAlbum, idArtist, iNumArtists FROM album,song WHERE song.idAlbum=album.idAlbum AND song.idArtist=" + ArtistID.ToString() + " ORDER BY strAlbum ASC"; + + SQLite.NET.SQLiteResultSet results; + results = MediaPortal.Music.Database.MusicDatabase.m_db.Execute(strSQL); + + for (int i = 0; i < results.Rows.Count; ++i) + { + ECP2Assembly.CustomMPObjects.MusicAlbum album = new ECP2Assembly.CustomMPObjects.MusicAlbum(); + + album.AlbumID = MediaPortal.Database.DatabaseUtility.GetAsInt(results, i, "album.idAlbum"); + album.AlbumName = MediaPortal.Database.DatabaseUtility.Get(results, i, "album.strAlbum"); + album.ArtistID = MediaPortal.Database.DatabaseUtility.GetAsInt(results, i, "album.idArtist"); + album.NumOfArtists = MediaPortal.Database.DatabaseUtility.GetAsInt(results, i, "album.iNumArtists"); + + albumList.Add(album); + } + + return albumList; + } +#endregion + +#region Volume commands + public int GetVolumePercentage() + { + MediaPortal.Player.VolumeHandler volumeHandler = new MediaPortal.Player.VolumeHandler(); + + decimal tmpVolume; + decimal realVolume = volumeHandler.Volume; + tmpVolume = realVolume; + tmpVolume = tmpVolume / (volumeHandler.Maximum - volumeHandler.Minimum); + tmpVolume = tmpVolume * 100; + return (int)System.Math.Round(tmpVolume, 0); + } + + public bool SetVolumePercentage(int VolumePercent) + { + try + { + MediaPortal.Player.VolumeHandler volumeHandler = new MediaPortal.Player.VolumeHandler(); + + decimal tmpVolume; + tmpVolume = VolumePercent; + tmpVolume = tmpVolume / 100; + tmpVolume = tmpVolume * (volumeHandler.Maximum - volumeHandler.Minimum); + tmpVolume = tmpVolume + volumeHandler.Minimum; + + volumeHandler.Volume = (int)System.Math.Round(tmpVolume, 0); + + return true; + } + catch + { + return false; + } + } +#endregion + + #region ECP2 Version commands public string MPECP2Version { get Modified: trunk/source/ECP2WebService/App_Code/Service.cs =================================================================== --- trunk/source/ECP2WebService/App_Code/Service.cs 2006-08-13 12:40:07 UTC (rev 17) +++ trunk/source/ECP2WebService/App_Code/Service.cs 2006-08-19 17:27:28 UTC (rev 18) @@ -303,6 +303,30 @@ return GetEMPH().GetgPlayerProps(propName); } + + [WebMethod(Description = "This command tells the player to seek to a certain point in the item. This point must be expressed in seconds, and must be within the duration of the item. The duration can be checked by using the gPlayerProps method, with the parameter Duration.")] + public bool gPlayerSeekAbsolute(double TimePosition) + { + return GetEMPH().gPlayerSeekAbsolute(TimePosition); + } + + [WebMethod(Description = "This command tells the player to seek to a certain point in the item as a percentage. This point must be expressed as an integer between 0 and 100.")] + public bool gPlayerSeekAbsolutePercentage(int TimePositionPercentage) + { + return GetEMPH().gPlayerSeekAbsolutePercentage(TimePositionPercentage); + } + + [WebMethod(Description = "This command tells the player to seek to a certain point RELATIVE to the current position of the item. For example, if the value -10 was given, this would tell the player to go back 10 seconds. This point must be expressed in seconds, and must be within the duration of the item. The duration can be checked by using the gPlayerProps method, with the parameter Duration.")] + public bool gPlayerSeekRelative(double RelativeTimePosition) + { + return GetEMPH().gPlayerSeekRelative(RelativeTimePosition); + } + + [WebMethod(Description = "This command tells the player to seek to a RELATIVE certain point in the item as a percentage. Therefore if a value of 5 was given, the player would advance to a point 5% ahead of the current point. This point must be expressed as an integer between 0 and 100.")] + public bool gPlayerSeekRelativePercentage(int RelativeTimePositionPercentage) + { + return GetEMPH().gPlayerSeekRelativePercentage(RelativeTimePositionPercentage); + } #endregion #region scheduled recording commands @@ -1142,12 +1166,24 @@ playlistTypeResolve = (MediaPortal.Playlists.PlayListType)Enum.Parse(typeof(MediaPortal.Playlists.PlayListType),playlistType); - MediaPortal.Playlists.PlayList playlist; + ECP2Assembly.CustomMPObjects.PlayList playlist; playlist = GetEMPH().GetPlaylist(playlistTypeResolve); + ////maintain list of types that could exist in the MusicTag property + //System.Type[] musicTagTypes = new System.Type[1]; + //musicTagTypes[0] = typeof(MediaPortal.TagReader.MusicTag); + + // As MusicTag causes problems, set its XMLIgnore attribute to true + System.Xml.Serialization.XmlAttributeOverrides xmlOverrides = new System.Xml.Serialization.XmlAttributeOverrides(); + System.Xml.Serialization.XmlAttributes xmlAttributes; + + xmlAttributes = new System.Xml.Serialization.XmlAttributes(); + xmlAttributes.XmlIgnore = true; + xmlOverrides.Add(typeof(MediaPortal.Playlists.PlayListItem), "MusicTag", xmlAttributes); + System.IO.MemoryStream xwMem = new System.IO.MemoryStream(); System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(xwMem, GetXMLDocWriterSettings()); - System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(MediaPortal.Playlists.PlayListItem )); + System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(MediaPortal.Playlists.PlayListItem), xmlOverrides); MediaPortal.Playlists.PlayListItem playlistItem; try @@ -1156,10 +1192,11 @@ xw.WriteStartElement("MPData"); xw.WriteStartElement("Playlist"); xw.WriteAttributeString("type", playlistType); + xw.WriteAttributeString("count", playlist.PlayListItems.Count.ToString()); - for (int i = 0; i <= playlist.Count - 1; i++) + for (int i = 0; i < playlist.PlayListItems.Count; i++) { - playlistItem = (MediaPortal.Playlists.PlayListItem)playlist[i]; + playlistItem = (MediaPortal.Playlists.PlayListItem)playlist.PlayListItems[i]; xs.Serialize(xw, playlistItem); } @@ -1313,6 +1350,593 @@ } #endregion + #region music commands + [WebMethod(Description = "This command returns a list of all the music albums in XML format.")] + public string GetAllAlbums() + { + List<ECP2Assembly.CustomMPObjects.MusicAlbum> albumList; + albumList = GetEMPH().GetAlbums(); + + if (albumList.Count == 0) return ""; + + System.IO.MemoryStream xwMem = new System.IO.MemoryStream(); + System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(xwMem, GetXMLDocWriterSettings()); + System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(ECP2Assembly.CustomMPObjects.MusicAlbum)); + ECP2Assembly.CustomMPObjects.MusicAlbum album; + + try + { + xw.WriteStartDocument(); + xw.WriteStartElement("MPData"); + xw.WriteStartElement("MusicAlbums"); + + for (int i = 0; i <= albumList.Count - 1; i++) + { + album = (ECP2Assembly.CustomMPObjects.MusicAlbum)albumList[i]; + xs.Serialize(xw, album); + } + + xw.WriteEndElement(); + xw.WriteEndElement(); + xw.WriteEndDocument(); + + xw.Flush(); + } + catch (Exception ex) + { + return ex.ToString(); + } + + return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); + } + + [WebMethod(Description = "This command searches the album name field and returns a list of the matching music albums in XML format. The SearchType parameter can take: wildcardatend, wildcardatstartend, wildcardatstart, or exact.")] + public string GetAlbumsBySearch(string SearchType, string AlbumName) + { + List<ECP2Assembly.CustomMPObjects.MusicAlbum> albumList; + albumList = GetEMPH().GetAlbums(SearchType,AlbumName); + + if (albumList.Count == 0) return ""; + + System.IO.MemoryStream xwMem = new System.IO.MemoryStream(); + System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(xwMem, GetXMLDocWriterSettings()); + System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(ECP2Assembly.CustomMPObjects.MusicAlbum)); + ECP2Assembly.CustomMPObjects.MusicAlbum album; + + try + { + xw.WriteStartDocument(); + xw.WriteStartElement("MPData"); + xw.WriteStartElement("MusicAlbums"); + + for (int i = 0; i <= albumList.Count - 1; i++) + { + album = (ECP2Assembly.CustomMPObjects.MusicAlbum)albumList[i]; + xs.Serialize(xw, album); + } + + xw.WriteEndElement(); + xw.WriteEndElement(); + xw.WriteEndDocument(); + + xw.Flush(); + } + catch (Exception ex) + { + return ex.ToString(); + } + + return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); + } + + [WebMethod(Description = "This command returns a list of all the music artists in XML format.")] + public string GetAllArtists() + { + List<ECP2Assembly.CustomMPObjects.MusicArtist> artistList; + artistList = GetEMPH().GetArtists(); + + if (artistList.Count == 0) return ""; + + System.IO.MemoryStream xwMem = new System.IO.MemoryStream(); + System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(xwMem, GetXMLDocWriterSettings()); + System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(ECP2Assembly.CustomMPObjects.MusicArtist)); + ECP2Assembly.CustomMPObjects.MusicArtist artist; + + try + { + xw.WriteStartDocument(); + xw.WriteStartElement("MPData"); + xw.WriteStartElement("MusicArtists"); + + for (int i = 0; i <= artistList.Count - 1; i++) + { + artist = (ECP2Assembly.CustomMPObjects.MusicArtist)artistList[i]; + xs.Serialize(xw, artist); + } + + xw.WriteEndElement(); + xw.WriteEndElement(); + xw.WriteEndDocument(); + + xw.Flush(); + } + catch (Exception ex) + { + return ex.ToString(); + } + + return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); + } + + [WebMethod(Description = "This command searches the artist name field and returns a list of the matching music artists in XML format. The SearchType parameter can take: wildcardatend, wildcardatstartend, wildcardatstart, or exact.")] + public string GetArtistsBySearch(string SearchType, string ArtistName) + { + List<ECP2Assembly.CustomMPObjects.MusicArtist> artistList; + artistList = GetEMPH().GetArtists(SearchType, ArtistName); + + if (artistList.Count == 0) return ""; + + System.IO.MemoryStream xwMem = new System.IO.MemoryStream(); + System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(xwMem, GetXMLDocWriterSettings()); + System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(ECP2Assembly.CustomMPObjects.MusicArtist)); + ECP2Assembly.CustomMPObjects.MusicArtist artist; + + try + { + xw.WriteStartDocument(); + xw.WriteStartElement("MPData"); + xw.WriteStartElement("MusicArtists"); + + for (int i = 0; i <= artistList.Count - 1; i++) + { + artist = (ECP2Assembly.CustomMPObjects.MusicArtist)artistList[i]; + xs.Serialize(xw, artist); + } + + xw.WriteEndElement(); + xw.WriteEndElement(); + xw.WriteEndDocument(); + + xw.Flush(); + } + catch (Exception ex) + { + return ex.ToString(); + } + + return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); + } + + [WebMethod(Description = "This command returns a list of all the music genres in XML format.")] + public string GetAllGenres() + { + List<ECP2Assembly.CustomMPObjects.MusicGenre> genreList; + genreList = GetEMPH().GetMusicGenres(); + + if (genreList.Count == 0) return ""; + + System.IO.MemoryStream xwMem = new System.IO.MemoryStream(); + System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(xwMem, GetXMLDocWriterSettings()); + System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(ECP2Assembly.CustomMPObjects.MusicGenre)); + ECP2Assembly.CustomMPObjects.MusicGenre genre; + + try + { + xw.WriteStartDocument(); + xw.WriteStartElement("MPData"); + xw.WriteStartElement("MusicGenres"); + + for (int i = 0; i <= genreList.Count - 1; i++) + { + genre = (ECP2Assembly.CustomMPObjects.MusicGenre)genreList[i]; + xs.Serialize(xw, genre); + } + + xw.WriteEndElement(); + xw.WriteEndElement(); + xw.WriteEndDocument(); + + xw.Flush(); + } + catch (Exception ex) + { + return ex.ToString(); + } + + return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); + } + + [WebMethod(Description = "This command searches the genre name field and returns a list of the matching music genres in XML format. The SearchType parameter can take: wildcardatend, wildcardatstartend, wildcardatstart, or exact.")] + public string GetGenresBySearch(string SearchType, string GenreName) + { + List<ECP2Assembly.CustomMPObjects.MusicGenre> genreList; + genreList = GetEMPH().GetMusicGenres(SearchType, GenreName); + + if (genreList.Count == 0) return ""; + + System.IO.MemoryStream xwMem = new System.IO.MemoryStream(); + System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(xwMem, GetXMLDocWriterSettings()); + System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(ECP2Assembly.CustomMPObjects.MusicGenre)); + ECP2Assembly.CustomMPObjects.MusicGenre genre; + + try + { + xw.WriteStartDocument(); + xw.WriteStartElement("MPData"); + xw.WriteStartElement("MusicGenres"); + + for (int i = 0; i <= genreList.Count - 1; i++) + { + genre = (ECP2Assembly.CustomMPObjects.MusicGenre)genreList[i]; + xs.Serialize(xw, genre); + } + + xw.WriteEndElement(); + xw.WriteEndElement(); + xw.WriteEndDocument(); + + xw.Flush(); + } + catch (Exception ex) + { + return ex.ToString(); + } + + return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); + } + + [WebMethod(Description = "This command returns the total number of songs in MP's database.")] + public int GetTotalNumberOfSongs() + { + return GetEMPH().GetNumOfSongs(); + } + + [WebMethod(Description = "This command returns a random song in XML format.")] + public string GetRandomSong() + { + MediaPortal.Music.Database.Song song; + song = GetEMPH().GetRandomSong(); + + if (song == null) return ""; + + System.IO.MemoryStream xwMem = new System.IO.MemoryStream(); + System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(xwMem, GetXMLDocWriterSettings()); + System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(MediaPortal.Music.Database.Song)); + + try + { + xw.WriteStartDocument(); + xw.WriteStartElement("MPData"); + xw.WriteStartElement("MusicSongs"); + + xs.Serialize(xw, song); + + xw.WriteEndElement(); + xw.WriteEndElement(); + xw.WriteEndDocument(); + + xw.Flush(); + } + catch (Exception ex) + { + return ex.ToString(); + } + + return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); + } + + [WebMethod(Description = "This command returns the song with the matching song ID in XML format.")] + public string GetSongByID(int SongID) + { + MediaPortal.Music.Database.Song song; + song = GetEMPH().GetSong(SongID ); + + if (song == null) return ""; + + System.IO.MemoryStream xwMem = new System.IO.MemoryStream(); + System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(xwMem, GetXMLDocWriterSettings()); + System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(MediaPortal.Music.Database.Song)); + + try + { + xw.WriteStartDocument(); + xw.WriteStartElement("MPData"); + xw.WriteStartElement("MusicSongs"); + + xs.Serialize(xw, song); + + xw.WriteEndElement(); + xw.WriteEndElement(); + xw.WriteEndDocument(); + + xw.Flush(); + } + catch (Exception ex) + { + return ex.ToString(); + } + + return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); + } + + [WebMethod(Description = "This command returns the song with the matching song title in XML format. Note if there is more than one song with the title, it will only return the first one.")] + public string GetSongByTitle(string SongTitle) + { + MediaPortal.Music.Database.Song song; + song = GetEMPH().GetSong(SongTitle); + + if (song == null) return ""; + + System.IO.MemoryStream xwMem = new System.IO.MemoryStream(); + System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(xwMem, GetXMLDocWriterSettings()); + System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(MediaPortal.Music.Database.Song)); + + try + { + xw.WriteStartDocument(); + xw.WriteStartElement("MPData"); + xw.WriteStartElement("MusicSongs"); + + xs.Serialize(xw, song); + + xw.WriteEndElement(); + xw.WriteEndElement(); + xw.WriteEndDocument(); + + xw.Flush(); + } + catch (Exception ex) + { + return ex.ToString(); + } + + return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); + } + + [WebMethod(Description = "This command returns the song with the matching song title in XML format. Note if there is more than one song with the title, it will only return the first one.")] + public string GetSongByFileName(string SongFileName) + { + MediaPortal.Music.Database.Song song; + song = GetEMPH().GetSongByFileName(SongFileName); + + if (song == null) return ""; + + System.IO.MemoryStream xwMem = new System.IO.MemoryStream(); + System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(xwMem, GetXMLDocWriterSettings()); + System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(MediaPortal.Music.Database.Song)); + + try + { + xw.WriteStartDocument(); + xw.WriteStartElement("MPData"); + xw.WriteStartElement("MusicSongs"); + + xs.Serialize(xw, song); + + xw.WriteEndElement(); + xw.WriteEndElement(); + xw.WriteEndDocument(); + + xw.Flush(); + } + catch (Exception ex) + { + return ex.ToString(); + } + + return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); + } + + [WebMethod(Description = "This command returns a list of the songs under the specified album ID in XML format.")] + public string GetSongsByAlbum(int AlbumID) + { + List<MediaPortal.Music.Database.Song> songList; + songList = GetEMPH().GetSongsByAlbum(AlbumID); + + ... [truncated message content] |