These forums are archived

See this post for further info

get_iplayer forums

Forum archived. Posting disabled.

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

user-2325

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);
Code:
C:
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
pause

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

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?
Thanks

user-2

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.

user-1923

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:
Code:
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
Code:
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.)
Code:
get_iplayer -zMySeries
get_iplayer -zMySeries -t

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

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

Delete the Preset
Code:
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:
Code:
@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.

user-250

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

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

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

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

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

user-2325

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!

user-910

If it's of any use, this is the script I run nightly via the task scheduler:

Code:
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 ------------------------------------------------------------
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.
    echo No batch file import
    echo.
    ) >>%$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:

Code:
"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.

user-250

Darren
Nice batch file ;)

I have something similar in Linux. I text myself shows I want to listen to and a script grabs them from messages.android.com 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".

These forums are archived

See this post for further info