Example #1
0
        public override void handleCommand(string command, string[] arguments, ref TvControl.IUser me)
        {
            // we want to list all recorded TV shows
            List <string> results = new List <string>();

            List <RecordedInfo> recorded = TVServerConnection.getRecordedTV();

            foreach (RecordedInfo r in recorded)
            {
                Int32  runningTime = Convert.ToInt32((r.endTime.Ticks - r.startTime.Ticks) / 10000000);
                string streamURL   = TVServerConnection.getRecordingURL(Convert.ToInt32(r.ID));
                string recitem     = writer.makeItem(
                    r.ID.ToString(),
                    r.title.Replace(";", ""),
                    r.description.Replace(";", ""),
                    r.genre,
                    r.played.ToString(),
                    r.startTime.ToString(),
                    r.endTime.ToString(),
                    r.filename,
                    r.channelName.Replace(";", ""),
                    runningTime.ToString(),
                    streamURL);
                results.Add(recitem);
                Console.WriteLine("Recorded: " + recitem);
            }

            writer.writeList(results);
        }
Example #2
0
        public override void handleCommand(string command, string[] arguments, ref TvControl.IUser me)
        {
            int           cardID  = -1;
            List <string> results = new List <string>();

            try
            {
                if (arguments != null)
                {
                    cardID = Int32.Parse(arguments[0]);
                }
                else
                {
                    cardID = me.CardId;
                }

                TVServerController server  = TVServerConnection.GetServerInterface();
                ReceptionDetails   details = server.GetReceptionDetails(cardID);

                server.HeartBeat(me);
                writer.write(details.signalLevel.ToString() + "|" + details.signalQuality.ToString());
            }
            catch
            {
                Console.WriteLine(getCommandToHandle() + ": failed");
                writer.write("");
            }
            //getConnection().WriteLine("[ERROR]: Expected format: " + getCommandToHandle() + "[:cardID]");
        }
        /*
         * Expect arguments: ChannelID
         */
        public override void handleCommand(string command, string[] arguments, ref TvControl.IUser me)
        {
            if (arguments == null || arguments.Length < 1)
            {
                getConnection().WriteLine("[ERROR]: Usage: " + getCommandToHandle() + ":ChannelId[|ResolveIPs=False][|StopTimeshift=True]");
                return;
            }

            try {
                int    chanId        = int.Parse(arguments[0]);
                bool   resolveToIP   = true;
                bool   stoptimeshift = true;
                string originalURL   = "";
                string result;
                string timeShiftFileName = "";
                Int64  timeShiftBufPos   = 0;
                long   timeShiftBufNr    = 0;

                if (arguments.Length >= 2)
                {
                    resolveToIP = Boolean.Parse(arguments[1]);
                    if (arguments.Length >= 3)
                    {
                        stoptimeshift = Boolean.Parse(arguments[2]);
                    }

                    if (stoptimeshift)
                    {
                        TVServerConnection.StopTimeshift(ref me);
                    }

                    result = TVServerConnection.playChannel(chanId, resolveToIP, ref originalURL, ref me, ref timeShiftFileName, ref timeShiftBufPos, ref timeShiftBufNr);
                    if (!result.StartsWith("[ERROR]"))
                    {
                        if (resolveToIP == true)
                        {
                            result += "|" + originalURL;
                        }
                        else
                        {
                            result += "|";
                        }
                        result += "|" + timeShiftFileName +
                                  "|" + me.CardId.ToString() +
                                  "|" + timeShiftBufPos.ToString() +
                                  "|" + timeShiftBufNr.ToString();
                    }

                    writer.write(result);
                }
                else
                {   //backward compatibility
                    TVServerConnection.StopTimeshift(ref me);
                    result = TVServerConnection.playChannel(chanId, resolveToIP, ref originalURL, ref me, ref timeShiftFileName, ref timeShiftBufPos, ref timeShiftBufNr);
                    writer.write(result);
                }
            } catch {
                getConnection().WriteLine("[ERROR]: Usage: " + getCommandToHandle() + ":ChannelId[|ResolveIPs][|StopTimeshift]");
            }
        }
        public override void handleCommand(string command, string[] arguments, ref TvControl.IUser me)
        {
            String result;

            if (arguments != null)
            {
                try
                {
                    int  index          = Int32.Parse(arguments[0]);
                    bool useUriEncoding = false;

                    if (arguments.Length >= 2)
                    {
                        useUriEncoding = bool.Parse(arguments[1]);
                    }

                    result = TVServerConnection.GetScheduleInfo(index);
                    Console.WriteLine("GetScheduleInfo:" + index + " " + result);

                    writer.write(result, useUriEncoding);
                }
                catch
                {
                    Console.WriteLine("GetScheduleInfo: failed");
                    writer.write("");
                }
            }
            else
            {
                getConnection().WriteLine("[ERROR]: Expected format: " + getCommandToHandle() + ":ScheduleID");
            }
        }
