Bulk download from Moodle (How to)


If you created your h5p content on a Moodle site, it is possible to ‘bulk download your h5p files in an automated script.
If you visit your course, the “reuse” button and the “download as an .h5p file” are the tools you use to manually download your .h5p.
What actually is happening, is that 2 php files are called with the appropriate variables. 
I will explain how you can use excell to make a list of url's to download your h5p files and how to loop trough them with an Autiomator script. 
I tried to attach the excell and automator script but that is not allowed. If you want them, let me know.

The first url (you can see while visiting the page) is: 

https:// URL OF YOUR MOODLE/mod/hvp/view.php?id=xxx 
The second url is: 

https:// URL OF YOUR MOODLE/pluginfile.php/yyy/mod_hvp/exports/zzz.h5p

Here it is getting a bit difficult.
You need to have access to your Database. 
The zzz (name of the resulting file) is the slug as found in the HVP table.
The xxx and yyy are InstanceID and ID as found in the CONTEXT table.
Unfortunately, there is no reference in those tables connecting them.
Therefore, we need a third table (COURSE MODULES), where course (as in HVP table) and ID (as in CONTEXT table) are connected.

So download csv for excel HVP, COURSE_MODULES and CONTEXT. (I use phpmyadmin)
I made an excel to make it a bit easier. unfortantelly, I can't attach him but I took a screenshot to illustrate (attached)
Prepare an excelfile:
in cell H1 => URL of your Moodle site 

in cell H3 => ="https://"&H1&"/mod/hvp/view.php?id="
in cell H4 => =H$3&E4

in cell I3 => ="https://"&H1&"/mod/hvp/view.php?id="
in cell j3 => /mod_hvp/exports/
in cell K3 => .h5p
in cell I4 => =I$3&G4&J$3&A4&"-"&B4&K$3

Put slug, ID and Course of the HVP table in column A/B/C. (starting on line 4)
Put course and ID of the COURSE_MODULES in column D/E
Delete all cells of columns D and E where C and D are not the same
Put InstanceID and ID of CONTEXT in column F/G

Delete all cells of columns F and G where E and F are not the same
Now drag cell H4 and I4 to the end of the cells or double click the little black square in the corner.
All the URL’s you need to download all your content are now produced.
But they are next to each other and we need them in a list.
I used a macro to insert blank lines I found online (Thank you Theo Schipper).

Sub InvoegenLegeRijenMetInterval()
Dim Rng As Range
Dim xInterval As Integer
Dim xRows As Integer
Dim xRowsCount As Integer
Dim xNum1 As Integer
Dim xNum2 As Integer
Dim WorkRng As Range
Dim xWs As Worksheet
xTitleId = "Theo Schipper - www.theoschipper.nl"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
xRowsCount = WorkRng.Rows.Count
xInterval = Application.InputBox("Interval rijen ", xTitleId, 1, Type:=1)
xRows = Application.InputBox("Hoeveel rijen invoegen na de interval? ", xTitleId, 1, Type:=1)
xNum1 = WorkRng.Row + xInterval
xNum2 = xRows + xInterval
Set xWs = WorkRng.Parent
For i = 1 To Int(xRowsCount / xInterval)
xWs.Range(xWs.Cells(xNum1, WorkRng.Column), xWs.Cells(xNum1 + xRows - 1, WorkRng.Column)).Select
xNum1 = xNum1 + xNum2
End Sub

Copy H4 and I4 and all the cells under them to the second tab.
Run the macro “InvoegenLegeRijenMetInterval” (=> insert empty row whit interval). Adjust the range to all cells, keep interval on 1.
In cell C1, type =A1 and in cell C2, type  =B1. Select C1 and C2 and draw to the end or double click the little black square.
Almost there, Now select and copy column C into column D and paste special ‘Values’.
We now have a list with url’s, if you open them in this sequence, the h5p will be downloaded. Copy this list to a text document named list.txt.

Run the Automator file. The Automator file will loop trough the list and open all the url’s in a new tab. Every second url will download an h5p file. It is a good idea to stay around and close tabs. I ‘ve done 1600 downloads in 4 hours something. Every half an hour, I closed the tabs (2 times 1600 = 3200 tabs in total) to prevent the computer of running out of memory. You could probably close the tabs automatically in Automator but I had no time or energy to find out how to do it.

In Automator



RUN Applescript

on run {input, parameters}

read (item 1 of input)

set ps to paragraphs of the result

set tot to count ps

tell application "Safari"



end tell

repeat with i from 1 to tot

set p to item i of ps

if p is not "" then


tell application "Safari"

tell front window

set r to make new tab with properties {URL:p}

set current tab to r

delay 5

end tell

end tell

end try

end if

end repeat

end run