Rob's Blog

This is stuff.

Renaming video files from get_iplayer for easy import into Sonarr

There may become a time where someone wants to obtain some media from the popular get_iplayer application to add to their Sonarr library.

Sonarr doesn’t like importing such files by default because the season and episode numbers aren’t in a common format.

I couldn’t find any easily automated method to rename the files into a supported format online, so I’ve pieced together a small script to help achieve this quickly and easily.

I’m not a programmer, but do have enough experience to know roughly what a piece of code is doing so please bear this in mind with my script, it may not be perfect or perform all necessary functions but it should help you enough to get Sonarr to correctly recognise them and it can then rename appropriately upon import if your installation is set to do so.

This is made mostly by code samples found online with some minor modifications, your mileage may vary. This script is designed to run on media files for a single TV show at a time, not one large folder with multiple shows downloaded into it (mostly due to my future hopes/plans for the script).

Open up a new plaintext editor such as Notepad on Windows, then paste the following:

VB
Set objFso = CreateObject("Scripting.FileSystemObject")
Set Folder = objFSO.GetFolder("X:\path-to-files")

For Each File In Folder.Files
    sNewFile = File.Name
    sNewFile = Replace(sNewFile,"_Series_"," - S0")
    if (sNewFile<>File.Name) then 
        File.Move(File.ParentFolder+"\"+sNewFile)
    end if

Next

For Each File In Folder.Files
    sNewFile = File.Name
    sNewFile = Replace(sNewFile,"_-_","E")
    if (sNewFile<>File.Name) then 
        File.Move(File.ParentFolder+"\"+sNewFile)
    end if

Next

For Each File In Folder.Files
    sNewFile = File.Name
    sNewFile = Replace(sNewFile,"._"," - ")
    if (sNewFile<>File.Name) then 
        File.Move(File.ParentFolder+"\"+sNewFile)
    end if

Next

For Each File In Folder.Files
    sNewFile = File.Name
    sNewFile = Replace(sNewFile,"_"," ")
    if (sNewFile<>File.Name) then 
        File.Move(File.ParentFolder+"\"+sNewFile)
    end if

Next

You should edit line two, to insert the path to your downloaded video files, you’ll need to do this for each new folder of media that you wish to rename, then save it as a vbscript file, for example “rename.vbs”.

Double-click it and accept any security warning to allow it to run and you should then see your media names with the common SxxExx naming format.

This script works by searching for and replacing certain values. It doesn’t account for all types of files downloaded through get_iplayer, for example it doesn’t recognise special episodes because their file name doesn’t include the word “Series”.

I may improve this over time, I would like to add the following:

  • Recognise special episodes and move them to a subfolder for manual renaming
  • Organise files into subfolders by season for easier copy/paste into your media library
  • Scan recursive media folders with multiple shows

For now though, I just wanted to get it working well enough for my needs which it does, and share it with anyone else who may find it useful.

  1. noyb says:

    RTFM FTW:

    get_iplayer –pid=m000pb85

    -> […]\Industry_Series_1_-_01._Induction_m000pb85_original.mp4

    get_iplayer –pid=m000pb85 –whitespace –fileprefix=””

    -> […]\Industry – s01e01 – Induction.mp4

    get_iplayer –pid=m000pb85 –whitespace –fileprefix=”” –subdir –subdir-format=”Season ”

    -> […]\Season 01\Industry – s01e01 – Induction.mp4

Leave a Reply

Your email address will not be published. Required fields are marked *

© 2025 Rob's Blog