Advertisement
go2tom42

Untitled

Sep 11th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Function Get-IniContent {  
  2.     <#  
  3.     .Synopsis  
  4.         Gets the content of an INI file  
  5.          
  6.     .Description  
  7.         Gets the content of an INI file and returns it as a hashtable  
  8.          
  9.     .Notes  
  10.         Author        : Oliver Lipkau <oliver@lipkau.net>  
  11.         Blog        : http://oliver.lipkau.net/blog/  
  12.         Source        : https://github.com/lipkau/PsIni
  13.                       http://gallery.technet.microsoft.com/scriptcenter/ea40c1ef-c856-434b-b8fb-ebd7a76e8d91
  14.         Version        : 1.0 - 2010/03/12 - Initial release  
  15.                       1.1 - 2014/12/11 - Typo (Thx SLDR)
  16.                                          Typo (Thx Dave Stiff)
  17.          
  18.         #Requires -Version 2.0  
  19.          
  20.     .Inputs  
  21.         System.String  
  22.          
  23.     .Outputs  
  24.         System.Collections.Hashtable  
  25.          
  26.     .Parameter FilePath  
  27.         Specifies the path to the input file.  
  28.          
  29.     .Example  
  30.         $FileContent = Get-IniContent "C:\myinifile.ini"  
  31.         -----------  
  32.         Description  
  33.         Saves the content of the c:\myinifile.ini in a hashtable called $FileContent  
  34.      
  35.     .Example  
  36.         $inifilepath | $FileContent = Get-IniContent  
  37.         -----------  
  38.         Description  
  39.         Gets the content of the ini file passed through the pipe into a hashtable called $FileContent  
  40.      
  41.     .Example  
  42.         C:\PS>$FileContent = Get-IniContent "c:\settings.ini"  
  43.         C:\PS>$FileContent["Section"]["Key"]  
  44.         -----------  
  45.         Description  
  46.         Returns the key "Key" of the section "Section" from the C:\settings.ini file  
  47.          
  48.     .Link  
  49.         Out-IniFile  
  50.     #>  
  51.      
  52.     [CmdletBinding()]  
  53.     Param(  
  54.         [ValidateNotNullOrEmpty()]  
  55.         [ValidateScript({(Test-Path $_) -and ((Get-Item $_).Extension -eq ".ini")})]  
  56.         [Parameter(ValueFromPipeline=$True,Mandatory=$True)]  
  57.         [string]$FilePath  
  58.     )  
  59.      
  60.     Begin  
  61.         {Write-Verbose "$($MyInvocation.MyCommand.Name):: Function started"}  
  62.          
  63.     Process  
  64.     {  
  65.         Write-Verbose "$($MyInvocation.MyCommand.Name):: Processing file: $Filepath"  
  66.              
  67.         $ini = @{}  
  68.         switch -regex -file $FilePath  
  69.         {  
  70.             "^\[(.+)\]$" # Section  
  71.             {  
  72.                 $section = $matches[1]  
  73.                 $ini[$section] = @{}  
  74.                 $CommentCount = 0  
  75.             }  
  76.             "^(;.*)$" # Comment  
  77.             {  
  78.                 if (!($section))  
  79.                 {  
  80.                     $section = "No-Section"  
  81.                     $ini[$section] = @{}  
  82.                 }  
  83.                 $value = $matches[1]  
  84.                 $CommentCount = $CommentCount + 1  
  85.                 $name = "Comment" + $CommentCount  
  86.                 $ini[$section][$name] = $value  
  87.             }  
  88.             "(.+?)\s*=\s*(.*)" # Key  
  89.             {  
  90.                 if (!($section))  
  91.                 {  
  92.                     $section = "No-Section"  
  93.                     $ini[$section] = @{}  
  94.                 }  
  95.                 $name,$value = $matches[1..2]  
  96.                 $ini[$section][$name] = $value  
  97.             }  
  98.         }  
  99.         Write-Verbose "$($MyInvocation.MyCommand.Name):: Finished Processing file: $FilePath"  
  100.         Return $ini  
  101.     }  
  102.          
  103.     End  
  104.         {Write-Verbose "$($MyInvocation.MyCommand.Name):: Function ended"}  
  105. }
  106.  
  107. $ScriptDir = (Split-Path $MyInvocation.MyCommand.Path)
  108. $FileContent = Get-IniContent "$ScriptDir\ripper.ini"
  109.  
  110.  
  111. ##########Get base xml to test against
  112. foreach($key in $FileContent.keys)
  113. {
  114.        
  115.     If ($FileContent[$key]["ID"].StartsWith("PL")) { #determine if User or Playlist
  116.         $url = $FileContent[$key]["ID"]
  117.         Invoke-WebRequest -Uri "https://www.youtube.com/feeds/videos.xml?playlist_id=$url" -OutFile "$key.txt"
  118.     }else{
  119.         $url = $FileContent[$key]["ID"]
  120.         Invoke-WebRequest -Uri "https://www.youtube.com/feeds/videos.xml?channel_id=$url" -OutFile "$key.txt"
  121.     }
  122.  
  123. }
  124. ##########Get base xml to test against
  125.  
  126.  
  127. ##########Updatecheck
  128. $a = 1
  129. #debug check $b = 1
  130. DO
  131. {
  132. foreach($key in $FileContent.keys)
  133. {
  134.     If ($FileContent[$key]["ID"].StartsWith("PL")) { #determine if User or Playlist
  135.   $url = $FileContent[$key]["ID"]
  136.         Invoke-WebRequest -Uri "https://www.youtube.com/feeds/videos.xml?playlist_id=$url" -OutFile "$key.check.txt"
  137.     }else{
  138.         $url = $FileContent[$key]["ID"]
  139.         Invoke-WebRequest -Uri "https://www.youtube.com/feeds/videos.xml?channel_id=$url" -OutFile "$key.check.txt"
  140.     }
  141.  
  142.     $updatecheck = Compare-Object -ReferenceObject $(Get-Item -Path "$ScriptDir\$key.txt") -DifferenceObject $(Get-Item -Path "$ScriptDir\$key.check.txt") -Property Length
  143.  
  144.     if ($updatecheck) {
  145. #debug check        Copy-Item -Path "$ScriptDir\$key.txt" -Destination "$ScriptDir\$b.old"
  146. #debug check        Copy-Item -Path "$ScriptDir\$key.check.txt" -Destination "$ScriptDir\$b.new"
  147.         Move-Item -Path "$ScriptDir\$key.txt" -Destination "c:\Users\tom42\Dropbox\IFTTT\$key.txt"
  148.         Move-Item -Path "$ScriptDir\$key.check.txt" -Destination "$ScriptDir\$key.txt"
  149.         'Update'
  150.     } else {
  151.         Remove-Item "$ScriptDir\$key.check.txt"
  152.         'No update'
  153.     }
  154. #debug check $b++
  155.     Start-Sleep -s 5
  156.  
  157. }
  158.  
  159. } While ($a -le 2)
  160.  
  161. ##########Updatecheck
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement