PowerShell v2 Youtube Video Downloader

by christianh August 09, 2009 21:08

PowerShell v2 Youtube Video DownloaderThis script requires PowerShell v2 in it’s final version (as included in Windows 7 RTM).

This script will download any Youtube video in it’s best available quality as an MP4 file.

Syntax: GetYouTube Video-ID

Example: GetYouTube irp8CNj9qBI

Of course, one can also send a list of video ids to the script via a prepared text file, like so:

foreach ($video in get-content list.txt) { getyoutube.ps1 $video  } 

Here is the script GetYouTube.ps1:

Import-Module bitstransfer
$ErrorActionPreference = "SilentlyContinue"
$v=$args[0]
#$v="irp8CNj9qBI"
#Grab Youtube Page
$s=(New-Object System.Net.WebClient).DownloadString("http://www.youtube.com/watch?v=" + $v)
#extract token
$t=$s | % {$_.substring($_.IndexOf("`"t`": `"")+6,44)}
#extract title
$r="<title\b[^>]*>YouTube - (.*?)</title>" ; $f = $s | ?{ $_ -match $r } |  %{ $_ -match $r | out-null ; $matches[1] }
#Try downloading 720p version of video
$u = "http://www.youtube.com/get_video?fmt=22&video_id=" + $v + "&t=" + $t
$o = $Env:Userprofile + "\Videos\" + $f + "(HQ).mp4"
Start-BitsTransfer –source $u -destination $o
#Try downloading regular mp4 version of video, if HQ version failed
if (!$?) {
$u = "http://www.youtube.com/get_video?fmt=18&video_id=" + $v + "&t=" + $t
$o = $Env:Userprofile + "\Videos\" + $f + ".mp4"
Start-BitsTransfer –source $u -destination $o
}

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Tags: ,

Scripting

Kommentar schreiben


(Zeigt dein Gravatar icon)

  Country flag

biuquote
  • Kommentar
  • Live Vorschau
Loading



Powered by BlogEngine.NET 1.5.0.7
Theme by Mads Kristensen | Modified by Mooglegiant

Über den Autor

MCTS

Christian Haberl Christian Haberl ist seit mehr als 10 Jahren als EDV Berater, Vortragender und Trainer tätig. Er kann sich nicht für ein Spezialgebiet entscheiden, drum heißt dieser Blog auch "Kraut & Rüben Blog" - Unter seine Interessen fallen Web-Entwicklung auf ASP.NET Basis, Information Worker & Productivity Technologien (Windows, Office), Server (Windows Server, Small Business, Virtualisierung, Exchange), Scripting, Spam Filtering/Security und Digital Home. Christian Haberl ist auch einer der führenden Produktspezialisten für Windows Media Center und Windows Home Server und ist Direktor des ClubDigitalHome.
Im Jahr 2008 hat Christian Haberl über 200 Vorträge und Schulungen durchgeführt.
Im Frühjahr 2009 wurde Christian Haberl von Microsoft Österreich zum "Influencer" ernannt, weiters wurde er Microsoft Certified Technology Specialist / Microsoft Certified Connected Home Integrator sowie Microsoft Certified Consumer Sales Specialist.

Countdown bis zur allgemeinen Verfügbarkeit von Windows 7


Netzwerk Management

Bandwidth

RecentComments

Comment RSS