Podcatcher mit Powershell v2 & BITS

by ChristianH April 19, 2009 02:25

Vor kurzem habe ich einen Podcatcher mit Powershell und BITS (“Background Intelligent Transfer Service”) geschrieben, für den man aber zusätzlich noch bitsadmin.exe und bget.cmd benötigt.
Da bitsadmin.exe eher mühsam und bget.cmd zwar nett aber etwas buggy ist, bin ich gleich auf die schon damals angeführte Möglichkeit umgestiegen, Powershell v2 (CTP 3) zu verwenden – damit braucht man nämlich keine zusätzlichen Tools mehr.

Das ganze funktioniert bisher recht robust – ich möchte nur noch eine (visuelle) Statusanzeige dazu programmieren.

param ([switch] $schedule)
#Set-PSDebug -Trace 1
Import-Module FileTransfer -Verbose

$today = get-date
$yesterday = $today.AddDays(-1)
$today = Get-Date -date $today -uformat "%Y%m%d"
$yesterday = Get-Date -date $yesterday -uformat "%Y%m%d"
$today = $today.tostring()
$yesterday = $yesterday.tostring()

if ($schedule) {
$taskname = $myinvocation.mycommand.definition -replace '\W','_'
schtasks /create /ru PIVO9\Christian /rl HÖCHSTE /sc MINUTE /MO 5 /tn "$taskname" /tr "%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell -c $($myinvocation.mycommand.definition)"
return;
}

pushd (split-path -parent $myinvocation.mycommand.definition)

$feed=[xml](New-Object System.Net.WebClient).DownloadString("http://***.*****.net/mythfeed/feed.php")
foreach($i in $feed.rss.channel.item) {
    $url = New-Object System.Uri($i.enclosure.url)
    $absURL = $url.AbsoluteUri   
    $filename = "C:\Users\Public\Videos\ElskeTV\" + $url.Segments[-1]
    If ((Test-Path $filename) -eq $FALSE) 
    {
echo ----------------------------------------------------------------------------------------------------
echo $url.Segments[-1]

$joblist = Get-FileTransfer
$jobexist = $false

foreach ($i in $joblist) {

foreach ($j in $i.filelist) {
if ($j.IsTransferComplete) { Complete-FileTransfer $i }
if ($j.RemoteName -eq $absURL) {
echo "Job wurde gefunden..."
if ($j.BytesTotal -gt 0) { "{0:P1}" -f  ($j.BytesTransferred / $j.BytesTotal) }
$i.JobState
$i.CreationTime
$jobexist = $true
if ($j.RemoteName -match $today) {$i | Set-FileTransfer -Priority "FOREGROUND" }
if ($j.RemoteName -match $yesterday) {$i | Set-FileTransfer -Priority "FOREGROUND" }
}
}}

if ($jobexist -eq $false) {
New-FileTransfer -ServerFileName $absURL -ClientFileNamePrefix C:\users\Public\videos\ElskeTV\ -Displayname $url.Segments[-1] -Asynchronous
Echo "Neuer Download-Job wurde hinzugefügt!"
}

    }
}

echo ----------------------------------------------------------------------------------------------------

popd

#Fortschritt in Prozent der einzelnen Downloads
#$joblist = Get-FileTransfer ; foreach ($i in $joblist) { foreach ($j in $i.filelist) { if ($j.BytesTotal -gt 0) { "{0:P1}" -f  ($j.BytesTransferred / $j.BytesTotal) }}}

#Summe aller übertragenen Bytes aller Downloadjobs
#$joblist = Get-FileTransfer ; $total = 0 ; foreach ($i in $joblist) { foreach ($j in $i.filelist) { if ($j.BytesTotal -gt 0) {$total = $total + $j.BytesTransferred}}} ; $total ; get-date

#Downloadjobs auflisten, die in den letzten 10 Minuten erstellt wurden
#get-FileTransfer | Where {$(Get-Date).AddMinutes(-10) -lt $_.CreationTime}

#Dateien auflisten mit einem bestimmten Datum im Dateinamen
#$joblist = Get-FileTransfer ; foreach ($i in $joblist) { foreach ($j in $i.filelist) { if ($j.RemoteName -match "20090418") {$i | fl * } }}

#Priority hochsetzen für Downloads mit einem bestimmten Datum im Dateinamen
#$joblist = Get-FileTransfer ; foreach ($i in $joblist) { foreach ($j in $i.filelist) { if ($j.RemoteName -match "20090418") {$i | Set-FileTransfer -Priority "FOREGROUND" } }}

 

 

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Tags: , ,

Scripting

Kommentare

26.07.2011 21:07:22 #

BBW Fucked

Hey very nice weblog man, beautiful, everything is great layout articles, i'll bookmark and subscribe for the feeds!Hello there i spotted your own website using google while searching for good read, and your blogposts seem extremely exciting to me!

BBW Fucked United States

22.11.2011 06:57:40 #

Dunia Digital

Hi there thank for give us valuable information in your blog i hope you can provide more information like this in future. Thanks friends.

Dunia Digital Yemen

16.12.2011 18:45:49 #

500 rubles

I dugg some of you post as I thought   they were  really beneficial   invaluable

500 rubles United States

25.12.2011 11:55:08 #

tahitian hip band

I want  foregathering useful   info, this post has got me even more info! .

tahitian hip band United States

19.01.2012 23:57:00 #

reading pillow

With all of the current web-sites We have frequented on-line, this may be a merely submit That i've ever identify the exceptional composing. Your lucidity of this article clarifies nicely the conversation. I are going to be delighted how the writer shared this certain subject for your visitors. I loved how the blogger ideas its creating high quality. It may be known as as an effective profession.

reading pillow United States

28.01.2012 06:56:25 #

Deanat

It could just as easily be the other way around: the privatization fans are morons (okay, I don't think that, but at least you could make that case). Private companies have two rather large disadvantages over public agencies: (1) they have to pay federal and state income taxes and, more importantly, (2) they have far higher financing expenses, that are not tax-free but are much riskier because there is no government behind them to bail them out. Of course, this is why public authorities exist in the first place; it was hoped they'd meld the advantages of both systems. And sorry, but a private company with a transit franchise may have an incentive to help the bottom line, but they don't have an incentive to innovate against competition because by definition they probably don't have competitors.|

Deanat United States

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

Facebook

Ü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.


Netzwerk Management

Bandwidth

RecentComments

Comment RSS