Example #5
0
        public override void handleCommand(string command, string[] arguments, ref TvControl.IUser me)
        {
            if ((arguments != null) && (arguments.Length == 2))
            {
                try
                {
                    string  strChannelName = arguments[0];
                    Boolean bIsRadio       = Boolean.Parse(arguments[1]);
                    string  strThumbName   = "False";
                    Boolean bFound         = false;

                    string strThumbPath = TVServerConnection.GetLogoPath(bIsRadio);

                    string strThumbBaseName = ToThumbFileName(strChannelName);

                    foreach (string strExt in strThumbExt)
                    {
                        strThumbName = strThumbBaseName + strExt;
                        if (File.Exists(strThumbPath + strThumbName))
                        {
                            bFound = true;
                            break;
                        }
                    }

                    if (!bFound)
                    {
                        writer.write("0|False");
                    }
                    else
                    {
                        Byte[] thumbData            = File.ReadAllBytes(strThumbPath + strThumbName);
                        Int32  fileLength           = thumbData.Length;
                        Int32  thumbNameLength      = strThumbName.Length;
                        Byte[] utf8ThumbName        = System.Text.Encoding.UTF8.GetBytes(strThumbName);
                        Byte[] thumbNameLengthBytes = BitConverter.GetBytes(System.Net.IPAddress.HostToNetworkOrder(utf8ThumbName.Length));
                        Byte[] fileLengthBytes      = BitConverter.GetBytes(System.Net.IPAddress.HostToNetworkOrder(fileLength));

                        Byte[] strThumbInfo = { 0x31, 0x7C }; // ASCII: "1|"

                        writer.writeBytes(strThumbInfo);
                        writer.writeBytes(thumbNameLengthBytes);
                        writer.writeBytes(utf8ThumbName);
                        writer.writeBytes(fileLengthBytes);
                        writer.writeBytes(thumbData);

                        Byte[] strEnd = { 0x7C, 0x45, 0x4E, 0x44 }; // ASCII: "|END"
                        writer.writeBytes(strEnd);
                    }
                }
                catch
                {
                    writer.write("0|Error");
                }
            }
            else
            {
                getConnection().WriteLine("[ERROR]: Expected format: " + getCommandToHandle() + ":ChannelName|IsRadio");
            }
        }
Example #6
0
        /*
         * No arguments needed
         */
        public override void handleCommand(string command, string[] arguments, ref TvControl.IUser me)
        {
            bool result = TVServerConnection.StopTimeshift(ref me);

            Console.WriteLine("StopTimeshift result: " + result.ToString());
            writer.write(result.ToString());
        }
Example #7
0
        /*
         * No arguments needed
         */
        public override void handleCommand(string command, string[] arguments, ref TvControl.IUser me)
        {
            bool result = TVServerConnection.IsRecording();

            Console.WriteLine("IsRecording result: " + result.ToString());
            writer.write(result.ToString());
        }
Example #8
0
        public override void handleCommand(string command, string[] arguments, ref TvControl.IUser me)
        {
            List <string> groups;

            if ((arguments != null) && (arguments[0].Length > 0))
            {   //we want to list all channels in group arg[0]
                groups = new List <string>(arguments);
            }
            else
            {
                groups = new List <string>();
            }

            List <string> tvchannels = TVServerConnection.GetTVChannels(groups);

            if (tvchannels != null)
            {
                foreach (string channel in tvchannels)
                {
                    Console.WriteLine(channel);
                }
                writer.writeList(tvchannels);
            }
            else
            {
                getConnection().WriteLine("[ERROR]: No TV channels found");
            }
        }
