How do I run multiple get_iplayer commands from a single .bat file?
Hi guys

I'd like to create a batch script that I can just run and it'll pick up any new episodes of the shows I want, but I'm struggling to get it to work. Any ideas how?

I tried putting this into a bat file (created in Notepad++ in the correct format);
cd "\Program Files (x86)\get_iplayer\"
get_iplayer --refresh
get_iplayer -g --pid-recursive --pid b01qv24w
get_iplayer -g --pid-recursive --pid b01bsr61
get_iplayer -g --pid-recursive --pid b006xxw3

I've also tried it like this;
cd "\Program Files (x86)\get_iplayer\"
get_iplayer --refresh
get_iplayer --pid-recursive --pid b01qv24w --pid b01bsr61 --pid b02mms7s

But that doesn't do it. It runs, does the indexing, but then just closes the cmd. What do I need to do to get it working?
If you're trying to learn batch script programming, that's fair enough, but I suggest you let get_iplayer do the work. Use the PVR functionality - that's what it is for. If you don't want to do that, here is a hint relevant to your script: As you're told in the documentation, when you launch get_iplayer, you're actually launching another batch script (get_iplayer.cmd). Do some googling on the different ways to do that and their implications. As it is, you have no way to return to the main script after the first get_iplayer command finishes.

Also, it is unnecessary to make the installation directory your working directory. If your value of %PATH% is screwed up such get_iplayer is not available from any working directory, you need to reinstall or fix %PATH%. In any event, you generally don't want to let a script you invoke interactively persist a change of working directory after it exits. Google for info on how to make such environment changes local to the script itself.
Hi Finchy505,
For how you've outlined your problem, Dinky's suggestion of using get_iplayer's pvr options is probably the way you want to go. However, for other downloads a batch script may be appropriate. So, here's some ideas:
  • From the get_iplayer Prompt
    I notice you've included the --get option in your examples which isn't needed when using --pid. Additionally, running your commands will pick up all available episodes including ones you've already downloaded—you probably want to include the --hide option to avoid all the already in history warnings. You also have three separate commands; it can all be done in one:
get_iplayer --hide --pid-recursive --pid b01qv24w,b01bsr61,b006xxw3
  • Using a get_iplayer Preset
    You could use --preset (-z) to add the options you want and then run that preset:
Create the Preset
get_iplayer -zMySeries --prefs-add --hide --pid-recursive --pid b01qv24w,b01bsr61,b006xxw3

Run the Preset
(You can include additional options if you want; for example --test.)
get_iplayer -zMySeries
get_iplayer -zMySeries -t

View the Preset's Options
get_iplayer -zMySeries --prefs-show

Update the Preset
get_iplayer -zMySeries --prefs-add <replacement and/or new options>
get_iplayer -zMySeries --prefs-del <option(s) to be removed>

Delete the Preset
get_iplayer -zMySeries --prefs-clear
  • Using a Batch Script
    I can't give a tutorial on batch scripts here, but the trick to downloading when using get_iplayer in a script is to prefix the get_iplayer command with cmd /c. It's also probably best to use .cmd as the file extension instead of .bat. Here's a quick example:
@echo off
echo Downloading new episodes for my series
cmd /c get_iplayer --hide --pid-recursive ^
   --subdir-format "Kids\<nameshort>\Series< 00seriesnum>" ^
   --pid b01qv24w,b01bsr61
cmd /c get_iplayer --hide --pid-recursive --pid b006xxw3
echo Finished downloading
exit /b 0
Note, the caret (^) in batch scripts escapes the next character (newlines in this example) so although the first download command is split across three lines in the script, it is treated as a single line and a single get_iplayer command.

I hope this helps.
I don't use windows much, but this is what I use.
::get_iplayer.cmd --type=radio --pid-recursive   --pid=n,n,n  --force

get_iplayer.cmd --type=radio --pid-recursive --pid=pid1,pid2,pid3

get_iplayer.cmd --type=tv --pid-recursive    --pid=pid1,pid2,pid3

get_iplayer.cmd --type=tv    --pid=pid1,pid2,pid3

get_iplayer.cmd --type=radio --pid=pid1,pid2,pid3
Thanks for the replies guys. I'll have a look through the options and see what works best for me. I'm not trying to learn batch script programming, I'm just looking for the quickest and easiest way to have a way of picking up all new episodes with a couple of clicks. I've not used the pvr part of get_iplayer before as it seemed it needs some time to get an understanding of it. I have a small operation today so will have a few days in bed, so will hopefully have time to read up to try to get my head around it!
If it's of any use, this is the script I run nightly via the task scheduler:

cd C:\Program Files (x86)\get_iplayer
set $batchFile="D:\iPlayer Recordings\Batch.txt"
set $logFile="D:\iPlayer Recordings\PVR-log.txt"
call get_iplayer --type=tv,radio --refresh

echo ------------------------------------------------------------
echo ---------      %time%    %date%       ---------
echo ------------------------------------------------------------
echo.) >>%$logFile%

if exist %$batchFile% (
    echo Batch file import started
    ( echo.
    echo Batch file import started
    echo. ) >>%$logFile%
    for /f "delims=" %%a in ('type %$batchFile%') do (
        echo Batch checking %%a >>%$logFile%
        call get_iplayer --get --quiet --whitespace %%a >>%$logFile%

    echo. >>%$logFile%
    ) else (
    echo No batch file import
    ) >>%$logFile%
call get_iplayer --pvr --quiet --whitespace 2>>%$logFile%

move "D:\iPlayer Recordings\*.mp4" "D:\iPlayer Recordings\Downloaded\"
move "D:\iPlayer Recordings\*.m4a" "D:\iPlayer Recordings\Downloaded\"

It reads a text file (Batch.txt) containing the programme names that it should look for and download. An example of the content there would be:

"Les Miserables"
"New Wild"
"Slipstream" --type=radio

My set-up is both this and the built-in PVR. I have the PVR set for "long term" stuff that I always want to download, and I use the batch file for individual series of stuff like that so I don't have to mess around with the PVR too much, plus I can remotely access and edit the batch.txt file easily when I'm travelling and want to set something to be grabbed.

Everything is logged to the log file, and then once downloaded it's moved to the downloaded folder out of the way.
Nice batch file ;)

I have something similar in Linux. I text myself shows I want to listen to and a script grabs them from and passes them to get_iplayer and drops them on the cloud so I can listen to them anywhere. I find the BBC app very hit and miss, often shows don't appear for "copyright reasons".

Possibly Related Threads…
Thread Author Replies Views Last Post
  Ashamed to admit - how do I put commands in ? dieselweasel 2 2,531 01-11-2017, 10:03 PM
Last Post: dieselweasel
  WebPVR: How to exclude common single word programme names? MrArtist 3 3,602 22-01-2017, 01:23 AM
Last Post: dinky
  BBC PID download single or multiple Robbie 3 3,663 02-11-2014, 10:22 AM
Last Post: Robbie