Advertisement
Guest User

Xbmc Avr autoconfig

a guest
Jul 16th, 2013
343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Get-WebPage {
  2. <#  
  3. .SYNOPSIS  
  4.    Downloads web page from site.
  5. .DESCRIPTION
  6.    Downloads web page from site and displays source code or displays total bytes of webpage downloaded
  7. .PARAMETER Url
  8.     URL of the website to test access to.
  9. .PARAMETER UseDefaultCredentials
  10.     Use the currently authenticated user's credentials  
  11. .PARAMETER Proxy
  12.     Used to connect via a proxy
  13. .PARAMETER Credential
  14.     Provide alternate credentials
  15. .PARAMETER ShowSize
  16.     Displays the size of the downloaded page in bytes
  17. .NOTES  
  18.     Name: Get-WebPage
  19.     Author: Boe Prox
  20.     DateCreated: 08Feb2011        
  21. .EXAMPLE  
  22.     Get-WebPage -url "http://www.bing.com"
  23.    
  24. Description
  25. ------------
  26. Returns the source code from bing.com -showsize
  27. .EXAMPLE  
  28.     Get-WebPage -url "http://www.bing.com" -ShowSize
  29.    
  30. Description
  31. ------------
  32. Returns the size of the webpage bing.com in bytes.
  33. #>
  34. [cmdletbinding(
  35.     DefaultParameterSetName = 'url',
  36.     ConfirmImpact = 'low'
  37. )]
  38.     Param(
  39.         [Parameter(
  40.             Mandatory = $True,
  41.             Position = 0,
  42.             ParameterSetName = '',
  43.             ValueFromPipeline = $True)]
  44.             [string][ValidatePattern("^(http|https)\://*")]$Url,
  45.         [Parameter(
  46.             Position = 1,
  47.             Mandatory = $False,
  48.             ParameterSetName = 'defaultcred')]
  49.             [switch]$UseDefaultCredentials,
  50.         [Parameter(
  51.             Mandatory = $False,
  52.             ParameterSetName = '')]
  53.             [string]$Proxy,
  54.         [Parameter(
  55.             Mandatory = $False,
  56.             ParameterSetName = 'altcred')]
  57.             [switch]$Credential,
  58.         [Parameter(
  59.             Mandatory = $False,
  60.             ParameterSetName = '')]
  61.             [switch]$ShowSize                        
  62.                        
  63.         )
  64. Begin {    
  65.     $psBoundParameters.GetEnumerator() | % {
  66.         Write-Verbose "Parameter: $_"
  67.         }
  68.    
  69.     #Create the initial WebClient object
  70.     Write-Verbose "Creating web client object"
  71.     $wc = New-Object Net.WebClient
  72.    
  73.     #Use Proxy address if specified
  74.     If ($PSBoundParameters.ContainsKey('Proxy')) {
  75.         #Create Proxy Address for Web Request
  76.         Write-Verbose "Creating proxy address and adding into Web Request"
  77.         $wc.Proxy = New-Object -TypeName Net.WebProxy($proxy,$True)
  78.         }      
  79.    
  80.     #Determine if using Default Credentials
  81.     If ($PSBoundParameters.ContainsKey('UseDefaultCredentials')) {
  82.         #Set to True, otherwise remains False
  83.         Write-Verbose "Using Default Credentials"
  84.         $wc.UseDefaultCredentials = $True
  85.         }
  86.     #Determine if using Alternate Credentials
  87.     If ($PSBoundParameters.ContainsKey('Credentials')) {
  88.         #Prompt for alternate credentals
  89.         Write-Verbose "Prompt for alternate credentials"
  90.         $wc.Credential = (Get-Credential).GetNetworkCredential()
  91.         }        
  92.        
  93.     }
  94. Process {    
  95.     Try {
  96.         If ($ShowSize) {
  97.             #Get the size of the webpage
  98.             Write-Verbose "Downloading web page and determining size"
  99.             "{0:N0}" -f ($wr.DownloadString($url) | Out-String).length -as [INT]
  100.             }
  101.         Else {
  102.             #Get the contents of the webpage
  103.             Write-Verbose "Downloading web page and displaying source code"
  104.             $wc.DownloadString($url)      
  105.             }
  106.        
  107.         }
  108.     Catch {
  109.         Write-Warning "$($Error[0])"
  110.         }
  111.     }  
  112. }  
  113.  
  114. cls
  115. #If it's off, switch to 2.0 and all settings to OFF
  116. #If it's on, switch to 5.1 and all settings to ON
  117.  
  118. # XML loading
  119. $XMLPath = $env:USERPROFILE+"\AppData\Roaming\XBMC\userdata\guisettings.xml"
  120.  
  121. $XML =[xml](Get-content $XMLPath)
  122.  
  123. if (!(Get-WebPage -url "http://192.168.137.115/top.asp").tolower().Contains("/top_off.png"))
  124. {
  125.     #it's on
  126.     $XML.settings.audiooutput.ac3passthrough = "true"
  127.     $XML.settings.audiooutput.channels = "8"
  128.     $XML.settings.audiooutput.dtshdpassthrough = "true"
  129.     $XML.settings.audiooutput.dtspassthrough = "true"
  130.     $XML.settings.audiooutput.multichannellpcm = "true"
  131.     $XML.settings.audiooutput.passthroughaac = "true"
  132.     $XML.settings.audiooutput.stereoupmix = "true"
  133.     $XML.settings.audiooutput.truehdpassthrough = "true"
  134. }
  135. else
  136. {
  137.     #it's off
  138.     $XML.settings.audiooutput.ac3passthrough = "false"
  139.     $XML.settings.audiooutput.channels = "1"
  140.     $XML.settings.audiooutput.dtshdpassthrough = "false"
  141.     $XML.settings.audiooutput.dtspassthrough = "false"
  142.     $XML.settings.audiooutput.multichannellpcm = "false"
  143.     $XML.settings.audiooutput.passthroughaac = "false"
  144.     $XML.settings.audiooutput.stereoupmix = "false"
  145.     $XML.settings.audiooutput.truehdpassthrough = "false"
  146. }
  147.  
  148. #save XML
  149.  
  150. $XML.Save($XMLPath)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement