These forums are archived

See this post for further info

get_iplayer forums

Forum archived. Posting disabled.

Powershell Script to Download Series

user-822

After the recent fails created by the BB's changes, I started to look at what I could to get getiplayer working in the way I wanted again. I am quite pleased with how it is going, so thought id share here in case anyone else could find it useful..

Situation;
I wanted to download radio programs for a few programs regularly - most of these programmes are on going, so at present, I focus on about 5 each time. The PVR seems to have fallen apart for me (and I don't understand the makings of the app to be able to fix), but I have found that it still lets me download by PID - although the file is not named correctly - it just has the PID and some other characters. The metadata does come down though - that shows in the console window when it is processing.

I have come up with this script that does the following...
Runs a download for each series PID to pull down the files, saves the output from that to a text file
Reads the text file in to a variable as one string.
Goes through each file in my download directory that has a PID name and searches the metadata that saved in step one for a match.
When a match is found it renames the files and moves on to the next.

I have been quite surprised at how well this is working, so if you find yourself with similar requirements, you may be able to make use of it. Obviously the usual caution should be exercised when running this - please ensure you understand it before running it to avoid unexpected outcomes!

Apologies that this is not the best written script - if I get a chance I will tidy it up one day, just thought worth sharing

#set working dir to be location of get_iplayer.cmd
Set-Location 'C:\Program Files\get_iplayer'
#delete old metadata files (this empties all of temp)
Get-ChildItem c:\temp\ |Remove-Item

#run the getiplayer app against each series I want and dump output to a file
.\get_iplayer.cmd --pid b04830x1 --type radio --pid-recursive --modes=flashaacstd1,flashhigh,flashvhigh,rtsphigh,rtspvhigh | Out-File c:\temp\justso.log -append
.\get_iplayer.cmd --pid b006qy2s --type radio --pid-recursive --modes=flashaacstd1,flashhigh,flashvhigh,rtsphigh,rtspvhigh | Out-File c:\temp\15mindrama.log -append
.\get_iplayer.cmd --pid b006qtlx --type radio --pid-recursive --modes=flashaacstd1,flashhigh,flashvhigh,rtsphigh,rtspvhigh |Out-File c:\temp\batb.log -append

.\get_iplayer.cmd --pid b006qrzz --type radio --pid-recursive --modes=flashaacstd1,flashhigh,flashvhigh,rtsphigh,rtspvhigh |Out-File c:\temp\afternoon.log -append
.\get_iplayer.cmd --pid b01lyb82 --type radio --pid-recursive --modes=flashaacstd1,flashhigh,flashvhigh,rtsphigh,rtspvhigh |Out-File c:\temp\philoarms.log -append

#pull the output back from the file and in to a variable - minimise size by filtering on just the relevant lines

$15mindrama = (Get-Content C:\temp\15mindrama.log| ?{$_ -like '* episode *' -or $_ -like '* series:*'}| Out-String)
$afterNoon = (Get-Content C:\temp\afternoon.log| ?{$_ -like '* episode *' -or $_ -like '* series:*'}| Out-String)
$bedtime= (Get-Content C:\temp\batb.log| ?{$_ -like '* episode *' -or $_ -like '* series:*'}| Out-String)
$JustSo=(Get-Content C:\temp\JustSo.log| ?{$_ -like '* episode *' -or $_ -like '* series:*'}| Out-String)
$philoarms=(Get-Content C:\temp\philoarms.log| ?{$_ -like '* episode *' -or $_ -like '* series:*'}| Out-String)

#define the series to process that have been downloaded above
$progs = ("AfterNoon","15MinDrama","JustSo","PhiloArms","BedTime")

foreach($txt in $progs){
#go through each variable of series metadata
$metadata = Get-Variable -Name $txt -ValueOnly -ea Continue
if($metadata){
#if something is there....
get-childitem c:\iplayer -filter BBC_Ip* |foreach{
#iterate though each file in my holding area for downloads
$_.name -match "(?:BBC_iPlayer_Feeds_-_)(?<pid>[^_]+)" |Out-Null
#get any that have just the pid type of name
$pidf =$matches.pid
if($metadata -like "*$pidf*"){
"$pidf found in metadata: $txt"
#search for real name in metadata
$reg = "(?:.+Series:\s*?['<](?<ser>(?-s).*)['>])(?=.+Episode '(?<ep>.*)'\s\($pidf)"
$result = ([regex]::Match($metadata,$reg,@('SingleLine')))
$ser = $result.groups['ser'].value
$ep = $result.groups['ep'].value
#"$ser $ep"
if($result.groups['ser'].value){
#if found, rename the file
$newname = "$txt`_$(($ser).replace('?',''))_$(($ep).replace('?',''))$($_.Extension)" #changed added ext
$_ |Rename-Item -NewName $newname
$newname
}else{
write-error "$pidf found in metadata, but no series or episode identifid"
}
}else{
write-warning "$pidf not found in metadata: $txt"
}#end pid check
}#end file iteration
}#end metadata check (to see if it exists)
}#for loop.

user-2

Naturally, you should use whatever version of get_player you like, and use it however you wish. However, for the benefit of other users who may come across this post I feel obliged to point out that the problem addressed by the above script was fixed in get_iplayer 2 months ago. You only need to upgrade to the latest version of get_iplayer (currently 2.91).

user-822

Thank you user-2. I should have checked that more carefully...

I should have also added that 'gip' is a really nifty creation for which I am very greatfull...it opens up so much more as I can choose when I listen! A big thank you to all its creators and anyone who suppprts it!

These forums are archived

See this post for further info