Example #9
0
        public override void handleCommand(string command, string[] arguments, ref TvControl.IUser me)
        {
            string VersionNr = "1.0.0";

            // Fetch the MediaPortal TVServer version
            VersionNr = TVServerConnection.GetVersion();

            writer.write(VersionNr);
        }
        public override void handleCommand(string command, string[] arguments, ref TvControl.IUser me)
        {
            // we want to list all channels in group arg[0]
            // String group = arguments[0];
            int count = 0;

            count = TVServerConnection.getScheduleCount();

            Console.WriteLine("GetScheduleCount: " + count);

            writer.write(count.ToString());
        }
Example #11
0
        public override void handleCommand(string command, string[] arguments, ref TvControl.IUser me)
        {
            DateTime localtime = DateTime.Now;
            DateTime utctime   = DateTime.UtcNow;
            TimeSpan utcdiff   = (localtime - utctime);

            Console.WriteLine("Local time: " + localtime + " UTC time: " + utctime + " Offset: " + utcdiff.Hours);
            //Format: dd-mm-yyyy hh:mm:ss;offset hours;offset seconds
            writer.write(writer.makeItem(localtime.ToString("u"),
                                         utcdiff.Hours.ToString(),
                                         utcdiff.Minutes.ToString()));
        }
Example #12
0
        public override void handleCommand(string command, string[] arguments, ref TvControl.IUser me)
        {
            // this needs no arguments, and will just list all the tvgroups

            List <String> groups = TVServerConnection.GetTVGroups();

            foreach (String group in groups)
            {
                Console.WriteLine("GROUP : " + group);
            }

            writer.writeList(groups);
        }
Example #13
0
        /*
         * 1 optional argument: id
         */
        public override void handleCommand(string command, string[] arguments, ref TvControl.IUser me)
        {
            int schedId = -1;

            if ((arguments != null) && (arguments.Length == 1))
            {
                schedId = int.Parse(arguments[0]);
            }

            bool result = TVServerConnection.StopRecording(schedId);

            Console.WriteLine("StopRecording result : " + result.ToString());
            writer.write(result.ToString());
        }
Example #14
0
        /*
         * No arguments needed, will list all commands available
         */
        public override void handleCommand(string myCommand, string[] arguments, ref TvControl.IUser me)
        {
            // get a list of all commands
            Dictionary <String, CommandHandler> allCommands = this.getConnection().getAllHandlers();

            List <string> results = new List <string>();

            foreach (CommandHandler command in allCommands.Values)
            {
                results.Add(command.getCommandToHandle());
            }
            writer.writeList(results);

            Console.WriteLine("Returned " + results.Count + " commands");
        }
        public override void handleCommand(string command, string[] arguments, ref TvControl.IUser me)
        {
            if (arguments == null)
            {
                getConnection().WriteLine("[ERROR]: Expected format: " + getCommandToHandle() + ":RecordingId");
                return;
            }

            int recId = int.Parse(arguments[0]);

            bool result = TVServerConnection.DeleteRecordedTV(recId);

            Console.WriteLine("DeleteRecordedTV result : " + result.ToString());
            writer.write(result.ToString());
        }
Example #16
0
        public override void handleCommand(string command, string[] arguments, ref TvControl.IUser me)
        {
            // we want to list all recordings
            List <string> results     = new List <string>();
            bool          resolveToIP = true;
            string        originalURL = "";

            if (arguments != null && arguments.Length == 1)
            {
                resolveToIP = Boolean.Parse(arguments[0]);
            }

            results = TVServerConnection.GetRecordings(resolveToIP, ref originalURL);
            writer.writeList(results);
        }
