Skip to content

Instantly share code, notes, and snippets.

@shanselman
Created September 26, 2019 20:48
Show Gist options
  • Select an option

  • Save shanselman/9a5f73071e41b46dfcf9585ed5e14085 to your computer and use it in GitHub Desktop.

Select an option

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)
}
}
@ArkNieckarz
Copy link
Copy Markdown

# This will download high quality mp4 video files, ~1.14GB in total!!!
# Prepend sequence numbers to each file.
#CHECK THE PATH ON LINE 2 and the FEED on LINE 3
cd "c:\TEMP"
$a = ([xml](new-object net.webclient).downloadstring("https://channel9.msdn.com/Series/CSharp-101/feed/mp4"))
$cnt = 20
$a.rss.channel.item | foreach{  
    $url = New-Object System.Uri($_.enclosure.url)
    $file = $url.Segments[-1]
    $cnt = $cnt - 1
    $file_name = "$cnt" + "_" + $file
    if (!(test-path $file)) {
    $f = $url.OriginalString
    $n = $f.Replace(".mp4", "_high.mp4")
        echo $n, $file_name
        (New-Object System.Net.WebClient).DownloadFile($n, $file_name)
    }
}

@liuning0820
Copy link
Copy Markdown

#CHECK THE PATH ON LINE 2 and the FEED on LINE 3
cd "$env:USERPROFILE\Downloads"

@MarioBinder
Copy link
Copy Markdown

Import-Module BitsTransfer

$path =  $env:USERPROFILE + "\Downloads\"
$feedContent = ([xml](new-object net.webclient).downloadstring("https://channel9.msdn.com/Series/CSharp-101/feed/mp4"))
$cnt = 20
$feedContent.rss.channel.item | foreach{  
    $url = New-Object System.Uri($_.enclosure.url)
    $file = $url.Segments[-1]
    $cnt = $cnt - 1
    $file_name = $path + "$cnt" + "_" + $file
    if (!(test-path $file)) {
        $f = $url.OriginalString
        $n = $f.Replace(".mp4", "_high.mp4")
            echo $n, $file_name
            Start-BitsTransfer -Source $n -Destination $file_name           
    }
}

@KUTlime
Copy link
Copy Markdown

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
Copy Markdown

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