Skip to content

Instantly share code, notes, and snippets.

@BroVic
Last active April 30, 2018 12:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BroVic/9e114d1db1046e2aa71c0348ebdf4801 to your computer and use it in GitHub Desktop.
Save BroVic/9e114d1db1046e2aa71c0348ebdf4801 to your computer and use it in GitHub Desktop.
Quick download for course videos (part 2)
# video-download.ps1
# Takes an array of video URLs and downloads them into the working directory
# and renames them
function Get-EdxVideos {
param([string[]]$UrlArray, [string[]]$NewNames)
for ($i = 0; $i -lt $UrlArray.Length; $i++) {
# Prepare new filenames
$nuName = $NewNames[$i]
$nuName = $nuName.Trim()
$nuName = $nuName.ToLower()
$nuName = $nuName.Replace(' ', '-')
$nuName = $nuName.Replace('introduction', 'intro')
$nuName = $nuName + '.mp4'
# thought of abbreviating 'javascript' to 'js' but function
# is actually meant to be generic across all courses
$vid = $UrlArray[$i]
Start-BitsTransfer $vid
$tmp = Split-Path $vid -Leaf
Rename-Item $tmp -NewName $nuName
}
}
New-Alias -Name edxvids -Value Get-EdxVideos
# wk2-downloads.ps1
."..\..\video-download.ps1" # has definition of 'Get-EdxVideos'
$wk2_vids = "https://edx-video.net/PENPWJSX2017-V000900_DTH.mp4",
"https://edx-video.net/PENPWJSX2017-V001900_DTH.mp4",
"https://edx-video.net/PENPWJSX2017-V000800_DTH.mp4",
"https://edx-video.net/PENPWJSX2017-V000700_DTH.mp4",
"https://edx-video.net/PENPWJSX2017-V003700_DTH.mp4",
"https://edx-video.net/PENPWJSX2017-V002000_DTH.mp4",
"https://edx-video.net/PENPWJSX2017-V004000_DTH.mp4",
"https://edx-video.net/PENPWJSX2017-V003800_DTH.mp4",
"https://edx-video.net/PENPWJSX2017-V002100_DTH.mp4",
"https://edx-video.net/PENPWJSX2017-V002200_DTH.mp4",
"https://edx-video.net/PENPWJSX2017-V002500_DTH.mp4"
$vidNames = "Introduction to JavaScript",
"JavaScript variables",
"JavaScript arrays and objects",
"JavaScript control structures",
"JavaScript functions",
"JavaScript regular expressions",
"Introduction to the DOM",
"DOM events",
"Introduction to jQuery",
"jQuery event handling",
"jQuery event handling"
Get-EdxVideos -UrlArray $wk2_vids -NewNames $vidNames
if ($(Get-ChildItem).Name.Contains('videos') -ne 'True') {
New-Item -Name videos -ItemType d
}
Move-Item *.mp4 -Destination .\videos
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment