Skip to content

Instantly share code, notes, and snippets.

@shanselman
Created September 26, 2019 20:48
Show Gist options
  • Star 17 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save shanselman/9a5f73071e41b46dfcf9585ed5e14085 to your computer and use it in GitHub Desktop.
Save shanselman/9a5f73071e41b46dfcf9585ed5e14085 to your computer and use it in GitHub Desktop.
#CHECK THE PATH ON LINE 2 and the FEED on LINE 3
cd "C:\users\scott\Downloads"
$a = ([xml](new-object net.webclient).downloadstring("https://channel9.msdn.com/Series/CSharp-101/feed/mp4"))
$a.rss.channel.item | foreach{
$url = New-Object System.Uri($_.enclosure.url)
$file = $url.Segments[-1]
$file
if (!(test-path $file)) {
(New-Object System.Net.WebClient).DownloadFile($url, $file)
}
}
@KUTlime
Copy link

KUTlime commented Oct 26, 2019

General, more robust, more PS way. Suitable for building a collection of favourite shows/series, e.g. for home entertainment system.

function Update-dotNETVideo
{
    [CmdletBinding()]
    param (
        # A path to subtitle file of folder where the subtitles are located.
        [Parameter(Mandatory = $true,
            ValueFromPipeline = $true,
            ValueFromPipelineByPropertyName = $true,
            ValueFromRemainingArguments = $false,
            Position = 0,
            ParameterSetName = 'Basic')]
        [ValidateNotNullOrEmpty()]
        [ValidateScript( {
                if ( -Not ($_ | Test-Path) )
                {
                    throw "The path does not exist."
                }
                return $true
            })]
        [System.IO.FileInfo]
        $Path,

        # A show-to-download name.
        [Parameter(Mandatory = $true,
            ValueFromPipeline = $true,
            ValueFromPipelineByPropertyName = $true,
            ValueFromRemainingArguments = $false,
            Position = 1)]
        [ValidateNotNullOrEmpty()]
        [String]
        $Name,

        # A switch for high quality video download
        [Parameter(Mandatory = $false)]
        [Switch]
        $HighQuality

    )
    Process
    {
        if(!(Test-Path -Path "$Path\$Name"))
        {
            New-Item -Path $Path -Name $Name -ItemType Directory -Force | Write-Verbose
        }
        Set-Location -Path "$Path\$Name"

        if ($HighQuality)
        {
            $suffix = "high"
        }
        $urlToRss = "https://channel9.msdn.com/Series/$Name/feed/mp4$suffix"
        try
        {
            ([System.Net.WebRequest]::Create($urlToRss)).GetResponse() | Write-Verbose # Test if it is show or series.
        }
        catch
        {
            $urlToRss = "https://channel9.msdn.com/Shows/$Name/feed/mp4$suffix"
        }
        Write-Verbose -Message "RSS URL: $urlToRss"
        $a = ([xml](new-object net.webclient).downloadstring($urlToRss))
        $a.rss.channel.item |
            ForEach-Object {
                $url = New-Object System.Uri($_.enclosure.url)
                $file = $url.Segments[-1]
                $file
                $file = "$Path\$Name\$file"
                if (!(test-path $file))
                {   
                    (New-Object -TypeName ([System.Net.WebClient])).DownloadFile($url, $file)
                }
            }
    }
}


@('XamarinShow','CSharp-101','ASPNET-Core-101','Xamarin-101','Entity-Framework-Core-101','NET-Core-101','Desktop-and-NET-Core-101','Docker-and-NET-Core-101') |
Update-dotNETVideo -Path "$env:USERPROFILE\Downloads" -HighQuality -Verbose

@peterneave
Copy link

Script no longer works as original link been shutdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment