Flag/switch to start MediaPortal with/without waking TV? (1 Viewer)

DragonQ

Portal Pro
August 30, 2011
644
79
Home Country
United Kingdom United Kingdom
Hi,

I use the "wake TV server when launching" option (forgot exact name), which works fine but it introduces a significant delay to the launch time. If I want to start MediaPortal just to use a non-TV function (e.g. watch a film or series episode) it's annoying to have to wait 20-25 seconds for the TV server to wake up when I don't need it to.

So is there a way to set the "wake TV server when launching" option via a command line argument/switch/flag? Something like "...MediaPortal.exe -WakeTV" or whatever?


Thanks.
 

DragonQ

Portal Pro
August 30, 2011
644
79
Home Country
United Kingdom United Kingdom
After some playing around I think I managed to get this to work but it requires manual editing of the MediaPortal.xml configuration file. Basically if you want to launch MediaPortal without it connecting to your TV Server, you need to disable the TV plugin. You'll need a batch file or small utility program to do this. I have a "kiosk" type program written in VB.NET that I use as a selection tool, so I just made a pair of functions for it:

Code:
Private Function EnableMediaPortalTV() As Boolean

  Try
    'Read in MediaPortal.xml configuration file
    Dim MyLines As String() = IO.File.ReadAllLines("C:\ProgramData\Team MediaPortal\MediaPortal\MediaPortal.xml")
    Dim Flag As Boolean = False

    'Look through each line until we find the ones we need to change
    For a As Int32 = 0 To MyLines.Length - 1
      'If flag is set, we've passed a prerequisite line, so continue checks...
      If Flag Then
        If MyLines(a).Contains("<entry name=""TV"">") Then
          'This is a line we need to change, so do it then reset flag
          MyLines(a) = MyLines(a).Replace("<entry name=""TV"">no</entry>", "<entry name=""TV"">yes</entry>")
          Flag = False
        End If
      ElseIf MyLines(a).Contains("<section name=""plugins"">") OrElse MyLines(a).Contains("<section name=""pluginsdlls"">") Then
        'We've reached a prerequisite line, which means we'll need to change the next instance of "TV", so set flag to true
        Flag = True
      End If

      'This line only appears once and needs changing
      If MyLines(a).Contains("<entry name=""TvPlugin.TVHome"">") Then MyLines(a) = MyLines(a).Replace("<entry name=""TvPlugin.TVHome"">no</entry>", "<entry name=""TvPlugin.TVHome"">yes</entry>")
    Next

    'Write out our changed configuration lines to the XML file
    File.WriteAllLines("C:\ProgramData\Team MediaPortal\MediaPortal\MediaPortal.xml", MyLines)

    Return True 'Everything went OK
  Catch ex As Exception 'Something went wrong so inform user
    MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error)
    Return False
  End Try

End Function


Private Function DisableMediaPortalTV() As Boolean

  Try
    'Read in MediaPortal.xml configuration file
    Dim MyLines As String() = IO.File.ReadAllLines("C:\ProgramData\Team MediaPortal\MediaPortal\MediaPortal.xml")
    Dim Flag As Boolean = False

    'Look through each line until we find the ones we need to change
    For a As Int32 = 0 To MyLines.Length - 1
      'If flag is set, we've passed a prerequisite line, so continue checks...
      If Flag Then
        If MyLines(a).Contains("<entry name=""TV"">") Then
          'This is a line we need to change, so do it then reset flag
          MyLines(a) = MyLines(a).Replace("<entry name=""TV"">yes</entry>", "<entry name=""TV"">no</entry>")
          Flag = False
        End If
      ElseIf MyLines(a).Contains("<section name=""plugins"">") OrElse MyLines(a).Contains("<section name=""pluginsdlls"">") Then
        'We've reached a prerequisite line, which means we'll need to change the next instance of "TV", so set flag to true
        Flag = True
      End If

      'This line only appears once and needs changing
      If MyLines(a).Contains("<entry name=""TvPlugin.TVHome"">") Then MyLines(a) = MyLines(a).Replace("<entry name=""TvPlugin.TVHome"">yes</entry>", "<entry name=""TvPlugin.TVHome"">no</entry>")
    Next

    'Write out our changed configuration lines to the XML file
    File.WriteAllLines("C:\ProgramData\Team MediaPortal\MediaPortal\MediaPortal.xml", MyLines)

    Return True 'Everything went OK
  Catch ex As Exception 'Something went wrong so inform user
    MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error)
    Return False
  End Try

End Function

There is a cleaner way of doing it with .NET's XMLReader class but this was just quicker to write. I'm also doing the WOL (Wake on LAN) part myself now in code. This is probably unnecessary but MediaPortal might still try to initiate a WOL command with the TV plugin disabled, I'm not sure.
 

Users who are viewing this thread

Top Bottom