Skip to content

Instantly share code, notes, and snippets.

@arebee
Last active May 20, 2024 02:38
  • Select an option

Select an option

Revisions

  1. arebee revised this gist Jun 6, 2016. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions createPodcastRss.ps1
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    # Based on the format described at http://podcast411.com/howto_1.html

    function createRssElement{
    param(
    [string]$elementName,
  2. arebee revised this gist Jun 6, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion createPodcastRss.ps1
    Original file line number Diff line number Diff line change
    @@ -40,7 +40,7 @@ foreach ($item in $mp3s)
    # The URL is by default the file path.
    # You may want something like:
    # $null = $enclosure.SetAttribute('url',"http://example.com/pathToMp3s/$($item.Name)")
    $null = $enclosure.SetAttribute('url',"$($item.FullName)")
    $null = $enclosure.SetAttribute('url',"file://$($item.FullName)")
    $null = $enclosure.SetAttribute('length',"$($item.Length)")
    $null = $enclosure.SetAttribute('type','audio/mpeg')
    }
  3. arebee revised this gist Jun 6, 2016. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions createPodcastRss.ps1
    Original file line number Diff line number Diff line change
    @@ -37,6 +37,9 @@ foreach ($item in $mp3s)
    $enclosure = createRssElement -elementName 'enclosure' -value '' -parent $thisItem
    $null = createRssElement -elementName 'category' -value "Podcasts" -parent $thisItem
    $null = createRssElement -elementName 'pubDate' -value $item.LastWriteTimeUtc.ToString('u') -parent $thisItem
    # The URL is by default the file path.
    # You may want something like:
    # $null = $enclosure.SetAttribute('url',"http://example.com/pathToMp3s/$($item.Name)")
    $null = $enclosure.SetAttribute('url',"$($item.FullName)")
    $null = $enclosure.SetAttribute('length',"$($item.Length)")
    $null = $enclosure.SetAttribute('type','audio/mpeg')
  4. arebee created this gist Jun 6, 2016.
    57 changes: 57 additions & 0 deletions createPodcastRss.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,57 @@
    function createRssElement{
    param(
    [string]$elementName,
    [string]$value,
    $parent
    )

    $thisNode = $rss.CreateElement($elementName)
    $thisNode.InnerText = $value
    $null = $parent.AppendChild($thisNode)
    return $thisNode
    }

    $mp3s = gci $pwd -filter *.mp3 # -recurse
    [xml]$rss = ''
    $root = $rss.CreateElement('rss')
    $null = $root.SetAttribute('version','2.0')
    $null = $rss.AppendChild($root)
    $rssChannel = $rss.CreateElement('channel')
    $null = $root.AppendChild($rssChannel)
    # Channel metadata
    $null = createRssElement -elementName 'title' -value 'Your title' -parent $rssChannel
    $null = createRssElement -elementName 'description' -value 'Your description' -parent $rssChannel
    $null = createRssElement -elementName 'link' -value 'http://example.com' -parent $rssChannel
    $null = createRssElement -elementName 'language' -value 'en-US' -parent $rssChannel
    $null = createRssElement -elementName 'copyright' -value 'entity' -parent $rssChannel
    $null = createRssElement -elementName 'lastBuildDate' -value $([datetime]::Now.ToString('s')) -parent $rssChannel
    $null = createRssElement -elementName 'pubDate' -value $([datetime]::Now.ToString('s')) -parent $rssChannel
    # Items in rss feed
    foreach ($item in $mp3s)
    {
    $thisItem = createRssElement -elementName 'item' -value '' -parent $rssChannel
    $null = createRssElement -elementName 'title' -value $item.Name -parent $thisItem
    $null = createRssElement -elementName 'link' -value 'http://example.com' -parent $thisItem
    $null = createRssElement -elementName 'description' -value 'Your description' -parent $thisItem
    $null = createRssElement -elementName 'guid' -value $item.FullName -parent $thisItem
    $enclosure = createRssElement -elementName 'enclosure' -value '' -parent $thisItem
    $null = createRssElement -elementName 'category' -value "Podcasts" -parent $thisItem
    $null = createRssElement -elementName 'pubDate' -value $item.LastWriteTimeUtc.ToString('u') -parent $thisItem
    $null = $enclosure.SetAttribute('url',"$($item.FullName)")
    $null = $enclosure.SetAttribute('length',"$($item.Length)")
    $null = $enclosure.SetAttribute('type','audio/mpeg')
    }

    $_filename = join-path $pwd "test.rss"

    $xmlWriterSettings = new-object System.Xml.XmlWriterSettings
    $xmlWriterSettings.CloseOutput = $true
    # 4 space indent
    $xmlWriterSettings.IndentChars = ' '
    $xmlWriterSettings.Indent = $true
    # $xmlWriterSettings.ConformanceLevel = 2
    write-verbose $('xml formatting - writing to ' + $_filename)
    $xmlWriter = [System.Xml.XmlWriter]::Create($_filename, $xmlWriterSettings)
    $rss.Save($xmlWriter)
    $xmlWriter.Close()
    Write-Verbose ("Tabbify finish " + ("*" * 60))