Example #17
0
        public override void handleCommand(string command, string[] arguments, ref TvControl.IUser me)
        {
            if ((arguments != null) && (arguments.Length == 1))
            {
                int recindex = int.Parse(arguments[0]);

                int result = TVServerConnection.GetRecordingStopTime(recindex);
                Console.WriteLine("GetRecordingStopTime result : " + result.ToString());
                writer.write(result.ToString());
            }
            else
            {
                getConnection().WriteLine("[ERROR]: Expected format: " + getCommandToHandle() + ":RecordingIndex");
            }
        }
Example #18
0
        public override void handleCommand(string command, string[] arguments, ref TvControl.IUser me)
        {
            // we want to list all channels in group arg[0]
            if ((arguments != null) && (arguments.Length == 2))
            {
                int    recindex = int.Parse(arguments[0]);
                String name     = arguments[1];

                bool result = TVServerConnection.UpdateRecording(recindex, name);
                Console.WriteLine("UpdateRecording result : " + result.ToString());
                writer.write(result.ToString());
            }
            else
            {
                getConnection().WriteLine("[ERROR]: Expected format: " + getCommandToHandle() + ":RecordingIndex|NewName");
            }
        }
        public override void handleCommand(string command, string[] arguments, ref TvControl.IUser me)
        {
            // we want to list all channels in group arg[0]
            if ((arguments != null) && (arguments.Length == 2))
            {
                int recindex = int.Parse(arguments[0]);
                int count    = int.Parse(arguments[1]);

                bool result = TVServerConnection.SetRecordingTimesWatched(recindex, count);
                Console.WriteLine("SetRecordingTimesWatched result : " + result.ToString());
                writer.write(result.ToString());
            }
            else
            {
                getConnection().WriteLine("[ERROR]: Expected format: " + getCommandToHandle() + ":RecordingIndex|timesWatched");
            }
        }
        public override void handleCommand(string command, string[] arguments, ref TvControl.IUser me)
        {
            // Fetch the info for a particular recording
            String result;

            if (arguments != null)
            {
                try
                {
                    int  index              = Int32.Parse(arguments[0]);
                    bool withRTSPurl        = false;
                    bool useUriEncoding     = false;
                    bool resolveRTSPurlToIP = false;

                    if (arguments.Length >= 2)
                    {
                        withRTSPurl = bool.Parse(arguments[1]);
                    }
                    if (arguments.Length >= 3)
                    {
                        useUriEncoding = bool.Parse(arguments[2]);
                    }
                    if (arguments.Length >= 4)
                    {
                        resolveRTSPurlToIP = bool.Parse(arguments[3]);
                    }

                    result = TVServerConnection.getRecordingInfo(index, withRTSPurl, resolveRTSPurlToIP);
                    Console.WriteLine(getCommandToHandle() + ":" + index + " " + result);

                    writer.write(result, useUriEncoding);
                }
                catch
                {
                    Console.WriteLine(getCommandToHandle() + ": failed");
                    writer.write("");
                }
            }
            else
            {
                getConnection().WriteLine("[ERROR]: Expected format: " + getCommandToHandle() + ":RecordingID[|withRTSPurl=False]");
            }
        }
Example #21
0
        public override void handleCommand(string command, string[] arguments, ref TvControl.IUser me)
        {
            String group;
            int    count = 0;

            if (arguments != null)
            {   //we want to list all channels in group arg[0]
                group = arguments[0];
            }
            else
            {
                group = "";
            }

            count = TVServerConnection.getChannelCount(group);

            Console.WriteLine("GetChannelCount: " + count);

            writer.write(count.ToString());
        }
Example #22
0
 public override void handleCommand(string command, string[] arguments, ref TvControl.IUser me)
 {
     // we want to list all channels in group arg[0]
     if ((arguments != null) && (arguments.Length == 1))
     {
         try
         {
             String name = arguments[0];
             me = TVServerConnection.RequestUser(name);
             writer.write("True");
         }
         catch
         {
             writer.write("[ERROR]");
         }
     }
     else
     {
         getConnection().WriteLine("[ERROR]: Expected format: " + getCommandToHandle() + ":Name");
     }
 }
Example #23
0
        public override void handleCommand(string command, string[] arguments, ref TvControl.IUser me)
        {
            //TvEngine.PowerScheduler.WaitableTimer tveps;
            TvBusinessLayer layer     = new TvBusinessLayer();
            int             schedtype = (int)TvDatabase.ScheduleRecordingType.Once;
            Schedule        newSchedule;

            DateTime startTime = new DateTime(2009, 11, 23, 10, 00, 00);
            DateTime endTime   = new DateTime(2009, 11, 23, 11, 15, 00);

            try
            {
                newSchedule = layer.AddSchedule(32, "Marcel test", startTime, endTime, schedtype);
                newSchedule.Persist();
                Console.WriteLine("Schedule added: " + newSchedule.IdChannel.ToString());
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Example #24
0
        public override void handleCommand(string command, string[] arguments, ref TvControl.IUser me)
        {
            List <string> groups;

            if ((arguments != null) && (arguments[0].Length > 0))
            {   //we want to list all channels in group arg[0]
                groups = new List <string>(arguments);
            }
            else
            {
                groups = new List <string>();
            }

            List <string> radiochannels = TVServerConnection.GetRadioChannels(groups);

            foreach (string channel in radiochannels)
            {
                Console.WriteLine(channel);
            }

            writer.writeList(radiochannels);
        }
Example #25
0
        public override void handleCommand(string command, string[] arguments, ref TvControl.IUser me)
        {
            try
            {
                bool seriesSupport = false;
                if (arguments != null && arguments.Length >= 1)
                {
                    if (arguments[0].Length > 0)
                    {
                        seriesSupport = Boolean.Parse(arguments[0]);
                    }
                }

                // we want to list all scheduled recordings
                List <string> results = new List <string>();

                results = TVServerConnection.GetSchedules(seriesSupport);
                writer.writeList(results);
            } catch {
                getConnection().WriteLine("[ERROR]: Usage: " + getCommandToHandle() + ":[seriesSupport=False]");
            }
        }
Example #26
0
        public override void handleCommand(string command, string[] arguments, ref TvControl.IUser me)
        {
            String        group;
            List <string> results = new List <string>();

            if (arguments != null)
            {   //we want to list all channels in group arg[0]
                group = arguments[0];
            }
            else
            {
                group = "";
            }

            List <ChannelInfo> channels = TVServerConnection.getChannels(group);

            foreach (ChannelInfo c in channels)
            {
                results.Add(writer.makeItemSmart(c));
                Console.WriteLine("CHANNEL : " + c.channelID + ";" + c.name + ";" + c.isScrambled.ToString());
            }

            writer.writeList(results);
        }
Example #27
0
        /*
         * No arguments needed
         */
        public override void handleCommand(string command, string[] arguments, ref TvControl.IUser me)
        {
            TimeShiftURLs timeShiftURLs = TVServerConnection.getTimeshiftURLs(ref me);
            bool          result        = true;

            if (timeShiftURLs == null || String.IsNullOrEmpty(timeShiftURLs.RTSPUrl) || String.IsNullOrEmpty(timeShiftURLs.TimeShiftFileName))
            {
                timeShiftURLs = new TimeShiftURLs {
                    RTSPUrl = "", TimeShiftFileName = ""
                };
                result = false;
            }

            // results = isShifting;url;chanInfo as in ListChannels
            // chanInfo must be the same as the listchannel..
            ChannelInfo c = new ChannelInfo();

            if (result)
            {
                c = TVServerConnection.getTimeshiftInfo(ref me);
            }

            writer.write(writer.makeItemSmart(result.ToString(), timeShiftURLs.RTSPUrl, timeShiftURLs.TimeShiftFileName, c));
        }
Example #28
0
        public override void handleCommand(string command, string[] arguments, ref TvControl.IUser me)
        {
            bool          timeshiftingUsers = false;
            List <string> results           = new List <string>();

            if (arguments != null && arguments.Length == 1)
            {
                if (arguments[0] == "TimeshiftingUsers")
                {
                    timeshiftingUsers = true;
                }
            }

            if (timeshiftingUsers)
            {
                results = TVServerConnection.getTimeshiftingUserNames();
            }
            else
            {
                results.Add(me.Name);
            }

            writer.writeList(results);
        }
Example #29
0
        public override void handleCommand(string command, string[] arguments, ref TvControl.IUser me)
        {
            int           cardID  = -1;
            List <string> results = new List <string>();

            try
            {
                if (arguments != null)
                {
                    cardID = Int32.Parse(arguments[0]);
                }

                TVServerController server = TVServerConnection.GetServerInterface();
                results = server.GetCardSettings(cardID);

                writer.writeList(results);
            }
            catch
            {
                Console.WriteLine(getCommandToHandle() + ": failed");
                writer.write("");
            }
            //getConnection().WriteLine("[ERROR]: Expected format: " + getCommandToHandle() + "[:cardID]");
        }
 public override void handleCommand(string command, string[] arguments, ref TvControl.IUser me)
 {
     writer.write(TVServerConnection.getBackendName());
 }
Example #31
0
        public void HandleConnection()
        {
            try
            {
                NetworkStream cStream = this.client.GetStream();
                StreamReader reader = new StreamReader(cStream);
                writer = new DataWriter(cStream);

                // first we get what version of the protocol
                // we expect "TVServerXBMC:0-2"
                String versionInfo = reader.ReadLine();
                if (versionInfo == null) return;

                // version 2 is not backards compatible
                versionInfo = Uri.UnescapeDataString(versionInfo);
                if (versionInfo.ToLower().Contains("telnet"))
                {
                    // human connection
                    writer.setArgumentSeparator("|");
                    writer.setListSeparator(Environment.NewLine);
                    writer.setHumanEncoders();

                    //reader side:
                    cmd_sep = ":";
                    arg_sep = "|";

                    WriteLine("Protocol Accepted; TVServerKodi version: " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString());
                    Console.WriteLine("Correct protocol, telnet connection accepted!");
                    Log.Debug("TVServerKodi: telnet connection accepted!");

                    username = "******";
                    clientType = ClientType.telnet;
                }
                else if (Regex.IsMatch(versionInfo, "^TVServerXBMC:0-[0-3]$", RegexOptions.IgnoreCase))
                {
                    WriteLine("Protocol-Accept;0-3");
                    Console.WriteLine("Correct protocol, connection accepted!");
                    Log.Debug("TVServerKodi: connection accepted!");
                    username = "******";
                    clientType = ClientType.python;
                }
                else if (Regex.IsMatch(versionInfo, "^PVRclientXBMC:0-[1]$", RegexOptions.IgnoreCase))
                {
                    writer.setArgumentSeparator("|");
                    //reader side:
                    cmd_sep = ":";
                    arg_sep = "|";

                    WriteLine("Protocol-Accept:0|" + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString());
                    Console.WriteLine("Correct protocol, connection accepted!");
                    Log.Debug("TVServerKodi: connection accepted from XBMC PVR addon");

                    username = "******" + clientnr;
                    clientType = ClientType.pvrclient;
                }
                else if (Regex.IsMatch(versionInfo, "^PVRclientKodi:0-[1]$", RegexOptions.IgnoreCase))
                {
                    writer.setArgumentSeparator("|");
                    //reader side:
                    cmd_sep = ":";
                    arg_sep = "|";

                    WriteLine("Protocol-Accept:0|" + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString());
                    Console.WriteLine("Correct protocol, connection accepted!");
                    Log.Debug("TVServerKodi: connection accepted from Kodi PVR addon");

                    username = "******" + clientnr;
                    clientType = ClientType.pvrclient;
                }
                else
                {
                    WriteLine("Unexpected Protocol");
                    client.Close();
                    Console.WriteLine("Unexpected protocol:" + versionInfo);
                    Log.Debug("TVServerKodi: Unexpected protocol:" + versionInfo);

                    clientType = ClientType.unknown;
                    return;
                }

                me = TVServerConnection.RequestUser(username);

                ProcessConnection(reader);
                reader.Dispose();
                cStream.Dispose();
            }
            catch (Exception e)
            {
                WriteLine("[ERROR]: HandleConnection failed");
                Log.Debug("TVServerKodi: HandleConnection failed");
                Log.Debug("TVServerKodi: Exception => " + e.Message);
                Log.Debug("TVServerKodi: Stack trace: " + e.StackTrace);
            }
        }