Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Function Get-IniContent {
- <#
- .Synopsis
- Gets the content of an INI file
- .Description
- Gets the content of an INI file and returns it as a hashtable
- .Notes
- Author : Oliver Lipkau <oliver@lipkau.net>
- Blog : http://oliver.lipkau.net/blog/
- Source : https://github.com/lipkau/PsIni
- http://gallery.technet.microsoft.com/scriptcenter/ea40c1ef-c856-434b-b8fb-ebd7a76e8d91
- Version : 1.0 - 2010/03/12 - Initial release
- 1.1 - 2014/12/11 - Typo (Thx SLDR)
- Typo (Thx Dave Stiff)
- #Requires -Version 2.0
- .Inputs
- System.String
- .Outputs
- System.Collections.Hashtable
- .Parameter FilePath
- Specifies the path to the input file.
- .Example
- $FileContent = Get-IniContent "C:\myinifile.ini"
- -----------
- Description
- Saves the content of the c:\myinifile.ini in a hashtable called $FileContent
- .Example
- $inifilepath | $FileContent = Get-IniContent
- -----------
- Description
- Gets the content of the ini file passed through the pipe into a hashtable called $FileContent
- .Example
- C:\PS>$FileContent = Get-IniContent "c:\settings.ini"
- C:\PS>$FileContent["Section"]["Key"]
- -----------
- Description
- Returns the key "Key" of the section "Section" from the C:\settings.ini file
- .Link
- Out-IniFile
- #>
- [CmdletBinding()]
- Param(
- [ValidateNotNullOrEmpty()]
- [ValidateScript({(Test-Path $_) -and ((Get-Item $_).Extension -eq ".ini")})]
- [Parameter(ValueFromPipeline=$True,Mandatory=$True)]
- [string]$FilePath
- )
- Begin
- {Write-Verbose "$($MyInvocation.MyCommand.Name):: Function started"}
- Process
- {
- Write-Verbose "$($MyInvocation.MyCommand.Name):: Processing file: $Filepath"
- $ini = @{}
- switch -regex -file $FilePath
- {
- "^\[(.+)\]$" # Section
- {
- $section = $matches[1]
- $ini[$section] = @{}
- $CommentCount = 0
- }
- "^(;.*)$" # Comment
- {
- if (!($section))
- {
- $section = "No-Section"
- $ini[$section] = @{}
- }
- $value = $matches[1]
- $CommentCount = $CommentCount + 1
- $name = "Comment" + $CommentCount
- $ini[$section][$name] = $value
- }
- "(.+?)\s*=\s*(.*)" # Key
- {
- if (!($section))
- {
- $section = "No-Section"
- $ini[$section] = @{}
- }
- $name,$value = $matches[1..2]
- $ini[$section][$name] = $value
- }
- }
- Write-Verbose "$($MyInvocation.MyCommand.Name):: Finished Processing file: $FilePath"
- Return $ini
- }
- End
- {Write-Verbose "$($MyInvocation.MyCommand.Name):: Function ended"}
- }
- $ScriptDir = (Split-Path $MyInvocation.MyCommand.Path)
- $FileContent = Get-IniContent "$ScriptDir\ripper.ini"
- ##########Get base xml to test against
- foreach($key in $FileContent.keys)
- {
- If ($FileContent[$key]["ID"].StartsWith("PL")) { #determine if User or Playlist
- $url = $FileContent[$key]["ID"]
- Invoke-WebRequest -Uri "https://www.youtube.com/feeds/videos.xml?playlist_id=$url" -OutFile "$key.txt"
- }else{
- $url = $FileContent[$key]["ID"]
- Invoke-WebRequest -Uri "https://www.youtube.com/feeds/videos.xml?channel_id=$url" -OutFile "$key.txt"
- }
- }
- ##########Get base xml to test against
- ##########Updatecheck
- $a = 1
- #debug check $b = 1
- DO
- {
- foreach($key in $FileContent.keys)
- {
- If ($FileContent[$key]["ID"].StartsWith("PL")) { #determine if User or Playlist
- $url = $FileContent[$key]["ID"]
- Invoke-WebRequest -Uri "https://www.youtube.com/feeds/videos.xml?playlist_id=$url" -OutFile "$key.check.txt"
- }else{
- $url = $FileContent[$key]["ID"]
- Invoke-WebRequest -Uri "https://www.youtube.com/feeds/videos.xml?channel_id=$url" -OutFile "$key.check.txt"
- }
- $updatecheck = Compare-Object -ReferenceObject $(Get-Item -Path "$ScriptDir\$key.txt") -DifferenceObject $(Get-Item -Path "$ScriptDir\$key.check.txt") -Property Length
- if ($updatecheck) {
- #debug check Copy-Item -Path "$ScriptDir\$key.txt" -Destination "$ScriptDir\$b.old"
- #debug check Copy-Item -Path "$ScriptDir\$key.check.txt" -Destination "$ScriptDir\$b.new"
- Move-Item -Path "$ScriptDir\$key.txt" -Destination "c:\Users\tom42\Dropbox\IFTTT\$key.txt"
- Move-Item -Path "$ScriptDir\$key.check.txt" -Destination "$ScriptDir\$key.txt"
- 'Update'
- } else {
- Remove-Item "$ScriptDir\$key.check.txt"
- 'No update'
- }
- #debug check $b++
- Start-Sleep -s 5
- }
- } While ($a -le 2)
- ##########Updatecheck
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement